FoxSyntaxTree.Mod 160 KB

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