FoxSyntaxTree.Mod 164 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001
  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. END Symbol;
  2512. (**
  2513. <<TYPE name = declaredType>>
  2514. TypeDeclaration symbol represents a type declaration of the form TYPE name = declaredType.
  2515. Note that the declared type is not stored in the symbol's type field but rather in the declaredType field.
  2516. The type of a type declaration is set to "typeDeclarationType" in the semantic checker
  2517. **)
  2518. TypeDeclaration*= OBJECT(Symbol)
  2519. VAR
  2520. nextTypeDeclaration-: TypeDeclaration;
  2521. declaredType-: Type;
  2522. PROCEDURE &InitTypeDeclaration(position: Position; name: Identifier);
  2523. BEGIN
  2524. InitSymbol(position,name);
  2525. nextTypeDeclaration := NIL;
  2526. declaredType := NIL;
  2527. type := typeDeclarationType;
  2528. END InitTypeDeclaration;
  2529. PROCEDURE SetDeclaredType*(type: Type);
  2530. BEGIN
  2531. declaredType := type;
  2532. IF ~(type IS BasicType) THEN
  2533. type.typeDeclaration := SELF;
  2534. END;
  2535. END SetDeclaredType;
  2536. PROCEDURE SetType*(type: Type);
  2537. BEGIN
  2538. ASSERT(type = typeDeclarationType);
  2539. END SetType;
  2540. PROCEDURE Accept*(v: Visitor);
  2541. VAR position: LONGINT;
  2542. BEGIN position := SELF.position.start; v.VisitTypeDeclaration(SELF)
  2543. END Accept;
  2544. END TypeDeclaration;
  2545. (** <<CONST name = value >>
  2546. Constant declaration symbol. Represents a constant being defined in the form CONST name = value
  2547. The type of the constant is stored in the type field and is resolved by the semantic checker.
  2548. **)
  2549. Constant* = OBJECT (Symbol)
  2550. VAR
  2551. value-: Expression;
  2552. nextConstant-: Constant;
  2553. PROCEDURE & InitConstant( position: Position; name: Identifier );
  2554. BEGIN
  2555. InitSymbol(position,name);
  2556. value := NIL;
  2557. nextConstant := NIL;
  2558. END InitConstant;
  2559. PROCEDURE SetValue*( value: Expression );
  2560. BEGIN
  2561. SELF.value := value;
  2562. END SetValue;
  2563. PROCEDURE Accept*(v: Visitor);
  2564. VAR position: LONGINT;
  2565. BEGIN position := SELF.position.start; v.VisitConstant(SELF)
  2566. END Accept;
  2567. END Constant;
  2568. (** <<VAR name: type >>
  2569. Variable declaration symbol. Represents a variable defined in the form VAR name: Type.
  2570. The type of the variable is stored in the symbol's type field and is resolved by the semantic checker.
  2571. **)
  2572. Variable* = OBJECT (Symbol)
  2573. VAR
  2574. nextVariable-: Variable;
  2575. untraced-: BOOLEAN;
  2576. fictive-: BOOLEAN; (* variable is not allocated but has a fixed offset *)
  2577. fictiveOffset-: LONGINT; (* offset of fictive as provided by the source code *)
  2578. useRegister-: BOOLEAN; registerNumber-: LONGINT;
  2579. modifiers-: Modifier;
  2580. initializer-: Expression;
  2581. usedAsReference-: BOOLEAN;
  2582. PROCEDURE & InitVariable*( position: Position; name: Identifier);
  2583. BEGIN
  2584. InitSymbol(position,name);
  2585. nextVariable := NIL;
  2586. modifiers := NIL;
  2587. untraced := FALSE;
  2588. modifiers := NIL;
  2589. useRegister := FALSE;
  2590. registerNumber := -1;
  2591. usedAsReference := FALSE;
  2592. initializer := NIL;
  2593. fictive := FALSE;
  2594. END InitVariable;
  2595. PROCEDURE UsedAsReference*;
  2596. BEGIN
  2597. usedAsReference := TRUE
  2598. END UsedAsReference;
  2599. PROCEDURE SetUntraced*(u: BOOLEAN);
  2600. BEGIN untraced := u
  2601. END SetUntraced;
  2602. PROCEDURE SetUseRegister*(u: BOOLEAN);
  2603. BEGIN
  2604. useRegister := u
  2605. END SetUseRegister;
  2606. PROCEDURE SetRegisterNumber*(reg: LONGINT);
  2607. BEGIN
  2608. registerNumber := reg
  2609. END SetRegisterNumber;
  2610. PROCEDURE SetFictive*(offset: LONGINT);
  2611. BEGIN
  2612. fictive := TRUE;
  2613. fictiveOffset := offset;
  2614. END SetFictive;
  2615. PROCEDURE SetModifiers*(flag: Modifier);
  2616. BEGIN SELF.modifiers := flag;
  2617. END SetModifiers;
  2618. PROCEDURE SetInitializer*(initializer: Expression);
  2619. BEGIN SELF.initializer := initializer;
  2620. END SetInitializer;
  2621. PROCEDURE Accept*(v: Visitor);
  2622. VAR position: LONGINT;
  2623. BEGIN position := SELF.position.start; v.VisitVariable(SELF)
  2624. END Accept;
  2625. PROCEDURE NeedsTrace* (): BOOLEAN;
  2626. BEGIN RETURN ~untraced & (externalName = NIL) & type.NeedsTrace ();
  2627. END NeedsTrace;
  2628. END Variable;
  2629. (** << [VAR | CONST] name: type >>
  2630. Parameter declaration symbol. Represents a parameter in the form [VAR | CONST] name: Type.
  2631. The parameter's type is stored in the symbol's type field and is resolved by the semantic checker.
  2632. **)
  2633. Parameter* = OBJECT (Symbol)
  2634. VAR
  2635. nextParameter-, prevParameter-: Parameter;
  2636. modifiers-: Modifier;
  2637. defaultValue-: Expression;
  2638. kind-: LONGINT; (* ValueParameter, ConstParameter, VarParameter *)
  2639. ownerType-: Type;
  2640. untraced-: BOOLEAN;
  2641. movable-: BOOLEAN;
  2642. selfParameter-: BOOLEAN;
  2643. PROCEDURE & InitParameter( position: Position; ownerType: Type ; name: Identifier; kind: LONGINT);
  2644. BEGIN
  2645. InitSymbol( position, name );
  2646. SELF.kind := kind;
  2647. IF kind = ConstParameter THEN access := access END;
  2648. nextParameter := NIL;
  2649. SELF.ownerType := ownerType;
  2650. modifiers := NIL;
  2651. untraced := FALSE;
  2652. defaultValue := NIL;
  2653. movable := FALSE;
  2654. selfParameter := FALSE;
  2655. END InitParameter;
  2656. PROCEDURE SetModifiers*(flag: Modifier);
  2657. BEGIN SELF.modifiers := flag;
  2658. END SetModifiers;
  2659. PROCEDURE SetUntraced*(untraced: BOOLEAN);
  2660. BEGIN SELF.untraced := untraced
  2661. END SetUntraced;
  2662. PROCEDURE SetMoveable*(movable: BOOLEAN);
  2663. BEGIN SELF.movable := movable
  2664. END SetMoveable;
  2665. PROCEDURE SetSelfParameter*(b: BOOLEAN);
  2666. BEGIN
  2667. selfParameter := b;
  2668. END SetSelfParameter;
  2669. PROCEDURE SetDefaultValue*(e: Expression);
  2670. BEGIN defaultValue := e
  2671. END SetDefaultValue;
  2672. PROCEDURE Accept*(v: Visitor);
  2673. VAR position: LONGINT;
  2674. BEGIN position := SELF.position.start; v.VisitParameter(SELF)
  2675. END Accept;
  2676. PROCEDURE SetKind*(kind: LONGINT);
  2677. BEGIN SELF.kind := kind; END SetKind;
  2678. PROCEDURE NeedsTrace* (): BOOLEAN;
  2679. BEGIN RETURN ~untraced & type.NeedsTrace ();
  2680. END NeedsTrace;
  2681. END Parameter;
  2682. Property* = OBJECT (Variable)
  2683. VAR
  2684. nextProperty-, prevProperty-: Property;
  2685. value-: Expression;
  2686. PROCEDURE & InitProperty(position: Position; name: Identifier);
  2687. BEGIN
  2688. InitSymbol( position, name );
  2689. END InitProperty;
  2690. PROCEDURE SetValue*(e: Expression);
  2691. BEGIN value := e
  2692. END SetValue;
  2693. PROCEDURE Accept*(v: Visitor);
  2694. VAR position: LONGINT;
  2695. BEGIN position := SELF.position.start; v.VisitProperty(SELF)
  2696. END Accept;
  2697. END Property;
  2698. (** Procedure declaration symbol. Represents a procedure being defined in the form PROCEDURE name(parameters): returnType;
  2699. Note that the type of a procedure is a ProcedureType (and not the return type of the procedure).
  2700. Parameters, local variables, constants and type declarations are stored in the procedureScope field.
  2701. **)
  2702. Procedure* = OBJECT (Symbol)
  2703. VAR
  2704. nextProcedure-: Procedure;
  2705. procedureScope- : ProcedureScope;
  2706. super-: Procedure;
  2707. level-, methodNumber-: LONGINT;
  2708. isBodyProcedure-, isConstructor-,isFinalizer-,isInline-,isOberonInline-, isEntry-, isExit-,isFinal-,isAbstract-,isOverwritten-: BOOLEAN;
  2709. PROCEDURE & InitProcedure( position: Position; name: Identifier; scope: ProcedureScope);
  2710. BEGIN
  2711. InitSymbol(position,name);
  2712. nextProcedure := NIL;
  2713. procedureScope := scope;
  2714. ASSERT(scope.ownerProcedure = NIL); (* cannot register twice ! *)
  2715. scope.ownerProcedure := SELF;
  2716. super := NIL;
  2717. level := 0;
  2718. methodNumber := -1;
  2719. isBodyProcedure := FALSE;
  2720. isConstructor := FALSE;
  2721. isFinalizer := FALSE;
  2722. isInline := FALSE;
  2723. isOberonInline := FALSE;
  2724. isEntry := FALSE;
  2725. isExit := FALSE;
  2726. isFinal := FALSE;
  2727. isAbstract := FALSE;
  2728. isOverwritten := FALSE;
  2729. END InitProcedure;
  2730. PROCEDURE SetSuper*(super: Procedure);
  2731. BEGIN
  2732. SELF.super := super
  2733. END SetSuper;
  2734. PROCEDURE SetBodyProcedure*(isBodyProcedure: BOOLEAN);
  2735. BEGIN SELF.isBodyProcedure := isBodyProcedure;
  2736. END SetBodyProcedure;
  2737. PROCEDURE SetConstructor*(isConstructor: BOOLEAN);
  2738. BEGIN SELF.isConstructor := isConstructor
  2739. END SetConstructor;
  2740. PROCEDURE SetFinalizer*(isFinalizer: BOOLEAN);
  2741. BEGIN SELF.isFinalizer := isFinalizer
  2742. END SetFinalizer;
  2743. PROCEDURE SetInline*(isInline: BOOLEAN);
  2744. BEGIN SELF.isInline := isInline
  2745. END SetInline;
  2746. PROCEDURE SetOberonInline*(isInline: BOOLEAN);
  2747. BEGIN SELF.isOberonInline := isInline
  2748. END SetOberonInline;
  2749. PROCEDURE SetEntry*(entry: BOOLEAN);
  2750. BEGIN SELF.isEntry := entry
  2751. END SetEntry;
  2752. PROCEDURE SetExit*(exit: BOOLEAN);
  2753. BEGIN SELF.isExit := exit
  2754. END SetExit;
  2755. PROCEDURE SetFinal*(final: BOOLEAN);
  2756. BEGIN SELF.isFinal := final
  2757. END SetFinal;
  2758. PROCEDURE SetOverwritten*(locallyOverwritten: BOOLEAN);
  2759. BEGIN SELF.isOverwritten := locallyOverwritten
  2760. END SetOverwritten;
  2761. PROCEDURE SetAbstract*(abstract: BOOLEAN);
  2762. BEGIN SELF.isAbstract := abstract
  2763. END SetAbstract;
  2764. PROCEDURE SetLevel*(level: LONGINT);
  2765. BEGIN SELF.level := level
  2766. END SetLevel;
  2767. PROCEDURE SetMethodNumber*(methodNumber: LONGINT);
  2768. BEGIN SELF.methodNumber := methodNumber
  2769. END SetMethodNumber;
  2770. PROCEDURE Accept*(v: Visitor);
  2771. VAR position: LONGINT;
  2772. BEGIN position := SELF.position.start; v.VisitProcedure(SELF)
  2773. END Accept;
  2774. END Procedure;
  2775. (** Builtin symbol stands for a builtin procedure. Is resolved by the semantic checker. **)
  2776. Builtin* = OBJECT (Symbol)
  2777. VAR
  2778. nextBuiltin-: Builtin;
  2779. id-: LONGINT;
  2780. PROCEDURE & InitBuiltin(position: Position; name:Identifier; id: LONGINT);
  2781. BEGIN
  2782. InitSymbol(position,name); SELF.id := id;
  2783. END InitBuiltin;
  2784. PROCEDURE Accept*(v: Visitor);
  2785. VAR position: LONGINT;
  2786. BEGIN position := SELF.position.start; v.VisitBuiltin(SELF)
  2787. END Accept;
  2788. END Builtin;
  2789. CustomBuiltin*=OBJECT (Builtin)
  2790. VAR
  2791. subType-: SHORTINT;
  2792. PROCEDURE & InitCustomBuiltin(position: Position; name: Identifier; id: LONGINT; subType: SHORTINT);
  2793. BEGIN
  2794. InitBuiltin(position,name,id);
  2795. SELF.subType := subType;
  2796. END InitCustomBuiltin;
  2797. (* TODO: check if this is correct *)
  2798. PROCEDURE CompatibleTo*(otherType: Type): BOOLEAN;
  2799. BEGIN RETURN FALSE
  2800. END CompatibleTo;
  2801. END CustomBuiltin;
  2802. Operator* = OBJECT (Procedure)
  2803. VAR
  2804. nextOperator-: Operator;
  2805. isDynamic-: BOOLEAN; (* nopov *)
  2806. PROCEDURE & InitOperator(position: Position; name: Identifier; scope: ProcedureScope);
  2807. BEGIN
  2808. InitProcedure(position,name,scope);
  2809. nextOperator := NIL;
  2810. isDynamic := FALSE
  2811. END InitOperator;
  2812. (* nopov *)
  2813. PROCEDURE SetDynamic*(isDynamic: BOOLEAN);
  2814. BEGIN SELF.isDynamic := isDynamic
  2815. END SetDynamic;
  2816. PROCEDURE Accept*(v: Visitor);
  2817. VAR position: LONGINT;
  2818. BEGIN position := SELF.position.start; v.VisitOperator(SELF)
  2819. END Accept;
  2820. END Operator;
  2821. Import* = OBJECT (Symbol)
  2822. VAR
  2823. nextImport-: Import;
  2824. module-: Module;
  2825. moduleName-: Identifier;
  2826. context-: Identifier;
  2827. direct-: BOOLEAN; (* direct import *)
  2828. PROCEDURE & InitImport( position: Position; name, moduleName: Identifier; direct: BOOLEAN );
  2829. BEGIN
  2830. InitSymbol(position,name);
  2831. SELF.direct := direct;
  2832. module := NIL;
  2833. context := invalidIdentifier;
  2834. SELF.moduleName := moduleName;
  2835. type := importType;
  2836. END InitImport;
  2837. PROCEDURE SetType*(type: Type);
  2838. BEGIN
  2839. ASSERT(type = importType);
  2840. END SetType;
  2841. PROCEDURE SetModule*(module: Module);
  2842. BEGIN
  2843. SELF.module := module;
  2844. END SetModule;
  2845. PROCEDURE SetDirect*(d: BOOLEAN);
  2846. BEGIN
  2847. direct := d
  2848. END SetDirect;
  2849. PROCEDURE SetModuleName*(moduleName: Identifier);
  2850. BEGIN SELF.moduleName := moduleName
  2851. END SetModuleName;
  2852. PROCEDURE SetContext*(context: Identifier);
  2853. BEGIN
  2854. SELF.context := context
  2855. END SetContext;
  2856. PROCEDURE Accept*(v: Visitor);
  2857. VAR position: LONGINT;
  2858. BEGIN position := SELF.position.start; v.VisitImport(SELF)
  2859. END Accept;
  2860. END Import;
  2861. StatementSequence* = OBJECT
  2862. VAR
  2863. list: Basic.List;
  2864. PROCEDURE & InitList;
  2865. BEGIN NEW( list,32 );
  2866. END InitList;
  2867. PROCEDURE Length*( ): LONGINT;
  2868. BEGIN RETURN list.Length();
  2869. END Length;
  2870. PROCEDURE AddStatement*( statement: Statement);
  2871. BEGIN list.Add( statement );
  2872. END AddStatement;
  2873. PROCEDURE PrependStatement*( statement: Statement);
  2874. BEGIN list.Prepend( statement );
  2875. END PrependStatement;
  2876. PROCEDURE HasStatement*( statement: Statement):BOOLEAN;
  2877. BEGIN RETURN list.Contains(statement);
  2878. END HasStatement;
  2879. PROCEDURE GetStatement*( index: LONGINT ): Statement;
  2880. VAR p: ANY;
  2881. BEGIN p := list.Get( index ); RETURN p( Statement );
  2882. END GetStatement;
  2883. PROCEDURE SetStatement*(index: LONGINT; statement: Statement);
  2884. BEGIN
  2885. list.Set(index,statement);
  2886. END SetStatement;
  2887. PROCEDURE RemoveStatement*(statement: Statement);
  2888. BEGIN
  2889. list.Remove(statement);
  2890. END RemoveStatement;
  2891. PROCEDURE InsertBefore*(search, new: Statement);
  2892. BEGIN
  2893. list.Insert(list.IndexOf(search), new);
  2894. END InsertBefore;
  2895. PROCEDURE Clone(VAR copy: StatementSequence);
  2896. VAR i: LONGINT;
  2897. BEGIN
  2898. IF copy = NIL THEN NEW(copy) END;
  2899. FOR i := 0 TO Length()-1 DO
  2900. copy.AddStatement(CloneStatement(GetStatement(i)))
  2901. END;
  2902. END Clone;
  2903. END StatementSequence;
  2904. (**** statements ****)
  2905. Statement*= OBJECT
  2906. VAR outer-: Statement;
  2907. position-: Position;
  2908. isUnreachable-: BOOLEAN;
  2909. comment-: Comment;
  2910. PROCEDURE & InitStatement*(position: Position; outer: Statement);
  2911. BEGIN
  2912. SELF.position := position;
  2913. SELF.outer := outer;
  2914. isUnreachable := FALSE;
  2915. comment := NIL;
  2916. END InitStatement;
  2917. PROCEDURE SetOuter*(o: Statement);
  2918. BEGIN outer := o
  2919. END SetOuter;
  2920. PROCEDURE SetUnreachable*(unreachable: BOOLEAN);
  2921. BEGIN isUnreachable := unreachable
  2922. END SetUnreachable;
  2923. PROCEDURE Accept*(v: Visitor);
  2924. VAR position: LONGINT;
  2925. BEGIN position := SELF.position.start; v.VisitStatement(SELF)
  2926. END Accept;
  2927. PROCEDURE SetComment*(comment: Comment);
  2928. BEGIN SELF.comment := comment
  2929. END SetComment;
  2930. PROCEDURE Clone(): Statement;
  2931. BEGIN
  2932. HALT(200) (* abstract *)
  2933. END Clone;
  2934. END Statement;
  2935. (** << call(...) >> **)
  2936. ProcedureCallStatement*= OBJECT(Statement)
  2937. VAR call-: Designator;
  2938. PROCEDURE & InitProcedureCallStatement(position: Position; call: Designator; outer: Statement);
  2939. BEGIN InitStatement(position,outer); SELF.call := call;
  2940. END InitProcedureCallStatement;
  2941. PROCEDURE SetCall*(call: Designator);
  2942. BEGIN SELF.call := call;
  2943. END SetCall;
  2944. PROCEDURE Clone(): Statement;
  2945. VAR copy: ProcedureCallStatement;
  2946. BEGIN
  2947. NEW(copy, position, CloneDesignator(call), outer);
  2948. RETURN copy
  2949. END Clone;
  2950. PROCEDURE Accept*(v: Visitor);
  2951. VAR position: LONGINT;
  2952. BEGIN position := SELF.position.start; v.VisitProcedureCallStatement(SELF)
  2953. END Accept;
  2954. END ProcedureCallStatement;
  2955. (** << left := right >> **)
  2956. Assignment* = OBJECT (Statement)
  2957. VAR left-: Designator; right-: Expression;
  2958. PROCEDURE & InitAssignment*( position: Position; left: Designator; right: Expression; outer: Statement );
  2959. BEGIN
  2960. InitStatement( position,outer ); SELF.left := left; SELF.right := right;
  2961. END InitAssignment;
  2962. PROCEDURE SetLeft*(left: Designator);
  2963. BEGIN SELF.left := left
  2964. END SetLeft;
  2965. PROCEDURE SetRight*(right: Expression);
  2966. BEGIN SELF.right := right
  2967. END SetRight;
  2968. PROCEDURE Clone(): Statement;
  2969. VAR copy: Assignment;
  2970. BEGIN
  2971. NEW(copy, position, CloneDesignator(left), CloneExpression(right), outer);
  2972. RETURN copy
  2973. END Clone;
  2974. PROCEDURE Accept*(v: Visitor);
  2975. VAR position: LONGINT;
  2976. BEGIN position := SELF.position.start; v.VisitAssignment(SELF)
  2977. END Accept;
  2978. END Assignment;
  2979. (** << left ('!' | '?' | '<<' | '>>') right >> **)
  2980. CommunicationStatement* = OBJECT (Statement)
  2981. VAR
  2982. left-: Designator; right-: Expression; op-: LONGINT;
  2983. PROCEDURE & InitAssignment*( position: Position; op: LONGINT; left: Designator; right: Expression; outer: Statement );
  2984. BEGIN
  2985. InitStatement( position,outer ); SELF.op := op; SELF.left := left; SELF.right := right;
  2986. END InitAssignment;
  2987. PROCEDURE SetLeft*(left: Designator);
  2988. BEGIN SELF.left := left
  2989. END SetLeft;
  2990. PROCEDURE SetRight*(right: Expression);
  2991. BEGIN SELF.right := right
  2992. END SetRight;
  2993. PROCEDURE Accept*(v: Visitor);
  2994. VAR position: LONGINT;
  2995. BEGIN position := SELF.position.start; v.VisitCommunicationStatement(SELF)
  2996. END Accept;
  2997. END CommunicationStatement;
  2998. (** << ... condition THEN statements ... >> **)
  2999. IfPart*= OBJECT
  3000. VAR
  3001. condition-: Expression;
  3002. statements-: StatementSequence;
  3003. comment-: Comment;
  3004. PROCEDURE & InitIfPart;
  3005. BEGIN
  3006. statements := NIL; condition := NIL; comment := NIL;
  3007. END InitIfPart;
  3008. PROCEDURE SetCondition*(condition: Expression);
  3009. BEGIN SELF.condition := condition
  3010. END SetCondition;
  3011. PROCEDURE SetStatements*(statements: StatementSequence);
  3012. BEGIN SELF.statements := statements
  3013. END SetStatements;
  3014. PROCEDURE SetComment*(comment: Comment);
  3015. BEGIN SELF.comment := comment
  3016. END SetComment;
  3017. PROCEDURE Clone(): IfPart;
  3018. VAR copy: IfPart;
  3019. BEGIN
  3020. NEW(copy); copy.condition := CloneExpression(condition);
  3021. copy.statements := CloneStatementSequence(statements);
  3022. RETURN copy
  3023. END Clone;
  3024. END IfPart;
  3025. (** << IF ifPart {ELSIF elsifParts} ELSE elseParts >> **)
  3026. IfStatement* = OBJECT (Statement)
  3027. VAR
  3028. ifPart-: IfPart;
  3029. elsifParts: Basic.List;
  3030. elsePart-: StatementSequence;
  3031. PROCEDURE & InitIfStatement( position: Position ; outer: Statement);
  3032. BEGIN
  3033. InitStatement( position,outer ); ifPart := NewIfPart(); elsePart := NIL; elsifParts := NIL;
  3034. END InitIfStatement;
  3035. PROCEDURE SetElsePart*( elsePart: StatementSequence );
  3036. BEGIN
  3037. SELF.elsePart := elsePart;
  3038. END SetElsePart;
  3039. PROCEDURE AddElsifPart*( elsifPart: IfPart );
  3040. BEGIN
  3041. IF elsifParts = NIL THEN NEW(elsifParts,4); END;
  3042. elsifParts.Add( elsifPart );
  3043. END AddElsifPart;
  3044. PROCEDURE GetElsifPart*( i: LONGINT ): IfPart;
  3045. VAR a: ANY;
  3046. BEGIN a := elsifParts.Get( i ); RETURN a( IfPart )
  3047. END GetElsifPart;
  3048. PROCEDURE ElsifParts*( ): LONGINT;
  3049. BEGIN
  3050. IF elsifParts = NIL THEN RETURN 0 ELSE RETURN elsifParts.Length(); END;
  3051. END ElsifParts;
  3052. PROCEDURE Clone(): Statement;
  3053. VAR copy: IfStatement; i: LONGINT;
  3054. BEGIN
  3055. NEW(copy, position, outer);
  3056. copy.ifPart := ifPart.Clone();
  3057. FOR i := 0 TO ElsifParts()-1 DO
  3058. copy.AddElsifPart(GetElsifPart(i).Clone());
  3059. END;
  3060. copy.SetElsePart(CloneStatementSequence(elsePart));
  3061. RETURN copy
  3062. END Clone;
  3063. PROCEDURE Accept*(v: Visitor);
  3064. VAR position: LONGINT;
  3065. BEGIN position := SELF.position.start; v.VisitIfStatement(SELF)
  3066. END Accept;
  3067. END IfStatement;
  3068. WithPart*= OBJECT
  3069. VAR
  3070. variable-: Designator;
  3071. type-: Type; (* initially is qualified type *)
  3072. statements-: StatementSequence;
  3073. comment-: Comment;
  3074. PROCEDURE &InitWithPart();
  3075. BEGIN
  3076. type := NIL; variable := NIL; statements := NIL; comment := NIL;
  3077. END InitWithPart;
  3078. PROCEDURE SetVariable*( variable: Designator);
  3079. BEGIN
  3080. SELF.variable := variable
  3081. END SetVariable;
  3082. PROCEDURE SetType*( type: Type );
  3083. BEGIN
  3084. SELF.type := type
  3085. END SetType;
  3086. PROCEDURE SetStatements*( statements: StatementSequence );
  3087. BEGIN
  3088. SELF.statements := statements;
  3089. END SetStatements;
  3090. PROCEDURE SetComment*(comment: Comment);
  3091. BEGIN SELF.comment := comment
  3092. END SetComment;
  3093. PROCEDURE Clone(): WithPart;
  3094. VAR copy: WithPart;
  3095. BEGIN
  3096. NEW(copy);
  3097. copy.SetVariable(CloneDesignator(variable));
  3098. copy.SetType(type);
  3099. copy.SetStatements(CloneStatementSequence(statements));
  3100. RETURN copy
  3101. END Clone;
  3102. END WithPart;
  3103. (** << WITH variable : type DO statements END >> **)
  3104. WithStatement* = OBJECT (Statement)
  3105. VAR
  3106. withParts-: Basic.List;
  3107. elsePart-: StatementSequence;
  3108. PROCEDURE & InitWithStatement( position: Position; outer: Statement );
  3109. BEGIN
  3110. InitStatement( position,outer );
  3111. NEW(withParts,4); elsePart := NIL;
  3112. END InitWithStatement;
  3113. PROCEDURE AddWithPart*( withPart: WithPart );
  3114. BEGIN withParts.Add( withPart );
  3115. END AddWithPart;
  3116. PROCEDURE GetWithPart*( i: LONGINT ): WithPart;
  3117. VAR a: ANY;
  3118. BEGIN a := withParts.Get( i ); RETURN a( WithPart )
  3119. END GetWithPart;
  3120. PROCEDURE WithParts*( ): LONGINT;
  3121. BEGIN
  3122. IF withParts = NIL THEN RETURN 0 ELSE RETURN withParts.Length(); END;
  3123. END WithParts;
  3124. PROCEDURE SetElsePart*( elsePart: StatementSequence );
  3125. BEGIN
  3126. SELF.elsePart := elsePart;
  3127. END SetElsePart;
  3128. PROCEDURE Clone(): Statement;
  3129. VAR copy: WithStatement; i: LONGINT;
  3130. BEGIN
  3131. NEW(copy, position, outer);
  3132. FOR i := 0 TO WithParts()-1 DO
  3133. copy.AddWithPart(GetWithPart(i).Clone());
  3134. END;
  3135. copy.SetElsePart(CloneStatementSequence(elsePart));
  3136. RETURN copy
  3137. END Clone;
  3138. PROCEDURE Accept*(v: Visitor);
  3139. VAR position: LONGINT;
  3140. BEGIN position := SELF.position.start; v.VisitWithStatement(SELF)
  3141. END Accept;
  3142. END WithStatement;
  3143. CaseConstant*= POINTER TO RECORD min*,max*: LONGINT; next*: CaseConstant END;
  3144. (** << elements : statements >> **)
  3145. CasePart* = OBJECT
  3146. VAR
  3147. elements-: ExpressionList; (* expression list inserted by the parser *)
  3148. firstConstant-: CaseConstant; (* expression list resolved to int32s, inserted by checker *)
  3149. statements-: StatementSequence;
  3150. comment-: Comment;
  3151. PROCEDURE & InitCasePart;
  3152. BEGIN
  3153. elements := NewExpressionList(); firstConstant := NIL;
  3154. END InitCasePart;
  3155. PROCEDURE SetStatements*( statements: StatementSequence );
  3156. BEGIN
  3157. SELF.statements := statements;
  3158. END SetStatements;
  3159. PROCEDURE SetConstants*(firstConstant: CaseConstant);
  3160. BEGIN SELF.firstConstant := firstConstant
  3161. END SetConstants;
  3162. PROCEDURE SetComment*(comment: Comment);
  3163. BEGIN SELF.comment := comment
  3164. END SetComment;
  3165. PROCEDURE Clone(): CasePart;
  3166. VAR copy: CasePart;
  3167. BEGIN
  3168. NEW(copy);
  3169. copy.SetStatements(CloneStatementSequence(statements));
  3170. copy.firstConstant := firstConstant;
  3171. elements.Clone(copy.elements);
  3172. RETURN copy
  3173. END Clone;
  3174. END CasePart;
  3175. (** << CASE varaible OF caseParts ELSE elsePart >> **)
  3176. CaseStatement* = OBJECT (Statement)
  3177. VAR
  3178. variable-: Expression;
  3179. elsePart-: StatementSequence;
  3180. caseParts-: Basic.List;
  3181. min-,max-: LONGINT;
  3182. PROCEDURE & InitCaseStatement( position: Position ; outer: Statement);
  3183. BEGIN
  3184. InitStatement(position,outer ); variable := NIL; elsePart := NIL; caseParts := NIL;
  3185. min := MAX(LONGINT); max := MIN(LONGINT);
  3186. END InitCaseStatement;
  3187. PROCEDURE SetVariable*( expression: Expression );
  3188. BEGIN SELF.variable := expression;
  3189. END SetVariable;
  3190. PROCEDURE SetElsePart*( elsePart: StatementSequence );
  3191. BEGIN SELF.elsePart := elsePart;
  3192. END SetElsePart;
  3193. PROCEDURE AddCasePart*( casePart: CasePart );
  3194. BEGIN
  3195. IF caseParts = NIL THEN NEW(caseParts,4); END;
  3196. caseParts.Add( casePart );
  3197. END AddCasePart;
  3198. PROCEDURE GetCasePart*( i: LONGINT ): CasePart;
  3199. VAR a: ANY;
  3200. BEGIN a := caseParts.Get( i ); RETURN a( CasePart )
  3201. END GetCasePart;
  3202. PROCEDURE CaseParts*( ): LONGINT;
  3203. BEGIN
  3204. IF caseParts = NIL THEN RETURN 0 ELSE RETURN caseParts.Length(); END;
  3205. END CaseParts;
  3206. PROCEDURE Clone(): Statement;
  3207. VAR copy: CaseStatement; i: LONGINT;
  3208. BEGIN
  3209. NEW(copy, position, outer);
  3210. copy.SetVariable(CloneExpression(variable));
  3211. copy.SetElsePart(CloneStatementSequence(elsePart));
  3212. FOR i := 0 TO CaseParts()-1 DO
  3213. copy.AddCasePart(GetCasePart(i).Clone());
  3214. END;
  3215. copy.min := min; copy.max := max;
  3216. RETURN copy
  3217. END Clone;
  3218. PROCEDURE Accept*(v: Visitor);
  3219. VAR position: LONGINT;
  3220. BEGIN position := SELF.position.start; v.VisitCaseStatement(SELF)
  3221. END Accept;
  3222. PROCEDURE MaxConstant*(): LONGINT;
  3223. VAR val,i: LONGINT; part: CasePart; const: CaseConstant;
  3224. BEGIN
  3225. val := -1;
  3226. FOR i := 0 TO CaseParts() - 1 DO
  3227. part := GetCasePart(i);
  3228. const := part.firstConstant;
  3229. WHILE(const # NIL) DO
  3230. IF const.max > val THEN val := const.max; END;
  3231. const := const.next;
  3232. END;
  3233. END;
  3234. RETURN val;
  3235. END MaxConstant;
  3236. PROCEDURE SetMinMax*(min,max: LONGINT);
  3237. BEGIN
  3238. SELF.min := min; SELF.max := max;
  3239. END SetMinMax;
  3240. END CaseStatement;
  3241. (** << WHILE condition DO statements END >> **)
  3242. WhileStatement* = OBJECT (Statement)
  3243. VAR
  3244. condition-: Expression;
  3245. statements-: StatementSequence;
  3246. PROCEDURE & InitWhileStatement( position: Position ; outer: Statement);
  3247. BEGIN
  3248. InitStatement( position,outer ); condition := NIL; statements := NIL;
  3249. END InitWhileStatement;
  3250. PROCEDURE SetCondition*( condition: Expression );
  3251. BEGIN
  3252. SELF.condition := condition
  3253. END SetCondition;
  3254. PROCEDURE SetStatements*( statements: StatementSequence );
  3255. BEGIN
  3256. SELF.statements := statements;
  3257. END SetStatements;
  3258. PROCEDURE Clone(): Statement;
  3259. VAR copy: WhileStatement;
  3260. BEGIN
  3261. NEW(copy, position, outer);
  3262. copy.SetCondition(CloneExpression(condition));
  3263. copy.SetStatements(CloneStatementSequence(statements));
  3264. RETURN copy
  3265. END Clone;
  3266. PROCEDURE Accept*(v: Visitor);
  3267. VAR position: LONGINT;
  3268. BEGIN position := SELF.position.start; v.VisitWhileStatement(SELF)
  3269. END Accept;
  3270. END WhileStatement;
  3271. (** << REPEAT statements UNTIL condition >> **)
  3272. RepeatStatement* = OBJECT (Statement)
  3273. VAR
  3274. condition-: Expression;
  3275. statements-: StatementSequence;
  3276. PROCEDURE & InitRepeatStatement( position: Position; outer: Statement );
  3277. BEGIN
  3278. InitStatement( position,outer ); condition := NIL; statements := NIL;
  3279. END InitRepeatStatement;
  3280. PROCEDURE SetCondition*( condition: Expression );
  3281. BEGIN
  3282. SELF.condition := condition
  3283. END SetCondition;
  3284. PROCEDURE SetStatements*( statements: StatementSequence );
  3285. BEGIN
  3286. SELF.statements := statements;
  3287. END SetStatements;
  3288. PROCEDURE Clone(): Statement;
  3289. VAR copy: RepeatStatement;
  3290. BEGIN
  3291. NEW(copy, position, outer);
  3292. copy.SetCondition(CloneExpression(condition));
  3293. copy.SetStatements(CloneStatementSequence(statements));
  3294. RETURN copy
  3295. END Clone;
  3296. PROCEDURE Accept*(v: Visitor);
  3297. VAR position: LONGINT;
  3298. BEGIN position := SELF.position.start; v.VisitRepeatStatement(SELF)
  3299. END Accept;
  3300. END RepeatStatement;
  3301. (** << FOR variable := from TO to BY by DO statements END >> **)
  3302. ForStatement* = OBJECT (Statement)
  3303. VAR
  3304. variable-: Designator;
  3305. from-, to-, by-: Expression;
  3306. statements-: StatementSequence;
  3307. PROCEDURE & InitForStatement( position: Position; outer: Statement );
  3308. BEGIN
  3309. InitStatement( position,outer ); variable := NIL;from := NIL; to := NIL; by := NIL; statements := NIL;
  3310. END InitForStatement;
  3311. PROCEDURE SetVariable*( variable: Designator);
  3312. BEGIN
  3313. SELF.variable := variable
  3314. END SetVariable;
  3315. PROCEDURE SetFrom*( from: Expression );
  3316. BEGIN
  3317. SELF.from := from
  3318. END SetFrom;
  3319. PROCEDURE SetTo*( to: Expression );
  3320. BEGIN
  3321. SELF.to := to
  3322. END SetTo;
  3323. PROCEDURE SetBy*( by: Expression );
  3324. BEGIN SELF.by := by
  3325. END SetBy;
  3326. PROCEDURE SetStatements*( statements: StatementSequence );
  3327. BEGIN SELF.statements := statements;
  3328. END SetStatements;
  3329. PROCEDURE Clone(): Statement;
  3330. VAR copy: ForStatement;
  3331. BEGIN
  3332. NEW(copy, position, outer);
  3333. copy.SetVariable(CloneDesignator(variable));
  3334. copy.SetFrom(CloneExpression(from));
  3335. copy.SetTo(CloneExpression(to));
  3336. copy.SetBy(CloneExpression(by));
  3337. copy.SetStatements(CloneStatementSequence(statements));
  3338. RETURN copy
  3339. END Clone;
  3340. PROCEDURE Accept*(v: Visitor);
  3341. VAR position: LONGINT;
  3342. BEGIN position := SELF.position.start; v.VisitForStatement(SELF)
  3343. END Accept;
  3344. END ForStatement;
  3345. ExitableBlock*= OBJECT (Statement)
  3346. VAR statements-: StatementSequence;
  3347. PROCEDURE & InitExitableBlock( position: Position ; outer: Statement);
  3348. BEGIN
  3349. InitStatement( position ,outer); statements := NIL;
  3350. END InitExitableBlock;
  3351. PROCEDURE SetStatements*( statements: StatementSequence );
  3352. BEGIN SELF.statements := statements;
  3353. END SetStatements;
  3354. PROCEDURE Clone(): Statement;
  3355. VAR copy: ExitableBlock;
  3356. BEGIN
  3357. NEW(copy, position, outer);
  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.VisitExitableBlock(SELF)
  3364. END Accept;
  3365. END ExitableBlock;
  3366. (** << LOOP statements END >> **)
  3367. LoopStatement* = OBJECT (ExitableBlock)
  3368. PROCEDURE Clone(): Statement;
  3369. VAR copy: LoopStatement;
  3370. BEGIN
  3371. NEW(copy, position, outer);
  3372. copy.SetStatements(CloneStatementSequence(statements));
  3373. RETURN copy
  3374. END Clone;
  3375. PROCEDURE Accept*(v: Visitor);
  3376. VAR position: LONGINT;
  3377. BEGIN position := SELF.position.start; v.VisitLoopStatement(SELF)
  3378. END Accept;
  3379. END LoopStatement;
  3380. (** << EXIT >> **)
  3381. ExitStatement* = OBJECT (Statement)
  3382. PROCEDURE Accept*(v: Visitor);
  3383. VAR position: LONGINT;
  3384. BEGIN position := SELF.position.start; v.VisitExitStatement(SELF)
  3385. END Accept;
  3386. PROCEDURE Clone(): Statement;
  3387. VAR copy: ExitStatement;
  3388. BEGIN
  3389. NEW(copy, position, outer);
  3390. RETURN copy
  3391. END Clone;
  3392. END ExitStatement;
  3393. (** << RETURN returnValue >> **)
  3394. ReturnStatement* = OBJECT (Statement)
  3395. VAR returnValue-: Expression; (* strictly speaking this is not a value but this term is in common use here *)
  3396. PROCEDURE & InitReturnStatement( position: Position ; outer: Statement);
  3397. BEGIN
  3398. InitStatement( position,outer ); returnValue := NIL
  3399. END InitReturnStatement;
  3400. PROCEDURE SetReturnValue*( returnValue: Expression );
  3401. BEGIN SELF.returnValue := returnValue
  3402. END SetReturnValue;
  3403. PROCEDURE Clone(): Statement;
  3404. VAR copy: ReturnStatement;
  3405. BEGIN
  3406. NEW(copy, position, outer);
  3407. copy.SetReturnValue(CloneExpression(returnValue));
  3408. RETURN copy
  3409. END Clone;
  3410. PROCEDURE Accept*(v: Visitor);
  3411. VAR position: LONGINT;
  3412. BEGIN position := SELF.position.start; v.VisitReturnStatement(SELF)
  3413. END Accept;
  3414. END ReturnStatement;
  3415. (** << AWAIT condition >> **)
  3416. AwaitStatement* = OBJECT (Statement)
  3417. VAR condition-: Expression;
  3418. PROCEDURE & InitAwaitStatement( position: Position; outer: Statement );
  3419. BEGIN
  3420. InitStatement( position,outer ); condition := NIL
  3421. END InitAwaitStatement;
  3422. PROCEDURE SetCondition*( condition: Expression );
  3423. BEGIN SELF.condition := condition
  3424. END SetCondition;
  3425. PROCEDURE Clone(): Statement;
  3426. VAR copy: AwaitStatement;
  3427. BEGIN
  3428. NEW(copy, position, outer);
  3429. copy.SetCondition(CloneExpression(condition));
  3430. RETURN copy
  3431. END Clone;
  3432. PROCEDURE Accept*(v: Visitor);
  3433. VAR position: LONGINT;
  3434. BEGIN position := SELF.position.start; v.VisitAwaitStatement(SELF)
  3435. END Accept;
  3436. END AwaitStatement;
  3437. (* << Identifier ( Expression) >> *)
  3438. Modifier*= OBJECT
  3439. VAR
  3440. identifier-: Identifier; expression-: Expression;
  3441. resolved-: BOOLEAN;
  3442. nextModifier-: Modifier;
  3443. position-: Position;
  3444. PROCEDURE & InitModifier(position: Position; identifier: Identifier; expression: Expression);
  3445. BEGIN
  3446. SELF.position := position;
  3447. SELF.identifier := identifier; SELF.expression := expression; nextModifier := NIL; resolved := FALSE;
  3448. END InitModifier;
  3449. PROCEDURE Resolved*;
  3450. BEGIN resolved := TRUE
  3451. END Resolved;
  3452. PROCEDURE SetExpression*(e: Expression);
  3453. BEGIN SELF.expression := e
  3454. END SetExpression;
  3455. PROCEDURE SetNext*(modifier: Modifier);
  3456. BEGIN nextModifier := modifier
  3457. END SetNext;
  3458. END Modifier;
  3459. (** << BEGIN {Modifier, Modifier ... } statements END >> **)
  3460. StatementBlock* = OBJECT (Statement)
  3461. VAR
  3462. statements-: StatementSequence;
  3463. blockModifiers-: Modifier;
  3464. isExclusive-: BOOLEAN;
  3465. isRealtime-: BOOLEAN;
  3466. isUnchecked-: BOOLEAN;
  3467. isUncooperative-: BOOLEAN;
  3468. PROCEDURE & InitStatementBlock( position: Position ; outer: Statement);
  3469. BEGIN
  3470. InitStatement( position ,outer); statements := NIL; blockModifiers := NIL;
  3471. isExclusive := FALSE;
  3472. isRealtime := FALSE;
  3473. isUnchecked := FALSE;
  3474. isUncooperative := FALSE;
  3475. END InitStatementBlock;
  3476. PROCEDURE SetRealtime*(b: BOOLEAN);
  3477. BEGIN
  3478. isRealtime := b
  3479. END SetRealtime;
  3480. PROCEDURE SetUnchecked*(unchecked: BOOLEAN);
  3481. BEGIN
  3482. isUnchecked := unchecked
  3483. END SetUnchecked;
  3484. PROCEDURE SetUncooperative*(uncooperative: BOOLEAN);
  3485. BEGIN
  3486. isUncooperative := uncooperative
  3487. END SetUncooperative;
  3488. PROCEDURE SetModifier*(modifier: Modifier);
  3489. BEGIN
  3490. blockModifiers := modifier;
  3491. END SetModifier;
  3492. PROCEDURE SetExclusive*(excl: BOOLEAN);
  3493. BEGIN isExclusive := excl
  3494. END SetExclusive;
  3495. PROCEDURE SetStatementSequence*( statements: StatementSequence );
  3496. BEGIN SELF.statements := statements;
  3497. END SetStatementSequence;
  3498. PROCEDURE Accept*(v: Visitor);
  3499. VAR position: LONGINT;
  3500. BEGIN position := SELF.position.start; v.VisitStatementBlock(SELF)
  3501. END Accept;
  3502. END StatementBlock;
  3503. (** << CODE {flags} {character} END >> **)
  3504. Code*= OBJECT(Statement)
  3505. VAR
  3506. sourceCode-: SourceCode; sourceCodeLength-: LONGINT;
  3507. inlineCode-: BinaryCode;
  3508. inRules-, outRules-: StatementSequence;
  3509. PROCEDURE & InitCode(position: Position; outer: Statement);
  3510. BEGIN
  3511. InitStatement(position,outer);
  3512. inlineCode := NIL;
  3513. sourceCode := NIL; sourceCodeLength := 0;
  3514. NEW(inRules); NEW(outRules);
  3515. END InitCode;
  3516. PROCEDURE SetSourceCode*(source: SourceCode; length: LONGINT);
  3517. BEGIN sourceCode := source; sourceCodeLength := length;
  3518. ASSERT(sourceCodeLength <= LEN(source));
  3519. END SetSourceCode;
  3520. PROCEDURE SetBinaryCode*(code: BinaryCode);
  3521. BEGIN
  3522. inlineCode := code;
  3523. END SetBinaryCode;
  3524. PROCEDURE Clone(): Statement;
  3525. VAR copy: Code; s: Scanner.StringType;
  3526. BEGIN
  3527. NEW(copy, position, outer);
  3528. NEW(s, sourceCodeLength);
  3529. Strings.Copy(sourceCode^,0,sourceCodeLength,s^);
  3530. copy.SetSourceCode(s, sourceCodeLength);
  3531. copy.inRules := CloneStatementSequence(inRules);
  3532. copy.outRules := CloneStatementSequence(outRules);
  3533. RETURN copy
  3534. END Clone;
  3535. PROCEDURE Accept*(v: Visitor);
  3536. VAR position: LONGINT;
  3537. BEGIN position := SELF.position.start; v.VisitCode(SELF)
  3538. END Accept;
  3539. END Code;
  3540. (** << BEGIN {flags} statements FINALLY statements END >> **)
  3541. Body*= OBJECT(StatementBlock)
  3542. VAR
  3543. finally-: StatementSequence;
  3544. priority-: Expression; (* set by checker *)
  3545. inScope-: ProcedureScope;
  3546. code-: Code;
  3547. isActive-, isSafe-: BOOLEAN;
  3548. PROCEDURE & InitBody(position: Position; scope: ProcedureScope);
  3549. BEGIN
  3550. InitStatementBlock(position,NIL); finally := NIL; priority := NIL; inScope := scope; code := NIL;
  3551. isActive := FALSE; isSafe := FALSE; isRealtime := FALSE;
  3552. END InitBody;
  3553. PROCEDURE SetActive*(active: BOOLEAN);
  3554. BEGIN SELF.isActive := active
  3555. END SetActive;
  3556. PROCEDURE SetSafe*(safe: BOOLEAN);
  3557. BEGIN SELF.isSafe := safe
  3558. END SetSafe;
  3559. PROCEDURE SetFinally*( finally: StatementSequence );
  3560. BEGIN SELF.finally := finally
  3561. END SetFinally;
  3562. PROCEDURE SetPriority*(expression: Expression);
  3563. BEGIN priority := expression
  3564. END SetPriority;
  3565. PROCEDURE SetCode*(code: Code);
  3566. BEGIN SELF.code := code;
  3567. END SetCode;
  3568. END Body;
  3569. (** (* comment *) *)
  3570. Comment*=OBJECT
  3571. VAR position-: Position;
  3572. source-: String; (* currently: POINTER TO ARRAY OF CHAR *)
  3573. scope-: Scope;
  3574. item-: ANY; sameLine-: BOOLEAN;
  3575. nextComment-: Comment;
  3576. PROCEDURE & InitComment(pos: Position; scope: Scope; CONST s: ARRAY OF CHAR; length: LONGINT);
  3577. VAR i: LONGINT;
  3578. BEGIN
  3579. SELF.scope := scope;
  3580. NEW(source,length);
  3581. FOR i := 0 TO length-1 DO
  3582. source[i] := s[i];
  3583. END;
  3584. SELF.position := pos;
  3585. nextComment := NIL;
  3586. item := NIL; sameLine := FALSE;
  3587. END InitComment;
  3588. PROCEDURE SetItem*(p: ANY; sameLine: BOOLEAN);
  3589. BEGIN
  3590. item := p; SELF.sameLine := sameLine
  3591. END SetItem;
  3592. END Comment;
  3593. (**** building blocks ****)
  3594. Scope*=OBJECT
  3595. VAR
  3596. firstSymbol-: Symbol; numberSymbols-: LONGINT; (* all symbols in scope (sorted) *)
  3597. firstConstant-,lastConstant-: Constant; numberConstants-: LONGINT; (* constants *)
  3598. firstTypeDeclaration-,lastTypeDeclaration-: TypeDeclaration; numberTypeDeclarations-: LONGINT; (* type declarations *)
  3599. firstVariable-,lastVariable-: Variable; numberVariables-: LONGINT; (* variables *)
  3600. firstProcedure-,lastProcedure-: Procedure; numberProcedures-: LONGINT; (* procedures *)
  3601. procedures-: ProcedureList;
  3602. outerScope-: Scope; nextScope-: Scope;
  3603. ownerModule-: Module;
  3604. PROCEDURE & InitScope(outer: Scope);
  3605. BEGIN
  3606. firstSymbol := NIL; numberSymbols := 0;
  3607. firstConstant := NIL; lastConstant := NIL; numberConstants := 0;
  3608. firstTypeDeclaration := NIL; lastTypeDeclaration := NIL; numberTypeDeclarations := 0;
  3609. firstVariable := NIL; lastVariable := NIL; numberVariables := 0;
  3610. firstProcedure := NIL; lastProcedure := NIL; numberProcedures := 0;
  3611. outerScope := outer;
  3612. IF outer # NIL THEN
  3613. ownerModule := outer.ownerModule
  3614. ELSE
  3615. ownerModule := NIL;
  3616. END;
  3617. nextScope := NIL;
  3618. END InitScope;
  3619. PROCEDURE Clear*;
  3620. BEGIN
  3621. firstConstant := NIL; lastConstant := NIL; numberConstants := 0;
  3622. firstTypeDeclaration := NIL; lastTypeDeclaration := NIL; numberTypeDeclarations := 0;
  3623. firstVariable := NIL; lastVariable := NIL; numberVariables := 0;
  3624. firstProcedure := NIL; lastProcedure := NIL; numberProcedures := 0;
  3625. END Clear;
  3626. (** Enter a symbol in the scope, aplhabetically sorted, duplicate = TRUE if multiply identifier *)
  3627. PROCEDURE EnterSymbol*(symbol: Symbol; VAR duplicate: BOOLEAN);
  3628. VAR p,q: Symbol;
  3629. BEGIN
  3630. ASSERT(symbol.nextSymbol = NIL,101); (* symbol may only be present in one scope at a time ! *)
  3631. ASSERT(symbol.scope = NIL,102);
  3632. ASSERT(symbol.name # invalidIdentifier,103);
  3633. p := firstSymbol; q := NIL;
  3634. WHILE (p # NIL) & (StringPool.CompareString(p.name,symbol.name)<0) DO q := p; p := p.nextSymbol END;
  3635. IF (p#NIL) & (symbol.name = p.name) THEN
  3636. duplicate := TRUE;
  3637. ELSE
  3638. duplicate := FALSE
  3639. END;
  3640. symbol.nextSymbol := p;
  3641. IF q = NIL THEN firstSymbol := symbol ELSE q.nextSymbol := symbol END;
  3642. symbol.SetScope(SELF);
  3643. INC(numberSymbols);
  3644. END EnterSymbol;
  3645. (** Find symbol by name *)
  3646. PROCEDURE FindSymbol*(identifier: Identifier): Symbol;
  3647. VAR p: Symbol;
  3648. BEGIN
  3649. IF identifier # invalidIdentifier THEN
  3650. p := firstSymbol;
  3651. WHILE(p#NIL) & ((p.name # identifier) OR (p IS Operator)) DO p := p.nextSymbol END;
  3652. END;
  3653. RETURN p;
  3654. END FindSymbol;
  3655. PROCEDURE AddConstant*(c: Constant);
  3656. BEGIN
  3657. ASSERT(c # NIL);
  3658. IF lastConstant= NIL THEN firstConstant := c ELSE lastConstant.nextConstant := c END;
  3659. lastConstant := c;
  3660. INC(numberConstants);
  3661. END AddConstant;
  3662. PROCEDURE FindConstant*(identifier: Identifier): Constant;
  3663. VAR p: Constant;
  3664. BEGIN
  3665. p := firstConstant;
  3666. WHILE(p#NIL) & (p.name # identifier) DO p := p.nextConstant END;
  3667. RETURN p;
  3668. END FindConstant;
  3669. PROCEDURE AddTypeDeclaration*(t: TypeDeclaration);
  3670. BEGIN
  3671. ASSERT(t # NIL);
  3672. IF lastTypeDeclaration= NIL THEN firstTypeDeclaration := t ELSE lastTypeDeclaration.nextTypeDeclaration := t END;
  3673. INC(numberTypeDeclarations);
  3674. lastTypeDeclaration := t;
  3675. END AddTypeDeclaration;
  3676. PROCEDURE FindTypeDeclaration*(identifier: Identifier): TypeDeclaration;
  3677. VAR p: TypeDeclaration;
  3678. BEGIN
  3679. p := firstTypeDeclaration;
  3680. WHILE(p#NIL) & (p.name # identifier) DO p := p.nextTypeDeclaration END;
  3681. RETURN p;
  3682. END FindTypeDeclaration;
  3683. PROCEDURE AddVariable*(v: Variable);
  3684. BEGIN
  3685. ASSERT(v # NIL);
  3686. IF lastVariable= NIL THEN firstVariable := v ELSE lastVariable.nextVariable := v END;
  3687. INC(numberVariables);
  3688. lastVariable := v;
  3689. END AddVariable;
  3690. PROCEDURE PushVariable*(v: Variable);
  3691. BEGIN
  3692. ASSERT(v # NIL);
  3693. IF lastVariable= NIL THEN lastVariable := v ELSE v.nextVariable := firstVariable END;
  3694. INC(numberVariables);
  3695. firstVariable := v;
  3696. END PushVariable;
  3697. PROCEDURE FindVariable*(identifier: Identifier): Variable;
  3698. VAR p: Variable;
  3699. BEGIN
  3700. p := firstVariable;
  3701. WHILE(p#NIL) & (p.name # identifier) DO p := p.nextVariable END;
  3702. RETURN p;
  3703. END FindVariable;
  3704. PROCEDURE AddProcedure*(p: Procedure);
  3705. BEGIN
  3706. ASSERT(p # NIL);
  3707. IF lastProcedure= NIL THEN firstProcedure := p ELSE lastProcedure.nextProcedure := p END;
  3708. INC(numberProcedures);
  3709. lastProcedure := p;
  3710. END AddProcedure;
  3711. PROCEDURE AddProcedureDeclaration*(p: Procedure);
  3712. BEGIN
  3713. IF procedures = NIL THEN NEW(procedures) END;
  3714. procedures.AddProcedure(p);
  3715. END AddProcedureDeclaration;
  3716. PROCEDURE FindProcedure*(identifier: Identifier): Procedure;
  3717. VAR p: Procedure;
  3718. BEGIN
  3719. p := firstProcedure;
  3720. WHILE (p#NIL) & ((p.name # identifier) OR (p IS Operator)) DO p := p.nextProcedure END;
  3721. RETURN p;
  3722. END FindProcedure;
  3723. PROCEDURE FindMethod*(number: LONGINT): Procedure;
  3724. VAR p: Procedure;
  3725. BEGIN
  3726. p := firstProcedure;
  3727. WHILE (p# NIL) & (p.methodNumber # number) DO
  3728. p := p.nextProcedure
  3729. END;
  3730. RETURN p;
  3731. END FindMethod;
  3732. PROCEDURE Level*(): LONGINT;
  3733. VAR scope: Scope; level: LONGINT;
  3734. BEGIN
  3735. level := 0;
  3736. scope := SELF;
  3737. WHILE(scope.outerScope # NIL) DO
  3738. scope := scope.outerScope;
  3739. INC(level);
  3740. END;
  3741. RETURN level;
  3742. END Level;
  3743. PROCEDURE NeedsTrace* (): BOOLEAN;
  3744. VAR variable: Variable;
  3745. BEGIN
  3746. variable := firstVariable;
  3747. WHILE variable # NIL DO
  3748. IF variable.NeedsTrace () THEN RETURN TRUE END;
  3749. variable := variable.nextVariable;
  3750. END;
  3751. RETURN FALSE;
  3752. END NeedsTrace;
  3753. END Scope;
  3754. ProcedureScope*=OBJECT (Scope)
  3755. VAR
  3756. ownerProcedure-: Procedure;
  3757. body-: Body;
  3758. PROCEDURE & InitProcedureScope(outer: Scope);
  3759. BEGIN
  3760. InitScope(outer);
  3761. ownerProcedure := NIL;
  3762. body := NIL;
  3763. END InitProcedureScope;
  3764. PROCEDURE SetBody*(body: Body);
  3765. BEGIN
  3766. SELF.body := body;
  3767. END SetBody;
  3768. PROCEDURE NeedsTrace* (): BOOLEAN;
  3769. VAR parameter: Parameter;
  3770. BEGIN
  3771. parameter := ownerProcedure.type.resolved(ProcedureType).firstParameter;
  3772. WHILE parameter # NIL DO
  3773. IF parameter.NeedsTrace () THEN RETURN TRUE END;
  3774. parameter := parameter.nextParameter;
  3775. END;
  3776. RETURN NeedsTrace^();
  3777. END NeedsTrace;
  3778. END ProcedureScope;
  3779. EnumerationScope*= OBJECT(Scope)
  3780. VAR
  3781. ownerEnumeration-: EnumerationType;
  3782. (** Find symbol by name *)
  3783. PROCEDURE FindSymbol*(identifier: Identifier): Symbol;
  3784. VAR p: Symbol; base: Type;
  3785. BEGIN
  3786. p := FindSymbol^(identifier);
  3787. IF p = NIL THEN
  3788. base := ownerEnumeration.enumerationBase;
  3789. IF (base # NIL) & (base.resolved IS EnumerationType) THEN
  3790. p := base.resolved(EnumerationType).enumerationScope.FindSymbol(identifier)
  3791. END;
  3792. END;
  3793. RETURN p;
  3794. END FindSymbol;
  3795. PROCEDURE &InitEnumerationScope(outer: Scope);
  3796. BEGIN
  3797. InitScope(outer);
  3798. ownerEnumeration := NIL; (* must be set by EnumerationType *)
  3799. END InitEnumerationScope;
  3800. END EnumerationScope;
  3801. RecordScope*= OBJECT(Scope)
  3802. VAR
  3803. ownerRecord-: RecordType;
  3804. bodyProcedure-: Procedure;
  3805. constructor-: Procedure;
  3806. finalizer-: Procedure;
  3807. numberMethods-: LONGINT;
  3808. firstParameter-,lastParameter-: Parameter; numberParameters-: LONGINT; (* parameters for Active Cells programming*)
  3809. firstOperator-, lastOperator-: Operator; numberOperators: LONGINT; (* defined operators *)
  3810. PROCEDURE & InitRecordScope(outer: Scope);
  3811. BEGIN
  3812. InitScope(outer);
  3813. ownerRecord := NIL;
  3814. numberMethods := 0;
  3815. bodyProcedure := NIL;
  3816. constructor := NIL;
  3817. finalizer := NIL;
  3818. firstOperator := NIL; lastOperator := NIL; numberOperators := 0;
  3819. END InitRecordScope;
  3820. PROCEDURE SetBodyProcedure*(body: Procedure);
  3821. BEGIN SELF.bodyProcedure := body;
  3822. END SetBodyProcedure;
  3823. PROCEDURE SetConstructor*(body: Procedure);
  3824. BEGIN SELF.constructor := body
  3825. END SetConstructor;
  3826. PROCEDURE SetFinalizer*(body: Procedure);
  3827. BEGIN SELF.finalizer := body
  3828. END SetFinalizer;
  3829. PROCEDURE SetNumberMethods*(numberMethods: LONGINT);
  3830. BEGIN SELF.numberMethods := numberMethods;
  3831. END SetNumberMethods;
  3832. PROCEDURE AddOperator*(p: Operator);
  3833. BEGIN
  3834. ASSERT(p # NIL);
  3835. IF lastOperator= NIL THEN firstOperator := p ELSE lastOperator.nextOperator := p END;
  3836. INC(numberOperators);
  3837. lastOperator := p;
  3838. END AddOperator;
  3839. (** Find symbol by name *)
  3840. PROCEDURE FindSymbol*(identifier: Identifier): Symbol;
  3841. VAR p: Symbol; base: RecordType;
  3842. BEGIN
  3843. p := FindSymbol^(identifier);
  3844. IF p = NIL THEN
  3845. base := ownerRecord.GetBaseRecord();
  3846. IF (base # NIL) THEN
  3847. p := base.recordScope.FindSymbol(identifier)
  3848. END;
  3849. END;
  3850. RETURN p;
  3851. END FindSymbol;
  3852. PROCEDURE FindConstant*(identifier: Identifier): Constant;
  3853. VAR p: Constant; base: RecordType;
  3854. BEGIN
  3855. p := FindConstant^(identifier);
  3856. IF p = NIL THEN
  3857. base := ownerRecord.GetBaseRecord();
  3858. IF (base # NIL) THEN
  3859. p := base.recordScope.FindConstant(identifier)
  3860. END;
  3861. END;
  3862. RETURN p;
  3863. END FindConstant;
  3864. PROCEDURE FindTypeDeclaration*(identifier: Identifier): TypeDeclaration;
  3865. VAR p: TypeDeclaration; base: RecordType;
  3866. BEGIN
  3867. p := FindTypeDeclaration^(identifier);
  3868. IF p = NIL THEN
  3869. base := ownerRecord.GetBaseRecord();
  3870. IF (base # NIL) THEN
  3871. p := base.recordScope.FindTypeDeclaration(identifier)
  3872. END;
  3873. END;
  3874. RETURN p;
  3875. END FindTypeDeclaration;
  3876. PROCEDURE FindVariable*(identifier: Identifier): Variable;
  3877. VAR p: Variable; base: RecordType;
  3878. BEGIN
  3879. p := FindVariable^(identifier);
  3880. IF p = NIL THEN
  3881. base := ownerRecord.GetBaseRecord();
  3882. IF (base # NIL) THEN
  3883. p := base.recordScope.FindVariable(identifier)
  3884. END;
  3885. END;
  3886. RETURN p;
  3887. END FindVariable;
  3888. PROCEDURE FindProcedure*(identifier: Identifier): Procedure;
  3889. VAR p: Procedure; base: RecordType;
  3890. BEGIN
  3891. p := FindProcedure^(identifier);
  3892. IF p = NIL THEN
  3893. base := ownerRecord.GetBaseRecord();
  3894. IF (base # NIL) THEN
  3895. p := base.recordScope.FindProcedure(identifier)
  3896. END;
  3897. END;
  3898. RETURN p;
  3899. END FindProcedure;
  3900. PROCEDURE FindMethod*(number: LONGINT): Procedure;
  3901. VAR p: Procedure; base: RecordType;
  3902. BEGIN
  3903. p := FindMethod^(number);
  3904. IF p = NIL THEN
  3905. base := ownerRecord.GetBaseRecord();
  3906. IF (base # NIL) THEN
  3907. p := base.recordScope.FindMethod(number)
  3908. END;
  3909. END;
  3910. RETURN p;
  3911. END FindMethod;
  3912. PROCEDURE NeedsTrace* (): BOOLEAN;
  3913. VAR base: RecordType;
  3914. BEGIN
  3915. base := ownerRecord.GetBaseRecord();
  3916. IF (base # NIL) & (base.NeedsTrace ()) THEN RETURN TRUE END;
  3917. RETURN NeedsTrace^();
  3918. END NeedsTrace;
  3919. END RecordScope;
  3920. CellScope*=OBJECT (Scope)
  3921. VAR
  3922. ownerCell-: CellType;
  3923. bodyProcedure-: Procedure;
  3924. constructor-: Procedure;
  3925. firstImport-,lastImport-: Import; numberImports: LONGINT; (* imported modules *)
  3926. PROCEDURE & InitCellScope(outer: Scope);
  3927. BEGIN
  3928. InitScope(outer);
  3929. ownerCell := NIL;
  3930. bodyProcedure := NIL;
  3931. constructor := NIL;
  3932. firstImport := NIL; lastImport := NIL; numberImports := 0;
  3933. END InitCellScope;
  3934. PROCEDURE Clear*;
  3935. BEGIN
  3936. Clear^;
  3937. firstImport := NIL; lastImport := NIL; numberImports := 0;
  3938. constructor := NIL;
  3939. bodyProcedure := NIL;
  3940. END Clear;
  3941. PROCEDURE SetOwnerCell*(owner: CellType);
  3942. BEGIN
  3943. ownerCell := owner
  3944. END SetOwnerCell;
  3945. PROCEDURE SetBodyProcedure*(bodyProcedure: Procedure);
  3946. BEGIN
  3947. SELF.bodyProcedure := bodyProcedure;
  3948. END SetBodyProcedure;
  3949. PROCEDURE SetConstructor*(p: Procedure);
  3950. BEGIN constructor := p
  3951. END SetConstructor;
  3952. PROCEDURE AddImport*(i: Import);
  3953. BEGIN
  3954. ASSERT(i # NIL);
  3955. ASSERT(i.nextImport = NIL);
  3956. IF lastImport= NIL THEN firstImport:= i ELSE lastImport.nextImport := i END;
  3957. lastImport := i;
  3958. INC(numberImports);
  3959. END AddImport;
  3960. PROCEDURE FindImport*(identifier: Identifier): Import;
  3961. VAR p: Import;
  3962. BEGIN
  3963. p := firstImport;
  3964. WHILE(p#NIL) & (p.name # identifier) DO p := p.nextImport END; (* finds imports and re-imports! *)
  3965. RETURN p;
  3966. END FindImport;
  3967. PROCEDURE GetImport*( index: LONGINT ): Import;
  3968. VAR import: Import;
  3969. BEGIN
  3970. import := firstImport;
  3971. WHILE(import # NIL) & (index > 0) DO
  3972. import := import.nextImport;
  3973. DEC(index);
  3974. END;
  3975. RETURN import;
  3976. END GetImport;
  3977. PROCEDURE FindSymbol*(identifier: Identifier): Symbol;
  3978. VAR p: Symbol; base: Type;
  3979. BEGIN
  3980. p := FindSymbol^(identifier);
  3981. IF p = NIL THEN
  3982. IF ownerCell.isCellNet THEN
  3983. RETURN ownerCell.FindProperty(identifier);
  3984. END;
  3985. END;
  3986. IF p = NIL THEN
  3987. base := ownerCell.baseType;
  3988. IF (base # NIL) THEN
  3989. base := base.resolved;
  3990. IF base IS PointerType THEN
  3991. base := base(PointerType).pointerBase.resolved;
  3992. END;
  3993. WITH base: CellType DO
  3994. p := base.cellScope.FindSymbol(identifier)
  3995. |base: RecordType DO
  3996. p := base.recordScope.FindSymbol(identifier)
  3997. END;
  3998. END;
  3999. END;
  4000. RETURN p;
  4001. END FindSymbol;
  4002. END CellScope;
  4003. (**
  4004. <<
  4005. IMPORT firstImport .. lastImport;
  4006. ...
  4007. firstOperator ... lastOperator
  4008. ....
  4009. >>
  4010. **)
  4011. ModuleScope*= OBJECT(Scope)
  4012. VAR
  4013. firstImport-,lastImport-: Import; numberImports: LONGINT; (* imported modules *)
  4014. firstOperator-,lastOperator-: Operator; numberOperators: LONGINT; (* defined operators *)
  4015. firstBuiltin-,lastBuiltin-: Builtin; numberBuiltins: LONGINT; (* defined builtins, only for global and system module *)
  4016. firstComment-,lastComment-: Comment; numberComments-: LONGINT; (* comments *)
  4017. bodyProcedure-: Procedure;
  4018. PROCEDURE & InitModuleScope;
  4019. BEGIN
  4020. InitScope(NIL);
  4021. firstComment := NIL; lastComment := NIL; numberComments := 0;
  4022. firstImport:= NIL; lastImport := NIL; numberImports := 0;
  4023. firstOperator := NIL; lastOperator := NIL; numberOperators := 0;
  4024. END InitModuleScope;
  4025. PROCEDURE SetBodyProcedure*(body: Procedure);
  4026. BEGIN SELF.bodyProcedure := body;
  4027. END SetBodyProcedure;
  4028. PROCEDURE SetGlobalScope*(outer: Scope);
  4029. BEGIN
  4030. SELF.outerScope := outer;
  4031. END SetGlobalScope;
  4032. PROCEDURE AddBuiltin*(p: Builtin);
  4033. BEGIN
  4034. ASSERT(p # NIL);
  4035. IF lastBuiltin= NIL THEN firstBuiltin := p ELSE lastBuiltin.nextBuiltin := p END;
  4036. INC(numberBuiltins);
  4037. lastBuiltin := p;
  4038. END AddBuiltin;
  4039. PROCEDURE AddOperator*(p: Operator);
  4040. BEGIN
  4041. ASSERT(p # NIL);
  4042. IF lastOperator= NIL THEN firstOperator := p ELSE lastOperator.nextOperator := p END;
  4043. INC(numberOperators);
  4044. lastOperator := p;
  4045. END AddOperator;
  4046. PROCEDURE FindOperator*(identifier: Identifier): Operator;
  4047. VAR p: Operator;
  4048. BEGIN
  4049. p := firstOperator;
  4050. WHILE(p#NIL) & (p.name # identifier) DO p := p.nextOperator END;
  4051. RETURN p;
  4052. END FindOperator;
  4053. PROCEDURE AddImport*(i: Import);
  4054. BEGIN
  4055. ASSERT(i # NIL);
  4056. ASSERT(i.nextImport = NIL);
  4057. IF lastImport= NIL THEN firstImport:= i ELSE lastImport.nextImport := i END;
  4058. lastImport := i;
  4059. INC(numberImports);
  4060. END AddImport;
  4061. PROCEDURE FindImport*(identifier: Identifier): Import;
  4062. VAR p: Import;
  4063. BEGIN
  4064. p := firstImport;
  4065. WHILE(p#NIL) & (p.name # identifier) DO p := p.nextImport END; (* finds imports and re-imports! *)
  4066. RETURN p;
  4067. END FindImport;
  4068. PROCEDURE GetImport*( index: LONGINT ): Import;
  4069. VAR import: Import;
  4070. BEGIN
  4071. import := firstImport;
  4072. WHILE(import # NIL) & (index > 0) DO
  4073. import := import.nextImport;
  4074. DEC(index);
  4075. END;
  4076. RETURN import;
  4077. END GetImport;
  4078. PROCEDURE AddComment*(comment: Comment);
  4079. BEGIN
  4080. ASSERT(comment # NIL);
  4081. IF lastComment= NIL THEN firstComment := comment ELSE lastComment.nextComment := comment END;
  4082. INC(numberComments);
  4083. lastComment := comment;
  4084. END AddComment;
  4085. PROCEDURE ImportByModuleName*(moduleName,context: Identifier): Import;
  4086. VAR p: Import;
  4087. BEGIN
  4088. p := firstImport;
  4089. WHILE(p#NIL) & ~((moduleName = p.moduleName) & (context = p.context)) DO p := p.nextImport END;
  4090. RETURN p;
  4091. END ImportByModuleName;
  4092. PROCEDURE RemoveImporters*(moduleName,context: Identifier);
  4093. VAR this: Import;
  4094. PROCEDURE Check(p: Import): BOOLEAN;
  4095. VAR result: BOOLEAN;
  4096. BEGIN
  4097. IF (moduleName = p.moduleName) & (context = p.context) THEN
  4098. result := TRUE
  4099. ELSE
  4100. result := p.module.moduleScope.ImportByModuleName(moduleName,context) # NIL;
  4101. END;
  4102. RETURN result
  4103. END Check;
  4104. BEGIN
  4105. WHILE(firstImport # NIL) & Check(firstImport) DO
  4106. firstImport := firstImport.nextImport;
  4107. DEC(numberImports);
  4108. END;
  4109. IF firstImport = NIL THEN lastImport := NIL
  4110. ELSE
  4111. this :=firstImport;
  4112. WHILE(this.nextImport # NIL) DO
  4113. IF Check(this.nextImport) THEN
  4114. this.nextImport := this.nextImport.nextImport;
  4115. DEC(numberImports);
  4116. ELSE
  4117. this := this.nextImport
  4118. END;
  4119. END;
  4120. lastImport := this;
  4121. END;
  4122. END RemoveImporters;
  4123. END ModuleScope;
  4124. (* << MODULE name ['in' context] moduleScope name '.' >> *)
  4125. Module* = OBJECT (Symbol)
  4126. VAR
  4127. sourceName-: Basic.FileName;
  4128. moduleScope-: ModuleScope;
  4129. context-:Identifier; (* modules context *)
  4130. case-: LONGINT; (* module notation in lower or upper case, important for printout and operators *)
  4131. isCellNet-: BOOLEAN;
  4132. firstScope-,lastScope-: Scope; numberScopes-: LONGINT; (* list of all scopes for checker / backend traversal etc. *)
  4133. closingComment-: Comment;
  4134. modifiers-: Modifier;
  4135. PROCEDURE & InitModule( CONST sourceName: ARRAY OF CHAR; position: Position; name: Identifier; scope: ModuleScope; case: LONGINT);
  4136. BEGIN
  4137. InitSymbol(position,name);
  4138. COPY (sourceName, SELF.sourceName);
  4139. moduleScope := scope;
  4140. ASSERT(scope.ownerModule = NIL); (* cannot register twice ! *)
  4141. scope.ownerModule := SELF;
  4142. context := invalidIdentifier;
  4143. SELF.case := case;
  4144. firstScope := NIL; lastScope := NIL; numberScopes := 0;
  4145. SetType(moduleType);
  4146. closingComment := NIL;
  4147. isCellNet := FALSE;
  4148. modifiers := NIL;
  4149. END InitModule;
  4150. PROCEDURE SetCase*(case: LONGINT);
  4151. BEGIN
  4152. SELF.case := case
  4153. END SetCase;
  4154. PROCEDURE SetCellNet*(isCellNet: BOOLEAN);
  4155. BEGIN SELF.isCellNet := isCellNet
  4156. END SetCellNet;
  4157. PROCEDURE SetContext*(context: Identifier);
  4158. BEGIN SELF.context := context;
  4159. END SetContext;
  4160. PROCEDURE SetName*(name: Identifier);
  4161. BEGIN SELF.name := name
  4162. END SetName;
  4163. PROCEDURE SetClosingComment*(comment: Comment);
  4164. BEGIN SELF.closingComment := comment
  4165. END SetClosingComment;
  4166. PROCEDURE SetModifiers*(modifiers: Modifier);
  4167. BEGIN SELF.modifiers := modifiers
  4168. END SetModifiers;
  4169. PROCEDURE AddScope*(c: Scope);
  4170. BEGIN
  4171. IF lastScope= NIL THEN firstScope := c ELSE lastScope.nextScope := c END;
  4172. lastScope := c;
  4173. INC(numberScopes);
  4174. END AddScope;
  4175. PROCEDURE Accept*(v: Visitor);
  4176. VAR position: LONGINT;
  4177. BEGIN position := SELF.position.start; v.VisitModule(SELF)
  4178. END Accept;
  4179. END Module;
  4180. (** <<expression, expression, ...>> **)
  4181. SymbolList* = OBJECT
  4182. VAR list: Basic.List;
  4183. PROCEDURE & InitList*;
  4184. BEGIN NEW( list,8 );
  4185. END InitList;
  4186. PROCEDURE Length*( ): LONGINT;
  4187. BEGIN RETURN list.Length();
  4188. END Length;
  4189. PROCEDURE AddSymbol*( d: Symbol );
  4190. BEGIN list.Add(d)
  4191. END AddSymbol;
  4192. PROCEDURE GetSymbol*( index: LONGINT ): Symbol;
  4193. VAR p: ANY;
  4194. BEGIN
  4195. p := list.Get(index); RETURN p(Symbol);
  4196. END GetSymbol;
  4197. PROCEDURE SetSymbol*(index: LONGINT; expression: Symbol);
  4198. BEGIN list.Set(index,expression)
  4199. END SetSymbol;
  4200. PROCEDURE RemoveSymbol*(i: LONGINT);
  4201. BEGIN list.RemoveByIndex(i);
  4202. END RemoveSymbol;
  4203. (*
  4204. PROCEDURE Clone*(VAR list: SymbolList);
  4205. VAR i: LONGINT;
  4206. BEGIN
  4207. IF list = NIL THEN NEW(list) END;
  4208. FOR i := 0 TO Length()-1 DO
  4209. list.AddSymbol(CloneSymbol(GetSymbol(i)));
  4210. END;
  4211. END Clone;
  4212. *)
  4213. END SymbolList;
  4214. ProcedureList* = OBJECT
  4215. VAR list: Basic.List;
  4216. PROCEDURE & InitList*;
  4217. BEGIN NEW( list,8 );
  4218. END InitList;
  4219. PROCEDURE Length*( ): LONGINT;
  4220. BEGIN RETURN list.Length();
  4221. END Length;
  4222. PROCEDURE AddProcedure*( d: Procedure );
  4223. BEGIN list.Add(d)
  4224. END AddProcedure;
  4225. PROCEDURE GetProcedure*( index: LONGINT ): Procedure;
  4226. VAR p: ANY;
  4227. BEGIN
  4228. p := list.Get(index); RETURN p(Procedure);
  4229. END GetProcedure;
  4230. PROCEDURE SetProcedure*(index: LONGINT; expression: Procedure);
  4231. BEGIN list.Set(index,expression)
  4232. END SetProcedure;
  4233. PROCEDURE RemoveProcedure*(i: LONGINT);
  4234. BEGIN list.RemoveByIndex(i);
  4235. END RemoveProcedure;
  4236. (*
  4237. PROCEDURE Clone*(VAR list: ProcedureList);
  4238. VAR i: LONGINT;
  4239. BEGIN
  4240. IF list = NIL THEN NEW(list) END;
  4241. FOR i := 0 TO Length()-1 DO
  4242. list.AddProcedure(CloneProcedure(GetProcedure(i)));
  4243. END;
  4244. END Clone;
  4245. *)
  4246. END ProcedureList;
  4247. VAR
  4248. (* invalid items used, for example, by parser and checker *)
  4249. invalidIdentifier-: Identifier;
  4250. invalidQualifiedIdentifier-: QualifiedIdentifier;
  4251. invalidType-: Type;
  4252. invalidExpression-: Expression; (* mapped to invalidDesignator for better error handling in checker *)
  4253. invalidDesignator-: Designator;
  4254. invalidValue-: Value;
  4255. invalidSymbol-: Symbol;
  4256. invalidPosition-: Position;
  4257. anonymousIdentifier-: Identifier;
  4258. importType-: Type;
  4259. typeDeclarationType-: Type;
  4260. moduleType-: Type;
  4261. indexListSeparator-: Expression;
  4262. PROCEDURE InitFingerPrint*(VAR fingerprint: FingerPrint);
  4263. BEGIN
  4264. fingerprint.shallowAvailable := FALSE;
  4265. fingerprint.deepAvailable := FALSE;
  4266. fingerprint.shallow := 0;
  4267. fingerprint.private := 0;
  4268. fingerprint.public := 0;
  4269. END InitFingerPrint;
  4270. PROCEDURE NewModule*( CONST sourceName: ARRAY OF CHAR; position: Position; name: Identifier;scope: ModuleScope; case: LONGINT ): Module;
  4271. VAR module: Module;
  4272. BEGIN
  4273. NEW( module, sourceName, position, name, scope, case); RETURN module;
  4274. END NewModule;
  4275. PROCEDURE NewComment*(position: Position; scope: Scope; CONST source: ARRAY OF CHAR; length: LONGINT): Comment;
  4276. VAR comment: Comment;
  4277. BEGIN
  4278. NEW(comment,position,scope,source,length); RETURN comment;
  4279. END NewComment;
  4280. PROCEDURE NewImport*( position: Position; alias, name: Identifier; direct: BOOLEAN): Import;
  4281. VAR import: Import;
  4282. BEGIN
  4283. NEW( import, position, alias, name, direct ); RETURN import
  4284. END NewImport;
  4285. PROCEDURE NewConstant*( position: Position; name: Identifier ): Constant;
  4286. VAR constant: Constant;
  4287. BEGIN
  4288. NEW( constant, position, name ); RETURN constant
  4289. END NewConstant;
  4290. PROCEDURE NewProcedure*( position: Position; name: Identifier; scope: ProcedureScope ): Procedure;
  4291. VAR procedure: Procedure;
  4292. BEGIN
  4293. NEW( procedure, position, name, scope); RETURN procedure
  4294. END NewProcedure;
  4295. PROCEDURE NewBuiltin*(position: Position; name: Identifier; id: LONGINT): Builtin;
  4296. VAR builtin: Builtin;
  4297. BEGIN
  4298. NEW(builtin,position,name,id); RETURN builtin
  4299. END NewBuiltin;
  4300. PROCEDURE NewCustomBuiltin*(position: Position; name: Identifier; id: LONGINT; subType: SHORTINT): CustomBuiltin;
  4301. VAR builtin:CustomBuiltin;
  4302. BEGIN
  4303. NEW(builtin,position,name,id,subType); RETURN builtin
  4304. END NewCustomBuiltin;
  4305. PROCEDURE NewOperator*( position: Position; name: Identifier; scope: ProcedureScope): Operator;
  4306. VAR operator: Operator;
  4307. BEGIN
  4308. NEW( operator, position, name, scope); RETURN operator
  4309. END NewOperator;
  4310. PROCEDURE NewType*(): Type; (* for error handling: invalid Type, is realtime type *)
  4311. VAR type: Type;
  4312. BEGIN
  4313. NEW( type, invalidPosition);
  4314. type.SetRealtime(TRUE);
  4315. RETURN type
  4316. END NewType;
  4317. PROCEDURE NewByteType*(sizeInBits: LONGINT): ByteType;
  4318. VAR basicType: ByteType;
  4319. BEGIN
  4320. NEW(basicType, sizeInBits); RETURN basicType;
  4321. END NewByteType;
  4322. PROCEDURE NewAnyType*(sizeInBits: LONGINT): AnyType;
  4323. VAR basicType: AnyType;
  4324. BEGIN
  4325. NEW(basicType, sizeInBits); RETURN basicType;
  4326. END NewAnyType;
  4327. PROCEDURE NewObjectType*(sizeInBits: LONGINT): ObjectType;
  4328. VAR basicType: ObjectType;
  4329. BEGIN
  4330. NEW(basicType, sizeInBits); RETURN basicType;
  4331. END NewObjectType;
  4332. PROCEDURE NewNilType*(sizeInBits: LONGINT): NilType;
  4333. VAR basicType: NilType;
  4334. BEGIN
  4335. NEW(basicType, sizeInBits); RETURN basicType;
  4336. END NewNilType;
  4337. PROCEDURE NewAddressType*(sizeInBits: LONGINT): AddressType;
  4338. VAR basicType: AddressType;
  4339. BEGIN
  4340. NEW(basicType, sizeInBits); RETURN basicType;
  4341. END NewAddressType;
  4342. PROCEDURE NewSizeType*(sizeInBits: LONGINT): SizeType;
  4343. VAR basicType: SizeType;
  4344. BEGIN
  4345. NEW(basicType, sizeInBits); RETURN basicType;
  4346. END NewSizeType;
  4347. PROCEDURE NewBooleanType*(sizeInBits: LONGINT): BooleanType;
  4348. VAR basicType: BooleanType;
  4349. BEGIN
  4350. NEW(basicType, sizeInBits); RETURN basicType;
  4351. END NewBooleanType;
  4352. PROCEDURE NewSetType*(sizeInBits: LONGINT): SetType;
  4353. VAR basicType: SetType;
  4354. BEGIN
  4355. NEW(basicType, sizeInBits); RETURN basicType;
  4356. END NewSetType;
  4357. PROCEDURE NewCharacterType*(sizeInBits: LONGINT): CharacterType;
  4358. VAR basicType: CharacterType;
  4359. BEGIN
  4360. NEW(basicType, sizeInBits); RETURN basicType;
  4361. END NewCharacterType;
  4362. PROCEDURE NewRangeType*(sizeInBits: LONGINT): RangeType;
  4363. VAR basicType: RangeType;
  4364. BEGIN
  4365. NEW(basicType, sizeInBits); RETURN basicType;
  4366. END NewRangeType;
  4367. PROCEDURE NewComplexType*(base: Type): ComplexType;
  4368. VAR basicType: ComplexType;
  4369. BEGIN
  4370. NEW(basicType, base); RETURN basicType;
  4371. END NewComplexType;
  4372. PROCEDURE NewIntegerType*(size: LONGINT; signed: BOOLEAN): IntegerType;
  4373. VAR basicType: IntegerType;
  4374. BEGIN
  4375. NEW(basicType, size, signed); RETURN basicType;
  4376. END NewIntegerType;
  4377. PROCEDURE NewFloatType*(sizeInBits: LONGINT): FloatType;
  4378. VAR basicType: FloatType;
  4379. BEGIN
  4380. NEW(basicType, sizeInBits); RETURN basicType;
  4381. END NewFloatType;
  4382. PROCEDURE NewTypeDeclaration*(position: Position; name: Identifier): TypeDeclaration;
  4383. VAR typeDeclaration: TypeDeclaration;
  4384. BEGIN
  4385. ASSERT(name # invalidIdentifier);
  4386. NEW(typeDeclaration,position,name); RETURN typeDeclaration
  4387. END NewTypeDeclaration;
  4388. PROCEDURE NewStringType*( position: Position; baseType: Type; length: LONGINT): StringType;
  4389. VAR stringType: StringType;
  4390. BEGIN
  4391. NEW( stringType, position, baseType, length); RETURN stringType;
  4392. END NewStringType;
  4393. PROCEDURE NewEnumerationType*( position: Position; scope: Scope; enumerationScope: EnumerationScope): EnumerationType;
  4394. VAR enumerationType: EnumerationType;
  4395. BEGIN
  4396. NEW( enumerationType, position, scope, enumerationScope); RETURN enumerationType;
  4397. END NewEnumerationType;
  4398. PROCEDURE NewArrayType*( position: Position; scope: Scope; form: LONGINT): ArrayType;
  4399. VAR arrayType: ArrayType;
  4400. BEGIN
  4401. NEW( arrayType, position,scope, form); RETURN arrayType;
  4402. END NewArrayType;
  4403. PROCEDURE NewMathArrayType*( position: Position; scope: Scope; form: LONGINT): MathArrayType;
  4404. VAR mathArrayType: MathArrayType;
  4405. BEGIN
  4406. NEW( mathArrayType, position,scope,form); RETURN mathArrayType;
  4407. END NewMathArrayType;
  4408. PROCEDURE NewPointerType*( position: Position; scope: Scope): PointerType;
  4409. VAR pointerType: PointerType;
  4410. BEGIN
  4411. NEW( pointerType, position,scope); RETURN pointerType;
  4412. END NewPointerType;
  4413. PROCEDURE NewPortType*( position: Position; direction: LONGINT; sizeExpression: Expression; scope: Scope): PortType;
  4414. VAR portType: PortType;
  4415. BEGIN
  4416. NEW( portType, position, direction, sizeExpression, scope); RETURN portType;
  4417. END NewPortType;
  4418. PROCEDURE NewRecordType*( position: Position; scope: Scope; recordScope: RecordScope): RecordType;
  4419. VAR recordType: RecordType;
  4420. BEGIN
  4421. NEW( recordType, position, scope, recordScope); RETURN recordType
  4422. END NewRecordType;
  4423. PROCEDURE NewCellType*(position: Position; scope:Scope; cellScope: CellScope): CellType;
  4424. VAR actorType: CellType;
  4425. BEGIN
  4426. NEW(actorType, position, scope, cellScope); RETURN actorType;
  4427. END NewCellType;
  4428. PROCEDURE NewProcedureType*( position: Position; scope: Scope): ProcedureType;
  4429. VAR procedureType: ProcedureType;
  4430. BEGIN
  4431. NEW( procedureType, position,scope); RETURN procedureType;
  4432. END NewProcedureType;
  4433. PROCEDURE NewQualifiedType*( position: Position; scope: Scope; qualifiedIdentifier: QualifiedIdentifier): QualifiedType;
  4434. VAR qualifiedType: QualifiedType;
  4435. BEGIN
  4436. NEW( qualifiedType, position,scope,qualifiedIdentifier ); RETURN qualifiedType
  4437. END NewQualifiedType;
  4438. PROCEDURE NewSymbol*(name: Identifier): Symbol; (* for error handling: invalid Symbol *)
  4439. VAR symbol: Symbol;
  4440. BEGIN
  4441. NEW(symbol,invalidPosition,name); RETURN symbol
  4442. END NewSymbol;
  4443. PROCEDURE NewVariable*( position: Position; name: Identifier): Variable;
  4444. VAR variable: Variable;
  4445. BEGIN
  4446. NEW( variable, position, name ); RETURN variable
  4447. END NewVariable;
  4448. PROCEDURE NewQualifiedIdentifier*( position: Position; prefix, suffix: Identifier ): QualifiedIdentifier;
  4449. VAR qualifiedIdentifier: QualifiedIdentifier;
  4450. BEGIN
  4451. NEW( qualifiedIdentifier, position, prefix, suffix ); RETURN qualifiedIdentifier
  4452. END NewQualifiedIdentifier;
  4453. PROCEDURE NewIdentifier*(CONST name: ARRAY OF CHAR): Identifier;
  4454. BEGIN
  4455. RETURN Basic.MakeString(name);
  4456. END NewIdentifier;
  4457. PROCEDURE NewParameter*( position: Position; ownerType:Type ; name: Identifier; passAs: LONGINT): Parameter;
  4458. VAR parameter: Parameter;
  4459. BEGIN
  4460. NEW( parameter, position, ownerType, name, passAs); RETURN parameter;
  4461. END NewParameter;
  4462. PROCEDURE NewProperty*( position: Position; name: Identifier): Property;
  4463. VAR property: Property;
  4464. BEGIN
  4465. NEW( property, position, name); RETURN property;
  4466. END NewProperty;
  4467. PROCEDURE NewExpressionList*(): ExpressionList;
  4468. VAR expressionList: ExpressionList;
  4469. BEGIN
  4470. NEW(expressionList); RETURN expressionList
  4471. END NewExpressionList;
  4472. PROCEDURE CloneExpressionList*(l: ExpressionList): ExpressionList;
  4473. VAR copy: ExpressionList;
  4474. BEGIN
  4475. IF l = NIL THEN RETURN NIL ELSE l.Clone(copy); RETURN copy END;
  4476. END CloneExpressionList;
  4477. PROCEDURE NewDesignator*(): Designator; (* for error handling: invalid Designator *)
  4478. VAR designator: Designator;
  4479. BEGIN
  4480. NEW(designator,invalidPosition); RETURN designator;
  4481. END NewDesignator;
  4482. PROCEDURE NewIdentifierDesignator*( position: Position; identifier: Identifier): IdentifierDesignator;
  4483. VAR identifierDesignator: IdentifierDesignator;
  4484. BEGIN
  4485. NEW( identifierDesignator, position, identifier ); RETURN identifierDesignator
  4486. END NewIdentifierDesignator;
  4487. PROCEDURE NewSelectorDesignator*( position: Position; left: Designator; name: Identifier ): SelectorDesignator;
  4488. VAR selectorDesignator: SelectorDesignator;
  4489. BEGIN
  4490. NEW( selectorDesignator, position, left, name ); RETURN selectorDesignator
  4491. END NewSelectorDesignator;
  4492. PROCEDURE NewParameterDesignator*( position: Position; left: Designator; expressionList: ExpressionList ): ParameterDesignator;
  4493. VAR parameterDesignator: ParameterDesignator;
  4494. BEGIN
  4495. NEW( parameterDesignator,position, left, expressionList ); RETURN parameterDesignator
  4496. END NewParameterDesignator;
  4497. PROCEDURE NewArrowDesignator*( position: Position; left: Designator ): ArrowDesignator;
  4498. VAR dereferenceDesignator: ArrowDesignator;
  4499. BEGIN
  4500. NEW( dereferenceDesignator, position, left ); RETURN dereferenceDesignator;
  4501. END NewArrowDesignator;
  4502. PROCEDURE NewBracketDesignator*( position: Position; left: Designator; expressionList: ExpressionList ): BracketDesignator;
  4503. VAR bracketDesignator: BracketDesignator;
  4504. BEGIN
  4505. NEW( bracketDesignator, position, left, expressionList ); RETURN bracketDesignator
  4506. END NewBracketDesignator;
  4507. PROCEDURE NewSymbolDesignator*( position: Position; left: Designator; symbol: Symbol ): SymbolDesignator;
  4508. VAR symbolDesignator: SymbolDesignator;
  4509. BEGIN
  4510. NEW( symbolDesignator, position, left, symbol); RETURN symbolDesignator
  4511. END NewSymbolDesignator;
  4512. PROCEDURE NewIndexDesignator*( position: Position; left: Designator): IndexDesignator;
  4513. VAR indexDesignator: IndexDesignator;
  4514. BEGIN
  4515. NEW( indexDesignator, position, left); RETURN indexDesignator
  4516. END NewIndexDesignator;
  4517. PROCEDURE NewProcedureCallDesignator*(position: Position; left: Designator; parameters: ExpressionList): ProcedureCallDesignator;
  4518. VAR procedureCallDesignator: ProcedureCallDesignator;
  4519. BEGIN
  4520. NEW(procedureCallDesignator, position, left, parameters); RETURN procedureCallDesignator
  4521. END NewProcedureCallDesignator;
  4522. PROCEDURE NewBuiltinCallDesignator*(position: Position; id: LONGINT; left: Designator; parameters: ExpressionList): BuiltinCallDesignator;
  4523. VAR builtinCallDesignator: BuiltinCallDesignator;
  4524. BEGIN
  4525. NEW(builtinCallDesignator, position, id, left,parameters); RETURN builtinCallDesignator
  4526. END NewBuiltinCallDesignator;
  4527. PROCEDURE NewTypeGuardDesignator*(position: Position; left: Designator; type: Type): TypeGuardDesignator;
  4528. VAR guardDesignator: TypeGuardDesignator;
  4529. BEGIN
  4530. NEW(guardDesignator,position,left,type); RETURN guardDesignator;
  4531. END NewTypeGuardDesignator;
  4532. PROCEDURE NewDereferenceDesignator*( position: Position; left: Designator): DereferenceDesignator;
  4533. VAR dereferenceDesignator: DereferenceDesignator;
  4534. BEGIN
  4535. NEW( dereferenceDesignator, position, left); RETURN dereferenceDesignator
  4536. END NewDereferenceDesignator;
  4537. PROCEDURE NewSupercallDesignator*( position: Position; left: Designator): SupercallDesignator;
  4538. VAR supercallDesignator: SupercallDesignator;
  4539. BEGIN
  4540. NEW( supercallDesignator, position, left); RETURN supercallDesignator
  4541. END NewSupercallDesignator;
  4542. PROCEDURE NewSelfDesignator*( position: Position): SelfDesignator;
  4543. VAR selfDesignator: SelfDesignator;
  4544. BEGIN
  4545. NEW( selfDesignator, position); RETURN selfDesignator
  4546. END NewSelfDesignator;
  4547. PROCEDURE NewResultDesignator*( position: Position): ResultDesignator;
  4548. VAR resultDesignator: ResultDesignator;
  4549. BEGIN
  4550. NEW( resultDesignator, position); RETURN resultDesignator
  4551. END NewResultDesignator;
  4552. PROCEDURE NewExpression*(): Expression; (* for error handling: invalid Expression *)
  4553. VAR expression: Expression;
  4554. BEGIN
  4555. NEW(expression,invalidPosition); RETURN expression;
  4556. END NewExpression;
  4557. PROCEDURE CloneExpression*(e: Expression): Expression;
  4558. VAR copy: Expression;
  4559. BEGIN
  4560. IF e = NIL THEN
  4561. RETURN NIL
  4562. ELSE
  4563. copy := e.Clone();
  4564. copy.type := e.type;
  4565. copy.assignable := e.assignable;
  4566. copy.position := e.position;
  4567. copy.state := e.state;
  4568. IF e.resolved = e THEN copy.resolved := copy(Value);
  4569. ELSIF e.resolved # NIL THEN copy.resolved := CloneExpression(e.resolved)(Value);
  4570. END;
  4571. RETURN copy
  4572. END;
  4573. END CloneExpression;
  4574. PROCEDURE CloneDesignator*(e: Expression): Designator;
  4575. BEGIN
  4576. IF e = NIL THEN RETURN NIL ELSE RETURN CloneExpression(e)(Designator) END;
  4577. END CloneDesignator;
  4578. PROCEDURE NewElement*( position: Position; from,to: Expression ): Expression;
  4579. BEGIN
  4580. IF from = to THEN RETURN from
  4581. ELSE RETURN NewRangeExpression(position,from,to,NIL)
  4582. END;
  4583. END NewElement;
  4584. PROCEDURE NewSet*( position: Position ): Set;
  4585. VAR set: Set;
  4586. BEGIN NEW( set, position ); RETURN set
  4587. END NewSet;
  4588. PROCEDURE NewMathArrayExpression*( position: Position ): MathArrayExpression;
  4589. VAR mathArrayExpression: MathArrayExpression;
  4590. BEGIN NEW( mathArrayExpression, position ); RETURN mathArrayExpression
  4591. END NewMathArrayExpression;
  4592. PROCEDURE NewBinaryExpression*( position: Position; left, right: Expression; operator: LONGINT ): BinaryExpression;
  4593. VAR binaryExpression: BinaryExpression;
  4594. BEGIN
  4595. NEW( binaryExpression, position, left, right, operator ); RETURN binaryExpression;
  4596. END NewBinaryExpression;
  4597. PROCEDURE NewRangeExpression*(position: Position; first, last, step: Expression): RangeExpression;
  4598. VAR rangeExpression: RangeExpression;
  4599. BEGIN
  4600. NEW(rangeExpression, position, first, last, step); RETURN rangeExpression
  4601. END NewRangeExpression;
  4602. PROCEDURE NewTensorRangeExpression*(position: Position): TensorRangeExpression;
  4603. VAR tensorRangeExpression: TensorRangeExpression;
  4604. BEGIN
  4605. NEW(tensorRangeExpression,position); RETURN tensorRangeExpression
  4606. END NewTensorRangeExpression;
  4607. PROCEDURE NewUnaryExpression*( position: Position; operand: Expression; operator: LONGINT ): UnaryExpression;
  4608. VAR unaryExpression: UnaryExpression;
  4609. BEGIN
  4610. NEW( unaryExpression, position, operand, operator ); RETURN unaryExpression;
  4611. END NewUnaryExpression;
  4612. PROCEDURE NewConversion*( position: Position; expression: Expression; type: Type; typeExpression: Expression): Conversion;
  4613. VAR conversion: Conversion;
  4614. BEGIN
  4615. ASSERT(type # NIL);
  4616. NEW( conversion, position, expression,type, typeExpression ); RETURN conversion;
  4617. END NewConversion;
  4618. PROCEDURE NewValue*(): Value;(* for error handling: invalid Value *)
  4619. VAR value: Value;
  4620. BEGIN
  4621. NEW(value,invalidPosition); RETURN value;
  4622. END NewValue;
  4623. PROCEDURE NewIntegerValue*( position: Position; value: HUGEINT): IntegerValue;
  4624. VAR integerValue: IntegerValue;
  4625. BEGIN
  4626. NEW( integerValue, position, value); RETURN integerValue;
  4627. END NewIntegerValue;
  4628. PROCEDURE NewCharacterValue*( position: Position; value: CHAR): CharacterValue;
  4629. VAR characterValue: CharacterValue;
  4630. BEGIN
  4631. NEW( characterValue, position, value); RETURN characterValue;
  4632. END NewCharacterValue;
  4633. PROCEDURE NewSetValue*(position: Position; value: SET): SetValue;
  4634. VAR setValue: SetValue;
  4635. BEGIN
  4636. NEW(setValue, position, value); RETURN setValue
  4637. END NewSetValue;
  4638. PROCEDURE NewMathArrayValue*( position: Position ): MathArrayValue;
  4639. VAR mathArrayValue: MathArrayValue;
  4640. BEGIN NEW( mathArrayValue, position ); RETURN mathArrayValue
  4641. END NewMathArrayValue;
  4642. PROCEDURE NewRealValue*( position: Position; value: LONGREAL): RealValue;
  4643. VAR realValue: RealValue;
  4644. BEGIN
  4645. NEW( realValue, position, value); RETURN realValue
  4646. END NewRealValue;
  4647. PROCEDURE NewComplexValue*( position: Position; realValue, imagValue: LONGREAL): ComplexValue;
  4648. VAR complexValue: ComplexValue;
  4649. BEGIN
  4650. NEW( complexValue, position, realValue, imagValue); RETURN complexValue
  4651. END NewComplexValue;
  4652. PROCEDURE NewStringValue*( position: Position; value: String): StringValue;
  4653. VAR stringValue: StringValue;
  4654. BEGIN
  4655. NEW( stringValue, position, value ); RETURN stringValue
  4656. END NewStringValue;
  4657. PROCEDURE NewBooleanValue*( position: Position; value: BOOLEAN): BooleanValue;
  4658. VAR booleanValue: BooleanValue;
  4659. BEGIN
  4660. NEW( booleanValue, position, value ); RETURN booleanValue;
  4661. END NewBooleanValue;
  4662. PROCEDURE NewNilValue*( position: Position ): NilValue;
  4663. VAR nilValue: NilValue;
  4664. BEGIN
  4665. NEW( nilValue, position ); RETURN nilValue
  4666. END NewNilValue;
  4667. PROCEDURE NewEnumerationValue*( position: Position; value: LONGINT ): EnumerationValue;
  4668. VAR enumeratorValue: EnumerationValue;
  4669. BEGIN
  4670. NEW( enumeratorValue, position, value ); RETURN enumeratorValue
  4671. END NewEnumerationValue;
  4672. PROCEDURE NewStatement*(outer: Statement): Statement; (* for error handling: invalid Statement *)
  4673. VAR statement: Statement;
  4674. BEGIN NEW(statement,invalidPosition,outer); RETURN statement;
  4675. END NewStatement;
  4676. PROCEDURE CloneStatement*(statement: Statement): Statement;
  4677. BEGIN IF statement = NIL THEN RETURN NIL ELSE RETURN statement.Clone() END
  4678. END CloneStatement;
  4679. PROCEDURE NewStatementSequence*(): StatementSequence;
  4680. VAR statementSequence: StatementSequence;
  4681. BEGIN
  4682. NEW( statementSequence); RETURN statementSequence
  4683. END NewStatementSequence;
  4684. PROCEDURE CloneStatementSequence*(statementSequence: StatementSequence): StatementSequence;
  4685. VAR copy: StatementSequence;
  4686. BEGIN IF statementSequence = NIL THEN RETURN NIL ELSE statementSequence.Clone(copy); RETURN copy END
  4687. END CloneStatementSequence;
  4688. PROCEDURE NewModifier*(position: Position; identifier: Identifier; expression: Expression): Modifier;
  4689. VAR blockModifier: Modifier;
  4690. BEGIN
  4691. NEW(blockModifier,position,identifier,expression); RETURN blockModifier
  4692. END NewModifier;
  4693. PROCEDURE NewStatementBlock*( position: Position ; outer: Statement): StatementBlock;
  4694. VAR statementBlock: StatementBlock;
  4695. BEGIN
  4696. NEW( statementBlock, position, outer ); RETURN statementBlock
  4697. END NewStatementBlock;
  4698. PROCEDURE NewStatementDesignator*(position: Position; s: Statement): StatementDesignator;
  4699. VAR statementDesignator: StatementDesignator;
  4700. BEGIN
  4701. NEW( statementDesignator, position, s); RETURN statementDesignator
  4702. END NewStatementDesignator;
  4703. PROCEDURE NewBody*( position: Position ; scope: ProcedureScope): Body;
  4704. VAR body: Body;
  4705. BEGIN
  4706. NEW( body, position,scope ); RETURN body
  4707. END NewBody;
  4708. PROCEDURE NewIfPart*(): IfPart;
  4709. VAR ifPart: IfPart;
  4710. BEGIN
  4711. NEW( ifPart); RETURN ifPart
  4712. END NewIfPart;
  4713. PROCEDURE NewIfStatement*( position: Position ; outer: Statement): IfStatement;
  4714. VAR ifStatement: IfStatement;
  4715. BEGIN
  4716. NEW( ifStatement, position,outer ); RETURN ifStatement
  4717. END NewIfStatement;
  4718. PROCEDURE NewAssignment*( position: Position; left: Designator; right: Expression; outer: Statement): Assignment;
  4719. VAR assignment: Assignment;
  4720. BEGIN
  4721. NEW( assignment, position, left, right,outer ); RETURN assignment
  4722. END NewAssignment;
  4723. PROCEDURE NewCommunicationStatement*( position: Position; op: LONGINT; left: Designator; right: Expression; outer: Statement): CommunicationStatement;
  4724. VAR communication: CommunicationStatement;
  4725. BEGIN
  4726. NEW( communication, position, op, left, right,outer ); RETURN communication
  4727. END NewCommunicationStatement;
  4728. PROCEDURE NewProcedureCallStatement*(position: Position; call: Designator; outer: Statement): ProcedureCallStatement;
  4729. VAR caller: ProcedureCallStatement;
  4730. BEGIN
  4731. NEW(caller,position,call,outer); RETURN caller
  4732. END NewProcedureCallStatement;
  4733. PROCEDURE NewCaseStatement*( position: Position ; outer: Statement): CaseStatement;
  4734. VAR caseStatement: CaseStatement;
  4735. BEGIN
  4736. NEW( caseStatement, position,outer ); RETURN caseStatement
  4737. END NewCaseStatement;
  4738. PROCEDURE NewCasePart*(): CasePart;
  4739. VAR casePart: CasePart;
  4740. BEGIN
  4741. NEW( casePart); RETURN casePart
  4742. END NewCasePart;
  4743. PROCEDURE NewWithPart*(): WithPart;
  4744. VAR withPart: WithPart;
  4745. BEGIN
  4746. NEW( withPart); RETURN withPart
  4747. END NewWithPart;
  4748. PROCEDURE NewWithStatement*( position: Position; outer: Statement): WithStatement;
  4749. VAR withStatement: WithStatement;
  4750. BEGIN
  4751. NEW( withStatement, position, outer ); RETURN withStatement
  4752. END NewWithStatement;
  4753. PROCEDURE NewWhileStatement*( position: Position ; outer: Statement): WhileStatement;
  4754. VAR whileStatement: WhileStatement;
  4755. BEGIN
  4756. NEW( whileStatement, position,outer ); RETURN whileStatement
  4757. END NewWhileStatement;
  4758. PROCEDURE NewRepeatStatement*( position: Position ; outer: Statement): RepeatStatement;
  4759. VAR repeatStatement: RepeatStatement;
  4760. BEGIN
  4761. NEW( repeatStatement, position ,outer); RETURN repeatStatement
  4762. END NewRepeatStatement;
  4763. PROCEDURE NewForStatement*( position: Position; outer: Statement ): ForStatement;
  4764. VAR forStatement: ForStatement;
  4765. BEGIN
  4766. NEW( forStatement, position,outer ); RETURN forStatement
  4767. END NewForStatement;
  4768. PROCEDURE NewLoopStatement*( position: Position ; outer: Statement): LoopStatement;
  4769. VAR loopStatement: LoopStatement;
  4770. BEGIN
  4771. NEW( loopStatement, position ,outer); RETURN loopStatement
  4772. END NewLoopStatement;
  4773. PROCEDURE NewExitableBlock*( position: Position ; outer: Statement): ExitableBlock;
  4774. VAR loopStatement: ExitableBlock;
  4775. BEGIN
  4776. NEW( loopStatement, position ,outer); RETURN loopStatement
  4777. END NewExitableBlock;
  4778. PROCEDURE NewExitStatement*( position: Position ; outer: Statement): ExitStatement;
  4779. VAR exitStatement: ExitStatement;
  4780. BEGIN
  4781. NEW( exitStatement, position, outer); RETURN exitStatement
  4782. END NewExitStatement;
  4783. PROCEDURE NewReturnStatement*( position: Position; outer: Statement ): ReturnStatement;
  4784. VAR returnStatement: ReturnStatement;
  4785. BEGIN
  4786. NEW( returnStatement, position,outer ); RETURN returnStatement
  4787. END NewReturnStatement;
  4788. PROCEDURE NewAwaitStatement*( position: Position; outer: Statement ): AwaitStatement;
  4789. VAR awaitStatement: AwaitStatement;
  4790. BEGIN
  4791. NEW( awaitStatement, position, outer ); RETURN awaitStatement
  4792. END NewAwaitStatement;
  4793. PROCEDURE NewCode*(position: Position; outer: Statement): Code;
  4794. VAR code: Code;
  4795. BEGIN
  4796. NEW(code,position,outer); RETURN code
  4797. END NewCode;
  4798. PROCEDURE NewProcedureScope*(outer: Scope): ProcedureScope;
  4799. VAR scope: ProcedureScope;
  4800. BEGIN NEW(scope,outer); RETURN scope
  4801. END NewProcedureScope;
  4802. PROCEDURE NewModuleScope*(): ModuleScope;
  4803. VAR scope: ModuleScope;
  4804. BEGIN NEW(scope); RETURN scope
  4805. END NewModuleScope;
  4806. PROCEDURE NewRecordScope*(outer: Scope): RecordScope;
  4807. VAR scope: RecordScope;
  4808. BEGIN NEW(scope,outer); RETURN scope
  4809. END NewRecordScope;
  4810. PROCEDURE NewCellScope*(outer: Scope): CellScope;
  4811. VAR scope: CellScope;
  4812. BEGIN NEW(scope,outer); RETURN scope
  4813. END NewCellScope;
  4814. PROCEDURE NewEnumerationScope*(outer: Scope): EnumerationScope;
  4815. VAR scope: EnumerationScope;
  4816. BEGIN NEW(scope,outer); RETURN scope
  4817. END NewEnumerationScope;
  4818. PROCEDURE Init;
  4819. BEGIN;
  4820. invalidPosition.start := -1;
  4821. invalidIdentifier := Basic.invalidString;
  4822. invalidQualifiedIdentifier := NewQualifiedIdentifier(invalidPosition,invalidIdentifier,Basic.emptyString);
  4823. invalidType := NewType();
  4824. invalidDesignator := NewDesignator();
  4825. invalidDesignator.SetType(invalidType);
  4826. invalidExpression := invalidDesignator;
  4827. invalidValue := NewValue();
  4828. invalidSymbol := NewSymbol(NewIdentifier(""));
  4829. invalidSymbol.SetType(invalidType);
  4830. importType := NewType();
  4831. importType.SetState(Resolved);
  4832. typeDeclarationType := NewType();
  4833. typeDeclarationType.SetState(Resolved);
  4834. moduleType := NewType();
  4835. moduleType.SetState(Resolved);
  4836. anonymousIdentifier := NewIdentifier("");
  4837. indexListSeparator := NewDesignator();
  4838. indexListSeparator.SetType(invalidType);
  4839. END Init;
  4840. BEGIN
  4841. Init;
  4842. END FoxSyntaxTree.