FoxSyntaxTree.Mod 164 KB

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