FoxSyntaxTree.Mod 160 KB

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