FoxSyntaxTree.Mod 159 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832
  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 := 0;
  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 SetAlignmentInBits*(alignmentInBits: LONGINT);
  328. BEGIN SELF.alignmentInBits := alignmentInBits
  329. END SetAlignmentInBits;
  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. modifiers-: Modifier;
  1122. isObject-,isProtected: BOOLEAN;
  1123. (* a math array type describing an object's array structure; NIL if the type does not exhibit an array structure *)
  1124. arrayStructure-: MathArrayType;
  1125. (* list of all operators needed to access an array-structured object type *)
  1126. arrayAccessOperators-: ArrayAccessOperators;
  1127. PROCEDURE & InitRecordType( position: LONGINT; scope: Scope; recordScope: RecordScope);
  1128. BEGIN
  1129. InitType( position);
  1130. SELF.scope := scope;
  1131. baseType := NIL;
  1132. pointerType := NIL;
  1133. SELF.recordScope := recordScope;
  1134. ASSERT(recordScope # NIL);
  1135. ASSERT(recordScope.ownerRecord = NIL); (* cannot register twice ! *)
  1136. recordScope.ownerRecord := SELF;
  1137. isObject := FALSE; isProtected := FALSE;
  1138. arrayStructure := NIL;
  1139. modifiers := NIL;
  1140. END InitRecordType;
  1141. PROCEDURE SetModifiers*(flag: Modifier);
  1142. BEGIN SELF.modifiers := flag;
  1143. END SetModifiers;
  1144. PROCEDURE SetBaseType*( type: Type );
  1145. BEGIN
  1146. baseType := type; IF (baseType # NIL) & (baseType.hasPointers) THEN hasPointers := TRUE END;
  1147. END SetBaseType;
  1148. PROCEDURE SetPointerType*(pointerType: PointerType);
  1149. BEGIN SELF.pointerType := pointerType
  1150. END SetPointerType;
  1151. PROCEDURE IsObject*(isObject: BOOLEAN);
  1152. BEGIN SELF.isObject := isObject
  1153. END IsObject;
  1154. PROCEDURE IsActive*(): BOOLEAN;
  1155. VAR base: RecordType;
  1156. BEGIN
  1157. IF (recordScope.bodyProcedure # NIL) & (recordScope.bodyProcedure.procedureScope.body # NIL) & (recordScope.bodyProcedure.procedureScope.body.isActive) THEN RETURN TRUE END;
  1158. base := GetBaseRecord();
  1159. IF base # NIL THEN RETURN base.IsActive() END;
  1160. RETURN FALSE
  1161. END IsActive;
  1162. PROCEDURE IsProtected*(): BOOLEAN;
  1163. VAR base: RecordType;
  1164. BEGIN
  1165. IF isProtected THEN RETURN TRUE END;
  1166. base := GetBaseRecord();
  1167. IF base # NIL THEN RETURN base.IsProtected() END;
  1168. RETURN FALSE
  1169. END IsProtected;
  1170. PROCEDURE SetProtected*(protected: BOOLEAN);
  1171. BEGIN SELF.isProtected := protected
  1172. END SetProtected;
  1173. PROCEDURE Level*():LONGINT;
  1174. VAR type: RecordType; res: LONGINT;
  1175. BEGIN
  1176. type := SELF;
  1177. res := 0;
  1178. WHILE (type # NIL) & (type.baseType # NIL) DO
  1179. INC(res);
  1180. type := type.GetBaseRecord();
  1181. END;
  1182. RETURN res;
  1183. END Level;
  1184. PROCEDURE GetBaseRecord*():RecordType;
  1185. BEGIN
  1186. IF baseType = NIL THEN RETURN NIL; END;
  1187. IF baseType.resolved IS RecordType THEN
  1188. RETURN baseType.resolved(RecordType);
  1189. ELSIF baseType.resolved IS PointerType THEN
  1190. IF baseType.resolved(PointerType).pointerBase.resolved # NIL THEN
  1191. RETURN baseType.resolved(PointerType).pointerBase.resolved(RecordType);
  1192. END;
  1193. END;
  1194. RETURN NIL;
  1195. END GetBaseRecord;
  1196. PROCEDURE Extends*(this: Type): BOOLEAN;
  1197. VAR result: BOOLEAN; extension: Type;
  1198. BEGIN
  1199. result := FALSE;
  1200. IF this = SELF THEN result := TRUE
  1201. ELSIF this IS RecordType THEN
  1202. IF (baseType # NIL) THEN
  1203. extension := baseType.resolved;
  1204. IF extension IS PointerType THEN
  1205. result := extension(PointerType).Extends(this)
  1206. ELSIF extension IS RecordType THEN
  1207. result := extension(RecordType).Extends(this)
  1208. END;
  1209. END;
  1210. END;
  1211. RETURN result
  1212. END Extends;
  1213. PROCEDURE SameType*(this: Type): BOOLEAN;
  1214. BEGIN RETURN (this = SELF)
  1215. END SameType;
  1216. PROCEDURE CompatibleTo*(to: Type): BOOLEAN;
  1217. BEGIN RETURN Extends(to)
  1218. END CompatibleTo;
  1219. PROCEDURE SetArrayStructure*(arrayStructure: MathArrayType);
  1220. BEGIN SELF.arrayStructure := arrayStructure
  1221. END SetArrayStructure;
  1222. PROCEDURE SetArrayAccessOperators*(arrayAccessOperators: ArrayAccessOperators);
  1223. BEGIN SELF.arrayAccessOperators := arrayAccessOperators
  1224. END SetArrayAccessOperators;
  1225. PROCEDURE HasArrayStructure*(): BOOLEAN;
  1226. BEGIN RETURN (arrayStructure # NIL)
  1227. END HasArrayStructure
  1228. ;
  1229. PROCEDURE IsComposite(): BOOLEAN;
  1230. BEGIN RETURN TRUE
  1231. END IsComposite;
  1232. PROCEDURE NeedsTrace*(): BOOLEAN;
  1233. BEGIN RETURN recordScope.NeedsTrace();
  1234. END NeedsTrace;
  1235. PROCEDURE Accept*(v: Visitor);
  1236. VAR position: LONGINT;
  1237. BEGIN position := SELF.position; v.VisitRecordType(SELF)
  1238. END Accept;
  1239. PROCEDURE IsRecordType(): BOOLEAN;
  1240. BEGIN
  1241. RETURN TRUE;
  1242. END IsRecordType;
  1243. END RecordType;
  1244. CellType*=OBJECT (Type)
  1245. VAR
  1246. firstParameter-,lastParameter-: Parameter; numberParameters-: LONGINT; (* parameters *)
  1247. firstProperty-, lastProperty-: Property; numberProperties: LONGINT; (* capabilities *)
  1248. cellScope-: CellScope;
  1249. isCellNet-: BOOLEAN;
  1250. modifiers-: Modifier;
  1251. baseType-: Type;
  1252. PROCEDURE &InitCellType(position: LONGINT; scope: Scope; cellScope: CellScope);
  1253. BEGIN
  1254. InitType(position);
  1255. SELF.scope := scope;
  1256. numberParameters := 0; firstParameter := NIL; lastParameter := NIL;
  1257. numberProperties := 0; firstProperty := NIL; lastProperty := NIL;
  1258. SELF.cellScope := cellScope;
  1259. isCellNet := FALSE;
  1260. baseType := NIL;
  1261. END InitCellType;
  1262. PROCEDURE SetBaseType*(base: Type);
  1263. BEGIN
  1264. baseType := base;
  1265. END SetBaseType;
  1266. PROCEDURE GetBaseValueType*(): Type;
  1267. BEGIN
  1268. IF baseType = NIL THEN
  1269. RETURN NIL
  1270. ELSIF baseType.resolved IS PointerType THEN
  1271. RETURN baseType.resolved(PointerType).pointerBase.resolved
  1272. ELSE
  1273. RETURN baseType.resolved;
  1274. END;
  1275. END GetBaseValueType;
  1276. PROCEDURE GetBaseRecord*():RecordType;
  1277. BEGIN
  1278. IF baseType = NIL THEN RETURN NIL; END;
  1279. IF baseType.resolved IS CellType THEN
  1280. RETURN baseType.resolved(CellType).GetBaseRecord();
  1281. ELSIF baseType.resolved IS RecordType THEN
  1282. RETURN baseType.resolved(RecordType);
  1283. ELSIF baseType.resolved IS PointerType THEN
  1284. IF baseType.resolved(PointerType).pointerBase.resolved # NIL THEN
  1285. RETURN baseType.resolved(PointerType).pointerBase.resolved(RecordType);
  1286. END;
  1287. END;
  1288. RETURN NIL;
  1289. END GetBaseRecord;
  1290. PROCEDURE AddParameter*(p: Parameter);
  1291. BEGIN
  1292. ASSERT(p # NIL);
  1293. IF lastParameter= NIL THEN firstParameter := p ELSE lastParameter.nextParameter := p; p.prevParameter := lastParameter; END;
  1294. lastParameter := p;
  1295. INC(numberParameters);
  1296. END AddParameter;
  1297. PROCEDURE AddProperty*(p: Property);
  1298. BEGIN
  1299. ASSERT(p # NIL);
  1300. IF lastProperty= NIL THEN firstProperty := p ELSE lastProperty.nextProperty := p; p.prevProperty := lastProperty; END;
  1301. lastProperty := p;
  1302. INC(numberProperties);
  1303. END AddProperty;
  1304. PROCEDURE FindParameter*(identifier: Identifier): Parameter;
  1305. VAR p: Parameter;
  1306. BEGIN
  1307. p := NIL;
  1308. IF (baseType # NIL) & (baseType.resolved IS CellType) THEN
  1309. p := baseType.resolved(CellType).FindParameter(identifier);
  1310. END;
  1311. IF p = NIL THEN
  1312. p := firstParameter;
  1313. WHILE(p#NIL) & (p.name # identifier) DO p := p.nextParameter END;
  1314. END;
  1315. RETURN p;
  1316. END FindParameter;
  1317. PROCEDURE FindProperty*(identifier: Identifier): Property;
  1318. VAR p: Property;
  1319. BEGIN
  1320. p := NIL;
  1321. IF (baseType # NIL) & (baseType.resolved IS CellType) THEN
  1322. p := baseType.resolved(CellType).FindProperty(identifier);
  1323. END;
  1324. IF p = NIL THEN
  1325. p := firstProperty;
  1326. WHILE(p#NIL) & (p.name # identifier) DO p := p.nextProperty END;
  1327. END;
  1328. RETURN p;
  1329. END FindProperty;
  1330. PROCEDURE SetModifiers*(flag: Modifier);
  1331. BEGIN SELF.modifiers := flag;
  1332. END SetModifiers;
  1333. PROCEDURE IsCellNet*(t: BOOLEAN);
  1334. BEGIN isCellNet := t
  1335. END IsCellNet;
  1336. PROCEDURE SameType*(this: Type): BOOLEAN;
  1337. BEGIN RETURN this = SELF
  1338. END SameType;
  1339. PROCEDURE CompatibleTo*(to: Type): BOOLEAN;
  1340. BEGIN RETURN SameType(to)
  1341. END CompatibleTo;
  1342. PROCEDURE IsComposite(): BOOLEAN;
  1343. BEGIN RETURN TRUE
  1344. END IsComposite;
  1345. PROCEDURE Accept*(v: Visitor);
  1346. VAR position: LONGINT;
  1347. BEGIN position := SELF.position; v.VisitCellType(SELF)
  1348. END Accept;
  1349. END CellType;
  1350. (** <<procedureType = PROCEDURE [{DELEGATE}] (firstParameter .. lastParameter): returnType>>
  1351. also used as type for procedures
  1352. **)
  1353. ProcedureType* = OBJECT (Type)
  1354. VAR
  1355. modifiers-: Modifier; (* set by the parser *)
  1356. returnType-: Type;
  1357. returnTypeModifiers-: Modifier;
  1358. hasUntracedReturn-: BOOLEAN;
  1359. firstParameter-,lastParameter-: Parameter; numberParameters-: LONGINT; (* parameters *)
  1360. returnParameter-: Parameter; (* not really necessary in syntax tree but very handy for backends *)
  1361. isDelegate-,isInterrupt-,noPAF-,noReturn-: BOOLEAN;
  1362. pcOffset-: LONGINT; (* PC offset: used for ARM interrupt procedures *)
  1363. callingConvention-: LONGINT;
  1364. stackAlignment-: LONGINT;
  1365. parameterOffset-: LONGINT; (* stack parameter offset caused by parameters on stack *)
  1366. PROCEDURE & InitProcedureType( position: LONGINT; scope: Scope);
  1367. BEGIN
  1368. InitType( position);
  1369. SELF.scope := scope;
  1370. modifiers := NIL;
  1371. firstParameter := NIL; lastParameter := NIL; numberParameters := 0; returnParameter := NIL;
  1372. returnType := NIL;
  1373. stackAlignment := 1;
  1374. isDelegate := FALSE; isInterrupt := FALSE; noPAF := FALSE;
  1375. callingConvention := OberonCallingConvention;
  1376. parameterOffset := 0;
  1377. pcOffset := 0;
  1378. hasUntracedReturn := FALSE;
  1379. returnTypeModifiers := NIL;
  1380. END InitProcedureType;
  1381. PROCEDURE SetNoPAF*(noPAF: BOOLEAN);
  1382. BEGIN SELF.noPAF := noPAF
  1383. END SetNoPAF;
  1384. PROCEDURE SetNoReturn*(noReturn: BOOLEAN);
  1385. BEGIN SELF.noReturn := noReturn
  1386. END SetNoReturn;
  1387. PROCEDURE SetPcOffset*(pcOffset: LONGINT);
  1388. BEGIN SELF.pcOffset := pcOffset
  1389. END SetPcOffset;
  1390. PROCEDURE SetInterrupt*(isInterrupt: BOOLEAN);
  1391. BEGIN SELF.isInterrupt := isInterrupt
  1392. END SetInterrupt;
  1393. PROCEDURE SetModifiers*(flags: Modifier);
  1394. BEGIN modifiers := flags
  1395. END SetModifiers;
  1396. PROCEDURE SetReturnTypeModifiers*(flags: Modifier);
  1397. BEGIN returnTypeModifiers := flags
  1398. END SetReturnTypeModifiers;
  1399. PROCEDURE SetDelegate*(delegate: BOOLEAN);
  1400. BEGIN SELF.isDelegate := delegate; SELF.hasPointers := delegate;
  1401. END SetDelegate;
  1402. PROCEDURE SetUntracedReturn*(untraced: BOOLEAN);
  1403. BEGIN
  1404. hasUntracedReturn := untraced;
  1405. END SetUntracedReturn;
  1406. PROCEDURE SetStackAlignment*(alignment: LONGINT);
  1407. BEGIN
  1408. stackAlignment := alignment;
  1409. END SetStackAlignment;
  1410. PROCEDURE SetParameterOffset*(ofs: LONGINT);
  1411. BEGIN parameterOffset := ofs
  1412. END SetParameterOffset;
  1413. PROCEDURE SetReturnParameter*(parameter: Parameter);
  1414. BEGIN returnParameter := parameter
  1415. END SetReturnParameter;
  1416. PROCEDURE SetCallingConvention*(cc: LONGINT);
  1417. BEGIN callingConvention := cc
  1418. END SetCallingConvention;
  1419. PROCEDURE AddParameter*(p: Parameter);
  1420. BEGIN
  1421. ASSERT(p # NIL);
  1422. IF lastParameter= NIL THEN firstParameter := p ELSE lastParameter.nextParameter := p; p.prevParameter := lastParameter; END;
  1423. lastParameter := p;
  1424. INC(numberParameters);
  1425. ASSERT(p.access # {}); (* no hidden parameters ! *)
  1426. END AddParameter;
  1427. PROCEDURE RevertParameters*;
  1428. VAR this,next: Parameter; pnum: LONGINT;
  1429. BEGIN
  1430. pnum := numberParameters;
  1431. IF lastParameter # NIL THEN
  1432. this := lastParameter;
  1433. lastParameter := NIL;
  1434. firstParameter := NIL;
  1435. numberParameters := 0;
  1436. WHILE this # NIL DO
  1437. next := this.prevParameter;
  1438. this.prevParameter := NIL; this.nextParameter := NIL;
  1439. AddParameter(this);
  1440. this := next;
  1441. END;
  1442. END;
  1443. ASSERT(pnum = numberParameters);
  1444. END RevertParameters;
  1445. PROCEDURE SetReturnType*( type: Type );
  1446. BEGIN
  1447. returnType := type;
  1448. END SetReturnType;
  1449. PROCEDURE SameType*(this: Type): BOOLEAN;
  1450. VAR result: BOOLEAN; p1,p2: Parameter;
  1451. BEGIN
  1452. result := FALSE;
  1453. IF recursion THEN
  1454. result := TRUE
  1455. ELSIF this = SELF THEN
  1456. result := TRUE
  1457. ELSIF this IS ProcedureType THEN
  1458. recursion := TRUE;
  1459. WITH this: ProcedureType DO
  1460. result := (returnType = NIL) & (this.returnType = NIL) OR (returnType # NIL) & (this.returnType # NIL) & returnType.SameType(this.returnType.resolved);
  1461. result := result & (callingConvention = this.callingConvention);
  1462. result := result & (noReturn = this.noReturn);
  1463. IF result THEN
  1464. p1 := firstParameter; p2 := this.firstParameter;
  1465. 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
  1466. p1 := p1.nextParameter; p2 := p2.nextParameter
  1467. END;
  1468. result := ((p1=NIL) OR (p1.access = Hidden)) & ((p2=NIL) OR (p2.access= Hidden));
  1469. END;
  1470. END;
  1471. END;
  1472. recursion := FALSE;
  1473. RETURN result
  1474. END SameType;
  1475. PROCEDURE CompatibleTo*(to: Type): BOOLEAN;
  1476. BEGIN
  1477. RETURN SameType(to) & (~isDelegate OR to(ProcedureType).isDelegate) & (~to.isRealtime OR isRealtime);
  1478. END CompatibleTo;
  1479. PROCEDURE IsComposite(): BOOLEAN;
  1480. BEGIN RETURN isDelegate
  1481. END IsComposite;
  1482. PROCEDURE Accept*(v: Visitor);
  1483. VAR position: LONGINT;
  1484. BEGIN position := SELF.position; v.VisitProcedureType(SELF)
  1485. END Accept;
  1486. (** Returns if the type needs to be traced for garbage collection *)
  1487. PROCEDURE NeedsTrace*(): BOOLEAN;
  1488. BEGIN RETURN isDelegate;
  1489. END NeedsTrace;
  1490. END ProcedureType;
  1491. (**** expressions ****)
  1492. Expression* = OBJECT
  1493. VAR
  1494. type-: Type; (* the expression's type. Resolved by checker *)
  1495. assignable-: BOOLEAN; (* expression can be assigned to (or used as var-parameter): expression := ... *)
  1496. position-,endposition-: LONGINT;
  1497. state-: SET;
  1498. resolved-: Value;
  1499. isHidden-: BOOLEAN;
  1500. PROCEDURE End*( position: LONGINT );
  1501. BEGIN SELF.endposition := position;
  1502. END End;
  1503. PROCEDURE SetState*(state: LONGINT);
  1504. BEGIN INCL(SELF.state,state);
  1505. END SetState;
  1506. PROCEDURE &InitExpression(position: LONGINT);
  1507. BEGIN SELF.position := position; state := Undefined; type := NIL; assignable := FALSE; resolved := NIL; isHidden := FALSE;
  1508. END InitExpression;
  1509. PROCEDURE SetHidden*(hidden: BOOLEAN);
  1510. BEGIN isHidden := hidden
  1511. END SetHidden;
  1512. PROCEDURE SetType*(type: Type);
  1513. BEGIN
  1514. SELF.type := type;
  1515. END SetType;
  1516. PROCEDURE SetResolved*(value: Value);
  1517. BEGIN SELF.resolved := value
  1518. END SetResolved;
  1519. PROCEDURE SetAssignable*(assignable: BOOLEAN);
  1520. BEGIN SELF.assignable := assignable
  1521. END SetAssignable;
  1522. PROCEDURE Clone(): Expression;
  1523. VAR clone: Expression;
  1524. BEGIN
  1525. (* support cloning here for more robust error reporting -- should not happen normally *)
  1526. NEW(clone, position); RETURN clone
  1527. END Clone;
  1528. PROCEDURE Accept*(v: Visitor);
  1529. VAR position: LONGINT;
  1530. BEGIN position := SELF.position; v.VisitExpression(SELF)
  1531. END Accept;
  1532. PROCEDURE NeedsTrace* (): BOOLEAN;
  1533. BEGIN RETURN FALSE;
  1534. END NeedsTrace;
  1535. END Expression;
  1536. (** <<expression, expression, ...>> **)
  1537. ExpressionList* = OBJECT
  1538. VAR list: Basic.List;
  1539. PROCEDURE & InitList;
  1540. BEGIN NEW( list,8 );
  1541. END InitList;
  1542. PROCEDURE Length*( ): LONGINT;
  1543. BEGIN RETURN list.Length();
  1544. END Length;
  1545. PROCEDURE AddExpression*( d: Expression );
  1546. BEGIN list.Add(d)
  1547. END AddExpression;
  1548. PROCEDURE GetExpression*( index: LONGINT ): Expression;
  1549. VAR p: ANY;
  1550. BEGIN
  1551. p := list.Get(index); RETURN p(Expression);
  1552. END GetExpression;
  1553. PROCEDURE SetExpression*(index: LONGINT; expression: Expression);
  1554. BEGIN list.Set(index,expression)
  1555. END SetExpression;
  1556. PROCEDURE RemoveExpression*(i: LONGINT);
  1557. BEGIN list.RemoveByIndex(i);
  1558. END RemoveExpression;
  1559. PROCEDURE Revert*;
  1560. VAR i,j,last: LONGINT; ei,ej: ANY;
  1561. BEGIN
  1562. last := Length()-1;
  1563. FOR i := 0 TO last DO
  1564. j := last-i;
  1565. ei := list.Get(i);
  1566. ej := list.Get(j);
  1567. list.Set(i,ej);
  1568. list.Set(j,ei);
  1569. END;
  1570. END Revert;
  1571. PROCEDURE Clone*(VAR list: ExpressionList);
  1572. VAR i: LONGINT;
  1573. BEGIN
  1574. IF list = NIL THEN NEW(list) END;
  1575. FOR i := 0 TO Length()-1 DO
  1576. list.AddExpression(CloneExpression(GetExpression(i)));
  1577. END;
  1578. END Clone;
  1579. END ExpressionList;
  1580. (** << {elements} >> **)
  1581. Set* = OBJECT (Expression)
  1582. VAR elements-: ExpressionList; (* an element of the form from .. to is represented as a RangeExpression *)
  1583. PROCEDURE & InitSet( position: LONGINT );
  1584. BEGIN
  1585. InitExpression( position );
  1586. elements := NewExpressionList();
  1587. END InitSet;
  1588. PROCEDURE Clone(): Expression;
  1589. VAR copy: Set;
  1590. BEGIN
  1591. NEW(copy, position); elements.Clone(copy.elements); RETURN copy
  1592. END Clone;
  1593. PROCEDURE Accept*(v: Visitor);
  1594. VAR position: LONGINT;
  1595. BEGIN position := SELF.position; v.VisitSet(SELF)
  1596. END Accept;
  1597. END Set;
  1598. (** << [elements] >> **)
  1599. MathArrayExpression* = OBJECT (Expression)
  1600. VAR elements-: ExpressionList; (* an element of the form from .. to is represented as a RangeExpression *)
  1601. PROCEDURE & InitMathArrayExpression( position: LONGINT );
  1602. BEGIN
  1603. InitExpression( position );
  1604. elements := NewExpressionList();
  1605. END InitMathArrayExpression;
  1606. PROCEDURE Clone(): Expression;
  1607. VAR copy: MathArrayExpression;
  1608. BEGIN
  1609. NEW(copy, position); elements.Clone(copy.elements); RETURN copy
  1610. END Clone;
  1611. PROCEDURE Accept*(v: Visitor);
  1612. VAR position: LONGINT;
  1613. BEGIN position := SELF.position; v.VisitMathArrayExpression(SELF)
  1614. END Accept;
  1615. END MathArrayExpression;
  1616. (** <<operator left>> **)
  1617. UnaryExpression* = OBJECT (Expression)
  1618. VAR
  1619. left-: Expression;
  1620. operator-: LONGINT; (* one of Scanner.Minus ... Scanner.Not *)
  1621. PROCEDURE & InitUnaryExpression( position: LONGINT; operand: Expression; operator: LONGINT );
  1622. BEGIN
  1623. InitExpression( position ); SELF.left := operand; SELF.operator := operator;
  1624. END InitUnaryExpression;
  1625. PROCEDURE SetLeft*(left: Expression);
  1626. BEGIN SELF.left := left
  1627. END SetLeft;
  1628. PROCEDURE Clone(): Expression;
  1629. VAR copy: UnaryExpression;
  1630. BEGIN
  1631. NEW(copy, position, CloneExpression(left), operator); RETURN copy
  1632. END Clone;
  1633. PROCEDURE Accept*(v: Visitor);
  1634. VAR position: LONGINT;
  1635. BEGIN position := SELF.position; v.VisitUnaryExpression(SELF)
  1636. END Accept;
  1637. END UnaryExpression;
  1638. (** <<left operator right>> **)
  1639. BinaryExpression* = OBJECT (Expression)
  1640. VAR
  1641. left-, right-: Expression;
  1642. operator-: LONGINT; (* one of Scanner.Equal ... Scanner.Minus *)
  1643. PROCEDURE & InitBinaryExpression( position: LONGINT; left, right: Expression; operator: LONGINT );
  1644. BEGIN
  1645. InitExpression( position ); SELF.left := left; SELF.right := right; SELF.operator := operator;
  1646. END InitBinaryExpression;
  1647. PROCEDURE SetLeft*(left: Expression);
  1648. BEGIN SELF.left := left
  1649. END SetLeft;
  1650. PROCEDURE SetRight*(right: Expression);
  1651. BEGIN SELF.right := right
  1652. END SetRight;
  1653. PROCEDURE Clone(): Expression;
  1654. VAR copy: BinaryExpression;
  1655. BEGIN
  1656. NEW(copy, position, CloneExpression(left), CloneExpression(right), operator); RETURN copy
  1657. END Clone;
  1658. PROCEDURE Accept*(v: Visitor);
  1659. VAR position: LONGINT;
  1660. BEGIN position := SELF.position; v.VisitBinaryExpression(SELF)
  1661. END Accept;
  1662. END BinaryExpression;
  1663. (** expression that denotes a range
  1664. <<[first] '..' [last] ['by' step] | '*' >>
  1665. **)
  1666. RangeExpression* = OBJECT (Expression)
  1667. VAR
  1668. first-, last-, step-: Expression;
  1669. missingFirst-, missingLast-, missingStep-: BOOLEAN; (* only for printout*)
  1670. context-: SHORTINT; (* one of ArrayIndex, SetElement or CaseGuard *)
  1671. PROCEDURE &InitRangeExpression(position: LONGINT; first, last, step: Expression);
  1672. BEGIN
  1673. context := ArrayIndex; (* by default, a range represents array indices *)
  1674. InitExpression(position);
  1675. missingFirst := (first = NIL);
  1676. missingLast := (last = NIL);
  1677. missingStep := (step = NIL);
  1678. SELF.first := first;
  1679. SELF.last := last;
  1680. SELF.step := step;
  1681. END InitRangeExpression;
  1682. PROCEDURE SetFirst*(first: Expression);
  1683. BEGIN
  1684. SELF.first := first
  1685. END SetFirst;
  1686. PROCEDURE SetLast*(last: Expression);
  1687. BEGIN SELF.last := last
  1688. END SetLast;
  1689. PROCEDURE SetStep*(step: Expression);
  1690. BEGIN SELF.step := step
  1691. END SetStep;
  1692. PROCEDURE SetContext*(context: SHORTINT);
  1693. BEGIN
  1694. SELF.context := context
  1695. END SetContext;
  1696. PROCEDURE Clone(): Expression;
  1697. VAR copy: RangeExpression;
  1698. BEGIN
  1699. NEW(copy, position, CloneExpression(first), CloneExpression(last), CloneExpression(step)); RETURN copy
  1700. END Clone;
  1701. PROCEDURE Accept*(v: Visitor);
  1702. VAR position: LONGINT;
  1703. BEGIN position := SELF.position; v.VisitRangeExpression(SELF)
  1704. END Accept;
  1705. END RangeExpression;
  1706. (** << ? >> **)
  1707. TensorRangeExpression*=OBJECT (Expression);
  1708. PROCEDURE &InitTensorRangeExpression(position: LONGINT);
  1709. BEGIN
  1710. InitExpression(position);
  1711. END InitTensorRangeExpression;
  1712. PROCEDURE Clone(): Expression;
  1713. VAR copy: TensorRangeExpression;
  1714. BEGIN
  1715. NEW(copy, position); RETURN copy
  1716. END Clone;
  1717. PROCEDURE Accept*(v: Visitor);
  1718. VAR position: LONGINT;
  1719. BEGIN position := SELF.position; v.VisitTensorRangeExpression(SELF)
  1720. END Accept;
  1721. END TensorRangeExpression;
  1722. (** convert expression from expression.type to Conversion.type **)
  1723. Conversion* = OBJECT (Expression)
  1724. VAR
  1725. expression-: Expression;
  1726. typeExpression-: Expression; (* for printout *)
  1727. PROCEDURE & InitConversion( position: LONGINT; expression: Expression; type: Type; typeExpression: Expression);
  1728. BEGIN
  1729. InitExpression( position ); SELF.expression := expression; SELF.typeExpression := typeExpression; SELF.type := type;
  1730. END InitConversion;
  1731. PROCEDURE SetExpression*(expression: Expression);
  1732. BEGIN SELF.expression := expression
  1733. END SetExpression;
  1734. PROCEDURE Clone(): Expression;
  1735. VAR copy: Conversion;
  1736. BEGIN
  1737. NEW(copy, position, CloneExpression(expression), type, CloneExpression(typeExpression)); RETURN copy
  1738. END Clone;
  1739. PROCEDURE Accept*(v: Visitor);
  1740. VAR position: LONGINT;
  1741. BEGIN position := SELF.position; v.VisitConversion(SELF)
  1742. END Accept;
  1743. END Conversion;
  1744. (**** designators ****)
  1745. (** abstract **)
  1746. Designator* = OBJECT(Expression)
  1747. VAR
  1748. left-: Expression; (* currently only designators are allowed but for later purposes ... (as for example (a+b).c) *)
  1749. relatedRhs-: Expression; (* the RHS of an assignment if this designator is used on the LHS: *)
  1750. (* used if this designator contains an index operator call, e.g. 'asot.^"[]"(indexList)': *)
  1751. relatedAsot-: Expression; (* the ASOT on which the index operator is called *)
  1752. relatedIndexList-: ExpressionList; (* the index list *)
  1753. modifiers-: Modifier;
  1754. PROCEDURE &InitDesignator*(position: LONGINT);
  1755. BEGIN
  1756. InitExpression(position);
  1757. left := NIL;
  1758. relatedRhs := NIL;
  1759. relatedAsot := NIL;
  1760. relatedIndexList := NIL;
  1761. modifiers := NIL;
  1762. END InitDesignator;
  1763. PROCEDURE SetLeft*(expression: Expression);
  1764. BEGIN left := expression
  1765. END SetLeft;
  1766. PROCEDURE SetRelatedRhs*(relatedRhs: Expression);
  1767. BEGIN SELF.relatedRhs := relatedRhs
  1768. END SetRelatedRhs;
  1769. PROCEDURE SetRelatedAsot*(relatedAsot: Expression);
  1770. BEGIN SELF.relatedAsot := relatedAsot
  1771. END SetRelatedAsot;
  1772. PROCEDURE SetRelatedIndexList*(relatedIndexList: ExpressionList);
  1773. BEGIN SELF.relatedIndexList := relatedIndexList
  1774. END SetRelatedIndexList;
  1775. PROCEDURE SetModifiers*(flags: Modifier);
  1776. BEGIN modifiers := flags
  1777. END SetModifiers;
  1778. PROCEDURE Clone(): Expression;
  1779. VAR clone: Designator;
  1780. BEGIN
  1781. (* support cloning here for more robust error reporting -- should not happen normally *)
  1782. NEW(clone, position); RETURN clone
  1783. END Clone;
  1784. PROCEDURE Accept*(v: Visitor);
  1785. VAR position: LONGINT;
  1786. BEGIN position := SELF.position; v.VisitDesignator(SELF)
  1787. END Accept;
  1788. END Designator;
  1789. (*** first phase (parse time) designators ***)
  1790. (** <<identifier>>
  1791. may designate any symbol such as Variable, TypeDeclaration, Procedure
  1792. **)
  1793. IdentifierDesignator* = OBJECT(Designator)
  1794. VAR identifier-: Identifier;
  1795. PROCEDURE &InitIdentifierDesignator(position: LONGINT; id: Identifier);
  1796. BEGIN InitDesignator(position); identifier := id
  1797. END InitIdentifierDesignator;
  1798. PROCEDURE Clone(): Expression;
  1799. VAR copy: IdentifierDesignator;
  1800. BEGIN
  1801. NEW(copy, position, identifier); RETURN copy
  1802. END Clone;
  1803. PROCEDURE Accept*(v: Visitor);
  1804. VAR position: LONGINT;
  1805. BEGIN position := SELF.position; v.VisitIdentifierDesignator(SELF)
  1806. END Accept;
  1807. END IdentifierDesignator;
  1808. (** <<left.identifier>>
  1809. may designate a record / module element (constant, type, variable, procedure)
  1810. **)
  1811. SelectorDesignator* = OBJECT (Designator)
  1812. VAR identifier-: Identifier;
  1813. PROCEDURE & InitSelector(position: LONGINT; left: Designator; identifier: Identifier);
  1814. BEGIN InitDesignator(position); SELF.left := left; SELF.identifier := identifier;
  1815. END InitSelector;
  1816. PROCEDURE Clone(): Expression;
  1817. VAR copy: SelectorDesignator;
  1818. BEGIN
  1819. NEW(copy, position, CloneDesignator(left), identifier); RETURN copy
  1820. END Clone;
  1821. PROCEDURE Accept*(v: Visitor);
  1822. VAR position: LONGINT;
  1823. BEGIN position := SELF.position; v.VisitSelectorDesignator(SELF)
  1824. END Accept;
  1825. END SelectorDesignator;
  1826. (** <<left(arg1, arg2, ...)>>
  1827. may designate a function call or a type guard
  1828. **)
  1829. ParameterDesignator* = OBJECT(Designator)
  1830. VAR
  1831. parameters-: ExpressionList;
  1832. PROCEDURE &InitParameterDesignator(position: LONGINT; left: Designator; parameters: ExpressionList);
  1833. BEGIN InitDesignator(position); SELF.left := left; SELF.parameters := parameters
  1834. END InitParameterDesignator;
  1835. PROCEDURE Clone(): Expression;
  1836. VAR copy: ParameterDesignator;
  1837. BEGIN
  1838. NEW(copy, position, CloneDesignator(left), CloneExpressionList(parameters)); RETURN copy
  1839. END Clone;
  1840. PROCEDURE Accept*(v: Visitor);
  1841. VAR position: LONGINT;
  1842. BEGIN position := SELF.position; v.VisitParameterDesignator(SELF)
  1843. END Accept;
  1844. END ParameterDesignator;
  1845. (** <<left^>>
  1846. may designate a pointer dereference or a method supercall
  1847. **)
  1848. ArrowDesignator* = OBJECT (Designator)
  1849. PROCEDURE &InitArrowDesignator(position: LONGINT; left: Designator);
  1850. BEGIN InitDesignator(position); SELF.left := left;
  1851. END InitArrowDesignator;
  1852. PROCEDURE Clone(): Expression;
  1853. VAR copy: ArrowDesignator;
  1854. BEGIN
  1855. NEW(copy, position, CloneDesignator(left(Designator))); RETURN copy
  1856. END Clone;
  1857. PROCEDURE Accept*(v: Visitor);
  1858. VAR position: LONGINT;
  1859. BEGIN position := SELF.position; v.VisitArrowDesignator(SELF)
  1860. END Accept;
  1861. END ArrowDesignator;
  1862. (** <<left[parameters]>>
  1863. designates an index designator, before checker
  1864. **)
  1865. BracketDesignator* = OBJECT(Designator)
  1866. VAR parameters-: ExpressionList;
  1867. PROCEDURE &InitBracketDesignator(position: LONGINT; left: Designator; parameters: ExpressionList);
  1868. BEGIN InitDesignator(position); SELF.left := left; SELF.parameters := parameters;
  1869. END InitBracketDesignator;
  1870. PROCEDURE Clone(): Expression;
  1871. VAR copy: BracketDesignator;
  1872. BEGIN
  1873. NEW(copy, position, CloneDesignator(left), CloneExpressionList(parameters)); RETURN copy
  1874. END Clone;
  1875. PROCEDURE Accept*(v: Visitor);
  1876. VAR position: LONGINT;
  1877. BEGIN position := SELF.position; v.VisitBracketDesignator(SELF)
  1878. END Accept;
  1879. END BracketDesignator;
  1880. (*** second phase (after checker) designators ***)
  1881. (** symbol designator emerged from IdentifierDesignator or from Selector **)
  1882. SymbolDesignator* = OBJECT(Designator)
  1883. VAR
  1884. symbol-: Symbol;
  1885. PROCEDURE &InitSymbolDesignator(position: LONGINT; left: Designator; symbol: Symbol);
  1886. BEGIN
  1887. InitDesignator(position);
  1888. SELF.left := left;
  1889. SELF.symbol := symbol;
  1890. END InitSymbolDesignator;
  1891. PROCEDURE Accept*(v: Visitor);
  1892. VAR position: LONGINT;
  1893. BEGIN
  1894. position := SELF.position; v.VisitSymbolDesignator(SELF);
  1895. END Accept;
  1896. PROCEDURE Clone(): Expression;
  1897. VAR copy: SymbolDesignator;
  1898. BEGIN
  1899. NEW(copy, position, CloneDesignator(left), symbol); RETURN copy
  1900. END Clone;
  1901. PROCEDURE SetSymbol*(s: Symbol);
  1902. BEGIN SELF.symbol := s;
  1903. END SetSymbol;
  1904. PROCEDURE NeedsTrace* (): BOOLEAN;
  1905. BEGIN RETURN symbol.NeedsTrace() & ((left = NIL) OR (left.NeedsTrace()));
  1906. END NeedsTrace;
  1907. END SymbolDesignator;
  1908. (** <<left[parameters]>>
  1909. (ranged) indexer
  1910. **)
  1911. IndexDesignator* = OBJECT(Designator)
  1912. VAR
  1913. parameters-: ExpressionList;
  1914. hasRange-: BOOLEAN;
  1915. hasTensorRange-: BOOLEAN;
  1916. PROCEDURE &InitIndexDesignator(position: LONGINT; left: Designator);
  1917. BEGIN
  1918. InitDesignator(position);
  1919. SELF.left := left;
  1920. parameters := NewExpressionList();
  1921. hasRange := FALSE;
  1922. hasTensorRange := FALSE;
  1923. END InitIndexDesignator;
  1924. PROCEDURE HasRange*;
  1925. BEGIN hasRange := TRUE;
  1926. END HasRange;
  1927. PROCEDURE HasTensorRange*;
  1928. BEGIN hasTensorRange := TRUE;
  1929. END HasTensorRange;
  1930. PROCEDURE Clone(): Expression;
  1931. VAR copy: IndexDesignator;
  1932. BEGIN
  1933. NEW(copy, position, CloneDesignator(left));
  1934. parameters.Clone(copy.parameters);
  1935. copy.hasRange := hasRange; copy.hasTensorRange := hasTensorRange ; RETURN copy
  1936. END Clone;
  1937. PROCEDURE Accept*(v: Visitor);
  1938. VAR position: LONGINT;
  1939. BEGIN position := SELF.position; v.VisitIndexDesignator(SELF)
  1940. END Accept;
  1941. PROCEDURE NeedsTrace* (): BOOLEAN;
  1942. BEGIN RETURN type.NeedsTrace() & left.NeedsTrace(); (* for x[y]: if x is untraced, then also x[y] should be treated untraced *)
  1943. END NeedsTrace;
  1944. END IndexDesignator;
  1945. StatementDesignator* = OBJECT (Designator)
  1946. VAR
  1947. statement-: Statement;
  1948. result-: Expression;
  1949. PROCEDURE & InitStatementDesignator(position: LONGINT; s: Statement);
  1950. BEGIN
  1951. InitDesignator(position); statement := s; result := NIL;
  1952. END InitStatementDesignator;
  1953. PROCEDURE Clone(): Expression;
  1954. VAR copy: StatementDesignator;
  1955. BEGIN
  1956. NEW(copy, position, CloneStatement(statement)) ;
  1957. copy.result := CloneExpression(result);
  1958. RETURN copy
  1959. END Clone;
  1960. PROCEDURE SetResult*(r: Expression);
  1961. BEGIN result := r
  1962. END SetResult;
  1963. PROCEDURE Accept*(v: Visitor);
  1964. VAR position: LONGINT;
  1965. BEGIN position := SELF.position; v.VisitStatementDesignator(SELF)
  1966. END Accept;
  1967. END StatementDesignator;
  1968. (** <<left(parameters)>>
  1969. procedure call
  1970. **)
  1971. ProcedureCallDesignator*= OBJECT (Designator)
  1972. VAR parameters-: ExpressionList;
  1973. PROCEDURE & InitProcedureCallDesignator(position: LONGINT; left: Designator; parameters: ExpressionList);
  1974. BEGIN
  1975. InitDesignator(position); SELF.left := left; SELF.parameters := parameters;
  1976. END InitProcedureCallDesignator;
  1977. PROCEDURE Clone(): Expression;
  1978. VAR copy: ProcedureCallDesignator;
  1979. BEGIN
  1980. NEW(copy, position, CloneDesignator(left), CloneExpressionList(parameters)); RETURN copy
  1981. END Clone;
  1982. PROCEDURE Accept*(v: Visitor);
  1983. VAR position: LONGINT;
  1984. BEGIN position := SELF.position; v.VisitProcedureCallDesignator(SELF)
  1985. END Accept;
  1986. END ProcedureCallDesignator;
  1987. (** <<procedure(parameters)>>
  1988. builtin procedure call **)
  1989. BuiltinCallDesignator*= OBJECT (Designator) (*! should this be an extension of a procedure call designator ? *)
  1990. VAR
  1991. id-: LONGINT;
  1992. parameters-: ExpressionList;
  1993. builtin-: Builtin;
  1994. PROCEDURE & InitBuiltinCallDesignator(position: LONGINT; id: LONGINT; left: Designator; parameters: ExpressionList);
  1995. BEGIN
  1996. InitDesignator(position); SELF.parameters := parameters; SELF.id := id; SELF.left := left;
  1997. END InitBuiltinCallDesignator;
  1998. PROCEDURE Clone(): Expression;
  1999. VAR copy: BuiltinCallDesignator;
  2000. BEGIN
  2001. NEW(copy, position, id, CloneDesignator(left), CloneExpressionList(parameters)); RETURN copy
  2002. END Clone;
  2003. PROCEDURE Accept*(v: Visitor);
  2004. VAR position: LONGINT;
  2005. BEGIN position := SELF.position; v.VisitBuiltinCallDesignator(SELF)
  2006. END Accept;
  2007. END BuiltinCallDesignator;
  2008. (** <<left(type)>>
  2009. resolved parameter designator, designates a type guard
  2010. **)
  2011. TypeGuardDesignator* = OBJECT(Designator)
  2012. VAR
  2013. typeExpression-: Expression; (* for printing only *)
  2014. PROCEDURE &InitTypeGuardDesignator(position: LONGINT; left: Designator; type: Type);
  2015. BEGIN InitDesignator(position); SELF.left := left; SELF.type := type; typeExpression := NIL;
  2016. END InitTypeGuardDesignator;
  2017. PROCEDURE SetTypeExpression*(typeExpression: Expression);
  2018. BEGIN SELF.typeExpression := typeExpression
  2019. END SetTypeExpression;
  2020. PROCEDURE Clone(): Expression;
  2021. VAR copy: TypeGuardDesignator;
  2022. BEGIN
  2023. NEW(copy, position, CloneDesignator(left), type); RETURN copy
  2024. END Clone;
  2025. PROCEDURE Accept*(v: Visitor);
  2026. VAR position: LONGINT;
  2027. BEGIN position := SELF.position; v.VisitTypeGuardDesignator(SELF)
  2028. END Accept;
  2029. PROCEDURE NeedsTrace* (): BOOLEAN;
  2030. BEGIN RETURN left.NeedsTrace() & type.NeedsTrace(); (* for x(Y): if x is untraced, then x as Y should also be treated untraced *)
  2031. END NeedsTrace;
  2032. END TypeGuardDesignator;
  2033. (** <<left^>> resolved as dereference operation on pointer variable left **)
  2034. DereferenceDesignator*= OBJECT (Designator)
  2035. PROCEDURE &InitDereferenceDesignator(position: LONGINT; left: Designator);
  2036. BEGIN InitDesignator(position); SELF.left := left;
  2037. END InitDereferenceDesignator;
  2038. PROCEDURE Clone(): Expression;
  2039. VAR copy: DereferenceDesignator;
  2040. BEGIN
  2041. NEW(copy, position, CloneDesignator(left)); RETURN copy
  2042. END Clone;
  2043. PROCEDURE Accept*(v: Visitor);
  2044. VAR position: LONGINT;
  2045. BEGIN position := SELF.position; v.VisitDereferenceDesignator(SELF)
  2046. END Accept;
  2047. PROCEDURE NeedsTrace* (): BOOLEAN;
  2048. BEGIN RETURN left.NeedsTrace() & type.NeedsTrace(); (* for x^: if x is an untraced pointer, the content of x^ is also treated untraced *)
  2049. END NeedsTrace;
  2050. END DereferenceDesignator;
  2051. (** <<left^>> resolved as supercall operation on method left **)
  2052. SupercallDesignator*= OBJECT (Designator)
  2053. PROCEDURE &InitSupercallDesignator(position: LONGINT; left: Designator);
  2054. BEGIN InitDesignator(position); SELF.left := left;
  2055. END InitSupercallDesignator;
  2056. PROCEDURE Clone(): Expression;
  2057. VAR copy: SupercallDesignator;
  2058. BEGIN
  2059. NEW(copy, position, CloneDesignator(left)); RETURN copy
  2060. END Clone;
  2061. PROCEDURE Accept*(v: Visitor);
  2062. VAR position: LONGINT;
  2063. BEGIN position := SELF.position; v.VisitSupercallDesignator(SELF)
  2064. END Accept;
  2065. END SupercallDesignator;
  2066. (** <<SELF.x>> **)
  2067. SelfDesignator*= OBJECT (Designator)
  2068. PROCEDURE &InitSelfDesignator(position: LONGINT);
  2069. BEGIN InitDesignator(position);
  2070. END InitSelfDesignator;
  2071. PROCEDURE Clone(): Expression;
  2072. VAR copy: SelfDesignator;
  2073. BEGIN
  2074. NEW(copy, position); RETURN copy
  2075. END Clone;
  2076. PROCEDURE Accept*(v: Visitor);
  2077. VAR position: LONGINT;
  2078. BEGIN position := SELF.position; v.VisitSelfDesignator(SELF)
  2079. END Accept;
  2080. PROCEDURE NeedsTrace* (): BOOLEAN;
  2081. BEGIN RETURN type.NeedsTrace();
  2082. END NeedsTrace;
  2083. END SelfDesignator;
  2084. (** <<RESULT>> **)
  2085. ResultDesignator*= OBJECT (Designator)
  2086. PROCEDURE &InitResultDesignator(position: LONGINT);
  2087. BEGIN InitDesignator(position);
  2088. END InitResultDesignator;
  2089. PROCEDURE Clone(): Expression;
  2090. VAR copy: ResultDesignator;
  2091. BEGIN
  2092. NEW(copy, position); RETURN copy
  2093. END Clone;
  2094. PROCEDURE Accept*(v: Visitor);
  2095. VAR position: LONGINT;
  2096. BEGIN position := SELF.position; v.VisitResultDesignator(SELF)
  2097. END Accept;
  2098. END ResultDesignator;
  2099. (**** values ****)
  2100. Value* = OBJECT (Expression)
  2101. VAR fingerprint-: FingerPrint;
  2102. PROCEDURE &InitValue(position: LONGINT);
  2103. BEGIN SELF.position := position; resolved := SELF; InitFingerPrint(fingerprint);
  2104. END InitValue;
  2105. PROCEDURE SetFingerPrint*(CONST fp: FingerPrint);
  2106. BEGIN
  2107. SELF.fingerprint := fp
  2108. END SetFingerPrint;
  2109. PROCEDURE Accept*(v: Visitor);
  2110. VAR position: LONGINT;
  2111. BEGIN position := SELF.position; v.VisitValue(SELF)
  2112. END Accept;
  2113. PROCEDURE Equals*(v: Value):BOOLEAN;
  2114. BEGIN HALT(100); (* abstract *) RETURN FALSE; END Equals;
  2115. END Value;
  2116. (** <<value = TRUE , FALSE>> **)
  2117. BooleanValue* = OBJECT (Value)
  2118. VAR
  2119. value-: BOOLEAN;
  2120. PROCEDURE & InitBooleanValue(position: LONGINT; value: BOOLEAN);
  2121. BEGIN
  2122. InitValue(position); SELF.value := value;
  2123. END InitBooleanValue;
  2124. PROCEDURE SetValue*(value: BOOLEAN);
  2125. BEGIN SELF.value := value
  2126. END SetValue;
  2127. PROCEDURE Clone(): Expression;
  2128. VAR copy: BooleanValue;
  2129. BEGIN
  2130. NEW(copy, position, value); RETURN copy
  2131. END Clone;
  2132. PROCEDURE Accept*(v: Visitor);
  2133. VAR position: LONGINT;
  2134. BEGIN position := SELF.position; v.VisitBooleanValue(SELF)
  2135. END Accept;
  2136. PROCEDURE Equals*(v: Value):BOOLEAN;
  2137. BEGIN RETURN (v IS BooleanValue) & (v(BooleanValue).value = value); END Equals;
  2138. END BooleanValue;
  2139. (** <<value = 123456>> **)
  2140. IntegerValue* = OBJECT (Value)
  2141. VAR
  2142. hvalue-: HUGEINT;
  2143. value-: LONGINT;
  2144. PROCEDURE & InitIntegerValue(position: LONGINT; hvalue: HUGEINT);
  2145. BEGIN
  2146. InitValue(position); SELF.hvalue := hvalue; SELF.value := SHORT(hvalue);
  2147. END InitIntegerValue;
  2148. PROCEDURE SetValue*(hvalue: HUGEINT);
  2149. BEGIN SELF.hvalue := hvalue; SELF.value := SHORT(hvalue);
  2150. END SetValue;
  2151. PROCEDURE Clone(): Expression;
  2152. VAR copy: IntegerValue;
  2153. BEGIN
  2154. NEW(copy, position, hvalue); RETURN copy
  2155. END Clone;
  2156. PROCEDURE Accept*(v: Visitor);
  2157. VAR position: LONGINT;
  2158. BEGIN position := SELF.position; v.VisitIntegerValue(SELF)
  2159. END Accept;
  2160. PROCEDURE Equals*(v: Value):BOOLEAN;
  2161. BEGIN RETURN (v IS IntegerValue) & (v(IntegerValue).value = value); END Equals;
  2162. END IntegerValue;
  2163. (** <<value = 'c', 65X>> **)
  2164. CharacterValue*= OBJECT(Value)
  2165. VAR
  2166. value-: CHAR; (* potential for extension to support CHAR16 and CHAR32 *)
  2167. PROCEDURE & InitCharacterValue(position:LONGINT; value: CHAR);
  2168. BEGIN
  2169. InitValue(position); SELF.value := value;
  2170. END InitCharacterValue;
  2171. PROCEDURE SetValue*(value: CHAR);
  2172. BEGIN SELF.value := value
  2173. END SetValue;
  2174. PROCEDURE Clone(): Expression;
  2175. VAR copy: CharacterValue;
  2176. BEGIN
  2177. NEW(copy, position, value); RETURN copy
  2178. END Clone;
  2179. PROCEDURE Accept*(v: Visitor);
  2180. VAR position: LONGINT;
  2181. BEGIN position := SELF.position; v.VisitCharacterValue(SELF)
  2182. END Accept;
  2183. PROCEDURE Equals*(v: Value):BOOLEAN;
  2184. BEGIN RETURN (v IS CharacterValue) & (v(CharacterValue).value = value); END Equals;
  2185. END CharacterValue;
  2186. SetValueType = SetValue;
  2187. (** <<value = {1,2,3..5}>> **)
  2188. SetValue* = OBJECT (Value)
  2189. VAR
  2190. value-: SET;
  2191. PROCEDURE & InitSetValue(position: LONGINT; value: SET);
  2192. BEGIN
  2193. InitValue(position); SELF.value := value;
  2194. END InitSetValue;
  2195. PROCEDURE SetValue*(value: SET);
  2196. BEGIN SELF.value := value
  2197. END SetValue;
  2198. PROCEDURE Clone(): Expression;
  2199. VAR copy: SetValueType;
  2200. BEGIN
  2201. NEW(copy, position, value); RETURN copy
  2202. END Clone;
  2203. PROCEDURE Accept*(v: Visitor);
  2204. VAR position: LONGINT;
  2205. BEGIN position := SELF.position; v.VisitSetValue(SELF)
  2206. END Accept;
  2207. END SetValue;
  2208. (** << [elements] >> **)
  2209. MathArrayValue* = OBJECT (Value)
  2210. VAR array-: MathArrayExpression; (* an element of the form from .. to is represented as a RangeExpression *)
  2211. PROCEDURE & InitMathArrayValue(position: LONGINT);
  2212. BEGIN
  2213. InitValue(position);
  2214. array := NIL;
  2215. END InitMathArrayValue;
  2216. PROCEDURE SetArray*(array: MathArrayExpression);
  2217. BEGIN SELF.array := array
  2218. END SetArray;
  2219. PROCEDURE Clone(): Expression;
  2220. VAR copy: MathArrayValue;
  2221. BEGIN
  2222. NEW(copy, position);
  2223. IF array # NIL THEN copy.array := array.Clone()(MathArrayExpression) END;
  2224. RETURN copy
  2225. END Clone;
  2226. PROCEDURE Accept*(v: Visitor);
  2227. VAR position: LONGINT;
  2228. BEGIN position := SELF.position; v.VisitMathArrayValue(SELF)
  2229. END Accept;
  2230. END MathArrayValue;
  2231. (** <<value = 1.2345E01>> **)
  2232. RealValue* = OBJECT (Value)
  2233. VAR
  2234. value-: LONGREAL;
  2235. subtype-: LONGINT; (* accuracy information: REAL vs. LONGREAL *)
  2236. PROCEDURE & InitRealValue(position: LONGINT; value: LONGREAL);
  2237. BEGIN
  2238. InitValue(position); SELF.value := value; SELF.subtype := 0;
  2239. END InitRealValue;
  2240. PROCEDURE SetValue*(value: LONGREAL);
  2241. BEGIN SELF.value := value
  2242. END SetValue;
  2243. PROCEDURE SetSubtype*(subtype: LONGINT);
  2244. BEGIN SELF.subtype := subtype;
  2245. END SetSubtype;
  2246. PROCEDURE Clone(): Expression;
  2247. VAR copy: RealValue;
  2248. BEGIN
  2249. NEW(copy, position, value); RETURN copy
  2250. END Clone;
  2251. PROCEDURE Accept*(v: Visitor);
  2252. VAR position: LONGINT;
  2253. BEGIN position := SELF.position; v.VisitRealValue(SELF)
  2254. END Accept;
  2255. PROCEDURE Equals*(v: Value):BOOLEAN;
  2256. BEGIN RETURN (v IS RealValue) & (v(RealValue).value = value); END Equals;
  2257. END RealValue;
  2258. ComplexValue* = OBJECT (Value)
  2259. VAR
  2260. realValue-, imagValue-: LONGREAL;
  2261. subtype-: LONGINT; (* accuracy information of components: REAL vs. LONGREAL *)
  2262. PROCEDURE & InitComplexValue(position: LONGINT; realValue, imagValue: LONGREAL);
  2263. BEGIN
  2264. InitValue(position); SELF.realValue := realValue; SELF.imagValue := imagValue; SELF.subtype := 0;
  2265. END InitComplexValue;
  2266. PROCEDURE SetValue*(realValue, imagValue: LONGREAL);
  2267. BEGIN SELF.realValue := realValue; SELF.imagValue := imagValue;
  2268. END SetValue;
  2269. PROCEDURE UpdateSubtype*;
  2270. BEGIN
  2271. ASSERT((type # NIL) & (type.resolved # NIL) & (type.resolved IS ComplexType) & (type.resolved(ComplexType).componentType IS FloatType));
  2272. CASE type.resolved(ComplexType).componentType(FloatType).sizeInBits OF
  2273. | 32: subtype := Scanner.Real
  2274. | 64: subtype := Scanner.Longreal
  2275. END
  2276. END UpdateSubtype;
  2277. PROCEDURE SetSubtype*(subtype: LONGINT);
  2278. BEGIN SELF.subtype := subtype;
  2279. END SetSubtype;
  2280. PROCEDURE Clone(): Expression;
  2281. VAR copy: ComplexValue;
  2282. BEGIN
  2283. NEW(copy, position, realValue, imagValue); copy.subtype := subtype; RETURN copy
  2284. END Clone;
  2285. PROCEDURE Accept*(v: Visitor);
  2286. VAR position: LONGINT;
  2287. BEGIN position := SELF.position; v.VisitComplexValue(SELF)
  2288. END Accept;
  2289. PROCEDURE Equals*(v: Value):BOOLEAN;
  2290. BEGIN RETURN (v IS ComplexValue) & (v(ComplexValue).realValue = realValue) & (v(ComplexValue).imagValue = imagValue);
  2291. (* TODO: append this?
  2292. OR (v IS RealValue) & (v(RealValue).value = realValue) & (imagValue := 0)
  2293. *)
  2294. END Equals;
  2295. END ComplexValue;
  2296. (** <<value = "string">> **)
  2297. StringValue* = OBJECT (Value)
  2298. VAR
  2299. value-: String;
  2300. length-: LONGINT;
  2301. PROCEDURE & InitStringValue(position: LONGINT; value: String);
  2302. BEGIN
  2303. InitValue(position); SELF.value := value;
  2304. length := 0;
  2305. WHILE (length<LEN(value)) & (value[length] # 0X) DO
  2306. INC(length);
  2307. END;
  2308. IF length < LEN(value) THEN INC(length) END
  2309. END InitStringValue;
  2310. PROCEDURE SetValue*(CONST value: String);
  2311. BEGIN SELF.value := value
  2312. END SetValue;
  2313. PROCEDURE Append*(CONST value: String);
  2314. VAR new: String; len: LONGINT;
  2315. BEGIN
  2316. len := Strings.Length(SELF.value^) + Strings.Length(value^) + 1;
  2317. IF LEN(SELF.value) < len THEN
  2318. NEW(new, len);
  2319. COPY(SELF.value^, new^);
  2320. SELF.value := new
  2321. END;
  2322. Strings.Append(SELF.value^, value^);
  2323. length := len
  2324. END Append;
  2325. PROCEDURE AppendChar*(CONST ch: CHAR);
  2326. VAR v: String;
  2327. BEGIN
  2328. NEW(v,2); v[0] := ch;
  2329. Append(v);
  2330. END AppendChar;
  2331. PROCEDURE Clone(): Expression;
  2332. VAR copy: StringValue;
  2333. BEGIN
  2334. NEW(copy, position, value); RETURN copy
  2335. END Clone;
  2336. PROCEDURE Accept*(v: Visitor);
  2337. VAR position: LONGINT;
  2338. BEGIN position := SELF.position; v.VisitStringValue(SELF)
  2339. END Accept;
  2340. PROCEDURE Equals*(v: Value):BOOLEAN;
  2341. BEGIN RETURN (v IS StringValue) & (v(StringValue).value = value); END Equals;
  2342. END StringValue;
  2343. (** <<value = NIL>> **)
  2344. NilValue* = OBJECT (Value)
  2345. PROCEDURE Accept*(v: Visitor);
  2346. VAR position: LONGINT;
  2347. BEGIN position := SELF.position; v.VisitNilValue(SELF)
  2348. END Accept;
  2349. PROCEDURE Clone(): Expression;
  2350. VAR copy: NilValue;
  2351. BEGIN
  2352. NEW(copy, position); RETURN copy
  2353. END Clone;
  2354. PROCEDURE Equals*(v: Value):BOOLEAN;
  2355. BEGIN RETURN (v IS NilValue); END Equals;
  2356. END NilValue;
  2357. (** <<value = enum.x >> **)
  2358. EnumerationValue* = OBJECT (Value)
  2359. VAR
  2360. value-: LONGINT;
  2361. PROCEDURE & InitEnumerationValue(position: LONGINT; value: LONGINT);
  2362. BEGIN
  2363. InitValue(position); SELF.value := value;
  2364. END InitEnumerationValue;
  2365. PROCEDURE SetValue*(value: LONGINT);
  2366. BEGIN SELF.value := value
  2367. END SetValue;
  2368. PROCEDURE Clone(): Expression;
  2369. VAR copy: EnumerationValue;
  2370. BEGIN
  2371. NEW(copy, position, value); RETURN copy
  2372. END Clone;
  2373. PROCEDURE Accept*(v: Visitor);
  2374. VAR position: LONGINT;
  2375. BEGIN position := SELF.position; v.VisitEnumerationValue(SELF)
  2376. END Accept;
  2377. PROCEDURE Equals*(v: Value):BOOLEAN;
  2378. BEGIN RETURN (v IS EnumerationValue) & (v(EnumerationValue).value = value); END Equals;
  2379. END EnumerationValue;
  2380. (**** symbols ****)
  2381. Symbol*= OBJECT
  2382. VAR
  2383. nextSymbol-: Symbol;
  2384. name-: Identifier; (* constant / variable / parameter / type name / module name *)
  2385. externalName-: Scanner.StringType; (* variable / procedure *)
  2386. access-: SET; (* access flags (exported, readonly etc.) *)
  2387. type-: Type; (* type of constant / variable / parameter / procedure return type *)
  2388. scope-:Scope; (* container of symbol *)
  2389. offsetInBits-: LONGINT; (* offset in stack or heap, in bits *)
  2390. used-, written-: BOOLEAN;
  2391. fixed-: BOOLEAN;
  2392. alignment-: LONGINT;
  2393. position-: LONGINT; state-: SET;
  2394. fingerprint-: FingerPrint;
  2395. comment-: Comment;
  2396. PROCEDURE & InitSymbol(position: LONGINT; name:Identifier);
  2397. BEGIN
  2398. SELF.position := position; state := Undefined;
  2399. nextSymbol := NIL;
  2400. SELF.name := name;
  2401. externalName := NIL;
  2402. scope:= NIL;
  2403. type := NIL;
  2404. access := Internal;
  2405. state := Undefined;
  2406. offsetInBits := MIN(LONGINT);
  2407. alignment := 0; (* take default *)
  2408. fixed := FALSE;
  2409. used := FALSE; written := FALSE;
  2410. InitFingerPrint(fingerprint);
  2411. comment := NIL;
  2412. END InitSymbol;
  2413. PROCEDURE SetAlignment*(fix: BOOLEAN; align: LONGINT);
  2414. BEGIN SELF.alignment := align; fixed := fix;
  2415. END SetAlignment;
  2416. PROCEDURE SetFingerPrint*(CONST fp: FingerPrint);
  2417. BEGIN
  2418. SELF.fingerprint := fp
  2419. END SetFingerPrint;
  2420. PROCEDURE SetState*(state: LONGINT);
  2421. BEGIN INCL(SELF.state,state);
  2422. END SetState;
  2423. PROCEDURE SetScope*(scope: Scope);
  2424. BEGIN SELF.scope := scope
  2425. END SetScope;
  2426. PROCEDURE SetType*(type: Type);
  2427. BEGIN
  2428. SELF.type := type;
  2429. END SetType;
  2430. PROCEDURE SetNext*(symbol: Symbol);
  2431. BEGIN SELF.nextSymbol := symbol; END SetNext;
  2432. PROCEDURE SetAccess*(access: SET);
  2433. BEGIN
  2434. (* consistency guarantee *)
  2435. IF PublicWrite IN access THEN ASSERT(ProtectedWrite IN access) END;
  2436. IF ProtectedWrite IN access THEN ASSERT(InternalWrite IN access) END;
  2437. IF PublicRead IN access THEN ASSERT(ProtectedRead IN access) END;
  2438. IF ProtectedRead IN access THEN ASSERT(InternalRead IN access)END;
  2439. SELF.access := access;
  2440. END SetAccess;
  2441. PROCEDURE SetOffset*(ofs: LONGINT);
  2442. BEGIN offsetInBits := ofs
  2443. END SetOffset;
  2444. PROCEDURE MarkUsed*;
  2445. BEGIN used := TRUE
  2446. END MarkUsed;
  2447. PROCEDURE MarkWritten*;
  2448. BEGIN written := TRUE
  2449. END MarkWritten;
  2450. PROCEDURE GetName*(VAR str: ARRAY OF CHAR);
  2451. BEGIN Basic.GetString(name, str);
  2452. END GetName;
  2453. PROCEDURE SetComment*(comment: Comment);
  2454. BEGIN SELF.comment := comment
  2455. END SetComment;
  2456. PROCEDURE Accept*(v: Visitor);
  2457. VAR position: LONGINT;
  2458. BEGIN position := SELF.position; v.VisitSymbol(SELF)
  2459. END Accept;
  2460. PROCEDURE SetExternalName*(name: Scanner.StringType);
  2461. BEGIN externalName := name;
  2462. END SetExternalName;
  2463. PROCEDURE NeedsTrace* (): BOOLEAN;
  2464. BEGIN RETURN FALSE;
  2465. END NeedsTrace;
  2466. END Symbol;
  2467. (**
  2468. <<TYPE name = declaredType>>
  2469. TypeDeclaration symbol represents a type declaration of the form TYPE name = declaredType.
  2470. Note that the declared type is not stored in the symbol's type field but rather in the declaredType field.
  2471. The type of a type declaration is set to "typeDeclarationType" in the semantic checker
  2472. **)
  2473. TypeDeclaration*= OBJECT(Symbol)
  2474. VAR
  2475. nextTypeDeclaration-: TypeDeclaration;
  2476. declaredType-: Type;
  2477. PROCEDURE &InitTypeDeclaration(position: LONGINT; name: Identifier);
  2478. BEGIN
  2479. InitSymbol(position,name);
  2480. nextTypeDeclaration := NIL;
  2481. declaredType := NIL;
  2482. type := typeDeclarationType;
  2483. END InitTypeDeclaration;
  2484. PROCEDURE SetDeclaredType*(type: Type);
  2485. BEGIN
  2486. declaredType := type;
  2487. IF ~(type IS BasicType) THEN
  2488. type.typeDeclaration := SELF;
  2489. END;
  2490. END SetDeclaredType;
  2491. PROCEDURE SetType*(type: Type);
  2492. BEGIN
  2493. ASSERT(type = typeDeclarationType);
  2494. END SetType;
  2495. PROCEDURE Accept*(v: Visitor);
  2496. VAR position: LONGINT;
  2497. BEGIN position := SELF.position; v.VisitTypeDeclaration(SELF)
  2498. END Accept;
  2499. END TypeDeclaration;
  2500. (** <<CONST name = value >>
  2501. Constant declaration symbol. Represents a constant being defined in the form CONST name = value
  2502. The type of the constant is stored in the type field and is resolved by the semantic checker.
  2503. **)
  2504. Constant* = OBJECT (Symbol)
  2505. VAR
  2506. value-: Expression;
  2507. nextConstant-: Constant;
  2508. PROCEDURE & InitConstant( position: LONGINT; name: Identifier );
  2509. BEGIN
  2510. InitSymbol(position,name);
  2511. value := NIL;
  2512. nextConstant := NIL;
  2513. END InitConstant;
  2514. PROCEDURE SetValue*( value: Expression );
  2515. BEGIN
  2516. SELF.value := value;
  2517. END SetValue;
  2518. PROCEDURE Accept*(v: Visitor);
  2519. VAR position: LONGINT;
  2520. BEGIN position := SELF.position; v.VisitConstant(SELF)
  2521. END Accept;
  2522. END Constant;
  2523. (** <<VAR name: type >>
  2524. Variable declaration symbol. Represents a variable defined in the form VAR name: Type.
  2525. The type of the variable is stored in the symbol's type field and is resolved by the semantic checker.
  2526. **)
  2527. Variable* = OBJECT (Symbol)
  2528. VAR
  2529. nextVariable-: Variable;
  2530. untraced-: BOOLEAN;
  2531. useRegister-: BOOLEAN; registerNumber-: LONGINT;
  2532. modifiers-: Modifier;
  2533. initializer-: Expression;
  2534. usedAsReference-: BOOLEAN;
  2535. PROCEDURE & InitVariable*( position: LONGINT; name: Identifier);
  2536. BEGIN
  2537. InitSymbol(position,name);
  2538. nextVariable := NIL;
  2539. modifiers := NIL;
  2540. untraced := FALSE;
  2541. modifiers := NIL;
  2542. useRegister := FALSE;
  2543. registerNumber := -1;
  2544. usedAsReference := FALSE;
  2545. initializer := NIL;
  2546. END InitVariable;
  2547. PROCEDURE UsedAsReference*;
  2548. BEGIN
  2549. usedAsReference := TRUE
  2550. END UsedAsReference;
  2551. PROCEDURE SetUntraced*(u: BOOLEAN);
  2552. BEGIN untraced := u
  2553. END SetUntraced;
  2554. PROCEDURE SetUseRegister*(u: BOOLEAN);
  2555. BEGIN
  2556. useRegister := u
  2557. END SetUseRegister;
  2558. PROCEDURE SetRegisterNumber*(reg: LONGINT);
  2559. BEGIN
  2560. registerNumber := reg
  2561. END SetRegisterNumber;
  2562. PROCEDURE SetModifiers*(flag: Modifier);
  2563. BEGIN SELF.modifiers := flag;
  2564. END SetModifiers;
  2565. PROCEDURE SetInitializer*(initializer: Expression);
  2566. BEGIN SELF.initializer := initializer;
  2567. END SetInitializer;
  2568. PROCEDURE Accept*(v: Visitor);
  2569. VAR position: LONGINT;
  2570. BEGIN position := SELF.position; v.VisitVariable(SELF)
  2571. END Accept;
  2572. PROCEDURE NeedsTrace* (): BOOLEAN;
  2573. BEGIN RETURN ~untraced & (externalName = NIL) & type.NeedsTrace ();
  2574. END NeedsTrace;
  2575. END Variable;
  2576. (** << [VAR | CONST] name: type >>
  2577. Parameter declaration symbol. Represents a parameter in the form [VAR | CONST] name: Type.
  2578. The parameter's type is stored in the symbol's type field and is resolved by the semantic checker.
  2579. **)
  2580. Parameter* = OBJECT (Symbol)
  2581. VAR
  2582. nextParameter-, prevParameter-: Parameter;
  2583. modifiers-: Modifier;
  2584. defaultValue-: Expression;
  2585. kind-: LONGINT; (* ValueParameter, ConstParameter, VarParameter *)
  2586. ownerType-: Type;
  2587. untraced-: BOOLEAN;
  2588. movable-: BOOLEAN;
  2589. PROCEDURE & InitParameter( position: LONGINT; ownerType: Type ; name: Identifier; kind: LONGINT);
  2590. BEGIN
  2591. InitSymbol( position, name );
  2592. SELF.kind := kind;
  2593. IF kind = ConstParameter THEN access := access END;
  2594. nextParameter := NIL;
  2595. SELF.ownerType := ownerType;
  2596. modifiers := NIL;
  2597. untraced := FALSE;
  2598. defaultValue := NIL;
  2599. movable := FALSE;
  2600. END InitParameter;
  2601. PROCEDURE SetModifiers*(flag: Modifier);
  2602. BEGIN SELF.modifiers := flag;
  2603. END SetModifiers;
  2604. PROCEDURE SetUntraced*(untraced: BOOLEAN);
  2605. BEGIN SELF.untraced := untraced
  2606. END SetUntraced;
  2607. PROCEDURE SetMoveable*(movable: BOOLEAN);
  2608. BEGIN SELF.movable := movable
  2609. END SetMoveable;
  2610. PROCEDURE SetDefaultValue*(e: Expression);
  2611. BEGIN defaultValue := e
  2612. END SetDefaultValue;
  2613. PROCEDURE Accept*(v: Visitor);
  2614. VAR position: LONGINT;
  2615. BEGIN position := SELF.position; v.VisitParameter(SELF)
  2616. END Accept;
  2617. PROCEDURE SetKind*(kind: LONGINT);
  2618. BEGIN SELF.kind := kind; END SetKind;
  2619. PROCEDURE NeedsTrace* (): BOOLEAN;
  2620. BEGIN RETURN ~untraced & type.NeedsTrace ();
  2621. END NeedsTrace;
  2622. END Parameter;
  2623. Property* = OBJECT (Variable)
  2624. VAR
  2625. nextProperty-, prevProperty-: Property;
  2626. value-: Expression;
  2627. PROCEDURE & InitProperty(position: LONGINT; name: Identifier);
  2628. BEGIN
  2629. InitSymbol( position, name );
  2630. END InitProperty;
  2631. PROCEDURE SetValue*(e: Expression);
  2632. BEGIN value := e
  2633. END SetValue;
  2634. PROCEDURE Accept*(v: Visitor);
  2635. VAR position: LONGINT;
  2636. BEGIN position := SELF.position; v.VisitProperty(SELF)
  2637. END Accept;
  2638. END Property;
  2639. (** Procedure declaration symbol. Represents a procedure being defined in the form PROCEDURE name(parameters): returnType;
  2640. Note that the type of a procedure is a ProcedureType (and not the return type of the procedure).
  2641. Parameters, local variables, constants and type declarations are stored in the procedureScope field.
  2642. **)
  2643. Procedure* = OBJECT (Symbol)
  2644. VAR
  2645. nextProcedure-: Procedure;
  2646. procedureScope- : ProcedureScope;
  2647. super-: Procedure;
  2648. level-, methodNumber-: LONGINT;
  2649. isBodyProcedure-, isConstructor-,isFinalizer-,isInline-,isOberonInline-, isEntry-, isExit-,isFinal-,isAbstract-,isOverwritten-: BOOLEAN;
  2650. PROCEDURE & InitProcedure( position: LONGINT; name: Identifier; scope: ProcedureScope);
  2651. BEGIN
  2652. InitSymbol(position,name);
  2653. nextProcedure := NIL;
  2654. procedureScope := scope;
  2655. ASSERT(scope.ownerProcedure = NIL); (* cannot register twice ! *)
  2656. scope.ownerProcedure := SELF;
  2657. super := NIL;
  2658. level := 0;
  2659. methodNumber := -1;
  2660. isBodyProcedure := FALSE;
  2661. isConstructor := FALSE;
  2662. isFinalizer := FALSE;
  2663. isInline := FALSE;
  2664. isOberonInline := FALSE;
  2665. isEntry := FALSE;
  2666. isExit := FALSE;
  2667. isFinal := FALSE;
  2668. isAbstract := FALSE;
  2669. isOverwritten := FALSE;
  2670. END InitProcedure;
  2671. PROCEDURE SetSuper*(super: Procedure);
  2672. BEGIN
  2673. SELF.super := super
  2674. END SetSuper;
  2675. PROCEDURE SetBodyProcedure*(isBodyProcedure: BOOLEAN);
  2676. BEGIN SELF.isBodyProcedure := isBodyProcedure;
  2677. END SetBodyProcedure;
  2678. PROCEDURE SetConstructor*(isConstructor: BOOLEAN);
  2679. BEGIN SELF.isConstructor := isConstructor
  2680. END SetConstructor;
  2681. PROCEDURE SetFinalizer*(isFinalizer: BOOLEAN);
  2682. BEGIN SELF.isFinalizer := isFinalizer
  2683. END SetFinalizer;
  2684. PROCEDURE SetInline*(isInline: BOOLEAN);
  2685. BEGIN SELF.isInline := isInline
  2686. END SetInline;
  2687. PROCEDURE SetOberonInline*(isInline: BOOLEAN);
  2688. BEGIN SELF.isOberonInline := isInline
  2689. END SetOberonInline;
  2690. PROCEDURE SetEntry*(entry: BOOLEAN);
  2691. BEGIN SELF.isEntry := entry
  2692. END SetEntry;
  2693. PROCEDURE SetExit*(exit: BOOLEAN);
  2694. BEGIN SELF.isExit := exit
  2695. END SetExit;
  2696. PROCEDURE SetFinal*(final: BOOLEAN);
  2697. BEGIN SELF.isFinal := final
  2698. END SetFinal;
  2699. PROCEDURE SetOverwritten*(locallyOverwritten: BOOLEAN);
  2700. BEGIN SELF.isOverwritten := locallyOverwritten
  2701. END SetOverwritten;
  2702. PROCEDURE SetAbstract*(abstract: BOOLEAN);
  2703. BEGIN SELF.isAbstract := abstract
  2704. END SetAbstract;
  2705. PROCEDURE SetLevel*(level: LONGINT);
  2706. BEGIN SELF.level := level
  2707. END SetLevel;
  2708. PROCEDURE SetMethodNumber*(methodNumber: LONGINT);
  2709. BEGIN SELF.methodNumber := methodNumber
  2710. END SetMethodNumber;
  2711. PROCEDURE Accept*(v: Visitor);
  2712. VAR position: LONGINT;
  2713. BEGIN position := SELF.position; v.VisitProcedure(SELF)
  2714. END Accept;
  2715. END Procedure;
  2716. (** Builtin symbol stands for a builtin procedure. Is resolved by the semantic checker. **)
  2717. Builtin* = OBJECT (Symbol)
  2718. VAR
  2719. nextBuiltin-: Builtin;
  2720. id-: LONGINT;
  2721. PROCEDURE & InitBuiltin(position: LONGINT; name:Identifier; id: LONGINT);
  2722. BEGIN
  2723. InitSymbol(position,name); SELF.id := id;
  2724. END InitBuiltin;
  2725. PROCEDURE Accept*(v: Visitor);
  2726. VAR position: LONGINT;
  2727. BEGIN position := SELF.position; v.VisitBuiltin(SELF)
  2728. END Accept;
  2729. END Builtin;
  2730. CustomBuiltin*=OBJECT (Builtin)
  2731. VAR
  2732. subType-: SHORTINT;
  2733. PROCEDURE & InitCustomBuiltin(position: LONGINT; name: Identifier; id: LONGINT; subType: SHORTINT);
  2734. BEGIN
  2735. InitBuiltin(position,name,id);
  2736. SELF.subType := subType;
  2737. END InitCustomBuiltin;
  2738. (* TODO: check if this is correct *)
  2739. PROCEDURE CompatibleTo*(otherType: Type): BOOLEAN;
  2740. BEGIN RETURN FALSE
  2741. END CompatibleTo;
  2742. END CustomBuiltin;
  2743. Operator* = OBJECT (Procedure)
  2744. VAR
  2745. nextOperator-: Operator;
  2746. isDynamic-: BOOLEAN; (* nopov *)
  2747. PROCEDURE & InitOperator(position: LONGINT; name: Identifier; scope: ProcedureScope);
  2748. BEGIN
  2749. InitProcedure(position,name,scope);
  2750. nextOperator := NIL;
  2751. isDynamic := FALSE
  2752. END InitOperator;
  2753. (* nopov *)
  2754. PROCEDURE SetDynamic*(isDynamic: BOOLEAN);
  2755. BEGIN SELF.isDynamic := isDynamic
  2756. END SetDynamic;
  2757. PROCEDURE Accept*(v: Visitor);
  2758. VAR position: LONGINT;
  2759. BEGIN position := SELF.position; v.VisitOperator(SELF)
  2760. END Accept;
  2761. END Operator;
  2762. Import* = OBJECT (Symbol)
  2763. VAR
  2764. nextImport-: Import;
  2765. module-: Module;
  2766. moduleName-: Identifier;
  2767. context-: Identifier;
  2768. direct-: BOOLEAN; (* direct import *)
  2769. PROCEDURE & InitImport( position: LONGINT; name, moduleName: Identifier; direct: BOOLEAN );
  2770. BEGIN
  2771. InitSymbol(position,name);
  2772. SELF.direct := direct;
  2773. module := NIL;
  2774. context := invalidIdentifier;
  2775. SELF.moduleName := moduleName;
  2776. type := importType;
  2777. END InitImport;
  2778. PROCEDURE SetType*(type: Type);
  2779. BEGIN
  2780. ASSERT(type = importType);
  2781. END SetType;
  2782. PROCEDURE SetModule*(module: Module);
  2783. BEGIN
  2784. SELF.module := module;
  2785. END SetModule;
  2786. PROCEDURE SetDirect*(d: BOOLEAN);
  2787. BEGIN
  2788. direct := d
  2789. END SetDirect;
  2790. PROCEDURE SetModuleName*(moduleName: Identifier);
  2791. BEGIN SELF.moduleName := moduleName
  2792. END SetModuleName;
  2793. PROCEDURE SetContext*(context: Identifier);
  2794. BEGIN
  2795. SELF.context := context
  2796. END SetContext;
  2797. PROCEDURE Accept*(v: Visitor);
  2798. VAR position: LONGINT;
  2799. BEGIN position := SELF.position; v.VisitImport(SELF)
  2800. END Accept;
  2801. END Import;
  2802. StatementSequence* = OBJECT
  2803. VAR
  2804. list: Basic.List;
  2805. PROCEDURE & InitList;
  2806. BEGIN NEW( list,32 );
  2807. END InitList;
  2808. PROCEDURE Length*( ): LONGINT;
  2809. BEGIN RETURN list.Length();
  2810. END Length;
  2811. PROCEDURE AddStatement*( statement: Statement);
  2812. BEGIN list.Add( statement );
  2813. END AddStatement;
  2814. PROCEDURE PrependStatement*( statement: Statement);
  2815. BEGIN list.Prepend( statement );
  2816. END PrependStatement;
  2817. PROCEDURE HasStatement*( statement: Statement):BOOLEAN;
  2818. BEGIN RETURN list.Contains(statement);
  2819. END HasStatement;
  2820. PROCEDURE GetStatement*( index: LONGINT ): Statement;
  2821. VAR p: ANY;
  2822. BEGIN p := list.Get( index ); RETURN p( Statement );
  2823. END GetStatement;
  2824. PROCEDURE SetStatement*(index: LONGINT; statement: Statement);
  2825. BEGIN
  2826. list.Set(index,statement);
  2827. END SetStatement;
  2828. PROCEDURE RemoveStatement*(statement: Statement);
  2829. BEGIN
  2830. list.Remove(statement);
  2831. END RemoveStatement;
  2832. PROCEDURE InsertBefore*(search, new: Statement);
  2833. BEGIN
  2834. list.Insert(list.IndexOf(search), new);
  2835. END InsertBefore;
  2836. PROCEDURE Clone(VAR copy: StatementSequence);
  2837. VAR i: LONGINT;
  2838. BEGIN
  2839. IF copy = NIL THEN NEW(copy) END;
  2840. FOR i := 0 TO Length()-1 DO
  2841. copy.AddStatement(CloneStatement(GetStatement(i)))
  2842. END;
  2843. END Clone;
  2844. END StatementSequence;
  2845. (**** statements ****)
  2846. Statement*= OBJECT
  2847. VAR outer-: Statement;
  2848. position-: LONGINT;
  2849. isUnreachable-: BOOLEAN;
  2850. comment-: Comment;
  2851. PROCEDURE & InitStatement*(position: LONGINT; outer: Statement);
  2852. BEGIN
  2853. SELF.position := position;
  2854. SELF.outer := outer;
  2855. isUnreachable := FALSE;
  2856. comment := NIL;
  2857. END InitStatement;
  2858. PROCEDURE SetOuter*(o: Statement);
  2859. BEGIN outer := o
  2860. END SetOuter;
  2861. PROCEDURE SetUnreachable*(unreachable: BOOLEAN);
  2862. BEGIN isUnreachable := unreachable
  2863. END SetUnreachable;
  2864. PROCEDURE Accept*(v: Visitor);
  2865. VAR position: LONGINT;
  2866. BEGIN position := SELF.position; v.VisitStatement(SELF)
  2867. END Accept;
  2868. PROCEDURE SetComment*(comment: Comment);
  2869. BEGIN SELF.comment := comment
  2870. END SetComment;
  2871. PROCEDURE Clone(): Statement;
  2872. BEGIN
  2873. HALT(200) (* abstract *)
  2874. END Clone;
  2875. END Statement;
  2876. (** << call(...) >> **)
  2877. ProcedureCallStatement*= OBJECT(Statement)
  2878. VAR call-: Designator;
  2879. PROCEDURE & InitProcedureCallStatement(position: LONGINT; call: Designator; outer: Statement);
  2880. BEGIN InitStatement(position,outer); SELF.call := call;
  2881. END InitProcedureCallStatement;
  2882. PROCEDURE SetCall*(call: Designator);
  2883. BEGIN SELF.call := call;
  2884. END SetCall;
  2885. PROCEDURE Clone(): Statement;
  2886. VAR copy: ProcedureCallStatement;
  2887. BEGIN
  2888. NEW(copy, position, CloneDesignator(call), outer);
  2889. RETURN copy
  2890. END Clone;
  2891. PROCEDURE Accept*(v: Visitor);
  2892. VAR position: LONGINT;
  2893. BEGIN position := SELF.position; v.VisitProcedureCallStatement(SELF)
  2894. END Accept;
  2895. END ProcedureCallStatement;
  2896. (** << left := right >> **)
  2897. Assignment* = OBJECT (Statement)
  2898. VAR left-: Designator; right-: Expression;
  2899. PROCEDURE & InitAssignment*( position: LONGINT; left: Designator; right: Expression; outer: Statement );
  2900. BEGIN
  2901. InitStatement( position,outer ); SELF.left := left; SELF.right := right;
  2902. END InitAssignment;
  2903. PROCEDURE SetLeft*(left: Designator);
  2904. BEGIN SELF.left := left
  2905. END SetLeft;
  2906. PROCEDURE SetRight*(right: Expression);
  2907. BEGIN SELF.right := right
  2908. END SetRight;
  2909. PROCEDURE Clone(): Statement;
  2910. VAR copy: Assignment;
  2911. BEGIN
  2912. NEW(copy, position, CloneDesignator(left), CloneExpression(right), outer);
  2913. RETURN copy
  2914. END Clone;
  2915. PROCEDURE Accept*(v: Visitor);
  2916. VAR position: LONGINT;
  2917. BEGIN position := SELF.position; v.VisitAssignment(SELF)
  2918. END Accept;
  2919. END Assignment;
  2920. (** << left ('!' | '?' | '<<' | '>>') right >> **)
  2921. CommunicationStatement* = OBJECT (Statement)
  2922. VAR
  2923. left-: Designator; right-: Expression; op-: LONGINT;
  2924. PROCEDURE & InitAssignment*( position: LONGINT; op: LONGINT; left: Designator; right: Expression; outer: Statement );
  2925. BEGIN
  2926. InitStatement( position,outer ); SELF.op := op; SELF.left := left; SELF.right := right;
  2927. END InitAssignment;
  2928. PROCEDURE SetLeft*(left: Designator);
  2929. BEGIN SELF.left := left
  2930. END SetLeft;
  2931. PROCEDURE SetRight*(right: Expression);
  2932. BEGIN SELF.right := right
  2933. END SetRight;
  2934. PROCEDURE Accept*(v: Visitor);
  2935. VAR position: LONGINT;
  2936. BEGIN position := SELF.position; v.VisitCommunicationStatement(SELF)
  2937. END Accept;
  2938. END CommunicationStatement;
  2939. (** << ... condition THEN statements ... >> **)
  2940. IfPart*= OBJECT
  2941. VAR
  2942. condition-: Expression;
  2943. statements-: StatementSequence;
  2944. comment-: Comment;
  2945. PROCEDURE & InitIfPart;
  2946. BEGIN
  2947. statements := NIL; condition := NIL; comment := NIL;
  2948. END InitIfPart;
  2949. PROCEDURE SetCondition*(condition: Expression);
  2950. BEGIN SELF.condition := condition
  2951. END SetCondition;
  2952. PROCEDURE SetStatements*(statements: StatementSequence);
  2953. BEGIN SELF.statements := statements
  2954. END SetStatements;
  2955. PROCEDURE SetComment*(comment: Comment);
  2956. BEGIN SELF.comment := comment
  2957. END SetComment;
  2958. PROCEDURE Clone(): IfPart;
  2959. VAR copy: IfPart;
  2960. BEGIN
  2961. NEW(copy); copy.condition := CloneExpression(condition);
  2962. copy.statements := CloneStatementSequence(statements);
  2963. RETURN copy
  2964. END Clone;
  2965. END IfPart;
  2966. (** << IF ifPart {ELSIF elsifParts} ELSE elseParts >> **)
  2967. IfStatement* = OBJECT (Statement)
  2968. VAR
  2969. ifPart-: IfPart;
  2970. elsifParts: Basic.List;
  2971. elsePart-: StatementSequence;
  2972. PROCEDURE & InitIfStatement( position: LONGINT ; outer: Statement);
  2973. BEGIN
  2974. InitStatement( position,outer ); ifPart := NewIfPart(); elsePart := NIL; elsifParts := NIL;
  2975. END InitIfStatement;
  2976. PROCEDURE SetElsePart*( elsePart: StatementSequence );
  2977. BEGIN
  2978. SELF.elsePart := elsePart;
  2979. END SetElsePart;
  2980. PROCEDURE AddElsifPart*( elsifPart: IfPart );
  2981. BEGIN
  2982. IF elsifParts = NIL THEN NEW(elsifParts,4); END;
  2983. elsifParts.Add( elsifPart );
  2984. END AddElsifPart;
  2985. PROCEDURE GetElsifPart*( i: LONGINT ): IfPart;
  2986. VAR a: ANY;
  2987. BEGIN a := elsifParts.Get( i ); RETURN a( IfPart )
  2988. END GetElsifPart;
  2989. PROCEDURE ElsifParts*( ): LONGINT;
  2990. BEGIN
  2991. IF elsifParts = NIL THEN RETURN 0 ELSE RETURN elsifParts.Length(); END;
  2992. END ElsifParts;
  2993. PROCEDURE Clone(): Statement;
  2994. VAR copy: IfStatement; i: LONGINT;
  2995. BEGIN
  2996. NEW(copy, position, outer);
  2997. copy.ifPart := ifPart.Clone();
  2998. FOR i := 0 TO ElsifParts()-1 DO
  2999. copy.AddElsifPart(GetElsifPart(i).Clone());
  3000. END;
  3001. copy.SetElsePart(CloneStatementSequence(elsePart));
  3002. RETURN copy
  3003. END Clone;
  3004. PROCEDURE Accept*(v: Visitor);
  3005. VAR position: LONGINT;
  3006. BEGIN position := SELF.position; v.VisitIfStatement(SELF)
  3007. END Accept;
  3008. END IfStatement;
  3009. WithPart*= OBJECT
  3010. VAR
  3011. variable-: Designator;
  3012. type-: Type; (* initially is qualified type *)
  3013. statements-: StatementSequence;
  3014. comment-: Comment;
  3015. PROCEDURE &InitWithPart();
  3016. BEGIN
  3017. type := NIL; variable := NIL; statements := NIL; comment := NIL;
  3018. END InitWithPart;
  3019. PROCEDURE SetVariable*( variable: Designator);
  3020. BEGIN
  3021. SELF.variable := variable
  3022. END SetVariable;
  3023. PROCEDURE SetType*( type: Type );
  3024. BEGIN
  3025. SELF.type := type
  3026. END SetType;
  3027. PROCEDURE SetStatements*( statements: StatementSequence );
  3028. BEGIN
  3029. SELF.statements := statements;
  3030. END SetStatements;
  3031. PROCEDURE SetComment*(comment: Comment);
  3032. BEGIN SELF.comment := comment
  3033. END SetComment;
  3034. PROCEDURE Clone(): WithPart;
  3035. VAR copy: WithPart;
  3036. BEGIN
  3037. NEW(copy);
  3038. copy.SetVariable(CloneDesignator(variable));
  3039. copy.SetType(type);
  3040. copy.SetStatements(CloneStatementSequence(statements));
  3041. RETURN copy
  3042. END Clone;
  3043. END WithPart;
  3044. (** << WITH variable : type DO statements END >> **)
  3045. WithStatement* = OBJECT (Statement)
  3046. VAR
  3047. withParts-: Basic.List;
  3048. elsePart-: StatementSequence;
  3049. PROCEDURE & InitWithStatement( position: LONGINT; outer: Statement );
  3050. BEGIN
  3051. InitStatement( position,outer );
  3052. NEW(withParts,4); elsePart := NIL;
  3053. END InitWithStatement;
  3054. PROCEDURE AddWithPart*( withPart: WithPart );
  3055. BEGIN withParts.Add( withPart );
  3056. END AddWithPart;
  3057. PROCEDURE GetWithPart*( i: LONGINT ): WithPart;
  3058. VAR a: ANY;
  3059. BEGIN a := withParts.Get( i ); RETURN a( WithPart )
  3060. END GetWithPart;
  3061. PROCEDURE WithParts*( ): LONGINT;
  3062. BEGIN
  3063. IF withParts = NIL THEN RETURN 0 ELSE RETURN withParts.Length(); END;
  3064. END WithParts;
  3065. PROCEDURE SetElsePart*( elsePart: StatementSequence );
  3066. BEGIN
  3067. SELF.elsePart := elsePart;
  3068. END SetElsePart;
  3069. PROCEDURE Clone(): Statement;
  3070. VAR copy: WithStatement; i: LONGINT;
  3071. BEGIN
  3072. NEW(copy, position, outer);
  3073. FOR i := 0 TO WithParts()-1 DO
  3074. copy.AddWithPart(GetWithPart(i).Clone());
  3075. END;
  3076. copy.SetElsePart(CloneStatementSequence(elsePart));
  3077. RETURN copy
  3078. END Clone;
  3079. PROCEDURE Accept*(v: Visitor);
  3080. VAR position: LONGINT;
  3081. BEGIN position := SELF.position; v.VisitWithStatement(SELF)
  3082. END Accept;
  3083. END WithStatement;
  3084. CaseConstant*= POINTER TO RECORD min*,max*: LONGINT; next*: CaseConstant END;
  3085. (** << elements : statements >> **)
  3086. CasePart* = OBJECT
  3087. VAR
  3088. elements-: ExpressionList; (* expression list inserted by the parser *)
  3089. firstConstant-: CaseConstant; (* expression list resolved to int32s, inserted by checker *)
  3090. statements-: StatementSequence;
  3091. comment-: Comment;
  3092. PROCEDURE & InitCasePart;
  3093. BEGIN
  3094. elements := NewExpressionList(); firstConstant := NIL;
  3095. END InitCasePart;
  3096. PROCEDURE SetStatements*( statements: StatementSequence );
  3097. BEGIN
  3098. SELF.statements := statements;
  3099. END SetStatements;
  3100. PROCEDURE SetConstants*(firstConstant: CaseConstant);
  3101. BEGIN SELF.firstConstant := firstConstant
  3102. END SetConstants;
  3103. PROCEDURE SetComment*(comment: Comment);
  3104. BEGIN SELF.comment := comment
  3105. END SetComment;
  3106. PROCEDURE Clone(): CasePart;
  3107. VAR copy: CasePart;
  3108. BEGIN
  3109. NEW(copy);
  3110. copy.SetStatements(CloneStatementSequence(statements));
  3111. copy.firstConstant := firstConstant;
  3112. elements.Clone(copy.elements);
  3113. RETURN copy
  3114. END Clone;
  3115. END CasePart;
  3116. (** << CASE varaible OF caseParts ELSE elsePart >> **)
  3117. CaseStatement* = OBJECT (Statement)
  3118. VAR
  3119. variable-: Expression;
  3120. elsePart-: StatementSequence;
  3121. caseParts-: Basic.List;
  3122. min-,max-: LONGINT;
  3123. PROCEDURE & InitCaseStatement( position: LONGINT ; outer: Statement);
  3124. BEGIN
  3125. InitStatement(position,outer ); variable := NIL; elsePart := NIL; caseParts := NIL;
  3126. min := MAX(LONGINT); max := MIN(LONGINT);
  3127. END InitCaseStatement;
  3128. PROCEDURE SetVariable*( expression: Expression );
  3129. BEGIN SELF.variable := expression;
  3130. END SetVariable;
  3131. PROCEDURE SetElsePart*( elsePart: StatementSequence );
  3132. BEGIN SELF.elsePart := elsePart;
  3133. END SetElsePart;
  3134. PROCEDURE AddCasePart*( casePart: CasePart );
  3135. BEGIN
  3136. IF caseParts = NIL THEN NEW(caseParts,4); END;
  3137. caseParts.Add( casePart );
  3138. END AddCasePart;
  3139. PROCEDURE GetCasePart*( i: LONGINT ): CasePart;
  3140. VAR a: ANY;
  3141. BEGIN a := caseParts.Get( i ); RETURN a( CasePart )
  3142. END GetCasePart;
  3143. PROCEDURE CaseParts*( ): LONGINT;
  3144. BEGIN
  3145. IF caseParts = NIL THEN RETURN 0 ELSE RETURN caseParts.Length(); END;
  3146. END CaseParts;
  3147. PROCEDURE Clone(): Statement;
  3148. VAR copy: CaseStatement; i: LONGINT;
  3149. BEGIN
  3150. NEW(copy, position, outer);
  3151. copy.SetVariable(CloneExpression(variable));
  3152. copy.SetElsePart(CloneStatementSequence(elsePart));
  3153. FOR i := 0 TO CaseParts()-1 DO
  3154. copy.AddCasePart(GetCasePart(i).Clone());
  3155. END;
  3156. copy.min := min; copy.max := max;
  3157. RETURN copy
  3158. END Clone;
  3159. PROCEDURE Accept*(v: Visitor);
  3160. VAR position: LONGINT;
  3161. BEGIN position := SELF.position; v.VisitCaseStatement(SELF)
  3162. END Accept;
  3163. PROCEDURE MaxConstant*(): LONGINT;
  3164. VAR val,i: LONGINT; part: CasePart; const: CaseConstant;
  3165. BEGIN
  3166. val := -1;
  3167. FOR i := 0 TO CaseParts() - 1 DO
  3168. part := GetCasePart(i);
  3169. const := part.firstConstant;
  3170. WHILE(const # NIL) DO
  3171. IF const.max > val THEN val := const.max; END;
  3172. const := const.next;
  3173. END;
  3174. END;
  3175. RETURN val;
  3176. END MaxConstant;
  3177. PROCEDURE SetMinMax*(min,max: LONGINT);
  3178. BEGIN
  3179. SELF.min := min; SELF.max := max;
  3180. END SetMinMax;
  3181. END CaseStatement;
  3182. (** << WHILE condition DO statements END >> **)
  3183. WhileStatement* = OBJECT (Statement)
  3184. VAR
  3185. condition-: Expression;
  3186. statements-: StatementSequence;
  3187. PROCEDURE & InitWhileStatement( position: LONGINT ; outer: Statement);
  3188. BEGIN
  3189. InitStatement( position,outer ); condition := NIL; statements := NIL;
  3190. END InitWhileStatement;
  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: WhileStatement;
  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.VisitWhileStatement(SELF)
  3210. END Accept;
  3211. END WhileStatement;
  3212. (** << REPEAT statements UNTIL condition >> **)
  3213. RepeatStatement* = OBJECT (Statement)
  3214. VAR
  3215. condition-: Expression;
  3216. statements-: StatementSequence;
  3217. PROCEDURE & InitRepeatStatement( position: LONGINT; outer: Statement );
  3218. BEGIN
  3219. InitStatement( position,outer ); condition := NIL; statements := NIL;
  3220. END InitRepeatStatement;
  3221. PROCEDURE SetCondition*( condition: Expression );
  3222. BEGIN
  3223. SELF.condition := condition
  3224. END SetCondition;
  3225. PROCEDURE SetStatements*( statements: StatementSequence );
  3226. BEGIN
  3227. SELF.statements := statements;
  3228. END SetStatements;
  3229. PROCEDURE Clone(): Statement;
  3230. VAR copy: RepeatStatement;
  3231. BEGIN
  3232. NEW(copy, position, outer);
  3233. copy.SetCondition(CloneExpression(condition));
  3234. copy.SetStatements(CloneStatementSequence(statements));
  3235. RETURN copy
  3236. END Clone;
  3237. PROCEDURE Accept*(v: Visitor);
  3238. VAR position: LONGINT;
  3239. BEGIN position := SELF.position; v.VisitRepeatStatement(SELF)
  3240. END Accept;
  3241. END RepeatStatement;
  3242. (** << FOR variable := from TO to BY by DO statements END >> **)
  3243. ForStatement* = OBJECT (Statement)
  3244. VAR
  3245. variable-: Designator;
  3246. from-, to-, by-: Expression;
  3247. statements-: StatementSequence;
  3248. PROCEDURE & InitForStatement( position: LONGINT; outer: Statement );
  3249. BEGIN
  3250. InitStatement( position,outer ); variable := NIL;from := NIL; to := NIL; by := NIL; statements := NIL;
  3251. END InitForStatement;
  3252. PROCEDURE SetVariable*( variable: Designator);
  3253. BEGIN
  3254. SELF.variable := variable
  3255. END SetVariable;
  3256. PROCEDURE SetFrom*( from: Expression );
  3257. BEGIN
  3258. SELF.from := from
  3259. END SetFrom;
  3260. PROCEDURE SetTo*( to: Expression );
  3261. BEGIN
  3262. SELF.to := to
  3263. END SetTo;
  3264. PROCEDURE SetBy*( by: Expression );
  3265. BEGIN SELF.by := by
  3266. END SetBy;
  3267. PROCEDURE SetStatements*( statements: StatementSequence );
  3268. BEGIN SELF.statements := statements;
  3269. END SetStatements;
  3270. PROCEDURE Clone(): Statement;
  3271. VAR copy: ForStatement;
  3272. BEGIN
  3273. NEW(copy, position, outer);
  3274. copy.SetVariable(CloneDesignator(variable));
  3275. copy.SetFrom(CloneExpression(from));
  3276. copy.SetTo(CloneExpression(to));
  3277. copy.SetBy(CloneExpression(by));
  3278. copy.SetStatements(CloneStatementSequence(statements));
  3279. RETURN copy
  3280. END Clone;
  3281. PROCEDURE Accept*(v: Visitor);
  3282. VAR position: LONGINT;
  3283. BEGIN position := SELF.position; v.VisitForStatement(SELF)
  3284. END Accept;
  3285. END ForStatement;
  3286. ExitableBlock*= OBJECT (Statement)
  3287. VAR statements-: StatementSequence;
  3288. PROCEDURE & InitExitableBlock( position: LONGINT ; outer: Statement);
  3289. BEGIN
  3290. InitStatement( position ,outer); statements := NIL;
  3291. END InitExitableBlock;
  3292. PROCEDURE SetStatements*( statements: StatementSequence );
  3293. BEGIN SELF.statements := statements;
  3294. END SetStatements;
  3295. PROCEDURE Clone(): Statement;
  3296. VAR copy: ExitableBlock;
  3297. BEGIN
  3298. NEW(copy, position, outer);
  3299. copy.SetStatements(CloneStatementSequence(statements));
  3300. RETURN copy
  3301. END Clone;
  3302. PROCEDURE Accept*(v: Visitor);
  3303. VAR position: LONGINT;
  3304. BEGIN position := SELF.position; v.VisitExitableBlock(SELF)
  3305. END Accept;
  3306. END ExitableBlock;
  3307. (** << LOOP statements END >> **)
  3308. LoopStatement* = OBJECT (ExitableBlock)
  3309. PROCEDURE Clone(): Statement;
  3310. VAR copy: LoopStatement;
  3311. BEGIN
  3312. NEW(copy, position, outer);
  3313. copy.SetStatements(CloneStatementSequence(statements));
  3314. RETURN copy
  3315. END Clone;
  3316. PROCEDURE Accept*(v: Visitor);
  3317. VAR position: LONGINT;
  3318. BEGIN position := SELF.position; v.VisitLoopStatement(SELF)
  3319. END Accept;
  3320. END LoopStatement;
  3321. (** << EXIT >> **)
  3322. ExitStatement* = OBJECT (Statement)
  3323. PROCEDURE Accept*(v: Visitor);
  3324. VAR position: LONGINT;
  3325. BEGIN position := SELF.position; v.VisitExitStatement(SELF)
  3326. END Accept;
  3327. PROCEDURE Clone(): Statement;
  3328. VAR copy: ExitStatement;
  3329. BEGIN
  3330. NEW(copy, position, outer);
  3331. RETURN copy
  3332. END Clone;
  3333. END ExitStatement;
  3334. (** << RETURN returnValue >> **)
  3335. ReturnStatement* = OBJECT (Statement)
  3336. VAR returnValue-: Expression; (* strictly speaking this is not a value but this term is in common use here *)
  3337. PROCEDURE & InitReturnStatement( position: LONGINT ; outer: Statement);
  3338. BEGIN
  3339. InitStatement( position,outer ); returnValue := NIL
  3340. END InitReturnStatement;
  3341. PROCEDURE SetReturnValue*( returnValue: Expression );
  3342. BEGIN SELF.returnValue := returnValue
  3343. END SetReturnValue;
  3344. PROCEDURE Clone(): Statement;
  3345. VAR copy: ReturnStatement;
  3346. BEGIN
  3347. NEW(copy, position, outer);
  3348. copy.SetReturnValue(CloneExpression(returnValue));
  3349. RETURN copy
  3350. END Clone;
  3351. PROCEDURE Accept*(v: Visitor);
  3352. VAR position: LONGINT;
  3353. BEGIN position := SELF.position; v.VisitReturnStatement(SELF)
  3354. END Accept;
  3355. END ReturnStatement;
  3356. (** << AWAIT condition >> **)
  3357. AwaitStatement* = OBJECT (Statement)
  3358. VAR condition-: Expression;
  3359. PROCEDURE & InitAwaitStatement( position: LONGINT; outer: Statement );
  3360. BEGIN
  3361. InitStatement( position,outer ); condition := NIL
  3362. END InitAwaitStatement;
  3363. PROCEDURE SetCondition*( condition: Expression );
  3364. BEGIN SELF.condition := condition
  3365. END SetCondition;
  3366. PROCEDURE Clone(): Statement;
  3367. VAR copy: AwaitStatement;
  3368. BEGIN
  3369. NEW(copy, position, outer);
  3370. copy.SetCondition(CloneExpression(condition));
  3371. RETURN copy
  3372. END Clone;
  3373. PROCEDURE Accept*(v: Visitor);
  3374. VAR position: LONGINT;
  3375. BEGIN position := SELF.position; v.VisitAwaitStatement(SELF)
  3376. END Accept;
  3377. END AwaitStatement;
  3378. (* << Identifier ( Expression) >> *)
  3379. Modifier*= OBJECT
  3380. VAR
  3381. identifier-: Identifier; expression-: Expression;
  3382. resolved-: BOOLEAN;
  3383. nextModifier-: Modifier;
  3384. position-: LONGINT;
  3385. PROCEDURE & InitModifier(position: LONGINT; identifier: Identifier; expression: Expression);
  3386. BEGIN
  3387. SELF.position := position;
  3388. SELF.identifier := identifier; SELF.expression := expression; nextModifier := NIL; resolved := FALSE;
  3389. END InitModifier;
  3390. PROCEDURE Resolved*;
  3391. BEGIN resolved := TRUE
  3392. END Resolved;
  3393. PROCEDURE SetExpression*(e: Expression);
  3394. BEGIN SELF.expression := e
  3395. END SetExpression;
  3396. PROCEDURE SetNext*(modifier: Modifier);
  3397. BEGIN nextModifier := modifier
  3398. END SetNext;
  3399. END Modifier;
  3400. (** << BEGIN {Modifier, Modifier ... } statements END >> **)
  3401. StatementBlock* = OBJECT (Statement)
  3402. VAR
  3403. statements-: StatementSequence;
  3404. blockModifiers-: Modifier;
  3405. isExclusive-: BOOLEAN;
  3406. isRealtime-: BOOLEAN;
  3407. isUnchecked-: BOOLEAN;
  3408. isUncooperative-: BOOLEAN;
  3409. PROCEDURE & InitStatementBlock( position: LONGINT ; outer: Statement);
  3410. BEGIN
  3411. InitStatement( position ,outer); statements := NIL; blockModifiers := NIL;
  3412. isExclusive := FALSE;
  3413. isRealtime := FALSE;
  3414. isUnchecked := FALSE;
  3415. isUncooperative := FALSE;
  3416. END InitStatementBlock;
  3417. PROCEDURE SetRealtime*(b: BOOLEAN);
  3418. BEGIN
  3419. isRealtime := b
  3420. END SetRealtime;
  3421. PROCEDURE SetUnchecked*(unchecked: BOOLEAN);
  3422. BEGIN
  3423. isUnchecked := unchecked
  3424. END SetUnchecked;
  3425. PROCEDURE SetUncooperative*(uncooperative: BOOLEAN);
  3426. BEGIN
  3427. isUncooperative := uncooperative
  3428. END SetUncooperative;
  3429. PROCEDURE SetModifier*(modifier: Modifier);
  3430. BEGIN
  3431. blockModifiers := modifier;
  3432. END SetModifier;
  3433. PROCEDURE SetExclusive*(excl: BOOLEAN);
  3434. BEGIN isExclusive := excl
  3435. END SetExclusive;
  3436. PROCEDURE SetStatementSequence*( statements: StatementSequence );
  3437. BEGIN SELF.statements := statements;
  3438. END SetStatementSequence;
  3439. PROCEDURE Accept*(v: Visitor);
  3440. VAR position: LONGINT;
  3441. BEGIN position := SELF.position; v.VisitStatementBlock(SELF)
  3442. END Accept;
  3443. END StatementBlock;
  3444. (** << CODE {flags} {character} END >> **)
  3445. Code*= OBJECT(Statement)
  3446. VAR
  3447. sourceCode-: SourceCode; sourceCodeLength-: LONGINT;
  3448. inlineCode-: BinaryCode;
  3449. inRules-, outRules-: StatementSequence;
  3450. PROCEDURE & InitCode(position: LONGINT; outer: Statement);
  3451. BEGIN
  3452. InitStatement(position,outer);
  3453. inlineCode := NIL;
  3454. sourceCode := NIL; sourceCodeLength := 0;
  3455. NEW(inRules); NEW(outRules);
  3456. END InitCode;
  3457. PROCEDURE SetSourceCode*(source: SourceCode; length: LONGINT);
  3458. BEGIN sourceCode := source; sourceCodeLength := length;
  3459. ASSERT(sourceCodeLength <= LEN(source));
  3460. END SetSourceCode;
  3461. PROCEDURE SetBinaryCode*(code: BinaryCode);
  3462. BEGIN
  3463. inlineCode := code;
  3464. END SetBinaryCode;
  3465. PROCEDURE Clone(): Statement;
  3466. VAR copy: Code; s: Scanner.StringType;
  3467. BEGIN
  3468. NEW(copy, position, outer);
  3469. NEW(s, sourceCodeLength);
  3470. Strings.Copy(sourceCode^,0,sourceCodeLength,s^);
  3471. copy.SetSourceCode(s, sourceCodeLength);
  3472. copy.inRules := CloneStatementSequence(inRules);
  3473. copy.outRules := CloneStatementSequence(outRules);
  3474. RETURN copy
  3475. END Clone;
  3476. PROCEDURE Accept*(v: Visitor);
  3477. VAR position: LONGINT;
  3478. BEGIN position := SELF.position; v.VisitCode(SELF)
  3479. END Accept;
  3480. END Code;
  3481. (** << BEGIN {flags} statements FINALLY statements END >> **)
  3482. Body*= OBJECT(StatementBlock)
  3483. VAR
  3484. finally-: StatementSequence;
  3485. priority-: Expression; (* set by checker *)
  3486. inScope-: ProcedureScope;
  3487. code-: Code;
  3488. isActive-, isSafe-: BOOLEAN;
  3489. PROCEDURE & InitBody(position: LONGINT; scope: ProcedureScope);
  3490. BEGIN
  3491. InitStatementBlock(position,NIL); finally := NIL; priority := NIL; inScope := scope; code := NIL;
  3492. isActive := FALSE; isSafe := FALSE; isRealtime := FALSE;
  3493. END InitBody;
  3494. PROCEDURE SetActive*(active: BOOLEAN);
  3495. BEGIN SELF.isActive := active
  3496. END SetActive;
  3497. PROCEDURE SetSafe*(safe: BOOLEAN);
  3498. BEGIN SELF.isSafe := safe
  3499. END SetSafe;
  3500. PROCEDURE SetFinally*( finally: StatementSequence );
  3501. BEGIN SELF.finally := finally
  3502. END SetFinally;
  3503. PROCEDURE SetPriority*(expression: Expression);
  3504. BEGIN priority := expression
  3505. END SetPriority;
  3506. PROCEDURE SetCode*(code: Code);
  3507. BEGIN SELF.code := code;
  3508. END SetCode;
  3509. END Body;
  3510. (** (* comment *) *)
  3511. Comment*=OBJECT
  3512. VAR position-: LONGINT;
  3513. source-: String; (* currently: POINTER TO ARRAY OF CHAR *)
  3514. scope-: Scope;
  3515. item-: ANY; sameLine-: BOOLEAN;
  3516. nextComment-: Comment;
  3517. PROCEDURE & InitComment(pos: LONGINT; scope: Scope; CONST s: ARRAY OF CHAR; length: LONGINT);
  3518. VAR i: LONGINT;
  3519. BEGIN
  3520. SELF.scope := scope;
  3521. NEW(source,length);
  3522. FOR i := 0 TO length-1 DO
  3523. source[i] := s[i];
  3524. END;
  3525. SELF.position := pos;
  3526. nextComment := NIL;
  3527. item := NIL; sameLine := FALSE;
  3528. END InitComment;
  3529. PROCEDURE SetItem*(p: ANY; sameLine: BOOLEAN);
  3530. BEGIN
  3531. item := p; SELF.sameLine := sameLine
  3532. END SetItem;
  3533. END Comment;
  3534. (**** building blocks ****)
  3535. Scope*=OBJECT
  3536. VAR
  3537. firstSymbol-: Symbol; numberSymbols-: LONGINT; (* all symbols in scope (sorted) *)
  3538. firstConstant-,lastConstant-: Constant; numberConstants-: LONGINT; (* constants *)
  3539. firstTypeDeclaration-,lastTypeDeclaration-: TypeDeclaration; numberTypeDeclarations-: LONGINT; (* type declarations *)
  3540. firstVariable-,lastVariable-: Variable; numberVariables-: LONGINT; (* variables *)
  3541. firstProcedure-,lastProcedure-: Procedure; numberProcedures-: LONGINT; (* procedures *)
  3542. outerScope-: Scope; nextScope-: Scope;
  3543. ownerModule-: Module;
  3544. PROCEDURE & InitScope(outer: Scope);
  3545. BEGIN
  3546. firstSymbol := NIL; numberSymbols := 0;
  3547. firstConstant := NIL; lastConstant := NIL; numberConstants := 0;
  3548. firstTypeDeclaration := NIL; lastTypeDeclaration := NIL; numberTypeDeclarations := 0;
  3549. firstVariable := NIL; lastVariable := NIL; numberVariables := 0;
  3550. firstProcedure := NIL; lastProcedure := NIL; numberProcedures := 0;
  3551. outerScope := outer;
  3552. IF outer # NIL THEN
  3553. ownerModule := outer.ownerModule
  3554. ELSE
  3555. ownerModule := NIL;
  3556. END;
  3557. nextScope := NIL;
  3558. END InitScope;
  3559. (** Enter a symbol in the scope, aplhabetically sorted, duplicate = TRUE if multiply identifier *)
  3560. PROCEDURE EnterSymbol*(symbol: Symbol; VAR duplicate: BOOLEAN);
  3561. VAR p,q: Symbol; name,nextname: Scanner.StringType;
  3562. BEGIN
  3563. ASSERT(symbol.nextSymbol = NIL,101); (* symbol may only be present in one scope at a time ! *)
  3564. ASSERT(symbol.scope = NIL,102);
  3565. ASSERT(symbol.name # invalidIdentifier,103);
  3566. p := firstSymbol; q := NIL;
  3567. WHILE (p # NIL) & (StringPool.CompareString(p.name,symbol.name)<0) DO q := p; p := p.nextSymbol END;
  3568. IF (p#NIL) & (symbol.name = p.name) THEN
  3569. duplicate := TRUE;
  3570. ELSE
  3571. duplicate := FALSE
  3572. END;
  3573. symbol.nextSymbol := p;
  3574. IF q = NIL THEN firstSymbol := symbol ELSE q.nextSymbol := symbol END;
  3575. symbol.SetScope(SELF);
  3576. INC(numberSymbols);
  3577. END EnterSymbol;
  3578. (** Find symbol by name *)
  3579. PROCEDURE FindSymbol*(identifier: Identifier): Symbol;
  3580. VAR p: Symbol;
  3581. BEGIN
  3582. IF identifier # invalidIdentifier THEN
  3583. p := firstSymbol;
  3584. WHILE(p#NIL) & ((p.name # identifier) OR (p IS Operator)) DO p := p.nextSymbol END;
  3585. END;
  3586. RETURN p;
  3587. END FindSymbol;
  3588. PROCEDURE AddConstant*(c: Constant);
  3589. BEGIN
  3590. ASSERT(c # NIL);
  3591. IF lastConstant= NIL THEN firstConstant := c ELSE lastConstant.nextConstant := c END;
  3592. lastConstant := c;
  3593. INC(numberConstants);
  3594. END AddConstant;
  3595. PROCEDURE FindConstant*(identifier: Identifier): Constant;
  3596. VAR p: Constant;
  3597. BEGIN
  3598. p := firstConstant;
  3599. WHILE(p#NIL) & (p.name # identifier) DO p := p.nextConstant END;
  3600. RETURN p;
  3601. END FindConstant;
  3602. PROCEDURE AddTypeDeclaration*(t: TypeDeclaration);
  3603. BEGIN
  3604. ASSERT(t # NIL);
  3605. IF lastTypeDeclaration= NIL THEN firstTypeDeclaration := t ELSE lastTypeDeclaration.nextTypeDeclaration := t END;
  3606. INC(numberTypeDeclarations);
  3607. lastTypeDeclaration := t;
  3608. END AddTypeDeclaration;
  3609. PROCEDURE FindTypeDeclaration*(identifier: Identifier): TypeDeclaration;
  3610. VAR p: TypeDeclaration;
  3611. BEGIN
  3612. p := firstTypeDeclaration;
  3613. WHILE(p#NIL) & (p.name # identifier) DO p := p.nextTypeDeclaration END;
  3614. RETURN p;
  3615. END FindTypeDeclaration;
  3616. PROCEDURE AddVariable*(v: Variable);
  3617. BEGIN
  3618. ASSERT(v # NIL);
  3619. IF lastVariable= NIL THEN firstVariable := v ELSE lastVariable.nextVariable := v END;
  3620. INC(numberVariables);
  3621. lastVariable := v;
  3622. END AddVariable;
  3623. PROCEDURE PushVariable*(v: Variable);
  3624. BEGIN
  3625. ASSERT(v # NIL);
  3626. IF lastVariable= NIL THEN lastVariable := v ELSE v.nextVariable := firstVariable END;
  3627. INC(numberVariables);
  3628. firstVariable := v;
  3629. END PushVariable;
  3630. PROCEDURE FindVariable*(identifier: Identifier): Variable;
  3631. VAR p: Variable;
  3632. BEGIN
  3633. p := firstVariable;
  3634. WHILE(p#NIL) & (p.name # identifier) DO p := p.nextVariable END;
  3635. RETURN p;
  3636. END FindVariable;
  3637. PROCEDURE AddProcedure*(p: Procedure);
  3638. BEGIN
  3639. ASSERT(p # NIL);
  3640. IF lastProcedure= NIL THEN firstProcedure := p ELSE lastProcedure.nextProcedure := p END;
  3641. INC(numberProcedures);
  3642. lastProcedure := p;
  3643. END AddProcedure;
  3644. PROCEDURE FindProcedure*(identifier: Identifier): Procedure;
  3645. VAR p: Procedure;
  3646. BEGIN
  3647. p := firstProcedure;
  3648. WHILE (p#NIL) & ((p.name # identifier) OR (p IS Operator)) DO p := p.nextProcedure END;
  3649. RETURN p;
  3650. END FindProcedure;
  3651. PROCEDURE FindMethod*(number: LONGINT): Procedure;
  3652. VAR p: Procedure;
  3653. BEGIN
  3654. p := firstProcedure;
  3655. WHILE (p# NIL) & (p.methodNumber # number) DO
  3656. p := p.nextProcedure
  3657. END;
  3658. RETURN p;
  3659. END FindMethod;
  3660. PROCEDURE Level*(): LONGINT;
  3661. VAR scope: Scope; level: LONGINT;
  3662. BEGIN
  3663. level := 0;
  3664. scope := SELF;
  3665. WHILE(scope.outerScope # NIL) DO
  3666. scope := scope.outerScope;
  3667. INC(level);
  3668. END;
  3669. RETURN level;
  3670. END Level;
  3671. PROCEDURE NeedsTrace* (): BOOLEAN;
  3672. VAR variable: Variable;
  3673. BEGIN
  3674. variable := firstVariable;
  3675. WHILE variable # NIL DO
  3676. IF variable.NeedsTrace () THEN RETURN TRUE END;
  3677. variable := variable.nextVariable;
  3678. END;
  3679. RETURN FALSE;
  3680. END NeedsTrace;
  3681. END Scope;
  3682. ProcedureScope*=OBJECT (Scope)
  3683. VAR
  3684. ownerProcedure-: Procedure;
  3685. body-: Body;
  3686. PROCEDURE & InitProcedureScope(outer: Scope);
  3687. BEGIN
  3688. InitScope(outer);
  3689. ownerProcedure := NIL;
  3690. body := NIL;
  3691. END InitProcedureScope;
  3692. PROCEDURE SetBody*(body: Body);
  3693. BEGIN
  3694. SELF.body := body;
  3695. END SetBody;
  3696. PROCEDURE NeedsTrace* (): BOOLEAN;
  3697. VAR parameter: Parameter;
  3698. BEGIN
  3699. parameter := ownerProcedure.type.resolved(ProcedureType).firstParameter;
  3700. WHILE parameter # NIL DO
  3701. IF parameter.NeedsTrace () THEN RETURN TRUE END;
  3702. parameter := parameter.nextParameter;
  3703. END;
  3704. RETURN NeedsTrace^();
  3705. END NeedsTrace;
  3706. END ProcedureScope;
  3707. EnumerationScope*= OBJECT(Scope)
  3708. VAR
  3709. ownerEnumeration-: EnumerationType;
  3710. (** Find symbol by name *)
  3711. PROCEDURE FindSymbol*(identifier: Identifier): Symbol;
  3712. VAR p: Symbol; base: Type;
  3713. BEGIN
  3714. p := FindSymbol^(identifier);
  3715. IF p = NIL THEN
  3716. base := ownerEnumeration.enumerationBase;
  3717. IF (base # NIL) & (base.resolved IS EnumerationType) THEN
  3718. p := base.resolved(EnumerationType).enumerationScope.FindSymbol(identifier)
  3719. END;
  3720. END;
  3721. RETURN p;
  3722. END FindSymbol;
  3723. PROCEDURE &InitEnumerationScope(outer: Scope);
  3724. BEGIN
  3725. InitScope(outer);
  3726. ownerEnumeration := NIL; (* must be set by EnumerationType *)
  3727. END InitEnumerationScope;
  3728. END EnumerationScope;
  3729. RecordScope*= OBJECT(Scope)
  3730. VAR
  3731. ownerRecord-: RecordType;
  3732. bodyProcedure-: Procedure;
  3733. constructor-: Procedure;
  3734. finalizer-: Procedure;
  3735. numberMethods-: LONGINT;
  3736. firstParameter-,lastParameter-: Parameter; numberParameters-: LONGINT; (* parameters for Active Cells programming*)
  3737. firstOperator-, lastOperator-: Operator; numberOperators: LONGINT; (* defined operators *)
  3738. PROCEDURE & InitRecordScope(outer: Scope);
  3739. BEGIN
  3740. InitScope(outer);
  3741. ownerRecord := NIL;
  3742. numberMethods := 0;
  3743. bodyProcedure := NIL;
  3744. constructor := NIL;
  3745. finalizer := NIL;
  3746. firstOperator := NIL; lastOperator := NIL; numberOperators := 0;
  3747. END InitRecordScope;
  3748. PROCEDURE SetBodyProcedure*(body: Procedure);
  3749. BEGIN SELF.bodyProcedure := body;
  3750. END SetBodyProcedure;
  3751. PROCEDURE SetConstructor*(body: Procedure);
  3752. BEGIN SELF.constructor := body
  3753. END SetConstructor;
  3754. PROCEDURE SetFinalizer*(body: Procedure);
  3755. BEGIN SELF.finalizer := body
  3756. END SetFinalizer;
  3757. PROCEDURE SetNumberMethods*(numberMethods: LONGINT);
  3758. BEGIN SELF.numberMethods := numberMethods;
  3759. END SetNumberMethods;
  3760. PROCEDURE AddOperator*(p: Operator);
  3761. BEGIN
  3762. ASSERT(p # NIL);
  3763. IF lastOperator= NIL THEN firstOperator := p ELSE lastOperator.nextOperator := p END;
  3764. INC(numberOperators);
  3765. lastOperator := p;
  3766. END AddOperator;
  3767. (** Find symbol by name *)
  3768. PROCEDURE FindSymbol*(identifier: Identifier): Symbol;
  3769. VAR p: Symbol; base: RecordType;
  3770. BEGIN
  3771. p := FindSymbol^(identifier);
  3772. IF p = NIL THEN
  3773. base := ownerRecord.GetBaseRecord();
  3774. IF (base # NIL) THEN
  3775. p := base.recordScope.FindSymbol(identifier)
  3776. END;
  3777. END;
  3778. RETURN p;
  3779. END FindSymbol;
  3780. PROCEDURE FindConstant*(identifier: Identifier): Constant;
  3781. VAR p: Constant; base: RecordType;
  3782. BEGIN
  3783. p := FindConstant^(identifier);
  3784. IF p = NIL THEN
  3785. base := ownerRecord.GetBaseRecord();
  3786. IF (base # NIL) THEN
  3787. p := base.recordScope.FindConstant(identifier)
  3788. END;
  3789. END;
  3790. RETURN p;
  3791. END FindConstant;
  3792. PROCEDURE FindTypeDeclaration*(identifier: Identifier): TypeDeclaration;
  3793. VAR p: TypeDeclaration; base: RecordType;
  3794. BEGIN
  3795. p := FindTypeDeclaration^(identifier);
  3796. IF p = NIL THEN
  3797. base := ownerRecord.GetBaseRecord();
  3798. IF (base # NIL) THEN
  3799. p := base.recordScope.FindTypeDeclaration(identifier)
  3800. END;
  3801. END;
  3802. RETURN p;
  3803. END FindTypeDeclaration;
  3804. PROCEDURE FindVariable*(identifier: Identifier): Variable;
  3805. VAR p: Variable; base: RecordType;
  3806. BEGIN
  3807. p := FindVariable^(identifier);
  3808. IF p = NIL THEN
  3809. base := ownerRecord.GetBaseRecord();
  3810. IF (base # NIL) THEN
  3811. p := base.recordScope.FindVariable(identifier)
  3812. END;
  3813. END;
  3814. RETURN p;
  3815. END FindVariable;
  3816. PROCEDURE FindProcedure*(identifier: Identifier): Procedure;
  3817. VAR p: Procedure; base: RecordType;
  3818. BEGIN
  3819. p := FindProcedure^(identifier);
  3820. IF p = NIL THEN
  3821. base := ownerRecord.GetBaseRecord();
  3822. IF (base # NIL) THEN
  3823. p := base.recordScope.FindProcedure(identifier)
  3824. END;
  3825. END;
  3826. RETURN p;
  3827. END FindProcedure;
  3828. PROCEDURE FindMethod*(number: LONGINT): Procedure;
  3829. VAR p: Procedure; base: RecordType;
  3830. BEGIN
  3831. p := FindMethod^(number);
  3832. IF p = NIL THEN
  3833. base := ownerRecord.GetBaseRecord();
  3834. IF (base # NIL) THEN
  3835. p := base.recordScope.FindMethod(number)
  3836. END;
  3837. END;
  3838. RETURN p;
  3839. END FindMethod;
  3840. PROCEDURE NeedsTrace* (): BOOLEAN;
  3841. VAR base: RecordType;
  3842. BEGIN
  3843. base := ownerRecord.GetBaseRecord();
  3844. IF (base # NIL) & (base.NeedsTrace ()) THEN RETURN TRUE END;
  3845. RETURN NeedsTrace^();
  3846. END NeedsTrace;
  3847. END RecordScope;
  3848. CellScope*=OBJECT (Scope)
  3849. VAR
  3850. ownerCell-: CellType;
  3851. bodyProcedure-: Procedure;
  3852. constructor-: Procedure;
  3853. PROCEDURE & InitCellScope(outer: Scope);
  3854. BEGIN
  3855. InitScope(outer);
  3856. ownerCell := NIL;
  3857. bodyProcedure := NIL;
  3858. constructor := NIL;
  3859. END InitCellScope;
  3860. PROCEDURE SetOwnerCell*(owner: CellType);
  3861. BEGIN
  3862. ownerCell := owner
  3863. END SetOwnerCell;
  3864. PROCEDURE SetBodyProcedure*(bodyProcedure: Procedure);
  3865. BEGIN
  3866. SELF.bodyProcedure := bodyProcedure;
  3867. END SetBodyProcedure;
  3868. PROCEDURE SetConstructor*(p: Procedure);
  3869. BEGIN constructor := p
  3870. END SetConstructor;
  3871. PROCEDURE FindSymbol*(identifier: Identifier): Symbol;
  3872. VAR p: Symbol; base: Type;
  3873. BEGIN
  3874. p := FindSymbol^(identifier);
  3875. IF p = NIL THEN
  3876. IF ownerCell.isCellNet THEN
  3877. RETURN ownerCell.FindProperty(identifier);
  3878. END;
  3879. END;
  3880. IF p = NIL THEN
  3881. base := ownerCell.baseType;
  3882. IF (base # NIL) THEN
  3883. base := base.resolved;
  3884. IF base IS PointerType THEN
  3885. base := base(PointerType).pointerBase.resolved;
  3886. END;
  3887. WITH base: CellType DO
  3888. p := base.cellScope.FindSymbol(identifier)
  3889. |base: RecordType DO
  3890. p := base.recordScope.FindSymbol(identifier)
  3891. END;
  3892. END;
  3893. END;
  3894. RETURN p;
  3895. END FindSymbol;
  3896. END CellScope;
  3897. (**
  3898. <<
  3899. IMPORT firstImport .. lastImport;
  3900. ...
  3901. firstOperator ... lastOperator
  3902. ....
  3903. >>
  3904. **)
  3905. ModuleScope*= OBJECT(Scope)
  3906. VAR
  3907. firstImport-,lastImport-: Import; numberImports: LONGINT; (* imported modules *)
  3908. firstOperator-,lastOperator-: Operator; numberOperators: LONGINT; (* defined operators *)
  3909. firstBuiltin-,lastBuiltin-: Builtin; numberBuiltins: LONGINT; (* defined builtins, only for global and system module *)
  3910. firstComment-,lastComment-: Comment; numberComments-: LONGINT; (* comments *)
  3911. bodyProcedure-: Procedure;
  3912. PROCEDURE & InitModuleScope;
  3913. BEGIN
  3914. InitScope(NIL);
  3915. firstComment := NIL; lastComment := NIL; numberComments := 0;
  3916. firstImport:= NIL; lastImport := NIL; numberImports := 0;
  3917. firstOperator := NIL; lastOperator := NIL; numberOperators := 0;
  3918. END InitModuleScope;
  3919. PROCEDURE SetBodyProcedure*(body: Procedure);
  3920. BEGIN SELF.bodyProcedure := body;
  3921. END SetBodyProcedure;
  3922. PROCEDURE SetGlobalScope*(outer: Scope);
  3923. BEGIN
  3924. SELF.outerScope := outer;
  3925. END SetGlobalScope;
  3926. PROCEDURE AddBuiltin*(p: Builtin);
  3927. BEGIN
  3928. ASSERT(p # NIL);
  3929. IF lastBuiltin= NIL THEN firstBuiltin := p ELSE lastBuiltin.nextBuiltin := p END;
  3930. INC(numberBuiltins);
  3931. lastBuiltin := p;
  3932. END AddBuiltin;
  3933. PROCEDURE AddOperator*(p: Operator);
  3934. BEGIN
  3935. ASSERT(p # NIL);
  3936. IF lastOperator= NIL THEN firstOperator := p ELSE lastOperator.nextOperator := p END;
  3937. INC(numberOperators);
  3938. lastOperator := p;
  3939. END AddOperator;
  3940. PROCEDURE FindOperator*(identifier: Identifier): Operator;
  3941. VAR p: Operator;
  3942. BEGIN
  3943. p := firstOperator;
  3944. WHILE(p#NIL) & (p.name # identifier) DO p := p.nextOperator END;
  3945. RETURN p;
  3946. END FindOperator;
  3947. PROCEDURE AddImport*(i: Import);
  3948. BEGIN
  3949. ASSERT(i # NIL);
  3950. ASSERT(i.nextImport = NIL);
  3951. IF lastImport= NIL THEN firstImport:= i ELSE lastImport.nextImport := i END;
  3952. lastImport := i;
  3953. INC(numberImports);
  3954. END AddImport;
  3955. PROCEDURE FindImport*(identifier: Identifier): Import;
  3956. VAR p: Import;
  3957. BEGIN
  3958. p := firstImport;
  3959. WHILE(p#NIL) & (p.name # identifier) DO p := p.nextImport END; (* finds imports and re-imports! *)
  3960. RETURN p;
  3961. END FindImport;
  3962. PROCEDURE GetImport*( index: LONGINT ): Import;
  3963. VAR import: Import;
  3964. BEGIN
  3965. import := firstImport;
  3966. WHILE(import # NIL) & (index > 0) DO
  3967. import := import.nextImport;
  3968. DEC(index);
  3969. END;
  3970. RETURN import;
  3971. END GetImport;
  3972. PROCEDURE AddComment*(comment: Comment);
  3973. BEGIN
  3974. ASSERT(comment # NIL);
  3975. IF lastComment= NIL THEN firstComment := comment ELSE lastComment.nextComment := comment END;
  3976. INC(numberComments);
  3977. lastComment := comment;
  3978. END AddComment;
  3979. PROCEDURE ImportByModuleName*(moduleName,context: Identifier): Import;
  3980. VAR p: Import;
  3981. BEGIN
  3982. p := firstImport;
  3983. WHILE(p#NIL) & ~((moduleName = p.moduleName) & (context = p.context)) DO p := p.nextImport END;
  3984. RETURN p;
  3985. END ImportByModuleName;
  3986. PROCEDURE RemoveImporters*(moduleName,context: Identifier);
  3987. VAR this: Import;
  3988. PROCEDURE Check(p: Import): BOOLEAN;
  3989. VAR result: BOOLEAN;
  3990. BEGIN
  3991. IF (moduleName = p.moduleName) & (context = p.context) THEN
  3992. result := TRUE
  3993. ELSE
  3994. result := p.module.moduleScope.ImportByModuleName(moduleName,context) # NIL;
  3995. END;
  3996. RETURN result
  3997. END Check;
  3998. BEGIN
  3999. WHILE(firstImport # NIL) & Check(firstImport) DO
  4000. firstImport := firstImport.nextImport;
  4001. DEC(numberImports);
  4002. END;
  4003. IF firstImport = NIL THEN lastImport := NIL
  4004. ELSE
  4005. this :=firstImport;
  4006. WHILE(this.nextImport # NIL) DO
  4007. IF Check(this.nextImport) THEN
  4008. this.nextImport := this.nextImport.nextImport;
  4009. DEC(numberImports);
  4010. ELSE
  4011. this := this.nextImport
  4012. END;
  4013. END;
  4014. lastImport := this;
  4015. END;
  4016. END RemoveImporters;
  4017. END ModuleScope;
  4018. (* << MODULE name ['in' context] moduleScope name '.' >> *)
  4019. Module* = OBJECT (Symbol)
  4020. VAR
  4021. sourceName-: Basic.FileName;
  4022. moduleScope-: ModuleScope;
  4023. context-:Identifier; (* modules context *)
  4024. case-: LONGINT; (* module notation in lower or upper case, important for printout and operators *)
  4025. isCellNet-: BOOLEAN;
  4026. firstScope-,lastScope-: Scope; numberScopes-: LONGINT; (* list of all scopes for checker / backend traversal etc. *)
  4027. closingComment-: Comment;
  4028. modifiers-: Modifier;
  4029. PROCEDURE & InitModule( CONST sourceName: ARRAY OF CHAR; position: LONGINT; name: Identifier; scope: ModuleScope; case: LONGINT);
  4030. BEGIN
  4031. InitSymbol(position,name);
  4032. COPY (sourceName, SELF.sourceName);
  4033. moduleScope := scope;
  4034. ASSERT(scope.ownerModule = NIL); (* cannot register twice ! *)
  4035. scope.ownerModule := SELF;
  4036. context := invalidIdentifier;
  4037. SELF.case := case;
  4038. firstScope := NIL; lastScope := NIL; numberScopes := 0;
  4039. SetType(moduleType);
  4040. closingComment := NIL;
  4041. isCellNet := FALSE;
  4042. modifiers := NIL;
  4043. END InitModule;
  4044. PROCEDURE SetCase*(case: LONGINT);
  4045. BEGIN
  4046. SELF.case := case
  4047. END SetCase;
  4048. PROCEDURE SetCellNet*(isCellNet: BOOLEAN);
  4049. BEGIN SELF.isCellNet := isCellNet
  4050. END SetCellNet;
  4051. PROCEDURE SetContext*(context: Identifier);
  4052. BEGIN SELF.context := context;
  4053. END SetContext;
  4054. PROCEDURE SetName*(name: Identifier);
  4055. BEGIN SELF.name := name
  4056. END SetName;
  4057. PROCEDURE SetClosingComment*(comment: Comment);
  4058. BEGIN SELF.closingComment := comment
  4059. END SetClosingComment;
  4060. PROCEDURE SetModifiers*(modifiers: Modifier);
  4061. BEGIN SELF.modifiers := modifiers
  4062. END SetModifiers;
  4063. PROCEDURE AddScope*(c: Scope);
  4064. BEGIN
  4065. IF lastScope= NIL THEN firstScope := c ELSE lastScope.nextScope := c END;
  4066. lastScope := c;
  4067. INC(numberScopes);
  4068. END AddScope;
  4069. PROCEDURE Accept*(v: Visitor);
  4070. VAR position: LONGINT;
  4071. BEGIN position := SELF.position; v.VisitModule(SELF)
  4072. END Accept;
  4073. END Module;
  4074. (** <<expression, expression, ...>> **)
  4075. SymbolList* = OBJECT
  4076. VAR list: Basic.List;
  4077. PROCEDURE & InitList*;
  4078. BEGIN NEW( list,8 );
  4079. END InitList;
  4080. PROCEDURE Length*( ): LONGINT;
  4081. BEGIN RETURN list.Length();
  4082. END Length;
  4083. PROCEDURE AddSymbol*( d: Symbol );
  4084. BEGIN list.Add(d)
  4085. END AddSymbol;
  4086. PROCEDURE GetSymbol*( index: LONGINT ): Symbol;
  4087. VAR p: ANY;
  4088. BEGIN
  4089. p := list.Get(index); RETURN p(Symbol);
  4090. END GetSymbol;
  4091. PROCEDURE SetSymbol*(index: LONGINT; expression: Symbol);
  4092. BEGIN list.Set(index,expression)
  4093. END SetSymbol;
  4094. PROCEDURE RemoveSymbol*(i: LONGINT);
  4095. BEGIN list.RemoveByIndex(i);
  4096. END RemoveSymbol;
  4097. (*
  4098. PROCEDURE Clone*(VAR list: SymbolList);
  4099. VAR i: LONGINT;
  4100. BEGIN
  4101. IF list = NIL THEN NEW(list) END;
  4102. FOR i := 0 TO Length()-1 DO
  4103. list.AddSymbol(CloneSymbol(GetSymbol(i)));
  4104. END;
  4105. END Clone;
  4106. *)
  4107. END SymbolList;
  4108. VAR
  4109. (* invalid items used, for example, by parser and checker *)
  4110. invalidIdentifier-: Identifier;
  4111. invalidQualifiedIdentifier-: QualifiedIdentifier;
  4112. invalidType-: Type;
  4113. invalidExpression-: Expression; (* mapped to invalidDesignator for better error handling in checker *)
  4114. invalidDesignator-: Designator;
  4115. invalidValue-: Value;
  4116. invalidSymbol-: Symbol;
  4117. anonymousIdentifier-: Identifier;
  4118. importType-: Type;
  4119. typeDeclarationType-: Type;
  4120. moduleType-: Type;
  4121. indexListSeparator-: Expression;
  4122. PROCEDURE InitFingerPrint*(VAR fingerprint: FingerPrint);
  4123. BEGIN
  4124. fingerprint.shallowAvailable := FALSE;
  4125. fingerprint.deepAvailable := FALSE;
  4126. fingerprint.shallow := 0;
  4127. fingerprint.private := 0;
  4128. fingerprint.public := 0;
  4129. END InitFingerPrint;
  4130. PROCEDURE NewModule*( CONST sourceName: ARRAY OF CHAR; position: LONGINT; name: Identifier;scope: ModuleScope; case: LONGINT ): Module;
  4131. VAR module: Module;
  4132. BEGIN
  4133. NEW( module, sourceName, position, name, scope, case); RETURN module;
  4134. END NewModule;
  4135. PROCEDURE NewComment*(position: LONGINT; scope: Scope; CONST source: ARRAY OF CHAR; length: LONGINT): Comment;
  4136. VAR comment: Comment;
  4137. BEGIN
  4138. NEW(comment,position,scope,source,length); RETURN comment;
  4139. END NewComment;
  4140. PROCEDURE NewImport*( position: LONGINT; alias, name: Identifier; direct: BOOLEAN): Import;
  4141. VAR import: Import;
  4142. BEGIN
  4143. NEW( import, position, alias, name, direct ); RETURN import
  4144. END NewImport;
  4145. PROCEDURE NewConstant*( position: LONGINT; name: Identifier ): Constant;
  4146. VAR constant: Constant;
  4147. BEGIN
  4148. NEW( constant, position, name ); RETURN constant
  4149. END NewConstant;
  4150. PROCEDURE NewProcedure*( position: LONGINT; name: Identifier; scope: ProcedureScope ): Procedure;
  4151. VAR procedure: Procedure;
  4152. BEGIN
  4153. NEW( procedure, position, name, scope); RETURN procedure
  4154. END NewProcedure;
  4155. PROCEDURE NewBuiltin*(position: LONGINT; name: Identifier; id: LONGINT): Builtin;
  4156. VAR builtin: Builtin;
  4157. BEGIN
  4158. NEW(builtin,position,name,id); RETURN builtin
  4159. END NewBuiltin;
  4160. PROCEDURE NewCustomBuiltin*(position: LONGINT; name: Identifier; id: LONGINT; subType: SHORTINT): CustomBuiltin;
  4161. VAR builtin:CustomBuiltin;
  4162. BEGIN
  4163. NEW(builtin,position,name,id,subType); RETURN builtin
  4164. END NewCustomBuiltin;
  4165. PROCEDURE NewOperator*( position: LONGINT; name: Identifier; scope: ProcedureScope): Operator;
  4166. VAR operator: Operator;
  4167. BEGIN
  4168. NEW( operator, position, name, scope); RETURN operator
  4169. END NewOperator;
  4170. PROCEDURE NewType*(): Type; (* for error handling: invalid Type, is realtime type *)
  4171. VAR type: Type;
  4172. BEGIN
  4173. NEW( type, -1);
  4174. type.SetRealtime(TRUE);
  4175. RETURN type
  4176. END NewType;
  4177. PROCEDURE NewByteType*(sizeInBits: LONGINT): ByteType;
  4178. VAR basicType: ByteType;
  4179. BEGIN
  4180. NEW(basicType, sizeInBits); RETURN basicType;
  4181. END NewByteType;
  4182. PROCEDURE NewAnyType*(sizeInBits: LONGINT): AnyType;
  4183. VAR basicType: AnyType;
  4184. BEGIN
  4185. NEW(basicType, sizeInBits); RETURN basicType;
  4186. END NewAnyType;
  4187. PROCEDURE NewObjectType*(sizeInBits: LONGINT): ObjectType;
  4188. VAR basicType: ObjectType;
  4189. BEGIN
  4190. NEW(basicType, sizeInBits); RETURN basicType;
  4191. END NewObjectType;
  4192. PROCEDURE NewNilType*(sizeInBits: LONGINT): NilType;
  4193. VAR basicType: NilType;
  4194. BEGIN
  4195. NEW(basicType, sizeInBits); RETURN basicType;
  4196. END NewNilType;
  4197. PROCEDURE NewAddressType*(sizeInBits: LONGINT): AddressType;
  4198. VAR basicType: AddressType;
  4199. BEGIN
  4200. NEW(basicType, sizeInBits); RETURN basicType;
  4201. END NewAddressType;
  4202. PROCEDURE NewSizeType*(sizeInBits: LONGINT): SizeType;
  4203. VAR basicType: SizeType;
  4204. BEGIN
  4205. NEW(basicType, sizeInBits); RETURN basicType;
  4206. END NewSizeType;
  4207. PROCEDURE NewBooleanType*(sizeInBits: LONGINT): BooleanType;
  4208. VAR basicType: BooleanType;
  4209. BEGIN
  4210. NEW(basicType, sizeInBits); RETURN basicType;
  4211. END NewBooleanType;
  4212. PROCEDURE NewSetType*(sizeInBits: LONGINT): SetType;
  4213. VAR basicType: SetType;
  4214. BEGIN
  4215. NEW(basicType, sizeInBits); RETURN basicType;
  4216. END NewSetType;
  4217. PROCEDURE NewCharacterType*(sizeInBits: LONGINT): CharacterType;
  4218. VAR basicType: CharacterType;
  4219. BEGIN
  4220. NEW(basicType, sizeInBits); RETURN basicType;
  4221. END NewCharacterType;
  4222. PROCEDURE NewRangeType*(sizeInBits: LONGINT): RangeType;
  4223. VAR basicType: RangeType;
  4224. BEGIN
  4225. NEW(basicType, sizeInBits); RETURN basicType;
  4226. END NewRangeType;
  4227. PROCEDURE NewComplexType*(base: Type): ComplexType;
  4228. VAR basicType: ComplexType;
  4229. BEGIN
  4230. NEW(basicType, base); RETURN basicType;
  4231. END NewComplexType;
  4232. PROCEDURE NewIntegerType*(size: LONGINT; signed: BOOLEAN): IntegerType;
  4233. VAR basicType: IntegerType;
  4234. BEGIN
  4235. NEW(basicType, size, signed); RETURN basicType;
  4236. END NewIntegerType;
  4237. PROCEDURE NewFloatType*(sizeInBits: LONGINT): FloatType;
  4238. VAR basicType: FloatType;
  4239. BEGIN
  4240. NEW(basicType, sizeInBits); RETURN basicType;
  4241. END NewFloatType;
  4242. PROCEDURE NewTypeDeclaration*(position: LONGINT; name: Identifier): TypeDeclaration;
  4243. VAR typeDeclaration: TypeDeclaration;
  4244. BEGIN
  4245. ASSERT(name # invalidIdentifier);
  4246. NEW(typeDeclaration,position,name); RETURN typeDeclaration
  4247. END NewTypeDeclaration;
  4248. PROCEDURE NewStringType*( position: LONGINT; baseType: Type; length: LONGINT): StringType;
  4249. VAR stringType: StringType;
  4250. BEGIN
  4251. NEW( stringType, position, baseType, length); RETURN stringType;
  4252. END NewStringType;
  4253. PROCEDURE NewEnumerationType*( position: LONGINT; scope: Scope; enumerationScope: EnumerationScope): EnumerationType;
  4254. VAR enumerationType: EnumerationType;
  4255. BEGIN
  4256. NEW( enumerationType, position, scope, enumerationScope); RETURN enumerationType;
  4257. END NewEnumerationType;
  4258. PROCEDURE NewArrayType*( position: LONGINT; scope: Scope; form: LONGINT): ArrayType;
  4259. VAR arrayType: ArrayType;
  4260. BEGIN
  4261. NEW( arrayType, position,scope, form); RETURN arrayType;
  4262. END NewArrayType;
  4263. PROCEDURE NewMathArrayType*( position: LONGINT; scope: Scope; form: LONGINT): MathArrayType;
  4264. VAR mathArrayType: MathArrayType;
  4265. BEGIN
  4266. NEW( mathArrayType, position,scope,form); RETURN mathArrayType;
  4267. END NewMathArrayType;
  4268. PROCEDURE NewPointerType*( position: LONGINT; scope: Scope): PointerType;
  4269. VAR pointerType: PointerType;
  4270. BEGIN
  4271. NEW( pointerType, position,scope); RETURN pointerType;
  4272. END NewPointerType;
  4273. PROCEDURE NewPortType*( position: LONGINT; direction: LONGINT; sizeExpression: Expression; scope: Scope): PortType;
  4274. VAR portType: PortType;
  4275. BEGIN
  4276. NEW( portType, position, direction, sizeExpression, scope); RETURN portType;
  4277. END NewPortType;
  4278. PROCEDURE NewRecordType*( position: LONGINT; scope: Scope; recordScope: RecordScope): RecordType;
  4279. VAR recordType: RecordType;
  4280. BEGIN
  4281. NEW( recordType, position, scope, recordScope); RETURN recordType
  4282. END NewRecordType;
  4283. PROCEDURE NewCellType*(position: LONGINT; scope:Scope; cellScope: CellScope): CellType;
  4284. VAR actorType: CellType;
  4285. BEGIN
  4286. NEW(actorType, position, scope, cellScope); RETURN actorType;
  4287. END NewCellType;
  4288. PROCEDURE NewProcedureType*( position: LONGINT; scope: Scope): ProcedureType;
  4289. VAR procedureType: ProcedureType;
  4290. BEGIN
  4291. NEW( procedureType, position,scope); RETURN procedureType;
  4292. END NewProcedureType;
  4293. PROCEDURE NewQualifiedType*( position: LONGINT; scope: Scope; qualifiedIdentifier: QualifiedIdentifier): QualifiedType;
  4294. VAR qualifiedType: QualifiedType;
  4295. BEGIN
  4296. NEW( qualifiedType, position,scope,qualifiedIdentifier ); RETURN qualifiedType
  4297. END NewQualifiedType;
  4298. PROCEDURE NewSymbol*(name: Identifier): Symbol; (* for error handling: invalid Symbol *)
  4299. VAR symbol: Symbol;
  4300. BEGIN
  4301. NEW(symbol,-1,name); RETURN symbol
  4302. END NewSymbol;
  4303. PROCEDURE NewVariable*( position: LONGINT; name: Identifier): Variable;
  4304. VAR variable: Variable;
  4305. BEGIN
  4306. NEW( variable, position, name ); RETURN variable
  4307. END NewVariable;
  4308. PROCEDURE NewQualifiedIdentifier*( position: LONGINT; prefix, suffix: Identifier ): QualifiedIdentifier;
  4309. VAR qualifiedIdentifier: QualifiedIdentifier;
  4310. BEGIN
  4311. NEW( qualifiedIdentifier, position, prefix, suffix ); RETURN qualifiedIdentifier
  4312. END NewQualifiedIdentifier;
  4313. PROCEDURE NewIdentifier*(CONST name: ARRAY OF CHAR): Identifier;
  4314. BEGIN
  4315. RETURN Basic.MakeString(name);
  4316. END NewIdentifier;
  4317. PROCEDURE NewParameter*( position: LONGINT; ownerType:Type ; name: Identifier; passAs: LONGINT): Parameter;
  4318. VAR parameter: Parameter;
  4319. BEGIN
  4320. NEW( parameter, position, ownerType, name, passAs); RETURN parameter;
  4321. END NewParameter;
  4322. PROCEDURE NewProperty*( position: LONGINT; name: Identifier): Property;
  4323. VAR property: Property;
  4324. BEGIN
  4325. NEW( property, position, name); RETURN property;
  4326. END NewProperty;
  4327. PROCEDURE NewExpressionList*(): ExpressionList;
  4328. VAR expressionList: ExpressionList;
  4329. BEGIN
  4330. NEW(expressionList); RETURN expressionList
  4331. END NewExpressionList;
  4332. PROCEDURE CloneExpressionList*(l: ExpressionList): ExpressionList;
  4333. VAR copy: ExpressionList;
  4334. BEGIN
  4335. IF l = NIL THEN RETURN NIL ELSE l.Clone(copy); RETURN copy END;
  4336. END CloneExpressionList;
  4337. PROCEDURE NewDesignator*(): Designator; (* for error handling: invalid Designator *)
  4338. VAR designator: Designator;
  4339. BEGIN
  4340. NEW(designator,-1); RETURN designator;
  4341. END NewDesignator;
  4342. PROCEDURE NewIdentifierDesignator*( position: LONGINT; identifier: Identifier): IdentifierDesignator;
  4343. VAR identifierDesignator: IdentifierDesignator;
  4344. BEGIN
  4345. NEW( identifierDesignator, position, identifier ); RETURN identifierDesignator
  4346. END NewIdentifierDesignator;
  4347. PROCEDURE NewSelectorDesignator*( position: LONGINT; left: Designator; name: Identifier ): SelectorDesignator;
  4348. VAR selectorDesignator: SelectorDesignator;
  4349. BEGIN
  4350. NEW( selectorDesignator, position, left, name ); RETURN selectorDesignator
  4351. END NewSelectorDesignator;
  4352. PROCEDURE NewParameterDesignator*( position: LONGINT; left: Designator; expressionList: ExpressionList ): ParameterDesignator;
  4353. VAR parameterDesignator: ParameterDesignator;
  4354. BEGIN
  4355. NEW( parameterDesignator,position, left, expressionList ); RETURN parameterDesignator
  4356. END NewParameterDesignator;
  4357. PROCEDURE NewArrowDesignator*( position: LONGINT; left: Designator ): ArrowDesignator;
  4358. VAR dereferenceDesignator: ArrowDesignator;
  4359. BEGIN
  4360. NEW( dereferenceDesignator, position, left ); RETURN dereferenceDesignator;
  4361. END NewArrowDesignator;
  4362. PROCEDURE NewBracketDesignator*( position: LONGINT; left: Designator; expressionList: ExpressionList ): BracketDesignator;
  4363. VAR bracketDesignator: BracketDesignator;
  4364. BEGIN
  4365. NEW( bracketDesignator, position, left, expressionList ); RETURN bracketDesignator
  4366. END NewBracketDesignator;
  4367. PROCEDURE NewSymbolDesignator*( position: LONGINT; left: Designator; symbol: Symbol ): SymbolDesignator;
  4368. VAR symbolDesignator: SymbolDesignator;
  4369. BEGIN
  4370. NEW( symbolDesignator, position, left, symbol); RETURN symbolDesignator
  4371. END NewSymbolDesignator;
  4372. PROCEDURE NewIndexDesignator*( position: LONGINT; left: Designator): IndexDesignator;
  4373. VAR indexDesignator: IndexDesignator;
  4374. BEGIN
  4375. NEW( indexDesignator, position, left); RETURN indexDesignator
  4376. END NewIndexDesignator;
  4377. PROCEDURE NewProcedureCallDesignator*(position: LONGINT; left: Designator; parameters: ExpressionList): ProcedureCallDesignator;
  4378. VAR procedureCallDesignator: ProcedureCallDesignator;
  4379. BEGIN
  4380. NEW(procedureCallDesignator, position, left, parameters); RETURN procedureCallDesignator
  4381. END NewProcedureCallDesignator;
  4382. PROCEDURE NewBuiltinCallDesignator*(position: LONGINT; id: LONGINT; left: Designator; parameters: ExpressionList): BuiltinCallDesignator;
  4383. VAR builtinCallDesignator: BuiltinCallDesignator;
  4384. BEGIN
  4385. NEW(builtinCallDesignator, position, id, left,parameters); RETURN builtinCallDesignator
  4386. END NewBuiltinCallDesignator;
  4387. PROCEDURE NewTypeGuardDesignator*(position: LONGINT; left: Designator; type: Type): TypeGuardDesignator;
  4388. VAR guardDesignator: TypeGuardDesignator;
  4389. BEGIN
  4390. NEW(guardDesignator,position,left,type); RETURN guardDesignator;
  4391. END NewTypeGuardDesignator;
  4392. PROCEDURE NewDereferenceDesignator*( position: LONGINT; left: Designator): DereferenceDesignator;
  4393. VAR dereferenceDesignator: DereferenceDesignator;
  4394. BEGIN
  4395. NEW( dereferenceDesignator, position, left); RETURN dereferenceDesignator
  4396. END NewDereferenceDesignator;
  4397. PROCEDURE NewSupercallDesignator*( position: LONGINT; left: Designator): SupercallDesignator;
  4398. VAR supercallDesignator: SupercallDesignator;
  4399. BEGIN
  4400. NEW( supercallDesignator, position, left); RETURN supercallDesignator
  4401. END NewSupercallDesignator;
  4402. PROCEDURE NewSelfDesignator*( position: LONGINT): SelfDesignator;
  4403. VAR selfDesignator: SelfDesignator;
  4404. BEGIN
  4405. NEW( selfDesignator, position); RETURN selfDesignator
  4406. END NewSelfDesignator;
  4407. PROCEDURE NewResultDesignator*( position: LONGINT): ResultDesignator;
  4408. VAR resultDesignator: ResultDesignator;
  4409. BEGIN
  4410. NEW( resultDesignator, position); RETURN resultDesignator
  4411. END NewResultDesignator;
  4412. PROCEDURE NewExpression*(): Expression; (* for error handling: invalid Expression *)
  4413. VAR expression: Expression;
  4414. BEGIN
  4415. NEW(expression,-1); RETURN expression;
  4416. END NewExpression;
  4417. PROCEDURE CloneExpression*(e: Expression): Expression;
  4418. VAR copy: Expression;
  4419. BEGIN
  4420. IF e = NIL THEN
  4421. RETURN NIL
  4422. ELSE
  4423. copy := e.Clone();
  4424. copy.type := e.type;
  4425. copy.assignable := e.assignable;
  4426. copy.position := e.position;
  4427. copy.state := e.state;
  4428. IF e.resolved = e THEN copy.resolved := copy(Value);
  4429. ELSIF e.resolved # NIL THEN copy.resolved := CloneExpression(e.resolved)(Value);
  4430. END;
  4431. RETURN copy
  4432. END;
  4433. END CloneExpression;
  4434. PROCEDURE CloneDesignator*(e: Expression): Designator;
  4435. BEGIN
  4436. IF e = NIL THEN RETURN NIL ELSE RETURN CloneExpression(e)(Designator) END;
  4437. END CloneDesignator;
  4438. PROCEDURE NewElement*( position: LONGINT; from,to: Expression ): Expression;
  4439. BEGIN
  4440. IF from = to THEN RETURN from
  4441. ELSE RETURN NewRangeExpression(position,from,to,NIL)
  4442. END;
  4443. END NewElement;
  4444. PROCEDURE NewSet*( position: LONGINT ): Set;
  4445. VAR set: Set;
  4446. BEGIN NEW( set, position ); RETURN set
  4447. END NewSet;
  4448. PROCEDURE NewMathArrayExpression*( position: LONGINT ): MathArrayExpression;
  4449. VAR mathArrayExpression: MathArrayExpression;
  4450. BEGIN NEW( mathArrayExpression, position ); RETURN mathArrayExpression
  4451. END NewMathArrayExpression;
  4452. PROCEDURE NewBinaryExpression*( position: LONGINT; left, right: Expression; operator: LONGINT ): BinaryExpression;
  4453. VAR binaryExpression: BinaryExpression;
  4454. BEGIN
  4455. NEW( binaryExpression, position, left, right, operator ); RETURN binaryExpression;
  4456. END NewBinaryExpression;
  4457. PROCEDURE NewRangeExpression*(position: LONGINT; first, last, step: Expression): RangeExpression;
  4458. VAR rangeExpression: RangeExpression;
  4459. BEGIN
  4460. NEW(rangeExpression, position, first, last, step); RETURN rangeExpression
  4461. END NewRangeExpression;
  4462. PROCEDURE NewTensorRangeExpression*(position: LONGINT): TensorRangeExpression;
  4463. VAR tensorRangeExpression: TensorRangeExpression;
  4464. BEGIN
  4465. NEW(tensorRangeExpression,position); RETURN tensorRangeExpression
  4466. END NewTensorRangeExpression;
  4467. PROCEDURE NewUnaryExpression*( position: LONGINT; operand: Expression; operator: LONGINT ): UnaryExpression;
  4468. VAR unaryExpression: UnaryExpression;
  4469. BEGIN
  4470. NEW( unaryExpression, position, operand, operator ); RETURN unaryExpression;
  4471. END NewUnaryExpression;
  4472. PROCEDURE NewConversion*( position: LONGINT; expression: Expression; type: Type; typeExpression: Expression): Conversion;
  4473. VAR conversion: Conversion;
  4474. BEGIN
  4475. ASSERT(type # NIL);
  4476. NEW( conversion, position, expression,type, typeExpression ); RETURN conversion;
  4477. END NewConversion;
  4478. PROCEDURE NewValue*(): Value;(* for error handling: invalid Value *)
  4479. VAR value: Value;
  4480. BEGIN
  4481. NEW(value,-1); RETURN value;
  4482. END NewValue;
  4483. PROCEDURE NewIntegerValue*( position: LONGINT; value: HUGEINT): IntegerValue;
  4484. VAR integerValue: IntegerValue;
  4485. BEGIN
  4486. NEW( integerValue, position, value); RETURN integerValue;
  4487. END NewIntegerValue;
  4488. PROCEDURE NewCharacterValue*( position: LONGINT; value: CHAR): CharacterValue;
  4489. VAR characterValue: CharacterValue;
  4490. BEGIN
  4491. NEW( characterValue, position, value); RETURN characterValue;
  4492. END NewCharacterValue;
  4493. PROCEDURE NewSetValue*(position: LONGINT; value: SET): SetValue;
  4494. VAR setValue: SetValue;
  4495. BEGIN
  4496. NEW(setValue, position, value); RETURN setValue
  4497. END NewSetValue;
  4498. PROCEDURE NewMathArrayValue*( position: LONGINT ): MathArrayValue;
  4499. VAR mathArrayValue: MathArrayValue;
  4500. BEGIN NEW( mathArrayValue, position ); RETURN mathArrayValue
  4501. END NewMathArrayValue;
  4502. PROCEDURE NewRealValue*( position: LONGINT; value: LONGREAL): RealValue;
  4503. VAR realValue: RealValue;
  4504. BEGIN
  4505. NEW( realValue, position, value); RETURN realValue
  4506. END NewRealValue;
  4507. PROCEDURE NewComplexValue*( position: LONGINT; realValue, imagValue: LONGREAL): ComplexValue;
  4508. VAR complexValue: ComplexValue;
  4509. BEGIN
  4510. NEW( complexValue, position, realValue, imagValue); RETURN complexValue
  4511. END NewComplexValue;
  4512. PROCEDURE NewStringValue*( position: LONGINT; value: String): StringValue;
  4513. VAR stringValue: StringValue;
  4514. BEGIN
  4515. NEW( stringValue, position, value ); RETURN stringValue
  4516. END NewStringValue;
  4517. PROCEDURE NewBooleanValue*( position: LONGINT; value: BOOLEAN): BooleanValue;
  4518. VAR booleanValue: BooleanValue;
  4519. BEGIN
  4520. NEW( booleanValue, position, value ); RETURN booleanValue;
  4521. END NewBooleanValue;
  4522. PROCEDURE NewNilValue*( position: LONGINT ): NilValue;
  4523. VAR nilValue: NilValue;
  4524. BEGIN
  4525. NEW( nilValue, position ); RETURN nilValue
  4526. END NewNilValue;
  4527. PROCEDURE NewEnumerationValue*( position: LONGINT; value: LONGINT ): EnumerationValue;
  4528. VAR enumeratorValue: EnumerationValue;
  4529. BEGIN
  4530. NEW( enumeratorValue, position, value ); RETURN enumeratorValue
  4531. END NewEnumerationValue;
  4532. PROCEDURE NewStatement*(outer: Statement): Statement; (* for error handling: invalid Statement *)
  4533. VAR statement: Statement;
  4534. BEGIN NEW(statement,-1,outer); RETURN statement;
  4535. END NewStatement;
  4536. PROCEDURE CloneStatement*(statement: Statement): Statement;
  4537. BEGIN IF statement = NIL THEN RETURN NIL ELSE RETURN statement.Clone() END
  4538. END CloneStatement;
  4539. PROCEDURE NewStatementSequence*(): StatementSequence;
  4540. VAR statementSequence: StatementSequence;
  4541. BEGIN
  4542. NEW( statementSequence); RETURN statementSequence
  4543. END NewStatementSequence;
  4544. PROCEDURE CloneStatementSequence*(statementSequence: StatementSequence): StatementSequence;
  4545. VAR copy: StatementSequence;
  4546. BEGIN IF statementSequence = NIL THEN RETURN NIL ELSE statementSequence.Clone(copy); RETURN copy END
  4547. END CloneStatementSequence;
  4548. PROCEDURE NewModifier*(position: LONGINT; identifier: Identifier; expression: Expression): Modifier;
  4549. VAR blockModifier: Modifier;
  4550. BEGIN
  4551. NEW(blockModifier,position,identifier,expression); RETURN blockModifier
  4552. END NewModifier;
  4553. PROCEDURE NewStatementBlock*( position: LONGINT ; outer: Statement): StatementBlock;
  4554. VAR statementBlock: StatementBlock;
  4555. BEGIN
  4556. NEW( statementBlock, position, outer ); RETURN statementBlock
  4557. END NewStatementBlock;
  4558. PROCEDURE NewStatementDesignator*(position: LONGINT; s: Statement): StatementDesignator;
  4559. VAR statementDesignator: StatementDesignator;
  4560. BEGIN
  4561. NEW( statementDesignator, position, s); RETURN statementDesignator
  4562. END NewStatementDesignator;
  4563. PROCEDURE NewBody*( position: LONGINT ; scope: ProcedureScope): Body;
  4564. VAR body: Body;
  4565. BEGIN
  4566. NEW( body, position,scope ); RETURN body
  4567. END NewBody;
  4568. PROCEDURE NewIfPart*(): IfPart;
  4569. VAR ifPart: IfPart;
  4570. BEGIN
  4571. NEW( ifPart); RETURN ifPart
  4572. END NewIfPart;
  4573. PROCEDURE NewIfStatement*( position: LONGINT ; outer: Statement): IfStatement;
  4574. VAR ifStatement: IfStatement;
  4575. BEGIN
  4576. NEW( ifStatement, position,outer ); RETURN ifStatement
  4577. END NewIfStatement;
  4578. PROCEDURE NewAssignment*( position: LONGINT; left: Designator; right: Expression; outer: Statement): Assignment;
  4579. VAR assignment: Assignment;
  4580. BEGIN
  4581. NEW( assignment, position, left, right,outer ); RETURN assignment
  4582. END NewAssignment;
  4583. PROCEDURE NewCommunicationStatement*( position: LONGINT; op: LONGINT; left: Designator; right: Expression; outer: Statement): CommunicationStatement;
  4584. VAR communication: CommunicationStatement;
  4585. BEGIN
  4586. NEW( communication, position, op, left, right,outer ); RETURN communication
  4587. END NewCommunicationStatement;
  4588. PROCEDURE NewProcedureCallStatement*(position: LONGINT; call: Designator; outer: Statement): ProcedureCallStatement;
  4589. VAR caller: ProcedureCallStatement;
  4590. BEGIN
  4591. NEW(caller,position,call,outer); RETURN caller
  4592. END NewProcedureCallStatement;
  4593. PROCEDURE NewCaseStatement*( position: LONGINT ; outer: Statement): CaseStatement;
  4594. VAR caseStatement: CaseStatement;
  4595. BEGIN
  4596. NEW( caseStatement, position,outer ); RETURN caseStatement
  4597. END NewCaseStatement;
  4598. PROCEDURE NewCasePart*(): CasePart;
  4599. VAR casePart: CasePart;
  4600. BEGIN
  4601. NEW( casePart); RETURN casePart
  4602. END NewCasePart;
  4603. PROCEDURE NewWithPart*(): WithPart;
  4604. VAR withPart: WithPart;
  4605. BEGIN
  4606. NEW( withPart); RETURN withPart
  4607. END NewWithPart;
  4608. PROCEDURE NewWithStatement*( position: LONGINT; outer: Statement): WithStatement;
  4609. VAR withStatement: WithStatement;
  4610. BEGIN
  4611. NEW( withStatement, position, outer ); RETURN withStatement
  4612. END NewWithStatement;
  4613. PROCEDURE NewWhileStatement*( position: LONGINT ; outer: Statement): WhileStatement;
  4614. VAR whileStatement: WhileStatement;
  4615. BEGIN
  4616. NEW( whileStatement, position,outer ); RETURN whileStatement
  4617. END NewWhileStatement;
  4618. PROCEDURE NewRepeatStatement*( position: LONGINT ; outer: Statement): RepeatStatement;
  4619. VAR repeatStatement: RepeatStatement;
  4620. BEGIN
  4621. NEW( repeatStatement, position ,outer); RETURN repeatStatement
  4622. END NewRepeatStatement;
  4623. PROCEDURE NewForStatement*( position: LONGINT; outer: Statement ): ForStatement;
  4624. VAR forStatement: ForStatement;
  4625. BEGIN
  4626. NEW( forStatement, position,outer ); RETURN forStatement
  4627. END NewForStatement;
  4628. PROCEDURE NewLoopStatement*( position: LONGINT ; outer: Statement): LoopStatement;
  4629. VAR loopStatement: LoopStatement;
  4630. BEGIN
  4631. NEW( loopStatement, position ,outer); RETURN loopStatement
  4632. END NewLoopStatement;
  4633. PROCEDURE NewExitableBlock*( position: LONGINT ; outer: Statement): ExitableBlock;
  4634. VAR loopStatement: ExitableBlock;
  4635. BEGIN
  4636. NEW( loopStatement, position ,outer); RETURN loopStatement
  4637. END NewExitableBlock;
  4638. PROCEDURE NewExitStatement*( position: LONGINT ; outer: Statement): ExitStatement;
  4639. VAR exitStatement: ExitStatement;
  4640. BEGIN
  4641. NEW( exitStatement, position, outer); RETURN exitStatement
  4642. END NewExitStatement;
  4643. PROCEDURE NewReturnStatement*( position: LONGINT; outer: Statement ): ReturnStatement;
  4644. VAR returnStatement: ReturnStatement;
  4645. BEGIN
  4646. NEW( returnStatement, position,outer ); RETURN returnStatement
  4647. END NewReturnStatement;
  4648. PROCEDURE NewAwaitStatement*( position: LONGINT; outer: Statement ): AwaitStatement;
  4649. VAR awaitStatement: AwaitStatement;
  4650. BEGIN
  4651. NEW( awaitStatement, position, outer ); RETURN awaitStatement
  4652. END NewAwaitStatement;
  4653. PROCEDURE NewCode*(position: LONGINT; outer: Statement): Code;
  4654. VAR code: Code;
  4655. BEGIN
  4656. NEW(code,position,outer); RETURN code
  4657. END NewCode;
  4658. PROCEDURE NewProcedureScope*(outer: Scope): ProcedureScope;
  4659. VAR scope: ProcedureScope;
  4660. BEGIN NEW(scope,outer); RETURN scope
  4661. END NewProcedureScope;
  4662. PROCEDURE NewModuleScope*(): ModuleScope;
  4663. VAR scope: ModuleScope;
  4664. BEGIN NEW(scope); RETURN scope
  4665. END NewModuleScope;
  4666. PROCEDURE NewRecordScope*(outer: Scope): RecordScope;
  4667. VAR scope: RecordScope;
  4668. BEGIN NEW(scope,outer); RETURN scope
  4669. END NewRecordScope;
  4670. PROCEDURE NewCellScope*(outer: Scope): CellScope;
  4671. VAR scope: CellScope;
  4672. BEGIN NEW(scope,outer); RETURN scope
  4673. END NewCellScope;
  4674. PROCEDURE NewEnumerationScope*(outer: Scope): EnumerationScope;
  4675. VAR scope: EnumerationScope;
  4676. BEGIN NEW(scope,outer); RETURN scope
  4677. END NewEnumerationScope;
  4678. PROCEDURE Init;
  4679. BEGIN;
  4680. invalidIdentifier := Basic.invalidString;
  4681. invalidQualifiedIdentifier := NewQualifiedIdentifier(-1,invalidIdentifier,Basic.emptyString);
  4682. invalidType := NewType();
  4683. invalidDesignator := NewDesignator();
  4684. invalidDesignator.SetType(invalidType);
  4685. invalidExpression := invalidDesignator;
  4686. invalidValue := NewValue();
  4687. invalidSymbol := NewSymbol(NewIdentifier(""));
  4688. invalidSymbol.SetType(invalidType);
  4689. importType := NewType();
  4690. importType.SetState(Resolved);
  4691. typeDeclarationType := NewType();
  4692. typeDeclarationType.SetState(Resolved);
  4693. moduleType := NewType();
  4694. moduleType.SetState(Resolved);
  4695. anonymousIdentifier := NewIdentifier("");
  4696. indexListSeparator := NewDesignator();
  4697. indexListSeparator.SetType(invalidType);
  4698. END Init;
  4699. BEGIN
  4700. Init;
  4701. END FoxSyntaxTree.