FoxSyntaxTree.Mod 159 KB

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