FoxSyntaxTree.Mod 164 KB

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