FoxSyntaxTree.Mod 160 KB

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