FoxSyntaxTree.Mod 164 KB

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