FoxSyntaxTree.Mod 159 KB

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