FoxSyntaxTree.Mod 161 KB

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