FoxSyntaxTree.Mod 165 KB

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