FoxSyntaxTree.Mod 158 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784
  1. MODULE FoxSyntaxTree; (** AUTHOR "fof & fn"; PURPOSE "Oberon Compiler: Abstract Syntax Tree"; **)
  2. (* (c) fof ETHZ 2009 *)
  3. (**
  4. note on documentation:
  5. Most objects in this module are commented with an informal Oberon syntax example indicating which variables of the respective object stand for what symbol /expression etc.
  6. This syntax example should not be confused with a profound description of the syntax in an EBNF form, which can rather be found in the parser module.
  7. The informal Oberon syntax is marked with << ... >>
  8. **)
  9. IMPORT
  10. Basic := FoxBasic, Scanner := FoxScanner, BitSets, Commands, StringPool, Strings(* , D := Debugging (* only for debuggging / counting *) *) ;
  11. CONST
  12. (** general flags: used in statements, procedure types and symbols
  13. general flags are unique and may overlap with access flags only
  14. flag numbers have no meaning and are not used for object files etc., i.e. flag renumbering is possible without effect
  15. *)
  16. (** calling conventions *)
  17. OberonCallingConvention* =0;
  18. CCallingConvention* =1;
  19. WinAPICallingConvention* =2;
  20. DarwinCCallingConvention* =3;
  21. InterruptCallingConvention* = 4;
  22. (** Access Flags *)
  23. InternalRead* = 0; (** can read symbol in same module *)
  24. InternalWrite* = 1; (** can write symbol in same module *)
  25. ProtectedRead* = 2; (** can read symbol in type extentions *)
  26. ProtectedWrite* = 3; (** can write symbol in type extentions *)
  27. PublicRead* = 4; (** can read everywhere *)
  28. PublicWrite* = 5; (** can write everywhere *)
  29. Hidden* = {};
  30. Internal* = {InternalRead, InternalWrite};
  31. Protected* = {ProtectedRead, ProtectedWrite} ;
  32. Public* = {PublicRead, PublicWrite} ;
  33. ReadOnly* = {InternalRead, ProtectedRead,PublicRead};
  34. (** parameter forms *)
  35. ValueParameter* = 0; VarParameter* = 1; ConstParameter* = 2;
  36. InPort*=3; OutPort*=4;
  37. (** array forms *)
  38. Static*=1; (* ARRAY x OF .. / ARRAY [x] OF ... *)
  39. Open*=2; (* ARRAY OF ... / ARRAY [*] OF ... *)
  40. Tensor*=3; (* ARRAY [?] OF ... *)
  41. SemiDynamic*=4;
  42. (** node states, important for checker to avoid cycles *)
  43. Undefined*={}; BeingResolved*=1; Resolved*=2; FingerPrinted*=3; Warned*=4; RecursionFlag=31;
  44. (* context in which a range expression is used *)
  45. ArrayIndex* = 0;
  46. SetElement* = 1;
  47. CaseGuard* = 2;
  48. TYPE
  49. SourceCode*= Scanner.StringType;
  50. BinaryCode*= BitSets.BitSet;
  51. String*= Scanner.StringType;
  52. IdentifierString*= Scanner.IdentifierString;
  53. (** visitor pattern implementation *)
  54. (* to use this object in your implementation, copy and paste and replace "x: " by "x: SyntaxTree." *)
  55. Visitor* = OBJECT
  56. (** types *)
  57. PROCEDURE VisitType*(x: Type);
  58. BEGIN HALT(100) (* abstract *) END VisitType;
  59. PROCEDURE VisitBasicType*(x: BasicType);
  60. BEGIN HALT(100) (* abstract *) END VisitBasicType;
  61. PROCEDURE VisitByteType*(x: ByteType);
  62. BEGIN HALT(100) (* abstract *) END VisitByteType;
  63. PROCEDURE VisitAnyType*(x: AnyType);
  64. BEGIN HALT(100) (* abstract *) END VisitAnyType;
  65. PROCEDURE VisitObjectType*(x: ObjectType);
  66. BEGIN HALT(100) (* abstract *) END VisitObjectType;
  67. PROCEDURE VisitNilType*(x: NilType);
  68. BEGIN HALT(100) (* abstract *) END VisitNilType;
  69. PROCEDURE VisitAddressType*(x: AddressType);
  70. BEGIN HALT(100) (* abstract *) END VisitAddressType;
  71. PROCEDURE VisitSizeType*(x: SizeType);
  72. BEGIN HALT(100) (* abstract *) END VisitSizeType;
  73. PROCEDURE VisitBooleanType*(x: BooleanType);
  74. BEGIN HALT(100) (* abstract *) END VisitBooleanType;
  75. PROCEDURE VisitSetType*(x: SetType);
  76. BEGIN HALT(100) (* abstract *) END VisitSetType;
  77. PROCEDURE VisitCharacterType*(x: CharacterType);
  78. BEGIN HALT(100) END VisitCharacterType;
  79. PROCEDURE VisitIntegerType*(x: IntegerType);
  80. BEGIN HALT(100) END VisitIntegerType;
  81. PROCEDURE VisitFloatType*(x: FloatType);
  82. BEGIN HALT(100) END VisitFloatType;
  83. PROCEDURE VisitComplexType*(x: ComplexType);
  84. BEGIN HALT(100) END VisitComplexType;
  85. PROCEDURE VisitQualifiedType*(x: QualifiedType);
  86. BEGIN HALT(100) (* abstract *) END VisitQualifiedType;
  87. PROCEDURE VisitStringType*(x: StringType);
  88. BEGIN HALT(100) (* abstract *) END VisitStringType;
  89. PROCEDURE VisitEnumerationType*(x: EnumerationType);
  90. BEGIN HALT(100) (* abstract *) END VisitEnumerationType;
  91. PROCEDURE VisitRangeType*(x: RangeType);
  92. BEGIN HALT(100) (* abstract *) END VisitRangeType;
  93. PROCEDURE VisitArrayType*(x: ArrayType);
  94. BEGIN HALT(100) (* abstract *) END VisitArrayType;
  95. PROCEDURE VisitMathArrayType*(x: MathArrayType);
  96. BEGIN HALT(100) (* abstract *) END VisitMathArrayType;
  97. PROCEDURE VisitPointerType*(x: PointerType);
  98. BEGIN HALT(100) (* abstract *) END VisitPointerType;
  99. PROCEDURE VisitPortType*(x: PortType);
  100. BEGIN HALT(100) (* abstract *) END VisitPortType;
  101. PROCEDURE VisitRecordType*(x: RecordType);
  102. BEGIN HALT(100) (* abstract *) END VisitRecordType;
  103. PROCEDURE VisitCellType*(x: CellType);
  104. BEGIN HALT(100) (* abstract *) END VisitCellType;
  105. PROCEDURE VisitProcedureType*(x: ProcedureType);
  106. BEGIN HALT(100) (* abstract *) END VisitProcedureType;
  107. (** expressions *)
  108. PROCEDURE VisitExpression*(x: Expression);
  109. BEGIN HALT(100) (* abstract *) END VisitExpression;
  110. PROCEDURE VisitSet*(x: Set);
  111. BEGIN HALT(100) (* abstract *) END VisitSet;
  112. PROCEDURE VisitMathArrayExpression*(x: MathArrayExpression);
  113. BEGIN HALT(100) (* abstract *) END VisitMathArrayExpression;
  114. PROCEDURE VisitUnaryExpression*(x: UnaryExpression);
  115. BEGIN HALT(100) (* abstract *) END VisitUnaryExpression;
  116. PROCEDURE VisitBinaryExpression*(x: BinaryExpression);
  117. BEGIN HALT(100) (* abstract *) END VisitBinaryExpression;
  118. PROCEDURE VisitRangeExpression*(x: RangeExpression);
  119. BEGIN HALT(100) (* abstract *) END VisitRangeExpression;
  120. PROCEDURE VisitTensorRangeExpression*(x: TensorRangeExpression);
  121. BEGIN HALT(100) (* abstract *) END VisitTensorRangeExpression;
  122. PROCEDURE VisitConversion*(x: Conversion);
  123. BEGIN HALT(100) (* abstract *) END VisitConversion;
  124. (** designators (expressions) *)
  125. PROCEDURE VisitDesignator*(x: Designator);
  126. BEGIN HALT(100) (* abstract *) END VisitDesignator;
  127. PROCEDURE VisitIdentifierDesignator*(x: IdentifierDesignator);
  128. BEGIN HALT(100) (* abstract *) END VisitIdentifierDesignator;
  129. PROCEDURE VisitSelectorDesignator*(x: SelectorDesignator);
  130. BEGIN HALT(100) (* abstract *) END VisitSelectorDesignator;
  131. PROCEDURE VisitParameterDesignator*(x: ParameterDesignator);
  132. BEGIN HALT(100) (* abstract *) END VisitParameterDesignator;
  133. PROCEDURE VisitArrowDesignator*(x: ArrowDesignator);
  134. BEGIN HALT(100) (* abstract *) END VisitArrowDesignator;
  135. PROCEDURE VisitBracketDesignator*(x: BracketDesignator);
  136. BEGIN HALT(100) (* abstract *) END VisitBracketDesignator;
  137. PROCEDURE VisitSymbolDesignator*(x: SymbolDesignator);
  138. BEGIN HALT(100) (* abstract *) END VisitSymbolDesignator;
  139. PROCEDURE VisitIndexDesignator*(x: IndexDesignator);
  140. BEGIN HALT(100) (* abstract *) END VisitIndexDesignator;
  141. PROCEDURE VisitProcedureCallDesignator*(x: ProcedureCallDesignator);
  142. BEGIN HALT(100) (* abstract *) END VisitProcedureCallDesignator;
  143. PROCEDURE VisitStatementDesignator*(x: StatementDesignator);
  144. BEGIN HALT(100) (* abstract *) END VisitStatementDesignator;
  145. PROCEDURE VisitBuiltinCallDesignator*(x: BuiltinCallDesignator);
  146. BEGIN HALT(100) (* abstract *) END VisitBuiltinCallDesignator;
  147. PROCEDURE VisitTypeGuardDesignator*(x: TypeGuardDesignator);
  148. BEGIN HALT(100) (* abstract *) END VisitTypeGuardDesignator;
  149. PROCEDURE VisitDereferenceDesignator*(x: DereferenceDesignator);
  150. BEGIN HALT(100) (* abstract *) END VisitDereferenceDesignator;
  151. PROCEDURE VisitSupercallDesignator*(x: SupercallDesignator);
  152. BEGIN HALT(100) (* abstract *) END VisitSupercallDesignator;
  153. PROCEDURE VisitSelfDesignator*(x: SelfDesignator);
  154. BEGIN HALT(100) (* abstract *) END VisitSelfDesignator;
  155. PROCEDURE VisitResultDesignator*(x: ResultDesignator);
  156. BEGIN HALT(100) (* abstract *) END VisitResultDesignator;
  157. (** values *)
  158. PROCEDURE VisitValue*(x: Value);
  159. BEGIN HALT(100) (* abstract *) END VisitValue;
  160. PROCEDURE VisitBooleanValue*(x: BooleanValue);
  161. BEGIN HALT(100) (* abstract *) END VisitBooleanValue;
  162. PROCEDURE VisitIntegerValue*(x: IntegerValue);
  163. BEGIN HALT(100) (* abstract *) END VisitIntegerValue;
  164. PROCEDURE VisitCharacterValue*(x: CharacterValue);
  165. BEGIN HALT(100) (* abstract *) END VisitCharacterValue;
  166. PROCEDURE VisitSetValue*(x: SetValue);
  167. BEGIN HALT(100) (* abstract *) END VisitSetValue;
  168. PROCEDURE VisitMathArrayValue*(x: MathArrayValue);
  169. BEGIN HALT(100) (* abstract *) END VisitMathArrayValue;
  170. PROCEDURE VisitRealValue*(x: RealValue);
  171. BEGIN HALT(100) (* abstract *) END VisitRealValue;
  172. PROCEDURE VisitComplexValue*(x: ComplexValue);
  173. BEGIN HALT(100) (* abstract *) END VisitComplexValue;
  174. PROCEDURE VisitStringValue*(x: StringValue);
  175. BEGIN HALT(100) (* abstract *) END VisitStringValue;
  176. PROCEDURE VisitNilValue*(x: NilValue);
  177. BEGIN HALT(100) (* abstract *) END VisitNilValue;
  178. PROCEDURE VisitEnumerationValue*(x: EnumerationValue);
  179. BEGIN HALT(100) (* abstract *) END VisitEnumerationValue;
  180. (** symbols *)
  181. PROCEDURE VisitSymbol*(x: Symbol);
  182. BEGIN HALT(100) (* abstract *) END VisitSymbol;
  183. PROCEDURE VisitModule*(x: Module);
  184. BEGIN HALT(100) (* abstract *) END VisitModule;
  185. PROCEDURE VisitTypeDeclaration*(x: TypeDeclaration);
  186. BEGIN HALT(100) (* abstract *) END VisitTypeDeclaration;
  187. PROCEDURE VisitConstant*(x: Constant);
  188. BEGIN HALT(100) (* abstract *) END VisitConstant;
  189. PROCEDURE VisitVariable*(x: Variable);
  190. BEGIN HALT(100) (* abstract *) END VisitVariable;
  191. PROCEDURE VisitParameter*(x: Parameter);
  192. BEGIN HALT(100) (* abstract *) END VisitParameter;
  193. PROCEDURE VisitProperty*(x: Property);
  194. BEGIN HALT(100) (* abstract *) END VisitProperty;
  195. PROCEDURE VisitProcedure*(x: Procedure);
  196. BEGIN HALT(100) (* abstract *) END VisitProcedure;
  197. PROCEDURE VisitBuiltin*(x: Builtin);
  198. BEGIN HALT(100) (* abstract *) END VisitBuiltin;
  199. PROCEDURE VisitOperator*(x: Operator);
  200. BEGIN HALT(100) (* abstract *) END VisitOperator;
  201. PROCEDURE VisitImport*(x: Import);
  202. BEGIN HALT(100) (* abstract *) END VisitImport;
  203. (** statements *)
  204. PROCEDURE VisitStatement*(x: Statement);
  205. BEGIN HALT(100) (* abstract *) END VisitStatement;
  206. PROCEDURE VisitProcedureCallStatement*(x: ProcedureCallStatement);
  207. BEGIN HALT(100) (* abstract *) END VisitProcedureCallStatement;
  208. PROCEDURE VisitAssignment*(x: Assignment);
  209. BEGIN HALT(100) (* abstract *) END VisitAssignment;
  210. PROCEDURE VisitCommunicationStatement*(x: CommunicationStatement);
  211. BEGIN HALT(100) (* abstract *) END VisitCommunicationStatement;
  212. PROCEDURE VisitIfStatement*(x: IfStatement);
  213. BEGIN HALT(100) (* abstract *) END VisitIfStatement;
  214. PROCEDURE VisitWithStatement*(x: WithStatement);
  215. BEGIN HALT(100) (* abstract *) END VisitWithStatement;
  216. PROCEDURE VisitCaseStatement*(x: CaseStatement);
  217. BEGIN HALT(100) (* abstract *) END VisitCaseStatement;
  218. PROCEDURE VisitWhileStatement*(x: WhileStatement);
  219. BEGIN HALT(100) (* abstract *) END VisitWhileStatement;
  220. PROCEDURE VisitRepeatStatement*(x: RepeatStatement);
  221. BEGIN HALT(100) (* abstract *) END VisitRepeatStatement;
  222. PROCEDURE VisitForStatement*(x: ForStatement);
  223. BEGIN HALT(100) (* abstract *) END VisitForStatement;
  224. PROCEDURE VisitLoopStatement*(x: LoopStatement);
  225. BEGIN HALT(100) (* abstract *) END VisitLoopStatement;
  226. PROCEDURE VisitExitableBlock*(x: ExitableBlock);
  227. BEGIN HALT(100) (* abstract *) END VisitExitableBlock;
  228. PROCEDURE VisitExitStatement*(x: ExitStatement);
  229. BEGIN HALT(100) (* abstract *) END VisitExitStatement;
  230. PROCEDURE VisitReturnStatement*(x: ReturnStatement);
  231. BEGIN HALT(100) (* abstract *) END VisitReturnStatement;
  232. PROCEDURE VisitAwaitStatement*(x: AwaitStatement);
  233. BEGIN HALT(100) (* abstract *) END VisitAwaitStatement;
  234. PROCEDURE VisitStatementBlock*(x: StatementBlock);
  235. BEGIN HALT(100) (* abstract *) END VisitStatementBlock;
  236. PROCEDURE VisitCode*(x: Code);
  237. BEGIN HALT(100) (* abstract *) END VisitCode;
  238. END Visitor;
  239. ArrayAccessOperators* = RECORD
  240. len*: Operator; (* length operator *)
  241. generalRead*, generalWrite*: Operator; (* operators on ARRAY [*] RANGE, for tensors *)
  242. read*, write*: POINTER TO ARRAY OF Operator; (* fixed-dim. operators *)
  243. END;
  244. FingerPrint*= RECORD
  245. shallow*,public*, private*: LONGINT;
  246. shallowAvailable*, deepAvailable*: BOOLEAN;
  247. END;
  248. (** identifiers in a program text **)
  249. Identifier* = Basic.String;
  250. (** qualified identifiers << Identifier.Identifier >> **)
  251. QualifiedIdentifier* = OBJECT
  252. VAR
  253. prefix-, suffix-: Identifier; (* use string index instead ? *)
  254. position-: LONGINT;
  255. PROCEDURE & InitQualifiedIdentifier( position: LONGINT; prefix, suffix: Identifier);
  256. BEGIN
  257. (* ASSERT(suffix # invalidIdentifier); can happen but should be catched by the parser with error report and not here with trap *)
  258. SELF.position := position;
  259. SELF.prefix := prefix; SELF.suffix := suffix;
  260. END InitQualifiedIdentifier;
  261. PROCEDURE GetName*(VAR name: Basic.SegmentedName);
  262. VAR s: ARRAY 64 OF CHAR;
  263. BEGIN
  264. Basic.InitSegmentedName(name);
  265. IF prefix # invalidIdentifier THEN Basic.SuffixSegmentedName(name, prefix) END;
  266. Basic.SuffixSegmentedName(name, suffix)
  267. END GetName;
  268. END QualifiedIdentifier;
  269. (**** types ****)
  270. (**
  271. Type
  272. BasicType
  273. ObjectType
  274. NilType
  275. AnyType
  276. ByteType
  277. AddressType
  278. SizeType
  279. BooleanType
  280. SetType
  281. CharacterType
  282. RangeType
  283. NumberType
  284. IntegerType
  285. FloatType
  286. ComplexType
  287. QualifiedType
  288. StringType
  289. EnumerationType
  290. ArrayType
  291. MathArrayType
  292. PointerType
  293. PortType
  294. RecordType
  295. CellType
  296. ProcedureType
  297. *)
  298. Type* = OBJECT
  299. VAR
  300. typeDeclaration-: TypeDeclaration; (* link to declaration (if any), needed for printing, debugging and symbol lookup *)
  301. scope-: Scope; (* scope where the type has been declared *)
  302. resolved-: Type; (* indirection to resolved type to preserve qualified types *)
  303. position-,endposition-: LONGINT;
  304. state-: SET;
  305. hasPointers-: BOOLEAN;
  306. fingerprint-: FingerPrint;
  307. isRealtime-: BOOLEAN;
  308. recursion: BOOLEAN;
  309. sizeInBits-: LONGINT; (* allocation size of this type in bits *)
  310. alignmentInBits-: LONGINT;
  311. PROCEDURE & InitType*( position: LONGINT);
  312. BEGIN
  313. SELF.position := position; state := Undefined;
  314. typeDeclaration := NIL;
  315. scope := NIL;
  316. resolved := SELF;
  317. sizeInBits := MIN(LONGINT);
  318. alignmentInBits := MIN(LONGINT);
  319. isRealtime := FALSE;
  320. recursion := FALSE;
  321. hasPointers := FALSE;
  322. InitFingerPrint(fingerprint);
  323. END InitType;
  324. PROCEDURE SetSize*(sizeInBits: LONGINT);
  325. BEGIN SELF.sizeInBits := sizeInBits
  326. END SetSize;
  327. PROCEDURE SetAlignment*(alignmentInBits: LONGINT);
  328. BEGIN SELF.alignmentInBits := alignmentInBits
  329. END SetAlignment;
  330. PROCEDURE End*( position: LONGINT );
  331. BEGIN SELF.endposition := position;
  332. END End;
  333. PROCEDURE SetFingerPrint*(CONST fp: FingerPrint);
  334. BEGIN
  335. SELF.fingerprint := fp
  336. END SetFingerPrint;
  337. PROCEDURE SetState*(state: LONGINT);
  338. BEGIN INCL(SELF.state,state);
  339. END SetState;
  340. PROCEDURE SetHasPointers*(has: BOOLEAN);
  341. BEGIN
  342. hasPointers := has
  343. END SetHasPointers;
  344. PROCEDURE RemoveState*(state: LONGINT);
  345. BEGIN EXCL(SELF.state,state)
  346. END RemoveState;
  347. PROCEDURE SetTypeDeclaration*(typeDeclaration: TypeDeclaration);
  348. BEGIN SELF.typeDeclaration := typeDeclaration
  349. END SetTypeDeclaration;
  350. PROCEDURE SetScope*(scope: Scope);
  351. BEGIN SELF.scope := scope
  352. END SetScope;
  353. PROCEDURE SetRealtime*(isRealtime: BOOLEAN);
  354. BEGIN SELF.isRealtime := isRealtime
  355. END SetRealtime;
  356. PROCEDURE SameType*(this: Type): BOOLEAN;
  357. BEGIN RETURN FALSE
  358. END SameType;
  359. (** assignment compatibility of this := SELF *)
  360. PROCEDURE CompatibleTo*(to: Type): BOOLEAN;
  361. BEGIN RETURN FALSE
  362. END CompatibleTo;
  363. (** Returns if the type is a pointer *)
  364. PROCEDURE IsPointer*(): BOOLEAN;
  365. BEGIN RETURN FALSE
  366. END IsPointer;
  367. (** Returns if the type consists of more than one parts. Implies that an instance of this type cannot be (easily) represented in one register. *)
  368. PROCEDURE IsComposite*(): BOOLEAN;
  369. BEGIN RETURN FALSE
  370. END IsComposite;
  371. (** Returns if the type needs to be traced for garbage collection *)
  372. PROCEDURE NeedsTrace*(): BOOLEAN;
  373. BEGIN RETURN IsPointer ();
  374. END NeedsTrace;
  375. PROCEDURE Accept*(v: Visitor);
  376. VAR position: LONGINT;
  377. BEGIN position := SELF.position; v.VisitType(SELF)
  378. END Accept;
  379. PROCEDURE IsRecordType*(): BOOLEAN;
  380. BEGIN
  381. RETURN FALSE;
  382. END IsRecordType;
  383. END Type;
  384. (* basic types, defined in global name space *)
  385. BasicType*= OBJECT(Type)
  386. VAR name-: Identifier;
  387. PROCEDURE & InitBasicType(CONST id: ARRAY OF CHAR; sizeInBits: LONGINT);
  388. VAR str: IdentifierString;
  389. BEGIN
  390. COPY(id, str);Basic.AppendNumber(str,sizeInBits); name := NewIdentifier(str);
  391. InitType(-1);
  392. SetSize(sizeInBits);
  393. SELF.name := name
  394. END InitBasicType;
  395. PROCEDURE SetName*(CONST id: ARRAY OF CHAR);
  396. BEGIN
  397. name := NewIdentifier(id);
  398. END SetName;
  399. PROCEDURE SetTypeDeclaration*(typeDeclaration: TypeDeclaration);
  400. BEGIN HALT(100);
  401. END SetTypeDeclaration;
  402. PROCEDURE Accept*(v: Visitor);
  403. VAR position: LONGINT;
  404. BEGIN position := SELF.position; v.VisitBasicType(SELF)
  405. END Accept;
  406. END BasicType;
  407. (** <<OBJECT>>
  408. object type (base type of all objects)
  409. **)
  410. ObjectType*=OBJECT(BasicType)
  411. PROCEDURE & InitObjectType(sizeInBits: LONGINT);
  412. BEGIN
  413. InitBasicType("@Object",sizeInBits);
  414. hasPointers := TRUE;
  415. END InitObjectType;
  416. PROCEDURE SameType*(this: Type): BOOLEAN;
  417. BEGIN RETURN (this IS ObjectType)
  418. END SameType;
  419. PROCEDURE CompatibleTo*(to: Type): BOOLEAN;
  420. BEGIN RETURN ((to IS AnyType) OR (to IS ObjectType))
  421. END CompatibleTo;
  422. PROCEDURE Accept*(v: Visitor);
  423. VAR position: LONGINT;
  424. BEGIN position := SELF.position; v.VisitObjectType(SELF)
  425. END Accept;
  426. PROCEDURE IsPointer(): BOOLEAN;
  427. BEGIN RETURN TRUE
  428. END IsPointer;
  429. END ObjectType;
  430. (** <<NIL>>
  431. nil type (type of NIL pointers), may be replaced by any type
  432. **)
  433. NilType*=OBJECT(BasicType)
  434. PROCEDURE & InitNilType(sizeInBits: LONGINT);
  435. BEGIN
  436. InitBasicType("@Nil",sizeInBits);
  437. SetRealtime(TRUE);
  438. hasPointers := TRUE;
  439. END InitNilType;
  440. PROCEDURE SameType*(this: Type): BOOLEAN;
  441. BEGIN RETURN (this IS NilType)
  442. END SameType;
  443. PROCEDURE CompatibleTo*(to: Type): BOOLEAN;
  444. BEGIN RETURN (to IS NilType) OR (to IS ObjectType) OR (to IS AnyType) OR (to IS PointerType) OR (to IS ProcedureType) OR (to IS AddressType)
  445. END CompatibleTo;
  446. PROCEDURE IsPointer(): BOOLEAN;
  447. BEGIN RETURN TRUE
  448. END IsPointer;
  449. PROCEDURE Accept*(v: Visitor);
  450. VAR position: LONGINT;
  451. BEGIN position := SELF.position; v.VisitNilType(SELF)
  452. END Accept;
  453. END NilType;
  454. (** <<SYSTEM.BYTE>>
  455. any pointer type (pointer to record and pointer to array)
  456. **)
  457. AnyType*=OBJECT(BasicType)
  458. PROCEDURE & InitAnyType(sizeInBits: LONGINT);
  459. BEGIN
  460. InitBasicType("@Any",sizeInBits);
  461. hasPointers := TRUE;
  462. END InitAnyType;
  463. PROCEDURE SameType*(this: Type): BOOLEAN;
  464. BEGIN RETURN this IS AnyType
  465. END SameType;
  466. PROCEDURE CompatibleTo*(to: Type): BOOLEAN;
  467. BEGIN RETURN (to IS AnyType)
  468. END CompatibleTo;
  469. PROCEDURE IsPointer(): BOOLEAN;
  470. BEGIN RETURN TRUE
  471. END IsPointer;
  472. PROCEDURE Accept*(v: Visitor);
  473. VAR position: LONGINT;
  474. BEGIN position := SELF.position; v.VisitAnyType(SELF)
  475. END Accept;
  476. END AnyType;
  477. (** <<SYSTEM.BYTE>>
  478. byte type
  479. **)
  480. ByteType*=OBJECT(BasicType)
  481. PROCEDURE & InitByteType(sizeInBits: LONGINT);
  482. BEGIN
  483. InitBasicType("@Byte",sizeInBits);
  484. SetRealtime(TRUE);
  485. END InitByteType;
  486. PROCEDURE Accept*(v: Visitor);
  487. VAR position: LONGINT;
  488. BEGIN position := SELF.position; v.VisitByteType(SELF)
  489. END Accept;
  490. PROCEDURE SameType*(this: Type): BOOLEAN;
  491. BEGIN RETURN this IS ByteType
  492. END SameType;
  493. PROCEDURE CompatibleTo*(to: Type): BOOLEAN;
  494. BEGIN RETURN (to IS ByteType)
  495. END CompatibleTo;
  496. END ByteType;
  497. (** <<ADDRESS>>
  498. address type
  499. **)
  500. AddressType*=OBJECT(BasicType)
  501. PROCEDURE & InitAddressType(sizeInBits: LONGINT);
  502. BEGIN
  503. InitBasicType("@Address",sizeInBits);
  504. SetRealtime(TRUE);
  505. END InitAddressType;
  506. PROCEDURE SameType*(this: Type): BOOLEAN;
  507. BEGIN RETURN (this IS AddressType)
  508. END SameType;
  509. PROCEDURE CompatibleTo*(to: Type): BOOLEAN;
  510. BEGIN RETURN (to IS AddressType) OR (to IS SizeType) OR (to IS IntegerType) & (to.sizeInBits >= sizeInBits) OR (to IS PointerType) & to(PointerType).isUnsafe
  511. END CompatibleTo;
  512. PROCEDURE Accept*(v: Visitor);
  513. VAR position: LONGINT;
  514. BEGIN position := SELF.position; v.VisitAddressType(SELF)
  515. END Accept;
  516. END AddressType;
  517. (** <<SIZE>>
  518. size type (signed address type)
  519. **)
  520. SizeType*=OBJECT(BasicType)
  521. PROCEDURE & InitSizeType(sizeInBits: LONGINT);
  522. BEGIN
  523. InitBasicType("@Size",sizeInBits);
  524. SetRealtime(TRUE);
  525. END InitSizeType;
  526. PROCEDURE SameType*(this: Type): BOOLEAN;
  527. BEGIN RETURN (this IS SizeType) OR (this IS IntegerType) & (this(IntegerType).signed = TRUE) & (this.sizeInBits = sizeInBits)
  528. END SameType;
  529. PROCEDURE CompatibleTo*(to: Type): BOOLEAN;
  530. BEGIN RETURN (to IS SizeType) OR (to IS AddressType) OR (to IS IntegerType) & (to.sizeInBits >= sizeInBits)
  531. END CompatibleTo;
  532. PROCEDURE Accept*(v: Visitor);
  533. VAR position: LONGINT;
  534. BEGIN position := SELF.position; v.VisitSizeType(SELF)
  535. END Accept;
  536. END SizeType;
  537. (** <<BOOLEAN>>
  538. boolean type
  539. **)
  540. BooleanType*=OBJECT(BasicType)
  541. PROCEDURE & InitBooleanType(sizeInBits: LONGINT);
  542. BEGIN
  543. InitBasicType("@Boolean",sizeInBits);
  544. SetRealtime(TRUE);
  545. END InitBooleanType;
  546. PROCEDURE SameType*(this: Type): BOOLEAN;
  547. BEGIN RETURN this IS BooleanType
  548. END SameType;
  549. PROCEDURE CompatibleTo*(to: Type): BOOLEAN;
  550. BEGIN RETURN (to IS BooleanType)
  551. END CompatibleTo;
  552. PROCEDURE Accept*(v: Visitor);
  553. VAR position: LONGINT;
  554. BEGIN position := SELF.position; v.VisitBooleanType(SELF)
  555. END Accept;
  556. END BooleanType;
  557. (** <<SET>>
  558. set type
  559. **)
  560. SetType*=OBJECT(BasicType)
  561. PROCEDURE & InitSetType(sizeInBits: LONGINT);
  562. BEGIN
  563. InitBasicType("@Set",sizeInBits);
  564. SetRealtime(TRUE);
  565. END InitSetType;
  566. PROCEDURE SameType*(this: Type): BOOLEAN;
  567. BEGIN RETURN (this IS SetType)
  568. END SameType;
  569. PROCEDURE CompatibleTo*(to: Type): BOOLEAN;
  570. BEGIN RETURN (to IS SetType)
  571. END CompatibleTo;
  572. PROCEDURE Accept*(v: Visitor);
  573. VAR position: LONGINT;
  574. BEGIN position := SELF.position; v.VisitSetType(SELF)
  575. END Accept;
  576. END SetType;
  577. (** <<CHAR, CHAR8, CHAR16, CHAR32>>
  578. character types
  579. **)
  580. CharacterType*=OBJECT(BasicType)
  581. PROCEDURE & InitCharacterType(sizeInBits: LONGINT);
  582. BEGIN
  583. InitBasicType("@Character", sizeInBits);
  584. SetRealtime(TRUE);
  585. END InitCharacterType;
  586. PROCEDURE SameType*(this: Type): BOOLEAN;
  587. BEGIN RETURN (this = SELF) OR (this IS CharacterType) & (this.sizeInBits = sizeInBits)
  588. END SameType;
  589. PROCEDURE CompatibleTo*(to: Type): BOOLEAN;
  590. BEGIN RETURN ((to IS CharacterType) OR (to IS ByteType)) & (to.sizeInBits >= sizeInBits)
  591. END CompatibleTo;
  592. PROCEDURE Accept*(v: Visitor);
  593. VAR position: LONGINT;
  594. BEGIN position := SELF.position; v.VisitCharacterType(SELF)
  595. END Accept;
  596. END CharacterType;
  597. (** type of ranges (case constants, set elements, array indices)
  598. represented by basic type <<RANGE>>
  599. **)
  600. RangeType* = OBJECT(BasicType)
  601. PROCEDURE & InitRangeType(sizeInBits: LONGINT);
  602. BEGIN
  603. InitBasicType("@RangeType",sizeInBits);
  604. SetRealtime(TRUE);
  605. END InitRangeType;
  606. PROCEDURE SameType*(this: Type): BOOLEAN;
  607. BEGIN RETURN (this = SELF) OR (this IS RangeType)
  608. END SameType;
  609. PROCEDURE CompatibleTo*(to: Type): BOOLEAN;
  610. BEGIN RETURN SameType(to)
  611. END CompatibleTo;
  612. PROCEDURE IsComposite(): BOOLEAN;
  613. BEGIN RETURN TRUE
  614. END IsComposite;
  615. PROCEDURE Accept*(v: Visitor);
  616. VAR position: LONGINT;
  617. BEGIN position := SELF.position; v.VisitRangeType(SELF)
  618. END Accept;
  619. END RangeType;
  620. (* number types: IntegerType or FloatType *)
  621. NumberType*=OBJECT(BasicType)
  622. PROCEDURE & InitNumberType( CONST name: ARRAY OF CHAR; sizeInBits: LONGINT);
  623. BEGIN
  624. InitBasicType(name, sizeInBits);
  625. SetRealtime(TRUE);
  626. END InitNumberType;
  627. END NumberType;
  628. (** <<SHORTINT, INTEGER, LONGINT, HUGEINT>>
  629. integer types
  630. **)
  631. IntegerType*= OBJECT (NumberType)
  632. VAR signed-: BOOLEAN;
  633. PROCEDURE & InitIntegerType(sizeInBits: LONGINT; signed: BOOLEAN);
  634. BEGIN
  635. IF signed THEN
  636. InitNumberType("@Integer",sizeInBits);
  637. ELSE
  638. InitNumberType("@Unsigned",sizeInBits);
  639. END;
  640. SELF.signed := signed;
  641. END InitIntegerType;
  642. PROCEDURE SameType*(this: Type): BOOLEAN;
  643. BEGIN RETURN (this = SELF) OR (this IS IntegerType) & (this.sizeInBits = sizeInBits) & (this(IntegerType).signed = signed)
  644. OR (this IS SizeType) & (this.sizeInBits=sizeInBits)
  645. END SameType;
  646. PROCEDURE CompatibleTo*(to: Type): BOOLEAN;
  647. BEGIN RETURN ((to IS IntegerType) OR (to IS AddressType) OR (to IS SizeType) OR (to IS ByteType)) & (to.sizeInBits >= sizeInBits) OR (to IS FloatType)
  648. OR (to IS ComplexType) & CompatibleTo((to(ComplexType).componentType))
  649. END CompatibleTo;
  650. PROCEDURE Accept*(v: Visitor);
  651. VAR position: LONGINT;
  652. BEGIN position := SELF.position; v.VisitIntegerType(SELF)
  653. END Accept;
  654. END IntegerType;
  655. (** <<REAL,LONGREAL>>
  656. real types: REAL, LONGREAL
  657. **)
  658. FloatType*= OBJECT (NumberType)
  659. PROCEDURE & InitFloatType(sizeInBits: LONGINT);
  660. BEGIN
  661. InitNumberType("@Float",sizeInBits);
  662. END InitFloatType;
  663. PROCEDURE SameType*(this: Type): BOOLEAN;
  664. BEGIN RETURN (this = SELF) OR (this IS FloatType) & (this.sizeInBits = sizeInBits)
  665. END SameType;
  666. PROCEDURE CompatibleTo*(to: Type): BOOLEAN;
  667. BEGIN
  668. RETURN (to IS FloatType) & (to.sizeInBits >= sizeInBits)
  669. OR (to IS ComplexType) & CompatibleTo((to(ComplexType).componentType))
  670. END CompatibleTo;
  671. PROCEDURE Accept*(v: Visitor);
  672. VAR position: LONGINT;
  673. BEGIN position := SELF.position; v.VisitFloatType(SELF)
  674. END Accept;
  675. END FloatType;
  676. (** <<COMPLEX,LONGCOMPLEX>>
  677. complex types: COMPLEX, LONGCOMPLEX
  678. **)
  679. ComplexType*= OBJECT (NumberType)
  680. VAR componentType-: Type; (* REAL or LONGREAL*)
  681. PROCEDURE & InitComplexType(componentType: Type);
  682. BEGIN
  683. ASSERT(componentType # NIL);
  684. SELF.componentType := componentType;
  685. sizeInBits := 2 * componentType.sizeInBits;
  686. InitNumberType("@Complex",sizeInBits);
  687. END InitComplexType;
  688. PROCEDURE SameType*(this: Type): BOOLEAN;
  689. BEGIN RETURN (this = SELF) OR (this IS ComplexType) & (componentType.SameType(this(ComplexType).componentType))
  690. END SameType;
  691. PROCEDURE CompatibleTo*(to: Type): BOOLEAN;
  692. BEGIN RETURN (to IS ComplexType) & (componentType.CompatibleTo(to(ComplexType).componentType))
  693. END CompatibleTo;
  694. PROCEDURE IsComposite(): BOOLEAN;
  695. BEGIN RETURN TRUE
  696. END IsComposite;
  697. PROCEDURE Accept*(v: Visitor);
  698. VAR position: LONGINT;
  699. BEGIN position := SELF.position; v.VisitComplexType(SELF)
  700. END Accept;
  701. END ComplexType;
  702. (** <<qualifiedIdentifier = resolved>>
  703. named reference to a type
  704. **)
  705. QualifiedType* = OBJECT (Type)
  706. VAR
  707. qualifiedIdentifier-: QualifiedIdentifier;
  708. PROCEDURE & InitQualifiedType( position: LONGINT; scope: Scope; qualifiedIdentifier: QualifiedIdentifier);
  709. BEGIN
  710. ASSERT(qualifiedIdentifier # NIL);
  711. InitType( position);
  712. SELF.scope := scope;
  713. SELF.qualifiedIdentifier := qualifiedIdentifier;
  714. resolved := NIL;
  715. END InitQualifiedType;
  716. PROCEDURE SetResolved*(resolved: Type);
  717. BEGIN SELF.resolved := resolved; IF resolved # NIL THEN hasPointers := resolved.hasPointers END;
  718. END SetResolved;
  719. PROCEDURE SameType*(this: Type): BOOLEAN;
  720. BEGIN RETURN (this = SELF) OR (resolved # NIL) & (this.resolved # NIL) & resolved.SameType(this.resolved)
  721. END SameType;
  722. PROCEDURE CompatibleTo*(to: Type): BOOLEAN;
  723. BEGIN RETURN (resolved # NIL) & resolved.CompatibleTo(to)
  724. END CompatibleTo;
  725. PROCEDURE IsPointer(): BOOLEAN;
  726. BEGIN RETURN (resolved # NIL) & resolved.IsPointer()
  727. END IsPointer;
  728. PROCEDURE IsComposite(): BOOLEAN;
  729. BEGIN RETURN (resolved # NIL) & resolved.IsComposite()
  730. END IsComposite;
  731. PROCEDURE Accept*(v: Visitor);
  732. VAR position: LONGINT;
  733. BEGIN position := SELF.position; v.VisitQualifiedType(SELF)
  734. END Accept;
  735. PROCEDURE NeedsTrace* (): BOOLEAN;
  736. BEGIN RETURN (resolved # NIL) & (resolved.NeedsTrace());
  737. END NeedsTrace;
  738. PROCEDURE IsRecordType(): BOOLEAN;
  739. BEGIN
  740. RETURN (resolved # NIL) & (resolved.IsRecordType());
  741. END IsRecordType;
  742. END QualifiedType;
  743. (** string literal type **)
  744. StringType*= OBJECT(Type)
  745. VAR
  746. length-: LONGINT;
  747. baseType-: Type;
  748. PROCEDURE & InitStringType(position: LONGINT; baseType: Type; length: LONGINT);
  749. BEGIN
  750. InitType(position);
  751. SetRealtime(TRUE);
  752. SELF.length := length;
  753. SELF.baseType := baseType;
  754. END InitStringType;
  755. PROCEDURE SetLength*(length: LONGINT);
  756. BEGIN SELF.length := length
  757. END SetLength;
  758. PROCEDURE SameType*(this: Type): BOOLEAN;
  759. BEGIN RETURN (this IS StringType) & (this(StringType).length = length)
  760. END SameType;
  761. PROCEDURE CompatibleTo*(to: Type): BOOLEAN;
  762. BEGIN
  763. IF to IS ArrayType THEN
  764. WITH to: ArrayType DO
  765. RETURN to.arrayBase.SameType(baseType.resolved) & ((to.form = Open) OR (to.staticLength >= length))
  766. END;
  767. ELSIF to IS CharacterType THEN
  768. RETURN (length=2) & baseType.CompatibleTo(to)
  769. ELSE RETURN FALSE
  770. END;
  771. END CompatibleTo;
  772. PROCEDURE IsComposite(): BOOLEAN;
  773. BEGIN RETURN TRUE
  774. END IsComposite;
  775. PROCEDURE Accept*(v: Visitor);
  776. VAR position: LONGINT;
  777. BEGIN position := SELF.position; v.VisitStringType(SELF)
  778. END Accept;
  779. END StringType;
  780. (** enumeration type of the form <<enum (base) red,green,blue end>> **)
  781. EnumerationType*=OBJECT(Type)
  782. VAR
  783. enumerationScope-: EnumerationScope;
  784. enumerationBase-: Type;
  785. rangeLowest-,rangeHighest-: LONGINT;
  786. PROCEDURE &InitEnumerationType(position: LONGINT; scope: Scope; enumerationScope: EnumerationScope);
  787. BEGIN
  788. InitType(position);
  789. SetRealtime(TRUE);
  790. SELF.scope := scope;
  791. enumerationBase := NIL;
  792. rangeLowest := 0; rangeHighest := 0;
  793. SELF.enumerationScope := enumerationScope;
  794. enumerationScope.ownerEnumeration := SELF;
  795. END InitEnumerationType;
  796. PROCEDURE SetEnumerationBase*(base: Type);
  797. BEGIN enumerationBase := base
  798. END SetEnumerationBase;
  799. PROCEDURE SetRange*(lowest,highest: LONGINT);
  800. BEGIN rangeLowest := lowest; rangeHighest := highest;
  801. END SetRange;
  802. PROCEDURE Extends*(this: EnumerationType): BOOLEAN;
  803. BEGIN RETURN (SELF = this) OR (enumerationBase # NIL) & (enumerationBase.resolved(EnumerationType).Extends(this));
  804. END Extends;
  805. PROCEDURE SameType*(this: Type): BOOLEAN;
  806. BEGIN RETURN this = SELF
  807. END SameType;
  808. PROCEDURE CompatibleTo*(to: Type): BOOLEAN;
  809. BEGIN RETURN (to IS EnumerationType) & (to(EnumerationType).Extends(SELF))
  810. END CompatibleTo;
  811. PROCEDURE Accept*(v: Visitor);
  812. VAR position: LONGINT;
  813. BEGIN position := SELF.position; v.VisitEnumerationType(SELF)
  814. END Accept;
  815. END EnumerationType;
  816. (** <<ARRAY [length] OF baseType>> *)
  817. ArrayType* = OBJECT (Type)
  818. VAR
  819. arrayBase-: Type;
  820. length-: Expression;
  821. staticLength-: LONGINT;
  822. form-: LONGINT; (* redundant: (form = Open) = (staticLength = 0) else (form = Static) *)
  823. PROCEDURE & InitArrayType(position: LONGINT; scope: Scope; form: LONGINT);
  824. BEGIN
  825. length := NIL; arrayBase := NIL; InitType(position); staticLength := 0; SELF.form := form; SELF.scope := scope;
  826. END InitArrayType;
  827. PROCEDURE SetArrayBase*( type: Type );
  828. BEGIN
  829. arrayBase := type; IF (arrayBase # NIL) & (arrayBase.hasPointers) THEN SetHasPointers(TRUE) END;
  830. END SetArrayBase;
  831. PROCEDURE SetForm*(f: LONGINT);
  832. BEGIN
  833. form := f;
  834. END SetForm;
  835. PROCEDURE SetLength*(length: Expression);
  836. BEGIN
  837. SELF.length := length;
  838. IF (length.resolved # NIL) & (length.resolved IS IntegerValue) THEN
  839. staticLength := length.resolved(IntegerValue).value
  840. END;
  841. END SetLength;
  842. PROCEDURE Child*(nr: LONGINT):Type;
  843. BEGIN
  844. IF nr = 0 THEN RETURN SELF;
  845. ELSIF nr = 1 THEN RETURN arrayBase.resolved;
  846. ELSE RETURN arrayBase.resolved(ArrayType).Child(nr-1);
  847. END;
  848. END Child;
  849. (* recursion safety for cases such as
  850. A= POINTER TO ARRAY OF B;
  851. B= POINTER TO ARRAY OF A;
  852. *)
  853. PROCEDURE SameType*(this: Type): BOOLEAN;
  854. VAR result : BOOLEAN;
  855. BEGIN
  856. result := FALSE;
  857. IF this = SELF THEN
  858. result := TRUE
  859. ELSIF recursion THEN
  860. result := TRUE;
  861. ELSIF this IS ArrayType THEN
  862. recursion := TRUE;
  863. WITH this: ArrayType DO
  864. result := (this.form = form) & (this.staticLength = staticLength) & arrayBase.SameType(this.arrayBase.resolved);
  865. END;
  866. END;
  867. recursion := FALSE;
  868. RETURN result
  869. END SameType;
  870. PROCEDURE CompatibleTo*(to: Type): BOOLEAN;
  871. BEGIN
  872. RETURN (form = Static) & SameType(to)
  873. END CompatibleTo;
  874. PROCEDURE IsComposite(): BOOLEAN;
  875. BEGIN RETURN TRUE
  876. END IsComposite;
  877. PROCEDURE NeedsTrace*(): BOOLEAN;
  878. BEGIN RETURN arrayBase.resolved.NeedsTrace ();
  879. END NeedsTrace;
  880. PROCEDURE Accept*(v: Visitor);
  881. VAR position: LONGINT;
  882. BEGIN position := SELF.position; v.VisitArrayType(SELF)
  883. END Accept;
  884. END ArrayType;
  885. (** <<ARRAY '[' length | '*' | '?' ']' OF baseType>> **)
  886. MathArrayType* = OBJECT (Type)
  887. VAR
  888. arrayBase-: Type;
  889. length-: Expression;
  890. staticLength-: LONGINT;
  891. staticIncrementInBits-: LONGINT;
  892. form-: LONGINT;
  893. PROCEDURE & InitMathArrayType(position: LONGINT;scope: Scope; form: LONGINT);
  894. BEGIN
  895. length := NIL; arrayBase := NIL; InitType(position); staticLength := 0; staticIncrementInBits := 0; SELF.form := form; SELF.scope := scope;
  896. END InitMathArrayType;
  897. PROCEDURE SetForm*(form: LONGINT);
  898. BEGIN
  899. SELF.form := form; IF form # Static THEN SetHasPointers(TRUE) END;
  900. END SetForm;
  901. PROCEDURE SetArrayBase*( type: Type );
  902. BEGIN
  903. arrayBase := type; IF (arrayBase # NIL) & (arrayBase.hasPointers) THEN SetHasPointers(TRUE) END;
  904. END SetArrayBase;
  905. PROCEDURE SetLength*(length: Expression);
  906. BEGIN
  907. SELF.length := length;
  908. IF (length # NIL) & (length.resolved # NIL) & (length.resolved IS IntegerValue) THEN
  909. staticLength := length.resolved(IntegerValue).value;
  910. (* optimization: unless the base type is a dynamic array, make this array static *)
  911. IF ~((arrayBase # NIL) & (arrayBase IS MathArrayType) & (arrayBase(MathArrayType).form # Static)) THEN
  912. form := Static;
  913. END
  914. ELSIF length = NIL THEN
  915. form := Open;
  916. END;
  917. END SetLength;
  918. PROCEDURE SetIncrement*(increment: LONGINT);
  919. BEGIN staticIncrementInBits := increment
  920. END SetIncrement;
  921. (* recursion safety for cases such as
  922. A= POINTER TO ARRAY OF B;
  923. B= POINTER TO ARRAY OF A;
  924. *)
  925. PROCEDURE SameType*(this: Type): BOOLEAN;
  926. VAR result: BOOLEAN;
  927. BEGIN
  928. result := FALSE;
  929. IF this = SELF THEN
  930. result := TRUE
  931. ELSIF recursion THEN
  932. result := TRUE;
  933. ELSIF this IS MathArrayType THEN
  934. recursion := TRUE;
  935. WITH this: MathArrayType DO
  936. result := (this.form = form) & (this.staticLength = staticLength) &
  937. ((arrayBase = NIL) & (this.arrayBase = NIL) OR (arrayBase # NIL) & (this.arrayBase # NIL) &
  938. arrayBase.SameType(this.arrayBase.resolved));
  939. END;
  940. END;
  941. recursion := FALSE;
  942. RETURN result
  943. END SameType;
  944. PROCEDURE CompatibleTo*(to: Type): BOOLEAN;
  945. BEGIN
  946. HALT(200); (*! implement *)
  947. RETURN (form = Static) & SameType(to)
  948. END CompatibleTo;
  949. (** get the element type of a math array, i.e. the first type in the math array chain that is not a math array **)
  950. PROCEDURE ElementType*(): Type;
  951. VAR
  952. type: Type;
  953. BEGIN
  954. type := SELF;
  955. WHILE type IS MathArrayType DO
  956. type := type(MathArrayType).arrayBase.resolved
  957. END;
  958. RETURN type
  959. END ElementType;
  960. (** get the number of dimensions of a math array; 0 in case of tensors **)
  961. PROCEDURE Dimensionality*(): LONGINT;
  962. VAR
  963. type: Type;
  964. dim: LONGINT;
  965. BEGIN
  966. IF form = Tensor THEN
  967. dim := 0
  968. ELSE
  969. type := SELF;
  970. dim := 0;
  971. WHILE type IS MathArrayType DO
  972. ASSERT(type(MathArrayType).form # Tensor);
  973. INC(dim);
  974. type := type(MathArrayType).arrayBase.resolved
  975. END
  976. END;
  977. RETURN dim
  978. END Dimensionality;
  979. (** if the math array is of the form ARRAY [*, *, ..., *], i.e. contains no static length and is not a tensor either **)
  980. PROCEDURE IsFullyDynamic*(): BOOLEAN;
  981. VAR
  982. type: Type;
  983. result: BOOLEAN;
  984. BEGIN
  985. IF form = Tensor THEN
  986. result := FALSE;
  987. ELSE
  988. result := TRUE;
  989. type := SELF;
  990. WHILE type IS MathArrayType DO
  991. IF type(MathArrayType).form # Open THEN result := FALSE END;
  992. type := type(MathArrayType).arrayBase.resolved
  993. END
  994. END;
  995. RETURN result
  996. END IsFullyDynamic;
  997. PROCEDURE IsComposite(): BOOLEAN;
  998. BEGIN RETURN TRUE
  999. END IsComposite;
  1000. PROCEDURE Accept*(v: Visitor);
  1001. VAR position: LONGINT;
  1002. BEGIN position := SELF.position; v.VisitMathArrayType(SELF)
  1003. END Accept;
  1004. END MathArrayType;
  1005. (** <<POINTER TO pointerBase>> **)
  1006. PointerType* = OBJECT (Type)
  1007. VAR
  1008. modifiers-: Modifier; (* set by the parser *)
  1009. pointerBase-: Type;
  1010. isPlain-: BOOLEAN;
  1011. isUnsafe-: BOOLEAN;
  1012. isDisposable-: BOOLEAN;
  1013. isHidden-: BOOLEAN;
  1014. PROCEDURE & InitPointerType(position: LONGINT; scope: Scope);
  1015. BEGIN
  1016. modifiers := NIL;
  1017. pointerBase := NIL;
  1018. isPlain := FALSE;
  1019. isUnsafe := FALSE;
  1020. isDisposable := FALSE;
  1021. InitType(position);
  1022. SELF.scope := scope;
  1023. hasPointers := TRUE;
  1024. isHidden := FALSE;
  1025. END InitPointerType;
  1026. PROCEDURE SetHidden*(hidden: BOOLEAN);
  1027. BEGIN
  1028. isHidden := hidden;
  1029. END SetHidden; (** <<POINTER TO pointerBase>> **)
  1030. PROCEDURE SetModifiers*(flags: Modifier);
  1031. BEGIN modifiers := flags
  1032. END SetModifiers;
  1033. PROCEDURE SetPointerBase*( type: Type );
  1034. BEGIN
  1035. pointerBase := type;
  1036. END SetPointerBase;
  1037. PROCEDURE SetPlain*(plain: BOOLEAN);
  1038. BEGIN
  1039. isPlain := plain;
  1040. END SetPlain;
  1041. PROCEDURE SetUnsafe*(unsafe: BOOLEAN);
  1042. BEGIN
  1043. isUnsafe := unsafe;
  1044. END SetUnsafe;
  1045. PROCEDURE SetDisposable*(disposable: BOOLEAN);
  1046. BEGIN
  1047. isDisposable := disposable;
  1048. END SetDisposable;
  1049. PROCEDURE Extends*(this: Type): BOOLEAN;
  1050. VAR result: BOOLEAN; extension, base: Type;
  1051. BEGIN
  1052. result := FALSE;
  1053. IF ((this IS ObjectType) OR (this IS AnyType)) & (pointerBase.resolved IS RecordType) THEN result := TRUE
  1054. ELSE
  1055. extension := pointerBase.resolved;
  1056. IF this IS PointerType THEN
  1057. base := this(PointerType).pointerBase.resolved;
  1058. ELSIF this IS RecordType THEN
  1059. base := this
  1060. ELSE base := NIL
  1061. END;
  1062. IF (extension IS RecordType) & (base # NIL) THEN
  1063. result := extension(RecordType).Extends(base)
  1064. END;
  1065. END;
  1066. RETURN result
  1067. END Extends;
  1068. PROCEDURE SameType*(this: Type): BOOLEAN;
  1069. BEGIN RETURN (SELF = this) OR (this IS PointerType) & (this(PointerType).pointerBase.SameType(pointerBase.resolved) & (this(PointerType).isUnsafe = isUnsafe))
  1070. END SameType;
  1071. PROCEDURE CompatibleTo*(to: Type): BOOLEAN;
  1072. BEGIN RETURN SameType(to) OR ~(to IS RecordType) & SELF.Extends(to)
  1073. END CompatibleTo;
  1074. PROCEDURE IsPointer(): BOOLEAN;
  1075. BEGIN RETURN TRUE
  1076. END IsPointer;
  1077. PROCEDURE Accept*(v: Visitor);
  1078. VAR position: LONGINT;
  1079. BEGIN position := SELF.position; v.VisitPointerType(SELF)
  1080. END Accept;
  1081. END PointerType;
  1082. (** << PORT (IN | OUT) [(size)] >>**)
  1083. PortType* = OBJECT (Type)
  1084. VAR
  1085. direction-: LONGINT;
  1086. sizeExpression-: Expression; (* generated by parser *)
  1087. sizeInBits-: LONGINT; (* computed by checker *)
  1088. PROCEDURE & InitPortType(position: LONGINT; direction: LONGINT; sizeExpression: Expression; scope: Scope);
  1089. BEGIN
  1090. InitType(position);
  1091. SELF.sizeExpression := sizeExpression;
  1092. SELF.direction := direction;
  1093. SELF.scope := scope;
  1094. END InitPortType;
  1095. PROCEDURE SetSize*(size: LONGINT);
  1096. BEGIN sizeInBits := size
  1097. END SetSize;
  1098. PROCEDURE SetSizeExpression*(sizeExpression: Expression);
  1099. BEGIN SELF.sizeExpression := sizeExpression
  1100. END SetSizeExpression;
  1101. PROCEDURE SameType*(this: Type): BOOLEAN;
  1102. BEGIN RETURN (this IS PortType) & (this(PortType).direction = direction) & (this(PortType).sizeInBits = sizeInBits)
  1103. END SameType;
  1104. PROCEDURE CompatibleTo*(to: Type): BOOLEAN;
  1105. BEGIN RETURN SameType(to)
  1106. END CompatibleTo;
  1107. PROCEDURE Accept*(v: Visitor);
  1108. VAR position: LONGINT;
  1109. BEGIN position := SELF.position; v.VisitPortType(SELF)
  1110. END Accept;
  1111. END PortType;
  1112. (** << recordType =
  1113. [POINTER TO] RECORD (baseType) .. END |
  1114. OBJECT (baseType) .. END
  1115. >> **)
  1116. RecordType* = OBJECT (Type)
  1117. VAR
  1118. recordScope-:RecordScope;
  1119. baseType-: Type;
  1120. pointerType-: PointerType; (* for support of A = POINTER TO RECORD ... END and B = POINTER TO RECORD (A) END; *)
  1121. isObject-,isProtected: BOOLEAN;
  1122. (* a math array type describing an object's array structure; NIL if the type does not exhibit an array structure *)
  1123. arrayStructure-: MathArrayType;
  1124. (* list of all operators needed to access an array-structured object type *)
  1125. arrayAccessOperators-: ArrayAccessOperators;
  1126. PROCEDURE & InitRecordType( position: LONGINT; scope: Scope; recordScope: RecordScope);
  1127. BEGIN
  1128. InitType( position);
  1129. SELF.scope := scope;
  1130. baseType := NIL;
  1131. pointerType := NIL;
  1132. SELF.recordScope := recordScope;
  1133. ASSERT(recordScope # NIL);
  1134. ASSERT(recordScope.ownerRecord = NIL); (* cannot register twice ! *)
  1135. recordScope.ownerRecord := SELF;
  1136. isObject := FALSE; isProtected := FALSE;
  1137. arrayStructure := NIL;
  1138. END InitRecordType;
  1139. PROCEDURE SetBaseType*( type: Type );
  1140. BEGIN
  1141. baseType := type; IF (baseType # NIL) & (baseType.hasPointers) THEN hasPointers := TRUE END;
  1142. END SetBaseType;
  1143. PROCEDURE SetPointerType*(pointerType: PointerType);
  1144. BEGIN SELF.pointerType := pointerType
  1145. END SetPointerType;
  1146. PROCEDURE IsObject*(isObject: BOOLEAN);
  1147. BEGIN SELF.isObject := isObject
  1148. END IsObject;
  1149. PROCEDURE IsActive*(): BOOLEAN;
  1150. VAR base: RecordType;
  1151. BEGIN
  1152. IF (recordScope.bodyProcedure # NIL) & (recordScope.bodyProcedure.procedureScope.body # NIL) & (recordScope.bodyProcedure.procedureScope.body.isActive) THEN RETURN TRUE END;
  1153. base := GetBaseRecord();
  1154. IF base # NIL THEN RETURN base.IsActive() END;
  1155. RETURN FALSE
  1156. END IsActive;
  1157. PROCEDURE IsProtected*(): BOOLEAN;
  1158. VAR base: RecordType;
  1159. BEGIN
  1160. IF isProtected THEN RETURN TRUE END;
  1161. base := GetBaseRecord();
  1162. IF base # NIL THEN RETURN base.IsProtected() END;
  1163. RETURN FALSE
  1164. END IsProtected;
  1165. PROCEDURE SetProtected*(protected: BOOLEAN);
  1166. BEGIN SELF.isProtected := protected
  1167. END SetProtected;
  1168. PROCEDURE Level*():LONGINT;
  1169. VAR type: RecordType; res: LONGINT;
  1170. BEGIN
  1171. type := SELF;
  1172. res := 0;
  1173. WHILE (type # NIL) & (type.baseType # NIL) DO
  1174. INC(res);
  1175. type := type.GetBaseRecord();
  1176. END;
  1177. RETURN res;
  1178. END Level;
  1179. PROCEDURE GetBaseRecord*():RecordType;
  1180. BEGIN
  1181. IF baseType = NIL THEN RETURN NIL; END;
  1182. IF baseType.resolved IS RecordType THEN
  1183. RETURN baseType.resolved(RecordType);
  1184. ELSIF baseType.resolved IS PointerType THEN
  1185. IF baseType.resolved(PointerType).pointerBase.resolved # NIL THEN
  1186. RETURN baseType.resolved(PointerType).pointerBase.resolved(RecordType);
  1187. END;
  1188. END;
  1189. RETURN NIL;
  1190. END GetBaseRecord;
  1191. PROCEDURE Extends*(this: Type): BOOLEAN;
  1192. VAR result: BOOLEAN; extension: Type;
  1193. BEGIN
  1194. result := FALSE;
  1195. IF this = SELF THEN result := TRUE
  1196. ELSIF this IS RecordType THEN
  1197. IF (baseType # NIL) THEN
  1198. extension := baseType.resolved;
  1199. IF extension IS PointerType THEN
  1200. result := extension(PointerType).Extends(this)
  1201. ELSIF extension IS RecordType THEN
  1202. result := extension(RecordType).Extends(this)
  1203. END;
  1204. END;
  1205. END;
  1206. RETURN result
  1207. END Extends;
  1208. PROCEDURE SameType*(this: Type): BOOLEAN;
  1209. BEGIN RETURN (this = SELF)
  1210. END SameType;
  1211. PROCEDURE CompatibleTo*(to: Type): BOOLEAN;
  1212. BEGIN RETURN Extends(to)
  1213. END CompatibleTo;
  1214. PROCEDURE SetArrayStructure*(arrayStructure: MathArrayType);
  1215. BEGIN SELF.arrayStructure := arrayStructure
  1216. END SetArrayStructure;
  1217. PROCEDURE SetArrayAccessOperators*(arrayAccessOperators: ArrayAccessOperators);
  1218. BEGIN SELF.arrayAccessOperators := arrayAccessOperators
  1219. END SetArrayAccessOperators;
  1220. PROCEDURE HasArrayStructure*(): BOOLEAN;
  1221. BEGIN RETURN (arrayStructure # NIL)
  1222. END HasArrayStructure
  1223. ;
  1224. PROCEDURE IsComposite(): BOOLEAN;
  1225. BEGIN RETURN TRUE
  1226. END IsComposite;
  1227. PROCEDURE NeedsTrace*(): BOOLEAN;
  1228. BEGIN RETURN recordScope.NeedsTrace();
  1229. END NeedsTrace;
  1230. PROCEDURE Accept*(v: Visitor);
  1231. VAR position: LONGINT;
  1232. BEGIN position := SELF.position; v.VisitRecordType(SELF)
  1233. END Accept;
  1234. PROCEDURE IsRecordType(): BOOLEAN;
  1235. BEGIN
  1236. RETURN TRUE;
  1237. END IsRecordType;
  1238. END RecordType;
  1239. CellType*=OBJECT (Type)
  1240. VAR
  1241. firstParameter-,lastParameter-: Parameter; numberParameters-: LONGINT; (* parameters *)
  1242. firstProperty-, lastProperty-: Property; numberProperties: LONGINT; (* capabilities *)
  1243. cellScope-: CellScope;
  1244. isCellNet-: BOOLEAN;
  1245. modifiers-: Modifier;
  1246. baseType-: Type;
  1247. PROCEDURE &InitCellType(position: LONGINT; scope: Scope; cellScope: CellScope);
  1248. BEGIN
  1249. InitType(position);
  1250. SELF.scope := scope;
  1251. numberParameters := 0; firstParameter := NIL; lastParameter := NIL;
  1252. numberProperties := 0; firstProperty := NIL; lastProperty := NIL;
  1253. SELF.cellScope := cellScope;
  1254. isCellNet := FALSE;
  1255. baseType := NIL;
  1256. END InitCellType;
  1257. PROCEDURE SetBaseType*(base: Type);
  1258. BEGIN
  1259. baseType := base;
  1260. END SetBaseType;
  1261. PROCEDURE GetBaseRecord*():RecordType;
  1262. BEGIN
  1263. IF baseType = NIL THEN RETURN NIL; END;
  1264. IF baseType.resolved IS RecordType THEN
  1265. RETURN baseType.resolved(RecordType);
  1266. ELSIF baseType.resolved IS PointerType THEN
  1267. IF baseType.resolved(PointerType).pointerBase.resolved # NIL THEN
  1268. RETURN baseType.resolved(PointerType).pointerBase.resolved(RecordType);
  1269. END;
  1270. END;
  1271. RETURN NIL;
  1272. END GetBaseRecord;
  1273. PROCEDURE AddParameter*(p: Parameter);
  1274. BEGIN
  1275. ASSERT(p # NIL);
  1276. IF lastParameter= NIL THEN firstParameter := p ELSE lastParameter.nextParameter := p; p.prevParameter := lastParameter; END;
  1277. lastParameter := p;
  1278. INC(numberParameters);
  1279. END AddParameter;
  1280. PROCEDURE AddProperty*(p: Property);
  1281. BEGIN
  1282. ASSERT(p # NIL);
  1283. IF lastProperty= NIL THEN firstProperty := p ELSE lastProperty.nextProperty := p; p.prevProperty := lastProperty; END;
  1284. lastProperty := p;
  1285. INC(numberProperties);
  1286. END AddProperty;
  1287. PROCEDURE FindParameter*(identifier: Identifier): Parameter;
  1288. VAR p: Parameter;
  1289. BEGIN
  1290. p := firstParameter;
  1291. WHILE(p#NIL) & (p.name # identifier) DO p := p.nextParameter END;
  1292. RETURN p;
  1293. END FindParameter;
  1294. PROCEDURE FindProperty*(identifier: Identifier): Property;
  1295. VAR p: Property;
  1296. BEGIN
  1297. p := firstProperty;
  1298. WHILE(p#NIL) & (p.name # identifier) DO p := p.nextProperty END;
  1299. RETURN p;
  1300. END FindProperty;
  1301. PROCEDURE SetModifiers*(flag: Modifier);
  1302. BEGIN SELF.modifiers := flag;
  1303. END SetModifiers;
  1304. PROCEDURE IsCellNet*(t: BOOLEAN);
  1305. BEGIN isCellNet := t
  1306. END IsCellNet;
  1307. PROCEDURE SameType*(this: Type): BOOLEAN;
  1308. BEGIN RETURN this = SELF
  1309. END SameType;
  1310. PROCEDURE CompatibleTo*(to: Type): BOOLEAN;
  1311. BEGIN RETURN SameType(to)
  1312. END CompatibleTo;
  1313. PROCEDURE IsComposite(): BOOLEAN;
  1314. BEGIN RETURN TRUE
  1315. END IsComposite;
  1316. PROCEDURE Accept*(v: Visitor);
  1317. VAR position: LONGINT;
  1318. BEGIN position := SELF.position; v.VisitCellType(SELF)
  1319. END Accept;
  1320. END CellType;
  1321. (** <<procedureType = PROCEDURE [{DELEGATE}] (firstParameter .. lastParameter): returnType>>
  1322. also used as type for procedures
  1323. **)
  1324. ProcedureType* = OBJECT (Type)
  1325. VAR
  1326. modifiers-: Modifier; (* set by the parser *)
  1327. returnType-: Type;
  1328. returnTypeModifiers-: Modifier;
  1329. hasUntracedReturn-: BOOLEAN;
  1330. firstParameter-,lastParameter-: Parameter; numberParameters-: LONGINT; (* parameters *)
  1331. returnParameter-: Parameter; (* not really necessary in syntax tree but very handy for backends *)
  1332. isDelegate-,isInterrupt-,noPAF-,noReturn-: BOOLEAN;
  1333. pcOffset-: LONGINT; (* PC offset: used for ARM interrupt procedures *)
  1334. callingConvention-: LONGINT;
  1335. stackAlignment-: LONGINT;
  1336. parameterOffset-: LONGINT; (* stack parameter offset caused by parameters on stack *)
  1337. PROCEDURE & InitProcedureType( position: LONGINT; scope: Scope);
  1338. BEGIN
  1339. InitType( position);
  1340. SELF.scope := scope;
  1341. modifiers := NIL;
  1342. firstParameter := NIL; lastParameter := NIL; numberParameters := 0; returnParameter := NIL;
  1343. returnType := NIL;
  1344. stackAlignment := 1;
  1345. isDelegate := FALSE; isInterrupt := FALSE; noPAF := FALSE;
  1346. callingConvention := OberonCallingConvention;
  1347. parameterOffset := 0;
  1348. pcOffset := 0;
  1349. hasUntracedReturn := FALSE;
  1350. returnTypeModifiers := NIL;
  1351. END InitProcedureType;
  1352. PROCEDURE SetNoPAF*(noPAF: BOOLEAN);
  1353. BEGIN SELF.noPAF := noPAF
  1354. END SetNoPAF;
  1355. PROCEDURE SetNoReturn*(noReturn: BOOLEAN);
  1356. BEGIN SELF.noReturn := noReturn
  1357. END SetNoReturn;
  1358. PROCEDURE SetPcOffset*(pcOffset: LONGINT);
  1359. BEGIN SELF.pcOffset := pcOffset
  1360. END SetPcOffset;
  1361. PROCEDURE SetInterrupt*(isInterrupt: BOOLEAN);
  1362. BEGIN SELF.isInterrupt := isInterrupt
  1363. END SetInterrupt;
  1364. PROCEDURE SetModifiers*(flags: Modifier);
  1365. BEGIN modifiers := flags
  1366. END SetModifiers;
  1367. PROCEDURE SetReturnTypeModifiers*(flags: Modifier);
  1368. BEGIN returnTypeModifiers := flags
  1369. END SetReturnTypeModifiers;
  1370. PROCEDURE SetDelegate*(delegate: BOOLEAN);
  1371. BEGIN SELF.isDelegate := delegate; SELF.hasPointers := delegate;
  1372. END SetDelegate;
  1373. PROCEDURE SetUntracedReturn*(untraced: BOOLEAN);
  1374. BEGIN
  1375. hasUntracedReturn := untraced;
  1376. END SetUntracedReturn;
  1377. PROCEDURE SetStackAlignment*(alignment: LONGINT);
  1378. BEGIN
  1379. stackAlignment := alignment;
  1380. END SetStackAlignment;
  1381. PROCEDURE SetParameterOffset*(ofs: LONGINT);
  1382. BEGIN parameterOffset := ofs
  1383. END SetParameterOffset;
  1384. PROCEDURE SetReturnParameter*(parameter: Parameter);
  1385. BEGIN returnParameter := parameter
  1386. END SetReturnParameter;
  1387. PROCEDURE SetCallingConvention*(cc: LONGINT);
  1388. BEGIN callingConvention := cc
  1389. END SetCallingConvention;
  1390. PROCEDURE AddParameter*(p: Parameter);
  1391. BEGIN
  1392. ASSERT(p # NIL);
  1393. IF lastParameter= NIL THEN firstParameter := p ELSE lastParameter.nextParameter := p; p.prevParameter := lastParameter; END;
  1394. lastParameter := p;
  1395. INC(numberParameters);
  1396. ASSERT(p.access # {}); (* no hidden parameters ! *)
  1397. END AddParameter;
  1398. PROCEDURE RevertParameters*;
  1399. VAR this,next: Parameter; pnum: LONGINT;
  1400. BEGIN
  1401. pnum := numberParameters;
  1402. IF lastParameter # NIL THEN
  1403. this := lastParameter;
  1404. lastParameter := NIL;
  1405. firstParameter := NIL;
  1406. numberParameters := 0;
  1407. WHILE this # NIL DO
  1408. next := this.prevParameter;
  1409. this.prevParameter := NIL; this.nextParameter := NIL;
  1410. AddParameter(this);
  1411. this := next;
  1412. END;
  1413. END;
  1414. ASSERT(pnum = numberParameters);
  1415. END RevertParameters;
  1416. PROCEDURE SetReturnType*( type: Type );
  1417. BEGIN
  1418. returnType := type;
  1419. END SetReturnType;
  1420. PROCEDURE SameType*(this: Type): BOOLEAN;
  1421. VAR result: BOOLEAN; p1,p2: Parameter;
  1422. BEGIN
  1423. result := FALSE;
  1424. IF recursion THEN
  1425. result := TRUE
  1426. ELSIF this = SELF THEN
  1427. result := TRUE
  1428. ELSIF this IS ProcedureType THEN
  1429. recursion := TRUE;
  1430. WITH this: ProcedureType DO
  1431. result := (returnType = NIL) & (this.returnType = NIL) OR (returnType # NIL) & (this.returnType # NIL) & returnType.SameType(this.returnType.resolved);
  1432. result := result & (callingConvention = this.callingConvention);
  1433. result := result & (noReturn = this.noReturn);
  1434. IF result THEN
  1435. p1 := firstParameter; p2 := this.firstParameter;
  1436. WHILE (p1 # NIL) & (p2 # NIL) & (p1.access # Hidden) & (p2.access # Hidden) & (p1.kind = p2.kind) & (p1.type.SameType(p2.type) OR (p2.type.resolved # NIL) & p1.type.SameType(p2.type.resolved) OR (p1.type.resolved IS AddressType) & (p2.type.resolved IS PointerType) & p2.type.resolved(PointerType).isUnsafe) DO
  1437. p1 := p1.nextParameter; p2 := p2.nextParameter
  1438. END;
  1439. result := ((p1=NIL) OR (p1.access = Hidden)) & ((p2=NIL) OR (p2.access= Hidden));
  1440. END;
  1441. END;
  1442. END;
  1443. recursion := FALSE;
  1444. RETURN result
  1445. END SameType;
  1446. PROCEDURE CompatibleTo*(to: Type): BOOLEAN;
  1447. BEGIN
  1448. RETURN SameType(to) & (~isDelegate OR to(ProcedureType).isDelegate) & (~to.isRealtime OR isRealtime);
  1449. END CompatibleTo;
  1450. PROCEDURE IsComposite(): BOOLEAN;
  1451. BEGIN RETURN isDelegate
  1452. END IsComposite;
  1453. PROCEDURE Accept*(v: Visitor);
  1454. VAR position: LONGINT;
  1455. BEGIN position := SELF.position; v.VisitProcedureType(SELF)
  1456. END Accept;
  1457. (** Returns if the type needs to be traced for garbage collection *)
  1458. PROCEDURE NeedsTrace*(): BOOLEAN;
  1459. BEGIN RETURN isDelegate;
  1460. END NeedsTrace;
  1461. END ProcedureType;
  1462. (**** expressions ****)
  1463. Expression* = OBJECT
  1464. VAR
  1465. type-: Type; (* the expression's type. Resolved by checker *)
  1466. assignable-: BOOLEAN; (* expression can be assigned to (or used as var-parameter): expression := ... *)
  1467. position-,endposition-: LONGINT;
  1468. state-: SET;
  1469. resolved-: Value;
  1470. isHidden-: BOOLEAN;
  1471. PROCEDURE End*( position: LONGINT );
  1472. BEGIN SELF.endposition := position;
  1473. END End;
  1474. PROCEDURE SetState*(state: LONGINT);
  1475. BEGIN INCL(SELF.state,state);
  1476. END SetState;
  1477. PROCEDURE &InitExpression(position: LONGINT);
  1478. BEGIN SELF.position := position; state := Undefined; type := NIL; assignable := FALSE; resolved := NIL; isHidden := FALSE;
  1479. END InitExpression;
  1480. PROCEDURE SetHidden*(hidden: BOOLEAN);
  1481. BEGIN isHidden := hidden
  1482. END SetHidden;
  1483. PROCEDURE SetType*(type: Type);
  1484. BEGIN
  1485. SELF.type := type;
  1486. END SetType;
  1487. PROCEDURE SetResolved*(value: Value);
  1488. BEGIN SELF.resolved := value
  1489. END SetResolved;
  1490. PROCEDURE SetAssignable*(assignable: BOOLEAN);
  1491. BEGIN SELF.assignable := assignable
  1492. END SetAssignable;
  1493. PROCEDURE Clone(): Expression;
  1494. VAR clone: Expression;
  1495. BEGIN
  1496. (* support cloning here for more robust error reporting -- should not happen normally *)
  1497. NEW(clone, position); RETURN clone
  1498. END Clone;
  1499. PROCEDURE Accept*(v: Visitor);
  1500. VAR position: LONGINT;
  1501. BEGIN position := SELF.position; v.VisitExpression(SELF)
  1502. END Accept;
  1503. PROCEDURE NeedsTrace* (): BOOLEAN;
  1504. BEGIN RETURN FALSE;
  1505. END NeedsTrace;
  1506. END Expression;
  1507. (** <<expression, expression, ...>> **)
  1508. ExpressionList* = OBJECT
  1509. VAR list: Basic.List;
  1510. PROCEDURE & InitList;
  1511. BEGIN NEW( list,8 );
  1512. END InitList;
  1513. PROCEDURE Length*( ): LONGINT;
  1514. BEGIN RETURN list.Length();
  1515. END Length;
  1516. PROCEDURE AddExpression*( d: Expression );
  1517. BEGIN list.Add(d)
  1518. END AddExpression;
  1519. PROCEDURE GetExpression*( index: LONGINT ): Expression;
  1520. VAR p: ANY;
  1521. BEGIN
  1522. p := list.Get(index); RETURN p(Expression);
  1523. END GetExpression;
  1524. PROCEDURE SetExpression*(index: LONGINT; expression: Expression);
  1525. BEGIN list.Set(index,expression)
  1526. END SetExpression;
  1527. PROCEDURE RemoveExpression*(i: LONGINT);
  1528. BEGIN list.RemoveByIndex(i);
  1529. END RemoveExpression;
  1530. PROCEDURE Revert*;
  1531. VAR i,j,last: LONGINT; ei,ej: ANY;
  1532. BEGIN
  1533. last := Length()-1;
  1534. FOR i := 0 TO last DO
  1535. j := last-i;
  1536. ei := list.Get(i);
  1537. ej := list.Get(j);
  1538. list.Set(i,ej);
  1539. list.Set(j,ei);
  1540. END;
  1541. END Revert;
  1542. PROCEDURE Clone*(VAR list: ExpressionList);
  1543. VAR i: LONGINT;
  1544. BEGIN
  1545. IF list = NIL THEN NEW(list) END;
  1546. FOR i := 0 TO Length()-1 DO
  1547. list.AddExpression(CloneExpression(GetExpression(i)));
  1548. END;
  1549. END Clone;
  1550. END ExpressionList;
  1551. (** << {elements} >> **)
  1552. Set* = OBJECT (Expression)
  1553. VAR elements-: ExpressionList; (* an element of the form from .. to is represented as a RangeExpression *)
  1554. PROCEDURE & InitSet( position: LONGINT );
  1555. BEGIN
  1556. InitExpression( position );
  1557. elements := NewExpressionList();
  1558. END InitSet;
  1559. PROCEDURE Clone(): Expression;
  1560. VAR copy: Set;
  1561. BEGIN
  1562. NEW(copy, position); elements.Clone(copy.elements); RETURN copy
  1563. END Clone;
  1564. PROCEDURE Accept*(v: Visitor);
  1565. VAR position: LONGINT;
  1566. BEGIN position := SELF.position; v.VisitSet(SELF)
  1567. END Accept;
  1568. END Set;
  1569. (** << [elements] >> **)
  1570. MathArrayExpression* = OBJECT (Expression)
  1571. VAR elements-: ExpressionList; (* an element of the form from .. to is represented as a RangeExpression *)
  1572. PROCEDURE & InitMathArrayExpression( position: LONGINT );
  1573. BEGIN
  1574. InitExpression( position );
  1575. elements := NewExpressionList();
  1576. END InitMathArrayExpression;
  1577. PROCEDURE Clone(): Expression;
  1578. VAR copy: MathArrayExpression;
  1579. BEGIN
  1580. NEW(copy, position); elements.Clone(copy.elements); RETURN copy
  1581. END Clone;
  1582. PROCEDURE Accept*(v: Visitor);
  1583. VAR position: LONGINT;
  1584. BEGIN position := SELF.position; v.VisitMathArrayExpression(SELF)
  1585. END Accept;
  1586. END MathArrayExpression;
  1587. (** <<operator left>> **)
  1588. UnaryExpression* = OBJECT (Expression)
  1589. VAR
  1590. left-: Expression;
  1591. operator-: LONGINT; (* one of Scanner.Minus ... Scanner.Not *)
  1592. PROCEDURE & InitUnaryExpression( position: LONGINT; operand: Expression; operator: LONGINT );
  1593. BEGIN
  1594. InitExpression( position ); SELF.left := operand; SELF.operator := operator;
  1595. END InitUnaryExpression;
  1596. PROCEDURE SetLeft*(left: Expression);
  1597. BEGIN SELF.left := left
  1598. END SetLeft;
  1599. PROCEDURE Clone(): Expression;
  1600. VAR copy: UnaryExpression;
  1601. BEGIN
  1602. NEW(copy, position, CloneExpression(left), operator); RETURN copy
  1603. END Clone;
  1604. PROCEDURE Accept*(v: Visitor);
  1605. VAR position: LONGINT;
  1606. BEGIN position := SELF.position; v.VisitUnaryExpression(SELF)
  1607. END Accept;
  1608. END UnaryExpression;
  1609. (** <<left operator right>> **)
  1610. BinaryExpression* = OBJECT (Expression)
  1611. VAR
  1612. left-, right-: Expression;
  1613. operator-: LONGINT; (* one of Scanner.Equal ... Scanner.Minus *)
  1614. PROCEDURE & InitBinaryExpression( position: LONGINT; left, right: Expression; operator: LONGINT );
  1615. BEGIN
  1616. InitExpression( position ); SELF.left := left; SELF.right := right; SELF.operator := operator;
  1617. END InitBinaryExpression;
  1618. PROCEDURE SetLeft*(left: Expression);
  1619. BEGIN SELF.left := left
  1620. END SetLeft;
  1621. PROCEDURE SetRight*(right: Expression);
  1622. BEGIN SELF.right := right
  1623. END SetRight;
  1624. PROCEDURE Clone(): Expression;
  1625. VAR copy: BinaryExpression;
  1626. BEGIN
  1627. NEW(copy, position, CloneExpression(left), CloneExpression(right), operator); RETURN copy
  1628. END Clone;
  1629. PROCEDURE Accept*(v: Visitor);
  1630. VAR position: LONGINT;
  1631. BEGIN position := SELF.position; v.VisitBinaryExpression(SELF)
  1632. END Accept;
  1633. END BinaryExpression;
  1634. (** expression that denotes a range
  1635. <<[first] '..' [last] ['by' step] | '*' >>
  1636. **)
  1637. RangeExpression* = OBJECT (Expression)
  1638. VAR
  1639. first-, last-, step-: Expression;
  1640. missingFirst-, missingLast-, missingStep-: BOOLEAN; (* only for printout*)
  1641. context-: SHORTINT; (* one of ArrayIndex, SetElement or CaseGuard *)
  1642. PROCEDURE &InitRangeExpression(position: LONGINT; first, last, step: Expression);
  1643. BEGIN
  1644. context := ArrayIndex; (* by default, a range represents array indices *)
  1645. InitExpression(position);
  1646. missingFirst := (first = NIL);
  1647. missingLast := (last = NIL);
  1648. missingStep := (step = NIL);
  1649. SELF.first := first;
  1650. SELF.last := last;
  1651. SELF.step := step;
  1652. END InitRangeExpression;
  1653. PROCEDURE SetFirst*(first: Expression);
  1654. BEGIN
  1655. SELF.first := first
  1656. END SetFirst;
  1657. PROCEDURE SetLast*(last: Expression);
  1658. BEGIN SELF.last := last
  1659. END SetLast;
  1660. PROCEDURE SetStep*(step: Expression);
  1661. BEGIN SELF.step := step
  1662. END SetStep;
  1663. PROCEDURE SetContext*(context: SHORTINT);
  1664. BEGIN
  1665. SELF.context := context
  1666. END SetContext;
  1667. PROCEDURE Clone(): Expression;
  1668. VAR copy: RangeExpression;
  1669. BEGIN
  1670. NEW(copy, position, CloneExpression(first), CloneExpression(last), CloneExpression(step)); RETURN copy
  1671. END Clone;
  1672. PROCEDURE Accept*(v: Visitor);
  1673. VAR position: LONGINT;
  1674. BEGIN position := SELF.position; v.VisitRangeExpression(SELF)
  1675. END Accept;
  1676. END RangeExpression;
  1677. (** << ? >> **)
  1678. TensorRangeExpression*=OBJECT (Expression);
  1679. PROCEDURE &InitTensorRangeExpression(position: LONGINT);
  1680. BEGIN
  1681. InitExpression(position);
  1682. END InitTensorRangeExpression;
  1683. PROCEDURE Clone(): Expression;
  1684. VAR copy: TensorRangeExpression;
  1685. BEGIN
  1686. NEW(copy, position); RETURN copy
  1687. END Clone;
  1688. PROCEDURE Accept*(v: Visitor);
  1689. VAR position: LONGINT;
  1690. BEGIN position := SELF.position; v.VisitTensorRangeExpression(SELF)
  1691. END Accept;
  1692. END TensorRangeExpression;
  1693. (** convert expression from expression.type to Conversion.type **)
  1694. Conversion* = OBJECT (Expression)
  1695. VAR
  1696. expression-: Expression;
  1697. typeExpression-: Expression; (* for printout *)
  1698. PROCEDURE & InitConversion( position: LONGINT; expression: Expression; type: Type; typeExpression: Expression);
  1699. BEGIN
  1700. InitExpression( position ); SELF.expression := expression; SELF.typeExpression := typeExpression; SELF.type := type;
  1701. END InitConversion;
  1702. PROCEDURE SetExpression*(expression: Expression);
  1703. BEGIN SELF.expression := expression
  1704. END SetExpression;
  1705. PROCEDURE Clone(): Expression;
  1706. VAR copy: Conversion;
  1707. BEGIN
  1708. NEW(copy, position, CloneExpression(expression), type, CloneExpression(typeExpression)); RETURN copy
  1709. END Clone;
  1710. PROCEDURE Accept*(v: Visitor);
  1711. VAR position: LONGINT;
  1712. BEGIN position := SELF.position; v.VisitConversion(SELF)
  1713. END Accept;
  1714. END Conversion;
  1715. (**** designators ****)
  1716. (** abstract **)
  1717. Designator* = OBJECT(Expression)
  1718. VAR
  1719. left-: Expression; (* currently only designators are allowed but for later purposes ... (as for example (a+b).c) *)
  1720. relatedRhs-: Expression; (* the RHS of an assignment if this designator is used on the LHS: *)
  1721. (* used if this designator contains an index operator call, e.g. 'asot.^"[]"(indexList)': *)
  1722. relatedAsot-: Expression; (* the ASOT on which the index operator is called *)
  1723. relatedIndexList-: ExpressionList; (* the index list *)
  1724. modifiers-: Modifier;
  1725. PROCEDURE &InitDesignator*(position: LONGINT);
  1726. BEGIN
  1727. InitExpression(position);
  1728. left := NIL;
  1729. relatedRhs := NIL;
  1730. relatedAsot := NIL;
  1731. relatedIndexList := NIL;
  1732. modifiers := NIL;
  1733. END InitDesignator;
  1734. PROCEDURE SetLeft*(expression: Expression);
  1735. BEGIN left := expression
  1736. END SetLeft;
  1737. PROCEDURE SetRelatedRhs*(relatedRhs: Expression);
  1738. BEGIN SELF.relatedRhs := relatedRhs
  1739. END SetRelatedRhs;
  1740. PROCEDURE SetRelatedAsot*(relatedAsot: Expression);
  1741. BEGIN SELF.relatedAsot := relatedAsot
  1742. END SetRelatedAsot;
  1743. PROCEDURE SetRelatedIndexList*(relatedIndexList: ExpressionList);
  1744. BEGIN SELF.relatedIndexList := relatedIndexList
  1745. END SetRelatedIndexList;
  1746. PROCEDURE SetModifiers*(flags: Modifier);
  1747. BEGIN modifiers := flags
  1748. END SetModifiers;
  1749. PROCEDURE Clone(): Expression;
  1750. VAR clone: Designator;
  1751. BEGIN
  1752. (* support cloning here for more robust error reporting -- should not happen normally *)
  1753. NEW(clone, position); RETURN clone
  1754. END Clone;
  1755. PROCEDURE Accept*(v: Visitor);
  1756. VAR position: LONGINT;
  1757. BEGIN position := SELF.position; v.VisitDesignator(SELF)
  1758. END Accept;
  1759. END Designator;
  1760. (*** first phase (parse time) designators ***)
  1761. (** <<identifier>>
  1762. may designate any symbol such as Variable, TypeDeclaration, Procedure
  1763. **)
  1764. IdentifierDesignator* = OBJECT(Designator)
  1765. VAR identifier-: Identifier;
  1766. PROCEDURE &InitIdentifierDesignator(position: LONGINT; id: Identifier);
  1767. BEGIN InitDesignator(position); identifier := id
  1768. END InitIdentifierDesignator;
  1769. PROCEDURE Clone(): Expression;
  1770. VAR copy: IdentifierDesignator;
  1771. BEGIN
  1772. NEW(copy, position, identifier); RETURN copy
  1773. END Clone;
  1774. PROCEDURE Accept*(v: Visitor);
  1775. VAR position: LONGINT;
  1776. BEGIN position := SELF.position; v.VisitIdentifierDesignator(SELF)
  1777. END Accept;
  1778. END IdentifierDesignator;
  1779. (** <<left.identifier>>
  1780. may designate a record / module element (constant, type, variable, procedure)
  1781. **)
  1782. SelectorDesignator* = OBJECT (Designator)
  1783. VAR identifier-: Identifier;
  1784. PROCEDURE & InitSelector(position: LONGINT; left: Designator; identifier: Identifier);
  1785. BEGIN InitDesignator(position); SELF.left := left; SELF.identifier := identifier;
  1786. END InitSelector;
  1787. PROCEDURE Clone(): Expression;
  1788. VAR copy: SelectorDesignator;
  1789. BEGIN
  1790. NEW(copy, position, CloneDesignator(left), identifier); RETURN copy
  1791. END Clone;
  1792. PROCEDURE Accept*(v: Visitor);
  1793. VAR position: LONGINT;
  1794. BEGIN position := SELF.position; v.VisitSelectorDesignator(SELF)
  1795. END Accept;
  1796. END SelectorDesignator;
  1797. (** <<left(arg1, arg2, ...)>>
  1798. may designate a function call or a type guard
  1799. **)
  1800. ParameterDesignator* = OBJECT(Designator)
  1801. VAR
  1802. parameters-: ExpressionList;
  1803. PROCEDURE &InitParameterDesignator(position: LONGINT; left: Designator; parameters: ExpressionList);
  1804. BEGIN InitDesignator(position); SELF.left := left; SELF.parameters := parameters
  1805. END InitParameterDesignator;
  1806. PROCEDURE Clone(): Expression;
  1807. VAR copy: ParameterDesignator;
  1808. BEGIN
  1809. NEW(copy, position, CloneDesignator(left), CloneExpressionList(parameters)); RETURN copy
  1810. END Clone;
  1811. PROCEDURE Accept*(v: Visitor);
  1812. VAR position: LONGINT;
  1813. BEGIN position := SELF.position; v.VisitParameterDesignator(SELF)
  1814. END Accept;
  1815. END ParameterDesignator;
  1816. (** <<left^>>
  1817. may designate a pointer dereference or a method supercall
  1818. **)
  1819. ArrowDesignator* = OBJECT (Designator)
  1820. PROCEDURE &InitArrowDesignator(position: LONGINT; left: Designator);
  1821. BEGIN InitDesignator(position); SELF.left := left;
  1822. END InitArrowDesignator;
  1823. PROCEDURE Clone(): Expression;
  1824. VAR copy: ArrowDesignator;
  1825. BEGIN
  1826. NEW(copy, position, CloneDesignator(left(Designator))); RETURN copy
  1827. END Clone;
  1828. PROCEDURE Accept*(v: Visitor);
  1829. VAR position: LONGINT;
  1830. BEGIN position := SELF.position; v.VisitArrowDesignator(SELF)
  1831. END Accept;
  1832. END ArrowDesignator;
  1833. (** <<left[parameters]>>
  1834. designates an index designator, before checker
  1835. **)
  1836. BracketDesignator* = OBJECT(Designator)
  1837. VAR parameters-: ExpressionList;
  1838. PROCEDURE &InitBracketDesignator(position: LONGINT; left: Designator; parameters: ExpressionList);
  1839. BEGIN InitDesignator(position); SELF.left := left; SELF.parameters := parameters;
  1840. END InitBracketDesignator;
  1841. PROCEDURE Clone(): Expression;
  1842. VAR copy: BracketDesignator;
  1843. BEGIN
  1844. NEW(copy, position, CloneDesignator(left), CloneExpressionList(parameters)); RETURN copy
  1845. END Clone;
  1846. PROCEDURE Accept*(v: Visitor);
  1847. VAR position: LONGINT;
  1848. BEGIN position := SELF.position; v.VisitBracketDesignator(SELF)
  1849. END Accept;
  1850. END BracketDesignator;
  1851. (*** second phase (after checker) designators ***)
  1852. (** symbol designator emerged from IdentifierDesignator or from Selector **)
  1853. SymbolDesignator* = OBJECT(Designator)
  1854. VAR
  1855. symbol-: Symbol;
  1856. PROCEDURE &InitSymbolDesignator(position: LONGINT; left: Designator; symbol: Symbol);
  1857. BEGIN
  1858. InitDesignator(position);
  1859. SELF.left := left;
  1860. SELF.symbol := symbol;
  1861. END InitSymbolDesignator;
  1862. PROCEDURE Accept*(v: Visitor);
  1863. VAR position: LONGINT;
  1864. BEGIN
  1865. position := SELF.position; v.VisitSymbolDesignator(SELF);
  1866. END Accept;
  1867. PROCEDURE Clone(): Expression;
  1868. VAR copy: SymbolDesignator;
  1869. BEGIN
  1870. NEW(copy, position, CloneDesignator(left), symbol); RETURN copy
  1871. END Clone;
  1872. PROCEDURE SetSymbol*(s: Symbol);
  1873. BEGIN SELF.symbol := s;
  1874. END SetSymbol;
  1875. PROCEDURE NeedsTrace* (): BOOLEAN;
  1876. BEGIN RETURN symbol.NeedsTrace() & ((left = NIL) OR (left.NeedsTrace()));
  1877. END NeedsTrace;
  1878. END SymbolDesignator;
  1879. (** <<left[parameters]>>
  1880. (ranged) indexer
  1881. **)
  1882. IndexDesignator* = OBJECT(Designator)
  1883. VAR
  1884. parameters-: ExpressionList;
  1885. hasRange-: BOOLEAN;
  1886. hasTensorRange-: BOOLEAN;
  1887. PROCEDURE &InitIndexDesignator(position: LONGINT; left: Designator);
  1888. BEGIN
  1889. InitDesignator(position);
  1890. SELF.left := left;
  1891. parameters := NewExpressionList();
  1892. hasRange := FALSE;
  1893. hasTensorRange := FALSE;
  1894. END InitIndexDesignator;
  1895. PROCEDURE HasRange*;
  1896. BEGIN hasRange := TRUE;
  1897. END HasRange;
  1898. PROCEDURE HasTensorRange*;
  1899. BEGIN hasTensorRange := TRUE;
  1900. END HasTensorRange;
  1901. PROCEDURE Clone(): Expression;
  1902. VAR copy: IndexDesignator;
  1903. BEGIN
  1904. NEW(copy, position, CloneDesignator(left));
  1905. parameters.Clone(copy.parameters);
  1906. copy.hasRange := hasRange; copy.hasTensorRange := hasTensorRange ; RETURN copy
  1907. END Clone;
  1908. PROCEDURE Accept*(v: Visitor);
  1909. VAR position: LONGINT;
  1910. BEGIN position := SELF.position; v.VisitIndexDesignator(SELF)
  1911. END Accept;
  1912. PROCEDURE NeedsTrace* (): BOOLEAN;
  1913. BEGIN RETURN type.NeedsTrace() & left.NeedsTrace(); (* for x[y]: if x is untraced, then also x[y] should be treated untraced *)
  1914. END NeedsTrace;
  1915. END IndexDesignator;
  1916. StatementDesignator* = OBJECT (Designator)
  1917. VAR
  1918. statement-: Statement;
  1919. result-: Expression;
  1920. PROCEDURE & InitStatementDesignator(position: LONGINT; s: Statement);
  1921. BEGIN
  1922. InitDesignator(position); statement := s; result := NIL;
  1923. END InitStatementDesignator;
  1924. PROCEDURE Clone(): Expression;
  1925. VAR copy: StatementDesignator;
  1926. BEGIN
  1927. NEW(copy, position, CloneStatement(statement)) ;
  1928. copy.result := CloneExpression(result);
  1929. RETURN copy
  1930. END Clone;
  1931. PROCEDURE SetResult*(r: Expression);
  1932. BEGIN result := r
  1933. END SetResult;
  1934. PROCEDURE Accept*(v: Visitor);
  1935. VAR position: LONGINT;
  1936. BEGIN position := SELF.position; v.VisitStatementDesignator(SELF)
  1937. END Accept;
  1938. END StatementDesignator;
  1939. (** <<left(parameters)>>
  1940. procedure call
  1941. **)
  1942. ProcedureCallDesignator*= OBJECT (Designator)
  1943. VAR parameters-: ExpressionList;
  1944. PROCEDURE & InitProcedureCallDesignator(position: LONGINT; left: Designator; parameters: ExpressionList);
  1945. BEGIN
  1946. InitDesignator(position); SELF.left := left; SELF.parameters := parameters;
  1947. END InitProcedureCallDesignator;
  1948. PROCEDURE Clone(): Expression;
  1949. VAR copy: ProcedureCallDesignator;
  1950. BEGIN
  1951. NEW(copy, position, CloneDesignator(left), CloneExpressionList(parameters)); RETURN copy
  1952. END Clone;
  1953. PROCEDURE Accept*(v: Visitor);
  1954. VAR position: LONGINT;
  1955. BEGIN position := SELF.position; v.VisitProcedureCallDesignator(SELF)
  1956. END Accept;
  1957. END ProcedureCallDesignator;
  1958. (** <<procedure(parameters)>>
  1959. builtin procedure call **)
  1960. BuiltinCallDesignator*= OBJECT (Designator) (*! should this be an extension of a procedure call designator ? *)
  1961. VAR
  1962. id-: LONGINT;
  1963. parameters-: ExpressionList;
  1964. builtin-: Builtin;
  1965. PROCEDURE & InitBuiltinCallDesignator(position: LONGINT; id: LONGINT; left: Designator; parameters: ExpressionList);
  1966. BEGIN
  1967. InitDesignator(position); SELF.parameters := parameters; SELF.id := id; SELF.left := left;
  1968. END InitBuiltinCallDesignator;
  1969. PROCEDURE Clone(): Expression;
  1970. VAR copy: BuiltinCallDesignator;
  1971. BEGIN
  1972. NEW(copy, position, id, CloneDesignator(left), CloneExpressionList(parameters)); RETURN copy
  1973. END Clone;
  1974. PROCEDURE Accept*(v: Visitor);
  1975. VAR position: LONGINT;
  1976. BEGIN position := SELF.position; v.VisitBuiltinCallDesignator(SELF)
  1977. END Accept;
  1978. END BuiltinCallDesignator;
  1979. (** <<left(type)>>
  1980. resolved parameter designator, designates a type guard
  1981. **)
  1982. TypeGuardDesignator* = OBJECT(Designator)
  1983. VAR
  1984. typeExpression-: Expression; (* for printing only *)
  1985. PROCEDURE &InitTypeGuardDesignator(position: LONGINT; left: Designator; type: Type);
  1986. BEGIN InitDesignator(position); SELF.left := left; SELF.type := type; typeExpression := NIL;
  1987. END InitTypeGuardDesignator;
  1988. PROCEDURE SetTypeExpression*(typeExpression: Expression);
  1989. BEGIN SELF.typeExpression := typeExpression
  1990. END SetTypeExpression;
  1991. PROCEDURE Clone(): Expression;
  1992. VAR copy: TypeGuardDesignator;
  1993. BEGIN
  1994. NEW(copy, position, CloneDesignator(left), type); RETURN copy
  1995. END Clone;
  1996. PROCEDURE Accept*(v: Visitor);
  1997. VAR position: LONGINT;
  1998. BEGIN position := SELF.position; v.VisitTypeGuardDesignator(SELF)
  1999. END Accept;
  2000. PROCEDURE NeedsTrace* (): BOOLEAN;
  2001. BEGIN RETURN left.NeedsTrace() & type.NeedsTrace(); (* for x(Y): if x is untraced, then x as Y should also be treated untraced *)
  2002. END NeedsTrace;
  2003. END TypeGuardDesignator;
  2004. (** <<left^>> resolved as dereference operation on pointer variable left **)
  2005. DereferenceDesignator*= OBJECT (Designator)
  2006. PROCEDURE &InitDereferenceDesignator(position: LONGINT; left: Designator);
  2007. BEGIN InitDesignator(position); SELF.left := left;
  2008. END InitDereferenceDesignator;
  2009. PROCEDURE Clone(): Expression;
  2010. VAR copy: DereferenceDesignator;
  2011. BEGIN
  2012. NEW(copy, position, CloneDesignator(left)); RETURN copy
  2013. END Clone;
  2014. PROCEDURE Accept*(v: Visitor);
  2015. VAR position: LONGINT;
  2016. BEGIN position := SELF.position; v.VisitDereferenceDesignator(SELF)
  2017. END Accept;
  2018. PROCEDURE NeedsTrace* (): BOOLEAN;
  2019. BEGIN RETURN left.NeedsTrace() & type.NeedsTrace(); (* for x^: if x is an untraced pointer, the content of x^ is also treated untraced *)
  2020. END NeedsTrace;
  2021. END DereferenceDesignator;
  2022. (** <<left^>> resolved as supercall operation on method left **)
  2023. SupercallDesignator*= OBJECT (Designator)
  2024. PROCEDURE &InitSupercallDesignator(position: LONGINT; left: Designator);
  2025. BEGIN InitDesignator(position); SELF.left := left;
  2026. END InitSupercallDesignator;
  2027. PROCEDURE Clone(): Expression;
  2028. VAR copy: SupercallDesignator;
  2029. BEGIN
  2030. NEW(copy, position, CloneDesignator(left)); RETURN copy
  2031. END Clone;
  2032. PROCEDURE Accept*(v: Visitor);
  2033. VAR position: LONGINT;
  2034. BEGIN position := SELF.position; v.VisitSupercallDesignator(SELF)
  2035. END Accept;
  2036. END SupercallDesignator;
  2037. (** <<SELF.x>> **)
  2038. SelfDesignator*= OBJECT (Designator)
  2039. PROCEDURE &InitSelfDesignator(position: LONGINT);
  2040. BEGIN InitDesignator(position);
  2041. END InitSelfDesignator;
  2042. PROCEDURE Clone(): Expression;
  2043. VAR copy: SelfDesignator;
  2044. BEGIN
  2045. NEW(copy, position); RETURN copy
  2046. END Clone;
  2047. PROCEDURE Accept*(v: Visitor);
  2048. VAR position: LONGINT;
  2049. BEGIN position := SELF.position; v.VisitSelfDesignator(SELF)
  2050. END Accept;
  2051. PROCEDURE NeedsTrace* (): BOOLEAN;
  2052. BEGIN RETURN type.NeedsTrace();
  2053. END NeedsTrace;
  2054. END SelfDesignator;
  2055. (** <<RESULT>> **)
  2056. ResultDesignator*= OBJECT (Designator)
  2057. PROCEDURE &InitResultDesignator(position: LONGINT);
  2058. BEGIN InitDesignator(position);
  2059. END InitResultDesignator;
  2060. PROCEDURE Clone(): Expression;
  2061. VAR copy: ResultDesignator;
  2062. BEGIN
  2063. NEW(copy, position); RETURN copy
  2064. END Clone;
  2065. PROCEDURE Accept*(v: Visitor);
  2066. VAR position: LONGINT;
  2067. BEGIN position := SELF.position; v.VisitResultDesignator(SELF)
  2068. END Accept;
  2069. END ResultDesignator;
  2070. (**** values ****)
  2071. Value* = OBJECT (Expression)
  2072. VAR fingerprint-: FingerPrint;
  2073. PROCEDURE &InitValue(position: LONGINT);
  2074. BEGIN SELF.position := position; resolved := SELF; InitFingerPrint(fingerprint);
  2075. END InitValue;
  2076. PROCEDURE SetFingerPrint*(CONST fp: FingerPrint);
  2077. BEGIN
  2078. SELF.fingerprint := fp
  2079. END SetFingerPrint;
  2080. PROCEDURE Accept*(v: Visitor);
  2081. VAR position: LONGINT;
  2082. BEGIN position := SELF.position; v.VisitValue(SELF)
  2083. END Accept;
  2084. PROCEDURE Equals*(v: Value):BOOLEAN;
  2085. BEGIN HALT(100); (* abstract *) RETURN FALSE; END Equals;
  2086. END Value;
  2087. (** <<value = TRUE , FALSE>> **)
  2088. BooleanValue* = OBJECT (Value)
  2089. VAR
  2090. value-: BOOLEAN;
  2091. PROCEDURE & InitBooleanValue(position: LONGINT; value: BOOLEAN);
  2092. BEGIN
  2093. InitValue(position); SELF.value := value;
  2094. END InitBooleanValue;
  2095. PROCEDURE SetValue*(value: BOOLEAN);
  2096. BEGIN SELF.value := value
  2097. END SetValue;
  2098. PROCEDURE Clone(): Expression;
  2099. VAR copy: BooleanValue;
  2100. BEGIN
  2101. NEW(copy, position, value); RETURN copy
  2102. END Clone;
  2103. PROCEDURE Accept*(v: Visitor);
  2104. VAR position: LONGINT;
  2105. BEGIN position := SELF.position; v.VisitBooleanValue(SELF)
  2106. END Accept;
  2107. PROCEDURE Equals*(v: Value):BOOLEAN;
  2108. BEGIN RETURN (v IS BooleanValue) & (v(BooleanValue).value = value); END Equals;
  2109. END BooleanValue;
  2110. (** <<value = 123456>> **)
  2111. IntegerValue* = OBJECT (Value)
  2112. VAR
  2113. hvalue-: HUGEINT;
  2114. value-: LONGINT;
  2115. PROCEDURE & InitIntegerValue(position: LONGINT; hvalue: HUGEINT);
  2116. BEGIN
  2117. InitValue(position); SELF.hvalue := hvalue; SELF.value := SHORT(hvalue);
  2118. END InitIntegerValue;
  2119. PROCEDURE SetValue*(hvalue: HUGEINT);
  2120. BEGIN SELF.hvalue := hvalue; SELF.value := SHORT(hvalue);
  2121. END SetValue;
  2122. PROCEDURE Clone(): Expression;
  2123. VAR copy: IntegerValue;
  2124. BEGIN
  2125. NEW(copy, position, hvalue); RETURN copy
  2126. END Clone;
  2127. PROCEDURE Accept*(v: Visitor);
  2128. VAR position: LONGINT;
  2129. BEGIN position := SELF.position; v.VisitIntegerValue(SELF)
  2130. END Accept;
  2131. PROCEDURE Equals*(v: Value):BOOLEAN;
  2132. BEGIN RETURN (v IS IntegerValue) & (v(IntegerValue).value = value); END Equals;
  2133. END IntegerValue;
  2134. (** <<value = 'c', 65X>> **)
  2135. CharacterValue*= OBJECT(Value)
  2136. VAR
  2137. value-: CHAR; (* potential for extension to support CHAR16 and CHAR32 *)
  2138. PROCEDURE & InitCharacterValue(position:LONGINT; value: CHAR);
  2139. BEGIN
  2140. InitValue(position); SELF.value := value;
  2141. END InitCharacterValue;
  2142. PROCEDURE SetValue*(value: CHAR);
  2143. BEGIN SELF.value := value
  2144. END SetValue;
  2145. PROCEDURE Clone(): Expression;
  2146. VAR copy: CharacterValue;
  2147. BEGIN
  2148. NEW(copy, position, value); RETURN copy
  2149. END Clone;
  2150. PROCEDURE Accept*(v: Visitor);
  2151. VAR position: LONGINT;
  2152. BEGIN position := SELF.position; v.VisitCharacterValue(SELF)
  2153. END Accept;
  2154. PROCEDURE Equals*(v: Value):BOOLEAN;
  2155. BEGIN RETURN (v IS CharacterValue) & (v(CharacterValue).value = value); END Equals;
  2156. END CharacterValue;
  2157. SetValueType = SetValue;
  2158. (** <<value = {1,2,3..5}>> **)
  2159. SetValue* = OBJECT (Value)
  2160. VAR
  2161. value-: SET;
  2162. PROCEDURE & InitSetValue(position: LONGINT; value: SET);
  2163. BEGIN
  2164. InitValue(position); SELF.value := value;
  2165. END InitSetValue;
  2166. PROCEDURE SetValue*(value: SET);
  2167. BEGIN SELF.value := value
  2168. END SetValue;
  2169. PROCEDURE Clone(): Expression;
  2170. VAR copy: SetValueType;
  2171. BEGIN
  2172. NEW(copy, position, value); RETURN copy
  2173. END Clone;
  2174. PROCEDURE Accept*(v: Visitor);
  2175. VAR position: LONGINT;
  2176. BEGIN position := SELF.position; v.VisitSetValue(SELF)
  2177. END Accept;
  2178. END SetValue;
  2179. (** << [elements] >> **)
  2180. MathArrayValue* = OBJECT (Value)
  2181. VAR array-: MathArrayExpression; (* an element of the form from .. to is represented as a RangeExpression *)
  2182. PROCEDURE & InitMathArrayValue(position: LONGINT);
  2183. BEGIN
  2184. InitValue(position);
  2185. array := NIL;
  2186. END InitMathArrayValue;
  2187. PROCEDURE SetArray*(array: MathArrayExpression);
  2188. BEGIN SELF.array := array
  2189. END SetArray;
  2190. PROCEDURE Clone(): Expression;
  2191. VAR copy: MathArrayValue;
  2192. BEGIN
  2193. NEW(copy, position);
  2194. IF array # NIL THEN copy.array := array.Clone()(MathArrayExpression) END;
  2195. RETURN copy
  2196. END Clone;
  2197. PROCEDURE Accept*(v: Visitor);
  2198. VAR position: LONGINT;
  2199. BEGIN position := SELF.position; v.VisitMathArrayValue(SELF)
  2200. END Accept;
  2201. END MathArrayValue;
  2202. (** <<value = 1.2345E01>> **)
  2203. RealValue* = OBJECT (Value)
  2204. VAR
  2205. value-: LONGREAL;
  2206. subtype-: LONGINT; (* accuracy information: REAL vs. LONGREAL *)
  2207. PROCEDURE & InitRealValue(position: LONGINT; value: LONGREAL);
  2208. BEGIN
  2209. InitValue(position); SELF.value := value; SELF.subtype := 0;
  2210. END InitRealValue;
  2211. PROCEDURE SetValue*(value: LONGREAL);
  2212. BEGIN SELF.value := value
  2213. END SetValue;
  2214. PROCEDURE SetSubtype*(subtype: LONGINT);
  2215. BEGIN SELF.subtype := subtype;
  2216. END SetSubtype;
  2217. PROCEDURE Clone(): Expression;
  2218. VAR copy: RealValue;
  2219. BEGIN
  2220. NEW(copy, position, value); RETURN copy
  2221. END Clone;
  2222. PROCEDURE Accept*(v: Visitor);
  2223. VAR position: LONGINT;
  2224. BEGIN position := SELF.position; v.VisitRealValue(SELF)
  2225. END Accept;
  2226. PROCEDURE Equals*(v: Value):BOOLEAN;
  2227. BEGIN RETURN (v IS RealValue) & (v(RealValue).value = value); END Equals;
  2228. END RealValue;
  2229. ComplexValue* = OBJECT (Value)
  2230. VAR
  2231. realValue-, imagValue-: LONGREAL;
  2232. subtype-: LONGINT; (* accuracy information of components: REAL vs. LONGREAL *)
  2233. PROCEDURE & InitComplexValue(position: LONGINT; realValue, imagValue: LONGREAL);
  2234. BEGIN
  2235. InitValue(position); SELF.realValue := realValue; SELF.imagValue := imagValue; SELF.subtype := 0;
  2236. END InitComplexValue;
  2237. PROCEDURE SetValue*(realValue, imagValue: LONGREAL);
  2238. BEGIN SELF.realValue := realValue; SELF.imagValue := imagValue;
  2239. END SetValue;
  2240. PROCEDURE UpdateSubtype*;
  2241. BEGIN
  2242. ASSERT((type # NIL) & (type.resolved # NIL) & (type.resolved IS ComplexType) & (type.resolved(ComplexType).componentType IS FloatType));
  2243. CASE type.resolved(ComplexType).componentType(FloatType).sizeInBits OF
  2244. | 32: subtype := Scanner.Real
  2245. | 64: subtype := Scanner.Longreal
  2246. END
  2247. END UpdateSubtype;
  2248. PROCEDURE SetSubtype*(subtype: LONGINT);
  2249. BEGIN SELF.subtype := subtype;
  2250. END SetSubtype;
  2251. PROCEDURE Clone(): Expression;
  2252. VAR copy: ComplexValue;
  2253. BEGIN
  2254. NEW(copy, position, realValue, imagValue); copy.subtype := subtype; RETURN copy
  2255. END Clone;
  2256. PROCEDURE Accept*(v: Visitor);
  2257. VAR position: LONGINT;
  2258. BEGIN position := SELF.position; v.VisitComplexValue(SELF)
  2259. END Accept;
  2260. PROCEDURE Equals*(v: Value):BOOLEAN;
  2261. BEGIN RETURN (v IS ComplexValue) & (v(ComplexValue).realValue = realValue) & (v(ComplexValue).imagValue = imagValue);
  2262. (* TODO: append this?
  2263. OR (v IS RealValue) & (v(RealValue).value = realValue) & (imagValue := 0)
  2264. *)
  2265. END Equals;
  2266. END ComplexValue;
  2267. (** <<value = "string">> **)
  2268. StringValue* = OBJECT (Value)
  2269. VAR
  2270. value-: String;
  2271. length-: LONGINT;
  2272. PROCEDURE & InitStringValue(position: LONGINT; value: String);
  2273. BEGIN
  2274. InitValue(position); SELF.value := value;
  2275. length := 0;
  2276. WHILE (length<LEN(value)) & (value[length] # 0X) DO
  2277. INC(length);
  2278. END;
  2279. IF length < LEN(value) THEN INC(length) END
  2280. END InitStringValue;
  2281. PROCEDURE SetValue*(CONST value: String);
  2282. BEGIN SELF.value := value
  2283. END SetValue;
  2284. PROCEDURE Append*(CONST value: String);
  2285. VAR new: String; len: LONGINT;
  2286. BEGIN
  2287. len := Strings.Length(SELF.value^) + Strings.Length(value^) + 1;
  2288. IF LEN(SELF.value) < len THEN
  2289. NEW(new, len);
  2290. COPY(SELF.value^, new^);
  2291. SELF.value := new
  2292. END;
  2293. Strings.Append(SELF.value^, value^);
  2294. length := len
  2295. END Append;
  2296. PROCEDURE AppendChar*(CONST ch: CHAR);
  2297. VAR v: String;
  2298. BEGIN
  2299. NEW(v,2); v[0] := ch;
  2300. Append(v);
  2301. END AppendChar;
  2302. PROCEDURE Clone(): Expression;
  2303. VAR copy: StringValue;
  2304. BEGIN
  2305. NEW(copy, position, value); RETURN copy
  2306. END Clone;
  2307. PROCEDURE Accept*(v: Visitor);
  2308. VAR position: LONGINT;
  2309. BEGIN position := SELF.position; v.VisitStringValue(SELF)
  2310. END Accept;
  2311. PROCEDURE Equals*(v: Value):BOOLEAN;
  2312. BEGIN RETURN (v IS StringValue) & (v(StringValue).value = value); END Equals;
  2313. END StringValue;
  2314. (** <<value = NIL>> **)
  2315. NilValue* = OBJECT (Value)
  2316. PROCEDURE Accept*(v: Visitor);
  2317. VAR position: LONGINT;
  2318. BEGIN position := SELF.position; v.VisitNilValue(SELF)
  2319. END Accept;
  2320. PROCEDURE Clone(): Expression;
  2321. VAR copy: NilValue;
  2322. BEGIN
  2323. NEW(copy, position); RETURN copy
  2324. END Clone;
  2325. PROCEDURE Equals*(v: Value):BOOLEAN;
  2326. BEGIN RETURN (v IS NilValue); END Equals;
  2327. END NilValue;
  2328. (** <<value = enum.x >> **)
  2329. EnumerationValue* = OBJECT (Value)
  2330. VAR
  2331. value-: LONGINT;
  2332. PROCEDURE & InitEnumerationValue(position: LONGINT; value: LONGINT);
  2333. BEGIN
  2334. InitValue(position); SELF.value := value;
  2335. END InitEnumerationValue;
  2336. PROCEDURE SetValue*(value: LONGINT);
  2337. BEGIN SELF.value := value
  2338. END SetValue;
  2339. PROCEDURE Clone(): Expression;
  2340. VAR copy: EnumerationValue;
  2341. BEGIN
  2342. NEW(copy, position, value); RETURN copy
  2343. END Clone;
  2344. PROCEDURE Accept*(v: Visitor);
  2345. VAR position: LONGINT;
  2346. BEGIN position := SELF.position; v.VisitEnumerationValue(SELF)
  2347. END Accept;
  2348. PROCEDURE Equals*(v: Value):BOOLEAN;
  2349. BEGIN RETURN (v IS EnumerationValue) & (v(EnumerationValue).value = value); END Equals;
  2350. END EnumerationValue;
  2351. (**** symbols ****)
  2352. Symbol*= OBJECT
  2353. VAR
  2354. nextSymbol-: Symbol;
  2355. name-: Identifier; (* constant / variable / parameter / type name / module name *)
  2356. externalName-: Scanner.StringType; (* variable / procedure *)
  2357. access-: SET; (* access flags (exported, readonly etc.) *)
  2358. type-: Type; (* type of constant / variable / parameter / procedure return type *)
  2359. scope-:Scope; (* container of symbol *)
  2360. offsetInBits-: LONGINT; (* offset in stack or heap, in bits *)
  2361. used-, written-: BOOLEAN;
  2362. fixed-: BOOLEAN;
  2363. alignment-: LONGINT;
  2364. position-: LONGINT; state-: SET;
  2365. fingerprint-: FingerPrint;
  2366. comment-: Comment;
  2367. PROCEDURE & InitSymbol(position: LONGINT; name:Identifier);
  2368. BEGIN
  2369. SELF.position := position; state := Undefined;
  2370. nextSymbol := NIL;
  2371. SELF.name := name;
  2372. externalName := NIL;
  2373. scope:= NIL;
  2374. type := NIL;
  2375. access := Internal;
  2376. state := Undefined;
  2377. offsetInBits := MIN(LONGINT);
  2378. alignment := 0; (* take default *)
  2379. fixed := FALSE;
  2380. used := FALSE; written := FALSE;
  2381. InitFingerPrint(fingerprint);
  2382. comment := NIL;
  2383. END InitSymbol;
  2384. PROCEDURE SetAlignment*(fix: BOOLEAN; align: LONGINT);
  2385. BEGIN SELF.alignment := align; fixed := fix;
  2386. END SetAlignment;
  2387. PROCEDURE SetFingerPrint*(CONST fp: FingerPrint);
  2388. BEGIN
  2389. SELF.fingerprint := fp
  2390. END SetFingerPrint;
  2391. PROCEDURE SetState*(state: LONGINT);
  2392. BEGIN INCL(SELF.state,state);
  2393. END SetState;
  2394. PROCEDURE SetScope*(scope: Scope);
  2395. BEGIN SELF.scope := scope
  2396. END SetScope;
  2397. PROCEDURE SetType*(type: Type);
  2398. BEGIN
  2399. SELF.type := type;
  2400. END SetType;
  2401. PROCEDURE SetNext*(symbol: Symbol);
  2402. BEGIN SELF.nextSymbol := symbol; END SetNext;
  2403. PROCEDURE SetAccess*(access: SET);
  2404. BEGIN
  2405. (* consistency guarantee *)
  2406. IF PublicWrite IN access THEN ASSERT(ProtectedWrite IN access) END;
  2407. IF ProtectedWrite IN access THEN ASSERT(InternalWrite IN access) END;
  2408. IF PublicRead IN access THEN ASSERT(ProtectedRead IN access) END;
  2409. IF ProtectedRead IN access THEN ASSERT(InternalRead IN access)END;
  2410. SELF.access := access;
  2411. END SetAccess;
  2412. PROCEDURE SetOffset*(ofs: LONGINT);
  2413. BEGIN offsetInBits := ofs
  2414. END SetOffset;
  2415. PROCEDURE MarkUsed*;
  2416. BEGIN used := TRUE
  2417. END MarkUsed;
  2418. PROCEDURE MarkWritten*;
  2419. BEGIN written := TRUE
  2420. END MarkWritten;
  2421. PROCEDURE GetName*(VAR str: ARRAY OF CHAR);
  2422. BEGIN Basic.GetString(name, str);
  2423. END GetName;
  2424. PROCEDURE SetComment*(comment: Comment);
  2425. BEGIN SELF.comment := comment
  2426. END SetComment;
  2427. PROCEDURE Accept*(v: Visitor);
  2428. VAR position: LONGINT;
  2429. BEGIN position := SELF.position; v.VisitSymbol(SELF)
  2430. END Accept;
  2431. PROCEDURE SetExternalName*(name: Scanner.StringType);
  2432. BEGIN externalName := name;
  2433. END SetExternalName;
  2434. PROCEDURE NeedsTrace* (): BOOLEAN;
  2435. BEGIN RETURN FALSE;
  2436. END NeedsTrace;
  2437. END Symbol;
  2438. (**
  2439. <<TYPE name = declaredType>>
  2440. TypeDeclaration symbol represents a type declaration of the form TYPE name = declaredType.
  2441. Note that the declared type is not stored in the symbol's type field but rather in the declaredType field.
  2442. The type of a type declaration is set to "typeDeclarationType" in the semantic checker
  2443. **)
  2444. TypeDeclaration*= OBJECT(Symbol)
  2445. VAR
  2446. nextTypeDeclaration-: TypeDeclaration;
  2447. declaredType-: Type;
  2448. PROCEDURE &InitTypeDeclaration(position: LONGINT; name: Identifier);
  2449. BEGIN
  2450. InitSymbol(position,name);
  2451. nextTypeDeclaration := NIL;
  2452. declaredType := NIL;
  2453. type := typeDeclarationType;
  2454. END InitTypeDeclaration;
  2455. PROCEDURE SetDeclaredType*(type: Type);
  2456. BEGIN
  2457. declaredType := type;
  2458. IF ~(type IS BasicType) THEN
  2459. type.typeDeclaration := SELF;
  2460. END;
  2461. END SetDeclaredType;
  2462. PROCEDURE SetType*(type: Type);
  2463. BEGIN
  2464. ASSERT(type = typeDeclarationType);
  2465. END SetType;
  2466. PROCEDURE Accept*(v: Visitor);
  2467. VAR position: LONGINT;
  2468. BEGIN position := SELF.position; v.VisitTypeDeclaration(SELF)
  2469. END Accept;
  2470. END TypeDeclaration;
  2471. (** <<CONST name = value >>
  2472. Constant declaration symbol. Represents a constant being defined in the form CONST name = value
  2473. The type of the constant is stored in the type field and is resolved by the semantic checker.
  2474. **)
  2475. Constant* = OBJECT (Symbol)
  2476. VAR
  2477. value-: Expression;
  2478. nextConstant-: Constant;
  2479. PROCEDURE & InitConstant( position: LONGINT; name: Identifier );
  2480. BEGIN
  2481. InitSymbol(position,name);
  2482. value := NIL;
  2483. nextConstant := NIL;
  2484. END InitConstant;
  2485. PROCEDURE SetValue*( value: Expression );
  2486. BEGIN
  2487. SELF.value := value;
  2488. END SetValue;
  2489. PROCEDURE Accept*(v: Visitor);
  2490. VAR position: LONGINT;
  2491. BEGIN position := SELF.position; v.VisitConstant(SELF)
  2492. END Accept;
  2493. END Constant;
  2494. (** <<VAR name: type >>
  2495. Variable declaration symbol. Represents a variable defined in the form VAR name: Type.
  2496. The type of the variable is stored in the symbol's type field and is resolved by the semantic checker.
  2497. **)
  2498. Variable* = OBJECT (Symbol)
  2499. VAR
  2500. nextVariable-: Variable;
  2501. untraced-: BOOLEAN;
  2502. useRegister-: BOOLEAN; registerNumber-: LONGINT;
  2503. modifiers-: Modifier;
  2504. initializer-: Expression;
  2505. usedAsReference-: BOOLEAN;
  2506. PROCEDURE & InitVariable*( position: LONGINT; name: Identifier);
  2507. BEGIN
  2508. InitSymbol(position,name);
  2509. nextVariable := NIL;
  2510. modifiers := NIL;
  2511. untraced := FALSE;
  2512. modifiers := NIL;
  2513. useRegister := FALSE;
  2514. registerNumber := -1;
  2515. usedAsReference := FALSE;
  2516. initializer := NIL;
  2517. END InitVariable;
  2518. PROCEDURE UsedAsReference*;
  2519. BEGIN
  2520. usedAsReference := TRUE
  2521. END UsedAsReference;
  2522. PROCEDURE SetUntraced*(u: BOOLEAN);
  2523. BEGIN untraced := u
  2524. END SetUntraced;
  2525. PROCEDURE SetUseRegister*(u: BOOLEAN);
  2526. BEGIN
  2527. useRegister := u
  2528. END SetUseRegister;
  2529. PROCEDURE SetRegisterNumber*(reg: LONGINT);
  2530. BEGIN
  2531. registerNumber := reg
  2532. END SetRegisterNumber;
  2533. PROCEDURE SetModifiers*(flag: Modifier);
  2534. BEGIN SELF.modifiers := flag;
  2535. END SetModifiers;
  2536. PROCEDURE SetInitializer*(initializer: Expression);
  2537. BEGIN SELF.initializer := initializer;
  2538. END SetInitializer;
  2539. PROCEDURE Accept*(v: Visitor);
  2540. VAR position: LONGINT;
  2541. BEGIN position := SELF.position; v.VisitVariable(SELF)
  2542. END Accept;
  2543. PROCEDURE NeedsTrace* (): BOOLEAN;
  2544. BEGIN RETURN ~untraced & (externalName = NIL) & type.NeedsTrace ();
  2545. END NeedsTrace;
  2546. END Variable;
  2547. (** << [VAR | CONST] name: type >>
  2548. Parameter declaration symbol. Represents a parameter in the form [VAR | CONST] name: Type.
  2549. The parameter's type is stored in the symbol's type field and is resolved by the semantic checker.
  2550. **)
  2551. Parameter* = OBJECT (Symbol)
  2552. VAR
  2553. nextParameter-, prevParameter-: Parameter;
  2554. modifiers-: Modifier;
  2555. defaultValue-: Expression;
  2556. kind-: LONGINT; (* ValueParameter, ConstParameter, VarParameter *)
  2557. ownerType-: Type;
  2558. untraced-: BOOLEAN;
  2559. movable-: BOOLEAN;
  2560. PROCEDURE & InitParameter( position: LONGINT; ownerType: Type ; name: Identifier; kind: LONGINT);
  2561. BEGIN
  2562. InitSymbol( position, name );
  2563. SELF.kind := kind;
  2564. IF kind = ConstParameter THEN access := access END;
  2565. nextParameter := NIL;
  2566. SELF.ownerType := ownerType;
  2567. modifiers := NIL;
  2568. untraced := FALSE;
  2569. defaultValue := NIL;
  2570. movable := FALSE;
  2571. END InitParameter;
  2572. PROCEDURE SetModifiers*(flag: Modifier);
  2573. BEGIN SELF.modifiers := flag;
  2574. END SetModifiers;
  2575. PROCEDURE SetUntraced*(untraced: BOOLEAN);
  2576. BEGIN SELF.untraced := untraced
  2577. END SetUntraced;
  2578. PROCEDURE SetMoveable*(movable: BOOLEAN);
  2579. BEGIN SELF.movable := movable
  2580. END SetMoveable;
  2581. PROCEDURE SetDefaultValue*(e: Expression);
  2582. BEGIN defaultValue := e
  2583. END SetDefaultValue;
  2584. PROCEDURE Accept*(v: Visitor);
  2585. VAR position: LONGINT;
  2586. BEGIN position := SELF.position; v.VisitParameter(SELF)
  2587. END Accept;
  2588. PROCEDURE SetKind*(kind: LONGINT);
  2589. BEGIN SELF.kind := kind; END SetKind;
  2590. PROCEDURE NeedsTrace* (): BOOLEAN;
  2591. BEGIN RETURN ~untraced & type.NeedsTrace ();
  2592. END NeedsTrace;
  2593. END Parameter;
  2594. Property* = OBJECT (Variable)
  2595. VAR
  2596. nextProperty-, prevProperty-: Property;
  2597. value-: Expression;
  2598. PROCEDURE & InitProperty(position: LONGINT; name: Identifier);
  2599. BEGIN
  2600. InitSymbol( position, name );
  2601. END InitProperty;
  2602. PROCEDURE SetValue*(e: Expression);
  2603. BEGIN value := e
  2604. END SetValue;
  2605. PROCEDURE Accept*(v: Visitor);
  2606. VAR position: LONGINT;
  2607. BEGIN position := SELF.position; v.VisitProperty(SELF)
  2608. END Accept;
  2609. END Property;
  2610. (** Procedure declaration symbol. Represents a procedure being defined in the form PROCEDURE name(parameters): returnType;
  2611. Note that the type of a procedure is a ProcedureType (and not the return type of the procedure).
  2612. Parameters, local variables, constants and type declarations are stored in the procedureScope field.
  2613. **)
  2614. Procedure* = OBJECT (Symbol)
  2615. VAR
  2616. nextProcedure-: Procedure;
  2617. procedureScope- : ProcedureScope;
  2618. super-: Procedure;
  2619. level-, methodNumber-: LONGINT;
  2620. isBodyProcedure-, isConstructor-,isFinalizer-,isInline-,isOberonInline-, isEntry-, isExit-,isFinal-,isAbstract-,isOverwritten-: BOOLEAN;
  2621. PROCEDURE & InitProcedure( position: LONGINT; name: Identifier; scope: ProcedureScope);
  2622. BEGIN
  2623. InitSymbol(position,name);
  2624. nextProcedure := NIL;
  2625. procedureScope := scope;
  2626. ASSERT(scope.ownerProcedure = NIL); (* cannot register twice ! *)
  2627. scope.ownerProcedure := SELF;
  2628. super := NIL;
  2629. level := 0;
  2630. methodNumber := -1;
  2631. isBodyProcedure := FALSE;
  2632. isConstructor := FALSE;
  2633. isFinalizer := FALSE;
  2634. isInline := FALSE;
  2635. isOberonInline := FALSE;
  2636. isEntry := FALSE;
  2637. isExit := FALSE;
  2638. isFinal := FALSE;
  2639. isAbstract := FALSE;
  2640. isOverwritten := FALSE;
  2641. END InitProcedure;
  2642. PROCEDURE SetSuper*(super: Procedure);
  2643. BEGIN
  2644. SELF.super := super
  2645. END SetSuper;
  2646. PROCEDURE SetBodyProcedure*(isBodyProcedure: BOOLEAN);
  2647. BEGIN SELF.isBodyProcedure := isBodyProcedure;
  2648. END SetBodyProcedure;
  2649. PROCEDURE SetConstructor*(isConstructor: BOOLEAN);
  2650. BEGIN SELF.isConstructor := isConstructor
  2651. END SetConstructor;
  2652. PROCEDURE SetFinalizer*(isFinalizer: BOOLEAN);
  2653. BEGIN SELF.isFinalizer := isFinalizer
  2654. END SetFinalizer;
  2655. PROCEDURE SetInline*(isInline: BOOLEAN);
  2656. BEGIN SELF.isInline := isInline
  2657. END SetInline;
  2658. PROCEDURE SetOberonInline*(isInline: BOOLEAN);
  2659. BEGIN SELF.isOberonInline := isInline
  2660. END SetOberonInline;
  2661. PROCEDURE SetEntry*(entry: BOOLEAN);
  2662. BEGIN SELF.isEntry := entry
  2663. END SetEntry;
  2664. PROCEDURE SetExit*(exit: BOOLEAN);
  2665. BEGIN SELF.isExit := exit
  2666. END SetExit;
  2667. PROCEDURE SetFinal*(final: BOOLEAN);
  2668. BEGIN SELF.isFinal := final
  2669. END SetFinal;
  2670. PROCEDURE SetOverwritten*(locallyOverwritten: BOOLEAN);
  2671. BEGIN SELF.isOverwritten := locallyOverwritten
  2672. END SetOverwritten;
  2673. PROCEDURE SetAbstract*(abstract: BOOLEAN);
  2674. BEGIN SELF.isAbstract := abstract
  2675. END SetAbstract;
  2676. PROCEDURE SetLevel*(level: LONGINT);
  2677. BEGIN SELF.level := level
  2678. END SetLevel;
  2679. PROCEDURE SetMethodNumber*(methodNumber: LONGINT);
  2680. BEGIN SELF.methodNumber := methodNumber
  2681. END SetMethodNumber;
  2682. PROCEDURE Accept*(v: Visitor);
  2683. VAR position: LONGINT;
  2684. BEGIN position := SELF.position; v.VisitProcedure(SELF)
  2685. END Accept;
  2686. END Procedure;
  2687. (** Builtin symbol stands for a builtin procedure. Is resolved by the semantic checker. **)
  2688. Builtin* = OBJECT (Symbol)
  2689. VAR
  2690. nextBuiltin-: Builtin;
  2691. id-: LONGINT;
  2692. PROCEDURE & InitBuiltin(position: LONGINT; name:Identifier; id: LONGINT);
  2693. BEGIN
  2694. InitSymbol(position,name); SELF.id := id;
  2695. END InitBuiltin;
  2696. PROCEDURE Accept*(v: Visitor);
  2697. VAR position: LONGINT;
  2698. BEGIN position := SELF.position; v.VisitBuiltin(SELF)
  2699. END Accept;
  2700. END Builtin;
  2701. CustomBuiltin*=OBJECT (Builtin)
  2702. VAR
  2703. subType-: SHORTINT;
  2704. PROCEDURE & InitCustomBuiltin(position: LONGINT; name: Identifier; id: LONGINT; subType: SHORTINT);
  2705. BEGIN
  2706. InitBuiltin(position,name,id);
  2707. SELF.subType := subType;
  2708. END InitCustomBuiltin;
  2709. (* TODO: check if this is correct *)
  2710. PROCEDURE CompatibleTo*(otherType: Type): BOOLEAN;
  2711. BEGIN RETURN FALSE
  2712. END CompatibleTo;
  2713. END CustomBuiltin;
  2714. Operator* = OBJECT (Procedure)
  2715. VAR
  2716. nextOperator-: Operator;
  2717. isDynamic-: BOOLEAN; (* nopov *)
  2718. PROCEDURE & InitOperator(position: LONGINT; name: Identifier; scope: ProcedureScope);
  2719. BEGIN
  2720. InitProcedure(position,name,scope);
  2721. nextOperator := NIL;
  2722. isDynamic := FALSE
  2723. END InitOperator;
  2724. (* nopov *)
  2725. PROCEDURE SetDynamic*(isDynamic: BOOLEAN);
  2726. BEGIN SELF.isDynamic := isDynamic
  2727. END SetDynamic;
  2728. PROCEDURE Accept*(v: Visitor);
  2729. VAR position: LONGINT;
  2730. BEGIN position := SELF.position; v.VisitOperator(SELF)
  2731. END Accept;
  2732. END Operator;
  2733. Import* = OBJECT (Symbol)
  2734. VAR
  2735. nextImport-: Import;
  2736. module-: Module;
  2737. moduleName-: Identifier;
  2738. context-: Identifier;
  2739. direct-: BOOLEAN; (* direct import *)
  2740. PROCEDURE & InitImport( position: LONGINT; name, moduleName: Identifier; direct: BOOLEAN );
  2741. BEGIN
  2742. InitSymbol(position,name);
  2743. SELF.direct := direct;
  2744. module := NIL;
  2745. context := invalidIdentifier;
  2746. SELF.moduleName := moduleName;
  2747. type := importType;
  2748. END InitImport;
  2749. PROCEDURE SetType*(type: Type);
  2750. BEGIN
  2751. ASSERT(type = importType);
  2752. END SetType;
  2753. PROCEDURE SetModule*(module: Module);
  2754. BEGIN
  2755. SELF.module := module;
  2756. END SetModule;
  2757. PROCEDURE SetDirect*(d: BOOLEAN);
  2758. BEGIN
  2759. direct := d
  2760. END SetDirect;
  2761. PROCEDURE SetModuleName*(moduleName: Identifier);
  2762. BEGIN SELF.moduleName := moduleName
  2763. END SetModuleName;
  2764. PROCEDURE SetContext*(context: Identifier);
  2765. BEGIN
  2766. SELF.context := context
  2767. END SetContext;
  2768. PROCEDURE Accept*(v: Visitor);
  2769. VAR position: LONGINT;
  2770. BEGIN position := SELF.position; v.VisitImport(SELF)
  2771. END Accept;
  2772. END Import;
  2773. StatementSequence* = OBJECT
  2774. VAR
  2775. list: Basic.List;
  2776. PROCEDURE & InitList;
  2777. BEGIN NEW( list,32 );
  2778. END InitList;
  2779. PROCEDURE Length*( ): LONGINT;
  2780. BEGIN RETURN list.Length();
  2781. END Length;
  2782. PROCEDURE AddStatement*( statement: Statement);
  2783. BEGIN list.Add( statement );
  2784. END AddStatement;
  2785. PROCEDURE PrependStatement*( statement: Statement);
  2786. BEGIN list.Prepend( statement );
  2787. END PrependStatement;
  2788. PROCEDURE HasStatement*( statement: Statement):BOOLEAN;
  2789. BEGIN RETURN list.Contains(statement);
  2790. END HasStatement;
  2791. PROCEDURE GetStatement*( index: LONGINT ): Statement;
  2792. VAR p: ANY;
  2793. BEGIN p := list.Get( index ); RETURN p( Statement );
  2794. END GetStatement;
  2795. PROCEDURE SetStatement*(index: LONGINT; statement: Statement);
  2796. BEGIN
  2797. list.Set(index,statement);
  2798. END SetStatement;
  2799. PROCEDURE RemoveStatement*(statement: Statement);
  2800. BEGIN
  2801. list.Remove(statement);
  2802. END RemoveStatement;
  2803. PROCEDURE InsertBefore*(search, new: Statement);
  2804. BEGIN
  2805. list.Insert(list.IndexOf(search), new);
  2806. END InsertBefore;
  2807. PROCEDURE Clone(VAR copy: StatementSequence);
  2808. VAR i: LONGINT;
  2809. BEGIN
  2810. IF copy = NIL THEN NEW(copy) END;
  2811. FOR i := 0 TO Length()-1 DO
  2812. copy.AddStatement(CloneStatement(GetStatement(i)))
  2813. END;
  2814. END Clone;
  2815. END StatementSequence;
  2816. (**** statements ****)
  2817. Statement*= OBJECT
  2818. VAR outer-: Statement;
  2819. position-: LONGINT;
  2820. isUnreachable-: BOOLEAN;
  2821. comment-: Comment;
  2822. PROCEDURE & InitStatement*(position: LONGINT; outer: Statement);
  2823. BEGIN
  2824. SELF.position := position;
  2825. SELF.outer := outer;
  2826. isUnreachable := FALSE;
  2827. comment := NIL;
  2828. END InitStatement;
  2829. PROCEDURE SetOuter*(o: Statement);
  2830. BEGIN outer := o
  2831. END SetOuter;
  2832. PROCEDURE SetUnreachable*(unreachable: BOOLEAN);
  2833. BEGIN isUnreachable := unreachable
  2834. END SetUnreachable;
  2835. PROCEDURE Accept*(v: Visitor);
  2836. VAR position: LONGINT;
  2837. BEGIN position := SELF.position; v.VisitStatement(SELF)
  2838. END Accept;
  2839. PROCEDURE SetComment*(comment: Comment);
  2840. BEGIN SELF.comment := comment
  2841. END SetComment;
  2842. PROCEDURE Clone(): Statement;
  2843. BEGIN
  2844. HALT(200) (* abstract *)
  2845. END Clone;
  2846. END Statement;
  2847. (** << call(...) >> **)
  2848. ProcedureCallStatement*= OBJECT(Statement)
  2849. VAR call-: Designator;
  2850. PROCEDURE & InitProcedureCallStatement(position: LONGINT; call: Designator; outer: Statement);
  2851. BEGIN InitStatement(position,outer); SELF.call := call;
  2852. END InitProcedureCallStatement;
  2853. PROCEDURE SetCall*(call: Designator);
  2854. BEGIN SELF.call := call;
  2855. END SetCall;
  2856. PROCEDURE Clone(): Statement;
  2857. VAR copy: ProcedureCallStatement;
  2858. BEGIN
  2859. NEW(copy, position, CloneDesignator(call), outer);
  2860. RETURN copy
  2861. END Clone;
  2862. PROCEDURE Accept*(v: Visitor);
  2863. VAR position: LONGINT;
  2864. BEGIN position := SELF.position; v.VisitProcedureCallStatement(SELF)
  2865. END Accept;
  2866. END ProcedureCallStatement;
  2867. (** << left := right >> **)
  2868. Assignment* = OBJECT (Statement)
  2869. VAR left-: Designator; right-: Expression;
  2870. PROCEDURE & InitAssignment*( position: LONGINT; left: Designator; right: Expression; outer: Statement );
  2871. BEGIN
  2872. InitStatement( position,outer ); SELF.left := left; SELF.right := right;
  2873. END InitAssignment;
  2874. PROCEDURE SetLeft*(left: Designator);
  2875. BEGIN SELF.left := left
  2876. END SetLeft;
  2877. PROCEDURE SetRight*(right: Expression);
  2878. BEGIN SELF.right := right
  2879. END SetRight;
  2880. PROCEDURE Clone(): Statement;
  2881. VAR copy: Assignment;
  2882. BEGIN
  2883. NEW(copy, position, CloneDesignator(left), CloneExpression(right), outer);
  2884. RETURN copy
  2885. END Clone;
  2886. PROCEDURE Accept*(v: Visitor);
  2887. VAR position: LONGINT;
  2888. BEGIN position := SELF.position; v.VisitAssignment(SELF)
  2889. END Accept;
  2890. END Assignment;
  2891. (** << left ('!' | '?') right >> **)
  2892. CommunicationStatement* = OBJECT (Statement)
  2893. VAR left-: Designator; right-: Expression; send-: BOOLEAN;
  2894. PROCEDURE & InitAssignment*( position: LONGINT; send: BOOLEAN; left: Designator; right: Expression; outer: Statement );
  2895. BEGIN
  2896. InitStatement( position,outer ); SELF.send := send; SELF.left := left; SELF.right := right;
  2897. END InitAssignment;
  2898. PROCEDURE SetLeft*(left: Designator);
  2899. BEGIN SELF.left := left
  2900. END SetLeft;
  2901. PROCEDURE SetRight*(right: Expression);
  2902. BEGIN SELF.right := right
  2903. END SetRight;
  2904. PROCEDURE Accept*(v: Visitor);
  2905. VAR position: LONGINT;
  2906. BEGIN position := SELF.position; v.VisitCommunicationStatement(SELF)
  2907. END Accept;
  2908. END CommunicationStatement;
  2909. (** << ... condition THEN statements ... >> **)
  2910. IfPart*= OBJECT
  2911. VAR
  2912. condition-: Expression;
  2913. statements-: StatementSequence;
  2914. comment-: Comment;
  2915. PROCEDURE & InitIfPart;
  2916. BEGIN
  2917. statements := NIL; condition := NIL; comment := NIL;
  2918. END InitIfPart;
  2919. PROCEDURE SetCondition*(condition: Expression);
  2920. BEGIN SELF.condition := condition
  2921. END SetCondition;
  2922. PROCEDURE SetStatements*(statements: StatementSequence);
  2923. BEGIN SELF.statements := statements
  2924. END SetStatements;
  2925. PROCEDURE SetComment*(comment: Comment);
  2926. BEGIN SELF.comment := comment
  2927. END SetComment;
  2928. PROCEDURE Clone(): IfPart;
  2929. VAR copy: IfPart;
  2930. BEGIN
  2931. NEW(copy); copy.condition := CloneExpression(condition);
  2932. copy.statements := CloneStatementSequence(statements);
  2933. RETURN copy
  2934. END Clone;
  2935. END IfPart;
  2936. (** << IF ifPart {ELSIF elsifParts} ELSE elseParts >> **)
  2937. IfStatement* = OBJECT (Statement)
  2938. VAR
  2939. ifPart-: IfPart;
  2940. elsifParts: Basic.List;
  2941. elsePart-: StatementSequence;
  2942. PROCEDURE & InitIfStatement( position: LONGINT ; outer: Statement);
  2943. BEGIN
  2944. InitStatement( position,outer ); ifPart := NewIfPart(); elsePart := NIL; elsifParts := NIL;
  2945. END InitIfStatement;
  2946. PROCEDURE SetElsePart*( elsePart: StatementSequence );
  2947. BEGIN
  2948. SELF.elsePart := elsePart;
  2949. END SetElsePart;
  2950. PROCEDURE AddElsifPart*( elsifPart: IfPart );
  2951. BEGIN
  2952. IF elsifParts = NIL THEN NEW(elsifParts,4); END;
  2953. elsifParts.Add( elsifPart );
  2954. END AddElsifPart;
  2955. PROCEDURE GetElsifPart*( i: LONGINT ): IfPart;
  2956. VAR a: ANY;
  2957. BEGIN a := elsifParts.Get( i ); RETURN a( IfPart )
  2958. END GetElsifPart;
  2959. PROCEDURE ElsifParts*( ): LONGINT;
  2960. BEGIN
  2961. IF elsifParts = NIL THEN RETURN 0 ELSE RETURN elsifParts.Length(); END;
  2962. END ElsifParts;
  2963. PROCEDURE Clone(): Statement;
  2964. VAR copy: IfStatement; i: LONGINT;
  2965. BEGIN
  2966. NEW(copy, position, outer);
  2967. copy.ifPart := ifPart.Clone();
  2968. FOR i := 0 TO ElsifParts()-1 DO
  2969. copy.AddElsifPart(GetElsifPart(i).Clone());
  2970. END;
  2971. copy.SetElsePart(CloneStatementSequence(elsePart));
  2972. RETURN copy
  2973. END Clone;
  2974. PROCEDURE Accept*(v: Visitor);
  2975. VAR position: LONGINT;
  2976. BEGIN position := SELF.position; v.VisitIfStatement(SELF)
  2977. END Accept;
  2978. END IfStatement;
  2979. WithPart*= OBJECT
  2980. VAR
  2981. variable-: Designator;
  2982. type-: Type; (* initially is qualified type *)
  2983. statements-: StatementSequence;
  2984. comment-: Comment;
  2985. PROCEDURE &InitWithPart();
  2986. BEGIN
  2987. type := NIL; variable := NIL; statements := NIL; comment := NIL;
  2988. END InitWithPart;
  2989. PROCEDURE SetVariable*( variable: Designator);
  2990. BEGIN
  2991. SELF.variable := variable
  2992. END SetVariable;
  2993. PROCEDURE SetType*( type: Type );
  2994. BEGIN
  2995. SELF.type := type
  2996. END SetType;
  2997. PROCEDURE SetStatements*( statements: StatementSequence );
  2998. BEGIN
  2999. SELF.statements := statements;
  3000. END SetStatements;
  3001. PROCEDURE SetComment*(comment: Comment);
  3002. BEGIN SELF.comment := comment
  3003. END SetComment;
  3004. PROCEDURE Clone(): WithPart;
  3005. VAR copy: WithPart;
  3006. BEGIN
  3007. NEW(copy);
  3008. copy.SetVariable(CloneDesignator(variable));
  3009. copy.SetType(type);
  3010. copy.SetStatements(CloneStatementSequence(statements));
  3011. RETURN copy
  3012. END Clone;
  3013. END WithPart;
  3014. (** << WITH variable : type DO statements END >> **)
  3015. WithStatement* = OBJECT (Statement)
  3016. VAR
  3017. withParts-: Basic.List;
  3018. elsePart-: StatementSequence;
  3019. PROCEDURE & InitWithStatement( position: LONGINT; outer: Statement );
  3020. BEGIN
  3021. InitStatement( position,outer );
  3022. NEW(withParts,4); elsePart := NIL;
  3023. END InitWithStatement;
  3024. PROCEDURE AddWithPart*( withPart: WithPart );
  3025. BEGIN withParts.Add( withPart );
  3026. END AddWithPart;
  3027. PROCEDURE GetWithPart*( i: LONGINT ): WithPart;
  3028. VAR a: ANY;
  3029. BEGIN a := withParts.Get( i ); RETURN a( WithPart )
  3030. END GetWithPart;
  3031. PROCEDURE WithParts*( ): LONGINT;
  3032. BEGIN
  3033. IF withParts = NIL THEN RETURN 0 ELSE RETURN withParts.Length(); END;
  3034. END WithParts;
  3035. PROCEDURE SetElsePart*( elsePart: StatementSequence );
  3036. BEGIN
  3037. SELF.elsePart := elsePart;
  3038. END SetElsePart;
  3039. PROCEDURE Clone(): Statement;
  3040. VAR copy: WithStatement; i: LONGINT;
  3041. BEGIN
  3042. NEW(copy, position, outer);
  3043. FOR i := 0 TO WithParts()-1 DO
  3044. copy.AddWithPart(GetWithPart(i).Clone());
  3045. END;
  3046. copy.SetElsePart(CloneStatementSequence(elsePart));
  3047. RETURN copy
  3048. END Clone;
  3049. PROCEDURE Accept*(v: Visitor);
  3050. VAR position: LONGINT;
  3051. BEGIN position := SELF.position; v.VisitWithStatement(SELF)
  3052. END Accept;
  3053. END WithStatement;
  3054. CaseConstant*= POINTER TO RECORD min*,max*: LONGINT; next*: CaseConstant END;
  3055. (** << elements : statements >> **)
  3056. CasePart* = OBJECT
  3057. VAR
  3058. elements-: ExpressionList; (* expression list inserted by the parser *)
  3059. firstConstant-: CaseConstant; (* expression list resolved to int32s, inserted by checker *)
  3060. statements-: StatementSequence;
  3061. comment-: Comment;
  3062. PROCEDURE & InitCasePart;
  3063. BEGIN
  3064. elements := NewExpressionList(); firstConstant := NIL;
  3065. END InitCasePart;
  3066. PROCEDURE SetStatements*( statements: StatementSequence );
  3067. BEGIN
  3068. SELF.statements := statements;
  3069. END SetStatements;
  3070. PROCEDURE SetConstants*(firstConstant: CaseConstant);
  3071. BEGIN SELF.firstConstant := firstConstant
  3072. END SetConstants;
  3073. PROCEDURE SetComment*(comment: Comment);
  3074. BEGIN SELF.comment := comment
  3075. END SetComment;
  3076. PROCEDURE Clone(): CasePart;
  3077. VAR copy: CasePart;
  3078. BEGIN
  3079. NEW(copy);
  3080. copy.SetStatements(CloneStatementSequence(statements));
  3081. copy.firstConstant := firstConstant;
  3082. elements.Clone(copy.elements);
  3083. RETURN copy
  3084. END Clone;
  3085. END CasePart;
  3086. (** << CASE varaible OF caseParts ELSE elsePart >> **)
  3087. CaseStatement* = OBJECT (Statement)
  3088. VAR
  3089. variable-: Expression;
  3090. elsePart-: StatementSequence;
  3091. caseParts-: Basic.List;
  3092. min-,max-: LONGINT;
  3093. PROCEDURE & InitCaseStatement( position: LONGINT ; outer: Statement);
  3094. BEGIN
  3095. InitStatement(position,outer ); variable := NIL; elsePart := NIL; caseParts := NIL;
  3096. min := MAX(LONGINT); max := MIN(LONGINT);
  3097. END InitCaseStatement;
  3098. PROCEDURE SetVariable*( expression: Expression );
  3099. BEGIN SELF.variable := expression;
  3100. END SetVariable;
  3101. PROCEDURE SetElsePart*( elsePart: StatementSequence );
  3102. BEGIN SELF.elsePart := elsePart;
  3103. END SetElsePart;
  3104. PROCEDURE AddCasePart*( casePart: CasePart );
  3105. BEGIN
  3106. IF caseParts = NIL THEN NEW(caseParts,4); END;
  3107. caseParts.Add( casePart );
  3108. END AddCasePart;
  3109. PROCEDURE GetCasePart*( i: LONGINT ): CasePart;
  3110. VAR a: ANY;
  3111. BEGIN a := caseParts.Get( i ); RETURN a( CasePart )
  3112. END GetCasePart;
  3113. PROCEDURE CaseParts*( ): LONGINT;
  3114. BEGIN
  3115. IF caseParts = NIL THEN RETURN 0 ELSE RETURN caseParts.Length(); END;
  3116. END CaseParts;
  3117. PROCEDURE Clone(): Statement;
  3118. VAR copy: CaseStatement; i: LONGINT;
  3119. BEGIN
  3120. NEW(copy, position, outer);
  3121. copy.SetVariable(CloneExpression(variable));
  3122. copy.SetElsePart(CloneStatementSequence(elsePart));
  3123. FOR i := 0 TO CaseParts()-1 DO
  3124. copy.AddCasePart(GetCasePart(i).Clone());
  3125. END;
  3126. copy.min := min; copy.max := max;
  3127. RETURN copy
  3128. END Clone;
  3129. PROCEDURE Accept*(v: Visitor);
  3130. VAR position: LONGINT;
  3131. BEGIN position := SELF.position; v.VisitCaseStatement(SELF)
  3132. END Accept;
  3133. PROCEDURE MaxConstant*(): LONGINT;
  3134. VAR val,i: LONGINT; part: CasePart; const: CaseConstant;
  3135. BEGIN
  3136. val := -1;
  3137. FOR i := 0 TO CaseParts() - 1 DO
  3138. part := GetCasePart(i);
  3139. const := part.firstConstant;
  3140. WHILE(const # NIL) DO
  3141. IF const.max > val THEN val := const.max; END;
  3142. const := const.next;
  3143. END;
  3144. END;
  3145. RETURN val;
  3146. END MaxConstant;
  3147. PROCEDURE SetMinMax*(min,max: LONGINT);
  3148. BEGIN
  3149. SELF.min := min; SELF.max := max;
  3150. END SetMinMax;
  3151. END CaseStatement;
  3152. (** << WHILE condition DO statements END >> **)
  3153. WhileStatement* = OBJECT (Statement)
  3154. VAR
  3155. condition-: Expression;
  3156. statements-: StatementSequence;
  3157. PROCEDURE & InitWhileStatement( position: LONGINT ; outer: Statement);
  3158. BEGIN
  3159. InitStatement( position,outer ); condition := NIL; statements := NIL;
  3160. END InitWhileStatement;
  3161. PROCEDURE SetCondition*( condition: Expression );
  3162. BEGIN
  3163. SELF.condition := condition
  3164. END SetCondition;
  3165. PROCEDURE SetStatements*( statements: StatementSequence );
  3166. BEGIN
  3167. SELF.statements := statements;
  3168. END SetStatements;
  3169. PROCEDURE Clone(): Statement;
  3170. VAR copy: WhileStatement;
  3171. BEGIN
  3172. NEW(copy, position, outer);
  3173. copy.SetCondition(CloneExpression(condition));
  3174. copy.SetStatements(CloneStatementSequence(statements));
  3175. RETURN copy
  3176. END Clone;
  3177. PROCEDURE Accept*(v: Visitor);
  3178. VAR position: LONGINT;
  3179. BEGIN position := SELF.position; v.VisitWhileStatement(SELF)
  3180. END Accept;
  3181. END WhileStatement;
  3182. (** << REPEAT statements UNTIL condition >> **)
  3183. RepeatStatement* = OBJECT (Statement)
  3184. VAR
  3185. condition-: Expression;
  3186. statements-: StatementSequence;
  3187. PROCEDURE & InitRepeatStatement( position: LONGINT; outer: Statement );
  3188. BEGIN
  3189. InitStatement( position,outer ); condition := NIL; statements := NIL;
  3190. END InitRepeatStatement;
  3191. PROCEDURE SetCondition*( condition: Expression );
  3192. BEGIN
  3193. SELF.condition := condition
  3194. END SetCondition;
  3195. PROCEDURE SetStatements*( statements: StatementSequence );
  3196. BEGIN
  3197. SELF.statements := statements;
  3198. END SetStatements;
  3199. PROCEDURE Clone(): Statement;
  3200. VAR copy: RepeatStatement;
  3201. BEGIN
  3202. NEW(copy, position, outer);
  3203. copy.SetCondition(CloneExpression(condition));
  3204. copy.SetStatements(CloneStatementSequence(statements));
  3205. RETURN copy
  3206. END Clone;
  3207. PROCEDURE Accept*(v: Visitor);
  3208. VAR position: LONGINT;
  3209. BEGIN position := SELF.position; v.VisitRepeatStatement(SELF)
  3210. END Accept;
  3211. END RepeatStatement;
  3212. (** << FOR variable := from TO to BY by DO statements END >> **)
  3213. ForStatement* = OBJECT (Statement)
  3214. VAR
  3215. variable-: Designator;
  3216. from-, to-, by-: Expression;
  3217. statements-: StatementSequence;
  3218. PROCEDURE & InitForStatement( position: LONGINT; outer: Statement );
  3219. BEGIN
  3220. InitStatement( position,outer ); variable := NIL;from := NIL; to := NIL; by := NIL; statements := NIL;
  3221. END InitForStatement;
  3222. PROCEDURE SetVariable*( variable: Designator);
  3223. BEGIN
  3224. SELF.variable := variable
  3225. END SetVariable;
  3226. PROCEDURE SetFrom*( from: Expression );
  3227. BEGIN
  3228. SELF.from := from
  3229. END SetFrom;
  3230. PROCEDURE SetTo*( to: Expression );
  3231. BEGIN
  3232. SELF.to := to
  3233. END SetTo;
  3234. PROCEDURE SetBy*( by: Expression );
  3235. BEGIN SELF.by := by
  3236. END SetBy;
  3237. PROCEDURE SetStatements*( statements: StatementSequence );
  3238. BEGIN SELF.statements := statements;
  3239. END SetStatements;
  3240. PROCEDURE Clone(): Statement;
  3241. VAR copy: ForStatement;
  3242. BEGIN
  3243. NEW(copy, position, outer);
  3244. copy.SetVariable(CloneDesignator(variable));
  3245. copy.SetFrom(CloneExpression(from));
  3246. copy.SetTo(CloneExpression(to));
  3247. copy.SetBy(CloneExpression(by));
  3248. copy.SetStatements(CloneStatementSequence(statements));
  3249. RETURN copy
  3250. END Clone;
  3251. PROCEDURE Accept*(v: Visitor);
  3252. VAR position: LONGINT;
  3253. BEGIN position := SELF.position; v.VisitForStatement(SELF)
  3254. END Accept;
  3255. END ForStatement;
  3256. ExitableBlock*= OBJECT (Statement)
  3257. VAR statements-: StatementSequence;
  3258. PROCEDURE & InitExitableBlock( position: LONGINT ; outer: Statement);
  3259. BEGIN
  3260. InitStatement( position ,outer); statements := NIL;
  3261. END InitExitableBlock;
  3262. PROCEDURE SetStatements*( statements: StatementSequence );
  3263. BEGIN SELF.statements := statements;
  3264. END SetStatements;
  3265. PROCEDURE Clone(): Statement;
  3266. VAR copy: ExitableBlock;
  3267. BEGIN
  3268. NEW(copy, position, outer);
  3269. copy.SetStatements(CloneStatementSequence(statements));
  3270. RETURN copy
  3271. END Clone;
  3272. PROCEDURE Accept*(v: Visitor);
  3273. VAR position: LONGINT;
  3274. BEGIN position := SELF.position; v.VisitExitableBlock(SELF)
  3275. END Accept;
  3276. END ExitableBlock;
  3277. (** << LOOP statements END >> **)
  3278. LoopStatement* = OBJECT (ExitableBlock)
  3279. PROCEDURE Clone(): Statement;
  3280. VAR copy: LoopStatement;
  3281. BEGIN
  3282. NEW(copy, position, outer);
  3283. copy.SetStatements(CloneStatementSequence(statements));
  3284. RETURN copy
  3285. END Clone;
  3286. PROCEDURE Accept*(v: Visitor);
  3287. VAR position: LONGINT;
  3288. BEGIN position := SELF.position; v.VisitLoopStatement(SELF)
  3289. END Accept;
  3290. END LoopStatement;
  3291. (** << EXIT >> **)
  3292. ExitStatement* = OBJECT (Statement)
  3293. PROCEDURE Accept*(v: Visitor);
  3294. VAR position: LONGINT;
  3295. BEGIN position := SELF.position; v.VisitExitStatement(SELF)
  3296. END Accept;
  3297. PROCEDURE Clone(): Statement;
  3298. VAR copy: ExitStatement;
  3299. BEGIN
  3300. NEW(copy, position, outer);
  3301. RETURN copy
  3302. END Clone;
  3303. END ExitStatement;
  3304. (** << RETURN returnValue >> **)
  3305. ReturnStatement* = OBJECT (Statement)
  3306. VAR returnValue-: Expression; (* strictly speaking this is not a value but this term is in common use here *)
  3307. PROCEDURE & InitReturnStatement( position: LONGINT ; outer: Statement);
  3308. BEGIN
  3309. InitStatement( position,outer ); returnValue := NIL
  3310. END InitReturnStatement;
  3311. PROCEDURE SetReturnValue*( returnValue: Expression );
  3312. BEGIN SELF.returnValue := returnValue
  3313. END SetReturnValue;
  3314. PROCEDURE Clone(): Statement;
  3315. VAR copy: ReturnStatement;
  3316. BEGIN
  3317. NEW(copy, position, outer);
  3318. copy.SetReturnValue(CloneExpression(returnValue));
  3319. RETURN copy
  3320. END Clone;
  3321. PROCEDURE Accept*(v: Visitor);
  3322. VAR position: LONGINT;
  3323. BEGIN position := SELF.position; v.VisitReturnStatement(SELF)
  3324. END Accept;
  3325. END ReturnStatement;
  3326. (** << AWAIT condition >> **)
  3327. AwaitStatement* = OBJECT (Statement)
  3328. VAR condition-: Expression;
  3329. PROCEDURE & InitAwaitStatement( position: LONGINT; outer: Statement );
  3330. BEGIN
  3331. InitStatement( position,outer ); condition := NIL
  3332. END InitAwaitStatement;
  3333. PROCEDURE SetCondition*( condition: Expression );
  3334. BEGIN SELF.condition := condition
  3335. END SetCondition;
  3336. PROCEDURE Clone(): Statement;
  3337. VAR copy: AwaitStatement;
  3338. BEGIN
  3339. NEW(copy, position, outer);
  3340. copy.SetCondition(CloneExpression(condition));
  3341. RETURN copy
  3342. END Clone;
  3343. PROCEDURE Accept*(v: Visitor);
  3344. VAR position: LONGINT;
  3345. BEGIN position := SELF.position; v.VisitAwaitStatement(SELF)
  3346. END Accept;
  3347. END AwaitStatement;
  3348. (* << Identifier ( Expression) >> *)
  3349. Modifier*= OBJECT
  3350. VAR
  3351. identifier-: Identifier; expression-: Expression;
  3352. resolved-: BOOLEAN;
  3353. nextModifier-: Modifier;
  3354. position-: LONGINT;
  3355. PROCEDURE & InitModifier(position: LONGINT; identifier: Identifier; expression: Expression);
  3356. BEGIN
  3357. SELF.position := position;
  3358. SELF.identifier := identifier; SELF.expression := expression; nextModifier := NIL; resolved := FALSE;
  3359. END InitModifier;
  3360. PROCEDURE Resolved*;
  3361. BEGIN resolved := TRUE
  3362. END Resolved;
  3363. PROCEDURE SetExpression*(e: Expression);
  3364. BEGIN SELF.expression := e
  3365. END SetExpression;
  3366. PROCEDURE SetNext*(modifier: Modifier);
  3367. BEGIN nextModifier := modifier
  3368. END SetNext;
  3369. END Modifier;
  3370. (** << BEGIN {Modifier, Modifier ... } statements END >> **)
  3371. StatementBlock* = OBJECT (Statement)
  3372. VAR
  3373. statements-: StatementSequence;
  3374. blockModifiers-: Modifier;
  3375. isExclusive-: BOOLEAN;
  3376. isRealtime-: BOOLEAN;
  3377. isUnchecked-: BOOLEAN;
  3378. isUncooperative-: BOOLEAN;
  3379. PROCEDURE & InitStatementBlock( position: LONGINT ; outer: Statement);
  3380. BEGIN
  3381. InitStatement( position ,outer); statements := NIL; blockModifiers := NIL;
  3382. isExclusive := FALSE;
  3383. isRealtime := FALSE;
  3384. isUnchecked := FALSE;
  3385. isUncooperative := FALSE;
  3386. END InitStatementBlock;
  3387. PROCEDURE SetRealtime*(b: BOOLEAN);
  3388. BEGIN
  3389. isRealtime := b
  3390. END SetRealtime;
  3391. PROCEDURE SetUnchecked*(unchecked: BOOLEAN);
  3392. BEGIN
  3393. isUnchecked := unchecked
  3394. END SetUnchecked;
  3395. PROCEDURE SetUncooperative*(uncooperative: BOOLEAN);
  3396. BEGIN
  3397. isUncooperative := uncooperative
  3398. END SetUncooperative;
  3399. PROCEDURE SetModifier*(modifier: Modifier);
  3400. BEGIN
  3401. blockModifiers := modifier;
  3402. END SetModifier;
  3403. PROCEDURE SetExclusive*(excl: BOOLEAN);
  3404. BEGIN isExclusive := excl
  3405. END SetExclusive;
  3406. PROCEDURE SetStatementSequence*( statements: StatementSequence );
  3407. BEGIN SELF.statements := statements;
  3408. END SetStatementSequence;
  3409. PROCEDURE Accept*(v: Visitor);
  3410. VAR position: LONGINT;
  3411. BEGIN position := SELF.position; v.VisitStatementBlock(SELF)
  3412. END Accept;
  3413. END StatementBlock;
  3414. (** << CODE {flags} {character} END >> **)
  3415. Code*= OBJECT(Statement)
  3416. VAR
  3417. sourceCode-: SourceCode; sourceCodeLength-: LONGINT;
  3418. inlineCode-: BinaryCode;
  3419. inRules-, outRules-: StatementSequence;
  3420. PROCEDURE & InitCode(position: LONGINT; outer: Statement);
  3421. BEGIN
  3422. InitStatement(position,outer);
  3423. inlineCode := NIL;
  3424. sourceCode := NIL; sourceCodeLength := 0;
  3425. NEW(inRules); NEW(outRules);
  3426. END InitCode;
  3427. PROCEDURE SetSourceCode*(source: SourceCode; length: LONGINT);
  3428. BEGIN sourceCode := source; sourceCodeLength := length;
  3429. ASSERT(sourceCodeLength <= LEN(source));
  3430. END SetSourceCode;
  3431. PROCEDURE SetBinaryCode*(code: BinaryCode);
  3432. BEGIN
  3433. inlineCode := code;
  3434. END SetBinaryCode;
  3435. PROCEDURE Clone(): Statement;
  3436. VAR copy: Code; s: Scanner.StringType;
  3437. BEGIN
  3438. NEW(copy, position, outer);
  3439. NEW(s, sourceCodeLength);
  3440. Strings.Copy(sourceCode^,0,sourceCodeLength,s^);
  3441. copy.SetSourceCode(s, sourceCodeLength);
  3442. copy.inRules := CloneStatementSequence(inRules);
  3443. copy.outRules := CloneStatementSequence(outRules);
  3444. RETURN copy
  3445. END Clone;
  3446. PROCEDURE Accept*(v: Visitor);
  3447. VAR position: LONGINT;
  3448. BEGIN position := SELF.position; v.VisitCode(SELF)
  3449. END Accept;
  3450. END Code;
  3451. (** << BEGIN {flags} statements FINALLY statements END >> **)
  3452. Body*= OBJECT(StatementBlock)
  3453. VAR
  3454. finally-: StatementSequence;
  3455. priority-: Expression; (* set by checker *)
  3456. inScope-: ProcedureScope;
  3457. code-: Code;
  3458. isActive-, isSafe-: BOOLEAN;
  3459. PROCEDURE & InitBody(position: LONGINT; scope: ProcedureScope);
  3460. BEGIN
  3461. InitStatementBlock(position,NIL); finally := NIL; priority := NIL; inScope := scope; code := NIL;
  3462. isActive := FALSE; isSafe := FALSE; isRealtime := FALSE;
  3463. END InitBody;
  3464. PROCEDURE SetActive*(active: BOOLEAN);
  3465. BEGIN SELF.isActive := active
  3466. END SetActive;
  3467. PROCEDURE SetSafe*(safe: BOOLEAN);
  3468. BEGIN SELF.isSafe := safe
  3469. END SetSafe;
  3470. PROCEDURE SetFinally*( finally: StatementSequence );
  3471. BEGIN SELF.finally := finally
  3472. END SetFinally;
  3473. PROCEDURE SetPriority*(expression: Expression);
  3474. BEGIN priority := expression
  3475. END SetPriority;
  3476. PROCEDURE SetCode*(code: Code);
  3477. BEGIN SELF.code := code;
  3478. END SetCode;
  3479. END Body;
  3480. (** (* comment *) *)
  3481. Comment*=OBJECT
  3482. VAR position-: LONGINT;
  3483. source-: String; (* currently: POINTER TO ARRAY OF CHAR *)
  3484. scope-: Scope;
  3485. item-: ANY; sameLine-: BOOLEAN;
  3486. nextComment-: Comment;
  3487. PROCEDURE & InitComment(pos: LONGINT; scope: Scope; CONST s: ARRAY OF CHAR; length: LONGINT);
  3488. VAR i: LONGINT;
  3489. BEGIN
  3490. SELF.scope := scope;
  3491. NEW(source,length);
  3492. FOR i := 0 TO length-1 DO
  3493. source[i] := s[i];
  3494. END;
  3495. SELF.position := pos;
  3496. nextComment := NIL;
  3497. item := NIL; sameLine := FALSE;
  3498. END InitComment;
  3499. PROCEDURE SetItem*(p: ANY; sameLine: BOOLEAN);
  3500. BEGIN
  3501. item := p; SELF.sameLine := sameLine
  3502. END SetItem;
  3503. END Comment;
  3504. (**** building blocks ****)
  3505. Scope*=OBJECT
  3506. VAR
  3507. firstSymbol-: Symbol; numberSymbols-: LONGINT; (* all symbols in scope (sorted) *)
  3508. firstConstant-,lastConstant-: Constant; numberConstants-: LONGINT; (* constants *)
  3509. firstTypeDeclaration-,lastTypeDeclaration-: TypeDeclaration; numberTypeDeclarations-: LONGINT; (* type declarations *)
  3510. firstVariable-,lastVariable-: Variable; numberVariables-: LONGINT; (* variables *)
  3511. firstProcedure-,lastProcedure-: Procedure; numberProcedures-: LONGINT; (* procedures *)
  3512. outerScope-: Scope; nextScope-: Scope;
  3513. ownerModule-: Module;
  3514. PROCEDURE & InitScope(outer: Scope);
  3515. BEGIN
  3516. firstSymbol := NIL; numberSymbols := 0;
  3517. firstConstant := NIL; lastConstant := NIL; numberConstants := 0;
  3518. firstTypeDeclaration := NIL; lastTypeDeclaration := NIL; numberTypeDeclarations := 0;
  3519. firstVariable := NIL; lastVariable := NIL; numberVariables := 0;
  3520. firstProcedure := NIL; lastProcedure := NIL; numberProcedures := 0;
  3521. outerScope := outer;
  3522. IF outer # NIL THEN
  3523. ownerModule := outer.ownerModule
  3524. ELSE
  3525. ownerModule := NIL;
  3526. END;
  3527. nextScope := NIL;
  3528. END InitScope;
  3529. (** Enter a symbol in the scope, aplhabetically sorted, duplicate = TRUE if multiply identifier *)
  3530. PROCEDURE EnterSymbol*(symbol: Symbol; VAR duplicate: BOOLEAN);
  3531. VAR p,q: Symbol; name,nextname: Scanner.StringType;
  3532. BEGIN
  3533. ASSERT(symbol.nextSymbol = NIL,101); (* symbol may only be present in one scope at a time ! *)
  3534. ASSERT(symbol.scope = NIL,102);
  3535. ASSERT(symbol.name # invalidIdentifier,103);
  3536. p := firstSymbol; q := NIL;
  3537. WHILE (p # NIL) & (StringPool.CompareString(p.name,symbol.name)<0) DO q := p; p := p.nextSymbol END;
  3538. IF (p#NIL) & (symbol.name = p.name) THEN
  3539. duplicate := TRUE;
  3540. ELSE
  3541. duplicate := FALSE
  3542. END;
  3543. symbol.nextSymbol := p;
  3544. IF q = NIL THEN firstSymbol := symbol ELSE q.nextSymbol := symbol END;
  3545. symbol.SetScope(SELF);
  3546. INC(numberSymbols);
  3547. END EnterSymbol;
  3548. (** Find symbol by name *)
  3549. PROCEDURE FindSymbol*(identifier: Identifier): Symbol;
  3550. VAR p: Symbol;
  3551. BEGIN
  3552. IF identifier # invalidIdentifier THEN
  3553. p := firstSymbol;
  3554. WHILE(p#NIL) & ((p.name # identifier) OR (p IS Operator)) DO p := p.nextSymbol END;
  3555. END;
  3556. RETURN p;
  3557. END FindSymbol;
  3558. PROCEDURE AddConstant*(c: Constant);
  3559. BEGIN
  3560. ASSERT(c # NIL);
  3561. IF lastConstant= NIL THEN firstConstant := c ELSE lastConstant.nextConstant := c END;
  3562. lastConstant := c;
  3563. INC(numberConstants);
  3564. END AddConstant;
  3565. PROCEDURE FindConstant*(identifier: Identifier): Constant;
  3566. VAR p: Constant;
  3567. BEGIN
  3568. p := firstConstant;
  3569. WHILE(p#NIL) & (p.name # identifier) DO p := p.nextConstant END;
  3570. RETURN p;
  3571. END FindConstant;
  3572. PROCEDURE AddTypeDeclaration*(t: TypeDeclaration);
  3573. BEGIN
  3574. ASSERT(t # NIL);
  3575. IF lastTypeDeclaration= NIL THEN firstTypeDeclaration := t ELSE lastTypeDeclaration.nextTypeDeclaration := t END;
  3576. INC(numberTypeDeclarations);
  3577. lastTypeDeclaration := t;
  3578. END AddTypeDeclaration;
  3579. PROCEDURE FindTypeDeclaration*(identifier: Identifier): TypeDeclaration;
  3580. VAR p: TypeDeclaration;
  3581. BEGIN
  3582. p := firstTypeDeclaration;
  3583. WHILE(p#NIL) & (p.name # identifier) DO p := p.nextTypeDeclaration END;
  3584. RETURN p;
  3585. END FindTypeDeclaration;
  3586. PROCEDURE AddVariable*(v: Variable);
  3587. BEGIN
  3588. ASSERT(v # NIL);
  3589. IF lastVariable= NIL THEN firstVariable := v ELSE lastVariable.nextVariable := v END;
  3590. INC(numberVariables);
  3591. lastVariable := v;
  3592. END AddVariable;
  3593. PROCEDURE PushVariable*(v: Variable);
  3594. BEGIN
  3595. ASSERT(v # NIL);
  3596. IF lastVariable= NIL THEN lastVariable := v ELSE v.nextVariable := firstVariable END;
  3597. INC(numberVariables);
  3598. firstVariable := v;
  3599. END PushVariable;
  3600. PROCEDURE FindVariable*(identifier: Identifier): Variable;
  3601. VAR p: Variable;
  3602. BEGIN
  3603. p := firstVariable;
  3604. WHILE(p#NIL) & (p.name # identifier) DO p := p.nextVariable END;
  3605. RETURN p;
  3606. END FindVariable;
  3607. PROCEDURE AddProcedure*(p: Procedure);
  3608. BEGIN
  3609. ASSERT(p # NIL);
  3610. IF lastProcedure= NIL THEN firstProcedure := p ELSE lastProcedure.nextProcedure := p END;
  3611. INC(numberProcedures);
  3612. lastProcedure := p;
  3613. END AddProcedure;
  3614. PROCEDURE FindProcedure*(identifier: Identifier): Procedure;
  3615. VAR p: Procedure;
  3616. BEGIN
  3617. p := firstProcedure;
  3618. WHILE (p#NIL) & ((p.name # identifier) OR (p IS Operator)) DO p := p.nextProcedure END;
  3619. RETURN p;
  3620. END FindProcedure;
  3621. PROCEDURE FindMethod*(number: LONGINT): Procedure;
  3622. VAR p: Procedure;
  3623. BEGIN
  3624. p := firstProcedure;
  3625. WHILE (p# NIL) & (p.methodNumber # number) DO
  3626. p := p.nextProcedure
  3627. END;
  3628. RETURN p;
  3629. END FindMethod;
  3630. PROCEDURE Level*(): LONGINT;
  3631. VAR scope: Scope; level: LONGINT;
  3632. BEGIN
  3633. level := 0;
  3634. scope := SELF;
  3635. WHILE(scope.outerScope # NIL) DO
  3636. scope := scope.outerScope;
  3637. INC(level);
  3638. END;
  3639. RETURN level;
  3640. END Level;
  3641. PROCEDURE NeedsTrace* (): BOOLEAN;
  3642. VAR variable: Variable;
  3643. BEGIN
  3644. variable := firstVariable;
  3645. WHILE variable # NIL DO
  3646. IF variable.NeedsTrace () THEN RETURN TRUE END;
  3647. variable := variable.nextVariable;
  3648. END;
  3649. RETURN FALSE;
  3650. END NeedsTrace;
  3651. END Scope;
  3652. ProcedureScope*=OBJECT (Scope)
  3653. VAR
  3654. ownerProcedure-: Procedure;
  3655. body-: Body;
  3656. PROCEDURE & InitProcedureScope(outer: Scope);
  3657. BEGIN
  3658. InitScope(outer);
  3659. ownerProcedure := NIL;
  3660. body := NIL;
  3661. END InitProcedureScope;
  3662. PROCEDURE SetBody*(body: Body);
  3663. BEGIN
  3664. SELF.body := body;
  3665. END SetBody;
  3666. PROCEDURE NeedsTrace* (): BOOLEAN;
  3667. VAR parameter: Parameter;
  3668. BEGIN
  3669. parameter := ownerProcedure.type.resolved(ProcedureType).firstParameter;
  3670. WHILE parameter # NIL DO
  3671. IF parameter.NeedsTrace () THEN RETURN TRUE END;
  3672. parameter := parameter.nextParameter;
  3673. END;
  3674. RETURN NeedsTrace^();
  3675. END NeedsTrace;
  3676. END ProcedureScope;
  3677. EnumerationScope*= OBJECT(Scope)
  3678. VAR
  3679. ownerEnumeration-: EnumerationType;
  3680. (** Find symbol by name *)
  3681. PROCEDURE FindSymbol*(identifier: Identifier): Symbol;
  3682. VAR p: Symbol; base: Type;
  3683. BEGIN
  3684. p := FindSymbol^(identifier);
  3685. IF p = NIL THEN
  3686. base := ownerEnumeration.enumerationBase;
  3687. IF (base # NIL) & (base.resolved IS EnumerationType) THEN
  3688. p := base.resolved(EnumerationType).enumerationScope.FindSymbol(identifier)
  3689. END;
  3690. END;
  3691. RETURN p;
  3692. END FindSymbol;
  3693. PROCEDURE &InitEnumerationScope(outer: Scope);
  3694. BEGIN
  3695. InitScope(outer);
  3696. ownerEnumeration := NIL; (* must be set by EnumerationType *)
  3697. END InitEnumerationScope;
  3698. END EnumerationScope;
  3699. RecordScope*= OBJECT(Scope)
  3700. VAR
  3701. ownerRecord-: RecordType;
  3702. bodyProcedure-: Procedure;
  3703. constructor-: Procedure;
  3704. finalizer-: Procedure;
  3705. numberMethods-: LONGINT;
  3706. firstParameter-,lastParameter-: Parameter; numberParameters-: LONGINT; (* parameters for Active Cells programming*)
  3707. firstOperator-, lastOperator-: Operator; numberOperators: LONGINT; (* defined operators *)
  3708. PROCEDURE & InitRecordScope(outer: Scope);
  3709. BEGIN
  3710. InitScope(outer);
  3711. ownerRecord := NIL;
  3712. numberMethods := 0;
  3713. bodyProcedure := NIL;
  3714. constructor := NIL;
  3715. finalizer := NIL;
  3716. firstOperator := NIL; lastOperator := NIL; numberOperators := 0;
  3717. END InitRecordScope;
  3718. PROCEDURE SetBodyProcedure*(body: Procedure);
  3719. BEGIN SELF.bodyProcedure := body;
  3720. END SetBodyProcedure;
  3721. PROCEDURE SetConstructor*(body: Procedure);
  3722. BEGIN SELF.constructor := body
  3723. END SetConstructor;
  3724. PROCEDURE SetFinalizer*(body: Procedure);
  3725. BEGIN SELF.finalizer := body
  3726. END SetFinalizer;
  3727. PROCEDURE SetNumberMethods*(numberMethods: LONGINT);
  3728. BEGIN SELF.numberMethods := numberMethods;
  3729. END SetNumberMethods;
  3730. PROCEDURE AddOperator*(p: Operator);
  3731. BEGIN
  3732. ASSERT(p # NIL);
  3733. IF lastOperator= NIL THEN firstOperator := p ELSE lastOperator.nextOperator := p END;
  3734. INC(numberOperators);
  3735. lastOperator := p;
  3736. END AddOperator;
  3737. (** Find symbol by name *)
  3738. PROCEDURE FindSymbol*(identifier: Identifier): Symbol;
  3739. VAR p: Symbol; base: RecordType;
  3740. BEGIN
  3741. p := FindSymbol^(identifier);
  3742. IF p = NIL THEN
  3743. base := ownerRecord.GetBaseRecord();
  3744. IF (base # NIL) THEN
  3745. p := base.recordScope.FindSymbol(identifier)
  3746. END;
  3747. END;
  3748. RETURN p;
  3749. END FindSymbol;
  3750. PROCEDURE FindConstant*(identifier: Identifier): Constant;
  3751. VAR p: Constant; base: RecordType;
  3752. BEGIN
  3753. p := FindConstant^(identifier);
  3754. IF p = NIL THEN
  3755. base := ownerRecord.GetBaseRecord();
  3756. IF (base # NIL) THEN
  3757. p := base.recordScope.FindConstant(identifier)
  3758. END;
  3759. END;
  3760. RETURN p;
  3761. END FindConstant;
  3762. PROCEDURE FindTypeDeclaration*(identifier: Identifier): TypeDeclaration;
  3763. VAR p: TypeDeclaration; base: RecordType;
  3764. BEGIN
  3765. p := FindTypeDeclaration^(identifier);
  3766. IF p = NIL THEN
  3767. base := ownerRecord.GetBaseRecord();
  3768. IF (base # NIL) THEN
  3769. p := base.recordScope.FindTypeDeclaration(identifier)
  3770. END;
  3771. END;
  3772. RETURN p;
  3773. END FindTypeDeclaration;
  3774. PROCEDURE FindVariable*(identifier: Identifier): Variable;
  3775. VAR p: Variable; base: RecordType;
  3776. BEGIN
  3777. p := FindVariable^(identifier);
  3778. IF p = NIL THEN
  3779. base := ownerRecord.GetBaseRecord();
  3780. IF (base # NIL) THEN
  3781. p := base.recordScope.FindVariable(identifier)
  3782. END;
  3783. END;
  3784. RETURN p;
  3785. END FindVariable;
  3786. PROCEDURE FindProcedure*(identifier: Identifier): Procedure;
  3787. VAR p: Procedure; base: RecordType;
  3788. BEGIN
  3789. p := FindProcedure^(identifier);
  3790. IF p = NIL THEN
  3791. base := ownerRecord.GetBaseRecord();
  3792. IF (base # NIL) THEN
  3793. p := base.recordScope.FindProcedure(identifier)
  3794. END;
  3795. END;
  3796. RETURN p;
  3797. END FindProcedure;
  3798. PROCEDURE FindMethod*(number: LONGINT): Procedure;
  3799. VAR p: Procedure; base: RecordType;
  3800. BEGIN
  3801. p := FindMethod^(number);
  3802. IF p = NIL THEN
  3803. base := ownerRecord.GetBaseRecord();
  3804. IF (base # NIL) THEN
  3805. p := base.recordScope.FindMethod(number)
  3806. END;
  3807. END;
  3808. RETURN p;
  3809. END FindMethod;
  3810. PROCEDURE NeedsTrace* (): BOOLEAN;
  3811. VAR base: RecordType;
  3812. BEGIN
  3813. base := ownerRecord.GetBaseRecord();
  3814. IF (base # NIL) & (base.NeedsTrace ()) THEN RETURN TRUE END;
  3815. RETURN NeedsTrace^();
  3816. END NeedsTrace;
  3817. END RecordScope;
  3818. CellScope*=OBJECT (Scope)
  3819. VAR
  3820. ownerCell-: CellType;
  3821. bodyProcedure-: Procedure;
  3822. constructor-: Procedure;
  3823. PROCEDURE & InitCellScope(outer: Scope);
  3824. BEGIN
  3825. InitScope(outer);
  3826. ownerCell := NIL;
  3827. bodyProcedure := NIL;
  3828. constructor := NIL;
  3829. END InitCellScope;
  3830. PROCEDURE SetOwnerCell*(owner: CellType);
  3831. BEGIN
  3832. ownerCell := owner
  3833. END SetOwnerCell;
  3834. PROCEDURE SetBodyProcedure*(bodyProcedure: Procedure);
  3835. BEGIN
  3836. SELF.bodyProcedure := bodyProcedure;
  3837. END SetBodyProcedure;
  3838. PROCEDURE SetConstructor*(p: Procedure);
  3839. BEGIN constructor := p
  3840. END SetConstructor;
  3841. PROCEDURE FindSymbol*(identifier: Identifier): Symbol;
  3842. VAR p: Symbol; base: RecordType;
  3843. BEGIN
  3844. p := FindSymbol^(identifier);
  3845. IF p = NIL THEN
  3846. IF ownerCell.isCellNet THEN
  3847. RETURN ownerCell.FindProperty(identifier);
  3848. END;
  3849. END;
  3850. RETURN p;
  3851. END FindSymbol;
  3852. END CellScope;
  3853. (**
  3854. <<
  3855. IMPORT firstImport .. lastImport;
  3856. ...
  3857. firstOperator ... lastOperator
  3858. ....
  3859. >>
  3860. **)
  3861. ModuleScope*= OBJECT(Scope)
  3862. VAR
  3863. firstImport-,lastImport-: Import; numberImports: LONGINT; (* imported modules *)
  3864. firstOperator-,lastOperator-: Operator; numberOperators: LONGINT; (* defined operators *)
  3865. firstBuiltin-,lastBuiltin-: Builtin; numberBuiltins: LONGINT; (* defined builtins, only for global and system module *)
  3866. firstComment-,lastComment-: Comment; numberComments-: LONGINT; (* comments *)
  3867. bodyProcedure-: Procedure;
  3868. PROCEDURE & InitModuleScope;
  3869. BEGIN
  3870. InitScope(NIL);
  3871. firstComment := NIL; lastComment := NIL; numberComments := 0;
  3872. firstImport:= NIL; lastImport := NIL; numberImports := 0;
  3873. firstOperator := NIL; lastOperator := NIL; numberOperators := 0;
  3874. END InitModuleScope;
  3875. PROCEDURE SetBodyProcedure*(body: Procedure);
  3876. BEGIN SELF.bodyProcedure := body;
  3877. END SetBodyProcedure;
  3878. PROCEDURE SetGlobalScope*(outer: Scope);
  3879. BEGIN
  3880. SELF.outerScope := outer;
  3881. END SetGlobalScope;
  3882. PROCEDURE AddBuiltin*(p: Builtin);
  3883. BEGIN
  3884. ASSERT(p # NIL);
  3885. IF lastBuiltin= NIL THEN firstBuiltin := p ELSE lastBuiltin.nextBuiltin := p END;
  3886. INC(numberBuiltins);
  3887. lastBuiltin := p;
  3888. END AddBuiltin;
  3889. PROCEDURE AddOperator*(p: Operator);
  3890. BEGIN
  3891. ASSERT(p # NIL);
  3892. IF lastOperator= NIL THEN firstOperator := p ELSE lastOperator.nextOperator := p END;
  3893. INC(numberOperators);
  3894. lastOperator := p;
  3895. END AddOperator;
  3896. PROCEDURE FindOperator*(identifier: Identifier): Operator;
  3897. VAR p: Operator;
  3898. BEGIN
  3899. p := firstOperator;
  3900. WHILE(p#NIL) & (p.name # identifier) DO p := p.nextOperator END;
  3901. RETURN p;
  3902. END FindOperator;
  3903. PROCEDURE AddImport*(i: Import);
  3904. BEGIN
  3905. ASSERT(i # NIL);
  3906. ASSERT(i.nextImport = NIL);
  3907. IF lastImport= NIL THEN firstImport:= i ELSE lastImport.nextImport := i END;
  3908. lastImport := i;
  3909. INC(numberImports);
  3910. END AddImport;
  3911. PROCEDURE FindImport*(identifier: Identifier): Import;
  3912. VAR p: Import;
  3913. BEGIN
  3914. p := firstImport;
  3915. WHILE(p#NIL) & (p.name # identifier) DO p := p.nextImport END; (* finds imports and re-imports! *)
  3916. RETURN p;
  3917. END FindImport;
  3918. PROCEDURE GetImport*( index: LONGINT ): Import;
  3919. VAR import: Import;
  3920. BEGIN
  3921. import := firstImport;
  3922. WHILE(import # NIL) & (index > 0) DO
  3923. import := import.nextImport;
  3924. DEC(index);
  3925. END;
  3926. RETURN import;
  3927. END GetImport;
  3928. PROCEDURE AddComment*(comment: Comment);
  3929. BEGIN
  3930. ASSERT(comment # NIL);
  3931. IF lastComment= NIL THEN firstComment := comment ELSE lastComment.nextComment := comment END;
  3932. INC(numberComments);
  3933. lastComment := comment;
  3934. END AddComment;
  3935. PROCEDURE ImportByModuleName*(moduleName,context: Identifier): Import;
  3936. VAR p: Import;
  3937. BEGIN
  3938. p := firstImport;
  3939. WHILE(p#NIL) & ~((moduleName = p.moduleName) & (context = p.context)) DO p := p.nextImport END;
  3940. RETURN p;
  3941. END ImportByModuleName;
  3942. PROCEDURE RemoveImporters*(moduleName,context: Identifier);
  3943. VAR this: Import;
  3944. PROCEDURE Check(p: Import): BOOLEAN;
  3945. VAR result: BOOLEAN;
  3946. BEGIN
  3947. IF (moduleName = p.moduleName) & (context = p.context) THEN
  3948. result := TRUE
  3949. ELSE
  3950. result := p.module.moduleScope.ImportByModuleName(moduleName,context) # NIL;
  3951. END;
  3952. RETURN result
  3953. END Check;
  3954. BEGIN
  3955. WHILE(firstImport # NIL) & Check(firstImport) DO
  3956. firstImport := firstImport.nextImport;
  3957. DEC(numberImports);
  3958. END;
  3959. IF firstImport = NIL THEN lastImport := NIL
  3960. ELSE
  3961. this :=firstImport;
  3962. WHILE(this.nextImport # NIL) DO
  3963. IF Check(this.nextImport) THEN
  3964. this.nextImport := this.nextImport.nextImport;
  3965. DEC(numberImports);
  3966. ELSE
  3967. this := this.nextImport
  3968. END;
  3969. END;
  3970. lastImport := this;
  3971. END;
  3972. END RemoveImporters;
  3973. END ModuleScope;
  3974. (* << MODULE name ['in' context] moduleScope name '.' >> *)
  3975. Module* = OBJECT (Symbol)
  3976. VAR
  3977. sourceName-: Basic.FileName;
  3978. moduleScope-: ModuleScope;
  3979. context-:Identifier; (* modules context *)
  3980. case-: LONGINT; (* module notation in lower or upper case, important for printout and operators *)
  3981. isCellNet-: BOOLEAN;
  3982. firstScope-,lastScope-: Scope; numberScopes-: LONGINT; (* list of all scopes for checker / backend traversal etc. *)
  3983. closingComment-: Comment;
  3984. modifiers-: Modifier;
  3985. PROCEDURE & InitModule( CONST sourceName: ARRAY OF CHAR; position: LONGINT; name: Identifier; scope: ModuleScope; case: LONGINT);
  3986. BEGIN
  3987. InitSymbol(position,name);
  3988. COPY (sourceName, SELF.sourceName);
  3989. moduleScope := scope;
  3990. ASSERT(scope.ownerModule = NIL); (* cannot register twice ! *)
  3991. scope.ownerModule := SELF;
  3992. context := invalidIdentifier;
  3993. SELF.case := case;
  3994. firstScope := NIL; lastScope := NIL; numberScopes := 0;
  3995. SetType(moduleType);
  3996. closingComment := NIL;
  3997. isCellNet := FALSE;
  3998. modifiers := NIL;
  3999. END InitModule;
  4000. PROCEDURE SetCase*(case: LONGINT);
  4001. BEGIN
  4002. SELF.case := case
  4003. END SetCase;
  4004. PROCEDURE SetCellNet*(isCellNet: BOOLEAN);
  4005. BEGIN SELF.isCellNet := isCellNet
  4006. END SetCellNet;
  4007. PROCEDURE SetContext*(context: Identifier);
  4008. BEGIN SELF.context := context;
  4009. END SetContext;
  4010. PROCEDURE SetName*(name: Identifier);
  4011. BEGIN SELF.name := name
  4012. END SetName;
  4013. PROCEDURE SetClosingComment*(comment: Comment);
  4014. BEGIN SELF.closingComment := comment
  4015. END SetClosingComment;
  4016. PROCEDURE SetModifiers*(modifiers: Modifier);
  4017. BEGIN SELF.modifiers := modifiers
  4018. END SetModifiers;
  4019. PROCEDURE AddScope*(c: Scope);
  4020. BEGIN
  4021. IF lastScope= NIL THEN firstScope := c ELSE lastScope.nextScope := c END;
  4022. lastScope := c;
  4023. INC(numberScopes);
  4024. END AddScope;
  4025. PROCEDURE Accept*(v: Visitor);
  4026. VAR position: LONGINT;
  4027. BEGIN position := SELF.position; v.VisitModule(SELF)
  4028. END Accept;
  4029. END Module;
  4030. (** <<expression, expression, ...>> **)
  4031. SymbolList* = OBJECT
  4032. VAR list: Basic.List;
  4033. PROCEDURE & InitList*;
  4034. BEGIN NEW( list,8 );
  4035. END InitList;
  4036. PROCEDURE Length*( ): LONGINT;
  4037. BEGIN RETURN list.Length();
  4038. END Length;
  4039. PROCEDURE AddSymbol*( d: Symbol );
  4040. BEGIN list.Add(d)
  4041. END AddSymbol;
  4042. PROCEDURE GetSymbol*( index: LONGINT ): Symbol;
  4043. VAR p: ANY;
  4044. BEGIN
  4045. p := list.Get(index); RETURN p(Symbol);
  4046. END GetSymbol;
  4047. PROCEDURE SetSymbol*(index: LONGINT; expression: Symbol);
  4048. BEGIN list.Set(index,expression)
  4049. END SetSymbol;
  4050. PROCEDURE RemoveSymbol*(i: LONGINT);
  4051. BEGIN list.RemoveByIndex(i);
  4052. END RemoveSymbol;
  4053. (*
  4054. PROCEDURE Clone*(VAR list: SymbolList);
  4055. VAR i: LONGINT;
  4056. BEGIN
  4057. IF list = NIL THEN NEW(list) END;
  4058. FOR i := 0 TO Length()-1 DO
  4059. list.AddSymbol(CloneSymbol(GetSymbol(i)));
  4060. END;
  4061. END Clone;
  4062. *)
  4063. END SymbolList;
  4064. VAR
  4065. (* invalid items used, for example, by parser and checker *)
  4066. invalidIdentifier-: Identifier;
  4067. invalidQualifiedIdentifier-: QualifiedIdentifier;
  4068. invalidType-: Type;
  4069. invalidExpression-: Expression; (* mapped to invalidDesignator for better error handling in checker *)
  4070. invalidDesignator-: Designator;
  4071. invalidValue-: Value;
  4072. invalidSymbol-: Symbol;
  4073. anonymousIdentifier-: Identifier;
  4074. importType-: Type;
  4075. typeDeclarationType-: Type;
  4076. moduleType-: Type;
  4077. indexListSeparator-: Expression;
  4078. PROCEDURE InitFingerPrint*(VAR fingerprint: FingerPrint);
  4079. BEGIN
  4080. fingerprint.shallowAvailable := FALSE;
  4081. fingerprint.deepAvailable := FALSE;
  4082. fingerprint.shallow := 0;
  4083. fingerprint.private := 0;
  4084. fingerprint.public := 0;
  4085. END InitFingerPrint;
  4086. PROCEDURE NewModule*( CONST sourceName: ARRAY OF CHAR; position: LONGINT; name: Identifier;scope: ModuleScope; case: LONGINT ): Module;
  4087. VAR module: Module;
  4088. BEGIN
  4089. NEW( module, sourceName, position, name, scope, case); RETURN module;
  4090. END NewModule;
  4091. PROCEDURE NewComment*(position: LONGINT; scope: Scope; CONST source: ARRAY OF CHAR; length: LONGINT): Comment;
  4092. VAR comment: Comment;
  4093. BEGIN
  4094. NEW(comment,position,scope,source,length); RETURN comment;
  4095. END NewComment;
  4096. PROCEDURE NewImport*( position: LONGINT; alias, name: Identifier; direct: BOOLEAN): Import;
  4097. VAR import: Import;
  4098. BEGIN
  4099. NEW( import, position, alias, name, direct ); RETURN import
  4100. END NewImport;
  4101. PROCEDURE NewConstant*( position: LONGINT; name: Identifier ): Constant;
  4102. VAR constant: Constant;
  4103. BEGIN
  4104. NEW( constant, position, name ); RETURN constant
  4105. END NewConstant;
  4106. PROCEDURE NewProcedure*( position: LONGINT; name: Identifier; scope: ProcedureScope ): Procedure;
  4107. VAR procedure: Procedure;
  4108. BEGIN
  4109. NEW( procedure, position, name, scope); RETURN procedure
  4110. END NewProcedure;
  4111. PROCEDURE NewBuiltin*(position: LONGINT; name: Identifier; id: LONGINT): Builtin;
  4112. VAR builtin: Builtin;
  4113. BEGIN
  4114. NEW(builtin,position,name,id); RETURN builtin
  4115. END NewBuiltin;
  4116. PROCEDURE NewCustomBuiltin*(position: LONGINT; name: Identifier; id: LONGINT; subType: SHORTINT): CustomBuiltin;
  4117. VAR builtin:CustomBuiltin;
  4118. BEGIN
  4119. NEW(builtin,position,name,id,subType); RETURN builtin
  4120. END NewCustomBuiltin;
  4121. PROCEDURE NewOperator*( position: LONGINT; name: Identifier; scope: ProcedureScope): Operator;
  4122. VAR operator: Operator;
  4123. BEGIN
  4124. NEW( operator, position, name, scope); RETURN operator
  4125. END NewOperator;
  4126. PROCEDURE NewType*(): Type; (* for error handling: invalid Type, is realtime type *)
  4127. VAR type: Type;
  4128. BEGIN
  4129. NEW( type, -1);
  4130. type.SetRealtime(TRUE);
  4131. RETURN type
  4132. END NewType;
  4133. PROCEDURE NewByteType*(sizeInBits: LONGINT): ByteType;
  4134. VAR basicType: ByteType;
  4135. BEGIN
  4136. NEW(basicType, sizeInBits); RETURN basicType;
  4137. END NewByteType;
  4138. PROCEDURE NewAnyType*(sizeInBits: LONGINT): AnyType;
  4139. VAR basicType: AnyType;
  4140. BEGIN
  4141. NEW(basicType, sizeInBits); RETURN basicType;
  4142. END NewAnyType;
  4143. PROCEDURE NewObjectType*(sizeInBits: LONGINT): ObjectType;
  4144. VAR basicType: ObjectType;
  4145. BEGIN
  4146. NEW(basicType, sizeInBits); RETURN basicType;
  4147. END NewObjectType;
  4148. PROCEDURE NewNilType*(sizeInBits: LONGINT): NilType;
  4149. VAR basicType: NilType;
  4150. BEGIN
  4151. NEW(basicType, sizeInBits); RETURN basicType;
  4152. END NewNilType;
  4153. PROCEDURE NewAddressType*(sizeInBits: LONGINT): AddressType;
  4154. VAR basicType: AddressType;
  4155. BEGIN
  4156. NEW(basicType, sizeInBits); RETURN basicType;
  4157. END NewAddressType;
  4158. PROCEDURE NewSizeType*(sizeInBits: LONGINT): SizeType;
  4159. VAR basicType: SizeType;
  4160. BEGIN
  4161. NEW(basicType, sizeInBits); RETURN basicType;
  4162. END NewSizeType;
  4163. PROCEDURE NewBooleanType*(sizeInBits: LONGINT): BooleanType;
  4164. VAR basicType: BooleanType;
  4165. BEGIN
  4166. NEW(basicType, sizeInBits); RETURN basicType;
  4167. END NewBooleanType;
  4168. PROCEDURE NewSetType*(sizeInBits: LONGINT): SetType;
  4169. VAR basicType: SetType;
  4170. BEGIN
  4171. NEW(basicType, sizeInBits); RETURN basicType;
  4172. END NewSetType;
  4173. PROCEDURE NewCharacterType*(sizeInBits: LONGINT): CharacterType;
  4174. VAR basicType: CharacterType;
  4175. BEGIN
  4176. NEW(basicType, sizeInBits); RETURN basicType;
  4177. END NewCharacterType;
  4178. PROCEDURE NewRangeType*(sizeInBits: LONGINT): RangeType;
  4179. VAR basicType: RangeType;
  4180. BEGIN
  4181. NEW(basicType, sizeInBits); RETURN basicType;
  4182. END NewRangeType;
  4183. PROCEDURE NewComplexType*(base: Type): ComplexType;
  4184. VAR basicType: ComplexType;
  4185. BEGIN
  4186. NEW(basicType, base); RETURN basicType;
  4187. END NewComplexType;
  4188. PROCEDURE NewIntegerType*(size: LONGINT; signed: BOOLEAN): IntegerType;
  4189. VAR basicType: IntegerType;
  4190. BEGIN
  4191. NEW(basicType, size, signed); RETURN basicType;
  4192. END NewIntegerType;
  4193. PROCEDURE NewFloatType*(sizeInBits: LONGINT): FloatType;
  4194. VAR basicType: FloatType;
  4195. BEGIN
  4196. NEW(basicType, sizeInBits); RETURN basicType;
  4197. END NewFloatType;
  4198. PROCEDURE NewTypeDeclaration*(position: LONGINT; name: Identifier): TypeDeclaration;
  4199. VAR typeDeclaration: TypeDeclaration;
  4200. BEGIN
  4201. ASSERT(name # invalidIdentifier);
  4202. NEW(typeDeclaration,position,name); RETURN typeDeclaration
  4203. END NewTypeDeclaration;
  4204. PROCEDURE NewStringType*( position: LONGINT; baseType: Type; length: LONGINT): StringType;
  4205. VAR stringType: StringType;
  4206. BEGIN
  4207. NEW( stringType, position, baseType, length); RETURN stringType;
  4208. END NewStringType;
  4209. PROCEDURE NewEnumerationType*( position: LONGINT; scope: Scope; enumerationScope: EnumerationScope): EnumerationType;
  4210. VAR enumerationType: EnumerationType;
  4211. BEGIN
  4212. NEW( enumerationType, position, scope, enumerationScope); RETURN enumerationType;
  4213. END NewEnumerationType;
  4214. PROCEDURE NewArrayType*( position: LONGINT; scope: Scope; form: LONGINT): ArrayType;
  4215. VAR arrayType: ArrayType;
  4216. BEGIN
  4217. NEW( arrayType, position,scope, form); RETURN arrayType;
  4218. END NewArrayType;
  4219. PROCEDURE NewMathArrayType*( position: LONGINT; scope: Scope; form: LONGINT): MathArrayType;
  4220. VAR mathArrayType: MathArrayType;
  4221. BEGIN
  4222. NEW( mathArrayType, position,scope,form); RETURN mathArrayType;
  4223. END NewMathArrayType;
  4224. PROCEDURE NewPointerType*( position: LONGINT; scope: Scope): PointerType;
  4225. VAR pointerType: PointerType;
  4226. BEGIN
  4227. NEW( pointerType, position,scope); RETURN pointerType;
  4228. END NewPointerType;
  4229. PROCEDURE NewPortType*( position: LONGINT; direction: LONGINT; sizeExpression: Expression; scope: Scope): PortType;
  4230. VAR portType: PortType;
  4231. BEGIN
  4232. NEW( portType, position, direction, sizeExpression, scope); RETURN portType;
  4233. END NewPortType;
  4234. PROCEDURE NewRecordType*( position: LONGINT; scope: Scope; recordScope: RecordScope): RecordType;
  4235. VAR recordType: RecordType;
  4236. BEGIN
  4237. NEW( recordType, position, scope, recordScope); RETURN recordType
  4238. END NewRecordType;
  4239. PROCEDURE NewCellType*(position: LONGINT; scope:Scope; cellScope: CellScope): CellType;
  4240. VAR actorType: CellType;
  4241. BEGIN
  4242. NEW(actorType, position, scope, cellScope); RETURN actorType;
  4243. END NewCellType;
  4244. PROCEDURE NewProcedureType*( position: LONGINT; scope: Scope): ProcedureType;
  4245. VAR procedureType: ProcedureType;
  4246. BEGIN
  4247. NEW( procedureType, position,scope); RETURN procedureType;
  4248. END NewProcedureType;
  4249. PROCEDURE NewQualifiedType*( position: LONGINT; scope: Scope; qualifiedIdentifier: QualifiedIdentifier): QualifiedType;
  4250. VAR qualifiedType: QualifiedType;
  4251. BEGIN
  4252. NEW( qualifiedType, position,scope,qualifiedIdentifier ); RETURN qualifiedType
  4253. END NewQualifiedType;
  4254. PROCEDURE NewSymbol*(name: Identifier): Symbol; (* for error handling: invalid Symbol *)
  4255. VAR symbol: Symbol;
  4256. BEGIN
  4257. NEW(symbol,-1,name); RETURN symbol
  4258. END NewSymbol;
  4259. PROCEDURE NewVariable*( position: LONGINT; name: Identifier): Variable;
  4260. VAR variable: Variable;
  4261. BEGIN
  4262. NEW( variable, position, name ); RETURN variable
  4263. END NewVariable;
  4264. PROCEDURE NewQualifiedIdentifier*( position: LONGINT; prefix, suffix: Identifier ): QualifiedIdentifier;
  4265. VAR qualifiedIdentifier: QualifiedIdentifier;
  4266. BEGIN
  4267. NEW( qualifiedIdentifier, position, prefix, suffix ); RETURN qualifiedIdentifier
  4268. END NewQualifiedIdentifier;
  4269. PROCEDURE NewIdentifier*(CONST name: ARRAY OF CHAR): Identifier;
  4270. BEGIN
  4271. RETURN Basic.MakeString(name);
  4272. END NewIdentifier;
  4273. PROCEDURE NewParameter*( position: LONGINT; ownerType:Type ; name: Identifier; passAs: LONGINT): Parameter;
  4274. VAR parameter: Parameter;
  4275. BEGIN
  4276. NEW( parameter, position, ownerType, name, passAs); RETURN parameter;
  4277. END NewParameter;
  4278. PROCEDURE NewProperty*( position: LONGINT; name: Identifier): Property;
  4279. VAR property: Property;
  4280. BEGIN
  4281. NEW( property, position, name); RETURN property;
  4282. END NewProperty;
  4283. PROCEDURE NewExpressionList*(): ExpressionList;
  4284. VAR expressionList: ExpressionList;
  4285. BEGIN
  4286. NEW(expressionList); RETURN expressionList
  4287. END NewExpressionList;
  4288. PROCEDURE CloneExpressionList*(l: ExpressionList): ExpressionList;
  4289. VAR copy: ExpressionList;
  4290. BEGIN
  4291. IF l = NIL THEN RETURN NIL ELSE l.Clone(copy); RETURN copy END;
  4292. END CloneExpressionList;
  4293. PROCEDURE NewDesignator*(): Designator; (* for error handling: invalid Designator *)
  4294. VAR designator: Designator;
  4295. BEGIN
  4296. NEW(designator,-1); RETURN designator;
  4297. END NewDesignator;
  4298. PROCEDURE NewIdentifierDesignator*( position: LONGINT; identifier: Identifier): IdentifierDesignator;
  4299. VAR identifierDesignator: IdentifierDesignator;
  4300. BEGIN
  4301. NEW( identifierDesignator, position, identifier ); RETURN identifierDesignator
  4302. END NewIdentifierDesignator;
  4303. PROCEDURE NewSelectorDesignator*( position: LONGINT; left: Designator; name: Identifier ): SelectorDesignator;
  4304. VAR selectorDesignator: SelectorDesignator;
  4305. BEGIN
  4306. NEW( selectorDesignator, position, left, name ); RETURN selectorDesignator
  4307. END NewSelectorDesignator;
  4308. PROCEDURE NewParameterDesignator*( position: LONGINT; left: Designator; expressionList: ExpressionList ): ParameterDesignator;
  4309. VAR parameterDesignator: ParameterDesignator;
  4310. BEGIN
  4311. NEW( parameterDesignator,position, left, expressionList ); RETURN parameterDesignator
  4312. END NewParameterDesignator;
  4313. PROCEDURE NewArrowDesignator*( position: LONGINT; left: Designator ): ArrowDesignator;
  4314. VAR dereferenceDesignator: ArrowDesignator;
  4315. BEGIN
  4316. NEW( dereferenceDesignator, position, left ); RETURN dereferenceDesignator;
  4317. END NewArrowDesignator;
  4318. PROCEDURE NewBracketDesignator*( position: LONGINT; left: Designator; expressionList: ExpressionList ): BracketDesignator;
  4319. VAR bracketDesignator: BracketDesignator;
  4320. BEGIN
  4321. NEW( bracketDesignator, position, left, expressionList ); RETURN bracketDesignator
  4322. END NewBracketDesignator;
  4323. PROCEDURE NewSymbolDesignator*( position: LONGINT; left: Designator; symbol: Symbol ): SymbolDesignator;
  4324. VAR symbolDesignator: SymbolDesignator;
  4325. BEGIN
  4326. NEW( symbolDesignator, position, left, symbol); RETURN symbolDesignator
  4327. END NewSymbolDesignator;
  4328. PROCEDURE NewIndexDesignator*( position: LONGINT; left: Designator): IndexDesignator;
  4329. VAR indexDesignator: IndexDesignator;
  4330. BEGIN
  4331. NEW( indexDesignator, position, left); RETURN indexDesignator
  4332. END NewIndexDesignator;
  4333. PROCEDURE NewProcedureCallDesignator*(position: LONGINT; left: Designator; parameters: ExpressionList): ProcedureCallDesignator;
  4334. VAR procedureCallDesignator: ProcedureCallDesignator;
  4335. BEGIN
  4336. NEW(procedureCallDesignator, position, left, parameters); RETURN procedureCallDesignator
  4337. END NewProcedureCallDesignator;
  4338. PROCEDURE NewBuiltinCallDesignator*(position: LONGINT; id: LONGINT; left: Designator; parameters: ExpressionList): BuiltinCallDesignator;
  4339. VAR builtinCallDesignator: BuiltinCallDesignator;
  4340. BEGIN
  4341. NEW(builtinCallDesignator, position, id, left,parameters); RETURN builtinCallDesignator
  4342. END NewBuiltinCallDesignator;
  4343. PROCEDURE NewTypeGuardDesignator*(position: LONGINT; left: Designator; type: Type): TypeGuardDesignator;
  4344. VAR guardDesignator: TypeGuardDesignator;
  4345. BEGIN
  4346. NEW(guardDesignator,position,left,type); RETURN guardDesignator;
  4347. END NewTypeGuardDesignator;
  4348. PROCEDURE NewDereferenceDesignator*( position: LONGINT; left: Designator): DereferenceDesignator;
  4349. VAR dereferenceDesignator: DereferenceDesignator;
  4350. BEGIN
  4351. NEW( dereferenceDesignator, position, left); RETURN dereferenceDesignator
  4352. END NewDereferenceDesignator;
  4353. PROCEDURE NewSupercallDesignator*( position: LONGINT; left: Designator): SupercallDesignator;
  4354. VAR supercallDesignator: SupercallDesignator;
  4355. BEGIN
  4356. NEW( supercallDesignator, position, left); RETURN supercallDesignator
  4357. END NewSupercallDesignator;
  4358. PROCEDURE NewSelfDesignator*( position: LONGINT): SelfDesignator;
  4359. VAR selfDesignator: SelfDesignator;
  4360. BEGIN
  4361. NEW( selfDesignator, position); RETURN selfDesignator
  4362. END NewSelfDesignator;
  4363. PROCEDURE NewResultDesignator*( position: LONGINT): ResultDesignator;
  4364. VAR resultDesignator: ResultDesignator;
  4365. BEGIN
  4366. NEW( resultDesignator, position); RETURN resultDesignator
  4367. END NewResultDesignator;
  4368. PROCEDURE NewExpression*(): Expression; (* for error handling: invalid Expression *)
  4369. VAR expression: Expression;
  4370. BEGIN
  4371. NEW(expression,-1); RETURN expression;
  4372. END NewExpression;
  4373. PROCEDURE CloneExpression*(e: Expression): Expression;
  4374. VAR copy: Expression;
  4375. BEGIN
  4376. IF e = NIL THEN
  4377. RETURN NIL
  4378. ELSE
  4379. copy := e.Clone();
  4380. copy.type := e.type;
  4381. copy.assignable := e.assignable;
  4382. copy.position := e.position;
  4383. copy.state := e.state;
  4384. IF e.resolved = e THEN copy.resolved := copy(Value);
  4385. ELSIF e.resolved # NIL THEN copy.resolved := CloneExpression(e.resolved)(Value);
  4386. END;
  4387. RETURN copy
  4388. END;
  4389. END CloneExpression;
  4390. PROCEDURE CloneDesignator*(e: Expression): Designator;
  4391. BEGIN
  4392. IF e = NIL THEN RETURN NIL ELSE RETURN CloneExpression(e)(Designator) END;
  4393. END CloneDesignator;
  4394. PROCEDURE NewElement*( position: LONGINT; from,to: Expression ): Expression;
  4395. BEGIN
  4396. IF from = to THEN RETURN from
  4397. ELSE RETURN NewRangeExpression(position,from,to,NIL)
  4398. END;
  4399. END NewElement;
  4400. PROCEDURE NewSet*( position: LONGINT ): Set;
  4401. VAR set: Set;
  4402. BEGIN NEW( set, position ); RETURN set
  4403. END NewSet;
  4404. PROCEDURE NewMathArrayExpression*( position: LONGINT ): MathArrayExpression;
  4405. VAR mathArrayExpression: MathArrayExpression;
  4406. BEGIN NEW( mathArrayExpression, position ); RETURN mathArrayExpression
  4407. END NewMathArrayExpression;
  4408. PROCEDURE NewBinaryExpression*( position: LONGINT; left, right: Expression; operator: LONGINT ): BinaryExpression;
  4409. VAR binaryExpression: BinaryExpression;
  4410. BEGIN
  4411. NEW( binaryExpression, position, left, right, operator ); RETURN binaryExpression;
  4412. END NewBinaryExpression;
  4413. PROCEDURE NewRangeExpression*(position: LONGINT; first, last, step: Expression): RangeExpression;
  4414. VAR rangeExpression: RangeExpression;
  4415. BEGIN
  4416. NEW(rangeExpression, position, first, last, step); RETURN rangeExpression
  4417. END NewRangeExpression;
  4418. PROCEDURE NewTensorRangeExpression*(position: LONGINT): TensorRangeExpression;
  4419. VAR tensorRangeExpression: TensorRangeExpression;
  4420. BEGIN
  4421. NEW(tensorRangeExpression,position); RETURN tensorRangeExpression
  4422. END NewTensorRangeExpression;
  4423. PROCEDURE NewUnaryExpression*( position: LONGINT; operand: Expression; operator: LONGINT ): UnaryExpression;
  4424. VAR unaryExpression: UnaryExpression;
  4425. BEGIN
  4426. NEW( unaryExpression, position, operand, operator ); RETURN unaryExpression;
  4427. END NewUnaryExpression;
  4428. PROCEDURE NewConversion*( position: LONGINT; expression: Expression; type: Type; typeExpression: Expression): Conversion;
  4429. VAR conversion: Conversion;
  4430. BEGIN
  4431. ASSERT(type # NIL);
  4432. NEW( conversion, position, expression,type, typeExpression ); RETURN conversion;
  4433. END NewConversion;
  4434. PROCEDURE NewValue*(): Value;(* for error handling: invalid Value *)
  4435. VAR value: Value;
  4436. BEGIN
  4437. NEW(value,-1); RETURN value;
  4438. END NewValue;
  4439. PROCEDURE NewIntegerValue*( position: LONGINT; value: HUGEINT): IntegerValue;
  4440. VAR integerValue: IntegerValue;
  4441. BEGIN
  4442. NEW( integerValue, position, value); RETURN integerValue;
  4443. END NewIntegerValue;
  4444. PROCEDURE NewCharacterValue*( position: LONGINT; value: CHAR): CharacterValue;
  4445. VAR characterValue: CharacterValue;
  4446. BEGIN
  4447. NEW( characterValue, position, value); RETURN characterValue;
  4448. END NewCharacterValue;
  4449. PROCEDURE NewSetValue*(position: LONGINT; value: SET): SetValue;
  4450. VAR setValue: SetValue;
  4451. BEGIN
  4452. NEW(setValue, position, value); RETURN setValue
  4453. END NewSetValue;
  4454. PROCEDURE NewMathArrayValue*( position: LONGINT ): MathArrayValue;
  4455. VAR mathArrayValue: MathArrayValue;
  4456. BEGIN NEW( mathArrayValue, position ); RETURN mathArrayValue
  4457. END NewMathArrayValue;
  4458. PROCEDURE NewRealValue*( position: LONGINT; value: LONGREAL): RealValue;
  4459. VAR realValue: RealValue;
  4460. BEGIN
  4461. NEW( realValue, position, value); RETURN realValue
  4462. END NewRealValue;
  4463. PROCEDURE NewComplexValue*( position: LONGINT; realValue, imagValue: LONGREAL): ComplexValue;
  4464. VAR complexValue: ComplexValue;
  4465. BEGIN
  4466. NEW( complexValue, position, realValue, imagValue); RETURN complexValue
  4467. END NewComplexValue;
  4468. PROCEDURE NewStringValue*( position: LONGINT; value: String): StringValue;
  4469. VAR stringValue: StringValue;
  4470. BEGIN
  4471. NEW( stringValue, position, value ); RETURN stringValue
  4472. END NewStringValue;
  4473. PROCEDURE NewBooleanValue*( position: LONGINT; value: BOOLEAN): BooleanValue;
  4474. VAR booleanValue: BooleanValue;
  4475. BEGIN
  4476. NEW( booleanValue, position, value ); RETURN booleanValue;
  4477. END NewBooleanValue;
  4478. PROCEDURE NewNilValue*( position: LONGINT ): NilValue;
  4479. VAR nilValue: NilValue;
  4480. BEGIN
  4481. NEW( nilValue, position ); RETURN nilValue
  4482. END NewNilValue;
  4483. PROCEDURE NewEnumerationValue*( position: LONGINT; value: LONGINT ): EnumerationValue;
  4484. VAR enumeratorValue: EnumerationValue;
  4485. BEGIN
  4486. NEW( enumeratorValue, position, value ); RETURN enumeratorValue
  4487. END NewEnumerationValue;
  4488. PROCEDURE NewStatement*(outer: Statement): Statement; (* for error handling: invalid Statement *)
  4489. VAR statement: Statement;
  4490. BEGIN NEW(statement,-1,outer); RETURN statement;
  4491. END NewStatement;
  4492. PROCEDURE CloneStatement*(statement: Statement): Statement;
  4493. BEGIN IF statement = NIL THEN RETURN NIL ELSE RETURN statement.Clone() END
  4494. END CloneStatement;
  4495. PROCEDURE NewStatementSequence*(): StatementSequence;
  4496. VAR statementSequence: StatementSequence;
  4497. BEGIN
  4498. NEW( statementSequence); RETURN statementSequence
  4499. END NewStatementSequence;
  4500. PROCEDURE CloneStatementSequence*(statementSequence: StatementSequence): StatementSequence;
  4501. VAR copy: StatementSequence;
  4502. BEGIN IF statementSequence = NIL THEN RETURN NIL ELSE statementSequence.Clone(copy); RETURN copy END
  4503. END CloneStatementSequence;
  4504. PROCEDURE NewModifier*(position: LONGINT; identifier: Identifier; expression: Expression): Modifier;
  4505. VAR blockModifier: Modifier;
  4506. BEGIN
  4507. NEW(blockModifier,position,identifier,expression); RETURN blockModifier
  4508. END NewModifier;
  4509. PROCEDURE NewStatementBlock*( position: LONGINT ; outer: Statement): StatementBlock;
  4510. VAR statementBlock: StatementBlock;
  4511. BEGIN
  4512. NEW( statementBlock, position, outer ); RETURN statementBlock
  4513. END NewStatementBlock;
  4514. PROCEDURE NewStatementDesignator*(position: LONGINT; s: Statement): StatementDesignator;
  4515. VAR statementDesignator: StatementDesignator;
  4516. BEGIN
  4517. NEW( statementDesignator, position, s); RETURN statementDesignator
  4518. END NewStatementDesignator;
  4519. PROCEDURE NewBody*( position: LONGINT ; scope: ProcedureScope): Body;
  4520. VAR body: Body;
  4521. BEGIN
  4522. NEW( body, position,scope ); RETURN body
  4523. END NewBody;
  4524. PROCEDURE NewIfPart*(): IfPart;
  4525. VAR ifPart: IfPart;
  4526. BEGIN
  4527. NEW( ifPart); RETURN ifPart
  4528. END NewIfPart;
  4529. PROCEDURE NewIfStatement*( position: LONGINT ; outer: Statement): IfStatement;
  4530. VAR ifStatement: IfStatement;
  4531. BEGIN
  4532. NEW( ifStatement, position,outer ); RETURN ifStatement
  4533. END NewIfStatement;
  4534. PROCEDURE NewAssignment*( position: LONGINT; left: Designator; right: Expression; outer: Statement): Assignment;
  4535. VAR assignment: Assignment;
  4536. BEGIN
  4537. NEW( assignment, position, left, right,outer ); RETURN assignment
  4538. END NewAssignment;
  4539. PROCEDURE NewCommunicationStatement*( position: LONGINT; send: BOOLEAN; left: Designator; right: Expression; outer: Statement): CommunicationStatement;
  4540. VAR communication: CommunicationStatement;
  4541. BEGIN
  4542. NEW( communication, position, send, left, right,outer ); RETURN communication
  4543. END NewCommunicationStatement;
  4544. PROCEDURE NewProcedureCallStatement*(position: LONGINT; call: Designator; outer: Statement): ProcedureCallStatement;
  4545. VAR caller: ProcedureCallStatement;
  4546. BEGIN
  4547. NEW(caller,position,call,outer); RETURN caller
  4548. END NewProcedureCallStatement;
  4549. PROCEDURE NewCaseStatement*( position: LONGINT ; outer: Statement): CaseStatement;
  4550. VAR caseStatement: CaseStatement;
  4551. BEGIN
  4552. NEW( caseStatement, position,outer ); RETURN caseStatement
  4553. END NewCaseStatement;
  4554. PROCEDURE NewCasePart*(): CasePart;
  4555. VAR casePart: CasePart;
  4556. BEGIN
  4557. NEW( casePart); RETURN casePart
  4558. END NewCasePart;
  4559. PROCEDURE NewWithPart*(): WithPart;
  4560. VAR withPart: WithPart;
  4561. BEGIN
  4562. NEW( withPart); RETURN withPart
  4563. END NewWithPart;
  4564. PROCEDURE NewWithStatement*( position: LONGINT; outer: Statement): WithStatement;
  4565. VAR withStatement: WithStatement;
  4566. BEGIN
  4567. NEW( withStatement, position, outer ); RETURN withStatement
  4568. END NewWithStatement;
  4569. PROCEDURE NewWhileStatement*( position: LONGINT ; outer: Statement): WhileStatement;
  4570. VAR whileStatement: WhileStatement;
  4571. BEGIN
  4572. NEW( whileStatement, position,outer ); RETURN whileStatement
  4573. END NewWhileStatement;
  4574. PROCEDURE NewRepeatStatement*( position: LONGINT ; outer: Statement): RepeatStatement;
  4575. VAR repeatStatement: RepeatStatement;
  4576. BEGIN
  4577. NEW( repeatStatement, position ,outer); RETURN repeatStatement
  4578. END NewRepeatStatement;
  4579. PROCEDURE NewForStatement*( position: LONGINT; outer: Statement ): ForStatement;
  4580. VAR forStatement: ForStatement;
  4581. BEGIN
  4582. NEW( forStatement, position,outer ); RETURN forStatement
  4583. END NewForStatement;
  4584. PROCEDURE NewLoopStatement*( position: LONGINT ; outer: Statement): LoopStatement;
  4585. VAR loopStatement: LoopStatement;
  4586. BEGIN
  4587. NEW( loopStatement, position ,outer); RETURN loopStatement
  4588. END NewLoopStatement;
  4589. PROCEDURE NewExitableBlock*( position: LONGINT ; outer: Statement): ExitableBlock;
  4590. VAR loopStatement: ExitableBlock;
  4591. BEGIN
  4592. NEW( loopStatement, position ,outer); RETURN loopStatement
  4593. END NewExitableBlock;
  4594. PROCEDURE NewExitStatement*( position: LONGINT ; outer: Statement): ExitStatement;
  4595. VAR exitStatement: ExitStatement;
  4596. BEGIN
  4597. NEW( exitStatement, position, outer); RETURN exitStatement
  4598. END NewExitStatement;
  4599. PROCEDURE NewReturnStatement*( position: LONGINT; outer: Statement ): ReturnStatement;
  4600. VAR returnStatement: ReturnStatement;
  4601. BEGIN
  4602. NEW( returnStatement, position,outer ); RETURN returnStatement
  4603. END NewReturnStatement;
  4604. PROCEDURE NewAwaitStatement*( position: LONGINT; outer: Statement ): AwaitStatement;
  4605. VAR awaitStatement: AwaitStatement;
  4606. BEGIN
  4607. NEW( awaitStatement, position, outer ); RETURN awaitStatement
  4608. END NewAwaitStatement;
  4609. PROCEDURE NewCode*(position: LONGINT; outer: Statement): Code;
  4610. VAR code: Code;
  4611. BEGIN
  4612. NEW(code,position,outer); RETURN code
  4613. END NewCode;
  4614. PROCEDURE NewProcedureScope*(outer: Scope): ProcedureScope;
  4615. VAR scope: ProcedureScope;
  4616. BEGIN NEW(scope,outer); RETURN scope
  4617. END NewProcedureScope;
  4618. PROCEDURE NewModuleScope*(): ModuleScope;
  4619. VAR scope: ModuleScope;
  4620. BEGIN NEW(scope); RETURN scope
  4621. END NewModuleScope;
  4622. PROCEDURE NewRecordScope*(outer: Scope): RecordScope;
  4623. VAR scope: RecordScope;
  4624. BEGIN NEW(scope,outer); RETURN scope
  4625. END NewRecordScope;
  4626. PROCEDURE NewCellScope*(outer: Scope): CellScope;
  4627. VAR scope: CellScope;
  4628. BEGIN NEW(scope,outer); RETURN scope
  4629. END NewCellScope;
  4630. PROCEDURE NewEnumerationScope*(outer: Scope): EnumerationScope;
  4631. VAR scope: EnumerationScope;
  4632. BEGIN NEW(scope,outer); RETURN scope
  4633. END NewEnumerationScope;
  4634. PROCEDURE Init;
  4635. BEGIN;
  4636. invalidIdentifier := Basic.invalidString;
  4637. invalidQualifiedIdentifier := NewQualifiedIdentifier(-1,invalidIdentifier,Basic.emptyString);
  4638. invalidType := NewType();
  4639. invalidDesignator := NewDesignator();
  4640. invalidDesignator.SetType(invalidType);
  4641. invalidExpression := invalidDesignator;
  4642. invalidValue := NewValue();
  4643. invalidSymbol := NewSymbol(NewIdentifier(""));
  4644. invalidSymbol.SetType(invalidType);
  4645. importType := NewType();
  4646. importType.SetState(Resolved);
  4647. typeDeclarationType := NewType();
  4648. typeDeclarationType.SetState(Resolved);
  4649. moduleType := NewType();
  4650. moduleType.SetState(Resolved);
  4651. anonymousIdentifier := NewIdentifier("");
  4652. indexListSeparator := NewDesignator();
  4653. indexListSeparator.SetType(invalidType);
  4654. END Init;
  4655. BEGIN
  4656. Init;
  4657. END FoxSyntaxTree.