2
0

FoxSyntaxTree.Mod 160 KB

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