FoxSyntaxTree.Mod 160 KB

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