FoxSyntaxTree.Mod 164 KB

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