FoxSyntaxTree.Mod 161 KB

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