2
0

FoxSyntaxTree.Mod 160 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801
  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 x:
  289. | 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. PROCEDURE &InitValue(position: Position);
  2081. BEGIN SELF.position := position; resolved := SELF;
  2082. END InitValue;
  2083. PROCEDURE Equals*(v: Value):BOOLEAN;
  2084. BEGIN HALT(100); (* abstract *) RETURN FALSE; END Equals;
  2085. END Value;
  2086. (** <<value = TRUE , FALSE>> **)
  2087. BooleanValue* = OBJECT (Value)
  2088. VAR
  2089. value-: BOOLEAN;
  2090. PROCEDURE & InitBooleanValue(position: Position; value: BOOLEAN);
  2091. BEGIN
  2092. InitValue(position); SELF.value := value;
  2093. END InitBooleanValue;
  2094. PROCEDURE SetValue*(value: BOOLEAN);
  2095. BEGIN SELF.value := value
  2096. END SetValue;
  2097. PROCEDURE Clone(): Expression;
  2098. VAR copy: BooleanValue;
  2099. BEGIN
  2100. NEW(copy, position, value); RETURN copy
  2101. END Clone;
  2102. PROCEDURE Equals*(v: Value):BOOLEAN;
  2103. BEGIN RETURN (v IS BooleanValue) & (v(BooleanValue).value = value); END Equals;
  2104. END BooleanValue;
  2105. (** <<value = 123456>> **)
  2106. IntegerValue* = OBJECT (Value)
  2107. VAR
  2108. value-: Basic.Integer;
  2109. PROCEDURE & InitIntegerValue(position: Position; value: Basic.Integer);
  2110. BEGIN
  2111. InitValue(position); SELF.value := value;
  2112. END InitIntegerValue;
  2113. PROCEDURE SetValue*(value: Basic.Integer);
  2114. BEGIN SELF.value := value;
  2115. END SetValue;
  2116. PROCEDURE Clone(): Expression;
  2117. VAR copy: IntegerValue;
  2118. BEGIN
  2119. NEW(copy, position, value); RETURN copy
  2120. END Clone;
  2121. PROCEDURE Equals*(v: Value):BOOLEAN;
  2122. BEGIN RETURN (v IS IntegerValue) & (v(IntegerValue).value = value); END Equals;
  2123. END IntegerValue;
  2124. (** <<value = 'c', 65X>> **)
  2125. CharacterValue*= OBJECT(Value)
  2126. VAR
  2127. value-: CHAR; (* potential for extension to support CHAR16 and CHAR32 *)
  2128. PROCEDURE & InitCharacterValue(position: Position; value: CHAR);
  2129. BEGIN
  2130. InitValue(position); SELF.value := value;
  2131. END InitCharacterValue;
  2132. PROCEDURE SetValue*(value: CHAR);
  2133. BEGIN SELF.value := value
  2134. END SetValue;
  2135. PROCEDURE Clone(): Expression;
  2136. VAR copy: CharacterValue;
  2137. BEGIN
  2138. NEW(copy, position, value); RETURN copy
  2139. END Clone;
  2140. PROCEDURE Equals*(v: Value):BOOLEAN;
  2141. BEGIN RETURN (v IS CharacterValue) & (v(CharacterValue).value = value); END Equals;
  2142. END CharacterValue;
  2143. SetValueType = SetValue;
  2144. (** <<value = {1,2,3..5}>> **)
  2145. SetValue* = OBJECT (Value)
  2146. VAR
  2147. value-: Basic.Set;
  2148. PROCEDURE & InitSetValue(position: Position; value: Basic.Set);
  2149. BEGIN
  2150. InitValue(position); SELF.value := value;
  2151. END InitSetValue;
  2152. PROCEDURE SetValue*(value: Basic.Set);
  2153. BEGIN SELF.value := value
  2154. END SetValue;
  2155. PROCEDURE Clone(): Expression;
  2156. VAR copy: SetValueType;
  2157. BEGIN
  2158. NEW(copy, position, value); RETURN copy
  2159. END Clone;
  2160. END SetValue;
  2161. (** << [elements] >> **)
  2162. MathArrayValue* = OBJECT (Value)
  2163. VAR array-: MathArrayExpression; (* an element of the form from .. to is represented as a RangeExpression *)
  2164. PROCEDURE & InitMathArrayValue(position: Position);
  2165. BEGIN
  2166. InitValue(position);
  2167. array := NIL;
  2168. END InitMathArrayValue;
  2169. PROCEDURE SetArray*(array: MathArrayExpression);
  2170. BEGIN SELF.array := array
  2171. END SetArray;
  2172. PROCEDURE Clone(): Expression;
  2173. VAR copy: MathArrayValue;
  2174. BEGIN
  2175. NEW(copy, position);
  2176. IF array # NIL THEN copy.array := array.Clone()(MathArrayExpression) END;
  2177. RETURN copy
  2178. END Clone;
  2179. END MathArrayValue;
  2180. (** <<value = 1.2345E01>> **)
  2181. RealValue* = OBJECT (Value)
  2182. VAR
  2183. value-: LONGREAL;
  2184. subtype-: LONGINT; (* accuracy information: REAL vs. LONGREAL *)
  2185. PROCEDURE & InitRealValue(position: Position; value: LONGREAL);
  2186. BEGIN
  2187. InitValue(position); SELF.value := value; SELF.subtype := 0;
  2188. END InitRealValue;
  2189. PROCEDURE SetValue*(value: LONGREAL);
  2190. BEGIN SELF.value := value
  2191. END SetValue;
  2192. PROCEDURE SetSubtype*(subtype: LONGINT);
  2193. BEGIN SELF.subtype := subtype;
  2194. END SetSubtype;
  2195. PROCEDURE Clone(): Expression;
  2196. VAR copy: RealValue;
  2197. BEGIN
  2198. NEW(copy, position, value); RETURN copy
  2199. END Clone;
  2200. PROCEDURE Equals*(v: Value):BOOLEAN;
  2201. BEGIN RETURN (v IS RealValue) & (v(RealValue).value = value); END Equals;
  2202. END RealValue;
  2203. ComplexValue* = OBJECT (Value)
  2204. VAR
  2205. realValue-, imagValue-: LONGREAL;
  2206. subtype-: LONGINT; (* accuracy information of components: REAL vs. LONGREAL *)
  2207. PROCEDURE & InitComplexValue(position: Position; realValue, imagValue: LONGREAL);
  2208. BEGIN
  2209. InitValue(position); SELF.realValue := realValue; SELF.imagValue := imagValue; SELF.subtype := 0;
  2210. END InitComplexValue;
  2211. PROCEDURE SetValue*(realValue, imagValue: LONGREAL);
  2212. BEGIN SELF.realValue := realValue; SELF.imagValue := imagValue;
  2213. END SetValue;
  2214. PROCEDURE UpdateSubtype*;
  2215. BEGIN
  2216. ASSERT((type # NIL) & (type.resolved # NIL) & (type.resolved IS ComplexType) & (type.resolved(ComplexType).componentType IS FloatType));
  2217. CASE type.resolved(ComplexType).componentType(FloatType).sizeInBits OF
  2218. | 32: subtype := Scanner.Real
  2219. | 64: subtype := Scanner.Longreal
  2220. END
  2221. END UpdateSubtype;
  2222. PROCEDURE SetSubtype*(subtype: LONGINT);
  2223. BEGIN SELF.subtype := subtype;
  2224. END SetSubtype;
  2225. PROCEDURE Clone(): Expression;
  2226. VAR copy: ComplexValue;
  2227. BEGIN
  2228. NEW(copy, position, realValue, imagValue); copy.subtype := subtype; RETURN copy
  2229. END Clone;
  2230. PROCEDURE Equals*(v: Value):BOOLEAN;
  2231. BEGIN RETURN (v IS ComplexValue) & (v(ComplexValue).realValue = realValue) & (v(ComplexValue).imagValue = imagValue);
  2232. (* TODO: append this?
  2233. OR (v IS RealValue) & (v(RealValue).value = realValue) & (imagValue := 0)
  2234. *)
  2235. END Equals;
  2236. END ComplexValue;
  2237. (** <<value = "string">> **)
  2238. StringValue* = OBJECT (Value)
  2239. VAR
  2240. value-: String;
  2241. length-: LONGINT;
  2242. PROCEDURE & InitStringValue(position: Position; value: String);
  2243. BEGIN
  2244. InitValue(position); SELF.value := value;
  2245. length := 0;
  2246. WHILE (length<LEN(value)) & (value[length] # 0X) DO
  2247. INC(length);
  2248. END;
  2249. IF length < LEN(value) THEN INC(length) END
  2250. END InitStringValue;
  2251. PROCEDURE SetValue*(CONST value: String);
  2252. BEGIN SELF.value := value
  2253. END SetValue;
  2254. PROCEDURE Append*(CONST value: String);
  2255. VAR new: String; len: LONGINT;
  2256. BEGIN
  2257. len := Strings.Length(SELF.value^) + Strings.Length(value^) + 1;
  2258. IF LEN(SELF.value) < len THEN
  2259. NEW(new, len);
  2260. COPY(SELF.value^, new^);
  2261. SELF.value := new
  2262. END;
  2263. Strings.Append(SELF.value^, value^);
  2264. length := len
  2265. END Append;
  2266. PROCEDURE AppendChar*(CONST ch: CHAR);
  2267. VAR v: String;
  2268. BEGIN
  2269. NEW(v,2); v[0] := ch;
  2270. Append(v);
  2271. END AppendChar;
  2272. PROCEDURE Clone(): Expression;
  2273. VAR copy: StringValue;
  2274. BEGIN
  2275. NEW(copy, position, value); RETURN copy
  2276. END Clone;
  2277. PROCEDURE Equals*(v: Value):BOOLEAN;
  2278. BEGIN RETURN (v IS StringValue) & (v(StringValue).value = value); END Equals;
  2279. END StringValue;
  2280. (** <<value = NIL>> **)
  2281. NilValue* = OBJECT (Value)
  2282. PROCEDURE Clone(): Expression;
  2283. VAR copy: NilValue;
  2284. BEGIN
  2285. NEW(copy, position); RETURN copy
  2286. END Clone;
  2287. PROCEDURE Equals*(v: Value):BOOLEAN;
  2288. BEGIN RETURN (v IS NilValue); END Equals;
  2289. END NilValue;
  2290. (** <<value = enum.x >> **)
  2291. EnumerationValue* = OBJECT (Value)
  2292. VAR
  2293. value-: Basic.Integer;
  2294. PROCEDURE & InitEnumerationValue(position: Position; value: Basic.Integer);
  2295. BEGIN
  2296. InitValue(position); SELF.value := value;
  2297. END InitEnumerationValue;
  2298. PROCEDURE SetValue*(value: Basic.Integer);
  2299. BEGIN SELF.value := value
  2300. END SetValue;
  2301. PROCEDURE Clone(): Expression;
  2302. VAR copy: EnumerationValue;
  2303. BEGIN
  2304. NEW(copy, position, value); RETURN copy
  2305. END Clone;
  2306. PROCEDURE Equals*(v: Value):BOOLEAN;
  2307. BEGIN RETURN (v IS EnumerationValue) & (v(EnumerationValue).value = value); END Equals;
  2308. END EnumerationValue;
  2309. (**** symbols ****)
  2310. Symbol*= OBJECT
  2311. VAR
  2312. nextSymbol-: Symbol;
  2313. name-: Identifier; (* constant / variable / parameter / type name / module name *)
  2314. externalName-: Scanner.StringType; (* variable / procedure *)
  2315. access-: SET; (* access flags (exported, readonly etc.) *)
  2316. type-: Type; (* type of constant / variable / parameter / procedure return type *)
  2317. scope-:Scope; (* container of symbol *)
  2318. offsetInBits-: LONGINT; (* offset in stack or heap, in bits *)
  2319. used-, written-: BOOLEAN;
  2320. fixed-: BOOLEAN;
  2321. alignment-: LONGINT;
  2322. position-, end-: Position; state-: SET;
  2323. fingerprint-: Fingerprint;
  2324. comment-: Comment;
  2325. PROCEDURE & InitSymbol(position: Position; name:Identifier);
  2326. BEGIN
  2327. SELF.position := position; state := Undefined;
  2328. SELF.end := invalidPosition;
  2329. nextSymbol := NIL;
  2330. SELF.name := name;
  2331. externalName := NIL;
  2332. scope:= NIL;
  2333. type := NIL;
  2334. access := Internal;
  2335. state := Undefined;
  2336. offsetInBits := MIN(LONGINT);
  2337. alignment := 0; (* take default *)
  2338. fixed := FALSE;
  2339. used := FALSE; written := FALSE;
  2340. comment := NIL;
  2341. END InitSymbol;
  2342. PROCEDURE SetAlignment*(fix: BOOLEAN; align: LONGINT);
  2343. BEGIN SELF.alignment := align; fixed := fix;
  2344. END SetAlignment;
  2345. PROCEDURE SetFingerprint*(CONST fp: Fingerprint);
  2346. BEGIN
  2347. SELF.fingerprint := fp
  2348. END SetFingerprint;
  2349. PROCEDURE SetState*(state: LONGINT);
  2350. BEGIN INCL(SELF.state,state);
  2351. END SetState;
  2352. PROCEDURE SetScope*(scope: Scope);
  2353. BEGIN SELF.scope := scope
  2354. END SetScope;
  2355. PROCEDURE SetType*(type: Type);
  2356. BEGIN
  2357. SELF.type := type;
  2358. END SetType;
  2359. PROCEDURE SetNext*(symbol: Symbol);
  2360. BEGIN SELF.nextSymbol := symbol; END SetNext;
  2361. PROCEDURE SetAccess*(access: SET);
  2362. BEGIN
  2363. (* consistency guarantee *)
  2364. IF PublicWrite IN access THEN ASSERT(ProtectedWrite IN access) END;
  2365. IF ProtectedWrite IN access THEN ASSERT(InternalWrite IN access) END;
  2366. IF PublicRead IN access THEN ASSERT(ProtectedRead IN access) END;
  2367. IF ProtectedRead IN access THEN ASSERT(InternalRead IN access)END;
  2368. SELF.access := access;
  2369. END SetAccess;
  2370. PROCEDURE SetOffset*(ofs: LONGINT);
  2371. BEGIN offsetInBits := ofs
  2372. END SetOffset;
  2373. PROCEDURE MarkUsed*;
  2374. BEGIN used := TRUE
  2375. END MarkUsed;
  2376. PROCEDURE MarkWritten*;
  2377. BEGIN written := TRUE
  2378. END MarkWritten;
  2379. PROCEDURE GetName*(VAR str: ARRAY OF CHAR);
  2380. BEGIN Basic.GetString(name, str);
  2381. END GetName;
  2382. PROCEDURE SetComment*(comment: Comment);
  2383. BEGIN SELF.comment := comment
  2384. END SetComment;
  2385. PROCEDURE SetExternalName*(name: Scanner.StringType);
  2386. BEGIN externalName := name;
  2387. END SetExternalName;
  2388. PROCEDURE NeedsTrace* (): BOOLEAN;
  2389. BEGIN RETURN FALSE;
  2390. END NeedsTrace;
  2391. (* If a symbol needs to be vieible in the object file
  2392. A symbol needs to be visible in an object file when it is require during linking
  2393. This is the case for exported symbols but also for methods in a method table, for instance.
  2394. *)
  2395. PROCEDURE NeedsSection*(): BOOLEAN;
  2396. BEGIN
  2397. RETURN access * Public # {};
  2398. END NeedsSection;
  2399. END Symbol;
  2400. (**
  2401. <<TYPE name = declaredType>>
  2402. TypeDeclaration symbol represents a type declaration of the form TYPE name = declaredType.
  2403. Note that the declared type is not stored in the symbol's type field but rather in the declaredType field.
  2404. The type of a type declaration is set to "typeDeclarationType" in the semantic checker
  2405. **)
  2406. TypeDeclaration*= OBJECT(Symbol)
  2407. VAR
  2408. nextTypeDeclaration-: TypeDeclaration;
  2409. declaredType-: Type;
  2410. PROCEDURE &InitTypeDeclaration(position: Position; name: Identifier);
  2411. BEGIN
  2412. InitSymbol(position,name);
  2413. nextTypeDeclaration := NIL;
  2414. declaredType := NIL;
  2415. type := typeDeclarationType;
  2416. END InitTypeDeclaration;
  2417. PROCEDURE SetDeclaredType*(type: Type);
  2418. BEGIN
  2419. declaredType := type;
  2420. IF ~(type IS BasicType) THEN
  2421. type.typeDeclaration := SELF;
  2422. END;
  2423. END SetDeclaredType;
  2424. PROCEDURE SetType*(type: Type);
  2425. BEGIN
  2426. ASSERT(type = typeDeclarationType);
  2427. END SetType;
  2428. (* type declarations should be generally included in object files *)
  2429. PROCEDURE NeedsSection*(): BOOLEAN;
  2430. BEGIN
  2431. RETURN TRUE;
  2432. END NeedsSection;
  2433. END TypeDeclaration;
  2434. (** <<CONST name = value >>
  2435. Constant declaration symbol. Represents a constant being defined in the form CONST name = value
  2436. The type of the constant is stored in the type field and is resolved by the semantic checker.
  2437. **)
  2438. Constant* = OBJECT (Symbol)
  2439. VAR
  2440. value-: Expression;
  2441. nextConstant-: Constant;
  2442. PROCEDURE & InitConstant( position: Position; name: Identifier );
  2443. BEGIN
  2444. InitSymbol(position,name);
  2445. value := NIL;
  2446. nextConstant := NIL;
  2447. END InitConstant;
  2448. PROCEDURE SetValue*( value: Expression );
  2449. BEGIN
  2450. SELF.value := value;
  2451. END SetValue;
  2452. END Constant;
  2453. (** <<VAR name: type >>
  2454. Variable declaration symbol. Represents a variable defined in the form VAR name: Type.
  2455. The type of the variable is stored in the symbol's type field and is resolved by the semantic checker.
  2456. **)
  2457. Variable* = OBJECT (Symbol)
  2458. VAR
  2459. nextVariable-: Variable;
  2460. untraced-: BOOLEAN;
  2461. fictive-: BOOLEAN; (* variable is not allocated but has a fixed offset *)
  2462. fictiveOffset-: LONGINT; (* offset of fictive as provided by the source code *)
  2463. useRegister-: BOOLEAN; registerNumber-: LONGINT;
  2464. modifiers-: Modifier;
  2465. initializer-: Expression;
  2466. usedAsReference-: BOOLEAN;
  2467. PROCEDURE & InitVariable*( position: Position; name: Identifier);
  2468. BEGIN
  2469. InitSymbol(position,name);
  2470. nextVariable := NIL;
  2471. modifiers := NIL;
  2472. untraced := FALSE;
  2473. modifiers := NIL;
  2474. useRegister := FALSE;
  2475. registerNumber := -1;
  2476. usedAsReference := FALSE;
  2477. initializer := NIL;
  2478. fictive := FALSE;
  2479. END InitVariable;
  2480. PROCEDURE UsedAsReference*;
  2481. BEGIN
  2482. usedAsReference := TRUE
  2483. END UsedAsReference;
  2484. PROCEDURE SetUntraced*(u: BOOLEAN);
  2485. BEGIN untraced := u
  2486. END SetUntraced;
  2487. PROCEDURE SetUseRegister*(u: BOOLEAN);
  2488. BEGIN
  2489. useRegister := u
  2490. END SetUseRegister;
  2491. PROCEDURE SetRegisterNumber*(reg: LONGINT);
  2492. BEGIN
  2493. registerNumber := reg
  2494. END SetRegisterNumber;
  2495. PROCEDURE SetFictive*(offset: LONGINT);
  2496. BEGIN
  2497. fictive := TRUE;
  2498. fictiveOffset := offset;
  2499. END SetFictive;
  2500. PROCEDURE SetModifiers*(flag: Modifier);
  2501. BEGIN SELF.modifiers := flag;
  2502. END SetModifiers;
  2503. PROCEDURE SetInitializer*(initializer: Expression);
  2504. BEGIN SELF.initializer := initializer;
  2505. END SetInitializer;
  2506. PROCEDURE NeedsTrace* (): BOOLEAN;
  2507. BEGIN RETURN ~untraced & (externalName = NIL) & type.NeedsTrace ();
  2508. END NeedsTrace;
  2509. END Variable;
  2510. (** << [VAR | CONST] name: type >>
  2511. Parameter declaration symbol. Represents a parameter in the form [VAR | CONST] name: Type.
  2512. The parameter's type is stored in the symbol's type field and is resolved by the semantic checker.
  2513. **)
  2514. Parameter* = OBJECT (Symbol)
  2515. VAR
  2516. nextParameter-, prevParameter-: Parameter;
  2517. modifiers-: Modifier;
  2518. defaultValue-: Expression;
  2519. kind-: LONGINT; (* ValueParameter, ConstParameter, VarParameter *)
  2520. ownerType-: Type;
  2521. untraced-: BOOLEAN;
  2522. movable-: BOOLEAN;
  2523. selfParameter-: BOOLEAN;
  2524. PROCEDURE & InitParameter( position: Position; ownerType: Type ; name: Identifier; kind: LONGINT);
  2525. BEGIN
  2526. InitSymbol( position, name );
  2527. SELF.kind := kind;
  2528. IF kind = ConstParameter THEN access := access END;
  2529. nextParameter := NIL;
  2530. SELF.ownerType := ownerType;
  2531. modifiers := NIL;
  2532. untraced := FALSE;
  2533. defaultValue := NIL;
  2534. movable := FALSE;
  2535. selfParameter := FALSE;
  2536. END InitParameter;
  2537. PROCEDURE SetModifiers*(flag: Modifier);
  2538. BEGIN SELF.modifiers := flag;
  2539. END SetModifiers;
  2540. PROCEDURE SetUntraced*(untraced: BOOLEAN);
  2541. BEGIN SELF.untraced := untraced
  2542. END SetUntraced;
  2543. PROCEDURE SetMoveable*(movable: BOOLEAN);
  2544. BEGIN SELF.movable := movable
  2545. END SetMoveable;
  2546. PROCEDURE SetSelfParameter*(b: BOOLEAN);
  2547. BEGIN
  2548. selfParameter := b;
  2549. END SetSelfParameter;
  2550. PROCEDURE SetDefaultValue*(e: Expression);
  2551. BEGIN defaultValue := e
  2552. END SetDefaultValue;
  2553. PROCEDURE SetKind*(kind: LONGINT);
  2554. BEGIN SELF.kind := kind; END SetKind;
  2555. PROCEDURE NeedsTrace* (): BOOLEAN;
  2556. BEGIN RETURN ~untraced & type.NeedsTrace ();
  2557. END NeedsTrace;
  2558. END Parameter;
  2559. Property* = OBJECT (Variable)
  2560. VAR
  2561. nextProperty-, prevProperty-: Property;
  2562. value-: Expression;
  2563. PROCEDURE & InitProperty(position: Position; name: Identifier);
  2564. BEGIN
  2565. InitSymbol( position, name );
  2566. END InitProperty;
  2567. PROCEDURE SetValue*(e: Expression);
  2568. BEGIN value := e
  2569. END SetValue;
  2570. END Property;
  2571. Alias* = OBJECT (Symbol)
  2572. VAR
  2573. expression-: Expression;
  2574. PROCEDURE & InitAlias*(position: Position; name: Identifier; e: Expression);
  2575. BEGIN
  2576. InitSymbol(position, name);
  2577. expression := e;
  2578. END InitAlias;
  2579. PROCEDURE SetExpression*(e: Expression);
  2580. BEGIN
  2581. expression := e;
  2582. END SetExpression;
  2583. END Alias;
  2584. (** Procedure declaration symbol. Represents a procedure being defined in the form PROCEDURE name(parameters): returnType;
  2585. Note that the type of a procedure is a ProcedureType (and not the return type of the procedure).
  2586. Parameters, local variables, constants and type declarations are stored in the procedureScope field.
  2587. **)
  2588. Procedure* = OBJECT (Symbol)
  2589. VAR
  2590. nextProcedure-: Procedure;
  2591. procedureScope- : ProcedureScope;
  2592. super-: Procedure;
  2593. level-, methodNumber-: LONGINT;
  2594. isBodyProcedure-, isConstructor-,isFinalizer-,isInline-,isOberonInline-, isEntry-, isExit-,isFinal-,isAbstract-,isOverwritten-: BOOLEAN;
  2595. PROCEDURE & InitProcedure( position: Position; name: Identifier; scope: ProcedureScope);
  2596. BEGIN
  2597. InitSymbol(position,name);
  2598. nextProcedure := NIL;
  2599. procedureScope := scope;
  2600. ASSERT(scope.ownerProcedure = NIL); (* cannot register twice ! *)
  2601. scope.ownerProcedure := SELF;
  2602. super := NIL;
  2603. level := 0;
  2604. methodNumber := -1;
  2605. isBodyProcedure := FALSE;
  2606. isConstructor := FALSE;
  2607. isFinalizer := FALSE;
  2608. isInline := FALSE;
  2609. isOberonInline := FALSE;
  2610. isEntry := FALSE;
  2611. isExit := FALSE;
  2612. isFinal := FALSE;
  2613. isAbstract := FALSE;
  2614. isOverwritten := FALSE;
  2615. END InitProcedure;
  2616. PROCEDURE SetSuper*(super: Procedure);
  2617. BEGIN
  2618. SELF.super := super
  2619. END SetSuper;
  2620. PROCEDURE SetBodyProcedure*(isBodyProcedure: BOOLEAN);
  2621. BEGIN SELF.isBodyProcedure := isBodyProcedure;
  2622. END SetBodyProcedure;
  2623. PROCEDURE SetConstructor*(isConstructor: BOOLEAN);
  2624. BEGIN SELF.isConstructor := isConstructor
  2625. END SetConstructor;
  2626. PROCEDURE SetFinalizer*(isFinalizer: BOOLEAN);
  2627. BEGIN SELF.isFinalizer := isFinalizer
  2628. END SetFinalizer;
  2629. PROCEDURE SetInline*(isInline: BOOLEAN);
  2630. BEGIN SELF.isInline := isInline
  2631. END SetInline;
  2632. PROCEDURE SetOberonInline*(isInline: BOOLEAN);
  2633. BEGIN SELF.isOberonInline := isInline
  2634. END SetOberonInline;
  2635. PROCEDURE SetEntry*(entry: BOOLEAN);
  2636. BEGIN SELF.isEntry := entry
  2637. END SetEntry;
  2638. PROCEDURE SetExit*(exit: BOOLEAN);
  2639. BEGIN SELF.isExit := exit
  2640. END SetExit;
  2641. PROCEDURE SetFinal*(final: BOOLEAN);
  2642. BEGIN SELF.isFinal := final
  2643. END SetFinal;
  2644. PROCEDURE SetOverwritten*(locallyOverwritten: BOOLEAN);
  2645. BEGIN SELF.isOverwritten := locallyOverwritten
  2646. END SetOverwritten;
  2647. PROCEDURE SetAbstract*(abstract: BOOLEAN);
  2648. BEGIN SELF.isAbstract := abstract
  2649. END SetAbstract;
  2650. PROCEDURE SetLevel*(level: LONGINT);
  2651. BEGIN SELF.level := level
  2652. END SetLevel;
  2653. PROCEDURE SetMethodNumber*(methodNumber: LONGINT);
  2654. BEGIN SELF.methodNumber := methodNumber
  2655. END SetMethodNumber;
  2656. PROCEDURE NeedsSection*(): BOOLEAN;
  2657. BEGIN
  2658. RETURN (access * Public # {}) OR (methodNumber >= 0);
  2659. END NeedsSection;
  2660. END Procedure;
  2661. (** Builtin symbol stands for a builtin procedure. Is resolved by the semantic checker. **)
  2662. Builtin* = OBJECT (Symbol)
  2663. VAR
  2664. nextBuiltin-: Builtin;
  2665. id-: LONGINT;
  2666. PROCEDURE & InitBuiltin(position: Position; name:Identifier; id: LONGINT);
  2667. BEGIN
  2668. InitSymbol(position,name); SELF.id := id;
  2669. END InitBuiltin;
  2670. END Builtin;
  2671. CustomBuiltin*=OBJECT (Builtin)
  2672. VAR
  2673. subType-: SHORTINT;
  2674. PROCEDURE & InitCustomBuiltin(position: Position; name: Identifier; id: LONGINT; subType: SHORTINT);
  2675. BEGIN
  2676. InitBuiltin(position,name,id);
  2677. SELF.subType := subType;
  2678. END InitCustomBuiltin;
  2679. (* TODO: check if this is correct *)
  2680. PROCEDURE CompatibleTo*(otherType: Type): BOOLEAN;
  2681. BEGIN RETURN FALSE
  2682. END CompatibleTo;
  2683. END CustomBuiltin;
  2684. Operator* = OBJECT (Procedure)
  2685. VAR
  2686. nextOperator-: Operator;
  2687. isDynamic-: BOOLEAN; (* nopov *)
  2688. PROCEDURE & InitOperator(position: Position; name: Identifier; scope: ProcedureScope);
  2689. BEGIN
  2690. InitProcedure(position,name,scope);
  2691. nextOperator := NIL;
  2692. isDynamic := FALSE
  2693. END InitOperator;
  2694. (* nopov *)
  2695. PROCEDURE SetDynamic*(isDynamic: BOOLEAN);
  2696. BEGIN SELF.isDynamic := isDynamic
  2697. END SetDynamic;
  2698. END Operator;
  2699. Import* = OBJECT (Symbol)
  2700. VAR
  2701. nextImport-: Import;
  2702. module-: Module;
  2703. moduleName-: Identifier;
  2704. context-: Identifier;
  2705. direct-: BOOLEAN; (* direct import *)
  2706. PROCEDURE & InitImport( position: Position; name, moduleName: Identifier; direct: BOOLEAN );
  2707. BEGIN
  2708. InitSymbol(position,name);
  2709. SELF.direct := direct;
  2710. module := NIL;
  2711. context := invalidIdentifier;
  2712. SELF.moduleName := moduleName;
  2713. type := importType;
  2714. END InitImport;
  2715. PROCEDURE SetType*(type: Type);
  2716. BEGIN
  2717. ASSERT(type = importType);
  2718. END SetType;
  2719. PROCEDURE SetModule*(module: Module);
  2720. BEGIN
  2721. SELF.module := module;
  2722. END SetModule;
  2723. PROCEDURE SetDirect*(d: BOOLEAN);
  2724. BEGIN
  2725. direct := d
  2726. END SetDirect;
  2727. PROCEDURE SetModuleName*(moduleName: Identifier);
  2728. BEGIN SELF.moduleName := moduleName
  2729. END SetModuleName;
  2730. PROCEDURE SetContext*(context: Identifier);
  2731. BEGIN
  2732. SELF.context := context
  2733. END SetContext;
  2734. END Import;
  2735. StatementSequence* = OBJECT
  2736. VAR
  2737. list: Basic.List;
  2738. PROCEDURE & InitList;
  2739. BEGIN NEW( list,32 );
  2740. END InitList;
  2741. PROCEDURE Length*( ): LONGINT;
  2742. BEGIN RETURN list.Length();
  2743. END Length;
  2744. PROCEDURE AddStatement*( statement: Statement);
  2745. BEGIN list.Add( statement );
  2746. END AddStatement;
  2747. PROCEDURE PrependStatement*( statement: Statement);
  2748. BEGIN list.Prepend( statement );
  2749. END PrependStatement;
  2750. PROCEDURE HasStatement*( statement: Statement):BOOLEAN;
  2751. BEGIN RETURN list.Contains(statement);
  2752. END HasStatement;
  2753. PROCEDURE GetStatement*( index: LONGINT ): Statement;
  2754. VAR p: ANY;
  2755. BEGIN p := list.Get( index ); RETURN p( Statement );
  2756. END GetStatement;
  2757. PROCEDURE SetStatement*(index: LONGINT; statement: Statement);
  2758. BEGIN
  2759. list.Set(index,statement);
  2760. END SetStatement;
  2761. PROCEDURE RemoveStatement*(statement: Statement);
  2762. BEGIN
  2763. list.Remove(statement);
  2764. END RemoveStatement;
  2765. PROCEDURE InsertBefore*(search, new: Statement);
  2766. BEGIN
  2767. list.Insert(list.IndexOf(search), new);
  2768. END InsertBefore;
  2769. PROCEDURE Clone(VAR copy: StatementSequence);
  2770. VAR i: LONGINT;
  2771. BEGIN
  2772. IF copy = NIL THEN NEW(copy) END;
  2773. FOR i := 0 TO Length()-1 DO
  2774. copy.AddStatement(CloneStatement(GetStatement(i)))
  2775. END;
  2776. END Clone;
  2777. END StatementSequence;
  2778. (**** statements ****)
  2779. Statement*= OBJECT
  2780. VAR outer-: Statement;
  2781. position-,end-: Position;
  2782. isUnreachable-: BOOLEAN;
  2783. comment-: Comment;
  2784. PROCEDURE & InitStatement*(position: Position; outer: Statement);
  2785. BEGIN
  2786. SELF.position := position;
  2787. end := invalidPosition;
  2788. SELF.outer := outer;
  2789. isUnreachable := FALSE;
  2790. comment := NIL;
  2791. END InitStatement;
  2792. PROCEDURE SetOuter*(o: Statement);
  2793. BEGIN outer := o
  2794. END SetOuter;
  2795. PROCEDURE SetUnreachable*(unreachable: BOOLEAN);
  2796. BEGIN isUnreachable := unreachable
  2797. END SetUnreachable;
  2798. PROCEDURE SetComment*(comment: Comment);
  2799. BEGIN SELF.comment := comment
  2800. END SetComment;
  2801. PROCEDURE Clone(): Statement;
  2802. BEGIN
  2803. HALT(200) (* abstract *)
  2804. END Clone;
  2805. PROCEDURE End*(pos: Position);
  2806. BEGIN
  2807. end := pos;
  2808. END End;
  2809. END Statement;
  2810. (** << call(...) >> **)
  2811. ProcedureCallStatement*= OBJECT(Statement)
  2812. VAR ignore-: BOOLEAN;
  2813. VAR call-: Designator;
  2814. PROCEDURE & InitProcedureCallStatement(position: Position; ignore: BOOLEAN; call: Designator; outer: Statement);
  2815. BEGIN InitStatement(position,outer); SELF.ignore := ignore; SELF.call := call;
  2816. END InitProcedureCallStatement;
  2817. PROCEDURE SetIgnore*(ignore: BOOLEAN);
  2818. BEGIN SELF.ignore := ignore;
  2819. END SetIgnore;
  2820. PROCEDURE SetCall*(call: Designator);
  2821. BEGIN SELF.call := call;
  2822. END SetCall;
  2823. PROCEDURE Clone(): Statement;
  2824. VAR copy: ProcedureCallStatement;
  2825. BEGIN
  2826. NEW(copy, position, ignore, CloneDesignator(call), outer);
  2827. RETURN copy
  2828. END Clone;
  2829. END ProcedureCallStatement;
  2830. (** << left := right >> **)
  2831. Assignment* = OBJECT (Statement)
  2832. VAR left-: Designator; right-: Expression;
  2833. PROCEDURE & InitAssignment*( position: Position; left: Designator; right: Expression; outer: Statement );
  2834. BEGIN
  2835. InitStatement( position,outer ); SELF.left := left; SELF.right := right;
  2836. END InitAssignment;
  2837. PROCEDURE SetLeft*(left: Designator);
  2838. BEGIN SELF.left := left
  2839. END SetLeft;
  2840. PROCEDURE SetRight*(right: Expression);
  2841. BEGIN SELF.right := right
  2842. END SetRight;
  2843. PROCEDURE Clone(): Statement;
  2844. VAR copy: Assignment;
  2845. BEGIN
  2846. NEW(copy, position, CloneDesignator(left), CloneExpression(right), outer);
  2847. RETURN copy
  2848. END Clone;
  2849. END Assignment;
  2850. (** << left ('!' | '?' | '<<' | '>>') right >> **)
  2851. CommunicationStatement* = OBJECT (Statement)
  2852. VAR
  2853. left-: Designator; right-: Expression; op-: LONGINT;
  2854. PROCEDURE & InitAssignment*( position: Position; op: LONGINT; left: Designator; right: Expression; outer: Statement );
  2855. BEGIN
  2856. InitStatement( position,outer ); SELF.op := op; SELF.left := left; SELF.right := right;
  2857. END InitAssignment;
  2858. PROCEDURE SetLeft*(left: Designator);
  2859. BEGIN SELF.left := left
  2860. END SetLeft;
  2861. PROCEDURE SetRight*(right: Expression);
  2862. BEGIN SELF.right := right
  2863. END SetRight;
  2864. END CommunicationStatement;
  2865. Part*= OBJECT
  2866. VAR
  2867. position-, end-: Position;
  2868. PROCEDURE InitPart;
  2869. BEGIN
  2870. position := invalidPosition; end := invalidPosition;
  2871. END InitPart;
  2872. PROCEDURE SetPosition*(pos: Position);
  2873. BEGIN
  2874. position := pos;
  2875. END SetPosition;
  2876. PROCEDURE SetEnd*(pos: Position);
  2877. BEGIN
  2878. end := pos;
  2879. END SetEnd;
  2880. END Part;
  2881. (** << ... condition THEN statements ... >> **)
  2882. IfPart*= OBJECT (Part)
  2883. VAR
  2884. condition-: Expression;
  2885. statements-: StatementSequence;
  2886. comment-: Comment;
  2887. PROCEDURE & InitIfPart;
  2888. BEGIN
  2889. InitPart;
  2890. statements := NIL; condition := NIL; comment := NIL;
  2891. END InitIfPart;
  2892. PROCEDURE SetCondition*(condition: Expression);
  2893. BEGIN SELF.condition := condition
  2894. END SetCondition;
  2895. PROCEDURE SetStatements*(statements: StatementSequence);
  2896. BEGIN SELF.statements := statements
  2897. END SetStatements;
  2898. PROCEDURE SetComment*(comment: Comment);
  2899. BEGIN SELF.comment := comment
  2900. END SetComment;
  2901. PROCEDURE Clone(): IfPart;
  2902. VAR copy: IfPart;
  2903. BEGIN
  2904. NEW(copy); copy.condition := CloneExpression(condition);
  2905. copy.statements := CloneStatementSequence(statements);
  2906. RETURN copy
  2907. END Clone;
  2908. END IfPart;
  2909. (** << IF ifPart {ELSIF elsifParts} ELSE elseParts >> **)
  2910. IfStatement* = OBJECT (Statement)
  2911. VAR
  2912. ifPart-: IfPart;
  2913. elsifParts: Basic.List;
  2914. elsePart-: StatementSequence;
  2915. PROCEDURE & InitIfStatement( position: Position ; outer: Statement);
  2916. BEGIN
  2917. InitStatement( position,outer ); ifPart := NewIfPart();
  2918. ifPart.SetPosition(position);
  2919. elsePart := NIL; elsifParts := NIL;
  2920. END InitIfStatement;
  2921. PROCEDURE SetElsePart*( elsePart: StatementSequence );
  2922. BEGIN
  2923. SELF.elsePart := elsePart;
  2924. END SetElsePart;
  2925. PROCEDURE AddElsifPart*( elsifPart: IfPart );
  2926. BEGIN
  2927. IF elsifParts = NIL THEN NEW(elsifParts,4); END;
  2928. elsifParts.Add( elsifPart );
  2929. END AddElsifPart;
  2930. PROCEDURE GetElsifPart*( i: LONGINT ): IfPart;
  2931. VAR a: ANY;
  2932. BEGIN a := elsifParts.Get( i ); RETURN a( IfPart )
  2933. END GetElsifPart;
  2934. PROCEDURE ElsifParts*( ): LONGINT;
  2935. BEGIN
  2936. IF elsifParts = NIL THEN RETURN 0 ELSE RETURN elsifParts.Length(); END;
  2937. END ElsifParts;
  2938. PROCEDURE Clone(): Statement;
  2939. VAR copy: IfStatement; i: LONGINT;
  2940. BEGIN
  2941. NEW(copy, position, outer);
  2942. copy.ifPart := ifPart.Clone();
  2943. FOR i := 0 TO ElsifParts()-1 DO
  2944. copy.AddElsifPart(GetElsifPart(i).Clone());
  2945. END;
  2946. copy.SetElsePart(CloneStatementSequence(elsePart));
  2947. RETURN copy
  2948. END Clone;
  2949. END IfStatement;
  2950. WithPart*= OBJECT (Part)
  2951. VAR
  2952. type-: Type; (* initially is qualified type *)
  2953. statements-: StatementSequence;
  2954. comment-: Comment;
  2955. PROCEDURE &InitWithPart();
  2956. BEGIN
  2957. InitPart();
  2958. type := NIL; statements := NIL; comment := NIL;
  2959. END InitWithPart;
  2960. PROCEDURE SetType*( type: Type );
  2961. BEGIN
  2962. SELF.type := type
  2963. END SetType;
  2964. PROCEDURE SetStatements*( statements: StatementSequence );
  2965. BEGIN
  2966. SELF.statements := statements;
  2967. END SetStatements;
  2968. PROCEDURE SetComment*(comment: Comment);
  2969. BEGIN SELF.comment := comment
  2970. END SetComment;
  2971. PROCEDURE Clone(): WithPart;
  2972. VAR copy: WithPart;
  2973. BEGIN
  2974. NEW(copy);
  2975. copy.SetType(type);
  2976. copy.SetStatements(CloneStatementSequence(statements));
  2977. RETURN copy
  2978. END Clone;
  2979. END WithPart;
  2980. (** << WITH variable : type DO statements END >> **)
  2981. WithStatement* = OBJECT (Statement)
  2982. VAR
  2983. variable-: Designator;
  2984. withParts-: Basic.List;
  2985. elsePart-: StatementSequence;
  2986. PROCEDURE & InitWithStatement( position: Position; outer: Statement );
  2987. BEGIN
  2988. InitStatement( position,outer );
  2989. NEW(withParts,4); elsePart := NIL;
  2990. variable := NIL;
  2991. END InitWithStatement;
  2992. PROCEDURE SetVariable*( variable: Designator);
  2993. BEGIN
  2994. SELF.variable := variable
  2995. END SetVariable;
  2996. PROCEDURE AddWithPart*( withPart: WithPart );
  2997. BEGIN withParts.Add( withPart );
  2998. END AddWithPart;
  2999. PROCEDURE GetWithPart*( i: LONGINT ): WithPart;
  3000. VAR a: ANY;
  3001. BEGIN a := withParts.Get( i ); RETURN a( WithPart )
  3002. END GetWithPart;
  3003. PROCEDURE WithParts*( ): LONGINT;
  3004. BEGIN
  3005. IF withParts = NIL THEN RETURN 0 ELSE RETURN withParts.Length(); END;
  3006. END WithParts;
  3007. PROCEDURE SetElsePart*( elsePart: StatementSequence );
  3008. BEGIN
  3009. SELF.elsePart := elsePart;
  3010. END SetElsePart;
  3011. PROCEDURE Clone(): Statement;
  3012. VAR copy: WithStatement; i: LONGINT;
  3013. BEGIN
  3014. NEW(copy, position, outer);
  3015. FOR i := 0 TO WithParts()-1 DO
  3016. copy.AddWithPart(GetWithPart(i).Clone());
  3017. END;
  3018. copy.SetVariable(CloneDesignator(variable));
  3019. copy.SetElsePart(CloneStatementSequence(elsePart));
  3020. RETURN copy
  3021. END Clone;
  3022. END WithStatement;
  3023. CaseConstant*= POINTER TO RECORD min*,max*: Basic.Integer; next*: CaseConstant END;
  3024. (** << elements : statements >> **)
  3025. CasePart* = OBJECT (Part)
  3026. VAR
  3027. elements-: ExpressionList; (* expression list inserted by the parser *)
  3028. firstConstant-: CaseConstant; (* expression list resolved to int32s, inserted by checker *)
  3029. statements-: StatementSequence;
  3030. comment-: Comment;
  3031. PROCEDURE & InitCasePart;
  3032. BEGIN
  3033. InitPart;
  3034. elements := NewExpressionList(); firstConstant := NIL;
  3035. END InitCasePart;
  3036. PROCEDURE SetStatements*( statements: StatementSequence );
  3037. BEGIN
  3038. SELF.statements := statements;
  3039. END SetStatements;
  3040. PROCEDURE SetConstants*(firstConstant: CaseConstant);
  3041. BEGIN SELF.firstConstant := firstConstant
  3042. END SetConstants;
  3043. PROCEDURE SetComment*(comment: Comment);
  3044. BEGIN SELF.comment := comment
  3045. END SetComment;
  3046. PROCEDURE Clone(): CasePart;
  3047. VAR copy: CasePart;
  3048. BEGIN
  3049. NEW(copy);
  3050. copy.SetStatements(CloneStatementSequence(statements));
  3051. copy.firstConstant := firstConstant;
  3052. elements.Clone(copy.elements);
  3053. RETURN copy
  3054. END Clone;
  3055. END CasePart;
  3056. (** << CASE varaible OF caseParts ELSE elsePart >> **)
  3057. CaseStatement* = OBJECT (Statement)
  3058. VAR
  3059. variable-: Expression;
  3060. elsePart-: StatementSequence;
  3061. caseParts-: Basic.List;
  3062. min-,max-: Basic.Integer;
  3063. PROCEDURE & InitCaseStatement( position: Position ; outer: Statement);
  3064. BEGIN
  3065. InitStatement(position,outer ); variable := NIL; elsePart := NIL; caseParts := NIL;
  3066. min := MAX(Basic.Integer); max := MIN(Basic.Integer);
  3067. END InitCaseStatement;
  3068. PROCEDURE SetVariable*( expression: Expression );
  3069. BEGIN SELF.variable := expression;
  3070. END SetVariable;
  3071. PROCEDURE SetElsePart*( elsePart: StatementSequence );
  3072. BEGIN SELF.elsePart := elsePart;
  3073. END SetElsePart;
  3074. PROCEDURE AddCasePart*( casePart: CasePart );
  3075. BEGIN
  3076. IF caseParts = NIL THEN NEW(caseParts,4); END;
  3077. caseParts.Add( casePart );
  3078. END AddCasePart;
  3079. PROCEDURE GetCasePart*( i: LONGINT ): CasePart;
  3080. VAR a: ANY;
  3081. BEGIN a := caseParts.Get( i ); RETURN a( CasePart )
  3082. END GetCasePart;
  3083. PROCEDURE CaseParts*( ): LONGINT;
  3084. BEGIN
  3085. IF caseParts = NIL THEN RETURN 0 ELSE RETURN caseParts.Length(); END;
  3086. END CaseParts;
  3087. PROCEDURE Clone(): Statement;
  3088. VAR copy: CaseStatement; i: LONGINT;
  3089. BEGIN
  3090. NEW(copy, position, outer);
  3091. copy.SetVariable(CloneExpression(variable));
  3092. copy.SetElsePart(CloneStatementSequence(elsePart));
  3093. FOR i := 0 TO CaseParts()-1 DO
  3094. copy.AddCasePart(GetCasePart(i).Clone());
  3095. END;
  3096. copy.min := min; copy.max := max;
  3097. RETURN copy
  3098. END Clone;
  3099. PROCEDURE MaxConstant*(): Basic.Integer;
  3100. VAR val: Basic.Integer; i: LONGINT; part: CasePart; const: CaseConstant;
  3101. BEGIN
  3102. val := -1;
  3103. FOR i := 0 TO CaseParts() - 1 DO
  3104. part := GetCasePart(i);
  3105. const := part.firstConstant;
  3106. WHILE(const # NIL) DO
  3107. IF const.max > val THEN val := const.max; END;
  3108. const := const.next;
  3109. END;
  3110. END;
  3111. RETURN val;
  3112. END MaxConstant;
  3113. PROCEDURE SetMinMax*(min,max: Basic.Integer);
  3114. BEGIN
  3115. SELF.min := min; SELF.max := max;
  3116. END SetMinMax;
  3117. END CaseStatement;
  3118. (** << WHILE condition DO statements END >> **)
  3119. WhileStatement* = OBJECT (Statement)
  3120. VAR
  3121. condition-: Expression;
  3122. statements-: StatementSequence;
  3123. PROCEDURE & InitWhileStatement( position: Position ; outer: Statement);
  3124. BEGIN
  3125. InitStatement( position,outer ); condition := NIL; statements := NIL;
  3126. END InitWhileStatement;
  3127. PROCEDURE SetCondition*( condition: Expression );
  3128. BEGIN
  3129. SELF.condition := condition
  3130. END SetCondition;
  3131. PROCEDURE SetStatements*( statements: StatementSequence );
  3132. BEGIN
  3133. SELF.statements := statements;
  3134. END SetStatements;
  3135. PROCEDURE Clone(): Statement;
  3136. VAR copy: WhileStatement;
  3137. BEGIN
  3138. NEW(copy, position, outer);
  3139. copy.SetCondition(CloneExpression(condition));
  3140. copy.SetStatements(CloneStatementSequence(statements));
  3141. RETURN copy
  3142. END Clone;
  3143. END WhileStatement;
  3144. (** << REPEAT statements UNTIL condition >> **)
  3145. RepeatStatement* = OBJECT (Statement)
  3146. VAR
  3147. condition-: Expression;
  3148. statements-: StatementSequence;
  3149. PROCEDURE & InitRepeatStatement( position: Position; outer: Statement );
  3150. BEGIN
  3151. InitStatement( position,outer ); condition := NIL; statements := NIL;
  3152. END InitRepeatStatement;
  3153. PROCEDURE SetCondition*( condition: Expression );
  3154. BEGIN
  3155. SELF.condition := condition
  3156. END SetCondition;
  3157. PROCEDURE SetStatements*( statements: StatementSequence );
  3158. BEGIN
  3159. SELF.statements := statements;
  3160. END SetStatements;
  3161. PROCEDURE Clone(): Statement;
  3162. VAR copy: RepeatStatement;
  3163. BEGIN
  3164. NEW(copy, position, outer);
  3165. copy.SetCondition(CloneExpression(condition));
  3166. copy.SetStatements(CloneStatementSequence(statements));
  3167. RETURN copy
  3168. END Clone;
  3169. END RepeatStatement;
  3170. (** << FOR variable := from TO to BY by DO statements END >> **)
  3171. ForStatement* = OBJECT (Statement)
  3172. VAR
  3173. variable-: Designator;
  3174. from-, to-, by-: Expression;
  3175. statements-: StatementSequence;
  3176. PROCEDURE & InitForStatement( position: Position; outer: Statement );
  3177. BEGIN
  3178. InitStatement( position,outer ); variable := NIL;from := NIL; to := NIL; by := NIL; statements := NIL;
  3179. END InitForStatement;
  3180. PROCEDURE SetVariable*( variable: Designator);
  3181. BEGIN
  3182. SELF.variable := variable
  3183. END SetVariable;
  3184. PROCEDURE SetFrom*( from: Expression );
  3185. BEGIN
  3186. SELF.from := from
  3187. END SetFrom;
  3188. PROCEDURE SetTo*( to: Expression );
  3189. BEGIN
  3190. SELF.to := to
  3191. END SetTo;
  3192. PROCEDURE SetBy*( by: Expression );
  3193. BEGIN SELF.by := by
  3194. END SetBy;
  3195. PROCEDURE SetStatements*( statements: StatementSequence );
  3196. BEGIN SELF.statements := statements;
  3197. END SetStatements;
  3198. PROCEDURE Clone(): Statement;
  3199. VAR copy: ForStatement;
  3200. BEGIN
  3201. NEW(copy, position, outer);
  3202. copy.SetVariable(CloneDesignator(variable));
  3203. copy.SetFrom(CloneExpression(from));
  3204. copy.SetTo(CloneExpression(to));
  3205. copy.SetBy(CloneExpression(by));
  3206. copy.SetStatements(CloneStatementSequence(statements));
  3207. RETURN copy
  3208. END Clone;
  3209. END ForStatement;
  3210. ExitableBlock*= OBJECT (Statement)
  3211. VAR statements-: StatementSequence;
  3212. PROCEDURE & InitExitableBlock( position: Position ; outer: Statement);
  3213. BEGIN
  3214. InitStatement( position ,outer); statements := NIL;
  3215. END InitExitableBlock;
  3216. PROCEDURE SetStatements*( statements: StatementSequence );
  3217. BEGIN SELF.statements := statements;
  3218. END SetStatements;
  3219. PROCEDURE Clone(): Statement;
  3220. VAR copy: ExitableBlock;
  3221. BEGIN
  3222. NEW(copy, position, outer);
  3223. copy.SetStatements(CloneStatementSequence(statements));
  3224. RETURN copy
  3225. END Clone;
  3226. END ExitableBlock;
  3227. (** << LOOP statements END >> **)
  3228. LoopStatement* = OBJECT (ExitableBlock)
  3229. PROCEDURE Clone(): Statement;
  3230. VAR copy: LoopStatement;
  3231. BEGIN
  3232. NEW(copy, position, outer);
  3233. copy.SetStatements(CloneStatementSequence(statements));
  3234. RETURN copy
  3235. END Clone;
  3236. END LoopStatement;
  3237. (** << EXIT >> **)
  3238. ExitStatement* = OBJECT (Statement)
  3239. PROCEDURE Clone(): Statement;
  3240. VAR copy: ExitStatement;
  3241. BEGIN
  3242. NEW(copy, position, outer);
  3243. RETURN copy
  3244. END Clone;
  3245. END ExitStatement;
  3246. (** << RETURN returnValue >> **)
  3247. ReturnStatement* = OBJECT (Statement)
  3248. VAR returnValue-: Expression; (* strictly speaking this is not a value but this term is in common use here *)
  3249. PROCEDURE & InitReturnStatement( position: Position ; outer: Statement);
  3250. BEGIN
  3251. InitStatement( position,outer ); returnValue := NIL
  3252. END InitReturnStatement;
  3253. PROCEDURE SetReturnValue*( returnValue: Expression );
  3254. BEGIN SELF.returnValue := returnValue
  3255. END SetReturnValue;
  3256. PROCEDURE Clone(): Statement;
  3257. VAR copy: ReturnStatement;
  3258. BEGIN
  3259. NEW(copy, position, outer);
  3260. copy.SetReturnValue(CloneExpression(returnValue));
  3261. RETURN copy
  3262. END Clone;
  3263. END ReturnStatement;
  3264. (** << AWAIT condition >> **)
  3265. AwaitStatement* = OBJECT (Statement)
  3266. VAR condition-: Expression;
  3267. PROCEDURE & InitAwaitStatement( position: Position; outer: Statement );
  3268. BEGIN
  3269. InitStatement( position,outer ); condition := NIL
  3270. END InitAwaitStatement;
  3271. PROCEDURE SetCondition*( condition: Expression );
  3272. BEGIN SELF.condition := condition
  3273. END SetCondition;
  3274. PROCEDURE Clone(): Statement;
  3275. VAR copy: AwaitStatement;
  3276. BEGIN
  3277. NEW(copy, position, outer);
  3278. copy.SetCondition(CloneExpression(condition));
  3279. RETURN copy
  3280. END Clone;
  3281. END AwaitStatement;
  3282. (* << Identifier ( Expression) >> *)
  3283. Modifier*= OBJECT
  3284. VAR
  3285. identifier-: Identifier; expression-: Expression;
  3286. resolved-: BOOLEAN;
  3287. nextModifier-: Modifier;
  3288. position-: Position;
  3289. PROCEDURE & InitModifier(position: Position; identifier: Identifier; expression: Expression);
  3290. BEGIN
  3291. SELF.position := position;
  3292. SELF.identifier := identifier; SELF.expression := expression; nextModifier := NIL; resolved := FALSE;
  3293. END InitModifier;
  3294. PROCEDURE Resolved*;
  3295. BEGIN resolved := TRUE
  3296. END Resolved;
  3297. PROCEDURE SetExpression*(e: Expression);
  3298. BEGIN SELF.expression := e
  3299. END SetExpression;
  3300. PROCEDURE SetNext*(modifier: Modifier);
  3301. BEGIN nextModifier := modifier
  3302. END SetNext;
  3303. END Modifier;
  3304. (** << BEGIN {Modifier, Modifier ... } statements END >> **)
  3305. StatementBlock* = OBJECT (Statement)
  3306. VAR
  3307. statements-: StatementSequence;
  3308. blockModifiers-: Modifier;
  3309. isExclusive-: BOOLEAN;
  3310. isRealtime-: BOOLEAN;
  3311. isUnchecked-: BOOLEAN;
  3312. isUncooperative-: BOOLEAN;
  3313. scope-: Scope;
  3314. PROCEDURE & InitStatementBlock( position: Position ; outer: Statement; s: Scope);
  3315. BEGIN
  3316. InitStatement( position ,outer); statements := NIL; blockModifiers := NIL;
  3317. isExclusive := FALSE;
  3318. isRealtime := FALSE;
  3319. isUnchecked := FALSE;
  3320. isUncooperative := FALSE;
  3321. scope := s;
  3322. END InitStatementBlock;
  3323. PROCEDURE SetRealtime*(b: BOOLEAN);
  3324. BEGIN
  3325. isRealtime := b
  3326. END SetRealtime;
  3327. PROCEDURE SetUnchecked*(unchecked: BOOLEAN);
  3328. BEGIN
  3329. isUnchecked := unchecked
  3330. END SetUnchecked;
  3331. PROCEDURE SetUncooperative*(uncooperative: BOOLEAN);
  3332. BEGIN
  3333. isUncooperative := uncooperative
  3334. END SetUncooperative;
  3335. PROCEDURE SetModifier*(modifier: Modifier);
  3336. BEGIN
  3337. blockModifiers := modifier;
  3338. END SetModifier;
  3339. PROCEDURE SetExclusive*(excl: BOOLEAN);
  3340. BEGIN isExclusive := excl
  3341. END SetExclusive;
  3342. PROCEDURE SetStatementSequence*( statements: StatementSequence );
  3343. BEGIN SELF.statements := statements;
  3344. END SetStatementSequence;
  3345. END StatementBlock;
  3346. (** << CODE {flags} {character} END >> **)
  3347. Code*= OBJECT(Statement)
  3348. VAR
  3349. sourceCode-: SourceCode; sourceCodeLength-: LONGINT;
  3350. inlineCode-: BinaryCode;
  3351. inRules-, outRules-: StatementSequence;
  3352. PROCEDURE & InitCode(position: Position; outer: Statement);
  3353. BEGIN
  3354. InitStatement(position,outer);
  3355. inlineCode := NIL;
  3356. sourceCode := NIL; sourceCodeLength := 0;
  3357. NEW(inRules); NEW(outRules);
  3358. END InitCode;
  3359. PROCEDURE SetSourceCode*(source: SourceCode; length: LONGINT);
  3360. BEGIN sourceCode := source; sourceCodeLength := length;
  3361. ASSERT(sourceCodeLength <= LEN(source));
  3362. END SetSourceCode;
  3363. PROCEDURE SetBinaryCode*(code: BinaryCode);
  3364. BEGIN
  3365. inlineCode := code;
  3366. END SetBinaryCode;
  3367. PROCEDURE Clone(): Statement;
  3368. VAR copy: Code; s: Scanner.StringType;
  3369. BEGIN
  3370. NEW(copy, position, outer);
  3371. NEW(s, sourceCodeLength);
  3372. Strings.Copy(sourceCode^,0,sourceCodeLength,s^);
  3373. copy.SetSourceCode(s, sourceCodeLength);
  3374. copy.inRules := CloneStatementSequence(inRules);
  3375. copy.outRules := CloneStatementSequence(outRules);
  3376. RETURN copy
  3377. END Clone;
  3378. END Code;
  3379. (** << BEGIN {flags} statements FINALLY statements END >> **)
  3380. Body*= OBJECT(StatementBlock)
  3381. VAR
  3382. finally-: StatementSequence;
  3383. priority-: Expression; (* set by checker *)
  3384. inScope-: ProcedureScope;
  3385. code-: Code;
  3386. isActive-, isSafe-: BOOLEAN;
  3387. PROCEDURE & InitBody(position: Position; scope: ProcedureScope);
  3388. BEGIN
  3389. InitStatementBlock(position,NIL,NIL); finally := NIL; priority := NIL; inScope := scope; code := NIL;
  3390. isActive := FALSE; isSafe := FALSE; isRealtime := FALSE;
  3391. END InitBody;
  3392. PROCEDURE SetActive*(active: BOOLEAN);
  3393. BEGIN SELF.isActive := active
  3394. END SetActive;
  3395. PROCEDURE SetSafe*(safe: BOOLEAN);
  3396. BEGIN SELF.isSafe := safe
  3397. END SetSafe;
  3398. PROCEDURE SetFinally*( finally: StatementSequence );
  3399. BEGIN SELF.finally := finally
  3400. END SetFinally;
  3401. PROCEDURE SetPriority*(expression: Expression);
  3402. BEGIN priority := expression
  3403. END SetPriority;
  3404. PROCEDURE SetCode*(code: Code);
  3405. BEGIN SELF.code := code;
  3406. END SetCode;
  3407. END Body;
  3408. (** (* comment *) *)
  3409. Comment*=OBJECT
  3410. VAR position-: Position;
  3411. source-: String; (* currently: POINTER TO ARRAY OF CHAR *)
  3412. scope-: Scope;
  3413. item-: ANY; sameLine-: BOOLEAN;
  3414. nextComment-: Comment;
  3415. PROCEDURE & InitComment(pos: Position; scope: Scope; CONST s: ARRAY OF CHAR; length: LONGINT);
  3416. VAR i: LONGINT;
  3417. BEGIN
  3418. SELF.scope := scope;
  3419. NEW(source,length);
  3420. FOR i := 0 TO length-1 DO
  3421. source[i] := s[i];
  3422. END;
  3423. SELF.position := pos;
  3424. nextComment := NIL;
  3425. item := NIL; sameLine := FALSE;
  3426. END InitComment;
  3427. PROCEDURE SetItem*(p: ANY; sameLine: BOOLEAN);
  3428. BEGIN
  3429. item := p; SELF.sameLine := sameLine
  3430. END SetItem;
  3431. END Comment;
  3432. (**** building blocks ****)
  3433. Scope*=OBJECT
  3434. VAR
  3435. firstSymbol-: Symbol; numberSymbols-: LONGINT; (* all symbols in scope (sorted) *)
  3436. symbolTable: Basic.HashTableInt;
  3437. firstConstant-,lastConstant-: Constant; numberConstants-: LONGINT; (* constants *)
  3438. firstTypeDeclaration-,lastTypeDeclaration-: TypeDeclaration; numberTypeDeclarations-: LONGINT; (* type declarations *)
  3439. firstVariable-,lastVariable-: Variable; numberVariables-: LONGINT; (* variables *)
  3440. firstProcedure-,lastProcedure-: Procedure; numberProcedures-: LONGINT; (* procedures *)
  3441. procedures-: ProcedureList;
  3442. outerScope-: Scope; nextScope-: Scope;
  3443. ownerModule-: Module;
  3444. PROCEDURE & InitScope(outer: Scope);
  3445. BEGIN
  3446. firstSymbol := NIL; numberSymbols := 0;
  3447. firstConstant := NIL; lastConstant := NIL; numberConstants := 0;
  3448. firstTypeDeclaration := NIL; lastTypeDeclaration := NIL; numberTypeDeclarations := 0;
  3449. firstVariable := NIL; lastVariable := NIL; numberVariables := 0;
  3450. firstProcedure := NIL; lastProcedure := NIL; numberProcedures := 0;
  3451. outerScope := outer;
  3452. IF outer # NIL THEN
  3453. ownerModule := outer.ownerModule
  3454. ELSE
  3455. ownerModule := NIL;
  3456. END;
  3457. nextScope := NIL;
  3458. NEW(symbolTable,11);
  3459. END InitScope;
  3460. PROCEDURE Clear*;
  3461. BEGIN
  3462. firstConstant := NIL; lastConstant := NIL; numberConstants := 0;
  3463. firstTypeDeclaration := NIL; lastTypeDeclaration := NIL; numberTypeDeclarations := 0;
  3464. firstVariable := NIL; lastVariable := NIL; numberVariables := 0;
  3465. firstProcedure := NIL; lastProcedure := NIL; numberProcedures := 0;
  3466. END Clear;
  3467. (** Enter a symbol in the scope, aplhabetically sorted, duplicate = TRUE if multiply identifier *)
  3468. PROCEDURE EnterSymbol*(symbol: Symbol; VAR duplicate: BOOLEAN);
  3469. VAR p,q: Symbol;
  3470. BEGIN
  3471. ASSERT(symbol.nextSymbol = NIL,101); (* symbol may only be present in one scope at a time ! *)
  3472. ASSERT(symbol.scope = NIL,102);
  3473. ASSERT(symbol.name # invalidIdentifier,103);
  3474. p := firstSymbol; q := NIL;
  3475. WHILE (p # NIL) & (StringPool.CompareString(p.name,symbol.name)<0) DO q := p; p := p.nextSymbol END;
  3476. IF (p#NIL) & (symbol.name = p.name) THEN
  3477. duplicate := TRUE;
  3478. ELSE
  3479. duplicate := FALSE
  3480. END;
  3481. symbol.nextSymbol := p;
  3482. IF q = NIL THEN firstSymbol := symbol ELSE q.nextSymbol := symbol END;
  3483. symbol.SetScope(SELF);
  3484. symbolTable.Put(symbol.name,symbol);
  3485. INC(numberSymbols);
  3486. END EnterSymbol;
  3487. (** Find symbol by name *)
  3488. PROCEDURE FindSymbol*(identifier: Identifier): Symbol;
  3489. VAR p: Symbol; a: ANY;
  3490. BEGIN
  3491. IF identifier # invalidIdentifier THEN
  3492. a := symbolTable.Get(identifier);
  3493. IF (a # NIL) & ~(a IS Operator) THEN
  3494. p := a(Symbol);
  3495. END;
  3496. (*
  3497. p := firstSymbol;
  3498. WHILE(p#NIL) & ((p.name # identifier) OR (p IS Operator)) DO p := p.nextSymbol END;
  3499. *)
  3500. END;
  3501. RETURN p;
  3502. END FindSymbol;
  3503. PROCEDURE AddConstant*(c: Constant);
  3504. BEGIN
  3505. ASSERT(c # NIL);
  3506. IF lastConstant= NIL THEN firstConstant := c ELSE lastConstant.nextConstant := c END;
  3507. lastConstant := c;
  3508. INC(numberConstants);
  3509. END AddConstant;
  3510. PROCEDURE FindConstant*(identifier: Identifier): Constant;
  3511. VAR p: Constant;
  3512. BEGIN
  3513. p := firstConstant;
  3514. WHILE(p#NIL) & (p.name # identifier) DO p := p.nextConstant END;
  3515. RETURN p;
  3516. END FindConstant;
  3517. PROCEDURE AddTypeDeclaration*(t: TypeDeclaration);
  3518. BEGIN
  3519. ASSERT(t # NIL);
  3520. IF lastTypeDeclaration= NIL THEN firstTypeDeclaration := t ELSE lastTypeDeclaration.nextTypeDeclaration := t END;
  3521. INC(numberTypeDeclarations);
  3522. lastTypeDeclaration := t;
  3523. END AddTypeDeclaration;
  3524. PROCEDURE FindTypeDeclaration*(identifier: Identifier): TypeDeclaration;
  3525. VAR p: TypeDeclaration;
  3526. BEGIN
  3527. p := firstTypeDeclaration;
  3528. WHILE(p#NIL) & (p.name # identifier) DO p := p.nextTypeDeclaration END;
  3529. RETURN p;
  3530. END FindTypeDeclaration;
  3531. PROCEDURE AddVariable*(v: Variable);
  3532. BEGIN
  3533. ASSERT(v # NIL);
  3534. IF lastVariable= NIL THEN firstVariable := v ELSE lastVariable.nextVariable := v END;
  3535. INC(numberVariables);
  3536. lastVariable := v;
  3537. END AddVariable;
  3538. PROCEDURE PushVariable*(v: Variable);
  3539. BEGIN
  3540. ASSERT(v # NIL);
  3541. IF lastVariable= NIL THEN lastVariable := v ELSE v.nextVariable := firstVariable END;
  3542. INC(numberVariables);
  3543. firstVariable := v;
  3544. END PushVariable;
  3545. (* insert variable after variable in list -- can be important to keep variable offsets in order *)
  3546. (* pre: v # NIL, after # NIL *)
  3547. PROCEDURE InsertVariable*(v: Variable; after: Variable);
  3548. BEGIN
  3549. ASSERT(v # NIL);
  3550. ASSERT(after # NIL);
  3551. v.nextVariable := after.nextVariable;
  3552. after.nextVariable := v;
  3553. IF after = lastVariable THEN lastVariable := v END;
  3554. END InsertVariable;
  3555. PROCEDURE FindVariable*(identifier: Identifier): Variable;
  3556. VAR p: Variable;
  3557. BEGIN
  3558. p := firstVariable;
  3559. WHILE(p#NIL) & (p.name # identifier) DO p := p.nextVariable END;
  3560. RETURN p;
  3561. END FindVariable;
  3562. PROCEDURE AddProcedure*(p: Procedure);
  3563. BEGIN
  3564. ASSERT(p # NIL);
  3565. IF lastProcedure= NIL THEN firstProcedure := p ELSE lastProcedure.nextProcedure := p END;
  3566. INC(numberProcedures);
  3567. lastProcedure := p;
  3568. END AddProcedure;
  3569. PROCEDURE AddProcedureDeclaration*(p: Procedure);
  3570. BEGIN
  3571. IF procedures = NIL THEN NEW(procedures) END;
  3572. procedures.AddProcedure(p);
  3573. END AddProcedureDeclaration;
  3574. PROCEDURE FindProcedure*(identifier: Identifier): Procedure;
  3575. VAR p: Procedure;
  3576. BEGIN
  3577. p := firstProcedure;
  3578. WHILE (p#NIL) & ((p.name # identifier) OR (p IS Operator)) DO p := p.nextProcedure END;
  3579. RETURN p;
  3580. END FindProcedure;
  3581. PROCEDURE FindMethod*(number: LONGINT): Procedure;
  3582. VAR p: Procedure;
  3583. BEGIN
  3584. p := firstProcedure;
  3585. WHILE (p# NIL) & (p.methodNumber # number) DO
  3586. p := p.nextProcedure
  3587. END;
  3588. RETURN p;
  3589. END FindMethod;
  3590. PROCEDURE Level*(): LONGINT;
  3591. VAR scope: Scope; level: LONGINT;
  3592. BEGIN
  3593. level := 0;
  3594. scope := SELF;
  3595. WHILE(scope.outerScope # NIL) DO
  3596. scope := scope.outerScope;
  3597. INC(level);
  3598. END;
  3599. RETURN level;
  3600. END Level;
  3601. PROCEDURE NeedsTrace* (): BOOLEAN;
  3602. VAR variable: Variable;
  3603. BEGIN
  3604. variable := firstVariable;
  3605. WHILE variable # NIL DO
  3606. IF variable.NeedsTrace () THEN RETURN TRUE END;
  3607. variable := variable.nextVariable;
  3608. END;
  3609. RETURN FALSE;
  3610. END NeedsTrace;
  3611. END Scope;
  3612. ProcedureScope*=OBJECT (Scope)
  3613. VAR
  3614. ownerProcedure-: Procedure;
  3615. body-: Body;
  3616. PROCEDURE & InitProcedureScope(outer: Scope);
  3617. BEGIN
  3618. InitScope(outer);
  3619. ownerProcedure := NIL;
  3620. body := NIL;
  3621. END InitProcedureScope;
  3622. PROCEDURE SetBody*(body: Body);
  3623. BEGIN
  3624. SELF.body := body;
  3625. END SetBody;
  3626. PROCEDURE NeedsTrace* (): BOOLEAN;
  3627. VAR parameter: Parameter;
  3628. BEGIN
  3629. parameter := ownerProcedure.type.resolved(ProcedureType).firstParameter;
  3630. WHILE parameter # NIL DO
  3631. IF parameter.NeedsTrace () THEN RETURN TRUE END;
  3632. parameter := parameter.nextParameter;
  3633. END;
  3634. RETURN NeedsTrace^();
  3635. END NeedsTrace;
  3636. END ProcedureScope;
  3637. BlockScope* = OBJECT(Scope)
  3638. END BlockScope;
  3639. EnumerationScope*= OBJECT(Scope)
  3640. VAR
  3641. ownerEnumeration-: EnumerationType;
  3642. (** Find symbol by name *)
  3643. PROCEDURE FindSymbol*(identifier: Identifier): Symbol;
  3644. VAR p: Symbol; base: Type;
  3645. BEGIN
  3646. p := FindSymbol^(identifier);
  3647. IF p = NIL THEN
  3648. base := ownerEnumeration.enumerationBase;
  3649. IF (base # NIL) & (base.resolved IS EnumerationType) THEN
  3650. p := base.resolved(EnumerationType).enumerationScope.FindSymbol(identifier)
  3651. END;
  3652. END;
  3653. RETURN p;
  3654. END FindSymbol;
  3655. PROCEDURE &InitEnumerationScope(outer: Scope);
  3656. BEGIN
  3657. InitScope(outer);
  3658. ownerEnumeration := NIL; (* must be set by EnumerationType *)
  3659. END InitEnumerationScope;
  3660. END EnumerationScope;
  3661. RecordScope*= OBJECT(Scope)
  3662. VAR
  3663. ownerRecord-: RecordType;
  3664. bodyProcedure-: Procedure;
  3665. constructor-: Procedure;
  3666. finalizer-: Procedure;
  3667. numberMethods-: LONGINT;
  3668. firstParameter-,lastParameter-: Parameter; numberParameters-: LONGINT; (* parameters for Active Cells programming*)
  3669. firstOperator-, lastOperator-: Operator; numberOperators: LONGINT; (* defined operators *)
  3670. PROCEDURE & InitRecordScope(outer: Scope);
  3671. BEGIN
  3672. InitScope(outer);
  3673. ownerRecord := NIL;
  3674. numberMethods := 0;
  3675. bodyProcedure := NIL;
  3676. constructor := NIL;
  3677. finalizer := NIL;
  3678. firstOperator := NIL; lastOperator := NIL; numberOperators := 0;
  3679. END InitRecordScope;
  3680. PROCEDURE SetBodyProcedure*(body: Procedure);
  3681. BEGIN SELF.bodyProcedure := body;
  3682. END SetBodyProcedure;
  3683. PROCEDURE SetConstructor*(body: Procedure);
  3684. BEGIN SELF.constructor := body
  3685. END SetConstructor;
  3686. PROCEDURE SetFinalizer*(body: Procedure);
  3687. BEGIN SELF.finalizer := body
  3688. END SetFinalizer;
  3689. PROCEDURE SetNumberMethods*(numberMethods: LONGINT);
  3690. BEGIN SELF.numberMethods := numberMethods;
  3691. END SetNumberMethods;
  3692. PROCEDURE AddOperator*(p: Operator);
  3693. BEGIN
  3694. ASSERT(p # NIL);
  3695. IF lastOperator= NIL THEN firstOperator := p ELSE lastOperator.nextOperator := p END;
  3696. INC(numberOperators);
  3697. lastOperator := p;
  3698. END AddOperator;
  3699. (** Find symbol by name *)
  3700. PROCEDURE FindSymbol*(identifier: Identifier): Symbol;
  3701. VAR p: Symbol; base: RecordType;
  3702. BEGIN
  3703. p := FindSymbol^(identifier);
  3704. IF p = NIL THEN
  3705. base := ownerRecord.GetBaseRecord();
  3706. IF (base # NIL) THEN
  3707. p := base.recordScope.FindSymbol(identifier)
  3708. END;
  3709. END;
  3710. RETURN p;
  3711. END FindSymbol;
  3712. (* if there is an abstract procedure in the scope, return it. Otherwise return nil *)
  3713. PROCEDURE AbstractProcedure*(inScope: Scope): Procedure;
  3714. VAR p: Procedure; s: Symbol; base: RecordType;
  3715. BEGIN
  3716. p := firstProcedure;
  3717. WHILE p # NIL DO
  3718. IF p.isAbstract THEN
  3719. IF inScope # SELF THEN (* elevate to mother scope, if necesary *)
  3720. s := inScope.FindSymbol(p.name);
  3721. IF s = p THEN (* procedure is not overwritten *)
  3722. RETURN p
  3723. ELSE
  3724. ASSERT(s # NIL);
  3725. ASSERT(s IS Procedure);
  3726. END;
  3727. ELSE
  3728. RETURN p
  3729. END;
  3730. END;
  3731. p := p.nextProcedure;
  3732. END;
  3733. base := ownerRecord.GetBaseRecord();
  3734. IF (base # NIL) THEN
  3735. RETURN base.recordScope.AbstractProcedure(inScope);
  3736. END;
  3737. RETURN NIL;
  3738. END AbstractProcedure;
  3739. PROCEDURE FindConstant*(identifier: Identifier): Constant;
  3740. VAR p: Constant; base: RecordType;
  3741. BEGIN
  3742. p := FindConstant^(identifier);
  3743. IF p = NIL THEN
  3744. base := ownerRecord.GetBaseRecord();
  3745. IF (base # NIL) THEN
  3746. p := base.recordScope.FindConstant(identifier)
  3747. END;
  3748. END;
  3749. RETURN p;
  3750. END FindConstant;
  3751. PROCEDURE FindTypeDeclaration*(identifier: Identifier): TypeDeclaration;
  3752. VAR p: TypeDeclaration; base: RecordType;
  3753. BEGIN
  3754. p := FindTypeDeclaration^(identifier);
  3755. IF p = NIL THEN
  3756. base := ownerRecord.GetBaseRecord();
  3757. IF (base # NIL) THEN
  3758. p := base.recordScope.FindTypeDeclaration(identifier)
  3759. END;
  3760. END;
  3761. RETURN p;
  3762. END FindTypeDeclaration;
  3763. PROCEDURE FindVariable*(identifier: Identifier): Variable;
  3764. VAR p: Variable; base: RecordType;
  3765. BEGIN
  3766. p := FindVariable^(identifier);
  3767. IF p = NIL THEN
  3768. base := ownerRecord.GetBaseRecord();
  3769. IF (base # NIL) THEN
  3770. p := base.recordScope.FindVariable(identifier)
  3771. END;
  3772. END;
  3773. RETURN p;
  3774. END FindVariable;
  3775. PROCEDURE FindProcedure*(identifier: Identifier): Procedure;
  3776. VAR p: Procedure; base: RecordType;
  3777. BEGIN
  3778. p := FindProcedure^(identifier);
  3779. IF p = NIL THEN
  3780. base := ownerRecord.GetBaseRecord();
  3781. IF (base # NIL) THEN
  3782. p := base.recordScope.FindProcedure(identifier)
  3783. END;
  3784. END;
  3785. RETURN p;
  3786. END FindProcedure;
  3787. PROCEDURE FindMethod*(number: LONGINT): Procedure;
  3788. VAR p: Procedure; base: RecordType;
  3789. BEGIN
  3790. p := FindMethod^(number);
  3791. IF p = NIL THEN
  3792. base := ownerRecord.GetBaseRecord();
  3793. IF (base # NIL) THEN
  3794. p := base.recordScope.FindMethod(number)
  3795. END;
  3796. END;
  3797. RETURN p;
  3798. END FindMethod;
  3799. PROCEDURE NeedsTrace* (): BOOLEAN;
  3800. VAR base: RecordType;
  3801. BEGIN
  3802. base := ownerRecord.GetBaseRecord();
  3803. IF (base # NIL) & (base.NeedsTrace ()) THEN RETURN TRUE END;
  3804. RETURN NeedsTrace^();
  3805. END NeedsTrace;
  3806. END RecordScope;
  3807. CellScope*=OBJECT (Scope)
  3808. VAR
  3809. ownerCell-: CellType;
  3810. bodyProcedure-: Procedure;
  3811. constructor-: Procedure;
  3812. firstImport-,lastImport-: Import; numberImports: LONGINT; (* imported modules *)
  3813. PROCEDURE & InitCellScope(outer: Scope);
  3814. BEGIN
  3815. InitScope(outer);
  3816. ownerCell := NIL;
  3817. bodyProcedure := NIL;
  3818. constructor := NIL;
  3819. firstImport := NIL; lastImport := NIL; numberImports := 0;
  3820. END InitCellScope;
  3821. PROCEDURE Clear*;
  3822. BEGIN
  3823. Clear^;
  3824. firstImport := NIL; lastImport := NIL; numberImports := 0;
  3825. constructor := NIL;
  3826. bodyProcedure := NIL;
  3827. END Clear;
  3828. PROCEDURE SetOwnerCell*(owner: CellType);
  3829. BEGIN
  3830. ownerCell := owner
  3831. END SetOwnerCell;
  3832. PROCEDURE SetBodyProcedure*(bodyProcedure: Procedure);
  3833. BEGIN
  3834. SELF.bodyProcedure := bodyProcedure;
  3835. END SetBodyProcedure;
  3836. PROCEDURE SetConstructor*(p: Procedure);
  3837. BEGIN constructor := p
  3838. END SetConstructor;
  3839. PROCEDURE AddImport*(i: Import);
  3840. BEGIN
  3841. ASSERT(i # NIL);
  3842. ASSERT(i.nextImport = NIL);
  3843. IF lastImport= NIL THEN firstImport:= i ELSE lastImport.nextImport := i END;
  3844. lastImport := i;
  3845. INC(numberImports);
  3846. END AddImport;
  3847. PROCEDURE FindImport*(identifier: Identifier): Import;
  3848. VAR p: Import;
  3849. BEGIN
  3850. p := firstImport;
  3851. WHILE(p#NIL) & (p.name # identifier) DO p := p.nextImport END; (* finds imports and re-imports! *)
  3852. RETURN p;
  3853. END FindImport;
  3854. PROCEDURE GetImport*( index: LONGINT ): Import;
  3855. VAR import: Import;
  3856. BEGIN
  3857. import := firstImport;
  3858. WHILE(import # NIL) & (index > 0) DO
  3859. import := import.nextImport;
  3860. DEC(index);
  3861. END;
  3862. RETURN import;
  3863. END GetImport;
  3864. PROCEDURE FindSymbol*(identifier: Identifier): Symbol;
  3865. VAR p: Symbol; base: Type;
  3866. BEGIN
  3867. p := FindSymbol^(identifier);
  3868. IF p = NIL THEN
  3869. IF ownerCell.isCellNet THEN
  3870. RETURN ownerCell.FindProperty(identifier);
  3871. END;
  3872. END;
  3873. IF p = NIL THEN
  3874. base := ownerCell.baseType;
  3875. IF (base # NIL) THEN
  3876. base := base.resolved;
  3877. IF base IS PointerType THEN
  3878. base := base(PointerType).pointerBase.resolved;
  3879. END;
  3880. WITH base:
  3881. CellType DO
  3882. p := base.cellScope.FindSymbol(identifier)
  3883. |RecordType DO
  3884. p := base.recordScope.FindSymbol(identifier)
  3885. END;
  3886. END;
  3887. END;
  3888. RETURN p;
  3889. END FindSymbol;
  3890. END CellScope;
  3891. (**
  3892. <<
  3893. IMPORT firstImport .. lastImport;
  3894. ...
  3895. firstOperator ... lastOperator
  3896. ....
  3897. >>
  3898. **)
  3899. ModuleScope*= OBJECT(Scope)
  3900. VAR
  3901. firstImport-,lastImport-: Import; numberImports: LONGINT; (* imported modules *)
  3902. firstOperator-,lastOperator-: Operator; numberOperators: LONGINT; (* defined operators *)
  3903. firstBuiltin-,lastBuiltin-: Builtin; numberBuiltins: LONGINT; (* defined builtins, only for global and system module *)
  3904. firstComment-,lastComment-: Comment; numberComments-: LONGINT; (* comments *)
  3905. bodyProcedure-: Procedure;
  3906. PROCEDURE & InitModuleScope;
  3907. BEGIN
  3908. InitScope(NIL);
  3909. firstComment := NIL; lastComment := NIL; numberComments := 0;
  3910. firstImport:= NIL; lastImport := NIL; numberImports := 0;
  3911. firstOperator := NIL; lastOperator := NIL; numberOperators := 0;
  3912. END InitModuleScope;
  3913. PROCEDURE SetBodyProcedure*(body: Procedure);
  3914. BEGIN SELF.bodyProcedure := body;
  3915. END SetBodyProcedure;
  3916. PROCEDURE SetGlobalScope*(outer: Scope);
  3917. BEGIN
  3918. SELF.outerScope := outer;
  3919. END SetGlobalScope;
  3920. PROCEDURE AddBuiltin*(p: Builtin);
  3921. BEGIN
  3922. ASSERT(p # NIL);
  3923. IF lastBuiltin= NIL THEN firstBuiltin := p ELSE lastBuiltin.nextBuiltin := p END;
  3924. INC(numberBuiltins);
  3925. lastBuiltin := p;
  3926. END AddBuiltin;
  3927. PROCEDURE AddOperator*(p: Operator);
  3928. BEGIN
  3929. ASSERT(p # NIL);
  3930. IF lastOperator= NIL THEN firstOperator := p ELSE lastOperator.nextOperator := p END;
  3931. INC(numberOperators);
  3932. lastOperator := p;
  3933. END AddOperator;
  3934. PROCEDURE FindOperator*(identifier: Identifier): Operator;
  3935. VAR p: Operator;
  3936. BEGIN
  3937. p := firstOperator;
  3938. WHILE(p#NIL) & (p.name # identifier) DO p := p.nextOperator END;
  3939. RETURN p;
  3940. END FindOperator;
  3941. PROCEDURE AddImport*(i: Import);
  3942. BEGIN
  3943. ASSERT(i # NIL);
  3944. ASSERT(i.nextImport = NIL);
  3945. IF lastImport= NIL THEN firstImport:= i ELSE lastImport.nextImport := i END;
  3946. lastImport := i;
  3947. INC(numberImports);
  3948. END AddImport;
  3949. PROCEDURE FindImport*(identifier: Identifier): Import;
  3950. VAR p: Import;
  3951. BEGIN
  3952. p := firstImport;
  3953. WHILE(p#NIL) & (p.name # identifier) DO p := p.nextImport END; (* finds imports and re-imports! *)
  3954. RETURN p;
  3955. END FindImport;
  3956. PROCEDURE GetImport*( index: LONGINT ): Import;
  3957. VAR import: Import;
  3958. BEGIN
  3959. import := firstImport;
  3960. WHILE(import # NIL) & (index > 0) DO
  3961. import := import.nextImport;
  3962. DEC(index);
  3963. END;
  3964. RETURN import;
  3965. END GetImport;
  3966. PROCEDURE AddComment*(comment: Comment);
  3967. BEGIN
  3968. ASSERT(comment # NIL);
  3969. IF lastComment= NIL THEN firstComment := comment ELSE lastComment.nextComment := comment END;
  3970. INC(numberComments);
  3971. lastComment := comment;
  3972. END AddComment;
  3973. PROCEDURE ImportByModuleName*(moduleName,context: Identifier): Import;
  3974. VAR p: Import;
  3975. BEGIN
  3976. p := firstImport;
  3977. WHILE(p#NIL) & ~((moduleName = p.moduleName) & (context = p.context)) DO p := p.nextImport END;
  3978. RETURN p;
  3979. END ImportByModuleName;
  3980. PROCEDURE RemoveImporters*(moduleName,context: Identifier);
  3981. VAR this: Import;
  3982. PROCEDURE Check(p: Import): BOOLEAN;
  3983. VAR result: BOOLEAN;
  3984. BEGIN
  3985. IF (moduleName = p.moduleName) & (context = p.context) THEN
  3986. result := TRUE
  3987. ELSE
  3988. result := p.module.moduleScope.ImportByModuleName(moduleName,context) # NIL;
  3989. END;
  3990. RETURN result
  3991. END Check;
  3992. BEGIN
  3993. WHILE(firstImport # NIL) & Check(firstImport) DO
  3994. firstImport := firstImport.nextImport;
  3995. DEC(numberImports);
  3996. END;
  3997. IF firstImport = NIL THEN lastImport := NIL
  3998. ELSE
  3999. this :=firstImport;
  4000. WHILE(this.nextImport # NIL) DO
  4001. IF Check(this.nextImport) THEN
  4002. this.nextImport := this.nextImport.nextImport;
  4003. DEC(numberImports);
  4004. ELSE
  4005. this := this.nextImport
  4006. END;
  4007. END;
  4008. lastImport := this;
  4009. END;
  4010. END RemoveImporters;
  4011. END ModuleScope;
  4012. (* << MODULE name ['in' context] moduleScope name '.' >> *)
  4013. Module* = OBJECT (Symbol)
  4014. VAR
  4015. sourceName-: Basic.FileName;
  4016. moduleScope-: ModuleScope;
  4017. context-:Identifier; (* modules context *)
  4018. case-: LONGINT; (* module notation in lower or upper case, important for printout and operators *)
  4019. isCellNet-: BOOLEAN;
  4020. firstScope-,lastScope-: Scope; numberScopes-: LONGINT; (* list of all scopes for checker / backend traversal etc. *)
  4021. closingComment-: Comment;
  4022. modifiers-: Modifier;
  4023. PROCEDURE & InitModule( CONST sourceName: ARRAY OF CHAR; position: Position; name: Identifier; scope: ModuleScope; case: LONGINT);
  4024. BEGIN
  4025. InitSymbol(position,name);
  4026. COPY (sourceName, SELF.sourceName);
  4027. moduleScope := scope;
  4028. ASSERT(scope.ownerModule = NIL); (* cannot register twice ! *)
  4029. scope.ownerModule := SELF;
  4030. context := invalidIdentifier;
  4031. SELF.case := case;
  4032. firstScope := NIL; lastScope := NIL; numberScopes := 0;
  4033. SetType(moduleType);
  4034. closingComment := NIL;
  4035. isCellNet := FALSE;
  4036. modifiers := NIL;
  4037. END InitModule;
  4038. PROCEDURE SetCase*(case: LONGINT);
  4039. BEGIN
  4040. SELF.case := case
  4041. END SetCase;
  4042. PROCEDURE SetCellNet*(isCellNet: BOOLEAN);
  4043. BEGIN SELF.isCellNet := isCellNet
  4044. END SetCellNet;
  4045. PROCEDURE SetContext*(context: Identifier);
  4046. BEGIN SELF.context := context;
  4047. END SetContext;
  4048. PROCEDURE SetName*(name: Identifier);
  4049. BEGIN SELF.name := name
  4050. END SetName;
  4051. PROCEDURE SetClosingComment*(comment: Comment);
  4052. BEGIN SELF.closingComment := comment
  4053. END SetClosingComment;
  4054. PROCEDURE SetModifiers*(modifiers: Modifier);
  4055. BEGIN SELF.modifiers := modifiers
  4056. END SetModifiers;
  4057. PROCEDURE AddScope*(c: Scope);
  4058. BEGIN
  4059. IF lastScope= NIL THEN firstScope := c ELSE lastScope.nextScope := c END;
  4060. lastScope := c;
  4061. INC(numberScopes);
  4062. END AddScope;
  4063. END Module;
  4064. (** <<expression, expression, ...>> **)
  4065. SymbolList* = OBJECT
  4066. VAR list: Basic.List;
  4067. PROCEDURE & InitList*;
  4068. BEGIN NEW( list,8 );
  4069. END InitList;
  4070. PROCEDURE Length*( ): LONGINT;
  4071. BEGIN RETURN list.Length();
  4072. END Length;
  4073. PROCEDURE AddSymbol*( d: Symbol );
  4074. BEGIN list.Add(d)
  4075. END AddSymbol;
  4076. PROCEDURE GetSymbol*( index: LONGINT ): Symbol;
  4077. VAR p: ANY;
  4078. BEGIN
  4079. p := list.Get(index); RETURN p(Symbol);
  4080. END GetSymbol;
  4081. PROCEDURE SetSymbol*(index: LONGINT; expression: Symbol);
  4082. BEGIN list.Set(index,expression)
  4083. END SetSymbol;
  4084. PROCEDURE RemoveSymbol*(i: LONGINT);
  4085. BEGIN list.RemoveByIndex(i);
  4086. END RemoveSymbol;
  4087. (*
  4088. PROCEDURE Clone*(VAR list: SymbolList);
  4089. VAR i: LONGINT;
  4090. BEGIN
  4091. IF list = NIL THEN NEW(list) END;
  4092. FOR i := 0 TO Length()-1 DO
  4093. list.AddSymbol(CloneSymbol(GetSymbol(i)));
  4094. END;
  4095. END Clone;
  4096. *)
  4097. END SymbolList;
  4098. ProcedureList* = OBJECT
  4099. VAR list: Basic.List;
  4100. PROCEDURE & InitList*;
  4101. BEGIN NEW( list,8 );
  4102. END InitList;
  4103. PROCEDURE Length*( ): LONGINT;
  4104. BEGIN RETURN list.Length();
  4105. END Length;
  4106. PROCEDURE AddProcedure*( d: Procedure );
  4107. BEGIN list.Add(d)
  4108. END AddProcedure;
  4109. PROCEDURE GetProcedure*( index: LONGINT ): Procedure;
  4110. VAR p: ANY;
  4111. BEGIN
  4112. IF index >= list.Length() THEN RETURN NIL END;
  4113. p := list.Get(index);
  4114. IF p = NIL THEN
  4115. RETURN NIL
  4116. ELSE
  4117. RETURN p(Procedure);
  4118. END;
  4119. END GetProcedure;
  4120. PROCEDURE SetProcedure*(index: LONGINT; expression: Procedure);
  4121. BEGIN list.GrowAndSet(index,expression)
  4122. END SetProcedure;
  4123. PROCEDURE RemoveProcedure*(i: LONGINT);
  4124. BEGIN list.RemoveByIndex(i);
  4125. END RemoveProcedure;
  4126. (*
  4127. PROCEDURE Clone*(VAR list: ProcedureList);
  4128. VAR i: LONGINT;
  4129. BEGIN
  4130. IF list = NIL THEN NEW(list) END;
  4131. FOR i := 0 TO Length()-1 DO
  4132. list.AddProcedure(CloneProcedure(GetProcedure(i)));
  4133. END;
  4134. END Clone;
  4135. *)
  4136. END ProcedureList;
  4137. VAR
  4138. (* invalid items used, for example, by parser and checker *)
  4139. invalidIdentifier-: Identifier;
  4140. invalidQualifiedIdentifier-: QualifiedIdentifier;
  4141. invalidType-: Type;
  4142. invalidExpression-: Expression; (* mapped to invalidDesignator for better error handling in checker *)
  4143. invalidDesignator-: Designator;
  4144. invalidValue-: Value;
  4145. invalidSymbol-: Symbol;
  4146. invalidPosition-: Position;
  4147. anonymousIdentifier-: Identifier;
  4148. importType-: Type;
  4149. typeDeclarationType-: Type;
  4150. moduleType-: Type;
  4151. indexListSeparator-: Expression;
  4152. PROCEDURE NewModule*( CONST sourceName: ARRAY OF CHAR; position: Position; name: Identifier;scope: ModuleScope; case: LONGINT ): Module;
  4153. VAR module: Module;
  4154. BEGIN
  4155. NEW( module, sourceName, position, name, scope, case); RETURN module;
  4156. END NewModule;
  4157. PROCEDURE NewComment*(position: Position; scope: Scope; CONST source: ARRAY OF CHAR; length: LONGINT): Comment;
  4158. VAR comment: Comment;
  4159. BEGIN
  4160. NEW(comment,position,scope,source,length); RETURN comment;
  4161. END NewComment;
  4162. PROCEDURE NewImport*( position: Position; alias, name: Identifier; direct: BOOLEAN): Import;
  4163. VAR import: Import;
  4164. BEGIN
  4165. NEW( import, position, alias, name, direct ); RETURN import
  4166. END NewImport;
  4167. PROCEDURE NewConstant*( position: Position; name: Identifier ): Constant;
  4168. VAR constant: Constant;
  4169. BEGIN
  4170. NEW( constant, position, name ); RETURN constant
  4171. END NewConstant;
  4172. PROCEDURE NewProcedure*( position: Position; name: Identifier; scope: ProcedureScope ): Procedure;
  4173. VAR procedure: Procedure;
  4174. BEGIN
  4175. NEW( procedure, position, name, scope); RETURN procedure
  4176. END NewProcedure;
  4177. PROCEDURE NewAlias*( position: Position; name: Identifier; expression: Expression): Alias;
  4178. VAR alias: Alias;
  4179. BEGIN
  4180. NEW( alias, position, name, expression); RETURN alias
  4181. END NewAlias;
  4182. PROCEDURE NewBuiltin*(position: Position; name: Identifier; id: LONGINT): Builtin;
  4183. VAR builtin: Builtin;
  4184. BEGIN
  4185. NEW(builtin,position,name,id); RETURN builtin
  4186. END NewBuiltin;
  4187. PROCEDURE NewCustomBuiltin*(position: Position; name: Identifier; id: LONGINT; subType: SHORTINT): CustomBuiltin;
  4188. VAR builtin:CustomBuiltin;
  4189. BEGIN
  4190. NEW(builtin,position,name,id,subType); RETURN builtin
  4191. END NewCustomBuiltin;
  4192. PROCEDURE NewOperator*( position: Position; name: Identifier; scope: ProcedureScope): Operator;
  4193. VAR operator: Operator;
  4194. BEGIN
  4195. NEW( operator, position, name, scope); RETURN operator
  4196. END NewOperator;
  4197. PROCEDURE NewType*(): Type; (* for error handling: invalid Type, is realtime type *)
  4198. VAR type: Type;
  4199. BEGIN
  4200. NEW( type, invalidPosition);
  4201. type.SetRealtime(TRUE);
  4202. RETURN type
  4203. END NewType;
  4204. PROCEDURE NewByteType*(sizeInBits: LONGINT): ByteType;
  4205. VAR basicType: ByteType;
  4206. BEGIN
  4207. NEW(basicType, sizeInBits); RETURN basicType;
  4208. END NewByteType;
  4209. PROCEDURE NewAnyType*(sizeInBits: LONGINT): AnyType;
  4210. VAR basicType: AnyType;
  4211. BEGIN
  4212. NEW(basicType, sizeInBits); RETURN basicType;
  4213. END NewAnyType;
  4214. PROCEDURE NewObjectType*(sizeInBits: LONGINT): ObjectType;
  4215. VAR basicType: ObjectType;
  4216. BEGIN
  4217. NEW(basicType, sizeInBits); RETURN basicType;
  4218. END NewObjectType;
  4219. PROCEDURE NewNilType*(sizeInBits: LONGINT): NilType;
  4220. VAR basicType: NilType;
  4221. BEGIN
  4222. NEW(basicType, sizeInBits); RETURN basicType;
  4223. END NewNilType;
  4224. PROCEDURE NewAddressType*(sizeInBits: LONGINT): AddressType;
  4225. VAR basicType: AddressType;
  4226. BEGIN
  4227. NEW(basicType, sizeInBits); RETURN basicType;
  4228. END NewAddressType;
  4229. PROCEDURE NewSizeType*(sizeInBits: LONGINT): SizeType;
  4230. VAR basicType: SizeType;
  4231. BEGIN
  4232. NEW(basicType, sizeInBits); RETURN basicType;
  4233. END NewSizeType;
  4234. PROCEDURE NewBooleanType*(sizeInBits: LONGINT): BooleanType;
  4235. VAR basicType: BooleanType;
  4236. BEGIN
  4237. NEW(basicType, sizeInBits); RETURN basicType;
  4238. END NewBooleanType;
  4239. PROCEDURE NewSetType*(sizeInBits: LONGINT): SetType;
  4240. VAR basicType: SetType;
  4241. BEGIN
  4242. NEW(basicType, sizeInBits); RETURN basicType;
  4243. END NewSetType;
  4244. PROCEDURE NewCharacterType*(sizeInBits: LONGINT): CharacterType;
  4245. VAR basicType: CharacterType;
  4246. BEGIN
  4247. NEW(basicType, sizeInBits); RETURN basicType;
  4248. END NewCharacterType;
  4249. PROCEDURE NewRangeType*(sizeInBits: LONGINT): RangeType;
  4250. VAR basicType: RangeType;
  4251. BEGIN
  4252. NEW(basicType, sizeInBits); RETURN basicType;
  4253. END NewRangeType;
  4254. PROCEDURE NewComplexType*(base: Type): ComplexType;
  4255. VAR basicType: ComplexType;
  4256. BEGIN
  4257. NEW(basicType, base); RETURN basicType;
  4258. END NewComplexType;
  4259. PROCEDURE NewIntegerType*(size: LONGINT; signed: BOOLEAN): IntegerType;
  4260. VAR basicType: IntegerType;
  4261. BEGIN
  4262. NEW(basicType, size, signed); RETURN basicType;
  4263. END NewIntegerType;
  4264. PROCEDURE NewFloatType*(sizeInBits: LONGINT): FloatType;
  4265. VAR basicType: FloatType;
  4266. BEGIN
  4267. NEW(basicType, sizeInBits); RETURN basicType;
  4268. END NewFloatType;
  4269. PROCEDURE NewTypeDeclaration*(position: Position; name: Identifier): TypeDeclaration;
  4270. VAR typeDeclaration: TypeDeclaration;
  4271. BEGIN
  4272. ASSERT(name # invalidIdentifier);
  4273. NEW(typeDeclaration,position,name); RETURN typeDeclaration
  4274. END NewTypeDeclaration;
  4275. PROCEDURE NewStringType*( position: Position; baseType: Type; length: LONGINT): StringType;
  4276. VAR stringType: StringType;
  4277. BEGIN
  4278. NEW( stringType, position, baseType, length); RETURN stringType;
  4279. END NewStringType;
  4280. PROCEDURE NewEnumerationType*( position: Position; scope: Scope; enumerationScope: EnumerationScope): EnumerationType;
  4281. VAR enumerationType: EnumerationType;
  4282. BEGIN
  4283. NEW( enumerationType, position, scope, enumerationScope); RETURN enumerationType;
  4284. END NewEnumerationType;
  4285. PROCEDURE NewArrayType*( position: Position; scope: Scope; form: LONGINT): ArrayType;
  4286. VAR arrayType: ArrayType;
  4287. BEGIN
  4288. NEW( arrayType, position,scope, form); RETURN arrayType;
  4289. END NewArrayType;
  4290. PROCEDURE NewMathArrayType*( position: Position; scope: Scope; form: LONGINT): MathArrayType;
  4291. VAR mathArrayType: MathArrayType;
  4292. BEGIN
  4293. NEW( mathArrayType, position,scope,form); RETURN mathArrayType;
  4294. END NewMathArrayType;
  4295. PROCEDURE NewPointerType*( position: Position; scope: Scope): PointerType;
  4296. VAR pointerType: PointerType;
  4297. BEGIN
  4298. NEW( pointerType, position,scope); RETURN pointerType;
  4299. END NewPointerType;
  4300. PROCEDURE NewPortType*( position: Position; direction: LONGINT; sizeExpression: Expression; scope: Scope): PortType;
  4301. VAR portType: PortType;
  4302. BEGIN
  4303. NEW( portType, position, direction, sizeExpression, scope); RETURN portType;
  4304. END NewPortType;
  4305. PROCEDURE NewRecordType*( position: Position; scope: Scope; recordScope: RecordScope): RecordType;
  4306. VAR recordType: RecordType;
  4307. BEGIN
  4308. NEW( recordType, position, scope, recordScope); RETURN recordType
  4309. END NewRecordType;
  4310. PROCEDURE NewCellType*(position: Position; scope:Scope; cellScope: CellScope): CellType;
  4311. VAR actorType: CellType;
  4312. BEGIN
  4313. NEW(actorType, position, scope, cellScope); RETURN actorType;
  4314. END NewCellType;
  4315. PROCEDURE NewProcedureType*( position: Position; scope: Scope): ProcedureType;
  4316. VAR procedureType: ProcedureType;
  4317. BEGIN
  4318. NEW( procedureType, position,scope); RETURN procedureType;
  4319. END NewProcedureType;
  4320. PROCEDURE NewQualifiedType*( position: Position; scope: Scope; qualifiedIdentifier: QualifiedIdentifier): QualifiedType;
  4321. VAR qualifiedType: QualifiedType;
  4322. BEGIN
  4323. NEW( qualifiedType, position,scope,qualifiedIdentifier ); RETURN qualifiedType
  4324. END NewQualifiedType;
  4325. PROCEDURE NewSymbol*(name: Identifier): Symbol; (* for error handling: invalid Symbol *)
  4326. VAR symbol: Symbol;
  4327. BEGIN
  4328. NEW(symbol,invalidPosition,name); RETURN symbol
  4329. END NewSymbol;
  4330. PROCEDURE NewVariable*( position: Position; name: Identifier): Variable;
  4331. VAR variable: Variable;
  4332. BEGIN
  4333. NEW( variable, position, name ); RETURN variable
  4334. END NewVariable;
  4335. PROCEDURE NewQualifiedIdentifier*( position: Position; prefix, suffix: Identifier ): QualifiedIdentifier;
  4336. VAR qualifiedIdentifier: QualifiedIdentifier;
  4337. BEGIN
  4338. NEW( qualifiedIdentifier, position, prefix, suffix ); RETURN qualifiedIdentifier
  4339. END NewQualifiedIdentifier;
  4340. PROCEDURE NewIdentifier*(CONST name: ARRAY OF CHAR): Identifier;
  4341. BEGIN
  4342. RETURN Basic.MakeString(name);
  4343. END NewIdentifier;
  4344. PROCEDURE NewParameter*( position: Position; ownerType:Type ; name: Identifier; passAs: LONGINT): Parameter;
  4345. VAR parameter: Parameter;
  4346. BEGIN
  4347. NEW( parameter, position, ownerType, name, passAs); RETURN parameter;
  4348. END NewParameter;
  4349. PROCEDURE NewProperty*( position: Position; name: Identifier): Property;
  4350. VAR property: Property;
  4351. BEGIN
  4352. NEW( property, position, name); RETURN property;
  4353. END NewProperty;
  4354. PROCEDURE NewExpressionList*(): ExpressionList;
  4355. VAR expressionList: ExpressionList;
  4356. BEGIN
  4357. NEW(expressionList); RETURN expressionList
  4358. END NewExpressionList;
  4359. PROCEDURE CloneExpressionList*(l: ExpressionList): ExpressionList;
  4360. VAR copy: ExpressionList;
  4361. BEGIN
  4362. IF l = NIL THEN RETURN NIL ELSE l.Clone(copy); RETURN copy END;
  4363. END CloneExpressionList;
  4364. PROCEDURE NewDesignator*(): Designator; (* for error handling: invalid Designator *)
  4365. VAR designator: Designator;
  4366. BEGIN
  4367. NEW(designator,invalidPosition); RETURN designator;
  4368. END NewDesignator;
  4369. PROCEDURE NewIdentifierDesignator*( position: Position; identifier: Identifier): IdentifierDesignator;
  4370. VAR identifierDesignator: IdentifierDesignator;
  4371. BEGIN
  4372. NEW( identifierDesignator, position, identifier ); RETURN identifierDesignator
  4373. END NewIdentifierDesignator;
  4374. PROCEDURE NewSelectorDesignator*( position: Position; left: Designator; name: Identifier ): SelectorDesignator;
  4375. VAR selectorDesignator: SelectorDesignator;
  4376. BEGIN
  4377. NEW( selectorDesignator, position, left, name ); RETURN selectorDesignator
  4378. END NewSelectorDesignator;
  4379. PROCEDURE NewParameterDesignator*( position: Position; left: Designator; expressionList: ExpressionList ): ParameterDesignator;
  4380. VAR parameterDesignator: ParameterDesignator;
  4381. BEGIN
  4382. NEW( parameterDesignator,position, left, expressionList ); RETURN parameterDesignator
  4383. END NewParameterDesignator;
  4384. PROCEDURE NewArrowDesignator*( position: Position; left: Designator ): ArrowDesignator;
  4385. VAR dereferenceDesignator: ArrowDesignator;
  4386. BEGIN
  4387. NEW( dereferenceDesignator, position, left ); RETURN dereferenceDesignator;
  4388. END NewArrowDesignator;
  4389. PROCEDURE NewBracketDesignator*( position: Position; left: Designator; expressionList: ExpressionList ): BracketDesignator;
  4390. VAR bracketDesignator: BracketDesignator;
  4391. BEGIN
  4392. NEW( bracketDesignator, position, left, expressionList ); RETURN bracketDesignator
  4393. END NewBracketDesignator;
  4394. PROCEDURE NewSymbolDesignator*( position: Position; left: Designator; symbol: Symbol ): SymbolDesignator;
  4395. VAR symbolDesignator: SymbolDesignator;
  4396. BEGIN
  4397. NEW( symbolDesignator, position, left, symbol); RETURN symbolDesignator
  4398. END NewSymbolDesignator;
  4399. PROCEDURE NewIndexDesignator*( position: Position; left: Designator): IndexDesignator;
  4400. VAR indexDesignator: IndexDesignator;
  4401. BEGIN
  4402. NEW( indexDesignator, position, left); RETURN indexDesignator
  4403. END NewIndexDesignator;
  4404. PROCEDURE NewProcedureCallDesignator*(position: Position; left: Designator; parameters: ExpressionList): ProcedureCallDesignator;
  4405. VAR procedureCallDesignator: ProcedureCallDesignator;
  4406. BEGIN
  4407. NEW(procedureCallDesignator, position, left, parameters); RETURN procedureCallDesignator
  4408. END NewProcedureCallDesignator;
  4409. PROCEDURE NewInlineCallDesignator*(position: Position; o: ProcedureCallDesignator; block: StatementBlock): InlineCallDesignator;
  4410. VAR inlineCall: InlineCallDesignator;
  4411. BEGIN
  4412. NEW(inlineCall, position, o, block); RETURN inlineCall;
  4413. END NewInlineCallDesignator;
  4414. PROCEDURE NewBuiltinCallDesignator*(position: Position; id: LONGINT; left: Designator; parameters: ExpressionList): BuiltinCallDesignator;
  4415. VAR builtinCallDesignator: BuiltinCallDesignator;
  4416. BEGIN
  4417. NEW(builtinCallDesignator, position, id, left,parameters); RETURN builtinCallDesignator
  4418. END NewBuiltinCallDesignator;
  4419. PROCEDURE NewTypeGuardDesignator*(position: Position; left: Designator; type: Type): TypeGuardDesignator;
  4420. VAR guardDesignator: TypeGuardDesignator;
  4421. BEGIN
  4422. NEW(guardDesignator,position,left,type); RETURN guardDesignator;
  4423. END NewTypeGuardDesignator;
  4424. PROCEDURE NewDereferenceDesignator*( position: Position; left: Designator): DereferenceDesignator;
  4425. VAR dereferenceDesignator: DereferenceDesignator;
  4426. BEGIN
  4427. NEW( dereferenceDesignator, position, left); RETURN dereferenceDesignator
  4428. END NewDereferenceDesignator;
  4429. PROCEDURE NewSupercallDesignator*( position: Position; left: Designator): SupercallDesignator;
  4430. VAR supercallDesignator: SupercallDesignator;
  4431. BEGIN
  4432. NEW( supercallDesignator, position, left); RETURN supercallDesignator
  4433. END NewSupercallDesignator;
  4434. PROCEDURE NewSelfDesignator*( position: Position): SelfDesignator;
  4435. VAR selfDesignator: SelfDesignator;
  4436. BEGIN
  4437. NEW( selfDesignator, position); RETURN selfDesignator
  4438. END NewSelfDesignator;
  4439. PROCEDURE NewResultDesignator*( position: Position): ResultDesignator;
  4440. VAR resultDesignator: ResultDesignator;
  4441. BEGIN
  4442. NEW( resultDesignator, position); RETURN resultDesignator
  4443. END NewResultDesignator;
  4444. PROCEDURE NewExpression*(): Expression; (* for error handling: invalid Expression *)
  4445. VAR expression: Expression;
  4446. BEGIN
  4447. NEW(expression,invalidPosition); RETURN expression;
  4448. END NewExpression;
  4449. PROCEDURE CloneExpression*(e: Expression): Expression;
  4450. VAR copy: Expression;
  4451. BEGIN
  4452. IF e = NIL THEN
  4453. RETURN NIL
  4454. ELSE
  4455. copy := e.Clone();
  4456. copy.type := e.type;
  4457. copy.assignable := e.assignable;
  4458. copy.position := e.position;
  4459. copy.state := e.state;
  4460. IF e.resolved = e THEN copy.resolved := copy(Value) ELSE copy.resolved := e.resolved END;
  4461. RETURN copy
  4462. END;
  4463. END CloneExpression;
  4464. PROCEDURE CloneDesignator*(e: Expression): Designator;
  4465. BEGIN
  4466. IF e = NIL THEN RETURN NIL ELSE RETURN CloneExpression(e)(Designator) END;
  4467. END CloneDesignator;
  4468. PROCEDURE NewElement*( position: Position; from,to: Expression ): Expression;
  4469. BEGIN
  4470. IF from = to THEN RETURN from
  4471. ELSE RETURN NewRangeExpression(position,from,to,NIL)
  4472. END;
  4473. END NewElement;
  4474. PROCEDURE NewSet*( position: Position ): Set;
  4475. VAR set: Set;
  4476. BEGIN NEW( set, position ); RETURN set
  4477. END NewSet;
  4478. PROCEDURE NewMathArrayExpression*( position: Position ): MathArrayExpression;
  4479. VAR mathArrayExpression: MathArrayExpression;
  4480. BEGIN NEW( mathArrayExpression, position ); RETURN mathArrayExpression
  4481. END NewMathArrayExpression;
  4482. PROCEDURE NewBinaryExpression*( position: Position; left, right: Expression; operator: LONGINT ): BinaryExpression;
  4483. VAR binaryExpression: BinaryExpression;
  4484. BEGIN
  4485. NEW( binaryExpression, position, left, right, operator ); RETURN binaryExpression;
  4486. END NewBinaryExpression;
  4487. PROCEDURE NewRangeExpression*(position: Position; first, last, step: Expression): RangeExpression;
  4488. VAR rangeExpression: RangeExpression;
  4489. BEGIN
  4490. NEW(rangeExpression, position, first, last, step); RETURN rangeExpression
  4491. END NewRangeExpression;
  4492. PROCEDURE NewTensorRangeExpression*(position: Position): TensorRangeExpression;
  4493. VAR tensorRangeExpression: TensorRangeExpression;
  4494. BEGIN
  4495. NEW(tensorRangeExpression,position); RETURN tensorRangeExpression
  4496. END NewTensorRangeExpression;
  4497. PROCEDURE NewUnaryExpression*( position: Position; operand: Expression; operator: LONGINT ): UnaryExpression;
  4498. VAR unaryExpression: UnaryExpression;
  4499. BEGIN
  4500. NEW( unaryExpression, position, operand, operator ); RETURN unaryExpression;
  4501. END NewUnaryExpression;
  4502. PROCEDURE NewConversion*( position: Position; expression: Expression; type: Type; typeExpression: Expression): Conversion;
  4503. VAR conversion: Conversion;
  4504. BEGIN
  4505. ASSERT(type # NIL);
  4506. NEW( conversion, position, expression,type, typeExpression ); RETURN conversion;
  4507. END NewConversion;
  4508. PROCEDURE NewValue*(): Value;(* for error handling: invalid Value *)
  4509. VAR value: Value;
  4510. BEGIN
  4511. NEW(value,invalidPosition); RETURN value;
  4512. END NewValue;
  4513. PROCEDURE NewIntegerValue*( position: Position; value: Basic.Integer): IntegerValue;
  4514. VAR integerValue: IntegerValue;
  4515. BEGIN
  4516. NEW( integerValue, position, value); RETURN integerValue;
  4517. END NewIntegerValue;
  4518. PROCEDURE NewCharacterValue*( position: Position; value: CHAR): CharacterValue;
  4519. VAR characterValue: CharacterValue;
  4520. BEGIN
  4521. NEW( characterValue, position, value); RETURN characterValue;
  4522. END NewCharacterValue;
  4523. PROCEDURE NewSetValue*(position: Position; value: Basic.Set): SetValue;
  4524. VAR setValue: SetValue;
  4525. BEGIN
  4526. NEW(setValue, position, value); RETURN setValue
  4527. END NewSetValue;
  4528. PROCEDURE NewMathArrayValue*( position: Position ): MathArrayValue;
  4529. VAR mathArrayValue: MathArrayValue;
  4530. BEGIN NEW( mathArrayValue, position ); RETURN mathArrayValue
  4531. END NewMathArrayValue;
  4532. PROCEDURE NewRealValue*( position: Position; value: LONGREAL): RealValue;
  4533. VAR realValue: RealValue;
  4534. BEGIN
  4535. NEW( realValue, position, value); RETURN realValue
  4536. END NewRealValue;
  4537. PROCEDURE NewComplexValue*( position: Position; realValue, imagValue: LONGREAL): ComplexValue;
  4538. VAR complexValue: ComplexValue;
  4539. BEGIN
  4540. NEW( complexValue, position, realValue, imagValue); RETURN complexValue
  4541. END NewComplexValue;
  4542. PROCEDURE NewStringValue*( position: Position; value: String): StringValue;
  4543. VAR stringValue: StringValue;
  4544. BEGIN
  4545. NEW( stringValue, position, value ); RETURN stringValue
  4546. END NewStringValue;
  4547. PROCEDURE NewBooleanValue*( position: Position; value: BOOLEAN): BooleanValue;
  4548. VAR booleanValue: BooleanValue;
  4549. BEGIN
  4550. NEW( booleanValue, position, value ); RETURN booleanValue;
  4551. END NewBooleanValue;
  4552. PROCEDURE NewNilValue*( position: Position ): NilValue;
  4553. VAR nilValue: NilValue;
  4554. BEGIN
  4555. NEW( nilValue, position ); RETURN nilValue
  4556. END NewNilValue;
  4557. PROCEDURE NewEnumerationValue*( position: Position; value: Basic.Integer ): EnumerationValue;
  4558. VAR enumeratorValue: EnumerationValue;
  4559. BEGIN
  4560. NEW( enumeratorValue, position, value ); RETURN enumeratorValue
  4561. END NewEnumerationValue;
  4562. PROCEDURE NewStatement*(outer: Statement): Statement; (* for error handling: invalid Statement *)
  4563. VAR statement: Statement;
  4564. BEGIN NEW(statement,invalidPosition,outer); RETURN statement;
  4565. END NewStatement;
  4566. PROCEDURE CloneStatement*(statement: Statement): Statement;
  4567. BEGIN IF statement = NIL THEN RETURN NIL ELSE RETURN statement.Clone() END
  4568. END CloneStatement;
  4569. PROCEDURE NewStatementSequence*(): StatementSequence;
  4570. VAR statementSequence: StatementSequence;
  4571. BEGIN
  4572. NEW( statementSequence); RETURN statementSequence
  4573. END NewStatementSequence;
  4574. PROCEDURE CloneStatementSequence*(statementSequence: StatementSequence): StatementSequence;
  4575. VAR copy: StatementSequence;
  4576. BEGIN IF statementSequence = NIL THEN RETURN NIL ELSE statementSequence.Clone(copy); RETURN copy END
  4577. END CloneStatementSequence;
  4578. PROCEDURE NewModifier*(position: Position; identifier: Identifier; expression: Expression): Modifier;
  4579. VAR blockModifier: Modifier;
  4580. BEGIN
  4581. NEW(blockModifier,position,identifier,expression); RETURN blockModifier
  4582. END NewModifier;
  4583. PROCEDURE NewStatementBlock*( position: Position ; outer: Statement; scope: Scope): StatementBlock;
  4584. VAR statementBlock: StatementBlock;
  4585. BEGIN
  4586. NEW( statementBlock, position, outer, scope ); RETURN statementBlock
  4587. END NewStatementBlock;
  4588. PROCEDURE NewStatementDesignator*(position: Position; s: Statement): StatementDesignator;
  4589. VAR statementDesignator: StatementDesignator;
  4590. BEGIN
  4591. NEW( statementDesignator, position, s); RETURN statementDesignator
  4592. END NewStatementDesignator;
  4593. PROCEDURE NewBody*( position: Position ; scope: ProcedureScope): Body;
  4594. VAR body: Body;
  4595. BEGIN
  4596. NEW( body, position,scope ); RETURN body
  4597. END NewBody;
  4598. PROCEDURE NewIfPart*(): IfPart;
  4599. VAR ifPart: IfPart;
  4600. BEGIN
  4601. NEW( ifPart); RETURN ifPart
  4602. END NewIfPart;
  4603. PROCEDURE NewIfStatement*( position: Position ; outer: Statement): IfStatement;
  4604. VAR ifStatement: IfStatement;
  4605. BEGIN
  4606. NEW( ifStatement, position,outer ); RETURN ifStatement
  4607. END NewIfStatement;
  4608. PROCEDURE NewAssignment*( position: Position; left: Designator; right: Expression; outer: Statement): Assignment;
  4609. VAR assignment: Assignment;
  4610. BEGIN
  4611. NEW( assignment, position, left, right,outer ); RETURN assignment
  4612. END NewAssignment;
  4613. PROCEDURE NewCommunicationStatement*( position: Position; op: LONGINT; left: Designator; right: Expression; outer: Statement): CommunicationStatement;
  4614. VAR communication: CommunicationStatement;
  4615. BEGIN
  4616. NEW( communication, position, op, left, right,outer ); RETURN communication
  4617. END NewCommunicationStatement;
  4618. PROCEDURE NewProcedureCallStatement*(position: Position; ignore: BOOLEAN; call: Designator; outer: Statement): ProcedureCallStatement;
  4619. VAR caller: ProcedureCallStatement;
  4620. BEGIN
  4621. NEW(caller,position,ignore,call,outer); RETURN caller
  4622. END NewProcedureCallStatement;
  4623. PROCEDURE NewCaseStatement*( position: Position ; outer: Statement): CaseStatement;
  4624. VAR caseStatement: CaseStatement;
  4625. BEGIN
  4626. NEW( caseStatement, position,outer ); RETURN caseStatement
  4627. END NewCaseStatement;
  4628. PROCEDURE NewCasePart*(): CasePart;
  4629. VAR casePart: CasePart;
  4630. BEGIN
  4631. NEW( casePart); RETURN casePart
  4632. END NewCasePart;
  4633. PROCEDURE NewWithPart*(): WithPart;
  4634. VAR withPart: WithPart;
  4635. BEGIN
  4636. NEW( withPart); RETURN withPart
  4637. END NewWithPart;
  4638. PROCEDURE NewWithStatement*( position: Position; outer: Statement): WithStatement;
  4639. VAR withStatement: WithStatement;
  4640. BEGIN
  4641. NEW( withStatement, position, outer ); RETURN withStatement
  4642. END NewWithStatement;
  4643. PROCEDURE NewWhileStatement*( position: Position ; outer: Statement): WhileStatement;
  4644. VAR whileStatement: WhileStatement;
  4645. BEGIN
  4646. NEW( whileStatement, position,outer ); RETURN whileStatement
  4647. END NewWhileStatement;
  4648. PROCEDURE NewRepeatStatement*( position: Position ; outer: Statement): RepeatStatement;
  4649. VAR repeatStatement: RepeatStatement;
  4650. BEGIN
  4651. NEW( repeatStatement, position ,outer); RETURN repeatStatement
  4652. END NewRepeatStatement;
  4653. PROCEDURE NewForStatement*( position: Position; outer: Statement ): ForStatement;
  4654. VAR forStatement: ForStatement;
  4655. BEGIN
  4656. NEW( forStatement, position,outer ); RETURN forStatement
  4657. END NewForStatement;
  4658. PROCEDURE NewLoopStatement*( position: Position ; outer: Statement): LoopStatement;
  4659. VAR loopStatement: LoopStatement;
  4660. BEGIN
  4661. NEW( loopStatement, position ,outer); RETURN loopStatement
  4662. END NewLoopStatement;
  4663. PROCEDURE NewExitableBlock*( position: Position ; outer: Statement): ExitableBlock;
  4664. VAR loopStatement: ExitableBlock;
  4665. BEGIN
  4666. NEW( loopStatement, position ,outer); RETURN loopStatement
  4667. END NewExitableBlock;
  4668. PROCEDURE NewExitStatement*( position: Position ; outer: Statement): ExitStatement;
  4669. VAR exitStatement: ExitStatement;
  4670. BEGIN
  4671. NEW( exitStatement, position, outer); RETURN exitStatement
  4672. END NewExitStatement;
  4673. PROCEDURE NewReturnStatement*( position: Position; outer: Statement ): ReturnStatement;
  4674. VAR returnStatement: ReturnStatement;
  4675. BEGIN
  4676. NEW( returnStatement, position,outer ); RETURN returnStatement
  4677. END NewReturnStatement;
  4678. PROCEDURE NewAwaitStatement*( position: Position; outer: Statement ): AwaitStatement;
  4679. VAR awaitStatement: AwaitStatement;
  4680. BEGIN
  4681. NEW( awaitStatement, position, outer ); RETURN awaitStatement
  4682. END NewAwaitStatement;
  4683. PROCEDURE NewCode*(position: Position; outer: Statement): Code;
  4684. VAR code: Code;
  4685. BEGIN
  4686. NEW(code,position,outer); RETURN code
  4687. END NewCode;
  4688. PROCEDURE NewProcedureScope*(outer: Scope): ProcedureScope;
  4689. VAR scope: ProcedureScope;
  4690. BEGIN NEW(scope,outer); RETURN scope
  4691. END NewProcedureScope;
  4692. PROCEDURE NewBlockScope*(outer: Scope): BlockScope;
  4693. VAR scope: BlockScope;
  4694. BEGIN NEW(scope,outer); RETURN scope
  4695. END NewBlockScope;
  4696. PROCEDURE NewModuleScope*(): ModuleScope;
  4697. VAR scope: ModuleScope;
  4698. BEGIN NEW(scope); RETURN scope
  4699. END NewModuleScope;
  4700. PROCEDURE NewRecordScope*(outer: Scope): RecordScope;
  4701. VAR scope: RecordScope;
  4702. BEGIN NEW(scope,outer); RETURN scope
  4703. END NewRecordScope;
  4704. PROCEDURE NewCellScope*(outer: Scope): CellScope;
  4705. VAR scope: CellScope;
  4706. BEGIN NEW(scope,outer); RETURN scope
  4707. END NewCellScope;
  4708. PROCEDURE NewEnumerationScope*(outer: Scope): EnumerationScope;
  4709. VAR scope: EnumerationScope;
  4710. BEGIN NEW(scope,outer); RETURN scope
  4711. END NewEnumerationScope;
  4712. PROCEDURE Init;
  4713. BEGIN;
  4714. invalidPosition.start := -1;
  4715. invalidIdentifier := Basic.invalidString;
  4716. invalidQualifiedIdentifier := NewQualifiedIdentifier(invalidPosition,invalidIdentifier,Basic.emptyString);
  4717. invalidType := NewType();
  4718. invalidDesignator := NewDesignator();
  4719. invalidDesignator.SetType(invalidType);
  4720. invalidExpression := invalidDesignator;
  4721. invalidValue := NewValue();
  4722. invalidSymbol := NewSymbol(NewIdentifier(""));
  4723. invalidSymbol.SetType(invalidType);
  4724. importType := NewType();
  4725. importType.SetState(Resolved);
  4726. typeDeclarationType := NewType();
  4727. typeDeclarationType.SetState(Resolved);
  4728. moduleType := NewType();
  4729. moduleType.SetState(Resolved);
  4730. anonymousIdentifier := NewIdentifier("");
  4731. indexListSeparator := NewDesignator();
  4732. indexListSeparator.SetType(invalidType);
  4733. END Init;
  4734. BEGIN
  4735. Init;
  4736. END FoxSyntaxTree.