2
0

FoxSyntaxTree.Mod 160 KB

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