FoxSyntaxTree.Mod 159 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839
  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. returnType-: Type;
  1996. PROCEDURE & InitBuiltinCallDesignator(position: LONGINT; id: LONGINT; left: Designator; parameters: ExpressionList);
  1997. BEGIN
  1998. InitDesignator(position); SELF.parameters := parameters; SELF.id := id; SELF.left := left; returnType := NIL;
  1999. END InitBuiltinCallDesignator;
  2000. PROCEDURE SetReturnType*(type: Type);
  2001. BEGIN
  2002. returnType := type (* used for NEW Type() expression *)
  2003. END SetReturnType;
  2004. PROCEDURE Clone(): Expression;
  2005. VAR copy: BuiltinCallDesignator;
  2006. BEGIN
  2007. NEW(copy, position, id, CloneDesignator(left), CloneExpressionList(parameters)); RETURN copy
  2008. END Clone;
  2009. PROCEDURE Accept*(v: Visitor);
  2010. VAR position: LONGINT;
  2011. BEGIN position := SELF.position; v.VisitBuiltinCallDesignator(SELF)
  2012. END Accept;
  2013. END BuiltinCallDesignator;
  2014. (** <<left(type)>>
  2015. resolved parameter designator, designates a type guard
  2016. **)
  2017. TypeGuardDesignator* = OBJECT(Designator)
  2018. VAR
  2019. typeExpression-: Expression; (* for printing only *)
  2020. PROCEDURE &InitTypeGuardDesignator(position: LONGINT; left: Designator; type: Type);
  2021. BEGIN InitDesignator(position); SELF.left := left; SELF.type := type; typeExpression := NIL;
  2022. END InitTypeGuardDesignator;
  2023. PROCEDURE SetTypeExpression*(typeExpression: Expression);
  2024. BEGIN SELF.typeExpression := typeExpression
  2025. END SetTypeExpression;
  2026. PROCEDURE Clone(): Expression;
  2027. VAR copy: TypeGuardDesignator;
  2028. BEGIN
  2029. NEW(copy, position, CloneDesignator(left), type); RETURN copy
  2030. END Clone;
  2031. PROCEDURE Accept*(v: Visitor);
  2032. VAR position: LONGINT;
  2033. BEGIN position := SELF.position; v.VisitTypeGuardDesignator(SELF)
  2034. END Accept;
  2035. PROCEDURE NeedsTrace* (): BOOLEAN;
  2036. BEGIN RETURN left.NeedsTrace() & type.NeedsTrace(); (* for x(Y): if x is untraced, then x as Y should also be treated untraced *)
  2037. END NeedsTrace;
  2038. END TypeGuardDesignator;
  2039. (** <<left^>> resolved as dereference operation on pointer variable left **)
  2040. DereferenceDesignator*= OBJECT (Designator)
  2041. PROCEDURE &InitDereferenceDesignator(position: LONGINT; left: Designator);
  2042. BEGIN InitDesignator(position); SELF.left := left;
  2043. END InitDereferenceDesignator;
  2044. PROCEDURE Clone(): Expression;
  2045. VAR copy: DereferenceDesignator;
  2046. BEGIN
  2047. NEW(copy, position, CloneDesignator(left)); RETURN copy
  2048. END Clone;
  2049. PROCEDURE Accept*(v: Visitor);
  2050. VAR position: LONGINT;
  2051. BEGIN position := SELF.position; v.VisitDereferenceDesignator(SELF)
  2052. END Accept;
  2053. PROCEDURE NeedsTrace* (): BOOLEAN;
  2054. BEGIN RETURN left.NeedsTrace() & type.NeedsTrace(); (* for x^: if x is an untraced pointer, the content of x^ is also treated untraced *)
  2055. END NeedsTrace;
  2056. END DereferenceDesignator;
  2057. (** <<left^>> resolved as supercall operation on method left **)
  2058. SupercallDesignator*= OBJECT (Designator)
  2059. PROCEDURE &InitSupercallDesignator(position: LONGINT; left: Designator);
  2060. BEGIN InitDesignator(position); SELF.left := left;
  2061. END InitSupercallDesignator;
  2062. PROCEDURE Clone(): Expression;
  2063. VAR copy: SupercallDesignator;
  2064. BEGIN
  2065. NEW(copy, position, CloneDesignator(left)); RETURN copy
  2066. END Clone;
  2067. PROCEDURE Accept*(v: Visitor);
  2068. VAR position: LONGINT;
  2069. BEGIN position := SELF.position; v.VisitSupercallDesignator(SELF)
  2070. END Accept;
  2071. END SupercallDesignator;
  2072. (** <<SELF.x>> **)
  2073. SelfDesignator*= OBJECT (Designator)
  2074. PROCEDURE &InitSelfDesignator(position: LONGINT);
  2075. BEGIN InitDesignator(position);
  2076. END InitSelfDesignator;
  2077. PROCEDURE Clone(): Expression;
  2078. VAR copy: SelfDesignator;
  2079. BEGIN
  2080. NEW(copy, position); RETURN copy
  2081. END Clone;
  2082. PROCEDURE Accept*(v: Visitor);
  2083. VAR position: LONGINT;
  2084. BEGIN position := SELF.position; v.VisitSelfDesignator(SELF)
  2085. END Accept;
  2086. PROCEDURE NeedsTrace* (): BOOLEAN;
  2087. BEGIN RETURN type.NeedsTrace();
  2088. END NeedsTrace;
  2089. END SelfDesignator;
  2090. (** <<RESULT>> **)
  2091. ResultDesignator*= OBJECT (Designator)
  2092. PROCEDURE &InitResultDesignator(position: LONGINT);
  2093. BEGIN InitDesignator(position);
  2094. END InitResultDesignator;
  2095. PROCEDURE Clone(): Expression;
  2096. VAR copy: ResultDesignator;
  2097. BEGIN
  2098. NEW(copy, position); RETURN copy
  2099. END Clone;
  2100. PROCEDURE Accept*(v: Visitor);
  2101. VAR position: LONGINT;
  2102. BEGIN position := SELF.position; v.VisitResultDesignator(SELF)
  2103. END Accept;
  2104. END ResultDesignator;
  2105. (**** values ****)
  2106. Value* = OBJECT (Expression)
  2107. VAR fingerprint-: FingerPrint;
  2108. PROCEDURE &InitValue(position: LONGINT);
  2109. BEGIN SELF.position := position; resolved := SELF; InitFingerPrint(fingerprint);
  2110. END InitValue;
  2111. PROCEDURE SetFingerPrint*(CONST fp: FingerPrint);
  2112. BEGIN
  2113. SELF.fingerprint := fp
  2114. END SetFingerPrint;
  2115. PROCEDURE Accept*(v: Visitor);
  2116. VAR position: LONGINT;
  2117. BEGIN position := SELF.position; v.VisitValue(SELF)
  2118. END Accept;
  2119. PROCEDURE Equals*(v: Value):BOOLEAN;
  2120. BEGIN HALT(100); (* abstract *) RETURN FALSE; END Equals;
  2121. END Value;
  2122. (** <<value = TRUE , FALSE>> **)
  2123. BooleanValue* = OBJECT (Value)
  2124. VAR
  2125. value-: BOOLEAN;
  2126. PROCEDURE & InitBooleanValue(position: LONGINT; value: BOOLEAN);
  2127. BEGIN
  2128. InitValue(position); SELF.value := value;
  2129. END InitBooleanValue;
  2130. PROCEDURE SetValue*(value: BOOLEAN);
  2131. BEGIN SELF.value := value
  2132. END SetValue;
  2133. PROCEDURE Clone(): Expression;
  2134. VAR copy: BooleanValue;
  2135. BEGIN
  2136. NEW(copy, position, value); RETURN copy
  2137. END Clone;
  2138. PROCEDURE Accept*(v: Visitor);
  2139. VAR position: LONGINT;
  2140. BEGIN position := SELF.position; v.VisitBooleanValue(SELF)
  2141. END Accept;
  2142. PROCEDURE Equals*(v: Value):BOOLEAN;
  2143. BEGIN RETURN (v IS BooleanValue) & (v(BooleanValue).value = value); END Equals;
  2144. END BooleanValue;
  2145. (** <<value = 123456>> **)
  2146. IntegerValue* = OBJECT (Value)
  2147. VAR
  2148. hvalue-: HUGEINT;
  2149. value-: LONGINT;
  2150. PROCEDURE & InitIntegerValue(position: LONGINT; hvalue: HUGEINT);
  2151. BEGIN
  2152. InitValue(position); SELF.hvalue := hvalue; SELF.value := SHORT(hvalue);
  2153. END InitIntegerValue;
  2154. PROCEDURE SetValue*(hvalue: HUGEINT);
  2155. BEGIN SELF.hvalue := hvalue; SELF.value := SHORT(hvalue);
  2156. END SetValue;
  2157. PROCEDURE Clone(): Expression;
  2158. VAR copy: IntegerValue;
  2159. BEGIN
  2160. NEW(copy, position, hvalue); RETURN copy
  2161. END Clone;
  2162. PROCEDURE Accept*(v: Visitor);
  2163. VAR position: LONGINT;
  2164. BEGIN position := SELF.position; v.VisitIntegerValue(SELF)
  2165. END Accept;
  2166. PROCEDURE Equals*(v: Value):BOOLEAN;
  2167. BEGIN RETURN (v IS IntegerValue) & (v(IntegerValue).value = value); END Equals;
  2168. END IntegerValue;
  2169. (** <<value = 'c', 65X>> **)
  2170. CharacterValue*= OBJECT(Value)
  2171. VAR
  2172. value-: CHAR; (* potential for extension to support CHAR16 and CHAR32 *)
  2173. PROCEDURE & InitCharacterValue(position:LONGINT; value: CHAR);
  2174. BEGIN
  2175. InitValue(position); SELF.value := value;
  2176. END InitCharacterValue;
  2177. PROCEDURE SetValue*(value: CHAR);
  2178. BEGIN SELF.value := value
  2179. END SetValue;
  2180. PROCEDURE Clone(): Expression;
  2181. VAR copy: CharacterValue;
  2182. BEGIN
  2183. NEW(copy, position, value); RETURN copy
  2184. END Clone;
  2185. PROCEDURE Accept*(v: Visitor);
  2186. VAR position: LONGINT;
  2187. BEGIN position := SELF.position; v.VisitCharacterValue(SELF)
  2188. END Accept;
  2189. PROCEDURE Equals*(v: Value):BOOLEAN;
  2190. BEGIN RETURN (v IS CharacterValue) & (v(CharacterValue).value = value); END Equals;
  2191. END CharacterValue;
  2192. SetValueType = SetValue;
  2193. (** <<value = {1,2,3..5}>> **)
  2194. SetValue* = OBJECT (Value)
  2195. VAR
  2196. value-: SET;
  2197. PROCEDURE & InitSetValue(position: LONGINT; value: SET);
  2198. BEGIN
  2199. InitValue(position); SELF.value := value;
  2200. END InitSetValue;
  2201. PROCEDURE SetValue*(value: SET);
  2202. BEGIN SELF.value := value
  2203. END SetValue;
  2204. PROCEDURE Clone(): Expression;
  2205. VAR copy: SetValueType;
  2206. BEGIN
  2207. NEW(copy, position, value); RETURN copy
  2208. END Clone;
  2209. PROCEDURE Accept*(v: Visitor);
  2210. VAR position: LONGINT;
  2211. BEGIN position := SELF.position; v.VisitSetValue(SELF)
  2212. END Accept;
  2213. END SetValue;
  2214. (** << [elements] >> **)
  2215. MathArrayValue* = OBJECT (Value)
  2216. VAR array-: MathArrayExpression; (* an element of the form from .. to is represented as a RangeExpression *)
  2217. PROCEDURE & InitMathArrayValue(position: LONGINT);
  2218. BEGIN
  2219. InitValue(position);
  2220. array := NIL;
  2221. END InitMathArrayValue;
  2222. PROCEDURE SetArray*(array: MathArrayExpression);
  2223. BEGIN SELF.array := array
  2224. END SetArray;
  2225. PROCEDURE Clone(): Expression;
  2226. VAR copy: MathArrayValue;
  2227. BEGIN
  2228. NEW(copy, position);
  2229. IF array # NIL THEN copy.array := array.Clone()(MathArrayExpression) END;
  2230. RETURN copy
  2231. END Clone;
  2232. PROCEDURE Accept*(v: Visitor);
  2233. VAR position: LONGINT;
  2234. BEGIN position := SELF.position; v.VisitMathArrayValue(SELF)
  2235. END Accept;
  2236. END MathArrayValue;
  2237. (** <<value = 1.2345E01>> **)
  2238. RealValue* = OBJECT (Value)
  2239. VAR
  2240. value-: LONGREAL;
  2241. subtype-: LONGINT; (* accuracy information: REAL vs. LONGREAL *)
  2242. PROCEDURE & InitRealValue(position: LONGINT; value: LONGREAL);
  2243. BEGIN
  2244. InitValue(position); SELF.value := value; SELF.subtype := 0;
  2245. END InitRealValue;
  2246. PROCEDURE SetValue*(value: LONGREAL);
  2247. BEGIN SELF.value := value
  2248. END SetValue;
  2249. PROCEDURE SetSubtype*(subtype: LONGINT);
  2250. BEGIN SELF.subtype := subtype;
  2251. END SetSubtype;
  2252. PROCEDURE Clone(): Expression;
  2253. VAR copy: RealValue;
  2254. BEGIN
  2255. NEW(copy, position, value); RETURN copy
  2256. END Clone;
  2257. PROCEDURE Accept*(v: Visitor);
  2258. VAR position: LONGINT;
  2259. BEGIN position := SELF.position; v.VisitRealValue(SELF)
  2260. END Accept;
  2261. PROCEDURE Equals*(v: Value):BOOLEAN;
  2262. BEGIN RETURN (v IS RealValue) & (v(RealValue).value = value); END Equals;
  2263. END RealValue;
  2264. ComplexValue* = OBJECT (Value)
  2265. VAR
  2266. realValue-, imagValue-: LONGREAL;
  2267. subtype-: LONGINT; (* accuracy information of components: REAL vs. LONGREAL *)
  2268. PROCEDURE & InitComplexValue(position: LONGINT; realValue, imagValue: LONGREAL);
  2269. BEGIN
  2270. InitValue(position); SELF.realValue := realValue; SELF.imagValue := imagValue; SELF.subtype := 0;
  2271. END InitComplexValue;
  2272. PROCEDURE SetValue*(realValue, imagValue: LONGREAL);
  2273. BEGIN SELF.realValue := realValue; SELF.imagValue := imagValue;
  2274. END SetValue;
  2275. PROCEDURE UpdateSubtype*;
  2276. BEGIN
  2277. ASSERT((type # NIL) & (type.resolved # NIL) & (type.resolved IS ComplexType) & (type.resolved(ComplexType).componentType IS FloatType));
  2278. CASE type.resolved(ComplexType).componentType(FloatType).sizeInBits OF
  2279. | 32: subtype := Scanner.Real
  2280. | 64: subtype := Scanner.Longreal
  2281. END
  2282. END UpdateSubtype;
  2283. PROCEDURE SetSubtype*(subtype: LONGINT);
  2284. BEGIN SELF.subtype := subtype;
  2285. END SetSubtype;
  2286. PROCEDURE Clone(): Expression;
  2287. VAR copy: ComplexValue;
  2288. BEGIN
  2289. NEW(copy, position, realValue, imagValue); copy.subtype := subtype; RETURN copy
  2290. END Clone;
  2291. PROCEDURE Accept*(v: Visitor);
  2292. VAR position: LONGINT;
  2293. BEGIN position := SELF.position; v.VisitComplexValue(SELF)
  2294. END Accept;
  2295. PROCEDURE Equals*(v: Value):BOOLEAN;
  2296. BEGIN RETURN (v IS ComplexValue) & (v(ComplexValue).realValue = realValue) & (v(ComplexValue).imagValue = imagValue);
  2297. (* TODO: append this?
  2298. OR (v IS RealValue) & (v(RealValue).value = realValue) & (imagValue := 0)
  2299. *)
  2300. END Equals;
  2301. END ComplexValue;
  2302. (** <<value = "string">> **)
  2303. StringValue* = OBJECT (Value)
  2304. VAR
  2305. value-: String;
  2306. length-: LONGINT;
  2307. PROCEDURE & InitStringValue(position: LONGINT; value: String);
  2308. BEGIN
  2309. InitValue(position); SELF.value := value;
  2310. length := 0;
  2311. WHILE (length<LEN(value)) & (value[length] # 0X) DO
  2312. INC(length);
  2313. END;
  2314. IF length < LEN(value) THEN INC(length) END
  2315. END InitStringValue;
  2316. PROCEDURE SetValue*(CONST value: String);
  2317. BEGIN SELF.value := value
  2318. END SetValue;
  2319. PROCEDURE Append*(CONST value: String);
  2320. VAR new: String; len: LONGINT;
  2321. BEGIN
  2322. len := Strings.Length(SELF.value^) + Strings.Length(value^) + 1;
  2323. IF LEN(SELF.value) < len THEN
  2324. NEW(new, len);
  2325. COPY(SELF.value^, new^);
  2326. SELF.value := new
  2327. END;
  2328. Strings.Append(SELF.value^, value^);
  2329. length := len
  2330. END Append;
  2331. PROCEDURE AppendChar*(CONST ch: CHAR);
  2332. VAR v: String;
  2333. BEGIN
  2334. NEW(v,2); v[0] := ch;
  2335. Append(v);
  2336. END AppendChar;
  2337. PROCEDURE Clone(): Expression;
  2338. VAR copy: StringValue;
  2339. BEGIN
  2340. NEW(copy, position, value); RETURN copy
  2341. END Clone;
  2342. PROCEDURE Accept*(v: Visitor);
  2343. VAR position: LONGINT;
  2344. BEGIN position := SELF.position; v.VisitStringValue(SELF)
  2345. END Accept;
  2346. PROCEDURE Equals*(v: Value):BOOLEAN;
  2347. BEGIN RETURN (v IS StringValue) & (v(StringValue).value = value); END Equals;
  2348. END StringValue;
  2349. (** <<value = NIL>> **)
  2350. NilValue* = OBJECT (Value)
  2351. PROCEDURE Accept*(v: Visitor);
  2352. VAR position: LONGINT;
  2353. BEGIN position := SELF.position; v.VisitNilValue(SELF)
  2354. END Accept;
  2355. PROCEDURE Clone(): Expression;
  2356. VAR copy: NilValue;
  2357. BEGIN
  2358. NEW(copy, position); RETURN copy
  2359. END Clone;
  2360. PROCEDURE Equals*(v: Value):BOOLEAN;
  2361. BEGIN RETURN (v IS NilValue); END Equals;
  2362. END NilValue;
  2363. (** <<value = enum.x >> **)
  2364. EnumerationValue* = OBJECT (Value)
  2365. VAR
  2366. value-: LONGINT;
  2367. PROCEDURE & InitEnumerationValue(position: LONGINT; value: LONGINT);
  2368. BEGIN
  2369. InitValue(position); SELF.value := value;
  2370. END InitEnumerationValue;
  2371. PROCEDURE SetValue*(value: LONGINT);
  2372. BEGIN SELF.value := value
  2373. END SetValue;
  2374. PROCEDURE Clone(): Expression;
  2375. VAR copy: EnumerationValue;
  2376. BEGIN
  2377. NEW(copy, position, value); RETURN copy
  2378. END Clone;
  2379. PROCEDURE Accept*(v: Visitor);
  2380. VAR position: LONGINT;
  2381. BEGIN position := SELF.position; v.VisitEnumerationValue(SELF)
  2382. END Accept;
  2383. PROCEDURE Equals*(v: Value):BOOLEAN;
  2384. BEGIN RETURN (v IS EnumerationValue) & (v(EnumerationValue).value = value); END Equals;
  2385. END EnumerationValue;
  2386. (**** symbols ****)
  2387. Symbol*= OBJECT
  2388. VAR
  2389. nextSymbol-: Symbol;
  2390. name-: Identifier; (* constant / variable / parameter / type name / module name *)
  2391. externalName-: Scanner.StringType; (* variable / procedure *)
  2392. access-: SET; (* access flags (exported, readonly etc.) *)
  2393. type-: Type; (* type of constant / variable / parameter / procedure return type *)
  2394. scope-:Scope; (* container of symbol *)
  2395. offsetInBits-: LONGINT; (* offset in stack or heap, in bits *)
  2396. used-, written-: BOOLEAN;
  2397. fixed-: BOOLEAN;
  2398. alignment-: LONGINT;
  2399. position-: LONGINT; state-: SET;
  2400. fingerprint-: FingerPrint;
  2401. comment-: Comment;
  2402. PROCEDURE & InitSymbol(position: LONGINT; name:Identifier);
  2403. BEGIN
  2404. SELF.position := position; state := Undefined;
  2405. nextSymbol := NIL;
  2406. SELF.name := name;
  2407. externalName := NIL;
  2408. scope:= NIL;
  2409. type := NIL;
  2410. access := Internal;
  2411. state := Undefined;
  2412. offsetInBits := MIN(LONGINT);
  2413. alignment := 0; (* take default *)
  2414. fixed := FALSE;
  2415. used := FALSE; written := FALSE;
  2416. InitFingerPrint(fingerprint);
  2417. comment := NIL;
  2418. END InitSymbol;
  2419. PROCEDURE SetAlignment*(fix: BOOLEAN; align: LONGINT);
  2420. BEGIN SELF.alignment := align; fixed := fix;
  2421. END SetAlignment;
  2422. PROCEDURE SetFingerPrint*(CONST fp: FingerPrint);
  2423. BEGIN
  2424. SELF.fingerprint := fp
  2425. END SetFingerPrint;
  2426. PROCEDURE SetState*(state: LONGINT);
  2427. BEGIN INCL(SELF.state,state);
  2428. END SetState;
  2429. PROCEDURE SetScope*(scope: Scope);
  2430. BEGIN SELF.scope := scope
  2431. END SetScope;
  2432. PROCEDURE SetType*(type: Type);
  2433. BEGIN
  2434. SELF.type := type;
  2435. END SetType;
  2436. PROCEDURE SetNext*(symbol: Symbol);
  2437. BEGIN SELF.nextSymbol := symbol; END SetNext;
  2438. PROCEDURE SetAccess*(access: SET);
  2439. BEGIN
  2440. (* consistency guarantee *)
  2441. IF PublicWrite IN access THEN ASSERT(ProtectedWrite IN access) END;
  2442. IF ProtectedWrite IN access THEN ASSERT(InternalWrite IN access) END;
  2443. IF PublicRead IN access THEN ASSERT(ProtectedRead IN access) END;
  2444. IF ProtectedRead IN access THEN ASSERT(InternalRead IN access)END;
  2445. SELF.access := access;
  2446. END SetAccess;
  2447. PROCEDURE SetOffset*(ofs: LONGINT);
  2448. BEGIN offsetInBits := ofs
  2449. END SetOffset;
  2450. PROCEDURE MarkUsed*;
  2451. BEGIN used := TRUE
  2452. END MarkUsed;
  2453. PROCEDURE MarkWritten*;
  2454. BEGIN written := TRUE
  2455. END MarkWritten;
  2456. PROCEDURE GetName*(VAR str: ARRAY OF CHAR);
  2457. BEGIN Basic.GetString(name, str);
  2458. END GetName;
  2459. PROCEDURE SetComment*(comment: Comment);
  2460. BEGIN SELF.comment := comment
  2461. END SetComment;
  2462. PROCEDURE Accept*(v: Visitor);
  2463. VAR position: LONGINT;
  2464. BEGIN position := SELF.position; v.VisitSymbol(SELF)
  2465. END Accept;
  2466. PROCEDURE SetExternalName*(name: Scanner.StringType);
  2467. BEGIN externalName := name;
  2468. END SetExternalName;
  2469. PROCEDURE NeedsTrace* (): BOOLEAN;
  2470. BEGIN RETURN FALSE;
  2471. END NeedsTrace;
  2472. END Symbol;
  2473. (**
  2474. <<TYPE name = declaredType>>
  2475. TypeDeclaration symbol represents a type declaration of the form TYPE name = declaredType.
  2476. Note that the declared type is not stored in the symbol's type field but rather in the declaredType field.
  2477. The type of a type declaration is set to "typeDeclarationType" in the semantic checker
  2478. **)
  2479. TypeDeclaration*= OBJECT(Symbol)
  2480. VAR
  2481. nextTypeDeclaration-: TypeDeclaration;
  2482. declaredType-: Type;
  2483. PROCEDURE &InitTypeDeclaration(position: LONGINT; name: Identifier);
  2484. BEGIN
  2485. InitSymbol(position,name);
  2486. nextTypeDeclaration := NIL;
  2487. declaredType := NIL;
  2488. type := typeDeclarationType;
  2489. END InitTypeDeclaration;
  2490. PROCEDURE SetDeclaredType*(type: Type);
  2491. BEGIN
  2492. declaredType := type;
  2493. IF ~(type IS BasicType) THEN
  2494. type.typeDeclaration := SELF;
  2495. END;
  2496. END SetDeclaredType;
  2497. PROCEDURE SetType*(type: Type);
  2498. BEGIN
  2499. ASSERT(type = typeDeclarationType);
  2500. END SetType;
  2501. PROCEDURE Accept*(v: Visitor);
  2502. VAR position: LONGINT;
  2503. BEGIN position := SELF.position; v.VisitTypeDeclaration(SELF)
  2504. END Accept;
  2505. END TypeDeclaration;
  2506. (** <<CONST name = value >>
  2507. Constant declaration symbol. Represents a constant being defined in the form CONST name = value
  2508. The type of the constant is stored in the type field and is resolved by the semantic checker.
  2509. **)
  2510. Constant* = OBJECT (Symbol)
  2511. VAR
  2512. value-: Expression;
  2513. nextConstant-: Constant;
  2514. PROCEDURE & InitConstant( position: LONGINT; name: Identifier );
  2515. BEGIN
  2516. InitSymbol(position,name);
  2517. value := NIL;
  2518. nextConstant := NIL;
  2519. END InitConstant;
  2520. PROCEDURE SetValue*( value: Expression );
  2521. BEGIN
  2522. SELF.value := value;
  2523. END SetValue;
  2524. PROCEDURE Accept*(v: Visitor);
  2525. VAR position: LONGINT;
  2526. BEGIN position := SELF.position; v.VisitConstant(SELF)
  2527. END Accept;
  2528. END Constant;
  2529. (** <<VAR name: type >>
  2530. Variable declaration symbol. Represents a variable defined in the form VAR name: Type.
  2531. The type of the variable is stored in the symbol's type field and is resolved by the semantic checker.
  2532. **)
  2533. Variable* = OBJECT (Symbol)
  2534. VAR
  2535. nextVariable-: Variable;
  2536. untraced-: BOOLEAN;
  2537. useRegister-: BOOLEAN; registerNumber-: LONGINT;
  2538. modifiers-: Modifier;
  2539. initializer-: Expression;
  2540. usedAsReference-: BOOLEAN;
  2541. PROCEDURE & InitVariable*( position: LONGINT; name: Identifier);
  2542. BEGIN
  2543. InitSymbol(position,name);
  2544. nextVariable := NIL;
  2545. modifiers := NIL;
  2546. untraced := FALSE;
  2547. modifiers := NIL;
  2548. useRegister := FALSE;
  2549. registerNumber := -1;
  2550. usedAsReference := FALSE;
  2551. initializer := NIL;
  2552. END InitVariable;
  2553. PROCEDURE UsedAsReference*;
  2554. BEGIN
  2555. usedAsReference := TRUE
  2556. END UsedAsReference;
  2557. PROCEDURE SetUntraced*(u: BOOLEAN);
  2558. BEGIN untraced := u
  2559. END SetUntraced;
  2560. PROCEDURE SetUseRegister*(u: BOOLEAN);
  2561. BEGIN
  2562. useRegister := u
  2563. END SetUseRegister;
  2564. PROCEDURE SetRegisterNumber*(reg: LONGINT);
  2565. BEGIN
  2566. registerNumber := reg
  2567. END SetRegisterNumber;
  2568. PROCEDURE SetModifiers*(flag: Modifier);
  2569. BEGIN SELF.modifiers := flag;
  2570. END SetModifiers;
  2571. PROCEDURE SetInitializer*(initializer: Expression);
  2572. BEGIN SELF.initializer := initializer;
  2573. END SetInitializer;
  2574. PROCEDURE Accept*(v: Visitor);
  2575. VAR position: LONGINT;
  2576. BEGIN position := SELF.position; v.VisitVariable(SELF)
  2577. END Accept;
  2578. PROCEDURE NeedsTrace* (): BOOLEAN;
  2579. BEGIN RETURN ~untraced & (externalName = NIL) & type.NeedsTrace ();
  2580. END NeedsTrace;
  2581. END Variable;
  2582. (** << [VAR | CONST] name: type >>
  2583. Parameter declaration symbol. Represents a parameter in the form [VAR | CONST] name: Type.
  2584. The parameter's type is stored in the symbol's type field and is resolved by the semantic checker.
  2585. **)
  2586. Parameter* = OBJECT (Symbol)
  2587. VAR
  2588. nextParameter-, prevParameter-: Parameter;
  2589. modifiers-: Modifier;
  2590. defaultValue-: Expression;
  2591. kind-: LONGINT; (* ValueParameter, ConstParameter, VarParameter *)
  2592. ownerType-: Type;
  2593. untraced-: BOOLEAN;
  2594. movable-: BOOLEAN;
  2595. PROCEDURE & InitParameter( position: LONGINT; ownerType: Type ; name: Identifier; kind: LONGINT);
  2596. BEGIN
  2597. InitSymbol( position, name );
  2598. SELF.kind := kind;
  2599. IF kind = ConstParameter THEN access := access END;
  2600. nextParameter := NIL;
  2601. SELF.ownerType := ownerType;
  2602. modifiers := NIL;
  2603. untraced := FALSE;
  2604. defaultValue := NIL;
  2605. movable := FALSE;
  2606. END InitParameter;
  2607. PROCEDURE SetModifiers*(flag: Modifier);
  2608. BEGIN SELF.modifiers := flag;
  2609. END SetModifiers;
  2610. PROCEDURE SetUntraced*(untraced: BOOLEAN);
  2611. BEGIN SELF.untraced := untraced
  2612. END SetUntraced;
  2613. PROCEDURE SetMoveable*(movable: BOOLEAN);
  2614. BEGIN SELF.movable := movable
  2615. END SetMoveable;
  2616. PROCEDURE SetDefaultValue*(e: Expression);
  2617. BEGIN defaultValue := e
  2618. END SetDefaultValue;
  2619. PROCEDURE Accept*(v: Visitor);
  2620. VAR position: LONGINT;
  2621. BEGIN position := SELF.position; v.VisitParameter(SELF)
  2622. END Accept;
  2623. PROCEDURE SetKind*(kind: LONGINT);
  2624. BEGIN SELF.kind := kind; END SetKind;
  2625. PROCEDURE NeedsTrace* (): BOOLEAN;
  2626. BEGIN RETURN ~untraced & type.NeedsTrace ();
  2627. END NeedsTrace;
  2628. END Parameter;
  2629. Property* = OBJECT (Variable)
  2630. VAR
  2631. nextProperty-, prevProperty-: Property;
  2632. value-: Expression;
  2633. PROCEDURE & InitProperty(position: LONGINT; name: Identifier);
  2634. BEGIN
  2635. InitSymbol( position, name );
  2636. END InitProperty;
  2637. PROCEDURE SetValue*(e: Expression);
  2638. BEGIN value := e
  2639. END SetValue;
  2640. PROCEDURE Accept*(v: Visitor);
  2641. VAR position: LONGINT;
  2642. BEGIN position := SELF.position; v.VisitProperty(SELF)
  2643. END Accept;
  2644. END Property;
  2645. (** Procedure declaration symbol. Represents a procedure being defined in the form PROCEDURE name(parameters): returnType;
  2646. Note that the type of a procedure is a ProcedureType (and not the return type of the procedure).
  2647. Parameters, local variables, constants and type declarations are stored in the procedureScope field.
  2648. **)
  2649. Procedure* = OBJECT (Symbol)
  2650. VAR
  2651. nextProcedure-: Procedure;
  2652. procedureScope- : ProcedureScope;
  2653. super-: Procedure;
  2654. level-, methodNumber-: LONGINT;
  2655. isBodyProcedure-, isConstructor-,isFinalizer-,isInline-,isOberonInline-, isEntry-, isExit-,isFinal-,isAbstract-,isOverwritten-: BOOLEAN;
  2656. PROCEDURE & InitProcedure( position: LONGINT; name: Identifier; scope: ProcedureScope);
  2657. BEGIN
  2658. InitSymbol(position,name);
  2659. nextProcedure := NIL;
  2660. procedureScope := scope;
  2661. ASSERT(scope.ownerProcedure = NIL); (* cannot register twice ! *)
  2662. scope.ownerProcedure := SELF;
  2663. super := NIL;
  2664. level := 0;
  2665. methodNumber := -1;
  2666. isBodyProcedure := FALSE;
  2667. isConstructor := FALSE;
  2668. isFinalizer := FALSE;
  2669. isInline := FALSE;
  2670. isOberonInline := FALSE;
  2671. isEntry := FALSE;
  2672. isExit := FALSE;
  2673. isFinal := FALSE;
  2674. isAbstract := FALSE;
  2675. isOverwritten := FALSE;
  2676. END InitProcedure;
  2677. PROCEDURE SetSuper*(super: Procedure);
  2678. BEGIN
  2679. SELF.super := super
  2680. END SetSuper;
  2681. PROCEDURE SetBodyProcedure*(isBodyProcedure: BOOLEAN);
  2682. BEGIN SELF.isBodyProcedure := isBodyProcedure;
  2683. END SetBodyProcedure;
  2684. PROCEDURE SetConstructor*(isConstructor: BOOLEAN);
  2685. BEGIN SELF.isConstructor := isConstructor
  2686. END SetConstructor;
  2687. PROCEDURE SetFinalizer*(isFinalizer: BOOLEAN);
  2688. BEGIN SELF.isFinalizer := isFinalizer
  2689. END SetFinalizer;
  2690. PROCEDURE SetInline*(isInline: BOOLEAN);
  2691. BEGIN SELF.isInline := isInline
  2692. END SetInline;
  2693. PROCEDURE SetOberonInline*(isInline: BOOLEAN);
  2694. BEGIN SELF.isOberonInline := isInline
  2695. END SetOberonInline;
  2696. PROCEDURE SetEntry*(entry: BOOLEAN);
  2697. BEGIN SELF.isEntry := entry
  2698. END SetEntry;
  2699. PROCEDURE SetExit*(exit: BOOLEAN);
  2700. BEGIN SELF.isExit := exit
  2701. END SetExit;
  2702. PROCEDURE SetFinal*(final: BOOLEAN);
  2703. BEGIN SELF.isFinal := final
  2704. END SetFinal;
  2705. PROCEDURE SetOverwritten*(locallyOverwritten: BOOLEAN);
  2706. BEGIN SELF.isOverwritten := locallyOverwritten
  2707. END SetOverwritten;
  2708. PROCEDURE SetAbstract*(abstract: BOOLEAN);
  2709. BEGIN SELF.isAbstract := abstract
  2710. END SetAbstract;
  2711. PROCEDURE SetLevel*(level: LONGINT);
  2712. BEGIN SELF.level := level
  2713. END SetLevel;
  2714. PROCEDURE SetMethodNumber*(methodNumber: LONGINT);
  2715. BEGIN SELF.methodNumber := methodNumber
  2716. END SetMethodNumber;
  2717. PROCEDURE Accept*(v: Visitor);
  2718. VAR position: LONGINT;
  2719. BEGIN position := SELF.position; v.VisitProcedure(SELF)
  2720. END Accept;
  2721. END Procedure;
  2722. (** Builtin symbol stands for a builtin procedure. Is resolved by the semantic checker. **)
  2723. Builtin* = OBJECT (Symbol)
  2724. VAR
  2725. nextBuiltin-: Builtin;
  2726. id-: LONGINT;
  2727. PROCEDURE & InitBuiltin(position: LONGINT; name:Identifier; id: LONGINT);
  2728. BEGIN
  2729. InitSymbol(position,name); SELF.id := id;
  2730. END InitBuiltin;
  2731. PROCEDURE Accept*(v: Visitor);
  2732. VAR position: LONGINT;
  2733. BEGIN position := SELF.position; v.VisitBuiltin(SELF)
  2734. END Accept;
  2735. END Builtin;
  2736. CustomBuiltin*=OBJECT (Builtin)
  2737. VAR
  2738. subType-: SHORTINT;
  2739. PROCEDURE & InitCustomBuiltin(position: LONGINT; name: Identifier; id: LONGINT; subType: SHORTINT);
  2740. BEGIN
  2741. InitBuiltin(position,name,id);
  2742. SELF.subType := subType;
  2743. END InitCustomBuiltin;
  2744. (* TODO: check if this is correct *)
  2745. PROCEDURE CompatibleTo*(otherType: Type): BOOLEAN;
  2746. BEGIN RETURN FALSE
  2747. END CompatibleTo;
  2748. END CustomBuiltin;
  2749. Operator* = OBJECT (Procedure)
  2750. VAR
  2751. nextOperator-: Operator;
  2752. isDynamic-: BOOLEAN; (* nopov *)
  2753. PROCEDURE & InitOperator(position: LONGINT; name: Identifier; scope: ProcedureScope);
  2754. BEGIN
  2755. InitProcedure(position,name,scope);
  2756. nextOperator := NIL;
  2757. isDynamic := FALSE
  2758. END InitOperator;
  2759. (* nopov *)
  2760. PROCEDURE SetDynamic*(isDynamic: BOOLEAN);
  2761. BEGIN SELF.isDynamic := isDynamic
  2762. END SetDynamic;
  2763. PROCEDURE Accept*(v: Visitor);
  2764. VAR position: LONGINT;
  2765. BEGIN position := SELF.position; v.VisitOperator(SELF)
  2766. END Accept;
  2767. END Operator;
  2768. Import* = OBJECT (Symbol)
  2769. VAR
  2770. nextImport-: Import;
  2771. module-: Module;
  2772. moduleName-: Identifier;
  2773. context-: Identifier;
  2774. direct-: BOOLEAN; (* direct import *)
  2775. PROCEDURE & InitImport( position: LONGINT; name, moduleName: Identifier; direct: BOOLEAN );
  2776. BEGIN
  2777. InitSymbol(position,name);
  2778. SELF.direct := direct;
  2779. module := NIL;
  2780. context := invalidIdentifier;
  2781. SELF.moduleName := moduleName;
  2782. type := importType;
  2783. END InitImport;
  2784. PROCEDURE SetType*(type: Type);
  2785. BEGIN
  2786. ASSERT(type = importType);
  2787. END SetType;
  2788. PROCEDURE SetModule*(module: Module);
  2789. BEGIN
  2790. SELF.module := module;
  2791. END SetModule;
  2792. PROCEDURE SetDirect*(d: BOOLEAN);
  2793. BEGIN
  2794. direct := d
  2795. END SetDirect;
  2796. PROCEDURE SetModuleName*(moduleName: Identifier);
  2797. BEGIN SELF.moduleName := moduleName
  2798. END SetModuleName;
  2799. PROCEDURE SetContext*(context: Identifier);
  2800. BEGIN
  2801. SELF.context := context
  2802. END SetContext;
  2803. PROCEDURE Accept*(v: Visitor);
  2804. VAR position: LONGINT;
  2805. BEGIN position := SELF.position; v.VisitImport(SELF)
  2806. END Accept;
  2807. END Import;
  2808. StatementSequence* = OBJECT
  2809. VAR
  2810. list: Basic.List;
  2811. PROCEDURE & InitList;
  2812. BEGIN NEW( list,32 );
  2813. END InitList;
  2814. PROCEDURE Length*( ): LONGINT;
  2815. BEGIN RETURN list.Length();
  2816. END Length;
  2817. PROCEDURE AddStatement*( statement: Statement);
  2818. BEGIN list.Add( statement );
  2819. END AddStatement;
  2820. PROCEDURE PrependStatement*( statement: Statement);
  2821. BEGIN list.Prepend( statement );
  2822. END PrependStatement;
  2823. PROCEDURE HasStatement*( statement: Statement):BOOLEAN;
  2824. BEGIN RETURN list.Contains(statement);
  2825. END HasStatement;
  2826. PROCEDURE GetStatement*( index: LONGINT ): Statement;
  2827. VAR p: ANY;
  2828. BEGIN p := list.Get( index ); RETURN p( Statement );
  2829. END GetStatement;
  2830. PROCEDURE SetStatement*(index: LONGINT; statement: Statement);
  2831. BEGIN
  2832. list.Set(index,statement);
  2833. END SetStatement;
  2834. PROCEDURE RemoveStatement*(statement: Statement);
  2835. BEGIN
  2836. list.Remove(statement);
  2837. END RemoveStatement;
  2838. PROCEDURE InsertBefore*(search, new: Statement);
  2839. BEGIN
  2840. list.Insert(list.IndexOf(search), new);
  2841. END InsertBefore;
  2842. PROCEDURE Clone(VAR copy: StatementSequence);
  2843. VAR i: LONGINT;
  2844. BEGIN
  2845. IF copy = NIL THEN NEW(copy) END;
  2846. FOR i := 0 TO Length()-1 DO
  2847. copy.AddStatement(CloneStatement(GetStatement(i)))
  2848. END;
  2849. END Clone;
  2850. END StatementSequence;
  2851. (**** statements ****)
  2852. Statement*= OBJECT
  2853. VAR outer-: Statement;
  2854. position-: LONGINT;
  2855. isUnreachable-: BOOLEAN;
  2856. comment-: Comment;
  2857. PROCEDURE & InitStatement*(position: LONGINT; outer: Statement);
  2858. BEGIN
  2859. SELF.position := position;
  2860. SELF.outer := outer;
  2861. isUnreachable := FALSE;
  2862. comment := NIL;
  2863. END InitStatement;
  2864. PROCEDURE SetOuter*(o: Statement);
  2865. BEGIN outer := o
  2866. END SetOuter;
  2867. PROCEDURE SetUnreachable*(unreachable: BOOLEAN);
  2868. BEGIN isUnreachable := unreachable
  2869. END SetUnreachable;
  2870. PROCEDURE Accept*(v: Visitor);
  2871. VAR position: LONGINT;
  2872. BEGIN position := SELF.position; v.VisitStatement(SELF)
  2873. END Accept;
  2874. PROCEDURE SetComment*(comment: Comment);
  2875. BEGIN SELF.comment := comment
  2876. END SetComment;
  2877. PROCEDURE Clone(): Statement;
  2878. BEGIN
  2879. HALT(200) (* abstract *)
  2880. END Clone;
  2881. END Statement;
  2882. (** << call(...) >> **)
  2883. ProcedureCallStatement*= OBJECT(Statement)
  2884. VAR call-: Designator;
  2885. PROCEDURE & InitProcedureCallStatement(position: LONGINT; call: Designator; outer: Statement);
  2886. BEGIN InitStatement(position,outer); SELF.call := call;
  2887. END InitProcedureCallStatement;
  2888. PROCEDURE SetCall*(call: Designator);
  2889. BEGIN SELF.call := call;
  2890. END SetCall;
  2891. PROCEDURE Clone(): Statement;
  2892. VAR copy: ProcedureCallStatement;
  2893. BEGIN
  2894. NEW(copy, position, CloneDesignator(call), outer);
  2895. RETURN copy
  2896. END Clone;
  2897. PROCEDURE Accept*(v: Visitor);
  2898. VAR position: LONGINT;
  2899. BEGIN position := SELF.position; v.VisitProcedureCallStatement(SELF)
  2900. END Accept;
  2901. END ProcedureCallStatement;
  2902. (** << left := right >> **)
  2903. Assignment* = OBJECT (Statement)
  2904. VAR left-: Designator; right-: Expression;
  2905. PROCEDURE & InitAssignment*( position: LONGINT; left: Designator; right: Expression; outer: Statement );
  2906. BEGIN
  2907. InitStatement( position,outer ); SELF.left := left; SELF.right := right;
  2908. END InitAssignment;
  2909. PROCEDURE SetLeft*(left: Designator);
  2910. BEGIN SELF.left := left
  2911. END SetLeft;
  2912. PROCEDURE SetRight*(right: Expression);
  2913. BEGIN SELF.right := right
  2914. END SetRight;
  2915. PROCEDURE Clone(): Statement;
  2916. VAR copy: Assignment;
  2917. BEGIN
  2918. NEW(copy, position, CloneDesignator(left), CloneExpression(right), outer);
  2919. RETURN copy
  2920. END Clone;
  2921. PROCEDURE Accept*(v: Visitor);
  2922. VAR position: LONGINT;
  2923. BEGIN position := SELF.position; v.VisitAssignment(SELF)
  2924. END Accept;
  2925. END Assignment;
  2926. (** << left ('!' | '?' | '<<' | '>>') right >> **)
  2927. CommunicationStatement* = OBJECT (Statement)
  2928. VAR
  2929. left-: Designator; right-: Expression; op-: LONGINT;
  2930. PROCEDURE & InitAssignment*( position: LONGINT; op: LONGINT; left: Designator; right: Expression; outer: Statement );
  2931. BEGIN
  2932. InitStatement( position,outer ); SELF.op := op; SELF.left := left; SELF.right := right;
  2933. END InitAssignment;
  2934. PROCEDURE SetLeft*(left: Designator);
  2935. BEGIN SELF.left := left
  2936. END SetLeft;
  2937. PROCEDURE SetRight*(right: Expression);
  2938. BEGIN SELF.right := right
  2939. END SetRight;
  2940. PROCEDURE Accept*(v: Visitor);
  2941. VAR position: LONGINT;
  2942. BEGIN position := SELF.position; v.VisitCommunicationStatement(SELF)
  2943. END Accept;
  2944. END CommunicationStatement;
  2945. (** << ... condition THEN statements ... >> **)
  2946. IfPart*= OBJECT
  2947. VAR
  2948. condition-: Expression;
  2949. statements-: StatementSequence;
  2950. comment-: Comment;
  2951. PROCEDURE & InitIfPart;
  2952. BEGIN
  2953. statements := NIL; condition := NIL; comment := NIL;
  2954. END InitIfPart;
  2955. PROCEDURE SetCondition*(condition: Expression);
  2956. BEGIN SELF.condition := condition
  2957. END SetCondition;
  2958. PROCEDURE SetStatements*(statements: StatementSequence);
  2959. BEGIN SELF.statements := statements
  2960. END SetStatements;
  2961. PROCEDURE SetComment*(comment: Comment);
  2962. BEGIN SELF.comment := comment
  2963. END SetComment;
  2964. PROCEDURE Clone(): IfPart;
  2965. VAR copy: IfPart;
  2966. BEGIN
  2967. NEW(copy); copy.condition := CloneExpression(condition);
  2968. copy.statements := CloneStatementSequence(statements);
  2969. RETURN copy
  2970. END Clone;
  2971. END IfPart;
  2972. (** << IF ifPart {ELSIF elsifParts} ELSE elseParts >> **)
  2973. IfStatement* = OBJECT (Statement)
  2974. VAR
  2975. ifPart-: IfPart;
  2976. elsifParts: Basic.List;
  2977. elsePart-: StatementSequence;
  2978. PROCEDURE & InitIfStatement( position: LONGINT ; outer: Statement);
  2979. BEGIN
  2980. InitStatement( position,outer ); ifPart := NewIfPart(); elsePart := NIL; elsifParts := NIL;
  2981. END InitIfStatement;
  2982. PROCEDURE SetElsePart*( elsePart: StatementSequence );
  2983. BEGIN
  2984. SELF.elsePart := elsePart;
  2985. END SetElsePart;
  2986. PROCEDURE AddElsifPart*( elsifPart: IfPart );
  2987. BEGIN
  2988. IF elsifParts = NIL THEN NEW(elsifParts,4); END;
  2989. elsifParts.Add( elsifPart );
  2990. END AddElsifPart;
  2991. PROCEDURE GetElsifPart*( i: LONGINT ): IfPart;
  2992. VAR a: ANY;
  2993. BEGIN a := elsifParts.Get( i ); RETURN a( IfPart )
  2994. END GetElsifPart;
  2995. PROCEDURE ElsifParts*( ): LONGINT;
  2996. BEGIN
  2997. IF elsifParts = NIL THEN RETURN 0 ELSE RETURN elsifParts.Length(); END;
  2998. END ElsifParts;
  2999. PROCEDURE Clone(): Statement;
  3000. VAR copy: IfStatement; i: LONGINT;
  3001. BEGIN
  3002. NEW(copy, position, outer);
  3003. copy.ifPart := ifPart.Clone();
  3004. FOR i := 0 TO ElsifParts()-1 DO
  3005. copy.AddElsifPart(GetElsifPart(i).Clone());
  3006. END;
  3007. copy.SetElsePart(CloneStatementSequence(elsePart));
  3008. RETURN copy
  3009. END Clone;
  3010. PROCEDURE Accept*(v: Visitor);
  3011. VAR position: LONGINT;
  3012. BEGIN position := SELF.position; v.VisitIfStatement(SELF)
  3013. END Accept;
  3014. END IfStatement;
  3015. WithPart*= OBJECT
  3016. VAR
  3017. variable-: Designator;
  3018. type-: Type; (* initially is qualified type *)
  3019. statements-: StatementSequence;
  3020. comment-: Comment;
  3021. PROCEDURE &InitWithPart();
  3022. BEGIN
  3023. type := NIL; variable := NIL; statements := NIL; comment := NIL;
  3024. END InitWithPart;
  3025. PROCEDURE SetVariable*( variable: Designator);
  3026. BEGIN
  3027. SELF.variable := variable
  3028. END SetVariable;
  3029. PROCEDURE SetType*( type: Type );
  3030. BEGIN
  3031. SELF.type := type
  3032. END SetType;
  3033. PROCEDURE SetStatements*( statements: StatementSequence );
  3034. BEGIN
  3035. SELF.statements := statements;
  3036. END SetStatements;
  3037. PROCEDURE SetComment*(comment: Comment);
  3038. BEGIN SELF.comment := comment
  3039. END SetComment;
  3040. PROCEDURE Clone(): WithPart;
  3041. VAR copy: WithPart;
  3042. BEGIN
  3043. NEW(copy);
  3044. copy.SetVariable(CloneDesignator(variable));
  3045. copy.SetType(type);
  3046. copy.SetStatements(CloneStatementSequence(statements));
  3047. RETURN copy
  3048. END Clone;
  3049. END WithPart;
  3050. (** << WITH variable : type DO statements END >> **)
  3051. WithStatement* = OBJECT (Statement)
  3052. VAR
  3053. withParts-: Basic.List;
  3054. elsePart-: StatementSequence;
  3055. PROCEDURE & InitWithStatement( position: LONGINT; outer: Statement );
  3056. BEGIN
  3057. InitStatement( position,outer );
  3058. NEW(withParts,4); elsePart := NIL;
  3059. END InitWithStatement;
  3060. PROCEDURE AddWithPart*( withPart: WithPart );
  3061. BEGIN withParts.Add( withPart );
  3062. END AddWithPart;
  3063. PROCEDURE GetWithPart*( i: LONGINT ): WithPart;
  3064. VAR a: ANY;
  3065. BEGIN a := withParts.Get( i ); RETURN a( WithPart )
  3066. END GetWithPart;
  3067. PROCEDURE WithParts*( ): LONGINT;
  3068. BEGIN
  3069. IF withParts = NIL THEN RETURN 0 ELSE RETURN withParts.Length(); END;
  3070. END WithParts;
  3071. PROCEDURE SetElsePart*( elsePart: StatementSequence );
  3072. BEGIN
  3073. SELF.elsePart := elsePart;
  3074. END SetElsePart;
  3075. PROCEDURE Clone(): Statement;
  3076. VAR copy: WithStatement; i: LONGINT;
  3077. BEGIN
  3078. NEW(copy, position, outer);
  3079. FOR i := 0 TO WithParts()-1 DO
  3080. copy.AddWithPart(GetWithPart(i).Clone());
  3081. END;
  3082. copy.SetElsePart(CloneStatementSequence(elsePart));
  3083. RETURN copy
  3084. END Clone;
  3085. PROCEDURE Accept*(v: Visitor);
  3086. VAR position: LONGINT;
  3087. BEGIN position := SELF.position; v.VisitWithStatement(SELF)
  3088. END Accept;
  3089. END WithStatement;
  3090. CaseConstant*= POINTER TO RECORD min*,max*: LONGINT; next*: CaseConstant END;
  3091. (** << elements : statements >> **)
  3092. CasePart* = OBJECT
  3093. VAR
  3094. elements-: ExpressionList; (* expression list inserted by the parser *)
  3095. firstConstant-: CaseConstant; (* expression list resolved to int32s, inserted by checker *)
  3096. statements-: StatementSequence;
  3097. comment-: Comment;
  3098. PROCEDURE & InitCasePart;
  3099. BEGIN
  3100. elements := NewExpressionList(); firstConstant := NIL;
  3101. END InitCasePart;
  3102. PROCEDURE SetStatements*( statements: StatementSequence );
  3103. BEGIN
  3104. SELF.statements := statements;
  3105. END SetStatements;
  3106. PROCEDURE SetConstants*(firstConstant: CaseConstant);
  3107. BEGIN SELF.firstConstant := firstConstant
  3108. END SetConstants;
  3109. PROCEDURE SetComment*(comment: Comment);
  3110. BEGIN SELF.comment := comment
  3111. END SetComment;
  3112. PROCEDURE Clone(): CasePart;
  3113. VAR copy: CasePart;
  3114. BEGIN
  3115. NEW(copy);
  3116. copy.SetStatements(CloneStatementSequence(statements));
  3117. copy.firstConstant := firstConstant;
  3118. elements.Clone(copy.elements);
  3119. RETURN copy
  3120. END Clone;
  3121. END CasePart;
  3122. (** << CASE varaible OF caseParts ELSE elsePart >> **)
  3123. CaseStatement* = OBJECT (Statement)
  3124. VAR
  3125. variable-: Expression;
  3126. elsePart-: StatementSequence;
  3127. caseParts-: Basic.List;
  3128. min-,max-: LONGINT;
  3129. PROCEDURE & InitCaseStatement( position: LONGINT ; outer: Statement);
  3130. BEGIN
  3131. InitStatement(position,outer ); variable := NIL; elsePart := NIL; caseParts := NIL;
  3132. min := MAX(LONGINT); max := MIN(LONGINT);
  3133. END InitCaseStatement;
  3134. PROCEDURE SetVariable*( expression: Expression );
  3135. BEGIN SELF.variable := expression;
  3136. END SetVariable;
  3137. PROCEDURE SetElsePart*( elsePart: StatementSequence );
  3138. BEGIN SELF.elsePart := elsePart;
  3139. END SetElsePart;
  3140. PROCEDURE AddCasePart*( casePart: CasePart );
  3141. BEGIN
  3142. IF caseParts = NIL THEN NEW(caseParts,4); END;
  3143. caseParts.Add( casePart );
  3144. END AddCasePart;
  3145. PROCEDURE GetCasePart*( i: LONGINT ): CasePart;
  3146. VAR a: ANY;
  3147. BEGIN a := caseParts.Get( i ); RETURN a( CasePart )
  3148. END GetCasePart;
  3149. PROCEDURE CaseParts*( ): LONGINT;
  3150. BEGIN
  3151. IF caseParts = NIL THEN RETURN 0 ELSE RETURN caseParts.Length(); END;
  3152. END CaseParts;
  3153. PROCEDURE Clone(): Statement;
  3154. VAR copy: CaseStatement; i: LONGINT;
  3155. BEGIN
  3156. NEW(copy, position, outer);
  3157. copy.SetVariable(CloneExpression(variable));
  3158. copy.SetElsePart(CloneStatementSequence(elsePart));
  3159. FOR i := 0 TO CaseParts()-1 DO
  3160. copy.AddCasePart(GetCasePart(i).Clone());
  3161. END;
  3162. copy.min := min; copy.max := max;
  3163. RETURN copy
  3164. END Clone;
  3165. PROCEDURE Accept*(v: Visitor);
  3166. VAR position: LONGINT;
  3167. BEGIN position := SELF.position; v.VisitCaseStatement(SELF)
  3168. END Accept;
  3169. PROCEDURE MaxConstant*(): LONGINT;
  3170. VAR val,i: LONGINT; part: CasePart; const: CaseConstant;
  3171. BEGIN
  3172. val := -1;
  3173. FOR i := 0 TO CaseParts() - 1 DO
  3174. part := GetCasePart(i);
  3175. const := part.firstConstant;
  3176. WHILE(const # NIL) DO
  3177. IF const.max > val THEN val := const.max; END;
  3178. const := const.next;
  3179. END;
  3180. END;
  3181. RETURN val;
  3182. END MaxConstant;
  3183. PROCEDURE SetMinMax*(min,max: LONGINT);
  3184. BEGIN
  3185. SELF.min := min; SELF.max := max;
  3186. END SetMinMax;
  3187. END CaseStatement;
  3188. (** << WHILE condition DO statements END >> **)
  3189. WhileStatement* = OBJECT (Statement)
  3190. VAR
  3191. condition-: Expression;
  3192. statements-: StatementSequence;
  3193. PROCEDURE & InitWhileStatement( position: LONGINT ; outer: Statement);
  3194. BEGIN
  3195. InitStatement( position,outer ); condition := NIL; statements := NIL;
  3196. END InitWhileStatement;
  3197. PROCEDURE SetCondition*( condition: Expression );
  3198. BEGIN
  3199. SELF.condition := condition
  3200. END SetCondition;
  3201. PROCEDURE SetStatements*( statements: StatementSequence );
  3202. BEGIN
  3203. SELF.statements := statements;
  3204. END SetStatements;
  3205. PROCEDURE Clone(): Statement;
  3206. VAR copy: WhileStatement;
  3207. BEGIN
  3208. NEW(copy, position, outer);
  3209. copy.SetCondition(CloneExpression(condition));
  3210. copy.SetStatements(CloneStatementSequence(statements));
  3211. RETURN copy
  3212. END Clone;
  3213. PROCEDURE Accept*(v: Visitor);
  3214. VAR position: LONGINT;
  3215. BEGIN position := SELF.position; v.VisitWhileStatement(SELF)
  3216. END Accept;
  3217. END WhileStatement;
  3218. (** << REPEAT statements UNTIL condition >> **)
  3219. RepeatStatement* = OBJECT (Statement)
  3220. VAR
  3221. condition-: Expression;
  3222. statements-: StatementSequence;
  3223. PROCEDURE & InitRepeatStatement( position: LONGINT; outer: Statement );
  3224. BEGIN
  3225. InitStatement( position,outer ); condition := NIL; statements := NIL;
  3226. END InitRepeatStatement;
  3227. PROCEDURE SetCondition*( condition: Expression );
  3228. BEGIN
  3229. SELF.condition := condition
  3230. END SetCondition;
  3231. PROCEDURE SetStatements*( statements: StatementSequence );
  3232. BEGIN
  3233. SELF.statements := statements;
  3234. END SetStatements;
  3235. PROCEDURE Clone(): Statement;
  3236. VAR copy: RepeatStatement;
  3237. BEGIN
  3238. NEW(copy, position, outer);
  3239. copy.SetCondition(CloneExpression(condition));
  3240. copy.SetStatements(CloneStatementSequence(statements));
  3241. RETURN copy
  3242. END Clone;
  3243. PROCEDURE Accept*(v: Visitor);
  3244. VAR position: LONGINT;
  3245. BEGIN position := SELF.position; v.VisitRepeatStatement(SELF)
  3246. END Accept;
  3247. END RepeatStatement;
  3248. (** << FOR variable := from TO to BY by DO statements END >> **)
  3249. ForStatement* = OBJECT (Statement)
  3250. VAR
  3251. variable-: Designator;
  3252. from-, to-, by-: Expression;
  3253. statements-: StatementSequence;
  3254. PROCEDURE & InitForStatement( position: LONGINT; outer: Statement );
  3255. BEGIN
  3256. InitStatement( position,outer ); variable := NIL;from := NIL; to := NIL; by := NIL; statements := NIL;
  3257. END InitForStatement;
  3258. PROCEDURE SetVariable*( variable: Designator);
  3259. BEGIN
  3260. SELF.variable := variable
  3261. END SetVariable;
  3262. PROCEDURE SetFrom*( from: Expression );
  3263. BEGIN
  3264. SELF.from := from
  3265. END SetFrom;
  3266. PROCEDURE SetTo*( to: Expression );
  3267. BEGIN
  3268. SELF.to := to
  3269. END SetTo;
  3270. PROCEDURE SetBy*( by: Expression );
  3271. BEGIN SELF.by := by
  3272. END SetBy;
  3273. PROCEDURE SetStatements*( statements: StatementSequence );
  3274. BEGIN SELF.statements := statements;
  3275. END SetStatements;
  3276. PROCEDURE Clone(): Statement;
  3277. VAR copy: ForStatement;
  3278. BEGIN
  3279. NEW(copy, position, outer);
  3280. copy.SetVariable(CloneDesignator(variable));
  3281. copy.SetFrom(CloneExpression(from));
  3282. copy.SetTo(CloneExpression(to));
  3283. copy.SetBy(CloneExpression(by));
  3284. copy.SetStatements(CloneStatementSequence(statements));
  3285. RETURN copy
  3286. END Clone;
  3287. PROCEDURE Accept*(v: Visitor);
  3288. VAR position: LONGINT;
  3289. BEGIN position := SELF.position; v.VisitForStatement(SELF)
  3290. END Accept;
  3291. END ForStatement;
  3292. ExitableBlock*= OBJECT (Statement)
  3293. VAR statements-: StatementSequence;
  3294. PROCEDURE & InitExitableBlock( position: LONGINT ; outer: Statement);
  3295. BEGIN
  3296. InitStatement( position ,outer); statements := NIL;
  3297. END InitExitableBlock;
  3298. PROCEDURE SetStatements*( statements: StatementSequence );
  3299. BEGIN SELF.statements := statements;
  3300. END SetStatements;
  3301. PROCEDURE Clone(): Statement;
  3302. VAR copy: ExitableBlock;
  3303. BEGIN
  3304. NEW(copy, position, outer);
  3305. copy.SetStatements(CloneStatementSequence(statements));
  3306. RETURN copy
  3307. END Clone;
  3308. PROCEDURE Accept*(v: Visitor);
  3309. VAR position: LONGINT;
  3310. BEGIN position := SELF.position; v.VisitExitableBlock(SELF)
  3311. END Accept;
  3312. END ExitableBlock;
  3313. (** << LOOP statements END >> **)
  3314. LoopStatement* = OBJECT (ExitableBlock)
  3315. PROCEDURE Clone(): Statement;
  3316. VAR copy: LoopStatement;
  3317. BEGIN
  3318. NEW(copy, position, outer);
  3319. copy.SetStatements(CloneStatementSequence(statements));
  3320. RETURN copy
  3321. END Clone;
  3322. PROCEDURE Accept*(v: Visitor);
  3323. VAR position: LONGINT;
  3324. BEGIN position := SELF.position; v.VisitLoopStatement(SELF)
  3325. END Accept;
  3326. END LoopStatement;
  3327. (** << EXIT >> **)
  3328. ExitStatement* = OBJECT (Statement)
  3329. PROCEDURE Accept*(v: Visitor);
  3330. VAR position: LONGINT;
  3331. BEGIN position := SELF.position; v.VisitExitStatement(SELF)
  3332. END Accept;
  3333. PROCEDURE Clone(): Statement;
  3334. VAR copy: ExitStatement;
  3335. BEGIN
  3336. NEW(copy, position, outer);
  3337. RETURN copy
  3338. END Clone;
  3339. END ExitStatement;
  3340. (** << RETURN returnValue >> **)
  3341. ReturnStatement* = OBJECT (Statement)
  3342. VAR returnValue-: Expression; (* strictly speaking this is not a value but this term is in common use here *)
  3343. PROCEDURE & InitReturnStatement( position: LONGINT ; outer: Statement);
  3344. BEGIN
  3345. InitStatement( position,outer ); returnValue := NIL
  3346. END InitReturnStatement;
  3347. PROCEDURE SetReturnValue*( returnValue: Expression );
  3348. BEGIN SELF.returnValue := returnValue
  3349. END SetReturnValue;
  3350. PROCEDURE Clone(): Statement;
  3351. VAR copy: ReturnStatement;
  3352. BEGIN
  3353. NEW(copy, position, outer);
  3354. copy.SetReturnValue(CloneExpression(returnValue));
  3355. RETURN copy
  3356. END Clone;
  3357. PROCEDURE Accept*(v: Visitor);
  3358. VAR position: LONGINT;
  3359. BEGIN position := SELF.position; v.VisitReturnStatement(SELF)
  3360. END Accept;
  3361. END ReturnStatement;
  3362. (** << AWAIT condition >> **)
  3363. AwaitStatement* = OBJECT (Statement)
  3364. VAR condition-: Expression;
  3365. PROCEDURE & InitAwaitStatement( position: LONGINT; outer: Statement );
  3366. BEGIN
  3367. InitStatement( position,outer ); condition := NIL
  3368. END InitAwaitStatement;
  3369. PROCEDURE SetCondition*( condition: Expression );
  3370. BEGIN SELF.condition := condition
  3371. END SetCondition;
  3372. PROCEDURE Clone(): Statement;
  3373. VAR copy: AwaitStatement;
  3374. BEGIN
  3375. NEW(copy, position, outer);
  3376. copy.SetCondition(CloneExpression(condition));
  3377. RETURN copy
  3378. END Clone;
  3379. PROCEDURE Accept*(v: Visitor);
  3380. VAR position: LONGINT;
  3381. BEGIN position := SELF.position; v.VisitAwaitStatement(SELF)
  3382. END Accept;
  3383. END AwaitStatement;
  3384. (* << Identifier ( Expression) >> *)
  3385. Modifier*= OBJECT
  3386. VAR
  3387. identifier-: Identifier; expression-: Expression;
  3388. resolved-: BOOLEAN;
  3389. nextModifier-: Modifier;
  3390. position-: LONGINT;
  3391. PROCEDURE & InitModifier(position: LONGINT; identifier: Identifier; expression: Expression);
  3392. BEGIN
  3393. SELF.position := position;
  3394. SELF.identifier := identifier; SELF.expression := expression; nextModifier := NIL; resolved := FALSE;
  3395. END InitModifier;
  3396. PROCEDURE Resolved*;
  3397. BEGIN resolved := TRUE
  3398. END Resolved;
  3399. PROCEDURE SetExpression*(e: Expression);
  3400. BEGIN SELF.expression := e
  3401. END SetExpression;
  3402. PROCEDURE SetNext*(modifier: Modifier);
  3403. BEGIN nextModifier := modifier
  3404. END SetNext;
  3405. END Modifier;
  3406. (** << BEGIN {Modifier, Modifier ... } statements END >> **)
  3407. StatementBlock* = OBJECT (Statement)
  3408. VAR
  3409. statements-: StatementSequence;
  3410. blockModifiers-: Modifier;
  3411. isExclusive-: BOOLEAN;
  3412. isRealtime-: BOOLEAN;
  3413. isUnchecked-: BOOLEAN;
  3414. isUncooperative-: BOOLEAN;
  3415. PROCEDURE & InitStatementBlock( position: LONGINT ; outer: Statement);
  3416. BEGIN
  3417. InitStatement( position ,outer); statements := NIL; blockModifiers := NIL;
  3418. isExclusive := FALSE;
  3419. isRealtime := FALSE;
  3420. isUnchecked := FALSE;
  3421. isUncooperative := FALSE;
  3422. END InitStatementBlock;
  3423. PROCEDURE SetRealtime*(b: BOOLEAN);
  3424. BEGIN
  3425. isRealtime := b
  3426. END SetRealtime;
  3427. PROCEDURE SetUnchecked*(unchecked: BOOLEAN);
  3428. BEGIN
  3429. isUnchecked := unchecked
  3430. END SetUnchecked;
  3431. PROCEDURE SetUncooperative*(uncooperative: BOOLEAN);
  3432. BEGIN
  3433. isUncooperative := uncooperative
  3434. END SetUncooperative;
  3435. PROCEDURE SetModifier*(modifier: Modifier);
  3436. BEGIN
  3437. blockModifiers := modifier;
  3438. END SetModifier;
  3439. PROCEDURE SetExclusive*(excl: BOOLEAN);
  3440. BEGIN isExclusive := excl
  3441. END SetExclusive;
  3442. PROCEDURE SetStatementSequence*( statements: StatementSequence );
  3443. BEGIN SELF.statements := statements;
  3444. END SetStatementSequence;
  3445. PROCEDURE Accept*(v: Visitor);
  3446. VAR position: LONGINT;
  3447. BEGIN position := SELF.position; v.VisitStatementBlock(SELF)
  3448. END Accept;
  3449. END StatementBlock;
  3450. (** << CODE {flags} {character} END >> **)
  3451. Code*= OBJECT(Statement)
  3452. VAR
  3453. sourceCode-: SourceCode; sourceCodeLength-: LONGINT;
  3454. inlineCode-: BinaryCode;
  3455. inRules-, outRules-: StatementSequence;
  3456. PROCEDURE & InitCode(position: LONGINT; outer: Statement);
  3457. BEGIN
  3458. InitStatement(position,outer);
  3459. inlineCode := NIL;
  3460. sourceCode := NIL; sourceCodeLength := 0;
  3461. NEW(inRules); NEW(outRules);
  3462. END InitCode;
  3463. PROCEDURE SetSourceCode*(source: SourceCode; length: LONGINT);
  3464. BEGIN sourceCode := source; sourceCodeLength := length;
  3465. ASSERT(sourceCodeLength <= LEN(source));
  3466. END SetSourceCode;
  3467. PROCEDURE SetBinaryCode*(code: BinaryCode);
  3468. BEGIN
  3469. inlineCode := code;
  3470. END SetBinaryCode;
  3471. PROCEDURE Clone(): Statement;
  3472. VAR copy: Code; s: Scanner.StringType;
  3473. BEGIN
  3474. NEW(copy, position, outer);
  3475. NEW(s, sourceCodeLength);
  3476. Strings.Copy(sourceCode^,0,sourceCodeLength,s^);
  3477. copy.SetSourceCode(s, sourceCodeLength);
  3478. copy.inRules := CloneStatementSequence(inRules);
  3479. copy.outRules := CloneStatementSequence(outRules);
  3480. RETURN copy
  3481. END Clone;
  3482. PROCEDURE Accept*(v: Visitor);
  3483. VAR position: LONGINT;
  3484. BEGIN position := SELF.position; v.VisitCode(SELF)
  3485. END Accept;
  3486. END Code;
  3487. (** << BEGIN {flags} statements FINALLY statements END >> **)
  3488. Body*= OBJECT(StatementBlock)
  3489. VAR
  3490. finally-: StatementSequence;
  3491. priority-: Expression; (* set by checker *)
  3492. inScope-: ProcedureScope;
  3493. code-: Code;
  3494. isActive-, isSafe-: BOOLEAN;
  3495. PROCEDURE & InitBody(position: LONGINT; scope: ProcedureScope);
  3496. BEGIN
  3497. InitStatementBlock(position,NIL); finally := NIL; priority := NIL; inScope := scope; code := NIL;
  3498. isActive := FALSE; isSafe := FALSE; isRealtime := FALSE;
  3499. END InitBody;
  3500. PROCEDURE SetActive*(active: BOOLEAN);
  3501. BEGIN SELF.isActive := active
  3502. END SetActive;
  3503. PROCEDURE SetSafe*(safe: BOOLEAN);
  3504. BEGIN SELF.isSafe := safe
  3505. END SetSafe;
  3506. PROCEDURE SetFinally*( finally: StatementSequence );
  3507. BEGIN SELF.finally := finally
  3508. END SetFinally;
  3509. PROCEDURE SetPriority*(expression: Expression);
  3510. BEGIN priority := expression
  3511. END SetPriority;
  3512. PROCEDURE SetCode*(code: Code);
  3513. BEGIN SELF.code := code;
  3514. END SetCode;
  3515. END Body;
  3516. (** (* comment *) *)
  3517. Comment*=OBJECT
  3518. VAR position-: LONGINT;
  3519. source-: String; (* currently: POINTER TO ARRAY OF CHAR *)
  3520. scope-: Scope;
  3521. item-: ANY; sameLine-: BOOLEAN;
  3522. nextComment-: Comment;
  3523. PROCEDURE & InitComment(pos: LONGINT; scope: Scope; CONST s: ARRAY OF CHAR; length: LONGINT);
  3524. VAR i: LONGINT;
  3525. BEGIN
  3526. SELF.scope := scope;
  3527. NEW(source,length);
  3528. FOR i := 0 TO length-1 DO
  3529. source[i] := s[i];
  3530. END;
  3531. SELF.position := pos;
  3532. nextComment := NIL;
  3533. item := NIL; sameLine := FALSE;
  3534. END InitComment;
  3535. PROCEDURE SetItem*(p: ANY; sameLine: BOOLEAN);
  3536. BEGIN
  3537. item := p; SELF.sameLine := sameLine
  3538. END SetItem;
  3539. END Comment;
  3540. (**** building blocks ****)
  3541. Scope*=OBJECT
  3542. VAR
  3543. firstSymbol-: Symbol; numberSymbols-: LONGINT; (* all symbols in scope (sorted) *)
  3544. firstConstant-,lastConstant-: Constant; numberConstants-: LONGINT; (* constants *)
  3545. firstTypeDeclaration-,lastTypeDeclaration-: TypeDeclaration; numberTypeDeclarations-: LONGINT; (* type declarations *)
  3546. firstVariable-,lastVariable-: Variable; numberVariables-: LONGINT; (* variables *)
  3547. firstProcedure-,lastProcedure-: Procedure; numberProcedures-: LONGINT; (* procedures *)
  3548. outerScope-: Scope; nextScope-: Scope;
  3549. ownerModule-: Module;
  3550. PROCEDURE & InitScope(outer: Scope);
  3551. BEGIN
  3552. firstSymbol := NIL; numberSymbols := 0;
  3553. firstConstant := NIL; lastConstant := NIL; numberConstants := 0;
  3554. firstTypeDeclaration := NIL; lastTypeDeclaration := NIL; numberTypeDeclarations := 0;
  3555. firstVariable := NIL; lastVariable := NIL; numberVariables := 0;
  3556. firstProcedure := NIL; lastProcedure := NIL; numberProcedures := 0;
  3557. outerScope := outer;
  3558. IF outer # NIL THEN
  3559. ownerModule := outer.ownerModule
  3560. ELSE
  3561. ownerModule := NIL;
  3562. END;
  3563. nextScope := NIL;
  3564. END InitScope;
  3565. (** Enter a symbol in the scope, aplhabetically sorted, duplicate = TRUE if multiply identifier *)
  3566. PROCEDURE EnterSymbol*(symbol: Symbol; VAR duplicate: BOOLEAN);
  3567. VAR p,q: Symbol; name,nextname: Scanner.StringType;
  3568. BEGIN
  3569. ASSERT(symbol.nextSymbol = NIL,101); (* symbol may only be present in one scope at a time ! *)
  3570. ASSERT(symbol.scope = NIL,102);
  3571. ASSERT(symbol.name # invalidIdentifier,103);
  3572. p := firstSymbol; q := NIL;
  3573. WHILE (p # NIL) & (StringPool.CompareString(p.name,symbol.name)<0) DO q := p; p := p.nextSymbol END;
  3574. IF (p#NIL) & (symbol.name = p.name) THEN
  3575. duplicate := TRUE;
  3576. ELSE
  3577. duplicate := FALSE
  3578. END;
  3579. symbol.nextSymbol := p;
  3580. IF q = NIL THEN firstSymbol := symbol ELSE q.nextSymbol := symbol END;
  3581. symbol.SetScope(SELF);
  3582. INC(numberSymbols);
  3583. END EnterSymbol;
  3584. (** Find symbol by name *)
  3585. PROCEDURE FindSymbol*(identifier: Identifier): Symbol;
  3586. VAR p: Symbol;
  3587. BEGIN
  3588. IF identifier # invalidIdentifier THEN
  3589. p := firstSymbol;
  3590. WHILE(p#NIL) & ((p.name # identifier) OR (p IS Operator)) DO p := p.nextSymbol END;
  3591. END;
  3592. RETURN p;
  3593. END FindSymbol;
  3594. PROCEDURE AddConstant*(c: Constant);
  3595. BEGIN
  3596. ASSERT(c # NIL);
  3597. IF lastConstant= NIL THEN firstConstant := c ELSE lastConstant.nextConstant := c END;
  3598. lastConstant := c;
  3599. INC(numberConstants);
  3600. END AddConstant;
  3601. PROCEDURE FindConstant*(identifier: Identifier): Constant;
  3602. VAR p: Constant;
  3603. BEGIN
  3604. p := firstConstant;
  3605. WHILE(p#NIL) & (p.name # identifier) DO p := p.nextConstant END;
  3606. RETURN p;
  3607. END FindConstant;
  3608. PROCEDURE AddTypeDeclaration*(t: TypeDeclaration);
  3609. BEGIN
  3610. ASSERT(t # NIL);
  3611. IF lastTypeDeclaration= NIL THEN firstTypeDeclaration := t ELSE lastTypeDeclaration.nextTypeDeclaration := t END;
  3612. INC(numberTypeDeclarations);
  3613. lastTypeDeclaration := t;
  3614. END AddTypeDeclaration;
  3615. PROCEDURE FindTypeDeclaration*(identifier: Identifier): TypeDeclaration;
  3616. VAR p: TypeDeclaration;
  3617. BEGIN
  3618. p := firstTypeDeclaration;
  3619. WHILE(p#NIL) & (p.name # identifier) DO p := p.nextTypeDeclaration END;
  3620. RETURN p;
  3621. END FindTypeDeclaration;
  3622. PROCEDURE AddVariable*(v: Variable);
  3623. BEGIN
  3624. ASSERT(v # NIL);
  3625. IF lastVariable= NIL THEN firstVariable := v ELSE lastVariable.nextVariable := v END;
  3626. INC(numberVariables);
  3627. lastVariable := v;
  3628. END AddVariable;
  3629. PROCEDURE PushVariable*(v: Variable);
  3630. BEGIN
  3631. ASSERT(v # NIL);
  3632. IF lastVariable= NIL THEN lastVariable := v ELSE v.nextVariable := firstVariable END;
  3633. INC(numberVariables);
  3634. firstVariable := v;
  3635. END PushVariable;
  3636. PROCEDURE FindVariable*(identifier: Identifier): Variable;
  3637. VAR p: Variable;
  3638. BEGIN
  3639. p := firstVariable;
  3640. WHILE(p#NIL) & (p.name # identifier) DO p := p.nextVariable END;
  3641. RETURN p;
  3642. END FindVariable;
  3643. PROCEDURE AddProcedure*(p: Procedure);
  3644. BEGIN
  3645. ASSERT(p # NIL);
  3646. IF lastProcedure= NIL THEN firstProcedure := p ELSE lastProcedure.nextProcedure := p END;
  3647. INC(numberProcedures);
  3648. lastProcedure := p;
  3649. END AddProcedure;
  3650. PROCEDURE FindProcedure*(identifier: Identifier): Procedure;
  3651. VAR p: Procedure;
  3652. BEGIN
  3653. p := firstProcedure;
  3654. WHILE (p#NIL) & ((p.name # identifier) OR (p IS Operator)) DO p := p.nextProcedure END;
  3655. RETURN p;
  3656. END FindProcedure;
  3657. PROCEDURE FindMethod*(number: LONGINT): Procedure;
  3658. VAR p: Procedure;
  3659. BEGIN
  3660. p := firstProcedure;
  3661. WHILE (p# NIL) & (p.methodNumber # number) DO
  3662. p := p.nextProcedure
  3663. END;
  3664. RETURN p;
  3665. END FindMethod;
  3666. PROCEDURE Level*(): LONGINT;
  3667. VAR scope: Scope; level: LONGINT;
  3668. BEGIN
  3669. level := 0;
  3670. scope := SELF;
  3671. WHILE(scope.outerScope # NIL) DO
  3672. scope := scope.outerScope;
  3673. INC(level);
  3674. END;
  3675. RETURN level;
  3676. END Level;
  3677. PROCEDURE NeedsTrace* (): BOOLEAN;
  3678. VAR variable: Variable;
  3679. BEGIN
  3680. variable := firstVariable;
  3681. WHILE variable # NIL DO
  3682. IF variable.NeedsTrace () THEN RETURN TRUE END;
  3683. variable := variable.nextVariable;
  3684. END;
  3685. RETURN FALSE;
  3686. END NeedsTrace;
  3687. END Scope;
  3688. ProcedureScope*=OBJECT (Scope)
  3689. VAR
  3690. ownerProcedure-: Procedure;
  3691. body-: Body;
  3692. PROCEDURE & InitProcedureScope(outer: Scope);
  3693. BEGIN
  3694. InitScope(outer);
  3695. ownerProcedure := NIL;
  3696. body := NIL;
  3697. END InitProcedureScope;
  3698. PROCEDURE SetBody*(body: Body);
  3699. BEGIN
  3700. SELF.body := body;
  3701. END SetBody;
  3702. PROCEDURE NeedsTrace* (): BOOLEAN;
  3703. VAR parameter: Parameter;
  3704. BEGIN
  3705. parameter := ownerProcedure.type.resolved(ProcedureType).firstParameter;
  3706. WHILE parameter # NIL DO
  3707. IF parameter.NeedsTrace () THEN RETURN TRUE END;
  3708. parameter := parameter.nextParameter;
  3709. END;
  3710. RETURN NeedsTrace^();
  3711. END NeedsTrace;
  3712. END ProcedureScope;
  3713. EnumerationScope*= OBJECT(Scope)
  3714. VAR
  3715. ownerEnumeration-: EnumerationType;
  3716. (** Find symbol by name *)
  3717. PROCEDURE FindSymbol*(identifier: Identifier): Symbol;
  3718. VAR p: Symbol; base: Type;
  3719. BEGIN
  3720. p := FindSymbol^(identifier);
  3721. IF p = NIL THEN
  3722. base := ownerEnumeration.enumerationBase;
  3723. IF (base # NIL) & (base.resolved IS EnumerationType) THEN
  3724. p := base.resolved(EnumerationType).enumerationScope.FindSymbol(identifier)
  3725. END;
  3726. END;
  3727. RETURN p;
  3728. END FindSymbol;
  3729. PROCEDURE &InitEnumerationScope(outer: Scope);
  3730. BEGIN
  3731. InitScope(outer);
  3732. ownerEnumeration := NIL; (* must be set by EnumerationType *)
  3733. END InitEnumerationScope;
  3734. END EnumerationScope;
  3735. RecordScope*= OBJECT(Scope)
  3736. VAR
  3737. ownerRecord-: RecordType;
  3738. bodyProcedure-: Procedure;
  3739. constructor-: Procedure;
  3740. finalizer-: Procedure;
  3741. numberMethods-: LONGINT;
  3742. firstParameter-,lastParameter-: Parameter; numberParameters-: LONGINT; (* parameters for Active Cells programming*)
  3743. firstOperator-, lastOperator-: Operator; numberOperators: LONGINT; (* defined operators *)
  3744. PROCEDURE & InitRecordScope(outer: Scope);
  3745. BEGIN
  3746. InitScope(outer);
  3747. ownerRecord := NIL;
  3748. numberMethods := 0;
  3749. bodyProcedure := NIL;
  3750. constructor := NIL;
  3751. finalizer := NIL;
  3752. firstOperator := NIL; lastOperator := NIL; numberOperators := 0;
  3753. END InitRecordScope;
  3754. PROCEDURE SetBodyProcedure*(body: Procedure);
  3755. BEGIN SELF.bodyProcedure := body;
  3756. END SetBodyProcedure;
  3757. PROCEDURE SetConstructor*(body: Procedure);
  3758. BEGIN SELF.constructor := body
  3759. END SetConstructor;
  3760. PROCEDURE SetFinalizer*(body: Procedure);
  3761. BEGIN SELF.finalizer := body
  3762. END SetFinalizer;
  3763. PROCEDURE SetNumberMethods*(numberMethods: LONGINT);
  3764. BEGIN SELF.numberMethods := numberMethods;
  3765. END SetNumberMethods;
  3766. PROCEDURE AddOperator*(p: Operator);
  3767. BEGIN
  3768. ASSERT(p # NIL);
  3769. IF lastOperator= NIL THEN firstOperator := p ELSE lastOperator.nextOperator := p END;
  3770. INC(numberOperators);
  3771. lastOperator := p;
  3772. END AddOperator;
  3773. (** Find symbol by name *)
  3774. PROCEDURE FindSymbol*(identifier: Identifier): Symbol;
  3775. VAR p: Symbol; base: RecordType;
  3776. BEGIN
  3777. p := FindSymbol^(identifier);
  3778. IF p = NIL THEN
  3779. base := ownerRecord.GetBaseRecord();
  3780. IF (base # NIL) THEN
  3781. p := base.recordScope.FindSymbol(identifier)
  3782. END;
  3783. END;
  3784. RETURN p;
  3785. END FindSymbol;
  3786. PROCEDURE FindConstant*(identifier: Identifier): Constant;
  3787. VAR p: Constant; base: RecordType;
  3788. BEGIN
  3789. p := FindConstant^(identifier);
  3790. IF p = NIL THEN
  3791. base := ownerRecord.GetBaseRecord();
  3792. IF (base # NIL) THEN
  3793. p := base.recordScope.FindConstant(identifier)
  3794. END;
  3795. END;
  3796. RETURN p;
  3797. END FindConstant;
  3798. PROCEDURE FindTypeDeclaration*(identifier: Identifier): TypeDeclaration;
  3799. VAR p: TypeDeclaration; base: RecordType;
  3800. BEGIN
  3801. p := FindTypeDeclaration^(identifier);
  3802. IF p = NIL THEN
  3803. base := ownerRecord.GetBaseRecord();
  3804. IF (base # NIL) THEN
  3805. p := base.recordScope.FindTypeDeclaration(identifier)
  3806. END;
  3807. END;
  3808. RETURN p;
  3809. END FindTypeDeclaration;
  3810. PROCEDURE FindVariable*(identifier: Identifier): Variable;
  3811. VAR p: Variable; base: RecordType;
  3812. BEGIN
  3813. p := FindVariable^(identifier);
  3814. IF p = NIL THEN
  3815. base := ownerRecord.GetBaseRecord();
  3816. IF (base # NIL) THEN
  3817. p := base.recordScope.FindVariable(identifier)
  3818. END;
  3819. END;
  3820. RETURN p;
  3821. END FindVariable;
  3822. PROCEDURE FindProcedure*(identifier: Identifier): Procedure;
  3823. VAR p: Procedure; base: RecordType;
  3824. BEGIN
  3825. p := FindProcedure^(identifier);
  3826. IF p = NIL THEN
  3827. base := ownerRecord.GetBaseRecord();
  3828. IF (base # NIL) THEN
  3829. p := base.recordScope.FindProcedure(identifier)
  3830. END;
  3831. END;
  3832. RETURN p;
  3833. END FindProcedure;
  3834. PROCEDURE FindMethod*(number: LONGINT): Procedure;
  3835. VAR p: Procedure; base: RecordType;
  3836. BEGIN
  3837. p := FindMethod^(number);
  3838. IF p = NIL THEN
  3839. base := ownerRecord.GetBaseRecord();
  3840. IF (base # NIL) THEN
  3841. p := base.recordScope.FindMethod(number)
  3842. END;
  3843. END;
  3844. RETURN p;
  3845. END FindMethod;
  3846. PROCEDURE NeedsTrace* (): BOOLEAN;
  3847. VAR base: RecordType;
  3848. BEGIN
  3849. base := ownerRecord.GetBaseRecord();
  3850. IF (base # NIL) & (base.NeedsTrace ()) THEN RETURN TRUE END;
  3851. RETURN NeedsTrace^();
  3852. END NeedsTrace;
  3853. END RecordScope;
  3854. CellScope*=OBJECT (Scope)
  3855. VAR
  3856. ownerCell-: CellType;
  3857. bodyProcedure-: Procedure;
  3858. constructor-: Procedure;
  3859. PROCEDURE & InitCellScope(outer: Scope);
  3860. BEGIN
  3861. InitScope(outer);
  3862. ownerCell := NIL;
  3863. bodyProcedure := NIL;
  3864. constructor := NIL;
  3865. END InitCellScope;
  3866. PROCEDURE SetOwnerCell*(owner: CellType);
  3867. BEGIN
  3868. ownerCell := owner
  3869. END SetOwnerCell;
  3870. PROCEDURE SetBodyProcedure*(bodyProcedure: Procedure);
  3871. BEGIN
  3872. SELF.bodyProcedure := bodyProcedure;
  3873. END SetBodyProcedure;
  3874. PROCEDURE SetConstructor*(p: Procedure);
  3875. BEGIN constructor := p
  3876. END SetConstructor;
  3877. PROCEDURE FindSymbol*(identifier: Identifier): Symbol;
  3878. VAR p: Symbol; base: Type;
  3879. BEGIN
  3880. p := FindSymbol^(identifier);
  3881. IF p = NIL THEN
  3882. IF ownerCell.isCellNet THEN
  3883. RETURN ownerCell.FindProperty(identifier);
  3884. END;
  3885. END;
  3886. IF p = NIL THEN
  3887. base := ownerCell.baseType;
  3888. IF (base # NIL) THEN
  3889. base := base.resolved;
  3890. IF base IS PointerType THEN
  3891. base := base(PointerType).pointerBase.resolved;
  3892. END;
  3893. WITH base: CellType DO
  3894. p := base.cellScope.FindSymbol(identifier)
  3895. |base: RecordType DO
  3896. p := base.recordScope.FindSymbol(identifier)
  3897. END;
  3898. END;
  3899. END;
  3900. RETURN p;
  3901. END FindSymbol;
  3902. END CellScope;
  3903. (**
  3904. <<
  3905. IMPORT firstImport .. lastImport;
  3906. ...
  3907. firstOperator ... lastOperator
  3908. ....
  3909. >>
  3910. **)
  3911. ModuleScope*= OBJECT(Scope)
  3912. VAR
  3913. firstImport-,lastImport-: Import; numberImports: LONGINT; (* imported modules *)
  3914. firstOperator-,lastOperator-: Operator; numberOperators: LONGINT; (* defined operators *)
  3915. firstBuiltin-,lastBuiltin-: Builtin; numberBuiltins: LONGINT; (* defined builtins, only for global and system module *)
  3916. firstComment-,lastComment-: Comment; numberComments-: LONGINT; (* comments *)
  3917. bodyProcedure-: Procedure;
  3918. PROCEDURE & InitModuleScope;
  3919. BEGIN
  3920. InitScope(NIL);
  3921. firstComment := NIL; lastComment := NIL; numberComments := 0;
  3922. firstImport:= NIL; lastImport := NIL; numberImports := 0;
  3923. firstOperator := NIL; lastOperator := NIL; numberOperators := 0;
  3924. END InitModuleScope;
  3925. PROCEDURE SetBodyProcedure*(body: Procedure);
  3926. BEGIN SELF.bodyProcedure := body;
  3927. END SetBodyProcedure;
  3928. PROCEDURE SetGlobalScope*(outer: Scope);
  3929. BEGIN
  3930. SELF.outerScope := outer;
  3931. END SetGlobalScope;
  3932. PROCEDURE AddBuiltin*(p: Builtin);
  3933. BEGIN
  3934. ASSERT(p # NIL);
  3935. IF lastBuiltin= NIL THEN firstBuiltin := p ELSE lastBuiltin.nextBuiltin := p END;
  3936. INC(numberBuiltins);
  3937. lastBuiltin := p;
  3938. END AddBuiltin;
  3939. PROCEDURE AddOperator*(p: Operator);
  3940. BEGIN
  3941. ASSERT(p # NIL);
  3942. IF lastOperator= NIL THEN firstOperator := p ELSE lastOperator.nextOperator := p END;
  3943. INC(numberOperators);
  3944. lastOperator := p;
  3945. END AddOperator;
  3946. PROCEDURE FindOperator*(identifier: Identifier): Operator;
  3947. VAR p: Operator;
  3948. BEGIN
  3949. p := firstOperator;
  3950. WHILE(p#NIL) & (p.name # identifier) DO p := p.nextOperator END;
  3951. RETURN p;
  3952. END FindOperator;
  3953. PROCEDURE AddImport*(i: Import);
  3954. BEGIN
  3955. ASSERT(i # NIL);
  3956. ASSERT(i.nextImport = NIL);
  3957. IF lastImport= NIL THEN firstImport:= i ELSE lastImport.nextImport := i END;
  3958. lastImport := i;
  3959. INC(numberImports);
  3960. END AddImport;
  3961. PROCEDURE FindImport*(identifier: Identifier): Import;
  3962. VAR p: Import;
  3963. BEGIN
  3964. p := firstImport;
  3965. WHILE(p#NIL) & (p.name # identifier) DO p := p.nextImport END; (* finds imports and re-imports! *)
  3966. RETURN p;
  3967. END FindImport;
  3968. PROCEDURE GetImport*( index: LONGINT ): Import;
  3969. VAR import: Import;
  3970. BEGIN
  3971. import := firstImport;
  3972. WHILE(import # NIL) & (index > 0) DO
  3973. import := import.nextImport;
  3974. DEC(index);
  3975. END;
  3976. RETURN import;
  3977. END GetImport;
  3978. PROCEDURE AddComment*(comment: Comment);
  3979. BEGIN
  3980. ASSERT(comment # NIL);
  3981. IF lastComment= NIL THEN firstComment := comment ELSE lastComment.nextComment := comment END;
  3982. INC(numberComments);
  3983. lastComment := comment;
  3984. END AddComment;
  3985. PROCEDURE ImportByModuleName*(moduleName,context: Identifier): Import;
  3986. VAR p: Import;
  3987. BEGIN
  3988. p := firstImport;
  3989. WHILE(p#NIL) & ~((moduleName = p.moduleName) & (context = p.context)) DO p := p.nextImport END;
  3990. RETURN p;
  3991. END ImportByModuleName;
  3992. PROCEDURE RemoveImporters*(moduleName,context: Identifier);
  3993. VAR this: Import;
  3994. PROCEDURE Check(p: Import): BOOLEAN;
  3995. VAR result: BOOLEAN;
  3996. BEGIN
  3997. IF (moduleName = p.moduleName) & (context = p.context) THEN
  3998. result := TRUE
  3999. ELSE
  4000. result := p.module.moduleScope.ImportByModuleName(moduleName,context) # NIL;
  4001. END;
  4002. RETURN result
  4003. END Check;
  4004. BEGIN
  4005. WHILE(firstImport # NIL) & Check(firstImport) DO
  4006. firstImport := firstImport.nextImport;
  4007. DEC(numberImports);
  4008. END;
  4009. IF firstImport = NIL THEN lastImport := NIL
  4010. ELSE
  4011. this :=firstImport;
  4012. WHILE(this.nextImport # NIL) DO
  4013. IF Check(this.nextImport) THEN
  4014. this.nextImport := this.nextImport.nextImport;
  4015. DEC(numberImports);
  4016. ELSE
  4017. this := this.nextImport
  4018. END;
  4019. END;
  4020. lastImport := this;
  4021. END;
  4022. END RemoveImporters;
  4023. END ModuleScope;
  4024. (* << MODULE name ['in' context] moduleScope name '.' >> *)
  4025. Module* = OBJECT (Symbol)
  4026. VAR
  4027. sourceName-: Basic.FileName;
  4028. moduleScope-: ModuleScope;
  4029. context-:Identifier; (* modules context *)
  4030. case-: LONGINT; (* module notation in lower or upper case, important for printout and operators *)
  4031. isCellNet-: BOOLEAN;
  4032. firstScope-,lastScope-: Scope; numberScopes-: LONGINT; (* list of all scopes for checker / backend traversal etc. *)
  4033. closingComment-: Comment;
  4034. modifiers-: Modifier;
  4035. PROCEDURE & InitModule( CONST sourceName: ARRAY OF CHAR; position: LONGINT; name: Identifier; scope: ModuleScope; case: LONGINT);
  4036. BEGIN
  4037. InitSymbol(position,name);
  4038. COPY (sourceName, SELF.sourceName);
  4039. moduleScope := scope;
  4040. ASSERT(scope.ownerModule = NIL); (* cannot register twice ! *)
  4041. scope.ownerModule := SELF;
  4042. context := invalidIdentifier;
  4043. SELF.case := case;
  4044. firstScope := NIL; lastScope := NIL; numberScopes := 0;
  4045. SetType(moduleType);
  4046. closingComment := NIL;
  4047. isCellNet := FALSE;
  4048. modifiers := NIL;
  4049. END InitModule;
  4050. PROCEDURE SetCase*(case: LONGINT);
  4051. BEGIN
  4052. SELF.case := case
  4053. END SetCase;
  4054. PROCEDURE SetCellNet*(isCellNet: BOOLEAN);
  4055. BEGIN SELF.isCellNet := isCellNet
  4056. END SetCellNet;
  4057. PROCEDURE SetContext*(context: Identifier);
  4058. BEGIN SELF.context := context;
  4059. END SetContext;
  4060. PROCEDURE SetName*(name: Identifier);
  4061. BEGIN SELF.name := name
  4062. END SetName;
  4063. PROCEDURE SetClosingComment*(comment: Comment);
  4064. BEGIN SELF.closingComment := comment
  4065. END SetClosingComment;
  4066. PROCEDURE SetModifiers*(modifiers: Modifier);
  4067. BEGIN SELF.modifiers := modifiers
  4068. END SetModifiers;
  4069. PROCEDURE AddScope*(c: Scope);
  4070. BEGIN
  4071. IF lastScope= NIL THEN firstScope := c ELSE lastScope.nextScope := c END;
  4072. lastScope := c;
  4073. INC(numberScopes);
  4074. END AddScope;
  4075. PROCEDURE Accept*(v: Visitor);
  4076. VAR position: LONGINT;
  4077. BEGIN position := SELF.position; v.VisitModule(SELF)
  4078. END Accept;
  4079. END Module;
  4080. (** <<expression, expression, ...>> **)
  4081. SymbolList* = OBJECT
  4082. VAR list: Basic.List;
  4083. PROCEDURE & InitList*;
  4084. BEGIN NEW( list,8 );
  4085. END InitList;
  4086. PROCEDURE Length*( ): LONGINT;
  4087. BEGIN RETURN list.Length();
  4088. END Length;
  4089. PROCEDURE AddSymbol*( d: Symbol );
  4090. BEGIN list.Add(d)
  4091. END AddSymbol;
  4092. PROCEDURE GetSymbol*( index: LONGINT ): Symbol;
  4093. VAR p: ANY;
  4094. BEGIN
  4095. p := list.Get(index); RETURN p(Symbol);
  4096. END GetSymbol;
  4097. PROCEDURE SetSymbol*(index: LONGINT; expression: Symbol);
  4098. BEGIN list.Set(index,expression)
  4099. END SetSymbol;
  4100. PROCEDURE RemoveSymbol*(i: LONGINT);
  4101. BEGIN list.RemoveByIndex(i);
  4102. END RemoveSymbol;
  4103. (*
  4104. PROCEDURE Clone*(VAR list: SymbolList);
  4105. VAR i: LONGINT;
  4106. BEGIN
  4107. IF list = NIL THEN NEW(list) END;
  4108. FOR i := 0 TO Length()-1 DO
  4109. list.AddSymbol(CloneSymbol(GetSymbol(i)));
  4110. END;
  4111. END Clone;
  4112. *)
  4113. END SymbolList;
  4114. VAR
  4115. (* invalid items used, for example, by parser and checker *)
  4116. invalidIdentifier-: Identifier;
  4117. invalidQualifiedIdentifier-: QualifiedIdentifier;
  4118. invalidType-: Type;
  4119. invalidExpression-: Expression; (* mapped to invalidDesignator for better error handling in checker *)
  4120. invalidDesignator-: Designator;
  4121. invalidValue-: Value;
  4122. invalidSymbol-: Symbol;
  4123. anonymousIdentifier-: Identifier;
  4124. importType-: Type;
  4125. typeDeclarationType-: Type;
  4126. moduleType-: Type;
  4127. indexListSeparator-: Expression;
  4128. PROCEDURE InitFingerPrint*(VAR fingerprint: FingerPrint);
  4129. BEGIN
  4130. fingerprint.shallowAvailable := FALSE;
  4131. fingerprint.deepAvailable := FALSE;
  4132. fingerprint.shallow := 0;
  4133. fingerprint.private := 0;
  4134. fingerprint.public := 0;
  4135. END InitFingerPrint;
  4136. PROCEDURE NewModule*( CONST sourceName: ARRAY OF CHAR; position: LONGINT; name: Identifier;scope: ModuleScope; case: LONGINT ): Module;
  4137. VAR module: Module;
  4138. BEGIN
  4139. NEW( module, sourceName, position, name, scope, case); RETURN module;
  4140. END NewModule;
  4141. PROCEDURE NewComment*(position: LONGINT; scope: Scope; CONST source: ARRAY OF CHAR; length: LONGINT): Comment;
  4142. VAR comment: Comment;
  4143. BEGIN
  4144. NEW(comment,position,scope,source,length); RETURN comment;
  4145. END NewComment;
  4146. PROCEDURE NewImport*( position: LONGINT; alias, name: Identifier; direct: BOOLEAN): Import;
  4147. VAR import: Import;
  4148. BEGIN
  4149. NEW( import, position, alias, name, direct ); RETURN import
  4150. END NewImport;
  4151. PROCEDURE NewConstant*( position: LONGINT; name: Identifier ): Constant;
  4152. VAR constant: Constant;
  4153. BEGIN
  4154. NEW( constant, position, name ); RETURN constant
  4155. END NewConstant;
  4156. PROCEDURE NewProcedure*( position: LONGINT; name: Identifier; scope: ProcedureScope ): Procedure;
  4157. VAR procedure: Procedure;
  4158. BEGIN
  4159. NEW( procedure, position, name, scope); RETURN procedure
  4160. END NewProcedure;
  4161. PROCEDURE NewBuiltin*(position: LONGINT; name: Identifier; id: LONGINT): Builtin;
  4162. VAR builtin: Builtin;
  4163. BEGIN
  4164. NEW(builtin,position,name,id); RETURN builtin
  4165. END NewBuiltin;
  4166. PROCEDURE NewCustomBuiltin*(position: LONGINT; name: Identifier; id: LONGINT; subType: SHORTINT): CustomBuiltin;
  4167. VAR builtin:CustomBuiltin;
  4168. BEGIN
  4169. NEW(builtin,position,name,id,subType); RETURN builtin
  4170. END NewCustomBuiltin;
  4171. PROCEDURE NewOperator*( position: LONGINT; name: Identifier; scope: ProcedureScope): Operator;
  4172. VAR operator: Operator;
  4173. BEGIN
  4174. NEW( operator, position, name, scope); RETURN operator
  4175. END NewOperator;
  4176. PROCEDURE NewType*(): Type; (* for error handling: invalid Type, is realtime type *)
  4177. VAR type: Type;
  4178. BEGIN
  4179. NEW( type, -1);
  4180. type.SetRealtime(TRUE);
  4181. RETURN type
  4182. END NewType;
  4183. PROCEDURE NewByteType*(sizeInBits: LONGINT): ByteType;
  4184. VAR basicType: ByteType;
  4185. BEGIN
  4186. NEW(basicType, sizeInBits); RETURN basicType;
  4187. END NewByteType;
  4188. PROCEDURE NewAnyType*(sizeInBits: LONGINT): AnyType;
  4189. VAR basicType: AnyType;
  4190. BEGIN
  4191. NEW(basicType, sizeInBits); RETURN basicType;
  4192. END NewAnyType;
  4193. PROCEDURE NewObjectType*(sizeInBits: LONGINT): ObjectType;
  4194. VAR basicType: ObjectType;
  4195. BEGIN
  4196. NEW(basicType, sizeInBits); RETURN basicType;
  4197. END NewObjectType;
  4198. PROCEDURE NewNilType*(sizeInBits: LONGINT): NilType;
  4199. VAR basicType: NilType;
  4200. BEGIN
  4201. NEW(basicType, sizeInBits); RETURN basicType;
  4202. END NewNilType;
  4203. PROCEDURE NewAddressType*(sizeInBits: LONGINT): AddressType;
  4204. VAR basicType: AddressType;
  4205. BEGIN
  4206. NEW(basicType, sizeInBits); RETURN basicType;
  4207. END NewAddressType;
  4208. PROCEDURE NewSizeType*(sizeInBits: LONGINT): SizeType;
  4209. VAR basicType: SizeType;
  4210. BEGIN
  4211. NEW(basicType, sizeInBits); RETURN basicType;
  4212. END NewSizeType;
  4213. PROCEDURE NewBooleanType*(sizeInBits: LONGINT): BooleanType;
  4214. VAR basicType: BooleanType;
  4215. BEGIN
  4216. NEW(basicType, sizeInBits); RETURN basicType;
  4217. END NewBooleanType;
  4218. PROCEDURE NewSetType*(sizeInBits: LONGINT): SetType;
  4219. VAR basicType: SetType;
  4220. BEGIN
  4221. NEW(basicType, sizeInBits); RETURN basicType;
  4222. END NewSetType;
  4223. PROCEDURE NewCharacterType*(sizeInBits: LONGINT): CharacterType;
  4224. VAR basicType: CharacterType;
  4225. BEGIN
  4226. NEW(basicType, sizeInBits); RETURN basicType;
  4227. END NewCharacterType;
  4228. PROCEDURE NewRangeType*(sizeInBits: LONGINT): RangeType;
  4229. VAR basicType: RangeType;
  4230. BEGIN
  4231. NEW(basicType, sizeInBits); RETURN basicType;
  4232. END NewRangeType;
  4233. PROCEDURE NewComplexType*(base: Type): ComplexType;
  4234. VAR basicType: ComplexType;
  4235. BEGIN
  4236. NEW(basicType, base); RETURN basicType;
  4237. END NewComplexType;
  4238. PROCEDURE NewIntegerType*(size: LONGINT; signed: BOOLEAN): IntegerType;
  4239. VAR basicType: IntegerType;
  4240. BEGIN
  4241. NEW(basicType, size, signed); RETURN basicType;
  4242. END NewIntegerType;
  4243. PROCEDURE NewFloatType*(sizeInBits: LONGINT): FloatType;
  4244. VAR basicType: FloatType;
  4245. BEGIN
  4246. NEW(basicType, sizeInBits); RETURN basicType;
  4247. END NewFloatType;
  4248. PROCEDURE NewTypeDeclaration*(position: LONGINT; name: Identifier): TypeDeclaration;
  4249. VAR typeDeclaration: TypeDeclaration;
  4250. BEGIN
  4251. ASSERT(name # invalidIdentifier);
  4252. NEW(typeDeclaration,position,name); RETURN typeDeclaration
  4253. END NewTypeDeclaration;
  4254. PROCEDURE NewStringType*( position: LONGINT; baseType: Type; length: LONGINT): StringType;
  4255. VAR stringType: StringType;
  4256. BEGIN
  4257. NEW( stringType, position, baseType, length); RETURN stringType;
  4258. END NewStringType;
  4259. PROCEDURE NewEnumerationType*( position: LONGINT; scope: Scope; enumerationScope: EnumerationScope): EnumerationType;
  4260. VAR enumerationType: EnumerationType;
  4261. BEGIN
  4262. NEW( enumerationType, position, scope, enumerationScope); RETURN enumerationType;
  4263. END NewEnumerationType;
  4264. PROCEDURE NewArrayType*( position: LONGINT; scope: Scope; form: LONGINT): ArrayType;
  4265. VAR arrayType: ArrayType;
  4266. BEGIN
  4267. NEW( arrayType, position,scope, form); RETURN arrayType;
  4268. END NewArrayType;
  4269. PROCEDURE NewMathArrayType*( position: LONGINT; scope: Scope; form: LONGINT): MathArrayType;
  4270. VAR mathArrayType: MathArrayType;
  4271. BEGIN
  4272. NEW( mathArrayType, position,scope,form); RETURN mathArrayType;
  4273. END NewMathArrayType;
  4274. PROCEDURE NewPointerType*( position: LONGINT; scope: Scope): PointerType;
  4275. VAR pointerType: PointerType;
  4276. BEGIN
  4277. NEW( pointerType, position,scope); RETURN pointerType;
  4278. END NewPointerType;
  4279. PROCEDURE NewPortType*( position: LONGINT; direction: LONGINT; sizeExpression: Expression; scope: Scope): PortType;
  4280. VAR portType: PortType;
  4281. BEGIN
  4282. NEW( portType, position, direction, sizeExpression, scope); RETURN portType;
  4283. END NewPortType;
  4284. PROCEDURE NewRecordType*( position: LONGINT; scope: Scope; recordScope: RecordScope): RecordType;
  4285. VAR recordType: RecordType;
  4286. BEGIN
  4287. NEW( recordType, position, scope, recordScope); RETURN recordType
  4288. END NewRecordType;
  4289. PROCEDURE NewCellType*(position: LONGINT; scope:Scope; cellScope: CellScope): CellType;
  4290. VAR actorType: CellType;
  4291. BEGIN
  4292. NEW(actorType, position, scope, cellScope); RETURN actorType;
  4293. END NewCellType;
  4294. PROCEDURE NewProcedureType*( position: LONGINT; scope: Scope): ProcedureType;
  4295. VAR procedureType: ProcedureType;
  4296. BEGIN
  4297. NEW( procedureType, position,scope); RETURN procedureType;
  4298. END NewProcedureType;
  4299. PROCEDURE NewQualifiedType*( position: LONGINT; scope: Scope; qualifiedIdentifier: QualifiedIdentifier): QualifiedType;
  4300. VAR qualifiedType: QualifiedType;
  4301. BEGIN
  4302. NEW( qualifiedType, position,scope,qualifiedIdentifier ); RETURN qualifiedType
  4303. END NewQualifiedType;
  4304. PROCEDURE NewSymbol*(name: Identifier): Symbol; (* for error handling: invalid Symbol *)
  4305. VAR symbol: Symbol;
  4306. BEGIN
  4307. NEW(symbol,-1,name); RETURN symbol
  4308. END NewSymbol;
  4309. PROCEDURE NewVariable*( position: LONGINT; name: Identifier): Variable;
  4310. VAR variable: Variable;
  4311. BEGIN
  4312. NEW( variable, position, name ); RETURN variable
  4313. END NewVariable;
  4314. PROCEDURE NewQualifiedIdentifier*( position: LONGINT; prefix, suffix: Identifier ): QualifiedIdentifier;
  4315. VAR qualifiedIdentifier: QualifiedIdentifier;
  4316. BEGIN
  4317. NEW( qualifiedIdentifier, position, prefix, suffix ); RETURN qualifiedIdentifier
  4318. END NewQualifiedIdentifier;
  4319. PROCEDURE NewIdentifier*(CONST name: ARRAY OF CHAR): Identifier;
  4320. BEGIN
  4321. RETURN Basic.MakeString(name);
  4322. END NewIdentifier;
  4323. PROCEDURE NewParameter*( position: LONGINT; ownerType:Type ; name: Identifier; passAs: LONGINT): Parameter;
  4324. VAR parameter: Parameter;
  4325. BEGIN
  4326. NEW( parameter, position, ownerType, name, passAs); RETURN parameter;
  4327. END NewParameter;
  4328. PROCEDURE NewProperty*( position: LONGINT; name: Identifier): Property;
  4329. VAR property: Property;
  4330. BEGIN
  4331. NEW( property, position, name); RETURN property;
  4332. END NewProperty;
  4333. PROCEDURE NewExpressionList*(): ExpressionList;
  4334. VAR expressionList: ExpressionList;
  4335. BEGIN
  4336. NEW(expressionList); RETURN expressionList
  4337. END NewExpressionList;
  4338. PROCEDURE CloneExpressionList*(l: ExpressionList): ExpressionList;
  4339. VAR copy: ExpressionList;
  4340. BEGIN
  4341. IF l = NIL THEN RETURN NIL ELSE l.Clone(copy); RETURN copy END;
  4342. END CloneExpressionList;
  4343. PROCEDURE NewDesignator*(): Designator; (* for error handling: invalid Designator *)
  4344. VAR designator: Designator;
  4345. BEGIN
  4346. NEW(designator,-1); RETURN designator;
  4347. END NewDesignator;
  4348. PROCEDURE NewIdentifierDesignator*( position: LONGINT; identifier: Identifier): IdentifierDesignator;
  4349. VAR identifierDesignator: IdentifierDesignator;
  4350. BEGIN
  4351. NEW( identifierDesignator, position, identifier ); RETURN identifierDesignator
  4352. END NewIdentifierDesignator;
  4353. PROCEDURE NewSelectorDesignator*( position: LONGINT; left: Designator; name: Identifier ): SelectorDesignator;
  4354. VAR selectorDesignator: SelectorDesignator;
  4355. BEGIN
  4356. NEW( selectorDesignator, position, left, name ); RETURN selectorDesignator
  4357. END NewSelectorDesignator;
  4358. PROCEDURE NewParameterDesignator*( position: LONGINT; left: Designator; expressionList: ExpressionList ): ParameterDesignator;
  4359. VAR parameterDesignator: ParameterDesignator;
  4360. BEGIN
  4361. NEW( parameterDesignator,position, left, expressionList ); RETURN parameterDesignator
  4362. END NewParameterDesignator;
  4363. PROCEDURE NewArrowDesignator*( position: LONGINT; left: Designator ): ArrowDesignator;
  4364. VAR dereferenceDesignator: ArrowDesignator;
  4365. BEGIN
  4366. NEW( dereferenceDesignator, position, left ); RETURN dereferenceDesignator;
  4367. END NewArrowDesignator;
  4368. PROCEDURE NewBracketDesignator*( position: LONGINT; left: Designator; expressionList: ExpressionList ): BracketDesignator;
  4369. VAR bracketDesignator: BracketDesignator;
  4370. BEGIN
  4371. NEW( bracketDesignator, position, left, expressionList ); RETURN bracketDesignator
  4372. END NewBracketDesignator;
  4373. PROCEDURE NewSymbolDesignator*( position: LONGINT; left: Designator; symbol: Symbol ): SymbolDesignator;
  4374. VAR symbolDesignator: SymbolDesignator;
  4375. BEGIN
  4376. NEW( symbolDesignator, position, left, symbol); RETURN symbolDesignator
  4377. END NewSymbolDesignator;
  4378. PROCEDURE NewIndexDesignator*( position: LONGINT; left: Designator): IndexDesignator;
  4379. VAR indexDesignator: IndexDesignator;
  4380. BEGIN
  4381. NEW( indexDesignator, position, left); RETURN indexDesignator
  4382. END NewIndexDesignator;
  4383. PROCEDURE NewProcedureCallDesignator*(position: LONGINT; left: Designator; parameters: ExpressionList): ProcedureCallDesignator;
  4384. VAR procedureCallDesignator: ProcedureCallDesignator;
  4385. BEGIN
  4386. NEW(procedureCallDesignator, position, left, parameters); RETURN procedureCallDesignator
  4387. END NewProcedureCallDesignator;
  4388. PROCEDURE NewBuiltinCallDesignator*(position: LONGINT; id: LONGINT; left: Designator; parameters: ExpressionList): BuiltinCallDesignator;
  4389. VAR builtinCallDesignator: BuiltinCallDesignator;
  4390. BEGIN
  4391. NEW(builtinCallDesignator, position, id, left,parameters); RETURN builtinCallDesignator
  4392. END NewBuiltinCallDesignator;
  4393. PROCEDURE NewTypeGuardDesignator*(position: LONGINT; left: Designator; type: Type): TypeGuardDesignator;
  4394. VAR guardDesignator: TypeGuardDesignator;
  4395. BEGIN
  4396. NEW(guardDesignator,position,left,type); RETURN guardDesignator;
  4397. END NewTypeGuardDesignator;
  4398. PROCEDURE NewDereferenceDesignator*( position: LONGINT; left: Designator): DereferenceDesignator;
  4399. VAR dereferenceDesignator: DereferenceDesignator;
  4400. BEGIN
  4401. NEW( dereferenceDesignator, position, left); RETURN dereferenceDesignator
  4402. END NewDereferenceDesignator;
  4403. PROCEDURE NewSupercallDesignator*( position: LONGINT; left: Designator): SupercallDesignator;
  4404. VAR supercallDesignator: SupercallDesignator;
  4405. BEGIN
  4406. NEW( supercallDesignator, position, left); RETURN supercallDesignator
  4407. END NewSupercallDesignator;
  4408. PROCEDURE NewSelfDesignator*( position: LONGINT): SelfDesignator;
  4409. VAR selfDesignator: SelfDesignator;
  4410. BEGIN
  4411. NEW( selfDesignator, position); RETURN selfDesignator
  4412. END NewSelfDesignator;
  4413. PROCEDURE NewResultDesignator*( position: LONGINT): ResultDesignator;
  4414. VAR resultDesignator: ResultDesignator;
  4415. BEGIN
  4416. NEW( resultDesignator, position); RETURN resultDesignator
  4417. END NewResultDesignator;
  4418. PROCEDURE NewExpression*(): Expression; (* for error handling: invalid Expression *)
  4419. VAR expression: Expression;
  4420. BEGIN
  4421. NEW(expression,-1); RETURN expression;
  4422. END NewExpression;
  4423. PROCEDURE CloneExpression*(e: Expression): Expression;
  4424. VAR copy: Expression;
  4425. BEGIN
  4426. IF e = NIL THEN
  4427. RETURN NIL
  4428. ELSE
  4429. copy := e.Clone();
  4430. copy.type := e.type;
  4431. copy.assignable := e.assignable;
  4432. copy.position := e.position;
  4433. copy.state := e.state;
  4434. IF e.resolved = e THEN copy.resolved := copy(Value);
  4435. ELSIF e.resolved # NIL THEN copy.resolved := CloneExpression(e.resolved)(Value);
  4436. END;
  4437. RETURN copy
  4438. END;
  4439. END CloneExpression;
  4440. PROCEDURE CloneDesignator*(e: Expression): Designator;
  4441. BEGIN
  4442. IF e = NIL THEN RETURN NIL ELSE RETURN CloneExpression(e)(Designator) END;
  4443. END CloneDesignator;
  4444. PROCEDURE NewElement*( position: LONGINT; from,to: Expression ): Expression;
  4445. BEGIN
  4446. IF from = to THEN RETURN from
  4447. ELSE RETURN NewRangeExpression(position,from,to,NIL)
  4448. END;
  4449. END NewElement;
  4450. PROCEDURE NewSet*( position: LONGINT ): Set;
  4451. VAR set: Set;
  4452. BEGIN NEW( set, position ); RETURN set
  4453. END NewSet;
  4454. PROCEDURE NewMathArrayExpression*( position: LONGINT ): MathArrayExpression;
  4455. VAR mathArrayExpression: MathArrayExpression;
  4456. BEGIN NEW( mathArrayExpression, position ); RETURN mathArrayExpression
  4457. END NewMathArrayExpression;
  4458. PROCEDURE NewBinaryExpression*( position: LONGINT; left, right: Expression; operator: LONGINT ): BinaryExpression;
  4459. VAR binaryExpression: BinaryExpression;
  4460. BEGIN
  4461. NEW( binaryExpression, position, left, right, operator ); RETURN binaryExpression;
  4462. END NewBinaryExpression;
  4463. PROCEDURE NewRangeExpression*(position: LONGINT; first, last, step: Expression): RangeExpression;
  4464. VAR rangeExpression: RangeExpression;
  4465. BEGIN
  4466. NEW(rangeExpression, position, first, last, step); RETURN rangeExpression
  4467. END NewRangeExpression;
  4468. PROCEDURE NewTensorRangeExpression*(position: LONGINT): TensorRangeExpression;
  4469. VAR tensorRangeExpression: TensorRangeExpression;
  4470. BEGIN
  4471. NEW(tensorRangeExpression,position); RETURN tensorRangeExpression
  4472. END NewTensorRangeExpression;
  4473. PROCEDURE NewUnaryExpression*( position: LONGINT; operand: Expression; operator: LONGINT ): UnaryExpression;
  4474. VAR unaryExpression: UnaryExpression;
  4475. BEGIN
  4476. NEW( unaryExpression, position, operand, operator ); RETURN unaryExpression;
  4477. END NewUnaryExpression;
  4478. PROCEDURE NewConversion*( position: LONGINT; expression: Expression; type: Type; typeExpression: Expression): Conversion;
  4479. VAR conversion: Conversion;
  4480. BEGIN
  4481. ASSERT(type # NIL);
  4482. NEW( conversion, position, expression,type, typeExpression ); RETURN conversion;
  4483. END NewConversion;
  4484. PROCEDURE NewValue*(): Value;(* for error handling: invalid Value *)
  4485. VAR value: Value;
  4486. BEGIN
  4487. NEW(value,-1); RETURN value;
  4488. END NewValue;
  4489. PROCEDURE NewIntegerValue*( position: LONGINT; value: HUGEINT): IntegerValue;
  4490. VAR integerValue: IntegerValue;
  4491. BEGIN
  4492. NEW( integerValue, position, value); RETURN integerValue;
  4493. END NewIntegerValue;
  4494. PROCEDURE NewCharacterValue*( position: LONGINT; value: CHAR): CharacterValue;
  4495. VAR characterValue: CharacterValue;
  4496. BEGIN
  4497. NEW( characterValue, position, value); RETURN characterValue;
  4498. END NewCharacterValue;
  4499. PROCEDURE NewSetValue*(position: LONGINT; value: SET): SetValue;
  4500. VAR setValue: SetValue;
  4501. BEGIN
  4502. NEW(setValue, position, value); RETURN setValue
  4503. END NewSetValue;
  4504. PROCEDURE NewMathArrayValue*( position: LONGINT ): MathArrayValue;
  4505. VAR mathArrayValue: MathArrayValue;
  4506. BEGIN NEW( mathArrayValue, position ); RETURN mathArrayValue
  4507. END NewMathArrayValue;
  4508. PROCEDURE NewRealValue*( position: LONGINT; value: LONGREAL): RealValue;
  4509. VAR realValue: RealValue;
  4510. BEGIN
  4511. NEW( realValue, position, value); RETURN realValue
  4512. END NewRealValue;
  4513. PROCEDURE NewComplexValue*( position: LONGINT; realValue, imagValue: LONGREAL): ComplexValue;
  4514. VAR complexValue: ComplexValue;
  4515. BEGIN
  4516. NEW( complexValue, position, realValue, imagValue); RETURN complexValue
  4517. END NewComplexValue;
  4518. PROCEDURE NewStringValue*( position: LONGINT; value: String): StringValue;
  4519. VAR stringValue: StringValue;
  4520. BEGIN
  4521. NEW( stringValue, position, value ); RETURN stringValue
  4522. END NewStringValue;
  4523. PROCEDURE NewBooleanValue*( position: LONGINT; value: BOOLEAN): BooleanValue;
  4524. VAR booleanValue: BooleanValue;
  4525. BEGIN
  4526. NEW( booleanValue, position, value ); RETURN booleanValue;
  4527. END NewBooleanValue;
  4528. PROCEDURE NewNilValue*( position: LONGINT ): NilValue;
  4529. VAR nilValue: NilValue;
  4530. BEGIN
  4531. NEW( nilValue, position ); RETURN nilValue
  4532. END NewNilValue;
  4533. PROCEDURE NewEnumerationValue*( position: LONGINT; value: LONGINT ): EnumerationValue;
  4534. VAR enumeratorValue: EnumerationValue;
  4535. BEGIN
  4536. NEW( enumeratorValue, position, value ); RETURN enumeratorValue
  4537. END NewEnumerationValue;
  4538. PROCEDURE NewStatement*(outer: Statement): Statement; (* for error handling: invalid Statement *)
  4539. VAR statement: Statement;
  4540. BEGIN NEW(statement,-1,outer); RETURN statement;
  4541. END NewStatement;
  4542. PROCEDURE CloneStatement*(statement: Statement): Statement;
  4543. BEGIN IF statement = NIL THEN RETURN NIL ELSE RETURN statement.Clone() END
  4544. END CloneStatement;
  4545. PROCEDURE NewStatementSequence*(): StatementSequence;
  4546. VAR statementSequence: StatementSequence;
  4547. BEGIN
  4548. NEW( statementSequence); RETURN statementSequence
  4549. END NewStatementSequence;
  4550. PROCEDURE CloneStatementSequence*(statementSequence: StatementSequence): StatementSequence;
  4551. VAR copy: StatementSequence;
  4552. BEGIN IF statementSequence = NIL THEN RETURN NIL ELSE statementSequence.Clone(copy); RETURN copy END
  4553. END CloneStatementSequence;
  4554. PROCEDURE NewModifier*(position: LONGINT; identifier: Identifier; expression: Expression): Modifier;
  4555. VAR blockModifier: Modifier;
  4556. BEGIN
  4557. NEW(blockModifier,position,identifier,expression); RETURN blockModifier
  4558. END NewModifier;
  4559. PROCEDURE NewStatementBlock*( position: LONGINT ; outer: Statement): StatementBlock;
  4560. VAR statementBlock: StatementBlock;
  4561. BEGIN
  4562. NEW( statementBlock, position, outer ); RETURN statementBlock
  4563. END NewStatementBlock;
  4564. PROCEDURE NewStatementDesignator*(position: LONGINT; s: Statement): StatementDesignator;
  4565. VAR statementDesignator: StatementDesignator;
  4566. BEGIN
  4567. NEW( statementDesignator, position, s); RETURN statementDesignator
  4568. END NewStatementDesignator;
  4569. PROCEDURE NewBody*( position: LONGINT ; scope: ProcedureScope): Body;
  4570. VAR body: Body;
  4571. BEGIN
  4572. NEW( body, position,scope ); RETURN body
  4573. END NewBody;
  4574. PROCEDURE NewIfPart*(): IfPart;
  4575. VAR ifPart: IfPart;
  4576. BEGIN
  4577. NEW( ifPart); RETURN ifPart
  4578. END NewIfPart;
  4579. PROCEDURE NewIfStatement*( position: LONGINT ; outer: Statement): IfStatement;
  4580. VAR ifStatement: IfStatement;
  4581. BEGIN
  4582. NEW( ifStatement, position,outer ); RETURN ifStatement
  4583. END NewIfStatement;
  4584. PROCEDURE NewAssignment*( position: LONGINT; left: Designator; right: Expression; outer: Statement): Assignment;
  4585. VAR assignment: Assignment;
  4586. BEGIN
  4587. NEW( assignment, position, left, right,outer ); RETURN assignment
  4588. END NewAssignment;
  4589. PROCEDURE NewCommunicationStatement*( position: LONGINT; op: LONGINT; left: Designator; right: Expression; outer: Statement): CommunicationStatement;
  4590. VAR communication: CommunicationStatement;
  4591. BEGIN
  4592. NEW( communication, position, op, left, right,outer ); RETURN communication
  4593. END NewCommunicationStatement;
  4594. PROCEDURE NewProcedureCallStatement*(position: LONGINT; call: Designator; outer: Statement): ProcedureCallStatement;
  4595. VAR caller: ProcedureCallStatement;
  4596. BEGIN
  4597. NEW(caller,position,call,outer); RETURN caller
  4598. END NewProcedureCallStatement;
  4599. PROCEDURE NewCaseStatement*( position: LONGINT ; outer: Statement): CaseStatement;
  4600. VAR caseStatement: CaseStatement;
  4601. BEGIN
  4602. NEW( caseStatement, position,outer ); RETURN caseStatement
  4603. END NewCaseStatement;
  4604. PROCEDURE NewCasePart*(): CasePart;
  4605. VAR casePart: CasePart;
  4606. BEGIN
  4607. NEW( casePart); RETURN casePart
  4608. END NewCasePart;
  4609. PROCEDURE NewWithPart*(): WithPart;
  4610. VAR withPart: WithPart;
  4611. BEGIN
  4612. NEW( withPart); RETURN withPart
  4613. END NewWithPart;
  4614. PROCEDURE NewWithStatement*( position: LONGINT; outer: Statement): WithStatement;
  4615. VAR withStatement: WithStatement;
  4616. BEGIN
  4617. NEW( withStatement, position, outer ); RETURN withStatement
  4618. END NewWithStatement;
  4619. PROCEDURE NewWhileStatement*( position: LONGINT ; outer: Statement): WhileStatement;
  4620. VAR whileStatement: WhileStatement;
  4621. BEGIN
  4622. NEW( whileStatement, position,outer ); RETURN whileStatement
  4623. END NewWhileStatement;
  4624. PROCEDURE NewRepeatStatement*( position: LONGINT ; outer: Statement): RepeatStatement;
  4625. VAR repeatStatement: RepeatStatement;
  4626. BEGIN
  4627. NEW( repeatStatement, position ,outer); RETURN repeatStatement
  4628. END NewRepeatStatement;
  4629. PROCEDURE NewForStatement*( position: LONGINT; outer: Statement ): ForStatement;
  4630. VAR forStatement: ForStatement;
  4631. BEGIN
  4632. NEW( forStatement, position,outer ); RETURN forStatement
  4633. END NewForStatement;
  4634. PROCEDURE NewLoopStatement*( position: LONGINT ; outer: Statement): LoopStatement;
  4635. VAR loopStatement: LoopStatement;
  4636. BEGIN
  4637. NEW( loopStatement, position ,outer); RETURN loopStatement
  4638. END NewLoopStatement;
  4639. PROCEDURE NewExitableBlock*( position: LONGINT ; outer: Statement): ExitableBlock;
  4640. VAR loopStatement: ExitableBlock;
  4641. BEGIN
  4642. NEW( loopStatement, position ,outer); RETURN loopStatement
  4643. END NewExitableBlock;
  4644. PROCEDURE NewExitStatement*( position: LONGINT ; outer: Statement): ExitStatement;
  4645. VAR exitStatement: ExitStatement;
  4646. BEGIN
  4647. NEW( exitStatement, position, outer); RETURN exitStatement
  4648. END NewExitStatement;
  4649. PROCEDURE NewReturnStatement*( position: LONGINT; outer: Statement ): ReturnStatement;
  4650. VAR returnStatement: ReturnStatement;
  4651. BEGIN
  4652. NEW( returnStatement, position,outer ); RETURN returnStatement
  4653. END NewReturnStatement;
  4654. PROCEDURE NewAwaitStatement*( position: LONGINT; outer: Statement ): AwaitStatement;
  4655. VAR awaitStatement: AwaitStatement;
  4656. BEGIN
  4657. NEW( awaitStatement, position, outer ); RETURN awaitStatement
  4658. END NewAwaitStatement;
  4659. PROCEDURE NewCode*(position: LONGINT; outer: Statement): Code;
  4660. VAR code: Code;
  4661. BEGIN
  4662. NEW(code,position,outer); RETURN code
  4663. END NewCode;
  4664. PROCEDURE NewProcedureScope*(outer: Scope): ProcedureScope;
  4665. VAR scope: ProcedureScope;
  4666. BEGIN NEW(scope,outer); RETURN scope
  4667. END NewProcedureScope;
  4668. PROCEDURE NewModuleScope*(): ModuleScope;
  4669. VAR scope: ModuleScope;
  4670. BEGIN NEW(scope); RETURN scope
  4671. END NewModuleScope;
  4672. PROCEDURE NewRecordScope*(outer: Scope): RecordScope;
  4673. VAR scope: RecordScope;
  4674. BEGIN NEW(scope,outer); RETURN scope
  4675. END NewRecordScope;
  4676. PROCEDURE NewCellScope*(outer: Scope): CellScope;
  4677. VAR scope: CellScope;
  4678. BEGIN NEW(scope,outer); RETURN scope
  4679. END NewCellScope;
  4680. PROCEDURE NewEnumerationScope*(outer: Scope): EnumerationScope;
  4681. VAR scope: EnumerationScope;
  4682. BEGIN NEW(scope,outer); RETURN scope
  4683. END NewEnumerationScope;
  4684. PROCEDURE Init;
  4685. BEGIN;
  4686. invalidIdentifier := Basic.invalidString;
  4687. invalidQualifiedIdentifier := NewQualifiedIdentifier(-1,invalidIdentifier,Basic.emptyString);
  4688. invalidType := NewType();
  4689. invalidDesignator := NewDesignator();
  4690. invalidDesignator.SetType(invalidType);
  4691. invalidExpression := invalidDesignator;
  4692. invalidValue := NewValue();
  4693. invalidSymbol := NewSymbol(NewIdentifier(""));
  4694. invalidSymbol.SetType(invalidType);
  4695. importType := NewType();
  4696. importType.SetState(Resolved);
  4697. typeDeclarationType := NewType();
  4698. typeDeclarationType.SetState(Resolved);
  4699. moduleType := NewType();
  4700. moduleType.SetState(Resolved);
  4701. anonymousIdentifier := NewIdentifier("");
  4702. indexListSeparator := NewDesignator();
  4703. indexListSeparator.SetType(invalidType);
  4704. END Init;
  4705. BEGIN
  4706. Init;
  4707. END FoxSyntaxTree.