FoxSyntaxTree.Mod 164 KB

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