FoxSyntaxTree.Mod 158 KB

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