pastree.pp 162 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991
  1. {
  2. This file is part of the Free Component Library
  3. Pascal parse tree classes
  4. Copyright (c) 2000-2005 by
  5. Areca Systems GmbH / Sebastian Guenther, [email protected]
  6. See the file COPYING.FPC, included in this distribution,
  7. for details about the copyright.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. **********************************************************************}
  12. {$IFNDEF FPC_DOTTEDUNITS}
  13. unit PasTree;
  14. {$ENDIF FPC_DOTTEDUNITS}
  15. {$i fcl-passrc.inc}
  16. interface
  17. {$IFDEF FPC_DOTTEDUNITS}
  18. uses System.SysUtils, System.Classes;
  19. {$ELSE FPC_DOTTEDUNITS}
  20. uses SysUtils, Classes;
  21. {$ENDIF FPC_DOTTEDUNITS}
  22. resourcestring
  23. // Parse tree node type names
  24. SPasTreeElement = 'generic element';
  25. SPasTreeSection = 'unit section';
  26. SPasTreeProgramSection = 'program section';
  27. SPasTreeLibrarySection = 'library section';
  28. SPasTreeInterfaceSection = 'interface section';
  29. SPasTreeImplementationSection = 'implementation section';
  30. SPasTreeUsesUnit = 'uses unit';
  31. SPasTreeModule = 'module';
  32. SPasTreeUnit = 'unit';
  33. SPasTreeProgram = 'program';
  34. SPasTreePackage = 'package';
  35. SPasTreeResString = 'resource string';
  36. SPasTreeType = 'generic type';
  37. SPasTreePointerType = 'pointer type';
  38. SPasTreeAliasType = 'alias type';
  39. SPasTreeTypeAliasType = '"type" alias type';
  40. SPasTreeClassOfType = '"class of" type';
  41. SPasTreeRangeType = 'range type';
  42. SPasTreeArrayType = 'array type';
  43. SPasTreeFileType = 'file type';
  44. SPasTreeEnumValue = 'enumeration value';
  45. SPasTreeEnumType = 'enumeration type';
  46. SPasTreeSetType = 'set type';
  47. SPasTreeRecordType = 'record type';
  48. SPasStringType = 'string type';
  49. SPasTreeObjectType = 'object';
  50. SPasTreeClassType = 'class';
  51. SPasTreeInterfaceType = 'interface';
  52. SPasTreeSpecializedType = 'specialized class type';
  53. SPasTreeSpecializedExpr = 'specialize expr';
  54. SPasClassHelperType = 'class helper type';
  55. SPasRecordHelperType = 'record helper type';
  56. SPasTypeHelperType = 'type helper type';
  57. SPasTreeArgument = 'argument';
  58. SPasTreeProcedureType = 'procedure type';
  59. SPasTreeResultElement = 'function result';
  60. SPasTreeConstructorType = 'constructor type';
  61. SPasTreeDestructorType = 'destructor type';
  62. SPasTreeFunctionType = 'function type';
  63. SPasTreeUnresolvedTypeRef = 'unresolved type reference';
  64. SPasTreeVariable = 'variable';
  65. SPasTreeConst = 'constant';
  66. SPasTreeProperty = 'property';
  67. SPasTreeOverloadedProcedure = 'overloaded procedure';
  68. SPasTreeProcedure = 'procedure';
  69. SPasTreeFunction = 'function';
  70. SPasTreeOperator = 'operator';
  71. SPasTreeClassOperator = 'class operator';
  72. SPasTreeClassProcedure = 'class procedure';
  73. SPasTreeClassFunction = 'class function';
  74. SPasTreeClassConstructor = 'class constructor';
  75. SPasTreeClassDestructor = 'class destructor';
  76. SPasTreeConstructor = 'constructor';
  77. SPasTreeDestructor = 'destructor';
  78. SPasTreeAnonymousProcedure = 'anonymous procedure';
  79. SPasTreeAnonymousFunction = 'anonymous function';
  80. SPasTreeProcedureImpl = 'procedure/function implementation';
  81. SPasTreeConstructorImpl = 'constructor implementation';
  82. SPasTreeDestructorImpl = 'destructor implementation';
  83. type
  84. EPasTree = Class(Exception);
  85. TPastreeString = string;
  86. // Visitor pattern.
  87. TPassTreeVisitor = class;
  88. { TPasElementBase }
  89. TPasElementBase = class
  90. private
  91. FData: TObject;
  92. protected
  93. procedure Accept(Visitor: TPassTreeVisitor); virtual;
  94. public
  95. Property CustomData: TObject Read FData Write FData;
  96. end;
  97. TPasElementBaseClass = class of TPasElementBase;
  98. TPasModule = class;
  99. TPasMemberVisibility = (visDefault, visPrivate, visProtected, visPublic,
  100. visPublished, visAutomated,
  101. visStrictPrivate, visStrictProtected,
  102. visRequired, visOptional);
  103. TCallingConvention = (ccDefault,ccRegister,ccPascal,ccCDecl,ccStdCall,
  104. ccOldFPCCall,ccSafeCall,ccSysCall,ccMWPascal,
  105. ccHardFloat,ccSysV_ABI_Default,ccSysV_ABI_CDecl,
  106. ccMS_ABI_Default,ccMS_ABI_CDecl,
  107. ccVectorCall);
  108. TProcTypeModifier = (ptmOfObject,ptmIsNested,ptmStatic,ptmVarargs,
  109. ptmReferenceTo,ptmAsync,ptmFar,ptmCblock);
  110. TProcTypeModifiers = set of TProcTypeModifier;
  111. TPackMode = (pmNone,pmPacked,pmBitPacked);
  112. TPasMemberVisibilities = set of TPasMemberVisibility;
  113. TPasMemberHint = (hDeprecated,hLibrary,hPlatform,hExperimental,hUnimplemented);
  114. TPasMemberHints = set of TPasMemberHint;
  115. TPasElement = class;
  116. TPTreeElement = class of TPasElement;
  117. TPasElementArray = array of TPasElement;
  118. TOnForEachPasElement = procedure(El: TPasElement; arg: pointer) of object;
  119. { TPasElement }
  120. TPasElement = class(TPasElementBase)
  121. private
  122. FDocComment: TPasTreeString;
  123. FName: TPasTreeString;
  124. FParent: TPasElement;
  125. FHints: TPasMemberHints;
  126. FHintMessage: TPasTreeString;
  127. {$ifdef pas2js}
  128. FPasElementId: NativeInt;
  129. class var FLastPasElementId: NativeInt;
  130. {$endif}
  131. protected
  132. procedure ProcessHints(const ASemiColonPrefix: boolean; var AResult: TPasTreeString); virtual;
  133. procedure SetParent(const AValue: TPasElement); virtual;
  134. public
  135. SourceFilename: TPasTreeString;
  136. SourceLinenumber: Integer;
  137. SourceEndLinenumber: Integer;
  138. Visibility: TPasMemberVisibility;
  139. constructor Create(const AName: TPasTreeString; AParent: TPasElement); virtual;
  140. destructor Destroy; override;
  141. Class Function IsKeyWord(Const S : TPasTreeString) : Boolean;
  142. Class Function EscapeKeyWord(Const S : TPasTreeString) : TPasTreeString;
  143. function FreeChild(Child: TPasElement; Prepare: boolean): TPasElement;
  144. procedure FreeChildList(List: TFPList; Prepare: boolean);
  145. procedure FreeChildArray(A: TPasElementArray; Prepare: boolean);
  146. procedure FreeChildren(Prepare: boolean); virtual;
  147. procedure ForEachCall(const aMethodCall: TOnForEachPasElement;
  148. const Arg: Pointer); virtual;
  149. procedure ForEachChildCall(const aMethodCall: TOnForEachPasElement;
  150. const Arg: Pointer; Child: TPasElement; CheckParent: boolean); virtual;
  151. Function SafeName : TPasTreeString; virtual; // Name but with & prepended if name is a keyword.
  152. function FullPath: TPasTreeString; // parent's names, until parent is not TPasDeclarations
  153. function ParentPath: TPasTreeString; // parent's names
  154. function FullName: TPasTreeString; virtual; // FullPath + Name
  155. function PathName: TPasTreeString; virtual; // = Module.Name + ParentPath
  156. function GetModule: TPasModule;
  157. function ElementTypeName: TPasTreeString; virtual;
  158. Function HintsString : TPasTreeString;
  159. function GetDeclaration(full : Boolean) : TPasTreeString; virtual;
  160. procedure Accept(Visitor: TPassTreeVisitor); override;
  161. procedure ClearTypeReferences(aType: TPasElement); virtual;
  162. function HasParent(aParent: TPasElement): boolean;
  163. property Name: TPasTreeString read FName write FName;
  164. property Parent: TPasElement read FParent Write SetParent;
  165. property Hints : TPasMemberHints Read FHints Write FHints;
  166. property HintMessage : TPasTreeString Read FHintMessage Write FHintMessage;
  167. property DocComment : TPasTreeString Read FDocComment Write FDocComment;
  168. {$ifdef pas2js}
  169. property PasElementId: NativeInt read FPasElementId; // global unique id
  170. {$endif}
  171. end;
  172. TPasExprKind = (pekIdent, pekNumber, pekString, pekSet, pekNil, pekBoolConst,
  173. pekRange, pekUnary, pekBinary, pekFuncParams, pekArrayParams, pekListOfExp,
  174. pekInherited, pekSelf, pekSpecialize, pekProcedure);
  175. TExprOpCode = (eopNone,
  176. eopAdd,eopSubtract,eopMultiply,eopDivide{/}, eopDiv{div},eopMod, eopPower,// arithmetic
  177. eopShr,eopShl, // bit operations
  178. eopNot,eopAnd,eopOr,eopXor, // logical/bit
  179. eopEqual, eopNotEqual, // Logical
  180. eopLessThan,eopGreaterThan, eopLessthanEqual,eopGreaterThanEqual, // ordering
  181. eopIn,eopIs,eopAs, eopSymmetricaldifference, // Specials
  182. eopAddress, eopDeref, eopMemAddress, // Pointers eopMemAddress=**
  183. eopSubIdent); // SomeRec.A, A is subIdent of SomeRec
  184. { TPasExpr }
  185. TPasExpr = class(TPasElement)
  186. Kind : TPasExprKind;
  187. OpCode : TExprOpCode;
  188. Format1,Format2 : TPasExpr; // write, writeln, str
  189. constructor Create(AParent : TPasElement; AKind: TPasExprKind; AOpCode: TExprOpCode); virtual; overload;
  190. procedure FreeChildren(Prepare: boolean); override;
  191. end;
  192. { TUnaryExpr }
  193. TUnaryExpr = class(TPasExpr)
  194. Operand : TPasExpr;
  195. constructor Create(AParent : TPasElement; AOperand: TPasExpr; AOpCode: TExprOpCode); overload;
  196. function GetDeclaration(full : Boolean) : TPasTreeString; override;
  197. procedure FreeChildren(Prepare: boolean); override;
  198. procedure ForEachCall(const aMethodCall: TOnForEachPasElement;
  199. const Arg: Pointer); override;
  200. end;
  201. { TBinaryExpr }
  202. TBinaryExpr = class(TPasExpr)
  203. Left : TPasExpr;
  204. Right : TPasExpr;
  205. constructor Create(AParent : TPasElement; xleft, xright: TPasExpr; AOpCode: TExprOpCode); overload;
  206. constructor CreateRange(AParent : TPasElement; xleft, xright: TPasExpr); overload;
  207. function GetDeclaration(full : Boolean) : TPasTreeString; override;
  208. procedure FreeChildren(Prepare: boolean); override;
  209. procedure ForEachCall(const aMethodCall: TOnForEachPasElement;
  210. const Arg: Pointer); override;
  211. class function IsRightSubIdent(El: TPasElement): boolean;
  212. end;
  213. { TPrimitiveExpr }
  214. TPrimitiveExpr = class(TPasExpr)
  215. Value : TPasTreeString;
  216. constructor Create(AParent : TPasElement; AKind: TPasExprKind; const AValue : TPasTreeString); overload;
  217. function GetDeclaration(full : Boolean) : TPasTreeString; override;
  218. end;
  219. { TBoolConstExpr }
  220. TBoolConstExpr = class(TPasExpr)
  221. Value : Boolean;
  222. constructor Create(AParent : TPasElement; AKind: TPasExprKind; const ABoolValue : Boolean); overload;
  223. function GetDeclaration(full : Boolean) : TPasTreeString; override;
  224. end;
  225. { TNilExpr }
  226. TNilExpr = class(TPasExpr)
  227. constructor Create(AParent : TPasElement); overload;
  228. function GetDeclaration(full : Boolean) : TPasTreeString; override;
  229. end;
  230. { TInheritedExpr }
  231. TInheritedExpr = class(TPasExpr)
  232. Public
  233. constructor Create(AParent : TPasElement); overload;
  234. function GetDeclaration(full : Boolean) : TPasTreeString; override;
  235. end;
  236. { TSelfExpr }
  237. TSelfExpr = class(TPasExpr)
  238. constructor Create(AParent : TPasElement); overload;
  239. function GetDeclaration(full : Boolean) : TPasTreeString; override;
  240. end;
  241. TPasExprArray = array of TPasExpr;
  242. { TParamsExpr - source position is the opening bracket }
  243. TParamsExpr = class(TPasExpr)
  244. Value : TPasExpr;
  245. Params : TPasExprArray;
  246. // Kind: pekArrayParams, pekFuncParams, pekSet
  247. constructor Create(AParent : TPasElement; AKind: TPasExprKind); overload;
  248. function GetDeclaration(full : Boolean) : TPasTreeString; override;
  249. procedure FreeChildren(Prepare: boolean); override;
  250. procedure AddParam(xp: TPasExpr);
  251. procedure ForEachCall(const aMethodCall: TOnForEachPasElement;
  252. const Arg: Pointer); override;
  253. end;
  254. { TRecordValues }
  255. TRecordValuesItem = record
  256. Name : TPasTreeString;
  257. NameExp : TPrimitiveExpr;
  258. ValueExp : TPasExpr;
  259. end;
  260. PRecordValuesItem = ^TRecordValuesItem;
  261. TRecordValuesItemArray = array of TRecordValuesItem;
  262. TRecordValues = class(TPasExpr)
  263. Fields : TRecordValuesItemArray;
  264. constructor Create(AParent : TPasElement); overload;
  265. destructor Destroy; override;
  266. procedure FreeChildren(Prepare: boolean); override;
  267. procedure AddField(AName: TPrimitiveExpr; Value: TPasExpr);
  268. function GetDeclaration(full : Boolean) : TPasTreeString; override;
  269. procedure ForEachCall(const aMethodCall: TOnForEachPasElement;
  270. const Arg: Pointer); override;
  271. end;
  272. { TArrayValues }
  273. TArrayValues = class(TPasExpr)
  274. Values : TPasExprArray;
  275. constructor Create(AParent : TPasElement); overload;
  276. destructor Destroy; override;
  277. procedure FreeChildren(Prepare: boolean); override;
  278. procedure AddValues(AValue: TPasExpr);
  279. function GetDeclaration(full : Boolean) : TPasTreeString; override;
  280. procedure ForEachCall(const aMethodCall: TOnForEachPasElement;
  281. const Arg: Pointer); override;
  282. end;
  283. { TPasDeclarations - base class of TPasSection, TProcedureBody }
  284. TPasDeclarations = class(TPasElement)
  285. public
  286. constructor Create(const AName: TPasTreeString; AParent: TPasElement); override;
  287. destructor Destroy; override;
  288. procedure FreeChildren(Prepare: boolean); override;
  289. function ElementTypeName: TPasTreeString; override;
  290. procedure ForEachCall(const aMethodCall: TOnForEachPasElement;
  291. const Arg: Pointer); override;
  292. public
  293. Declarations: TFPList; // list of TPasElement
  294. // Declarations contains all the following:
  295. Attributes, // TPasAttributes
  296. Classes, // TPasClassType, TPasRecordType
  297. Consts, // TPasConst
  298. ExportSymbols,// TPasExportSymbol
  299. Functions, // TPasProcedure
  300. Properties, // TPasProperty
  301. ResStrings, // TPasResString
  302. Labels, // TPasLabel
  303. Types, // TPasType, except TPasClassType, TPasRecordType
  304. Variables // TPasVariable, not descendants
  305. : TFPList;
  306. end;
  307. { TPasUsesUnit - Parent is TPasSection }
  308. TPasUsesUnit = class(TPasElement)
  309. public
  310. procedure FreeChildren(Prepare: boolean); override;
  311. function ElementTypeName: TPasTreeString; override;
  312. procedure ForEachCall(const aMethodCall: TOnForEachPasElement;
  313. const Arg: Pointer); override;
  314. public
  315. Expr: TPasExpr; // name expression
  316. InFilename: TPrimitiveExpr; // Kind=pekString, can be nil
  317. Module: TPasElement; // TPasUnresolvedUnitRef or TPasModule
  318. end;
  319. TPasUsesClause = array of TPasUsesUnit;
  320. { TPasSection }
  321. TPasSection = class(TPasDeclarations)
  322. public
  323. constructor Create(const AName: TPasTreeString; AParent: TPasElement); override;
  324. destructor Destroy; override;
  325. procedure FreeChildren(Prepare: boolean); override;
  326. function AddUnitToUsesList(const AUnitName: TPasTreeString; aName: TPasExpr = nil;
  327. InFilename: TPrimitiveExpr = nil; aModule: TPasElement = nil;
  328. UsesUnit: TPasUsesUnit = nil): TPasUsesUnit;
  329. function ElementTypeName: TPasTreeString; override;
  330. procedure ForEachCall(const aMethodCall: TOnForEachPasElement;
  331. const Arg: Pointer); override;
  332. public
  333. UsesList: TFPList; // kept for compatibility, see TPasUsesUnit.Module
  334. UsesClause: TPasUsesClause;
  335. PendingUsedIntf: TPasUsesUnit; // <>nil while resolving a uses cycle
  336. end;
  337. TPasSectionClass = class of TPasSection;
  338. { TInterfaceSection }
  339. TInterfaceSection = class(TPasSection)
  340. public
  341. function ElementTypeName: TPasTreeString; override;
  342. end;
  343. { TImplementationSection }
  344. TImplementationSection = class(TPasSection)
  345. public
  346. function ElementTypeName: TPasTreeString; override;
  347. end;
  348. { TProgramSection }
  349. TProgramSection = class(TImplementationSection)
  350. public
  351. function ElementTypeName: TPasTreeString; override;
  352. end;
  353. { TLibrarySection }
  354. TLibrarySection = class(TImplementationSection)
  355. public
  356. function ElementTypeName: TPasTreeString; override;
  357. end;
  358. TPasImplCommandBase = class;
  359. TInitializationSection = class;
  360. TFinalizationSection = class;
  361. { TPasModule }
  362. TPasModule = class(TPasElement)
  363. public
  364. procedure FreeChildren(Prepare: boolean); override;
  365. function ElementTypeName: TPasTreeString; override;
  366. function GetDeclaration(full : boolean) : TPasTreeString; override;
  367. procedure ForEachCall(const aMethodCall: TOnForEachPasElement;
  368. const Arg: Pointer); override;
  369. public
  370. GlobalDirectivesSection: TPasImplCommandBase; // not used by pparser
  371. InterfaceSection: TInterfaceSection;
  372. ImplementationSection: TImplementationSection;
  373. InitializationSection: TInitializationSection; // in TPasProgram the begin..end.
  374. FinalizationSection: TFinalizationSection;
  375. PackageName: TPasTreeString;
  376. Filename : TPasTreeString; // the IN filename, only written when not empty.
  377. end;
  378. TPasModuleClass = class of TPasModule;
  379. { TPasUnitModule }
  380. TPasUnitModule = Class(TPasModule)
  381. function ElementTypeName: TPasTreeString; override;
  382. end;
  383. { TPasProgram }
  384. TPasProgram = class(TPasModule)
  385. Public
  386. procedure FreeChildren(Prepare: boolean); override;
  387. function ElementTypeName: TPasTreeString; override;
  388. procedure ForEachCall(const aMethodCall: TOnForEachPasElement;
  389. const Arg: Pointer); override;
  390. Public
  391. ProgramSection: TProgramSection;
  392. InputFile,OutPutFile : TPasTreeString;
  393. // Note: the begin..end. block is in the InitializationSection
  394. end;
  395. { TPasLibrary }
  396. TPasLibrary = class(TPasModule)
  397. Public
  398. procedure FreeChildren(Prepare: boolean); override;
  399. function ElementTypeName: TPasTreeString; override;
  400. procedure ForEachCall(const aMethodCall: TOnForEachPasElement;
  401. const Arg: Pointer); override;
  402. Public
  403. LibrarySection: TLibrarySection;
  404. InputFile,OutPutFile : TPasTreeString;
  405. end;
  406. { TPasPackage }
  407. TPasPackage = class(TPasElement)
  408. public
  409. constructor Create(const AName: TPasTreeString; AParent: TPasElement); override;
  410. destructor Destroy; override;
  411. procedure FreeChildren(Prepare: boolean); override;
  412. function ElementTypeName: TPasTreeString; override;
  413. procedure ForEachCall(const aMethodCall: TOnForEachPasElement;
  414. const Arg: Pointer); override;
  415. public
  416. Modules: TFPList; // List of TPasModule objects
  417. end;
  418. { TPasResString }
  419. TPasResString = class(TPasElement)
  420. public
  421. procedure FreeChildren(Prepare: boolean); override;
  422. function ElementTypeName: TPasTreeString; override;
  423. function GetDeclaration(full : Boolean) : TPasTreeString; Override;
  424. procedure ForEachCall(const aMethodCall: TOnForEachPasElement;
  425. const Arg: Pointer); override;
  426. public
  427. Expr: TPasExpr;
  428. end;
  429. { TPasType }
  430. TPasType = class(TPasElement)
  431. Protected
  432. Function FixTypeDecl(aDecl: TPasTreeString) : TPasTreeString;
  433. public
  434. Function SafeName : TPasTreeString; override;
  435. function ElementTypeName: TPasTreeString; override;
  436. end;
  437. TPasTypeArray = array of TPasType;
  438. { TPasAliasType }
  439. TPasAliasType = class(TPasType)
  440. public
  441. procedure FreeChildren(Prepare: boolean); override;
  442. function ElementTypeName: TPasTreeString; override;
  443. function GetDeclaration(full : Boolean): TPasTreeString; override;
  444. procedure ForEachCall(const aMethodCall: TOnForEachPasElement;
  445. const Arg: Pointer); override;
  446. procedure ClearTypeReferences(aType: TPasElement); override;
  447. public
  448. DestType: TPasType;
  449. SubType: TPasType;
  450. Expr: TPasExpr;
  451. CodepageExpr: TPasExpr;
  452. end;
  453. { TPasPointerType - todo: change it TPasAliasType }
  454. TPasPointerType = class(TPasType)
  455. public
  456. procedure FreeChildren(Prepare: boolean); override;
  457. function ElementTypeName: TPasTreeString; override;
  458. function GetDeclaration(full : Boolean): TPasTreeString; override;
  459. procedure ForEachCall(const aMethodCall: TOnForEachPasElement;
  460. const Arg: Pointer); override;
  461. procedure ClearTypeReferences(aType: TPasElement); override;
  462. public
  463. DestType: TPasType;
  464. end;
  465. { TPasTypeAliasType }
  466. TPasTypeAliasType = class(TPasAliasType)
  467. public
  468. function ElementTypeName: TPasTreeString; override;
  469. end;
  470. { TPasGenericTemplateType - type param of a generic }
  471. TPasGenericTemplateType = Class(TPasType)
  472. public
  473. destructor Destroy; override;
  474. procedure FreeChildren(Prepare: boolean); override;
  475. function GetDeclaration(full : boolean) : TPasTreeString; override;
  476. procedure ForEachCall(const aMethodCall: TOnForEachPasElement;
  477. const Arg: Pointer); override;
  478. procedure AddConstraint(El: TPasElement);
  479. procedure ClearTypeReferences(aType: TPasElement); override;
  480. Public
  481. TypeConstraint: TPasTreeString deprecated; // deprecated in fpc 3.3.1
  482. Constraints: TPasElementArray; // list of TPasExpr or TPasType, can be nil!
  483. end;
  484. { TPasGenericType - abstract base class for all types which can be generics }
  485. TPasGenericType = class(TPasType)
  486. public
  487. GenericTemplateTypes: TFPList; // list of TPasGenericTemplateType, can be nil
  488. destructor Destroy; override;
  489. procedure FreeChildren(Prepare: boolean); override;
  490. procedure ForEachCall(const aMethodCall: TOnForEachPasElement;
  491. const Arg: Pointer); override;
  492. procedure SetGenericTemplates(AList: TFPList); virtual;
  493. end;
  494. { TPasSpecializeType DestType<Params> }
  495. TPasSpecializeType = class(TPasAliasType)
  496. public
  497. constructor Create(const AName: TPasTreeString; AParent: TPasElement); override;
  498. destructor Destroy; override;
  499. procedure FreeChildren(Prepare: boolean); override;
  500. procedure ClearTypeReferences(aType: TPasElement); override;
  501. function ElementTypeName: TPasTreeString; override;
  502. function GetDeclaration(full: boolean) : TPasTreeString; override;
  503. procedure ForEachCall(const aMethodCall: TOnForEachPasElement;
  504. const Arg: Pointer); override;
  505. public
  506. Params: TFPList; // list of TPasType or TPasExpr
  507. end;
  508. { TInlineSpecializeExpr - A<B,C> }
  509. TInlineSpecializeExpr = class(TPasExpr)
  510. public
  511. constructor Create(const AName: TPasTreeString; AParent: TPasElement); override;
  512. destructor Destroy; override;
  513. procedure FreeChildren(Prepare: boolean); override;
  514. procedure ClearTypeReferences(aType: TPasElement); override;
  515. function ElementTypeName: TPasTreeString; override;
  516. function GetDeclaration(full : Boolean): TPasTreeString; override;
  517. procedure ForEachCall(const aMethodCall: TOnForEachPasElement;
  518. const Arg: Pointer); override;
  519. public
  520. NameExpr: TPasExpr;
  521. Params: TFPList; // list of TPasType
  522. end;
  523. { TPasClassOfType }
  524. TPasClassOfType = class(TPasAliasType)
  525. public
  526. function ElementTypeName: TPasTreeString; override;
  527. function GetDeclaration(full: boolean) : TPasTreeString; override;
  528. end;
  529. { TPasRangeType }
  530. TPasRangeType = class(TPasType)
  531. public
  532. function ElementTypeName: TPasTreeString; override;
  533. function GetDeclaration(full : boolean) : TPasTreeString; override;
  534. procedure ForEachCall(const aMethodCall: TOnForEachPasElement;
  535. const Arg: Pointer); override;
  536. public
  537. RangeExpr : TBinaryExpr; // Kind=pekRange
  538. procedure FreeChildren(Prepare: boolean); override;
  539. Function RangeStart : TPasTreeString;
  540. Function RangeEnd : TPasTreeString;
  541. end;
  542. { TPasArrayType }
  543. TPasArrayType = class(TPasGenericType)
  544. public
  545. procedure FreeChildren(Prepare: boolean); override;
  546. procedure ClearTypeReferences(aType: TPasElement); override;
  547. function ElementTypeName: TPasTreeString; override;
  548. function GetDeclaration(full : boolean) : TPasTreeString; override;
  549. public
  550. IndexRange : TPasTreeString; // only valid if Parser po_arrayrangeexpr disabled
  551. Ranges: TPasExprArray; // only valid if Parser po_arrayrangeexpr enabled
  552. PackMode : TPackMode;
  553. ElType: TPasType; // nil means array-of-const
  554. function IsGenericArray : Boolean; inline;
  555. function IsPacked : Boolean; inline;
  556. procedure AddRange(Range: TPasExpr);
  557. end;
  558. { TPasFileType }
  559. TPasFileType = class(TPasType)
  560. public
  561. procedure FreeChildren(Prepare: boolean); override;
  562. procedure ClearTypeReferences(aType: TPasElement); override;
  563. function ElementTypeName: TPasTreeString; override;
  564. function GetDeclaration(full : boolean) : TPasTreeString; override;
  565. procedure ForEachCall(const aMethodCall: TOnForEachPasElement;
  566. const Arg: Pointer); override;
  567. public
  568. ElType: TPasType;
  569. end;
  570. { TPasEnumValue - Parent is TPasEnumType }
  571. TPasEnumValue = class(TPasElement)
  572. public
  573. function ElementTypeName: TPasTreeString; override;
  574. procedure ForEachCall(const aMethodCall: TOnForEachPasElement;
  575. const Arg: Pointer); override;
  576. public
  577. Value: TPasExpr;
  578. procedure FreeChildren(Prepare: boolean); override;
  579. Function AssignedValue : TPasTreeString;
  580. end;
  581. { TPasEnumType }
  582. TPasEnumType = class(TPasType)
  583. public
  584. constructor Create(const AName: TPasTreeString; AParent: TPasElement); override;
  585. destructor Destroy; override;
  586. procedure FreeChildren(Prepare: boolean); override;
  587. function ElementTypeName: TPasTreeString; override;
  588. function GetDeclaration(full : boolean) : TPasTreeString; override;
  589. Procedure GetEnumNames(Names : TStrings);
  590. procedure ForEachCall(const aMethodCall: TOnForEachPasElement;
  591. const Arg: Pointer); override;
  592. public
  593. Values: TFPList; // List of TPasEnumValue
  594. end;
  595. { TPasSetType }
  596. TPasSetType = class(TPasType)
  597. public
  598. procedure FreeChildren(Prepare: boolean); override;
  599. procedure ClearTypeReferences(aType: TPasElement); override;
  600. function ElementTypeName: TPasTreeString; override;
  601. function GetDeclaration(full : boolean) : TPasTreeString; override;
  602. procedure ForEachCall(const aMethodCall: TOnForEachPasElement;
  603. const Arg: Pointer); override;
  604. public
  605. EnumType: TPasType; // alias or enumtype
  606. IsPacked : Boolean;
  607. end;
  608. TPasRecordType = class;
  609. { TPasVariant }
  610. TPasVariant = class(TPasElement)
  611. public
  612. constructor Create(const AName: TPasTreeString; AParent: TPasElement); override;
  613. destructor Destroy; override;
  614. procedure FreeChildren(Prepare: boolean); override;
  615. function GetDeclaration(full : boolean) : TPasTreeString; override;
  616. procedure ForEachCall(const aMethodCall: TOnForEachPasElement;
  617. const Arg: Pointer); override;
  618. public
  619. Values: TFPList; // list of TPasExpr
  620. Members: TPasRecordType;
  621. end;
  622. { TPasMembersType - base type for TPasRecordType and TPasClassType }
  623. TPasMembersType = class(TPasGenericType)
  624. public
  625. PackMode: TPackMode;
  626. Members: TFPList;
  627. Constructor Create(const AName: TPasTreeString; AParent: TPasElement); override;
  628. Destructor Destroy; override;
  629. procedure FreeChildren(Prepare: boolean); override;
  630. Function IsPacked: Boolean; inline;
  631. Function IsBitPacked : Boolean; inline;
  632. Procedure ForEachCall(const aMethodCall: TOnForEachPasElement;
  633. const Arg: Pointer); override;
  634. end;
  635. { TPasRecordType }
  636. TPasRecordType = class(TPasMembersType)
  637. private
  638. procedure GetMembers(S: TStrings);
  639. public
  640. constructor Create(const AName: TPasTreeString; AParent: TPasElement); override;
  641. destructor Destroy; override;
  642. procedure FreeChildren(Prepare: boolean); override;
  643. procedure ClearTypeReferences(aType: TPasElement); override;
  644. function ElementTypeName: TPasTreeString; override;
  645. function GetDeclaration(full : boolean) : TPasTreeString; override;
  646. procedure ForEachCall(const aMethodCall: TOnForEachPasElement;
  647. const Arg: Pointer); override;
  648. public
  649. VariantEl: TPasElement; // nil or TPasVariable or TPasType
  650. Variants: TFPList; // list of TPasVariant elements, may be nil!
  651. Function IsAdvancedRecord : Boolean;
  652. end;
  653. TPasObjKind = (
  654. okObject, okClass, okInterface,
  655. // okGeneric removed in FPC 3.3.1 check instead GenericTemplateTypes<>nil
  656. // okSpecialize removed in FPC 3.1.1
  657. okClassHelper, okRecordHelper, okTypeHelper,
  658. okDispInterface, okObjcClass, okObjcCategory,
  659. okObjcProtocol);
  660. const
  661. okWithFields = [okObject, okClass, okObjcClass, okObjcCategory];
  662. okAllHelpers = [okClassHelper,okRecordHelper,okTypeHelper];
  663. okWithClassFields = okWithFields+okAllHelpers;
  664. okObjCClasses = [okObjcClass, okObjcCategory, okObjcProtocol];
  665. type
  666. TPasClassInterfaceType = (
  667. citCom, // default
  668. citCorba
  669. );
  670. { TPasClassType }
  671. TPasClassType = class(TPasMembersType)
  672. public
  673. constructor Create(const AName: TPasTreeString; AParent: TPasElement); override;
  674. destructor Destroy; override;
  675. procedure FreeChildren(Prepare: boolean); override;
  676. procedure ClearTypeReferences(aType: TPasElement); override;
  677. function ElementTypeName: TPasTreeString; override;
  678. procedure ForEachCall(const aMethodCall: TOnForEachPasElement;
  679. const Arg: Pointer); override;
  680. public
  681. ObjKind: TPasObjKind;
  682. AncestorType: TPasType; // TPasClassType or TPasUnresolvedTypeRef or TPasAliasType or TPasTypeAliasType
  683. // Note: AncestorType can be nil even though it has a default ancestor
  684. HelperForType: TPasType; // any type, except helper
  685. IsForward: Boolean;
  686. IsExternal : Boolean;
  687. IsShortDefinition: Boolean;//class(anchestor); without end
  688. GUIDExpr : TPasExpr;
  689. Modifiers: TStringList;
  690. Interfaces : TFPList; // list of TPasType
  691. ExternalNameSpace : TPasTreeString;
  692. ExternalName : TPasTreeString;
  693. InterfaceType: TPasClassInterfaceType;
  694. Function IsObjCClass : Boolean;
  695. Function FindMember(MemberClass : TPTreeElement; Const MemberName : TPasTreeString) : TPasElement;
  696. Function FindMemberInAncestors(MemberClass : TPTreeElement; Const MemberName : TPasTreeString) : TPasElement;
  697. Function InterfaceGUID : TPasTreeString;
  698. Function IsSealed : Boolean;
  699. Function IsAbstract : Boolean;
  700. Function HasModifier(const aModifier: TPasTreeString): Boolean;
  701. end;
  702. TArgumentAccess = (argDefault, argConst, argVar, argOut, argConstRef);
  703. { TPasArgument }
  704. TPasArgument = class(TPasElement)
  705. public
  706. procedure FreeChildren(Prepare: boolean); override;
  707. procedure ClearTypeReferences(aType: TPasElement); override;
  708. function ElementTypeName: TPasTreeString; override;
  709. function GetDeclaration(full : boolean) : TPasTreeString; override;
  710. procedure ForEachCall(const aMethodCall: TOnForEachPasElement;
  711. const Arg: Pointer); override;
  712. public
  713. Access: TArgumentAccess;
  714. ArgType: TPasType; // can be nil, when Access<>argDefault
  715. ValueExpr: TPasExpr; // the default value
  716. Function Value : TPasTreeString;
  717. end;
  718. { TPasProcedureType }
  719. TPasProcedureType = class(TPasGenericType)
  720. private
  721. function GetIsAsync: Boolean; inline;
  722. function GetIsNested: Boolean; inline;
  723. function GetIsOfObject: Boolean; inline;
  724. function GetIsReference: Boolean; inline;
  725. procedure SetIsAsync(const AValue: Boolean);
  726. procedure SetIsNested(const AValue: Boolean);
  727. procedure SetIsOfObject(const AValue: Boolean);
  728. procedure SetIsReference(AValue: Boolean);
  729. public
  730. constructor Create(const AName: TPasTreeString; AParent: TPasElement); override;
  731. destructor Destroy; override;
  732. procedure FreeChildren(Prepare: boolean); override;
  733. procedure ClearTypeReferences(aType: TPasElement); override;
  734. class function TypeName: TPasTreeString; virtual;
  735. function ElementTypeName: TPasTreeString; override;
  736. function GetDeclaration(full : boolean) : TPasTreeString; override;
  737. procedure GetArguments(List : TStrings);
  738. function CreateArgument(const AName, AUnresolvedTypeName: TPasTreeString): TPasArgument; // not used by TPasParser
  739. procedure ForEachCall(const aMethodCall: TOnForEachPasElement;
  740. const Arg: Pointer); override;
  741. public
  742. Args: TFPList; // List of TPasArgument objects
  743. CallingConvention: TCallingConvention;
  744. Modifiers: TProcTypeModifiers;
  745. VarArgsType: TPasType;
  746. property IsOfObject: Boolean read GetIsOfObject write SetIsOfObject;
  747. property IsNested : Boolean read GetIsNested write SetIsNested;
  748. property IsReferenceTo : Boolean Read GetIsReference write SetIsReference;
  749. property IsAsync: Boolean read GetIsAsync write SetIsAsync;
  750. end;
  751. TPasProcedureTypeClass = class of TPasProcedureType;
  752. { TPasResultElement - parent is TPasFunctionType }
  753. TPasResultElement = class(TPasElement)
  754. public
  755. procedure FreeChildren(Prepare: boolean); override;
  756. function ElementTypeName : TPasTreeString; override;
  757. procedure ForEachCall(const aMethodCall: TOnForEachPasElement;
  758. const Arg: Pointer); override;
  759. procedure ClearTypeReferences(aType: TPasElement); override;
  760. public
  761. ResultType: TPasType;
  762. end;
  763. { TPasFunctionType }
  764. TPasFunctionType = class(TPasProcedureType)
  765. public
  766. procedure FreeChildren(Prepare: boolean); override;
  767. class function TypeName: TPasTreeString; override;
  768. function ElementTypeName: TPasTreeString; override;
  769. function GetDeclaration(Full : boolean) : TPasTreeString; override;
  770. procedure ForEachCall(const aMethodCall: TOnForEachPasElement;
  771. const Arg: Pointer); override;
  772. public
  773. ResultEl: TPasResultElement;
  774. end;
  775. TPasUnresolvedSymbolRef = class(TPasType)
  776. end;
  777. TPasUnresolvedTypeRef = class(TPasUnresolvedSymbolRef)
  778. public
  779. // Typerefs cannot be parented! -> AParent _must_ be NIL
  780. constructor Create(const AName: TPasTreeString; AParent: TPasElement); override;
  781. function ElementTypeName: TPasTreeString; override;
  782. end;
  783. { TPasUnresolvedUnitRef }
  784. TPasUnresolvedUnitRef = Class(TPasUnresolvedSymbolRef)
  785. public
  786. FileName : TPasTreeString;
  787. function ElementTypeName: TPasTreeString; override;
  788. end;
  789. { TPasStringType - e.g. TPasTreeString[len] }
  790. TPasStringType = class(TPasUnresolvedTypeRef)
  791. public
  792. LengthExpr : TPasTreeString;
  793. CodePageExpr : TPasTreeString;
  794. function ElementTypeName: TPasTreeString; override;
  795. end;
  796. { TPasTypeRef - not used by TPasParser }
  797. TPasTypeRef = class(TPasUnresolvedTypeRef)
  798. public
  799. procedure ForEachCall(const aMethodCall: TOnForEachPasElement;
  800. const Arg: Pointer); override;
  801. public
  802. RefType: TPasType;
  803. end;
  804. { TPasVariable }
  805. TVariableModifier = (vmCVar, vmExternal, vmPublic, vmExport, vmClass, vmStatic, vmfar);
  806. TVariableModifiers = set of TVariableModifier;
  807. TPasVariable = class(TPasElement)
  808. public
  809. procedure FreeChildren(Prepare: boolean); override;
  810. function ElementTypeName: TPasTreeString; override;
  811. function GetDeclaration(full : boolean) : TPasTreeString; override;
  812. procedure ForEachCall(const aMethodCall: TOnForEachPasElement;
  813. const Arg: Pointer); override;
  814. procedure ClearTypeReferences(aType: TPasElement); override;
  815. public
  816. VarType: TPasType;
  817. VarModifiers : TVariableModifiers;
  818. LibraryName : TPasExpr; // libname of modifier external
  819. ExportName : TPasExpr; // symbol name of modifier external, export and public
  820. Modifiers : TPasTreeString;
  821. AbsoluteLocation : TPasTreeString deprecated; // deprecated in fpc 3.1.1
  822. AbsoluteExpr: TPasExpr;
  823. Expr: TPasExpr;
  824. Function Value : TPasTreeString;
  825. end;
  826. { TPasExportSymbol }
  827. TPasExportSymbol = class(TPasElement)
  828. public
  829. NameExpr: TPasExpr; // only if name is not a simple identifier
  830. ExportName : TPasExpr;
  831. ExportIndex : TPasExpr;
  832. procedure FreeChildren(Prepare: boolean); override;
  833. function ElementTypeName: TPasTreeString; override;
  834. function GetDeclaration(full : boolean) : TPasTreeString; override;
  835. procedure ForEachCall(const aMethodCall: TOnForEachPasElement;
  836. const Arg: Pointer); override;
  837. end;
  838. { TPasConst }
  839. TPasConst = class(TPasVariable)
  840. public
  841. IsConst: boolean; // true iff untyped const or typed with $WritableConst off
  842. function ElementTypeName: TPasTreeString; override;
  843. end;
  844. { TPasProperty }
  845. TPasProperty = class(TPasVariable)
  846. private
  847. FArgs: TFPList;
  848. FResolvedType : TPasType;
  849. function GetIsClass: boolean; inline;
  850. procedure SetIsClass(AValue: boolean);
  851. public
  852. constructor Create(const AName: TPasTreeString; AParent: TPasElement); override;
  853. destructor Destroy; override;
  854. procedure FreeChildren(Prepare: boolean); override;
  855. function ElementTypeName: TPasTreeString; override;
  856. function GetDeclaration(full : boolean) : TPasTreeString; override;
  857. procedure ForEachCall(const aMethodCall: TOnForEachPasElement;
  858. const Arg: Pointer); override;
  859. public
  860. IndexExpr: TPasExpr;
  861. ReadAccessor: TPasExpr;
  862. WriteAccessor: TPasExpr;
  863. DispIDExpr : TPasExpr; // Can be nil.
  864. Implements: TPasExprArray;
  865. StoredAccessor: TPasExpr;
  866. DefaultExpr: TPasExpr;
  867. ReadAccessorName: TPasTreeString; // not used by resolver
  868. WriteAccessorName: TPasTreeString; // not used by resolver
  869. ImplementsName: TPasTreeString; // not used by resolver
  870. StoredAccessorName: TPasTreeString; // not used by resolver
  871. DispIDReadOnly,
  872. IsDefault, IsNodefault: Boolean;
  873. property Args: TFPList read FArgs; // List of TPasArgument objects
  874. property IsClass: boolean read GetIsClass write SetIsClass;
  875. Function ResolvedType : TPasType;
  876. Function IndexValue : TPasTreeString;
  877. Function DefaultValue : TPasTreeString;
  878. end;
  879. { TPasAttributes }
  880. TPasAttributes = class(TPasElement)
  881. public
  882. procedure FreeChildren(Prepare: boolean); override;
  883. procedure ForEachCall(const aMethodCall: TOnForEachPasElement;
  884. const Arg: Pointer); override;
  885. procedure AddCall(Expr: TPasExpr);
  886. public
  887. Calls: TPasExprArray;
  888. end;
  889. TProcType = (ptProcedure, ptFunction,
  890. ptOperator, ptClassOperator,
  891. ptConstructor, ptDestructor,
  892. ptClassProcedure, ptClassFunction,
  893. ptClassConstructor, ptClassDestructor,
  894. ptAnonymousProcedure, ptAnonymousFunction);
  895. { TPasProcedureBase }
  896. TPasProcedureBase = class(TPasElement)
  897. public
  898. function TypeName: TPasTreeString; virtual; abstract;
  899. end;
  900. { TPasOverloadedProc - not used by resolver }
  901. TPasOverloadedProc = class(TPasProcedureBase)
  902. public
  903. constructor Create(const AName: TPasTreeString; AParent: TPasElement); override;
  904. destructor Destroy; override;
  905. procedure FreeChildren(Prepare: boolean); override;
  906. function ElementTypeName: TPasTreeString; override;
  907. function TypeName: TPasTreeString; override;
  908. procedure ForEachCall(const aMethodCall: TOnForEachPasElement;
  909. const Arg: Pointer); override;
  910. public
  911. Overloads: TFPList; // List of TPasProcedure nodes
  912. end;
  913. { TPasProcedure }
  914. TProcedureModifier = (pmVirtual, pmDynamic, pmAbstract, pmOverride,
  915. pmExport, pmOverload, pmMessage, pmReintroduce,
  916. pmInline, pmAssembler, pmPublic,
  917. pmCompilerProc, pmExternal, pmForward, pmDispId,
  918. pmNoReturn, pmFar, pmFinal, pmDiscardResult,
  919. pmNoStackFrame, pmsection, pmRtlProc, pmInternProc);
  920. TProcedureModifiers = Set of TProcedureModifier;
  921. TProcedureMessageType = (pmtNone,pmtInteger,pmtString);
  922. { TProcedureNamePart }
  923. TProcedureNamePart = class
  924. Name: TPasTreeString;
  925. Templates: TFPList; // optional list of TPasGenericTemplateType, can be nil!
  926. end;
  927. TProcedureNameParts = TFPList; // list of TProcedureNamePart
  928. TProcedureBody = class;
  929. { TPasProcedure - named procedure, not anonymous }
  930. TPasProcedure = class(TPasProcedureBase)
  931. Private
  932. FModifiers : TProcedureModifiers;
  933. FMessageName : TPasTreeString;
  934. FMessageType : TProcedureMessageType;
  935. function GetCallingConvention: TCallingConvention;
  936. procedure SetCallingConvention(AValue: TCallingConvention);
  937. public
  938. destructor Destroy; override;
  939. procedure FreeChildren(Prepare: boolean); override;
  940. function ElementTypeName: TPasTreeString; override;
  941. function TypeName: TPasTreeString; override;
  942. function GetDeclaration(full: Boolean): TPasTreeString; override;
  943. procedure GetModifiers(List: TStrings);
  944. procedure ForEachCall(const aMethodCall: TOnForEachPasElement;
  945. const Arg: Pointer); override;
  946. public
  947. PublicName, // e.g. public PublicName;
  948. LibrarySymbolIndex : TPasExpr;
  949. LibrarySymbolName,
  950. LibraryExpr : TPasExpr; // e.g. external LibraryExpr name LibrarySymbolName;
  951. DispIDExpr : TPasExpr;
  952. MessageExpr: TPasExpr;
  953. CompProcID : String;
  954. AliasName : TPasTreeString;
  955. ProcType : TPasProcedureType;
  956. Body : TProcedureBody;
  957. NameParts: TProcedureNameParts; // only used for generic aka parametrized functions
  958. Procedure AddModifier(AModifier : TProcedureModifier);
  959. Function CanParseImplementation : Boolean;
  960. Function HasNoImplementation : Boolean;
  961. Function IsVirtual : Boolean; inline;
  962. Function IsDynamic : Boolean; inline;
  963. Function IsAbstract : Boolean; inline;
  964. Function IsOverride : Boolean; inline;
  965. Function IsExported : Boolean; inline;
  966. Function IsExternal : Boolean; inline;
  967. Function IsOverload : Boolean; inline;
  968. Function IsMessage: Boolean; inline;
  969. Function IsReintroduced : Boolean; inline;
  970. Function IsStatic : Boolean; inline;
  971. Function IsForward: Boolean; inline;
  972. Function IsCompilerProc: Boolean; inline;
  973. Function IsInternProc: Boolean; inline;
  974. Function IsAssembler: Boolean; inline;
  975. Function IsAsync: Boolean; inline;
  976. Function GetProcTypeEnum: TProcType; virtual;
  977. procedure SetNameParts(Parts: TProcedureNameParts);
  978. Property Modifiers : TProcedureModifiers Read FModifiers Write FModifiers;
  979. Property CallingConvention : TCallingConvention Read GetCallingConvention Write SetCallingConvention;
  980. Property MessageName : TPasTreeString Read FMessageName Write FMessageName;
  981. property MessageType : TProcedureMessageType Read FMessageType Write FMessageType;
  982. end;
  983. TPasProcedureClass = class of TPasProcedure;
  984. TArrayOfPasProcedure = array of TPasProcedure;
  985. { TPasFunction - named function, not anonymous function}
  986. TPasFunction = class(TPasProcedure)
  987. private
  988. function GetFT: TPasFunctionType; inline;
  989. public
  990. function ElementTypeName: TPasTreeString; override;
  991. function TypeName: TPasTreeString; override;
  992. Property FuncType : TPasFunctionType Read GetFT;
  993. function GetProcTypeEnum: TProcType; override;
  994. end;
  995. { TPasOperator }
  996. TOperatorType = (
  997. otUnknown,
  998. otImplicit, otExplicit,
  999. otMul, otPlus, otMinus, otDivision,
  1000. otLessThan, otEqual, otGreaterThan,
  1001. otAssign, otNotEqual, otLessEqualThan, otGreaterEqualThan,
  1002. otPower, otSymmetricalDifference,
  1003. otInc, otDec,
  1004. otMod,
  1005. otNegative, otPositive,
  1006. otBitWiseOr,
  1007. otDiv,
  1008. otLeftShift,
  1009. otLogicalOr,
  1010. otBitwiseAnd, otbitwiseXor,
  1011. otLogicalAnd, otLogicalNot, otLogicalXor,
  1012. otRightShift,
  1013. otEnumerator, otIn,
  1014. // Management operators
  1015. otInitialize,
  1016. otFinalize,
  1017. otAddRef,
  1018. otCopy
  1019. );
  1020. TOperatorTypes = set of TOperatorType;
  1021. TPasOperator = class(TPasFunction)
  1022. private
  1023. FOperatorType: TOperatorType;
  1024. FTokenBased: Boolean;
  1025. function NameSuffix: TPasTreeString;
  1026. public
  1027. Class Function OperatorTypeToToken(T : TOperatorType) : TPasTreeString;
  1028. Class Function OperatorTypeToOperatorName(T: TOperatorType) : TPasTreeString;
  1029. Class Function TokenToOperatorType(S : TPasTreeString) : TOperatorType;
  1030. Class Function NameToOperatorType(S : TPasTreeString) : TOperatorType;
  1031. Procedure CorrectName;
  1032. // For backwards compatibility the old name can still be used to search on.
  1033. function GetOperatorDeclaration(Full: Boolean): TPasTreeString;
  1034. Function OldName(WithPath : Boolean) : TPasTreeString;
  1035. function ElementTypeName: TPasTreeString; override;
  1036. function TypeName: TPasTreeString; override;
  1037. function GetProcTypeEnum: TProcType; override;
  1038. function GetDeclaration (full : boolean) : TPasTreeString; override;
  1039. Property OperatorType : TOperatorType Read FOperatorType Write FOperatorType;
  1040. // True if the declaration was using a token instead of an identifier
  1041. Property TokenBased : Boolean Read FTokenBased Write FTokenBased;
  1042. end;
  1043. { TPasClassOperator }
  1044. TPasClassOperator = class(TPasOperator)
  1045. public
  1046. function TypeName: TPasTreeString; override;
  1047. function GetProcTypeEnum: TProcType; override;
  1048. end;
  1049. { TPasConstructor }
  1050. TPasConstructor = class(TPasProcedure)
  1051. public
  1052. function ElementTypeName: TPasTreeString; override;
  1053. function TypeName: TPasTreeString; override;
  1054. function GetProcTypeEnum: TProcType; override;
  1055. end;
  1056. { TPasClassConstructor }
  1057. TPasClassConstructor = class(TPasConstructor)
  1058. public
  1059. function ElementTypeName: TPasTreeString; override;
  1060. function TypeName: TPasTreeString; override;
  1061. function GetProcTypeEnum: TProcType; override;
  1062. end;
  1063. { TPasDestructor }
  1064. TPasDestructor = class(TPasProcedure)
  1065. public
  1066. function ElementTypeName: TPasTreeString; override;
  1067. function TypeName: TPasTreeString; override;
  1068. function GetProcTypeEnum: TProcType; override;
  1069. end;
  1070. { TPasClassDestructor }
  1071. TPasClassDestructor = class(TPasDestructor)
  1072. public
  1073. function ElementTypeName: TPasTreeString; override;
  1074. function TypeName: TPasTreeString; override;
  1075. function GetProcTypeEnum: TProcType; override;
  1076. end;
  1077. { TPasClassProcedure }
  1078. TPasClassProcedure = class(TPasProcedure)
  1079. public
  1080. function ElementTypeName: TPasTreeString; override;
  1081. function TypeName: TPasTreeString; override;
  1082. function GetProcTypeEnum: TProcType; override;
  1083. end;
  1084. { TPasClassFunction }
  1085. TPasClassFunction = class(TPasFunction)
  1086. public
  1087. function ElementTypeName: TPasTreeString; override;
  1088. function TypeName: TPasTreeString; override;
  1089. function GetProcTypeEnum: TProcType; override;
  1090. end;
  1091. { TPasAnonymousProcedure - parent is TProcedureExpr }
  1092. TPasAnonymousProcedure = class(TPasProcedure)
  1093. public
  1094. function ElementTypeName: TPasTreeString; override;
  1095. function TypeName: TPasTreeString; override;
  1096. function GetProcTypeEnum: TProcType; override;
  1097. end;
  1098. { TPasAnonymousFunction - parent is TProcedureExpr and ProcType is TPasFunctionType}
  1099. TPasAnonymousFunction = class(TPasAnonymousProcedure)
  1100. private
  1101. function GetFT: TPasFunctionType; inline;
  1102. public
  1103. function ElementTypeName: TPasTreeString; override;
  1104. function TypeName: TPasTreeString; override;
  1105. Property FuncType : TPasFunctionType Read GetFT;
  1106. function GetProcTypeEnum: TProcType; override;
  1107. end;
  1108. { TProcedureExpr }
  1109. TProcedureExpr = class(TPasExpr)
  1110. public
  1111. Proc: TPasAnonymousProcedure;
  1112. constructor Create(AParent: TPasElement); overload;
  1113. procedure FreeChildren(Prepare: boolean); override;
  1114. function GetDeclaration(full: Boolean): TPasTreeString; override;
  1115. procedure ForEachCall(const aMethodCall: TOnForEachPasElement;
  1116. const Arg: Pointer); override;
  1117. end;
  1118. { TPasMethodResolution }
  1119. TPasMethodResolution = class(TPasElement)
  1120. public
  1121. procedure FreeChildren(Prepare: boolean); override;
  1122. procedure ForEachCall(const aMethodCall: TOnForEachPasElement;
  1123. const Arg: Pointer); override;
  1124. public
  1125. ProcClass: TPasProcedureClass;
  1126. InterfaceName: TPasExpr;
  1127. InterfaceProc: TPasExpr;
  1128. ImplementationProc: TPasExpr;
  1129. end;
  1130. TPasImplBlock = class;
  1131. { TProcedureBody - the var+type+const+begin, without the header, child of TPasProcedure }
  1132. TProcedureBody = class(TPasDeclarations)
  1133. public
  1134. procedure FreeChildren(Prepare: boolean); override;
  1135. procedure ForEachCall(const aMethodCall: TOnForEachPasElement;
  1136. const Arg: Pointer); override;
  1137. public
  1138. Body: TPasImplBlock;
  1139. end;
  1140. { TPasProcedureImpl - used by mkxmlrpc, not by pparser }
  1141. TPasProcedureImpl = class(TPasElement)
  1142. public
  1143. constructor Create(const AName: TPasTreeString; AParent: TPasElement); override;
  1144. destructor Destroy; override;
  1145. procedure FreeChildren(Prepare: boolean); override;
  1146. function ElementTypeName: TPasTreeString; override;
  1147. function TypeName: TPasTreeString; virtual;
  1148. public
  1149. ProcType: TPasProcedureType;
  1150. Locals: TFPList;
  1151. Body: TPasImplBlock;
  1152. IsClassMethod: boolean;
  1153. end;
  1154. { TPasConstructorImpl - used by mkxmlrpc, not by pparser }
  1155. TPasConstructorImpl = class(TPasProcedureImpl)
  1156. public
  1157. function ElementTypeName: TPasTreeString; override;
  1158. function TypeName: TPasTreeString; override;
  1159. end;
  1160. { TPasDestructorImpl - used by mkxmlrpc, not by pparser }
  1161. TPasDestructorImpl = class(TPasProcedureImpl)
  1162. public
  1163. function ElementTypeName: TPasTreeString; override;
  1164. function TypeName: TPasTreeString; override;
  1165. end;
  1166. { TPasImplElement - implementation element }
  1167. TPasImplElement = class(TPasElement)
  1168. end;
  1169. { TPasImplCommandBase }
  1170. TPasImplCommandBase = class(TPasImplElement)
  1171. public
  1172. SemicolonAtEOL: boolean;
  1173. constructor Create(const AName: TPasTreeString; AParent: TPasElement); override;
  1174. end;
  1175. { TPasImplCommand - currently used as empty statement, e.g. if then else ; }
  1176. TPasImplCommand = class(TPasImplCommandBase)
  1177. public
  1178. Command: TPasTreeString; // never set by TPasParser
  1179. end;
  1180. { TPasImplCommands - used by mkxmlrpc, not used by pparser }
  1181. TPasImplCommands = class(TPasImplCommandBase)
  1182. public
  1183. constructor Create(const AName: TPasTreeString; AParent: TPasElement); override;
  1184. destructor Destroy; override;
  1185. public
  1186. Commands: TStrings;
  1187. end;
  1188. { TPasLabels }
  1189. TPasLabels = class(TPasImplElement)
  1190. public
  1191. Labels: TStrings;
  1192. constructor Create(const AName: TPasTreeString; AParent: TPasElement); override;
  1193. destructor Destroy; override;
  1194. end;
  1195. TPasImplBeginBlock = class;
  1196. TPasImplRepeatUntil = class;
  1197. TPasImplIfElse = class;
  1198. TPasImplWhileDo = class;
  1199. TPasImplWithDo = class;
  1200. TPasImplCaseOf = class;
  1201. TPasImplForLoop = class;
  1202. TPasImplTry = class;
  1203. TPasImplExceptOn = class;
  1204. TPasImplRaise = class;
  1205. TPasImplAssign = class;
  1206. TPasImplSimple = class;
  1207. TPasImplLabelMark = class;
  1208. { TPasImplBlock }
  1209. TPasImplBlock = class(TPasImplElement)
  1210. public
  1211. constructor Create(const AName: TPasTreeString; AParent: TPasElement); override;
  1212. destructor Destroy; override;
  1213. procedure FreeChildren(Prepare: boolean); override;
  1214. procedure AddElement(Element: TPasImplElement); virtual;
  1215. function AddCommand(const ACommand: TPasTreeString): TPasImplCommand;
  1216. function AddCommands: TPasImplCommands; // used by mkxmlrpc, not by pparser
  1217. function AddBeginBlock: TPasImplBeginBlock;
  1218. function AddRepeatUntil: TPasImplRepeatUntil;
  1219. function AddIfElse(const ACondition: TPasExpr): TPasImplIfElse;
  1220. function AddWhileDo(const ACondition: TPasExpr): TPasImplWhileDo;
  1221. function AddWithDo(const Expression: TPasExpr): TPasImplWithDo;
  1222. function AddCaseOf(const Expression: TPasExpr): TPasImplCaseOf;
  1223. function AddForLoop(AVar: TPasVariable;
  1224. const AStartValue, AEndValue: TPasExpr): TPasImplForLoop;
  1225. function AddForLoop(AVarName : TPasExpr; AStartValue, AEndValue: TPasExpr;
  1226. ADownTo: Boolean = false): TPasImplForLoop;
  1227. function AddTry: TPasImplTry;
  1228. function AddExceptOn(const VarName, TypeName: TPasTreeString): TPasImplExceptOn;
  1229. function AddExceptOn(const VarName: TPasTreeString; VarType: TPasType): TPasImplExceptOn;
  1230. function AddExceptOn(const VarEl: TPasVariable): TPasImplExceptOn;
  1231. function AddExceptOn(const TypeEl: TPasType): TPasImplExceptOn;
  1232. function AddRaise: TPasImplRaise;
  1233. function AddLabelMark(const Id: TPasTreeString): TPasImplLabelMark;
  1234. function AddAssign(Left, Right: TPasExpr): TPasImplAssign;
  1235. function AddSimple(Expr: TPasExpr): TPasImplSimple;
  1236. function CloseOnSemicolon: boolean; virtual;
  1237. procedure ForEachCall(const aMethodCall: TOnForEachPasElement;
  1238. const Arg: Pointer); override;
  1239. public
  1240. Elements: TFPList; // list of TPasImplElement
  1241. end;
  1242. TPasImplBlockClass = class of TPasImplBlock;
  1243. { TPasImplStatement - base class }
  1244. TPasImplStatement = class(TPasImplBlock)
  1245. public
  1246. function CloseOnSemicolon: boolean; override;
  1247. end;
  1248. { TPasImplBeginBlock }
  1249. TPasImplBeginBlock = class(TPasImplBlock)
  1250. end;
  1251. { TInitializationSection }
  1252. TInitializationSection = class(TPasImplBlock)
  1253. end;
  1254. { TFinalizationSection }
  1255. TFinalizationSection = class(TPasImplBlock)
  1256. end;
  1257. { TPasImplAsmStatement }
  1258. TPasImplAsmStatement = class (TPasImplStatement)
  1259. private
  1260. FModifierTokens: TStrings;
  1261. FTokens: TStrings;
  1262. Public
  1263. constructor Create(const AName: TPasTreeString; AParent: TPasElement); override;
  1264. destructor Destroy; override;
  1265. Property Tokens : TStrings Read FTokens;
  1266. // ['register']
  1267. Property ModifierTokens : TStrings Read FModifierTokens;
  1268. end;
  1269. { TPasImplRepeatUntil }
  1270. TPasImplRepeatUntil = class(TPasImplBlock)
  1271. public
  1272. ConditionExpr : TPasExpr;
  1273. procedure FreeChildren(Prepare: boolean); override;
  1274. Function Condition: TPasTreeString;
  1275. procedure ForEachCall(const aMethodCall: TOnForEachPasElement;
  1276. const Arg: Pointer); override;
  1277. end;
  1278. { TPasImplIfElse }
  1279. TPasImplIfElse = class(TPasImplBlock)
  1280. public
  1281. procedure FreeChildren(Prepare: boolean); override;
  1282. procedure AddElement(Element: TPasImplElement); override;
  1283. function CloseOnSemicolon: boolean; override;
  1284. procedure ForEachCall(const aMethodCall: TOnForEachPasElement;
  1285. const Arg: Pointer); override;
  1286. public
  1287. ConditionExpr: TPasExpr;
  1288. IfBranch: TPasImplElement;
  1289. ElseBranch: TPasImplElement; // can be nil
  1290. Function Condition: TPasTreeString;
  1291. end;
  1292. { TPasImplWhileDo }
  1293. TPasImplWhileDo = class(TPasImplStatement)
  1294. public
  1295. procedure FreeChildren(Prepare: boolean); override;
  1296. procedure AddElement(Element: TPasImplElement); override;
  1297. procedure ForEachCall(const aMethodCall: TOnForEachPasElement;
  1298. const Arg: Pointer); override;
  1299. public
  1300. ConditionExpr : TPasExpr;
  1301. Body: TPasImplElement;
  1302. function Condition: TPasTreeString;
  1303. end;
  1304. { TPasImplWithDo }
  1305. TPasImplWithDo = class(TPasImplStatement)
  1306. public
  1307. constructor Create(const AName: TPasTreeString; AParent: TPasElement); override;
  1308. destructor Destroy; override;
  1309. procedure FreeChildren(Prepare: boolean); override;
  1310. procedure AddElement(Element: TPasImplElement); override;
  1311. procedure AddExpression(const Expression: TPasExpr);
  1312. procedure ForEachCall(const aMethodCall: TOnForEachPasElement;
  1313. const Arg: Pointer); override;
  1314. public
  1315. Expressions: TFPList; // list of TPasExpr
  1316. Body: TPasImplElement;
  1317. end;
  1318. { TPasInlineVarDeclStatement }
  1319. TPasInlineVarDeclStatement = class(TPasImplStatement)
  1320. public
  1321. Declarations: TFPList; // list of TPasVariable
  1322. Public
  1323. constructor Create(const aName : TPasTreeString; aParent: TPasElement); override;
  1324. procedure FreeChildren(Prepare: boolean); override;
  1325. destructor Destroy; override;
  1326. end;
  1327. TPasImplCaseStatement = class;
  1328. TPasImplCaseElse = class;
  1329. { TPasImplCaseOf - Elements are TPasImplCaseStatement }
  1330. TPasImplCaseOf = class(TPasImplBlock)
  1331. public
  1332. procedure FreeChildren(Prepare: boolean); override;
  1333. function AddCase(const Expression: TPasExpr): TPasImplCaseStatement;
  1334. function AddElse: TPasImplCaseElse;
  1335. procedure ForEachCall(const aMethodCall: TOnForEachPasElement;
  1336. const Arg: Pointer); override;
  1337. public
  1338. CaseExpr : TPasExpr;
  1339. ElseBranch: TPasImplCaseElse; // this is also in Elements
  1340. function Expression: TPasTreeString;
  1341. end;
  1342. { TPasImplCaseStatement }
  1343. TPasImplCaseStatement = class(TPasImplStatement)
  1344. public
  1345. constructor Create(const AName: TPasTreeString; AParent: TPasElement); override;
  1346. destructor Destroy; override;
  1347. procedure FreeChildren(Prepare: boolean); override;
  1348. procedure AddElement(Element: TPasImplElement); override;
  1349. procedure AddExpression(const Expr: TPasExpr);
  1350. procedure ForEachCall(const aMethodCall: TOnForEachPasElement;
  1351. const Arg: Pointer); override;
  1352. public
  1353. Expressions: TFPList; // list of TPasExpr
  1354. Body: TPasImplElement;
  1355. end;
  1356. { TPasImplCaseElse }
  1357. TPasImplCaseElse = class(TPasImplBlock)
  1358. end;
  1359. { TPasImplForLoop
  1360. - for VariableName in StartExpr do Body
  1361. - for VariableName := StartExpr to EndExpr do Body }
  1362. TLoopType = (ltNormal,ltDown,ltIn);
  1363. TPasImplForLoop = class(TPasImplStatement)
  1364. public
  1365. procedure FreeChildren(Prepare: boolean); override;
  1366. procedure AddElement(Element: TPasImplElement); override;
  1367. procedure ForEachCall(const aMethodCall: TOnForEachPasElement;
  1368. const Arg: Pointer); override;
  1369. public
  1370. VariableName : TPasExpr;
  1371. LoopType : TLoopType;
  1372. StartExpr : TPasExpr;
  1373. EndExpr : TPasExpr; // if LoopType=ltIn this is nil
  1374. Variable: TPasVariable; // not used by TPasParser
  1375. VarType : TPasType; // For initialized variables
  1376. ImplicitTyped : Boolean;
  1377. Body: TPasImplElement;
  1378. Function Down: boolean; inline;// downto, backward compatibility
  1379. Function StartValue : TPasTreeString;
  1380. Function EndValue: TPasTreeString;
  1381. end;
  1382. { TPasImplAssign }
  1383. TAssignKind = (akDefault,akAdd,akMinus,akMul,akDivision);
  1384. TPasImplAssign = class (TPasImplStatement)
  1385. public
  1386. Left : TPasExpr;
  1387. Right : TPasExpr;
  1388. Kind : TAssignKind;
  1389. procedure FreeChildren(Prepare: boolean); override;
  1390. procedure ForEachCall(const aMethodCall: TOnForEachPasElement;
  1391. const Arg: Pointer); override;
  1392. end;
  1393. { TPasImplSimple }
  1394. TPasImplSimple = class (TPasImplStatement)
  1395. public
  1396. Expr : TPasExpr;
  1397. procedure FreeChildren(Prepare: boolean); override;
  1398. procedure ForEachCall(const aMethodCall: TOnForEachPasElement;
  1399. const Arg: Pointer); override;
  1400. end;
  1401. TPasImplTryHandler = class;
  1402. TPasImplTryFinally = class;
  1403. TPasImplTryExcept = class;
  1404. TPasImplTryExceptElse = class;
  1405. { TPasImplTry }
  1406. TPasImplTry = class(TPasImplBlock)
  1407. public
  1408. procedure FreeChildren(Prepare: boolean); override;
  1409. function AddFinally: TPasImplTryFinally;
  1410. function AddExcept: TPasImplTryExcept;
  1411. function AddExceptElse: TPasImplTryExceptElse;
  1412. procedure ForEachCall(const aMethodCall: TOnForEachPasElement;
  1413. const Arg: Pointer); override;
  1414. public
  1415. FinallyExcept: TPasImplTryHandler; // not in Elements
  1416. ElseBranch: TPasImplTryExceptElse; // not in Elements
  1417. end;
  1418. TPasImplTryHandler = class(TPasImplBlock)
  1419. end;
  1420. { TPasImplTryFinally }
  1421. TPasImplTryFinally = class(TPasImplTryHandler)
  1422. end;
  1423. { TPasImplTryExcept }
  1424. TPasImplTryExcept = class(TPasImplTryHandler)
  1425. end;
  1426. { TPasImplTryExceptElse }
  1427. TPasImplTryExceptElse = class(TPasImplTryHandler)
  1428. end;
  1429. { TPasImplExceptOn - Parent is TPasImplTryExcept }
  1430. TPasImplExceptOn = class(TPasImplStatement)
  1431. public
  1432. procedure FreeChildren(Prepare: boolean); override;
  1433. procedure AddElement(Element: TPasImplElement); override;
  1434. procedure ForEachCall(const aMethodCall: TOnForEachPasElement;
  1435. const Arg: Pointer); override;
  1436. procedure ClearTypeReferences(aType: TPasElement); override;
  1437. public
  1438. VarEl: TPasVariable; // can be nil
  1439. TypeEl : TPasType; // if VarEl<>nil then TypeEl=VarEl.VarType
  1440. Body: TPasImplElement;
  1441. Function VariableName : TPasTreeString;
  1442. Function TypeName: TPasTreeString;
  1443. end;
  1444. { TPasImplRaise }
  1445. TPasImplRaise = class(TPasImplStatement)
  1446. public
  1447. procedure FreeChildren(Prepare: boolean); override;
  1448. procedure ForEachCall(const aMethodCall: TOnForEachPasElement;
  1449. const Arg: Pointer); override;
  1450. Public
  1451. ExceptObject,
  1452. ExceptAddr : TPasExpr;
  1453. end;
  1454. { TPasImplLabelMark }
  1455. TPasImplLabelMark = class(TPasImplElement)
  1456. public
  1457. LabelId: TPasTreeString;
  1458. end;
  1459. { TPasImplGoto }
  1460. TPasImplGoto = class(TPasImplStatement)
  1461. public
  1462. LabelName: TPasTreeString;
  1463. end;
  1464. { TPassTreeVisitor }
  1465. TPassTreeVisitor = class
  1466. public
  1467. procedure Visit(obj: TPasElement); virtual;
  1468. end;
  1469. const
  1470. AccessNames: array[TArgumentAccess] of TPasTreeString = ('', 'const ', 'var ', 'out ','constref ');
  1471. AccessDescriptions: array[TArgumentAccess] of TPasTreeString = ('default', 'const', 'var', 'out','constref');
  1472. AllVisibilities: TPasMemberVisibilities =
  1473. [visDefault, visPrivate, visProtected, visPublic,
  1474. visPublished, visAutomated];
  1475. VisibilityNames: array[TPasMemberVisibility] of TPasTreeString = (
  1476. 'default','private', 'protected', 'public', 'published', 'automated',
  1477. 'strict private', 'strict protected','required','optional');
  1478. ObjKindNames: array[TPasObjKind] of TPasTreeString = (
  1479. 'object', 'class', 'interface',
  1480. 'class helper','record helper','type helper',
  1481. 'dispinterface', 'ObjcClass', 'ObjcCategory',
  1482. 'ObjcProtocol');
  1483. InterfaceTypeNames: array[TPasClassInterfaceType] of TPasTreeString = (
  1484. 'COM',
  1485. 'Corba'
  1486. );
  1487. ExprKindNames : Array[TPasExprKind] of TPasTreeString = (
  1488. 'Ident',
  1489. 'Number',
  1490. 'TPasTreeString',
  1491. 'Set',
  1492. 'Nil',
  1493. 'BoolConst',
  1494. 'Range',
  1495. 'Unary',
  1496. 'Binary',
  1497. 'FuncParams',
  1498. 'ArrayParams',
  1499. 'ListOfExp',
  1500. 'Inherited',
  1501. 'Self',
  1502. 'Specialize',
  1503. 'Procedure');
  1504. OpcodeStrings : Array[TExprOpCode] of TPasTreeString = (
  1505. '','+','-','*','/','div','mod','**',
  1506. 'shr','shl',
  1507. 'not','and','or','xor',
  1508. '=','<>',
  1509. '<','>','<=','>=',
  1510. 'in','is','as','><',
  1511. '@','^','@@',
  1512. '.');
  1513. UnaryOperators = [otImplicit,otExplicit,otAssign,otNegative,otPositive,otEnumerator];
  1514. OperatorTokens : Array[TOperatorType] of TPasTreeString
  1515. = ('','','','*','+','-','/','<','=',
  1516. '>',':=','<>','<=','>=','**',
  1517. '><','Inc','Dec','mod','-','+','Or','div',
  1518. 'shl','or','and','xor','and','not','xor',
  1519. 'shr','enumerator','in','','','','');
  1520. OperatorNames : Array[TOperatorType] of TPasTreeString
  1521. = ('','implicit','explicit','multiply','add','subtract','divide','lessthan','equal',
  1522. 'greaterthan','assign','notequal','lessthanorequal','greaterthanorequal','power',
  1523. 'symmetricaldifference','inc','dec','modulus','negative','positive','bitwiseor','intdivide',
  1524. 'leftshift','logicalor','bitwiseand','bitwisexor','logicaland','logicalnot','logicalxor',
  1525. 'rightshift','enumerator','in','initialize','finalize','addref','copy');
  1526. AssignKindNames : Array[TAssignKind] of TPasTreeString = (':=','+=','-=','*=','/=' );
  1527. cPasMemberHint : Array[TPasMemberHint] of TPasTreeString =
  1528. ( 'deprecated', 'library', 'platform', 'experimental', 'unimplemented' );
  1529. cCallingConventions : Array[TCallingConvention] of TPasTreeString =
  1530. ( '', 'Register','Pascal','cdecl','stdcall','OldFPCCall','safecall','SysCall','MWPascal',
  1531. 'HardFloat','SysV_ABI_Default','SysV_ABI_CDecl',
  1532. 'MS_ABI_Default','MS_ABI_CDecl',
  1533. 'VectorCall');
  1534. ProcTypeModifiers : Array[TProcTypeModifier] of TPasTreeString =
  1535. ('of Object', 'is nested','static','varargs','reference to','async','far','cblock');
  1536. ModifierNames : Array[TProcedureModifier] of TPasTreeString
  1537. = ('virtual', 'dynamic','abstract', 'override',
  1538. 'export', 'overload', 'message', 'reintroduce',
  1539. 'inline','assembler','public',
  1540. 'compilerproc','external','forward','dispid',
  1541. 'noreturn','far','final','discardresult','nostackframe',
  1542. 'section','rtlproc','internproc');
  1543. VariableModifierNames : Array[TVariableModifier] of TPasTreeString
  1544. = ('cvar', 'external', 'public', 'export', 'class', 'static','far');
  1545. procedure FreeProcNameParts(var NameParts: TProcedureNameParts);
  1546. procedure FreePasExprArray(Parent: TPasElement; var A: TPasExprArray; Prepare: boolean);
  1547. function GenericTemplateTypesAsString(List: TFPList): TPasTreeString;
  1548. function dbgs(const s: TProcTypeModifiers): TPasTreeString; overload;
  1549. function WritePasElTree(Expr: TPasExpr; FollowPrefix: TPasTreeString = ''): TPasTreeString;
  1550. function GetPasElementDesc(El: TPasElement): TPasTreeString;
  1551. {$IFDEF HasPTDumpStack}
  1552. procedure PTDumpStack;
  1553. function GetPTDumpStack: TPasTreeString;
  1554. {$ENDIF}
  1555. implementation
  1556. procedure FreeProcNameParts(var NameParts: TProcedureNameParts);
  1557. var
  1558. i: Integer;
  1559. p: TProcedureNamePart;
  1560. begin
  1561. if NameParts=nil then exit;
  1562. for i:=0 to NameParts.Count-1 do
  1563. begin
  1564. p:=TProcedureNamePart(NameParts[i]);
  1565. p.Templates.Free;
  1566. p.Free;
  1567. end;
  1568. NameParts.Free;
  1569. NameParts:=nil;
  1570. end;
  1571. procedure FreePasExprArray(Parent: TPasElement; var A: TPasExprArray;
  1572. Prepare: boolean);
  1573. var
  1574. i: Integer;
  1575. begin
  1576. for i:=0 to High(A) do
  1577. Parent.FreeChild(A[i],Prepare);
  1578. A:=nil;
  1579. end;
  1580. function GenericTemplateTypesAsString(List: TFPList): TPasTreeString;
  1581. var
  1582. i, j: Integer;
  1583. T: TPasGenericTemplateType;
  1584. begin
  1585. Result:='';
  1586. for i:=0 to List.Count-1 do
  1587. begin
  1588. if i>0 then
  1589. Result:=Result+',';
  1590. T:=TPasGenericTemplateType(List[i]);
  1591. Result:=Result+T.Name;
  1592. if length(T.Constraints)>0 then
  1593. begin
  1594. Result:=Result+':';
  1595. for j:=0 to length(T.Constraints)-1 do
  1596. begin
  1597. if j>0 then
  1598. Result:=Result+',';
  1599. Result:=Result+T.GetDeclaration(false);
  1600. end;
  1601. end;
  1602. end;
  1603. Result:='<'+Result+'>';
  1604. end;
  1605. function dbgs(const s: TProcTypeModifiers): TPasTreeString;
  1606. var
  1607. m: TProcTypeModifier;
  1608. begin
  1609. Result:='';
  1610. for m in s do
  1611. begin
  1612. if Result<>'' then Result:=Result+',';
  1613. Result:=Result+ProcTypeModifiers[m];
  1614. end;
  1615. Result:='['+Result+']';
  1616. end;
  1617. function WritePasElTree(Expr: TPasExpr; FollowPrefix: TPasTreeString): TPasTreeString;
  1618. { TBinary Kind= OpCode=
  1619. +Left=TBinary Kind= OpCode=
  1620. | +Left=TParamsExpr[]
  1621. | | +Value=Prim Kind= Value=
  1622. | | +Params[1]=Prim Kind= Value=
  1623. +Right=Prim
  1624. }
  1625. var
  1626. C: TClass;
  1627. s: TPasTreeString;
  1628. ParamsExpr: TParamsExpr;
  1629. InlineSpecExpr: TInlineSpecializeExpr;
  1630. SubEl: TPasElement;
  1631. ArrayValues: TArrayValues;
  1632. i: Integer;
  1633. begin
  1634. if Expr=nil then exit('nil');
  1635. C:=Expr.ClassType;
  1636. Result:=C.ClassName;
  1637. str(Expr.Kind,s);
  1638. Result:=Result+' '+s;
  1639. str(Expr.OpCode,s);
  1640. Result:=Result+' '+s;
  1641. if C=TPrimitiveExpr then
  1642. Result:=Result+' Value="'+TPrimitiveExpr(Expr).Value+'"'
  1643. else if C=TUnaryExpr then
  1644. Result:=Result+' Operand='+WritePasElTree(TUnaryExpr(Expr).Operand,FollowPrefix)
  1645. else if C=TBoolConstExpr then
  1646. Result:=Result+' Value='+BoolToStr(TBoolConstExpr(Expr).Value,'True','False')
  1647. else if C=TArrayValues then
  1648. begin
  1649. ArrayValues:=TArrayValues(Expr);
  1650. for i:=0 to length(ArrayValues.Values)-1 do
  1651. Result:=Result+sLineBreak+FollowPrefix+'+Values['+IntToStr(i)+']='+WritePasElTree(ArrayValues.Values[i],FollowPrefix+'| ');
  1652. end
  1653. else if C=TBinaryExpr then
  1654. begin
  1655. Result:=Result+sLineBreak+FollowPrefix+'+Left='+WritePasElTree(TBinaryExpr(Expr).Left,FollowPrefix+'| ');
  1656. Result:=Result+sLineBreak+FollowPrefix+'+Right='+WritePasElTree(TBinaryExpr(Expr).Right,FollowPrefix+'| ');
  1657. end
  1658. else if C=TParamsExpr then
  1659. begin
  1660. ParamsExpr:=TParamsExpr(Expr);
  1661. Result:=Result+sLineBreak+FollowPrefix+'+Value='+WritePasElTree(ParamsExpr.Value,FollowPrefix+'| ');
  1662. for i:=0 to length(ParamsExpr.Params)-1 do
  1663. Result:=Result+sLineBreak+FollowPrefix+'+Params['+IntToStr(i)+']='+WritePasElTree(ParamsExpr.Params[i],FollowPrefix+'| ');
  1664. end
  1665. else if C=TInlineSpecializeExpr then
  1666. begin
  1667. InlineSpecExpr:=TInlineSpecializeExpr(Expr);
  1668. Result:=Result+sLineBreak+FollowPrefix+'+Name='+WritePasElTree(InlineSpecExpr.NameExpr,FollowPrefix+'| ');
  1669. if InlineSpecExpr.Params<>nil then
  1670. for i:=0 to InlineSpecExpr.Params.Count-1 do
  1671. begin
  1672. Result:=Result+sLineBreak+FollowPrefix+'+Params['+IntToStr(i)+']=';
  1673. SubEl:=TPasElement(InlineSpecExpr.Params[i]);
  1674. if SubEl=nil then
  1675. Result:=Result+'nil'
  1676. else if SubEl is TPasExpr then
  1677. Result:=Result+WritePasElTree(TPasExpr(SubEl),FollowPrefix+'| ')
  1678. else
  1679. Result:=Result+SubEl.Name+':'+SubEl.ClassName;
  1680. end;
  1681. end
  1682. else
  1683. Result:=C.ClassName+' Kind=';
  1684. end;
  1685. function GetPasElementDesc(El: TPasElement): TPasTreeString;
  1686. begin
  1687. if El=nil then exit('nil');
  1688. Result:=El.Name+':'+El.ClassName+'['+El.SourceFilename+','+IntToStr(El.SourceLinenumber)+']';
  1689. end;
  1690. Function IndentStrings(S : TStrings; indent : Integer) : TPasTreeString;
  1691. Var
  1692. I,CurrLen,CurrPos : Integer;
  1693. begin
  1694. Result:='';
  1695. CurrLen:=0;
  1696. CurrPos:=0;
  1697. For I:=0 to S.Count-1 do
  1698. begin
  1699. CurrLen:=Length(S[i]);
  1700. If (CurrLen+CurrPos)>72 then
  1701. begin
  1702. Result:=Result+LineEnding+StringOfChar(' ',Indent);
  1703. CurrPos:=Indent;
  1704. end;
  1705. Result:=Result+S[i];
  1706. CurrPos:=CurrPos+CurrLen;
  1707. end;
  1708. end;
  1709. { TPasGenericType }
  1710. destructor TPasGenericType.Destroy;
  1711. begin
  1712. FreeAndNil(GenericTemplateTypes);
  1713. inherited Destroy;
  1714. end;
  1715. procedure TPasGenericType.FreeChildren(Prepare: boolean);
  1716. begin
  1717. FreeChildList(GenericTemplateTypes,Prepare);
  1718. inherited FreeChildren(Prepare);
  1719. end;
  1720. procedure TPasGenericType.ForEachCall(const aMethodCall: TOnForEachPasElement;
  1721. const Arg: Pointer);
  1722. var
  1723. i: Integer;
  1724. begin
  1725. inherited ForEachCall(aMethodCall, Arg);
  1726. if GenericTemplateTypes<>nil then
  1727. for i:=0 to GenericTemplateTypes.Count-1 do
  1728. ForEachChildCall(aMethodCall,Arg,TPasElement(GenericTemplateTypes[i]),false);
  1729. end;
  1730. procedure TPasGenericType.SetGenericTemplates(AList: TFPList);
  1731. var
  1732. I: Integer;
  1733. El: TPasElement;
  1734. begin
  1735. if GenericTemplateTypes=nil then
  1736. GenericTemplateTypes:=TFPList.Create;
  1737. For I:=0 to AList.Count-1 do
  1738. begin
  1739. El:=TPasElement(AList[i]);
  1740. El.Parent:=Self;
  1741. GenericTemplateTypes.Add(El);
  1742. end;
  1743. AList.Clear;
  1744. end;
  1745. { TPasGenericTemplateType }
  1746. destructor TPasGenericTemplateType.Destroy;
  1747. begin
  1748. inherited Destroy;
  1749. end;
  1750. procedure TPasGenericTemplateType.FreeChildren(Prepare: boolean);
  1751. begin
  1752. FreeChildArray(Constraints,Prepare);
  1753. inherited FreeChildren(Prepare);
  1754. end;
  1755. function TPasGenericTemplateType.GetDeclaration(full: boolean): TPasTreeString;
  1756. var
  1757. i: Integer;
  1758. begin
  1759. Result:=inherited GetDeclaration(full);
  1760. if length(Constraints)>0 then
  1761. begin
  1762. Result:=Result+': ';
  1763. for i:=0 to length(Constraints)-1 do
  1764. begin
  1765. if i>0 then
  1766. Result:=Result+',';
  1767. Result:=Result+Constraints[i].GetDeclaration(false);
  1768. end;
  1769. end;
  1770. end;
  1771. procedure TPasGenericTemplateType.ForEachCall(
  1772. const aMethodCall: TOnForEachPasElement; const Arg: Pointer);
  1773. var
  1774. i: Integer;
  1775. begin
  1776. inherited ForEachCall(aMethodCall, Arg);
  1777. for i:=0 to length(Constraints)-1 do
  1778. ForEachChildCall(aMethodCall,Arg,Constraints[i],false);
  1779. end;
  1780. procedure TPasGenericTemplateType.AddConstraint(El: TPasElement);
  1781. var
  1782. l: Integer;
  1783. begin
  1784. l:=Length(Constraints);
  1785. SetLength(Constraints,l+1);
  1786. Constraints[l]:=El;
  1787. end;
  1788. procedure TPasGenericTemplateType.ClearTypeReferences(aType: TPasElement);
  1789. var
  1790. i: SizeInt;
  1791. aConstraint: TPasElement;
  1792. begin
  1793. for i:=length(Constraints)-1 downto 0 do
  1794. begin
  1795. aConstraint:=Constraints[i];
  1796. if aConstraint=aType then
  1797. Constraints[i]:=nil;
  1798. end;
  1799. end;
  1800. {$IFDEF HasPTDumpStack}
  1801. procedure PTDumpStack;
  1802. begin
  1803. {AllowWriteln}
  1804. writeln(GetPTDumpStack);
  1805. {AllowWriteln-}
  1806. end;
  1807. function GetPTDumpStack: TPasTreeString;
  1808. var
  1809. bp: Pointer;
  1810. addr: Pointer;
  1811. oldbp: Pointer;
  1812. CurAddress: Shortstring;
  1813. begin
  1814. Result:='';
  1815. { retrieve backtrace info }
  1816. bp:=get_caller_frame(get_frame);
  1817. while bp<>nil do begin
  1818. addr:=get_caller_addr(bp);
  1819. CurAddress:=BackTraceStrFunc(addr);
  1820. Result:=Result+CurAddress+LineEnding;
  1821. oldbp:=bp;
  1822. bp:=get_caller_frame(bp);
  1823. if (bp<=oldbp) or (bp>(StackBottom + StackLength)) then
  1824. bp:=nil;
  1825. end;
  1826. end;
  1827. {$ENDIF}
  1828. { TPasAttributes }
  1829. procedure TPasAttributes.FreeChildren(Prepare: boolean);
  1830. begin
  1831. FreePasExprArray(Self,Calls,Prepare);
  1832. inherited FreeChildren(Prepare);
  1833. end;
  1834. procedure TPasAttributes.ForEachCall(const aMethodCall: TOnForEachPasElement;
  1835. const Arg: Pointer);
  1836. var
  1837. i: Integer;
  1838. begin
  1839. inherited ForEachCall(aMethodCall, Arg);
  1840. for i:=0 to length(Calls)-1 do
  1841. ForEachChildCall(aMethodCall,Arg,Calls[i],false);
  1842. end;
  1843. procedure TPasAttributes.AddCall(Expr: TPasExpr);
  1844. var
  1845. i : Integer;
  1846. begin
  1847. i:=Length(Calls);
  1848. SetLength(Calls, i+1);
  1849. Calls[i]:=Expr;
  1850. end;
  1851. { TPasMethodResolution }
  1852. procedure TPasMethodResolution.FreeChildren(Prepare: boolean);
  1853. begin
  1854. InterfaceName:=TPasExpr(FreeChild(InterfaceName,Prepare));
  1855. InterfaceProc:=TPasExpr(FreeChild(InterfaceProc,Prepare));
  1856. ImplementationProc:=TPasExpr(FreeChild(ImplementationProc,Prepare));
  1857. inherited FreeChildren(Prepare);
  1858. end;
  1859. procedure TPasMethodResolution.ForEachCall(
  1860. const aMethodCall: TOnForEachPasElement; const Arg: Pointer);
  1861. begin
  1862. inherited ForEachCall(aMethodCall, Arg);
  1863. ForEachChildCall(aMethodCall,Arg,InterfaceName,false);
  1864. ForEachChildCall(aMethodCall,Arg,InterfaceProc,false);
  1865. ForEachChildCall(aMethodCall,Arg,ImplementationProc,false);
  1866. end;
  1867. { TPasImplCommandBase }
  1868. constructor TPasImplCommandBase.Create(const AName: TPasTreeString; AParent: TPasElement);
  1869. begin
  1870. inherited Create(AName, AParent);
  1871. SemicolonAtEOL := true;
  1872. end;
  1873. { TInlineSpecializeExpr }
  1874. constructor TInlineSpecializeExpr.Create(const AName: TPasTreeString;
  1875. AParent: TPasElement);
  1876. begin
  1877. if AName='' then ;
  1878. inherited Create(AParent, pekSpecialize, eopNone);
  1879. Params:=TFPList.Create;
  1880. end;
  1881. destructor TInlineSpecializeExpr.Destroy;
  1882. begin
  1883. FreeAndNil(Params);
  1884. inherited Destroy;
  1885. end;
  1886. procedure TInlineSpecializeExpr.FreeChildren(Prepare: boolean);
  1887. begin
  1888. NameExpr:=TPasExpr(FreeChild(NameExpr,Prepare));
  1889. FreeChildList(Params,Prepare);
  1890. inherited FreeChildren(Prepare);
  1891. end;
  1892. procedure TInlineSpecializeExpr.ClearTypeReferences(aType: TPasElement);
  1893. var
  1894. i: Integer;
  1895. El: TPasElement;
  1896. begin
  1897. for i:=Params.Count-1 downto 0 do
  1898. begin
  1899. El:=TPasElement(Params[i]);
  1900. if El=aType then
  1901. Params.Delete(i);
  1902. end;
  1903. end;
  1904. function TInlineSpecializeExpr.ElementTypeName: TPasTreeString;
  1905. begin
  1906. Result:=SPasTreeSpecializedExpr;
  1907. end;
  1908. function TInlineSpecializeExpr.GetDeclaration(full: Boolean): TPasTreeString;
  1909. var
  1910. i: Integer;
  1911. begin
  1912. Result:='specialize '+NameExpr.GetDeclaration(false)+'<';
  1913. for i:=0 to Params.Count-1 do
  1914. begin
  1915. if i>0 then
  1916. Result:=Result+',';
  1917. Result:=Result+TPasElement(Params[i]).GetDeclaration(false);
  1918. end;
  1919. Result:=Result+'>';
  1920. if full then ;
  1921. end;
  1922. procedure TInlineSpecializeExpr.ForEachCall(
  1923. const aMethodCall: TOnForEachPasElement; const Arg: Pointer);
  1924. var
  1925. i: Integer;
  1926. begin
  1927. inherited ForEachCall(aMethodCall, Arg);
  1928. ForEachChildCall(aMethodCall,Arg,NameExpr,false);
  1929. for i:=0 to Params.Count-1 do
  1930. ForEachChildCall(aMethodCall,Arg,TPasElement(Params[i]),true);
  1931. end;
  1932. { TPasSpecializeType }
  1933. constructor TPasSpecializeType.Create(const AName: TPasTreeString; AParent: TPasElement
  1934. );
  1935. begin
  1936. inherited Create(AName, AParent);
  1937. Params:=TFPList.Create;
  1938. end;
  1939. destructor TPasSpecializeType.Destroy;
  1940. begin
  1941. FreeAndNil(Params);
  1942. inherited Destroy;
  1943. end;
  1944. procedure TPasSpecializeType.FreeChildren(Prepare: boolean);
  1945. begin
  1946. FreeChildList(Params,Prepare);
  1947. inherited FreeChildren(Prepare);
  1948. end;
  1949. procedure TPasSpecializeType.ClearTypeReferences(aType: TPasElement);
  1950. var
  1951. i: Integer;
  1952. El: TPasElement;
  1953. begin
  1954. inherited ClearTypeReferences(aType);
  1955. for i:=Params.Count-1 downto 0 do
  1956. begin
  1957. El:=TPasElement(Params[i]);
  1958. if El=aType then
  1959. Params.Delete(i);
  1960. end;
  1961. end;
  1962. function TPasSpecializeType.ElementTypeName: TPasTreeString;
  1963. begin
  1964. Result:=SPasTreeSpecializedType;
  1965. end;
  1966. function TPasSpecializeType.GetDeclaration(full: boolean): TPasTreeString;
  1967. var
  1968. i: Integer;
  1969. begin
  1970. Result:='specialize '+DestType.Name+'<';
  1971. for i:=0 to Params.Count-1 do
  1972. begin
  1973. if i>0 then
  1974. Result:=Result+',';
  1975. Result:=Result+TPasElement(Params[i]).GetDeclaration(false);
  1976. end;
  1977. If Full and (Name<>'') then
  1978. begin
  1979. Result:=Name+' = '+Result;
  1980. ProcessHints(False,Result);
  1981. end;
  1982. end;
  1983. procedure TPasSpecializeType.ForEachCall(
  1984. const aMethodCall: TOnForEachPasElement; const Arg: Pointer);
  1985. var
  1986. i: Integer;
  1987. begin
  1988. inherited ForEachCall(aMethodCall, Arg);
  1989. for i:=0 to Params.Count-1 do
  1990. ForEachChildCall(aMethodCall,Arg,TPasElement(Params[i]),true);
  1991. end;
  1992. { TInterfaceSection }
  1993. function TInterfaceSection.ElementTypeName: TPasTreeString;
  1994. begin
  1995. Result:=SPasTreeInterfaceSection;
  1996. end;
  1997. { TLibrarySection }
  1998. function TLibrarySection.ElementTypeName: TPasTreeString;
  1999. begin
  2000. Result:=SPasTreeLibrarySection;
  2001. end;
  2002. { TProgramSection }
  2003. function TProgramSection.ElementTypeName: TPasTreeString;
  2004. begin
  2005. Result:=SPasTreeProgramSection;
  2006. end;
  2007. { TImplementationSection }
  2008. function TImplementationSection.ElementTypeName: TPasTreeString;
  2009. begin
  2010. Result:=SPasTreeImplementationSection;
  2011. end;
  2012. { TPasUsesUnit }
  2013. procedure TPasUsesUnit.FreeChildren(Prepare: boolean);
  2014. begin
  2015. Expr:=TPasExpr(FreeChild(Expr,Prepare));
  2016. InFilename:=TPrimitiveExpr(FreeChild(InFilename,Prepare));
  2017. Module:=TPasModule(FreeChild(Module,Prepare));
  2018. inherited FreeChildren(Prepare);
  2019. end;
  2020. function TPasUsesUnit.ElementTypeName: TPasTreeString;
  2021. begin
  2022. Result := SPasTreeUsesUnit;
  2023. end;
  2024. procedure TPasUsesUnit.ForEachCall(const aMethodCall: TOnForEachPasElement;
  2025. const Arg: Pointer);
  2026. begin
  2027. inherited ForEachCall(aMethodCall, Arg);
  2028. ForEachChildCall(aMethodCall,Arg,Expr,false);
  2029. ForEachChildCall(aMethodCall,Arg,InFilename,false);
  2030. ForEachChildCall(aMethodCall,Arg,Module,true);
  2031. end;
  2032. { TPasElementBase }
  2033. procedure TPasElementBase.Accept(Visitor: TPassTreeVisitor);
  2034. begin
  2035. if Visitor=nil then ;
  2036. end;
  2037. { TPasTypeRef }
  2038. procedure TPasTypeRef.ForEachCall(const aMethodCall: TOnForEachPasElement;
  2039. const Arg: Pointer);
  2040. begin
  2041. inherited ForEachCall(aMethodCall, Arg);
  2042. ForEachChildCall(aMethodCall,Arg,RefType,true);
  2043. end;
  2044. { TPasClassOperator }
  2045. function TPasClassOperator.TypeName: TPasTreeString;
  2046. begin
  2047. Result:='class operator';
  2048. end;
  2049. function TPasClassOperator.GetProcTypeEnum: TProcType;
  2050. begin
  2051. Result:=ptClassOperator;
  2052. end;
  2053. { TPasImplAsmStatement }
  2054. constructor TPasImplAsmStatement.Create(const AName: TPasTreeString;
  2055. AParent: TPasElement);
  2056. begin
  2057. inherited Create(AName, AParent);
  2058. FTokens:=TStringList.Create;
  2059. FModifierTokens:=TStringList.Create;
  2060. end;
  2061. destructor TPasImplAsmStatement.Destroy;
  2062. begin
  2063. FreeAndNil(FTokens);
  2064. FreeAndNil(FModifierTokens);
  2065. inherited Destroy;
  2066. end;
  2067. { TPasClassConstructor }
  2068. function TPasClassConstructor.TypeName: TPasTreeString;
  2069. begin
  2070. Result:='class '+ inherited TypeName;
  2071. end;
  2072. function TPasClassConstructor.GetProcTypeEnum: TProcType;
  2073. begin
  2074. Result:=ptClassConstructor;
  2075. end;
  2076. { TPasAnonymousProcedure }
  2077. function TPasAnonymousProcedure.ElementTypeName: TPasTreeString;
  2078. begin
  2079. Result:=SPasTreeAnonymousProcedure;
  2080. end;
  2081. function TPasAnonymousProcedure.TypeName: TPasTreeString;
  2082. begin
  2083. Result:='anonymous procedure';
  2084. end;
  2085. function TPasAnonymousProcedure.GetProcTypeEnum: TProcType;
  2086. begin
  2087. Result:=ptAnonymousProcedure;
  2088. end;
  2089. { TPasAnonymousFunction }
  2090. function TPasAnonymousFunction.GetFT: TPasFunctionType;
  2091. begin
  2092. Result:=ProcType as TPasFunctionType;
  2093. end;
  2094. function TPasAnonymousFunction.ElementTypeName: TPasTreeString;
  2095. begin
  2096. Result := SPasTreeAnonymousFunction;
  2097. end;
  2098. function TPasAnonymousFunction.TypeName: TPasTreeString;
  2099. begin
  2100. Result:='anonymous function';
  2101. end;
  2102. function TPasAnonymousFunction.GetProcTypeEnum: TProcType;
  2103. begin
  2104. Result:=ptAnonymousFunction;
  2105. end;
  2106. { TProcedureExpr }
  2107. constructor TProcedureExpr.Create(AParent: TPasElement);
  2108. begin
  2109. inherited Create(AParent,pekProcedure,eopNone);
  2110. end;
  2111. procedure TProcedureExpr.FreeChildren(Prepare: boolean);
  2112. begin
  2113. Proc:=TPasAnonymousProcedure(FreeChild(Proc,Prepare));
  2114. inherited FreeChildren(Prepare);
  2115. end;
  2116. function TProcedureExpr.GetDeclaration(full: Boolean): TPasTreeString;
  2117. begin
  2118. if Proc<>nil then
  2119. Result:=Proc.GetDeclaration(full)
  2120. else
  2121. Result:='procedure-expr';
  2122. end;
  2123. procedure TProcedureExpr.ForEachCall(const aMethodCall: TOnForEachPasElement;
  2124. const Arg: Pointer);
  2125. begin
  2126. inherited ForEachCall(aMethodCall, Arg);
  2127. ForEachChildCall(aMethodCall,Arg,Proc,false);
  2128. end;
  2129. { TPasImplRaise }
  2130. procedure TPasImplRaise.FreeChildren(Prepare: boolean);
  2131. begin
  2132. ExceptObject:=TPasExpr(FreeChild(ExceptObject,Prepare));
  2133. ExceptAddr:=TPasExpr(FreeChild(ExceptAddr,Prepare));
  2134. inherited FreeChildren(Prepare);
  2135. end;
  2136. procedure TPasImplRaise.ForEachCall(const aMethodCall: TOnForEachPasElement;
  2137. const Arg: Pointer);
  2138. begin
  2139. inherited ForEachCall(aMethodCall, Arg);
  2140. ForEachChildCall(aMethodCall,Arg,ExceptObject,false);
  2141. ForEachChildCall(aMethodCall,Arg,ExceptAddr,false);
  2142. end;
  2143. { TPasImplRepeatUntil }
  2144. procedure TPasImplRepeatUntil.FreeChildren(Prepare: boolean);
  2145. begin
  2146. ConditionExpr:=TPasExpr(FreeChild(ConditionExpr,Prepare));
  2147. inherited FreeChildren(Prepare);
  2148. end;
  2149. function TPasImplRepeatUntil.Condition: TPasTreeString;
  2150. begin
  2151. If Assigned(ConditionExpr) then
  2152. Result:=ConditionExpr.GetDeclaration(True)
  2153. else
  2154. Result:='';
  2155. end;
  2156. procedure TPasImplRepeatUntil.ForEachCall(
  2157. const aMethodCall: TOnForEachPasElement; const Arg: Pointer);
  2158. begin
  2159. inherited ForEachCall(aMethodCall, Arg);
  2160. ForEachChildCall(aMethodCall,Arg,ConditionExpr,false);
  2161. end;
  2162. { TPasImplSimple }
  2163. procedure TPasImplSimple.FreeChildren(Prepare: boolean);
  2164. begin
  2165. Expr:=TPasExpr(FreeChild(Expr,Prepare));
  2166. inherited FreeChildren(Prepare);
  2167. end;
  2168. procedure TPasImplSimple.ForEachCall(const aMethodCall: TOnForEachPasElement;
  2169. const Arg: Pointer);
  2170. begin
  2171. inherited ForEachCall(aMethodCall, Arg);
  2172. ForEachChildCall(aMethodCall,Arg,Expr,false);
  2173. end;
  2174. { TPasImplAssign }
  2175. procedure TPasImplAssign.FreeChildren(Prepare: boolean);
  2176. begin
  2177. Left:=TPasExpr(FreeChild(Left,Prepare));
  2178. Right:=TPasExpr(FreeChild(Right,Prepare));
  2179. inherited FreeChildren(Prepare);
  2180. end;
  2181. procedure TPasImplAssign.ForEachCall(const aMethodCall: TOnForEachPasElement;
  2182. const Arg: Pointer);
  2183. begin
  2184. inherited ForEachCall(aMethodCall, Arg);
  2185. ForEachChildCall(aMethodCall,Arg,Left,false);
  2186. ForEachChildCall(aMethodCall,Arg,Right,false);
  2187. end;
  2188. { TPasExportSymbol }
  2189. procedure TPasExportSymbol.FreeChildren(Prepare: boolean);
  2190. begin
  2191. NameExpr:=TPasExpr(FreeChild(NameExpr,Prepare));
  2192. ExportName:=TPasExpr(FreeChild(ExportName,Prepare));
  2193. ExportIndex:=TPasExpr(FreeChild(ExportIndex,Prepare));
  2194. inherited FreeChildren(Prepare);
  2195. end;
  2196. function TPasExportSymbol.ElementTypeName: TPasTreeString;
  2197. begin
  2198. Result:='Export'
  2199. end;
  2200. function TPasExportSymbol.GetDeclaration(full: boolean): TPasTreeString;
  2201. begin
  2202. Result:=Name;
  2203. if (ExportName<>Nil) then
  2204. Result:=Result+' name '+ExportName.GetDeclaration(Full)
  2205. else if (ExportIndex<>Nil) then
  2206. Result:=Result+' index '+ExportIndex.GetDeclaration(Full);
  2207. end;
  2208. procedure TPasExportSymbol.ForEachCall(const aMethodCall: TOnForEachPasElement;
  2209. const Arg: Pointer);
  2210. begin
  2211. inherited ForEachCall(aMethodCall, Arg);
  2212. ForEachChildCall(aMethodCall,Arg,NameExpr,false);
  2213. ForEachChildCall(aMethodCall,Arg,ExportName,false);
  2214. ForEachChildCall(aMethodCall,Arg,ExportIndex,false);
  2215. end;
  2216. { TPasUnresolvedUnitRef }
  2217. function TPasUnresolvedUnitRef.ElementTypeName: TPasTreeString;
  2218. begin
  2219. Result:=SPasTreeUnit;
  2220. end;
  2221. { TPasLibrary }
  2222. procedure TPasLibrary.FreeChildren(Prepare: boolean);
  2223. begin
  2224. LibrarySection:=TLibrarySection(FreeChild(LibrarySection,Prepare));
  2225. inherited FreeChildren(Prepare);
  2226. end;
  2227. function TPasLibrary.ElementTypeName: TPasTreeString;
  2228. begin
  2229. Result:=inherited ElementTypeName;
  2230. end;
  2231. procedure TPasLibrary.ForEachCall(const aMethodCall: TOnForEachPasElement;
  2232. const Arg: Pointer);
  2233. begin
  2234. ForEachChildCall(aMethodCall,Arg,LibrarySection,false);
  2235. inherited ForEachCall(aMethodCall, Arg);
  2236. end;
  2237. { TPasProgram }
  2238. procedure TPasProgram.FreeChildren(Prepare: boolean);
  2239. begin
  2240. ProgramSection:=TProgramSection(FreeChild(ProgramSection,Prepare));
  2241. inherited FreeChildren(Prepare);
  2242. end;
  2243. function TPasProgram.ElementTypeName: TPasTreeString;
  2244. begin
  2245. Result:=inherited ElementTypeName;
  2246. end;
  2247. procedure TPasProgram.ForEachCall(const aMethodCall: TOnForEachPasElement;
  2248. const Arg: Pointer);
  2249. begin
  2250. ForEachChildCall(aMethodCall,Arg,ProgramSection,false);
  2251. inherited ForEachCall(aMethodCall, Arg);
  2252. end;
  2253. { TPasUnitModule }
  2254. function TPasUnitModule.ElementTypeName: TPasTreeString;
  2255. begin
  2256. Result:=SPasTreeUnit;
  2257. end;
  2258. { Parse tree element type name functions }
  2259. function TPasElement.ElementTypeName: TPasTreeString; begin Result := SPasTreeElement end;
  2260. function TPasElement.HintsString: TPasTreeString;
  2261. Var
  2262. H : TPasmemberHint;
  2263. begin
  2264. Result:='';
  2265. For H := Low(TPasmemberHint) to High(TPasMemberHint) do
  2266. if H in Hints then
  2267. begin
  2268. If (Result<>'') then
  2269. Result:=Result+'; ';
  2270. Result:=Result+cPasMemberHint[h];
  2271. end;
  2272. end;
  2273. function TPasDeclarations.ElementTypeName: TPasTreeString; begin Result := SPasTreeSection end;
  2274. procedure TPasDeclarations.ForEachCall(const aMethodCall: TOnForEachPasElement;
  2275. const Arg: Pointer);
  2276. var
  2277. i: Integer;
  2278. begin
  2279. inherited ForEachCall(aMethodCall, Arg);
  2280. for i:=0 to Declarations.Count-1 do
  2281. ForEachChildCall(aMethodCall,Arg,TPasElement(Declarations[i]),false);
  2282. end;
  2283. function TPasModule.ElementTypeName: TPasTreeString; begin Result := SPasTreeModule end;
  2284. function TPasPackage.ElementTypeName: TPasTreeString; begin Result := SPasTreePackage end;
  2285. procedure TPasPackage.ForEachCall(const aMethodCall: TOnForEachPasElement;
  2286. const Arg: Pointer);
  2287. var
  2288. i: Integer;
  2289. begin
  2290. inherited ForEachCall(aMethodCall, Arg);
  2291. for i:=0 to Modules.Count-1 do
  2292. ForEachChildCall(aMethodCall,Arg,TPasModule(Modules[i]),true);
  2293. end;
  2294. function TPasResString.ElementTypeName: TPasTreeString; begin Result := SPasTreeResString; end;
  2295. function TPasType.FixTypeDecl(aDecl: TPasTreeString): TPasTreeString;
  2296. begin
  2297. Result:=aDecl;
  2298. if (Name<>'') then
  2299. Result:=SafeName+' = '+Result;
  2300. ProcessHints(false,Result);
  2301. end;
  2302. function TPasType.SafeName: TPasTreeString;
  2303. begin
  2304. if SameText(Name,'TPasTreeString') then
  2305. Result:=Name
  2306. else
  2307. Result:=inherited SafeName;
  2308. end;
  2309. function TPasType.ElementTypeName: TPasTreeString; begin Result := SPasTreeType; end;
  2310. function TPasPointerType.ElementTypeName: TPasTreeString; begin Result := SPasTreePointerType; end;
  2311. function TPasAliasType.ElementTypeName: TPasTreeString; begin Result := SPasTreeAliasType; end;
  2312. function TPasTypeAliasType.ElementTypeName: TPasTreeString; begin Result := SPasTreeTypeAliasType; end;
  2313. function TPasClassOfType.ElementTypeName: TPasTreeString; begin Result := SPasTreeClassOfType; end;
  2314. function TPasRangeType.ElementTypeName: TPasTreeString; begin Result := SPasTreeRangeType; end;
  2315. function TPasArrayType.ElementTypeName: TPasTreeString; begin Result := SPasTreeArrayType; end;
  2316. function TPasFileType.ElementTypeName: TPasTreeString; begin Result := SPasTreeFileType; end;
  2317. function TPasEnumValue.ElementTypeName: TPasTreeString; begin Result := SPasTreeEnumValue; end;
  2318. procedure TPasEnumValue.ForEachCall(const aMethodCall: TOnForEachPasElement;
  2319. const Arg: Pointer);
  2320. begin
  2321. inherited ForEachCall(aMethodCall, Arg);
  2322. ForEachChildCall(aMethodCall,Arg,Value,false);
  2323. end;
  2324. procedure TPasEnumValue.FreeChildren(Prepare: boolean);
  2325. begin
  2326. Value:=TPasExpr(FreeChild(Value,Prepare));
  2327. inherited FreeChildren(Prepare);
  2328. end;
  2329. function TPasEnumValue.AssignedValue: TPasTreeString;
  2330. begin
  2331. If Assigned(Value) then
  2332. Result:=Value.GetDeclaration(True)
  2333. else
  2334. Result:='';
  2335. end;
  2336. function TPasEnumType.ElementTypeName: TPasTreeString; begin Result := SPasTreeEnumType end;
  2337. function TPasSetType.ElementTypeName: TPasTreeString; begin Result := SPasTreeSetType end;
  2338. function TPasRecordType.ElementTypeName: TPasTreeString; begin Result := SPasTreeRecordType end;
  2339. function TPasArgument.ElementTypeName: TPasTreeString; begin Result := SPasTreeArgument end;
  2340. function TPasProcedureType.ElementTypeName: TPasTreeString; begin Result := SPasTreeProcedureType end;
  2341. function TPasResultElement.ElementTypeName: TPasTreeString; begin Result := SPasTreeResultElement end;
  2342. procedure TPasResultElement.ForEachCall(const aMethodCall: TOnForEachPasElement;
  2343. const Arg: Pointer);
  2344. begin
  2345. inherited ForEachCall(aMethodCall, Arg);
  2346. ForEachChildCall(aMethodCall,Arg,ResultType,true);
  2347. end;
  2348. procedure TPasResultElement.ClearTypeReferences(aType: TPasElement);
  2349. begin
  2350. if ResultType=aType then
  2351. ResultType:=nil
  2352. end;
  2353. function TPasFunctionType.ElementTypeName: TPasTreeString; begin Result := SPasTreeFunctionType end;
  2354. function TPasUnresolvedTypeRef.ElementTypeName: TPasTreeString; begin Result := SPasTreeUnresolvedTypeRef end;
  2355. function TPasVariable.ElementTypeName: TPasTreeString; begin Result := SPasTreeVariable end;
  2356. function TPasConst.ElementTypeName: TPasTreeString; begin Result := SPasTreeConst end;
  2357. function TPasProperty.ElementTypeName: TPasTreeString; begin Result := SPasTreeProperty end;
  2358. function TPasOverloadedProc.ElementTypeName: TPasTreeString; begin Result := SPasTreeOverloadedProcedure end;
  2359. function TPasProcedure.ElementTypeName: TPasTreeString; begin Result := SPasTreeProcedure end;
  2360. function TPasFunction.GetFT: TPasFunctionType;
  2361. begin
  2362. Result:=ProcType as TPasFunctionType;
  2363. end;
  2364. function TPasFunction.ElementTypeName: TPasTreeString; begin Result := SPasTreeFunction; end;
  2365. function TPasClassProcedure.ElementTypeName: TPasTreeString; begin Result := SPasTreeClassProcedure; end;
  2366. function TPasClassConstructor.ElementTypeName: TPasTreeString; begin Result := SPasTreeClassConstructor; end;
  2367. function TPasClassDestructor.ElementTypeName: TPasTreeString; begin Result := SPasTreeClassDestructor; end;
  2368. function TPasClassDestructor.TypeName: TPasTreeString;
  2369. begin
  2370. Result:='destructor';
  2371. end;
  2372. function TPasClassDestructor.GetProcTypeEnum: TProcType;
  2373. begin
  2374. Result:=ptClassDestructor;
  2375. end;
  2376. function TPasClassFunction.ElementTypeName: TPasTreeString; begin Result := SPasTreeClassFunction; end;
  2377. class function TPasOperator.OperatorTypeToToken(T: TOperatorType): TPasTreeString;
  2378. begin
  2379. Result:=OperatorTokens[T];
  2380. end;
  2381. class function TPasOperator.OperatorTypeToOperatorName(T: TOperatorType
  2382. ): TPasTreeString;
  2383. begin
  2384. Result:=OperatorNames[T];
  2385. end;
  2386. class function TPasOperator.TokenToOperatorType(S: TPasTreeString): TOperatorType;
  2387. begin
  2388. Result:=High(TOperatorType);
  2389. While (Result>otUnknown) and (CompareText(S,OperatorTokens[Result])<>0) do
  2390. Result:=Pred(Result);
  2391. end;
  2392. class function TPasOperator.NameToOperatorType(S: TPasTreeString): TOperatorType;
  2393. begin
  2394. Result:=High(TOperatorType);
  2395. While (Result>otUnknown) and (CompareText(S,OperatorNames[Result])<>0) do
  2396. Result:=Pred(Result);
  2397. end;
  2398. Function TPasOperator.NameSuffix : TPasTreeString;
  2399. Var
  2400. I : Integer;
  2401. begin
  2402. Result:='(';
  2403. if Assigned(ProcType) and Assigned(ProcType.Args) then
  2404. for i:=0 to ProcType.Args.Count-1 do
  2405. begin
  2406. if i>0 then
  2407. Result:=Result+',';
  2408. Result:=Result+TPasArgument(ProcType.Args[i]).ArgType.Name;
  2409. end;
  2410. Result:=Result+')';
  2411. if Assigned(TPasFunctionType(ProcType)) and
  2412. Assigned(TPasFunctionType(ProcType).ResultEl) and
  2413. Assigned(TPasFunctionType(ProcType).ResultEl.ResultType) then
  2414. Result:=Result+':'+TPasFunctionType(ProcType).ResultEl.ResultType.Name;
  2415. end;
  2416. procedure TPasOperator.CorrectName;
  2417. begin
  2418. Name:=OperatorNames[OperatorType]+NameSuffix;
  2419. end;
  2420. function TPasOperator.OldName(WithPath : Boolean): TPasTreeString;
  2421. Var
  2422. I : Integer;
  2423. S : TPasTreeString;
  2424. begin
  2425. Result:=TypeName+' '+OperatorTokens[OperatorType];
  2426. Result := Result + '(';
  2427. if Assigned(ProcType) then
  2428. begin
  2429. for i := 0 to ProcType.Args.Count - 1 do
  2430. begin
  2431. if i > 0 then
  2432. Result := Result + ', ';
  2433. Result := Result + TPasArgument(ProcType.Args[i]).ArgType.Name;
  2434. end;
  2435. Result := Result + ')';
  2436. if (OperatorType<>otInitialize) and Assigned(TPasFunctionType(ProcType).ResultEl.ResultType) then
  2437. Result:=Result+': ' + TPasFunctionType(ProcType).ResultEl.ResultType.Name;
  2438. If WithPath then
  2439. begin
  2440. S:=Self.ParentPath;
  2441. if (S<>'') then
  2442. Result:=S+'.'+Result;
  2443. end;
  2444. end;
  2445. end;
  2446. function TPasOperator.ElementTypeName: TPasTreeString;
  2447. begin
  2448. Result := SPasTreeOperator
  2449. end;
  2450. function TPasConstructor.ElementTypeName: TPasTreeString; begin Result := SPasTreeConstructor end;
  2451. function TPasDestructor.ElementTypeName: TPasTreeString; begin Result := SPasTreeDestructor end;
  2452. function TPasProcedureImpl.ElementTypeName: TPasTreeString; begin Result := SPasTreeProcedureImpl end;
  2453. function TPasConstructorImpl.ElementTypeName: TPasTreeString; begin Result := SPasTreeConstructorImpl end;
  2454. function TPasDestructorImpl.ElementTypeName: TPasTreeString; begin Result := SPasTreeDestructorImpl end;
  2455. function TPasStringType.ElementTypeName: TPasTreeString; begin Result:=SPasStringType;end;
  2456. { All other stuff: }
  2457. procedure TPasElement.ProcessHints(const ASemiColonPrefix: boolean; var AResult: TPasTreeString);
  2458. var
  2459. S : TPasTreeString;
  2460. begin
  2461. if Hints <> [] then
  2462. begin
  2463. if ASemiColonPrefix then
  2464. AResult := AResult + ';';
  2465. S:=HintsString;
  2466. if (S<>'') then
  2467. AResult:=AResult+' '+S;
  2468. if ASemiColonPrefix then
  2469. AResult:=AResult+';';
  2470. end;
  2471. end;
  2472. procedure TPasElement.SetParent(const AValue: TPasElement);
  2473. begin
  2474. FParent:=AValue;
  2475. end;
  2476. constructor TPasElement.Create(const AName: TPasTreeString; AParent: TPasElement);
  2477. begin
  2478. inherited Create;
  2479. FName := AName;
  2480. FParent := AParent;
  2481. {$ifdef pas2js}
  2482. inc(FLastPasElementId);
  2483. FPasElementId:=FLastPasElementId;
  2484. //writeln('TPasElement.Create ',Name,':',ClassName,' ID=[',FPasElementId,']');
  2485. {$endif}
  2486. end;
  2487. destructor TPasElement.Destroy;
  2488. begin
  2489. FParent:=nil;
  2490. inherited Destroy;
  2491. end;
  2492. class function TPasElement.IsKeyWord(const S: TPasTreeString): Boolean;
  2493. Const
  2494. KW=';absolute;and;array;asm;begin;case;const;constructor;destructor;div;do;'+
  2495. 'downto;else;end;file;for;function;goto;if;implementation;in;inherited;'+
  2496. 'inline;interface;label;mod;nil;not;object;of;on;operator;or;packed;'+
  2497. 'procedure;program;record;reintroduce;repeat;self;set;shl;shr;TPasTreeString;then;'+
  2498. 'to;type;unit;until;uses;var;while;with;xor;dispose;exit;false;new;true;'+
  2499. 'as;class;dispinterface;except;exports;finalization;finally;initialization;'+
  2500. 'inline;is;library;on;out;packed;property;raise;resourcestring;threadvar;try;'+
  2501. 'private;published;length;setlength;';
  2502. begin
  2503. Result:=Pos(';'+lowercase(S)+';',KW)<>0;
  2504. end;
  2505. class function TPasElement.EscapeKeyWord(const S: TPasTreeString): TPasTreeString;
  2506. begin
  2507. Result:=S;
  2508. If IsKeyWord(Result) then
  2509. Result:='&'+Result;
  2510. end;
  2511. function TPasElement.FreeChild(Child: TPasElement; Prepare: boolean
  2512. ): TPasElement;
  2513. begin
  2514. if Child=nil then
  2515. exit(nil)
  2516. else if Prepare then
  2517. begin
  2518. if Child.Parent=Self then
  2519. begin
  2520. Child.FreeChildren(true);
  2521. exit(Child); // keep reference
  2522. end
  2523. else
  2524. exit(nil); // clear reference
  2525. end
  2526. else
  2527. begin
  2528. Child.FreeChildren(false);
  2529. Child.Free;
  2530. Result:=nil;
  2531. end;
  2532. end;
  2533. procedure TPasElement.FreeChildList(List: TFPList; Prepare: boolean);
  2534. var
  2535. i: Integer;
  2536. begin
  2537. if List=nil then exit;
  2538. for i:=0 to List.Count-1 do
  2539. List[i]:=FreeChild(TPasElement(List[i]),Prepare);
  2540. List.Clear;
  2541. end;
  2542. procedure TPasElement.FreeChildArray(A: TPasElementArray; Prepare: boolean);
  2543. var
  2544. i: Integer;
  2545. begin
  2546. for i:=0 to High(A) do
  2547. A[i]:=FreeChild(A[i],Prepare);
  2548. end;
  2549. procedure TPasElement.FreeChildren(Prepare: boolean);
  2550. begin
  2551. if Prepare then ;
  2552. end;
  2553. procedure TPasElement.ForEachCall(const aMethodCall: TOnForEachPasElement;
  2554. const Arg: Pointer);
  2555. begin
  2556. aMethodCall(Self,Arg);
  2557. end;
  2558. procedure TPasElement.ForEachChildCall(const aMethodCall: TOnForEachPasElement;
  2559. const Arg: Pointer; Child: TPasElement; CheckParent: boolean);
  2560. begin
  2561. if (Child=nil) then exit;
  2562. if CheckParent and (not Child.HasParent(Self)) then exit;
  2563. Child.ForEachCall(aMethodCall,Arg);
  2564. end;
  2565. function TPasElement.SafeName: TPasTreeString;
  2566. begin
  2567. Result:=Name;
  2568. if IsKeyWord(Result) then
  2569. Result:='&'+Result;
  2570. end;
  2571. function TPasElement.FullPath: TPasTreeString;
  2572. var
  2573. p: TPasElement;
  2574. begin
  2575. Result := '';
  2576. p := Parent;
  2577. while Assigned(p) and not p.InheritsFrom(TPasDeclarations) do
  2578. begin
  2579. if (p.Name<>'') and (Not (p is TPasOverloadedProc)) then
  2580. if Length(Result) > 0 then
  2581. Result := p.Name + '.' + Result
  2582. else
  2583. Result := p.Name;
  2584. p := p.Parent;
  2585. end;
  2586. end;
  2587. function TPasElement.FullName: TPasTreeString;
  2588. begin
  2589. Result := FullPath;
  2590. if Result<>'' then
  2591. Result:=Result+'.'+Name
  2592. else
  2593. Result:=Name;
  2594. end;
  2595. function TPasElement.ParentPath: TPasTreeString;
  2596. var
  2597. p: TPasElement;
  2598. begin
  2599. Result:='';
  2600. p := Parent;
  2601. while Assigned(p) do
  2602. begin
  2603. if (p.Name<>'') and (Not (p is TPasOverloadedProc)) then
  2604. if Length(Result) > 0 then
  2605. Result := p.Name + '.' + Result
  2606. else
  2607. Result := p.Name;
  2608. p := p.Parent;
  2609. end;
  2610. end;
  2611. function TPasElement.PathName: TPasTreeString;
  2612. begin
  2613. Result := ParentPath;
  2614. if Result<>'' then
  2615. Result:=Result+'.'+Name
  2616. else
  2617. Result:=Name;
  2618. end;
  2619. function TPasElement.GetModule: TPasModule;
  2620. Var
  2621. p : TPaselement;
  2622. begin
  2623. if Self is TPasPackage then
  2624. Result := nil
  2625. else
  2626. begin
  2627. P:=Self;
  2628. While (P<>Nil) and Not (P is TPasModule) do
  2629. P:=P.Parent;
  2630. Result:=TPasModule(P);
  2631. end;
  2632. end;
  2633. function TPasElement.GetDeclaration(full: Boolean): TPasTreeString;
  2634. begin
  2635. if Full then
  2636. Result := SafeName
  2637. else
  2638. Result := '';
  2639. end;
  2640. procedure TPasElement.Accept(Visitor: TPassTreeVisitor);
  2641. begin
  2642. Visitor.Visit(Self);
  2643. end;
  2644. procedure TPasElement.ClearTypeReferences(aType: TPasElement);
  2645. begin
  2646. if aType=nil then ;
  2647. end;
  2648. function TPasElement.HasParent(aParent: TPasElement): boolean;
  2649. var
  2650. El: TPasElement;
  2651. begin
  2652. El:=Parent;
  2653. while El<>nil do
  2654. begin
  2655. if El=aParent then exit(true);
  2656. El:=El.Parent;
  2657. end;
  2658. Result:=false;
  2659. end;
  2660. constructor TPasDeclarations.Create(const AName: TPasTreeString; AParent: TPasElement);
  2661. begin
  2662. inherited Create(AName, AParent);
  2663. Declarations := TFPList.Create;
  2664. Attributes := TFPList.Create;
  2665. Classes := TFPList.Create;
  2666. Consts := TFPList.Create;
  2667. ExportSymbols := TFPList.Create;
  2668. Functions := TFPList.Create;
  2669. Properties := TFPList.Create;
  2670. ResStrings := TFPList.Create;
  2671. Types := TFPList.Create;
  2672. Labels := TFPList.Create;
  2673. Variables := TFPList.Create;
  2674. end;
  2675. destructor TPasDeclarations.Destroy;
  2676. begin
  2677. {$IFDEF VerbosePasTreeMem}writeln('TPasDeclarations.Destroy START');{$ENDIF}
  2678. FreeAndNil(Variables);
  2679. FreeAndNil(Types);
  2680. FreeAndNil(ResStrings);
  2681. FreeAndNil(Properties);
  2682. FreeAndNil(Functions);
  2683. FreeAndNil(ExportSymbols);
  2684. FreeAndNil(Consts);
  2685. FreeAndNil(Classes);
  2686. FreeAndNil(Attributes);
  2687. FreeAndNil(Labels);
  2688. FreeAndNil(Declarations);
  2689. {$IFDEF VerbosePasTreeMem}writeln('TPasDeclarations.Destroy inherited');{$ENDIF}
  2690. inherited Destroy;
  2691. {$IFDEF VerbosePasTreeMem}writeln('TPasDeclarations.Destroy END');{$ENDIF}
  2692. end;
  2693. procedure TPasDeclarations.FreeChildren(Prepare: boolean);
  2694. begin
  2695. FreeChildList(Declarations,Prepare);
  2696. inherited FreeChildren(Prepare);
  2697. end;
  2698. procedure TPasModule.FreeChildren(Prepare: boolean);
  2699. begin
  2700. GlobalDirectivesSection:=TPasImplCommandBase(FreeChild(GlobalDirectivesSection,Prepare));
  2701. InterfaceSection:=TInterfaceSection(FreeChild(InterfaceSection,Prepare));
  2702. ImplementationSection:=TImplementationSection(FreeChild(ImplementationSection,Prepare));
  2703. InitializationSection:=TInitializationSection(FreeChild(InitializationSection,Prepare));
  2704. FinalizationSection:=TFinalizationSection(FreeChild(FinalizationSection,Prepare));
  2705. inherited FreeChildren(Prepare);
  2706. end;
  2707. constructor TPasPackage.Create(const AName: TPasTreeString; AParent: TPasElement);
  2708. begin
  2709. if (Length(AName) > 0) and (AName[1] <> '#') then
  2710. inherited Create('#' + AName, AParent)
  2711. else
  2712. inherited Create(AName, AParent);
  2713. Modules := TFPList.Create;
  2714. end;
  2715. destructor TPasPackage.Destroy;
  2716. begin
  2717. FreeAndNil(Modules);
  2718. inherited Destroy;
  2719. end;
  2720. procedure TPasPackage.FreeChildren(Prepare: boolean);
  2721. begin
  2722. FreeChildList(Modules,Prepare);
  2723. inherited FreeChildren(Prepare);
  2724. end;
  2725. procedure TPasPointerType.FreeChildren(Prepare: boolean);
  2726. begin
  2727. DestType:=TPasType(FreeChild(DestType,Prepare));
  2728. inherited FreeChildren(Prepare);
  2729. end;
  2730. procedure TPasAliasType.FreeChildren(Prepare: boolean);
  2731. begin
  2732. SubType:=TPasType(FreeChild(SubType,Prepare));
  2733. DestType:=TPasType(FreeChild(DestType,Prepare));
  2734. Expr:=TPasExpr(FreeChild(Expr,Prepare));
  2735. CodepageExpr:=TPasExpr(FreeChild(CodepageExpr,Prepare));
  2736. inherited FreeChildren(Prepare);
  2737. end;
  2738. procedure TPasArrayType.FreeChildren(Prepare: boolean);
  2739. begin
  2740. FreePasExprArray(Self,Ranges,Prepare);
  2741. ElType:=TPasTypeRef(FreeChild(ElType,Prepare));
  2742. inherited FreeChildren(Prepare);
  2743. end;
  2744. procedure TPasArrayType.ClearTypeReferences(aType: TPasElement);
  2745. begin
  2746. inherited ClearTypeReferences(aType);
  2747. if ElType=aType then
  2748. ElType:=nil;
  2749. end;
  2750. procedure TPasFileType.FreeChildren(Prepare: boolean);
  2751. begin
  2752. ElType:=TPasType(FreeChild(ElType,Prepare));
  2753. inherited FreeChildren(Prepare);
  2754. end;
  2755. procedure TPasFileType.ClearTypeReferences(aType: TPasElement);
  2756. begin
  2757. if aType=ElType then
  2758. ElType:=nil;
  2759. end;
  2760. constructor TPasEnumType.Create(const AName: TPasTreeString; AParent: TPasElement);
  2761. begin
  2762. inherited Create(AName, AParent);
  2763. Values := TFPList.Create;
  2764. end;
  2765. destructor TPasEnumType.Destroy;
  2766. begin
  2767. FreeAndNil(Values);
  2768. inherited Destroy;
  2769. end;
  2770. procedure TPasEnumType.FreeChildren(Prepare: boolean);
  2771. begin
  2772. FreeChildList(Values,Prepare);
  2773. inherited FreeChildren(Prepare);
  2774. end;
  2775. procedure TPasEnumType.GetEnumNames(Names: TStrings);
  2776. var
  2777. i: Integer;
  2778. begin
  2779. with Values do
  2780. begin
  2781. for i := 0 to Count - 2 do
  2782. Names.Add(TPasEnumValue(Items[i]).Name + ',');
  2783. if Count > 0 then
  2784. Names.Add(TPasEnumValue(Items[Count - 1]).Name);
  2785. end;
  2786. end;
  2787. procedure TPasEnumType.ForEachCall(const aMethodCall: TOnForEachPasElement;
  2788. const Arg: Pointer);
  2789. var
  2790. i: Integer;
  2791. begin
  2792. inherited ForEachCall(aMethodCall, Arg);
  2793. for i:=0 to Values.Count-1 do
  2794. ForEachChildCall(aMethodCall,Arg,TPasEnumValue(Values[i]),false);
  2795. end;
  2796. constructor TPasVariant.Create(const AName: TPasTreeString; AParent: TPasElement);
  2797. begin
  2798. inherited Create(AName, AParent);
  2799. Values := TFPList.Create;
  2800. end;
  2801. destructor TPasVariant.Destroy;
  2802. begin
  2803. FreeAndNil(Values);
  2804. inherited Destroy;
  2805. end;
  2806. procedure TPasVariant.FreeChildren(Prepare: boolean);
  2807. begin
  2808. FreeChildList(Values,Prepare);
  2809. Members:=TPasRecordType(FreeChild(Members,Prepare));
  2810. inherited FreeChildren(Prepare);
  2811. end;
  2812. function TPasVariant.GetDeclaration(full: boolean): TPasTreeString;
  2813. Var
  2814. i : Integer;
  2815. S : TStrings;
  2816. begin
  2817. Result:='';
  2818. For I:=0 to Values.Count-1 do
  2819. begin
  2820. if (Result<>'') then
  2821. Result:=Result+', ';
  2822. Result:=Result+TPasElement(Values[i]).GetDeclaration(False);
  2823. Result:=Result+': ('+sLineBreak;
  2824. S:=TStringList.Create;
  2825. try
  2826. Members.GetMembers(S);
  2827. Result:=Result+S.Text;
  2828. finally
  2829. S.Free;
  2830. end;
  2831. Result:=Result+');';
  2832. if Full then ;
  2833. end;
  2834. end;
  2835. procedure TPasVariant.ForEachCall(const aMethodCall: TOnForEachPasElement;
  2836. const Arg: Pointer);
  2837. var
  2838. i: Integer;
  2839. begin
  2840. inherited ForEachCall(aMethodCall, Arg);
  2841. for i:=0 to Values.Count-1 do
  2842. ForEachChildCall(aMethodCall,Arg,TPasElement(Values[i]),false);
  2843. ForEachChildCall(aMethodCall,Arg,Members,false);
  2844. end;
  2845. { TPasRecordType }
  2846. constructor TPasRecordType.Create(const AName: TPasTreeString; AParent: TPasElement);
  2847. begin
  2848. inherited Create(AName, AParent);
  2849. end;
  2850. destructor TPasRecordType.Destroy;
  2851. begin
  2852. FreeAndNil(Variants);
  2853. inherited Destroy;
  2854. end;
  2855. procedure TPasRecordType.FreeChildren(Prepare: boolean);
  2856. begin
  2857. VariantEl:=FreeChild(VariantEl,Prepare);
  2858. FreeChildList(Variants,Prepare);
  2859. inherited FreeChildren(Prepare);
  2860. end;
  2861. procedure TPasRecordType.ClearTypeReferences(aType: TPasElement);
  2862. begin
  2863. inherited ClearTypeReferences(aType);
  2864. if VariantEl=aType then
  2865. VariantEl:=nil;
  2866. end;
  2867. { TPasClassType }
  2868. constructor TPasClassType.Create(const AName: TPasTreeString; AParent: TPasElement);
  2869. begin
  2870. inherited Create(AName, AParent);
  2871. IsShortDefinition := False;
  2872. Modifiers := TStringList.Create;
  2873. Interfaces:= TFPList.Create;
  2874. end;
  2875. destructor TPasClassType.Destroy;
  2876. begin
  2877. FreeAndNil(Interfaces);
  2878. FreeAndNil(Modifiers);
  2879. inherited Destroy;
  2880. end;
  2881. procedure TPasClassType.FreeChildren(Prepare: boolean);
  2882. begin
  2883. AncestorType:=TPasType(FreeChild(AncestorType,Prepare));
  2884. HelperForType:=TPasType(FreeChild(HelperForType,Prepare));
  2885. GUIDExpr:=TPasExpr(FreeChild(GUIDExpr,Prepare));
  2886. FreeChildList(Interfaces,Prepare);
  2887. inherited FreeChildren(Prepare);
  2888. end;
  2889. procedure TPasClassType.ClearTypeReferences(aType: TPasElement);
  2890. var
  2891. i: Integer;
  2892. El: TPasElement;
  2893. begin
  2894. inherited ClearTypeReferences(aType);
  2895. if AncestorType=aType then
  2896. AncestorType:=nil;
  2897. if HelperForType=aType then
  2898. HelperForType:=nil;
  2899. for i := Interfaces.Count - 1 downto 0 do
  2900. begin
  2901. El:=TPasElement(Interfaces[i]);
  2902. if El=aType then
  2903. Interfaces[i]:=nil;
  2904. end;
  2905. end;
  2906. function TPasClassType.ElementTypeName: TPasTreeString;
  2907. begin
  2908. case ObjKind of
  2909. okObject: Result := SPasTreeObjectType;
  2910. okClass: Result := SPasTreeClassType;
  2911. okInterface: Result := SPasTreeInterfaceType;
  2912. okClassHelper : Result:=SPasClassHelperType;
  2913. okRecordHelper : Result:=SPasRecordHelperType;
  2914. okTypeHelper : Result:=SPasTypeHelperType;
  2915. else
  2916. Result:='ObjKind('+IntToStr(ord(ObjKind))+')';
  2917. end;
  2918. end;
  2919. procedure TPasClassType.ForEachCall(const aMethodCall: TOnForEachPasElement;
  2920. const Arg: Pointer);
  2921. var
  2922. i: Integer;
  2923. begin
  2924. inherited ForEachCall(aMethodCall, Arg);
  2925. ForEachChildCall(aMethodCall,Arg,AncestorType,true);
  2926. for i:=0 to Interfaces.Count-1 do
  2927. ForEachChildCall(aMethodCall,Arg,TPasElement(Interfaces[i]),true);
  2928. ForEachChildCall(aMethodCall,Arg,HelperForType,true);
  2929. ForEachChildCall(aMethodCall,Arg,GUIDExpr,false);
  2930. end;
  2931. function TPasClassType.IsObjCClass: Boolean;
  2932. begin
  2933. Result:=ObjKind in okObjCClasses;
  2934. end;
  2935. function TPasClassType.FindMember(MemberClass: TPTreeElement; const MemberName: TPasTreeString): TPasElement;
  2936. Var
  2937. I : Integer;
  2938. begin
  2939. // Writeln('Looking for ',MemberName,'(',MemberClass.ClassName,') in ',Name);
  2940. Result:=Nil;
  2941. I:=0;
  2942. While (Result=Nil) and (I<Members.Count) do
  2943. begin
  2944. Result:=TPasElement(Members[i]);
  2945. if (Result.ClassType<>MemberClass) or (CompareText(Result.Name,MemberName)<>0) then
  2946. Result:=Nil;
  2947. Inc(I);
  2948. end;
  2949. end;
  2950. function TPasClassType.FindMemberInAncestors(MemberClass: TPTreeElement;
  2951. const MemberName: TPasTreeString): TPasElement;
  2952. Function A (C : TPasClassType) : TPasClassType;
  2953. begin
  2954. if C.AncestorType is TPasClassType then
  2955. result:=TPasClassType(C.AncestorType)
  2956. else
  2957. result:=Nil;
  2958. end;
  2959. Var
  2960. C : TPasClassType;
  2961. begin
  2962. Result:=Nil;
  2963. C:=A(Self);
  2964. While (Result=Nil) and (C<>Nil) do
  2965. begin
  2966. Result:=C.FindMember(MemberClass,MemberName);
  2967. C:=A(C);
  2968. end;
  2969. end;
  2970. function TPasClassType.InterfaceGUID: TPasTreeString;
  2971. begin
  2972. If Assigned(GUIDExpr) then
  2973. Result:=GUIDExpr.GetDeclaration(True)
  2974. else
  2975. Result:=''
  2976. end;
  2977. function TPasClassType.IsSealed: Boolean;
  2978. begin
  2979. Result:=HasModifier('sealed');
  2980. end;
  2981. function TPasClassType.IsAbstract: Boolean;
  2982. begin
  2983. Result:=HasModifier('abstract');
  2984. end;
  2985. function TPasClassType.HasModifier(const aModifier: TPasTreeString): Boolean;
  2986. var
  2987. i: Integer;
  2988. begin
  2989. for i:=0 to Modifiers.Count-1 do
  2990. if CompareText(aModifier,Modifiers[i])=0 then
  2991. exit(true);
  2992. Result:=false;
  2993. end;
  2994. { TPasArgument }
  2995. procedure TPasArgument.FreeChildren(Prepare: boolean);
  2996. begin
  2997. ArgType:=TPasTypeRef(FreeChild(ArgType,Prepare));
  2998. ValueExpr:=TPasExpr(FreeChild(ValueExpr,Prepare));
  2999. inherited FreeChildren(Prepare);
  3000. end;
  3001. procedure TPasArgument.ClearTypeReferences(aType: TPasElement);
  3002. begin
  3003. if ArgType=aType then
  3004. ArgType:=nil;
  3005. end;
  3006. function TPasArgument.GetDeclaration (full : boolean) : TPasTreeString;
  3007. begin
  3008. If Assigned(ArgType) then
  3009. begin
  3010. If ArgType.Name<>'' then
  3011. Result:=ArgType.SafeName
  3012. else
  3013. Result:=ArgType.GetDeclaration(False);
  3014. If Full and (Name<>'') then
  3015. Result:=SafeName+': '+Result;
  3016. end
  3017. else If Full then
  3018. Result:=SafeName
  3019. else
  3020. Result:='';
  3021. end;
  3022. procedure TPasArgument.ForEachCall(const aMethodCall: TOnForEachPasElement;
  3023. const Arg: Pointer);
  3024. begin
  3025. inherited ForEachCall(aMethodCall, Arg);
  3026. ForEachChildCall(aMethodCall,Arg,ArgType,true);
  3027. ForEachChildCall(aMethodCall,Arg,ValueExpr,false);
  3028. end;
  3029. function TPasArgument.Value: TPasTreeString;
  3030. begin
  3031. If Assigned(ValueExpr) then
  3032. Result:=ValueExpr.GetDeclaration(true)
  3033. else
  3034. Result:='';
  3035. end;
  3036. { TPasProcedureType }
  3037. // inline
  3038. function TPasProcedureType.GetIsAsync: Boolean;
  3039. begin
  3040. Result:=ptmAsync in Modifiers;
  3041. end;
  3042. // inline
  3043. function TPasProcedureType.GetIsNested: Boolean;
  3044. begin
  3045. Result:=ptmIsNested in Modifiers;
  3046. end;
  3047. // inline
  3048. function TPasProcedureType.GetIsOfObject: Boolean;
  3049. begin
  3050. Result:=ptmOfObject in Modifiers;
  3051. end;
  3052. // inline
  3053. function TPasProcedureType.GetIsReference: Boolean;
  3054. begin
  3055. Result:=ptmReferenceTo in Modifiers;
  3056. end;
  3057. procedure TPasProcedureType.SetIsAsync(const AValue: Boolean);
  3058. begin
  3059. if AValue then
  3060. Include(Modifiers,ptmAsync)
  3061. else
  3062. Exclude(Modifiers,ptmAsync);
  3063. end;
  3064. procedure TPasProcedureType.SetIsNested(const AValue: Boolean);
  3065. begin
  3066. if AValue then
  3067. Include(Modifiers,ptmIsNested)
  3068. else
  3069. Exclude(Modifiers,ptmIsNested);
  3070. end;
  3071. procedure TPasProcedureType.SetIsOfObject(const AValue: Boolean);
  3072. begin
  3073. if AValue then
  3074. Include(Modifiers,ptmOfObject)
  3075. else
  3076. Exclude(Modifiers,ptmOfObject);
  3077. end;
  3078. procedure TPasProcedureType.SetIsReference(AValue: Boolean);
  3079. begin
  3080. if AValue then
  3081. Include(Modifiers,ptmReferenceTo)
  3082. else
  3083. Exclude(Modifiers,ptmReferenceTo);
  3084. end;
  3085. constructor TPasProcedureType.Create(const AName: TPasTreeString; AParent: TPasElement);
  3086. begin
  3087. inherited Create(AName, AParent);
  3088. Args := TFPList.Create;
  3089. end;
  3090. destructor TPasProcedureType.Destroy;
  3091. begin
  3092. FreeAndNil(Args);
  3093. inherited Destroy;
  3094. end;
  3095. procedure TPasProcedureType.FreeChildren(Prepare: boolean);
  3096. begin
  3097. FreeChildList(Args,Prepare);
  3098. VarArgsType:=TPasType(FreeChild(VarArgsType,Prepare));
  3099. inherited FreeChildren(Prepare);
  3100. end;
  3101. procedure TPasProcedureType.ClearTypeReferences(aType: TPasElement);
  3102. begin
  3103. inherited ClearTypeReferences(aType);
  3104. if VarArgsType=aType then
  3105. VarArgsType:=nil;
  3106. end;
  3107. class function TPasProcedureType.TypeName: TPasTreeString;
  3108. begin
  3109. Result := 'procedure';
  3110. end;
  3111. function TPasProcedureType.CreateArgument(const AName,
  3112. AUnresolvedTypeName: TPasTreeString): TPasArgument;
  3113. begin
  3114. Result := TPasArgument.Create(AName, Self);
  3115. Args.Add(Result);
  3116. if AUnresolvedTypeName<>'' then
  3117. Result.ArgType := TPasUnresolvedTypeRef.Create(AUnresolvedTypeName, Result);
  3118. end;
  3119. procedure TPasProcedureType.ForEachCall(const aMethodCall: TOnForEachPasElement;
  3120. const Arg: Pointer);
  3121. var
  3122. i: Integer;
  3123. begin
  3124. inherited ForEachCall(aMethodCall, Arg);
  3125. for i:=0 to Args.Count-1 do
  3126. ForEachChildCall(aMethodCall,Arg,TPasElement(Args[i]),false);
  3127. ForEachChildCall(aMethodCall,Arg,VarArgsType,false);
  3128. end;
  3129. { TPasResultElement }
  3130. procedure TPasResultElement.FreeChildren(Prepare: boolean);
  3131. begin
  3132. ResultType:=TPasType(FreeChild(ResultType,Prepare));
  3133. inherited FreeChildren(Prepare);
  3134. end;
  3135. procedure TPasFunctionType.FreeChildren(Prepare: boolean);
  3136. begin
  3137. ResultEl:=TPasResultElement(FreeChild(ResultEl,Prepare));
  3138. inherited FreeChildren(Prepare);
  3139. end;
  3140. class function TPasFunctionType.TypeName: TPasTreeString;
  3141. begin
  3142. Result := 'function';
  3143. end;
  3144. constructor TPasUnresolvedTypeRef.Create(const AName: TPasTreeString; AParent: TPasElement);
  3145. begin
  3146. inherited Create(AName, nil);
  3147. if AParent=nil then ;
  3148. end;
  3149. procedure TPasVariable.FreeChildren(Prepare: boolean);
  3150. begin
  3151. VarType:=TPasType(FreeChild(VarType,Prepare));
  3152. LibraryName:=TPasExpr(FreeChild(LibraryName,Prepare));
  3153. ExportName:=TPasExpr(FreeChild(ExportName,Prepare));
  3154. AbsoluteExpr:=TPasExpr(FreeChild(AbsoluteExpr,Prepare));
  3155. Expr:=TPasExpr(FreeChild(Expr,Prepare));
  3156. inherited FreeChildren(Prepare);
  3157. end;
  3158. function TPasProperty.GetIsClass: boolean;
  3159. begin
  3160. Result:=vmClass in VarModifiers;
  3161. end;
  3162. procedure TPasProperty.SetIsClass(AValue: boolean);
  3163. begin
  3164. if AValue then
  3165. Include(VarModifiers,vmClass)
  3166. else
  3167. Exclude(VarModifiers,vmClass);
  3168. end;
  3169. constructor TPasProperty.Create(const AName: TPasTreeString; AParent: TPasElement);
  3170. begin
  3171. inherited Create(AName, AParent);
  3172. FArgs := TFPList.Create;
  3173. end;
  3174. destructor TPasProperty.Destroy;
  3175. begin
  3176. FreeAndNil(FArgs);
  3177. SetLength(Implements,0);
  3178. inherited Destroy;
  3179. end;
  3180. procedure TPasProperty.FreeChildren(Prepare: boolean);
  3181. begin
  3182. IndexExpr:=TPasExpr(FreeChild(IndexExpr,Prepare));
  3183. ReadAccessor:=TPasExpr(FreeChild(ReadAccessor,Prepare));
  3184. WriteAccessor:=TPasExpr(FreeChild(WriteAccessor,Prepare));
  3185. DispIDExpr:=TPasExpr(FreeChild(DispIDExpr,Prepare));
  3186. FreePasExprArray(Self,Implements,Prepare);
  3187. StoredAccessor:=TPasExpr(FreeChild(StoredAccessor,Prepare));
  3188. DefaultExpr:=TPasExpr(FreeChild(DefaultExpr,Prepare));
  3189. inherited FreeChildren(Prepare);
  3190. end;
  3191. constructor TPasOverloadedProc.Create(const AName: TPasTreeString; AParent: TPasElement);
  3192. begin
  3193. inherited Create(AName, AParent);
  3194. Overloads := TFPList.Create;
  3195. end;
  3196. destructor TPasOverloadedProc.Destroy;
  3197. begin
  3198. FreeAndNil(Overloads);
  3199. inherited Destroy;
  3200. end;
  3201. procedure TPasOverloadedProc.FreeChildren(Prepare: boolean);
  3202. begin
  3203. FreeChildList(Overloads,Prepare);
  3204. inherited FreeChildren(Prepare);
  3205. end;
  3206. function TPasOverloadedProc.TypeName: TPasTreeString;
  3207. begin
  3208. if Assigned(TPasProcedure(Overloads[0]).ProcType) then
  3209. Result := TPasProcedure(Overloads[0]).ProcType.TypeName
  3210. else
  3211. SetLength(Result, 0);
  3212. end;
  3213. procedure TPasOverloadedProc.ForEachCall(
  3214. const aMethodCall: TOnForEachPasElement; const Arg: Pointer);
  3215. var
  3216. i: Integer;
  3217. begin
  3218. inherited ForEachCall(aMethodCall, Arg);
  3219. for i:=0 to Overloads.Count-1 do
  3220. ForEachChildCall(aMethodCall,Arg,TPasProcedure(Overloads[i]),false);
  3221. end;
  3222. function TPasProcedure.GetCallingConvention: TCallingConvention;
  3223. begin
  3224. Result:=ccDefault;
  3225. if Assigned(ProcType) then
  3226. Result:=ProcType.CallingConvention;
  3227. end;
  3228. procedure TPasProcedure.SetCallingConvention(AValue: TCallingConvention);
  3229. begin
  3230. if Assigned(ProcType) then
  3231. ProcType.CallingConvention:=AValue;
  3232. end;
  3233. destructor TPasProcedure.Destroy;
  3234. begin
  3235. FreeProcNameParts(NameParts);
  3236. inherited Destroy;
  3237. end;
  3238. procedure TPasProcedure.FreeChildren(Prepare: boolean);
  3239. begin
  3240. PublicName:=TPasExpr(FreeChild(PublicName,Prepare));
  3241. LibrarySymbolIndex:=TPasExpr(FreeChild(LibrarySymbolIndex,Prepare));
  3242. LibrarySymbolName:=TPasExpr(FreeChild(LibrarySymbolName,Prepare));
  3243. LibraryExpr:=TPasExpr(FreeChild(LibraryExpr,Prepare));
  3244. DispIDExpr:=TPasExpr(FreeChild(DispIDExpr,Prepare));
  3245. MessageExpr:=TPasExpr(FreeChild(MessageExpr,Prepare));
  3246. ProcType:=TPasProcedureType(FreeChild(ProcType,Prepare));
  3247. Body:=TProcedureBody(FreeChild(Body,Prepare));
  3248. //FreeProcNameParts(Self,NameParts,Prepare);
  3249. inherited FreeChildren(Prepare);
  3250. end;
  3251. function TPasProcedure.TypeName: TPasTreeString;
  3252. begin
  3253. Result := 'procedure';
  3254. end;
  3255. constructor TPasProcedureImpl.Create(const AName: TPasTreeString; AParent: TPasElement);
  3256. begin
  3257. inherited Create(AName, AParent);
  3258. Locals := TFPList.Create;
  3259. end;
  3260. destructor TPasProcedureImpl.Destroy;
  3261. begin
  3262. FreeAndNil(Locals);
  3263. inherited Destroy;
  3264. end;
  3265. procedure TPasProcedureImpl.FreeChildren(Prepare: boolean);
  3266. begin
  3267. ProcType:=TPasProcedureType(FreeChild(ProcType,Prepare));
  3268. FreeChildList(Locals,Prepare);
  3269. Body:=TPasImplBlock(FreeChild(Body,Prepare));
  3270. inherited FreeChildren(Prepare);
  3271. end;
  3272. function TPasProcedureImpl.TypeName: TPasTreeString;
  3273. begin
  3274. Result := ProcType.TypeName;
  3275. end;
  3276. function TPasConstructorImpl.TypeName: TPasTreeString;
  3277. begin
  3278. Result := 'constructor';
  3279. end;
  3280. function TPasDestructorImpl.TypeName: TPasTreeString;
  3281. begin
  3282. Result := 'destructor';
  3283. end;
  3284. constructor TPasImplCommands.Create(const AName: TPasTreeString; AParent: TPasElement);
  3285. begin
  3286. inherited Create(AName, AParent);
  3287. Commands := TStringList.Create;
  3288. end;
  3289. destructor TPasImplCommands.Destroy;
  3290. begin
  3291. FreeAndNil(Commands);
  3292. inherited Destroy;
  3293. end;
  3294. procedure TPasImplIfElse.FreeChildren(Prepare: boolean);
  3295. begin
  3296. ConditionExpr:=TPasExpr(FreeChild(ConditionExpr,Prepare));
  3297. IfBranch:=TPasImplElement(FreeChild(IfBranch,Prepare));
  3298. ElseBranch:=TPasImplElement(FreeChild(ElseBranch,Prepare));
  3299. inherited FreeChildren(Prepare);
  3300. end;
  3301. procedure TPasImplIfElse.AddElement(Element: TPasImplElement);
  3302. begin
  3303. inherited AddElement(Element);
  3304. if IfBranch=nil then
  3305. begin
  3306. IfBranch:=Element;
  3307. end
  3308. else if ElseBranch=nil then
  3309. begin
  3310. ElseBranch:=Element;
  3311. end
  3312. else
  3313. raise EPasTree.Create('TPasImplIfElse.AddElement if and else already set - please report this bug');
  3314. end;
  3315. function TPasImplIfElse.CloseOnSemicolon: boolean;
  3316. begin
  3317. Result:=ElseBranch<>nil;
  3318. end;
  3319. procedure TPasImplIfElse.ForEachCall(const aMethodCall: TOnForEachPasElement;
  3320. const Arg: Pointer);
  3321. begin
  3322. ForEachChildCall(aMethodCall,Arg,ConditionExpr,false);
  3323. if Elements.IndexOf(IfBranch)<0 then
  3324. ForEachChildCall(aMethodCall,Arg,IfBranch,false);
  3325. if Elements.IndexOf(ElseBranch)<0 then
  3326. ForEachChildCall(aMethodCall,Arg,ElseBranch,false);
  3327. inherited ForEachCall(aMethodCall, Arg);
  3328. end;
  3329. function TPasImplIfElse.Condition: TPasTreeString;
  3330. begin
  3331. If Assigned(ConditionExpr) then
  3332. Result:=ConditionExpr.GetDeclaration(True)
  3333. else
  3334. Result:='';
  3335. end;
  3336. procedure TPasImplForLoop.FreeChildren(Prepare: boolean);
  3337. begin
  3338. VariableName:=TPasExpr(FreeChild(VariableName,Prepare));
  3339. StartExpr:=TPasExpr(FreeChild(StartExpr,Prepare));
  3340. EndExpr:=TPasExpr(FreeChild(EndExpr,Prepare));
  3341. Variable:=TPasVariable(FreeChild(Variable,Prepare));
  3342. VarType:=TPasType(FreeChild(VarType,Prepare));
  3343. Body:=TPasImplElement(FreeChild(Body,Prepare));
  3344. inherited FreeChildren(Prepare);
  3345. end;
  3346. procedure TPasImplForLoop.AddElement(Element: TPasImplElement);
  3347. begin
  3348. inherited AddElement(Element);
  3349. if Body=nil then
  3350. begin
  3351. Body:=Element;
  3352. end
  3353. else
  3354. raise EPasTree.Create('TPasImplForLoop.AddElement body already set - please report this bug');
  3355. end;
  3356. procedure TPasImplForLoop.ForEachCall(const aMethodCall: TOnForEachPasElement;
  3357. const Arg: Pointer);
  3358. begin
  3359. ForEachChildCall(aMethodCall,Arg,VariableName,false);
  3360. ForEachChildCall(aMethodCall,Arg,Variable,false);
  3361. ForEachChildCall(aMethodCall,Arg,StartExpr,false);
  3362. ForEachChildCall(aMethodCall,Arg,EndExpr,false);
  3363. if Elements.IndexOf(Body)<0 then
  3364. ForEachChildCall(aMethodCall,Arg,Body,false);
  3365. inherited ForEachCall(aMethodCall, Arg);
  3366. end;
  3367. function TPasImplForLoop.Down: boolean;
  3368. begin
  3369. Result:=(LoopType=ltDown);
  3370. end;
  3371. function TPasImplForLoop.StartValue: TPasTreeString;
  3372. begin
  3373. If Assigned(StartExpr) then
  3374. Result:=StartExpr.GetDeclaration(true)
  3375. else
  3376. Result:='';
  3377. end;
  3378. function TPasImplForLoop.EndValue: TPasTreeString;
  3379. begin
  3380. If Assigned(EndExpr) then
  3381. Result:=EndExpr.GetDeclaration(true)
  3382. else
  3383. Result:='';
  3384. end;
  3385. constructor TPasImplBlock.Create(const AName: TPasTreeString; AParent: TPasElement);
  3386. begin
  3387. inherited Create(AName, AParent);
  3388. Elements := TFPList.Create;
  3389. end;
  3390. destructor TPasImplBlock.Destroy;
  3391. begin
  3392. FreeAndNil(Elements);
  3393. inherited Destroy;
  3394. end;
  3395. procedure TPasImplBlock.FreeChildren(Prepare: boolean);
  3396. begin
  3397. FreeChildList(Elements,Prepare);
  3398. inherited FreeChildren(Prepare);
  3399. end;
  3400. procedure TPasImplBlock.AddElement(Element: TPasImplElement);
  3401. begin
  3402. Elements.Add(Element);
  3403. end;
  3404. function TPasImplBlock.AddCommand(const ACommand: TPasTreeString): TPasImplCommand;
  3405. begin
  3406. Result := TPasImplCommand.Create('', Self);
  3407. Result.Command := ACommand;
  3408. AddElement(Result);
  3409. end;
  3410. function TPasImplBlock.AddCommands: TPasImplCommands;
  3411. begin
  3412. Result := TPasImplCommands.Create('', Self);
  3413. AddElement(Result);
  3414. end;
  3415. function TPasImplBlock.AddBeginBlock: TPasImplBeginBlock;
  3416. begin
  3417. Result := TPasImplBeginBlock.Create('', Self);
  3418. AddElement(Result);
  3419. end;
  3420. function TPasImplBlock.AddRepeatUntil: TPasImplRepeatUntil;
  3421. begin
  3422. Result := TPasImplRepeatUntil.Create('', Self);
  3423. AddElement(Result);
  3424. end;
  3425. function TPasImplBlock.AddIfElse(const ACondition: TPasExpr): TPasImplIfElse;
  3426. begin
  3427. Result := TPasImplIfElse.Create('', Self);
  3428. Result.ConditionExpr := ACondition;
  3429. ACondition.Parent:=Result;
  3430. AddElement(Result);
  3431. end;
  3432. function TPasImplBlock.AddWhileDo(const ACondition: TPasExpr): TPasImplWhileDo;
  3433. begin
  3434. Result := TPasImplWhileDo.Create('', Self);
  3435. Result.ConditionExpr := ACondition;
  3436. ACondition.Parent:=Result;
  3437. AddElement(Result);
  3438. end;
  3439. function TPasImplBlock.AddWithDo(const Expression: TPasExpr): TPasImplWithDo;
  3440. begin
  3441. Result := TPasImplWithDo.Create('', Self);
  3442. Result.AddExpression(Expression);
  3443. AddElement(Result);
  3444. end;
  3445. function TPasImplBlock.AddCaseOf(const Expression: TPasExpr): TPasImplCaseOf;
  3446. begin
  3447. Result := TPasImplCaseOf.Create('', Self);
  3448. Result.CaseExpr:= Expression;
  3449. Expression.Parent:=Result;
  3450. AddElement(Result);
  3451. end;
  3452. function TPasImplBlock.AddForLoop(AVar: TPasVariable; const AStartValue,
  3453. AEndValue: TPasExpr): TPasImplForLoop;
  3454. begin
  3455. Result := TPasImplForLoop.Create('', Self);
  3456. Result.Variable := AVar;
  3457. Result.StartExpr := AStartValue;
  3458. AStartValue.Parent := Result;
  3459. Result.EndExpr := AEndValue;
  3460. AEndValue.Parent := Result;
  3461. AddElement(Result);
  3462. end;
  3463. function TPasImplBlock.AddForLoop(AVarName: TPasExpr; AStartValue,
  3464. AEndValue: TPasExpr; ADownTo: Boolean): TPasImplForLoop;
  3465. begin
  3466. Result := TPasImplForLoop.Create('', Self);
  3467. Result.VariableName := AVarName;
  3468. Result.StartExpr := AStartValue;
  3469. AStartValue.Parent := Result;
  3470. Result.EndExpr := AEndValue;
  3471. AEndValue.Parent := Result;
  3472. if ADownto then
  3473. Result.Looptype := ltDown;
  3474. AddElement(Result);
  3475. end;
  3476. function TPasImplBlock.AddTry: TPasImplTry;
  3477. begin
  3478. Result := TPasImplTry.Create('', Self);
  3479. AddElement(Result);
  3480. end;
  3481. function TPasImplBlock.AddExceptOn(const VarName, TypeName: TPasTreeString
  3482. ): TPasImplExceptOn;
  3483. begin
  3484. Result:=AddExceptOn(VarName,TPasUnresolvedTypeRef.Create(TypeName,nil));
  3485. end;
  3486. function TPasImplBlock.AddExceptOn(const VarName: TPasTreeString; VarType: TPasType
  3487. ): TPasImplExceptOn;
  3488. var
  3489. V: TPasVariable;
  3490. begin
  3491. V:=TPasVariable.Create(VarName,nil);
  3492. V.VarType:=VarType;
  3493. if VarType.Parent=nil then
  3494. VarType.Parent:=V;
  3495. Result:=AddExceptOn(V);
  3496. end;
  3497. function TPasImplBlock.AddExceptOn(const VarEl: TPasVariable): TPasImplExceptOn;
  3498. begin
  3499. Result:=TPasImplExceptOn.Create('',Self);
  3500. Result.VarEl:=VarEl;
  3501. VarEl.Parent:=Result;
  3502. Result.TypeEl:=VarEl.VarType;
  3503. AddElement(Result);
  3504. end;
  3505. function TPasImplBlock.AddExceptOn(const TypeEl: TPasType): TPasImplExceptOn;
  3506. begin
  3507. Result:=TPasImplExceptOn.Create('',Self);
  3508. Result.TypeEl:=TypeEl;
  3509. if TypeEl.Parent=nil then
  3510. TypeEl.Parent:=Result;
  3511. AddElement(Result);
  3512. end;
  3513. function TPasImplBlock.AddRaise: TPasImplRaise;
  3514. begin
  3515. Result:=TPasImplRaise.Create('',Self);
  3516. AddElement(Result);
  3517. end;
  3518. function TPasImplBlock.AddLabelMark(const Id: TPasTreeString): TPasImplLabelMark;
  3519. begin
  3520. Result:=TPasImplLabelMark.Create('', Self);
  3521. Result.LabelId:=Id;
  3522. AddElement(Result);
  3523. end;
  3524. function TPasImplBlock.AddAssign(Left,Right:TPasExpr):TPasImplAssign;
  3525. begin
  3526. Result:=TPasImplAssign.Create('', Self);
  3527. Result.Left:=Left;
  3528. Left.Parent:=Result;
  3529. Result.Right:=Right;
  3530. Right.Parent:=Result;
  3531. AddElement(Result);
  3532. end;
  3533. function TPasImplBlock.AddSimple(Expr:TPasExpr):TPasImplSimple;
  3534. begin
  3535. Result:=TPasImplSimple.Create('', Self);
  3536. Result.Expr:=Expr;
  3537. Expr.Parent:=Result;
  3538. AddElement(Result);
  3539. end;
  3540. function TPasImplBlock.CloseOnSemicolon: boolean;
  3541. begin
  3542. Result:=false;
  3543. end;
  3544. procedure TPasImplBlock.ForEachCall(const aMethodCall: TOnForEachPasElement;
  3545. const Arg: Pointer);
  3546. var
  3547. i: Integer;
  3548. begin
  3549. inherited ForEachCall(aMethodCall, Arg);
  3550. for i:=0 to Elements.Count-1 do
  3551. ForEachChildCall(aMethodCall,Arg,TPasElement(Elements[i]),false);
  3552. end;
  3553. { ---------------------------------------------------------------------
  3554. ---------------------------------------------------------------------}
  3555. function TPasModule.GetDeclaration(full : boolean): TPasTreeString;
  3556. begin
  3557. Result := 'Unit ' + SafeName;
  3558. if full then ;
  3559. end;
  3560. procedure TPasModule.ForEachCall(const aMethodCall: TOnForEachPasElement;
  3561. const Arg: Pointer);
  3562. begin
  3563. inherited ForEachCall(aMethodCall, Arg);
  3564. ForEachChildCall(aMethodCall,Arg,InterfaceSection,false);
  3565. ForEachChildCall(aMethodCall,Arg,ImplementationSection,false);
  3566. ForEachChildCall(aMethodCall,Arg,InitializationSection,false);
  3567. ForEachChildCall(aMethodCall,Arg,FinalizationSection,false);
  3568. end;
  3569. function TPasResString.GetDeclaration(full: Boolean): TPasTreeString;
  3570. begin
  3571. Result:=Expr.GetDeclaration(true);
  3572. If Full Then
  3573. begin
  3574. Result:=SafeName+' = '+Result;
  3575. ProcessHints(False,Result);
  3576. end;
  3577. end;
  3578. procedure TPasResString.ForEachCall(const aMethodCall: TOnForEachPasElement;
  3579. const Arg: Pointer);
  3580. begin
  3581. inherited ForEachCall(aMethodCall, Arg);
  3582. ForEachChildCall(aMethodCall,Arg,Expr,false);
  3583. end;
  3584. procedure TPasResString.FreeChildren(Prepare: boolean);
  3585. begin
  3586. Expr:=TPasExpr(FreeChild(Expr,Prepare));
  3587. inherited FreeChildren(Prepare);
  3588. end;
  3589. function TPasPointerType.GetDeclaration(full: Boolean): TPasTreeString;
  3590. begin
  3591. Result:='^'+DestType.SafeName;
  3592. If Full then
  3593. begin
  3594. Result:=SafeName+' = '+Result;
  3595. ProcessHints(False,Result);
  3596. end;
  3597. end;
  3598. procedure TPasPointerType.ForEachCall(const aMethodCall: TOnForEachPasElement;
  3599. const Arg: Pointer);
  3600. begin
  3601. inherited ForEachCall(aMethodCall, Arg);
  3602. ForEachChildCall(aMethodCall,Arg,DestType,true);
  3603. end;
  3604. procedure TPasPointerType.ClearTypeReferences(aType: TPasElement);
  3605. begin
  3606. if DestType=aType then
  3607. DestType:=nil;
  3608. end;
  3609. function TPasAliasType.GetDeclaration(full: Boolean): TPasTreeString;
  3610. begin
  3611. Result:=DestType.SafeName;
  3612. If Full then
  3613. Result:=FixTypeDecl(Result);
  3614. end;
  3615. procedure TPasAliasType.ForEachCall(const aMethodCall: TOnForEachPasElement;
  3616. const Arg: Pointer);
  3617. begin
  3618. inherited ForEachCall(aMethodCall, Arg);
  3619. ForEachChildCall(aMethodCall,Arg,DestType,true);
  3620. ForEachChildCall(aMethodCall,Arg,Expr,false);
  3621. end;
  3622. procedure TPasAliasType.ClearTypeReferences(aType: TPasElement);
  3623. begin
  3624. if DestType=aType then
  3625. DestType:=nil;
  3626. end;
  3627. function TPasClassOfType.GetDeclaration (full : boolean) : TPasTreeString;
  3628. begin
  3629. Result:='class of '+DestType.SafeName;
  3630. If Full then
  3631. Result:=FixTypeDecl(Result);
  3632. end;
  3633. function TPasRangeType.GetDeclaration (full : boolean) : TPasTreeString;
  3634. begin
  3635. Result:=RangeStart+'..'+RangeEnd;
  3636. If Full then
  3637. Result:=FixTypeDecl(Result);
  3638. end;
  3639. procedure TPasRangeType.ForEachCall(const aMethodCall: TOnForEachPasElement;
  3640. const Arg: Pointer);
  3641. begin
  3642. inherited ForEachCall(aMethodCall, Arg);
  3643. ForEachChildCall(aMethodCall,Arg,RangeExpr,false);
  3644. end;
  3645. procedure TPasRangeType.FreeChildren(Prepare: boolean);
  3646. begin
  3647. RangeExpr:=TBinaryExpr(FreeChild(RangeExpr,Prepare));
  3648. inherited FreeChildren(Prepare);
  3649. end;
  3650. function TPasRangeType.RangeStart: TPasTreeString;
  3651. begin
  3652. Result:=RangeExpr.Left.GetDeclaration(False);
  3653. end;
  3654. function TPasRangeType.RangeEnd: TPasTreeString;
  3655. begin
  3656. Result:=RangeExpr.Right.GetDeclaration(False);
  3657. end;
  3658. function TPasArrayType.GetDeclaration (full : boolean) : TPasTreeString;
  3659. begin
  3660. Result:='Array';
  3661. if Full then
  3662. begin
  3663. if GenericTemplateTypes<>nil then
  3664. Result:=SafeName+GenericTemplateTypesAsString(GenericTemplateTypes)+' = '+Result
  3665. else
  3666. Result:=SafeName+' = '+Result;
  3667. end;
  3668. If (IndexRange<>'') then
  3669. Result:=Result+'['+IndexRange+']';
  3670. Result:=Result+' of ';
  3671. If IsPacked then
  3672. Result := 'packed '+Result; // 12/04/04 Dave - Added
  3673. If Assigned(Eltype) then
  3674. Result:=Result+ElType.SafeName
  3675. else
  3676. Result:=Result+'const';
  3677. end;
  3678. function TPasArrayType.IsGenericArray: Boolean;
  3679. begin
  3680. Result:=GenericTemplateTypes<>nil;
  3681. end;
  3682. function TPasArrayType.IsPacked: Boolean;
  3683. begin
  3684. Result:=PackMode=pmPacked;
  3685. end;
  3686. procedure TPasArrayType.AddRange(Range: TPasExpr);
  3687. var
  3688. i: Integer;
  3689. begin
  3690. i:=Length(Ranges);
  3691. SetLength(Ranges, i+1);
  3692. Ranges[i]:=Range;
  3693. end;
  3694. function TPasFileType.GetDeclaration (full : boolean) : TPasTreeString;
  3695. begin
  3696. Result:='File';
  3697. If Assigned(Eltype) then
  3698. Result:=Result+' of '+ElType.SafeName;
  3699. If Full Then
  3700. Result:=FixTypeDecl(Result);
  3701. end;
  3702. procedure TPasFileType.ForEachCall(const aMethodCall: TOnForEachPasElement;
  3703. const Arg: Pointer);
  3704. begin
  3705. inherited ForEachCall(aMethodCall, Arg);
  3706. ForEachChildCall(aMethodCall,Arg,ElType,true);
  3707. end;
  3708. function TPasEnumType.GetDeclaration (full : boolean) : TPasTreeString;
  3709. Var
  3710. S : TStringList;
  3711. begin
  3712. S:=TStringList.Create;
  3713. Try
  3714. If Full and (Name<>'') then
  3715. S.Add(SafeName+' = (')
  3716. else
  3717. S.Add('(');
  3718. GetEnumNames(S);
  3719. S[S.Count-1]:=S[S.Count-1]+')';
  3720. If Full then
  3721. Result:=IndentStrings(S,Length(SafeName)+4)
  3722. else
  3723. Result:=IndentStrings(S,1);
  3724. if Full then
  3725. ProcessHints(False,Result);
  3726. finally
  3727. S.Free;
  3728. end;
  3729. end;
  3730. procedure TPasSetType.FreeChildren(Prepare: boolean);
  3731. begin
  3732. EnumType:=TPasTypeRef(FreeChild(EnumType,Prepare));
  3733. inherited FreeChildren(Prepare);
  3734. end;
  3735. procedure TPasSetType.ClearTypeReferences(aType: TPasElement);
  3736. begin
  3737. if EnumType=aType then
  3738. EnumType:=nil;
  3739. end;
  3740. function TPasSetType.GetDeclaration (full : boolean) : TPasTreeString;
  3741. Var
  3742. S : TStringList;
  3743. i : Integer;
  3744. begin
  3745. If (EnumType is TPasEnumType) and (EnumType.Name='') then
  3746. begin
  3747. S:=TStringList.Create;
  3748. Try
  3749. If Full and (Name<>'') then
  3750. S.Add(SafeName+'= Set of (')
  3751. else
  3752. S.Add('Set of (');
  3753. TPasEnumType(EnumType).GetEnumNames(S);
  3754. S[S.Count-1]:=S[S.Count-1]+')';
  3755. I:=Pos('(',S[0]);
  3756. Result:=IndentStrings(S,i);
  3757. finally
  3758. S.Free;
  3759. end;
  3760. end
  3761. else
  3762. begin
  3763. Result:='Set of '+EnumType.SafeName;
  3764. If Full then
  3765. Result:=SafeName+' = '+Result;
  3766. end;
  3767. If Full then
  3768. ProcessHints(False,Result);
  3769. end;
  3770. procedure TPasSetType.ForEachCall(const aMethodCall: TOnForEachPasElement;
  3771. const Arg: Pointer);
  3772. begin
  3773. inherited ForEachCall(aMethodCall, Arg);
  3774. ForEachChildCall(aMethodCall,Arg,EnumType,true);
  3775. end;
  3776. { TPasMembersType }
  3777. constructor TPasMembersType.Create(const AName: TPasTreeString; AParent: TPasElement);
  3778. begin
  3779. inherited Create(AName, AParent);
  3780. PackMode:=pmNone;
  3781. Members := TFPList.Create;
  3782. GenericTemplateTypes:=TFPList.Create;
  3783. end;
  3784. destructor TPasMembersType.Destroy;
  3785. begin
  3786. FreeAndNil(GenericTemplateTypes);
  3787. FreeAndNil(Members);
  3788. inherited Destroy;
  3789. end;
  3790. procedure TPasMembersType.FreeChildren(Prepare: boolean);
  3791. begin
  3792. FreeChildList(GenericTemplateTypes,Prepare);
  3793. FreeChildList(Members,Prepare);
  3794. inherited FreeChildren(Prepare);
  3795. end;
  3796. function TPasMembersType.IsPacked: Boolean;
  3797. begin
  3798. Result:=(PackMode <> pmNone);
  3799. end;
  3800. function TPasMembersType.IsBitPacked: Boolean;
  3801. begin
  3802. Result:=(PackMode=pmBitPacked)
  3803. end;
  3804. procedure TPasMembersType.ForEachCall(const aMethodCall: TOnForEachPasElement;
  3805. const Arg: Pointer);
  3806. var
  3807. i: Integer;
  3808. begin
  3809. inherited ForEachCall(aMethodCall, Arg);
  3810. for i:=0 to Members.Count-1 do
  3811. ForEachChildCall(aMethodCall,Arg,TPasElement(Members[i]),false);
  3812. end;
  3813. { TPasRecordType }
  3814. procedure TPasRecordType.GetMembers(S: TStrings);
  3815. Var
  3816. T : TStringList;
  3817. temp : TPasTreeString;
  3818. I,J : integer;
  3819. E : TPasElement;
  3820. CV : TPasMemberVisibility ;
  3821. begin
  3822. T:=TStringList.Create;
  3823. try
  3824. CV:=visDefault;
  3825. For I:=0 to Members.Count-1 do
  3826. begin
  3827. E:=TPasElement(Members[i]);
  3828. if E.Visibility<>CV then
  3829. begin
  3830. CV:=E.Visibility;
  3831. if CV<>visDefault then
  3832. S.Add(VisibilityNames[CV]);
  3833. end;
  3834. Temp:=E.GetDeclaration(True);
  3835. If E is TPasProperty then
  3836. Temp:='property '+Temp;
  3837. If Pos(LineEnding,Temp)>0 then
  3838. begin
  3839. T.Text:=Temp;
  3840. For J:=0 to T.Count-1 do
  3841. if J=T.Count-1 then
  3842. S.Add(' '+T[J]+';')
  3843. else
  3844. S.Add(' '+T[J])
  3845. end
  3846. else
  3847. S.Add(' '+Temp+';');
  3848. end;
  3849. if Variants<>nil then
  3850. begin
  3851. temp:='case ';
  3852. if (VariantEl is TPasVariable) then
  3853. temp:=Temp+VariantEl.Name+' : '+TPasVariable(VariantEl).VarType.Name
  3854. else if (VariantEl<>Nil) then
  3855. temp:=temp+VariantEl.Name;
  3856. S.Add(temp+' of');
  3857. T.Clear;
  3858. For I:=0 to Variants.Count-1 do
  3859. T.Add(TPasVariant(Variants[i]).GetDeclaration(True));
  3860. S.AddStrings(T);
  3861. end;
  3862. finally
  3863. T.Free;
  3864. end;
  3865. end;
  3866. function TPasRecordType.GetDeclaration (full : boolean) : TPasTreeString;
  3867. Var
  3868. S : TStringList;
  3869. temp : TPasTreeString;
  3870. begin
  3871. S:=TStringList.Create;
  3872. Try
  3873. Temp:='record';
  3874. If IsPacked then
  3875. if IsBitPacked then
  3876. Temp:='bitpacked '+Temp
  3877. else
  3878. Temp:='packed '+Temp;
  3879. If Full and (Name<>'') then
  3880. begin
  3881. if GenericTemplateTypes.Count>0 then
  3882. Temp:=SafeName+GenericTemplateTypesAsString(GenericTemplateTypes)+' = '+Temp
  3883. else
  3884. Temp:=SafeName+' = '+Temp;
  3885. end;
  3886. S.Add(Temp);
  3887. GetMembers(S);
  3888. S.Add('end');
  3889. Result:=S.Text;
  3890. if Full then
  3891. ProcessHints(False, Result);
  3892. finally
  3893. S.free;
  3894. end;
  3895. end;
  3896. procedure TPasRecordType.ForEachCall(const aMethodCall: TOnForEachPasElement;
  3897. const Arg: Pointer);
  3898. var
  3899. i: Integer;
  3900. begin
  3901. inherited ForEachCall(aMethodCall, Arg);
  3902. ForEachChildCall(aMethodCall,Arg,VariantEl,true);
  3903. if Variants<>nil then
  3904. for i:=0 to Variants.Count-1 do
  3905. ForEachChildCall(aMethodCall,Arg,TPasElement(Variants[i]),false);
  3906. end;
  3907. function TPasRecordType.IsAdvancedRecord: Boolean;
  3908. Var
  3909. I : Integer;
  3910. Member: TPasElement;
  3911. begin
  3912. Result:=False;
  3913. For I:=0 to Members.Count-1 do
  3914. begin
  3915. Member:=TPasElement(Members[i]);
  3916. if (Member.Visibility<>visPublic) then
  3917. Exit(True);
  3918. if (Member.ClassType<>TPasVariable) then
  3919. Exit(True);
  3920. end;
  3921. end;
  3922. procedure TPasProcedureType.GetArguments(List : TStrings);
  3923. Var
  3924. T : TPasTreeString;
  3925. I : Integer;
  3926. begin
  3927. For I:=0 to Args.Count-1 do
  3928. begin
  3929. T:=AccessNames[TPasArgument(Args[i]).Access];
  3930. T:=T+TPasArgument(Args[i]).GetDeclaration(True);
  3931. If I=0 then
  3932. T:='('+T;
  3933. If I<Args.Count-1 then
  3934. List.Add(T+'; ')
  3935. else
  3936. List.Add(T+')');
  3937. end;
  3938. end;
  3939. function TPasProcedureType.GetDeclaration (full : boolean) : TPasTreeString;
  3940. Var
  3941. S : TStringList;
  3942. begin
  3943. S:=TStringList.Create;
  3944. Try
  3945. If Full then
  3946. S.Add(Format('%s = ',[SafeName]));
  3947. S.Add(TypeName);
  3948. GetArguments(S);
  3949. If IsOfObject then
  3950. S.Add(' of object')
  3951. else if IsNested then
  3952. S.Add(' is nested');
  3953. If Full then
  3954. Result:=IndentStrings(S,Length(S[0])+Length(S[1])+1)
  3955. else
  3956. Result:=IndentStrings(S,Length(S[0])+1);
  3957. finally
  3958. S.Free;
  3959. end;
  3960. end;
  3961. function TPasFunctionType.GetDeclaration(Full: boolean): TPasTreeString;
  3962. Var
  3963. S : TStringList;
  3964. T : TPasTreeString;
  3965. begin
  3966. S:=TStringList.Create;
  3967. Try
  3968. If Full then
  3969. S.Add(Format('%s = ',[SafeName]));
  3970. S.Add(TypeName);
  3971. GetArguments(S);
  3972. If Assigned(ResultEl) then
  3973. begin
  3974. T:=' : ';
  3975. If (ResultEl.ResultType.Name<>'') then
  3976. T:=T+ResultEl.ResultType.SafeName
  3977. else
  3978. T:=T+ResultEl.ResultType.GetDeclaration(False);
  3979. S.Add(T);
  3980. end;
  3981. If IsOfObject then
  3982. S.Add(' of object');
  3983. If Full then
  3984. Result:=IndentStrings(S,Length(S[0])+Length(S[1])+1)
  3985. else
  3986. Result:=IndentStrings(S,Length(S[0])+1);
  3987. finally
  3988. S.Free;
  3989. end;
  3990. end;
  3991. procedure TPasFunctionType.ForEachCall(const aMethodCall: TOnForEachPasElement;
  3992. const Arg: Pointer);
  3993. begin
  3994. inherited ForEachCall(aMethodCall, Arg);
  3995. ForEachChildCall(aMethodCall,Arg,ResultEl,false);
  3996. end;
  3997. function TPasVariable.GetDeclaration (full : boolean) : TPasTreeString;
  3998. Const
  3999. Seps : Array[Boolean] of Char = ('=',':');
  4000. begin
  4001. If Assigned(VarType) then
  4002. begin
  4003. If VarType.Name='' then
  4004. Result:=VarType.GetDeclaration(False)
  4005. else
  4006. Result:=VarType.SafeName;
  4007. Result:=Result+Modifiers;
  4008. if (Value<>'') then
  4009. Result:=Result+' = '+Value;
  4010. end
  4011. else
  4012. Result:=Value;
  4013. If Full then
  4014. begin
  4015. Result:=SafeName+' '+Seps[Assigned(VarType)]+' '+Result;
  4016. Result:=Result+HintsString;
  4017. end;
  4018. end;
  4019. procedure TPasVariable.ForEachCall(const aMethodCall: TOnForEachPasElement;
  4020. const Arg: Pointer);
  4021. begin
  4022. inherited ForEachCall(aMethodCall, Arg);
  4023. ForEachChildCall(aMethodCall,Arg,VarType,true);
  4024. ForEachChildCall(aMethodCall,Arg,Expr,false);
  4025. ForEachChildCall(aMethodCall,Arg,LibraryName,false);
  4026. ForEachChildCall(aMethodCall,Arg,ExportName,false);
  4027. ForEachChildCall(aMethodCall,Arg,AbsoluteExpr,false);
  4028. end;
  4029. procedure TPasVariable.ClearTypeReferences(aType: TPasElement);
  4030. begin
  4031. if VarType=aType then
  4032. VarType:=nil;
  4033. end;
  4034. function TPasVariable.Value: TPasTreeString;
  4035. begin
  4036. If Assigned(Expr) then
  4037. Result:=Expr.GetDeclaration(True)
  4038. else
  4039. Result:='';
  4040. end;
  4041. function TPasProperty.GetDeclaration (full : boolean) : TPasTreeString;
  4042. Var
  4043. S : TPasTreeString;
  4044. I : Integer;
  4045. begin
  4046. Result:='';
  4047. If Assigned(VarType) then
  4048. begin
  4049. If VarType.Name='' then
  4050. Result:=VarType.GetDeclaration(False)
  4051. else
  4052. Result:=VarType.SafeName;
  4053. end
  4054. else if Assigned(Expr) then
  4055. Result:=Expr.GetDeclaration(True);
  4056. S:='';
  4057. If Assigned(Args) and (Args.Count>0) then
  4058. begin
  4059. For I:=0 to Args.Count-1 do
  4060. begin
  4061. If (S<>'') then
  4062. S:=S+';';
  4063. S:=S+TPasElement(Args[i]).GetDeclaration(true);
  4064. end;
  4065. end;
  4066. If S<>'' then
  4067. S:='['+S+']'
  4068. else
  4069. S:=' ';
  4070. If Full then
  4071. begin
  4072. Result:=SafeName+S+': '+Result;
  4073. If (ImplementsName<>'') then
  4074. Result:=Result+' implements '+EscapeKeyWord(ImplementsName);
  4075. end;
  4076. If IsDefault then
  4077. Result:=Result+'; default';
  4078. ProcessHints(True, Result);
  4079. end;
  4080. procedure TPasProperty.ForEachCall(const aMethodCall: TOnForEachPasElement;
  4081. const Arg: Pointer);
  4082. var
  4083. i: Integer;
  4084. begin
  4085. inherited ForEachCall(aMethodCall, Arg);
  4086. ForEachChildCall(aMethodCall,Arg,IndexExpr,false);
  4087. for i:=0 to Args.Count-1 do
  4088. ForEachChildCall(aMethodCall,Arg,TPasElement(Args[i]),false);
  4089. ForEachChildCall(aMethodCall,Arg,ReadAccessor,false);
  4090. ForEachChildCall(aMethodCall,Arg,WriteAccessor,false);
  4091. for i:=0 to length(Implements)-1 do
  4092. ForEachChildCall(aMethodCall,Arg,Implements[i],false);
  4093. ForEachChildCall(aMethodCall,Arg,StoredAccessor,false);
  4094. ForEachChildCall(aMethodCall,Arg,DefaultExpr,false);
  4095. end;
  4096. function TPasProperty.ResolvedType: TPasType;
  4097. Function GC(P : TPasProperty) : TPasClassType;
  4098. begin
  4099. if Assigned(P) and Assigned(P.Parent) and (P.Parent is TPasClassType) then
  4100. Result:=P.Parent as TPasClassType
  4101. else
  4102. Result:=Nil;
  4103. end;
  4104. Var
  4105. P : TPasProperty;
  4106. C : TPasClassType;
  4107. begin
  4108. Result:=FResolvedType;
  4109. if Result=Nil then
  4110. Result:=VarType;
  4111. P:=Self;
  4112. While (Result=Nil) and (P<>Nil) do
  4113. begin
  4114. C:=GC(P);
  4115. // Writeln('Looking for ',Name,' in ancestor ',C.Name);
  4116. P:=TPasProperty(C.FindMemberInAncestors(TPasProperty,Name));
  4117. if Assigned(P) then
  4118. begin
  4119. // Writeln('Found ',Name,' in ancestor : ',P.Name);
  4120. Result:=P.ResolvedType;
  4121. end
  4122. end;
  4123. end;
  4124. function TPasProperty.IndexValue: TPasTreeString;
  4125. begin
  4126. If Assigned(IndexExpr) then
  4127. Result:=IndexExpr.GetDeclaration(true)
  4128. else
  4129. Result:='';
  4130. end;
  4131. function TPasProperty.DefaultValue: TPasTreeString;
  4132. begin
  4133. If Assigned(DefaultExpr) then
  4134. Result:=DefaultExpr.GetDeclaration(true)
  4135. else
  4136. Result:='';
  4137. end;
  4138. procedure TPasProcedure.GetModifiers(List: TStrings);
  4139. Procedure DoAdd(B : Boolean; S : TPasTreeString);
  4140. begin
  4141. if B then
  4142. List.add('; '+S);
  4143. end;
  4144. begin
  4145. Doadd(IsVirtual,' Virtual');
  4146. DoAdd(IsDynamic,' Dynamic');
  4147. DoAdd(IsOverride,' Override');
  4148. DoAdd(IsAbstract,' Abstract');
  4149. DoAdd(IsOverload,' Overload');
  4150. DoAdd(IsReintroduced,' Reintroduce');
  4151. DoAdd(IsStatic,' Static');
  4152. DoAdd(IsMessage,' Message');
  4153. end;
  4154. procedure TPasProcedure.ForEachCall(const aMethodCall: TOnForEachPasElement;
  4155. const Arg: Pointer);
  4156. var
  4157. i, j: Integer;
  4158. Templates: TFPList;
  4159. begin
  4160. inherited ForEachCall(aMethodCall, Arg);
  4161. if NameParts<>nil then
  4162. for i:=0 to NameParts.Count-1 do
  4163. begin
  4164. Templates:=TProcedureNamePart(NameParts[i]).Templates;
  4165. if Templates<>nil then
  4166. for j:=0 to Templates.Count-1 do
  4167. ForEachChildCall(aMethodCall,Arg,TPasElement(Templates[j]),false);
  4168. end;
  4169. ForEachChildCall(aMethodCall,Arg,ProcType,false);
  4170. ForEachChildCall(aMethodCall,Arg,PublicName,false);
  4171. ForEachChildCall(aMethodCall,Arg,LibraryExpr,false);
  4172. ForEachChildCall(aMethodCall,Arg,LibrarySymbolName,false);
  4173. ForEachChildCall(aMethodCall,Arg,MessageExpr,false);
  4174. ForEachChildCall(aMethodCall,Arg,Body,false);
  4175. end;
  4176. procedure TPasProcedure.AddModifier(AModifier: TProcedureModifier);
  4177. begin
  4178. Include(FModifiers,AModifier);
  4179. end;
  4180. function TPasProcedure.CanParseImplementation: Boolean;
  4181. begin
  4182. Result:=not HasNoImplementation
  4183. and ((Parent is TImplementationSection) or (Parent is TProcedureBody));
  4184. end;
  4185. function TPasProcedure.HasNoImplementation: Boolean;
  4186. begin
  4187. Result:=IsExternal or IsForward or IsInternProc;
  4188. end;
  4189. function TPasProcedure.IsVirtual: Boolean;
  4190. begin
  4191. Result:=pmVirtual in FModifiers;
  4192. end;
  4193. function TPasProcedure.IsDynamic: Boolean;
  4194. begin
  4195. Result:=pmDynamic in FModifiers;
  4196. end;
  4197. function TPasProcedure.IsAbstract: Boolean;
  4198. begin
  4199. Result:=pmAbstract in FModifiers;
  4200. end;
  4201. function TPasProcedure.IsOverride: Boolean;
  4202. begin
  4203. Result:=pmOverride in FModifiers;
  4204. end;
  4205. function TPasProcedure.IsExported: Boolean;
  4206. begin
  4207. Result:=pmExport in FModifiers;
  4208. end;
  4209. function TPasProcedure.IsExternal: Boolean;
  4210. begin
  4211. Result:=pmExternal in FModifiers;
  4212. end;
  4213. function TPasProcedure.IsOverload: Boolean;
  4214. begin
  4215. Result:=pmOverload in FModifiers;
  4216. end;
  4217. function TPasProcedure.IsMessage: Boolean;
  4218. begin
  4219. Result:=pmMessage in FModifiers;
  4220. end;
  4221. function TPasProcedure.IsReintroduced: Boolean;
  4222. begin
  4223. Result:=pmReintroduce in FModifiers;
  4224. end;
  4225. function TPasProcedure.IsStatic: Boolean;
  4226. begin
  4227. Result:=ptmStatic in ProcType.Modifiers;
  4228. end;
  4229. function TPasProcedure.IsForward: Boolean;
  4230. begin
  4231. Result:=pmForward in FModifiers;
  4232. end;
  4233. function TPasProcedure.IsCompilerProc: Boolean;
  4234. begin
  4235. Result:=pmCompilerProc in FModifiers;
  4236. end;
  4237. function TPasProcedure.IsInternProc: Boolean;
  4238. begin
  4239. Result:=pmInternProc in FModifiers;
  4240. end;
  4241. function TPasProcedure.IsAssembler: Boolean;
  4242. begin
  4243. Result:=pmAssembler in FModifiers;
  4244. end;
  4245. function TPasProcedure.IsAsync: Boolean;
  4246. begin
  4247. Result:=ProcType.IsAsync;
  4248. end;
  4249. function TPasProcedure.GetProcTypeEnum: TProcType;
  4250. begin
  4251. Result:=ptProcedure;
  4252. end;
  4253. procedure TPasProcedure.SetNameParts(Parts: TProcedureNameParts);
  4254. var
  4255. i, j: Integer;
  4256. El: TPasElement;
  4257. begin
  4258. if NameParts<>nil then
  4259. FreeProcNameParts(NameParts);
  4260. NameParts:=TFPList.Create;
  4261. NameParts.Assign(Parts);
  4262. Parts.Clear;
  4263. for i:=0 to NameParts.Count-1 do
  4264. with TProcedureNamePart(NameParts[i]) do
  4265. if Templates<>nil then
  4266. for j:=0 to Templates.Count-1 do
  4267. begin
  4268. El:=TPasElement(Templates[j]);
  4269. El.Parent:=Self;
  4270. end;
  4271. end;
  4272. function TPasProcedure.GetDeclaration(full: Boolean): TPasTreeString;
  4273. Var
  4274. S : TStringList;
  4275. T: TPasTreeString;
  4276. i: Integer;
  4277. begin
  4278. S:=TStringList.Create;
  4279. try
  4280. If Full then
  4281. begin
  4282. T:=TypeName;
  4283. if NameParts<>nil then
  4284. begin
  4285. T:=T+' ';
  4286. for i:=0 to NameParts.Count-1 do
  4287. begin
  4288. if i>0 then
  4289. T:=T+'.';
  4290. with TProcedureNamePart(NameParts[i]) do
  4291. begin
  4292. T:=T+Name;
  4293. if Templates<>nil then
  4294. T:=T+GenericTemplateTypesAsString(Templates);
  4295. end;
  4296. end;
  4297. end
  4298. else if Name<>'' then
  4299. T:=T+' '+SafeName;
  4300. S.Add(T);
  4301. end;
  4302. ProcType.GetArguments(S);
  4303. If (ProcType is TPasFunctionType)
  4304. and Assigned(TPasFunctionType(Proctype).ResultEl) then
  4305. With TPasFunctionType(ProcType).ResultEl.ResultType do
  4306. begin
  4307. T:=' : ';
  4308. If (Name<>'') then
  4309. T:=T+SafeName
  4310. else
  4311. T:=T+GetDeclaration(False);
  4312. S.Add(T);
  4313. end;
  4314. GetModifiers(S);
  4315. Result:=IndentStrings(S,Length(S[0]));
  4316. finally
  4317. S.Free;
  4318. end;
  4319. end;
  4320. function TPasFunction.TypeName: TPasTreeString;
  4321. begin
  4322. Result:='function';
  4323. end;
  4324. function TPasFunction.GetProcTypeEnum: TProcType;
  4325. begin
  4326. Result:=ptFunction;
  4327. end;
  4328. function TPasOperator.GetOperatorDeclaration(Full : Boolean) : TPasTreeString;
  4329. begin
  4330. if Full then
  4331. begin
  4332. Result:=FullPath;
  4333. if (Result<>'') then
  4334. Result:=Result+'.';
  4335. end
  4336. else
  4337. Result:='';
  4338. if TokenBased then
  4339. Result:=Result+TypeName+' '+OperatorTypeToToken(OperatorType)
  4340. else
  4341. Result:=Result+TypeName+' '+OperatorTypeToOperatorName(OperatorType);
  4342. end;
  4343. function TPasOperator.GetDeclaration (full : boolean) : TPasTreeString;
  4344. Var
  4345. S : TStringList;
  4346. T : TPasTreeString;
  4347. begin
  4348. S:=TStringList.Create;
  4349. try
  4350. If Full then
  4351. S.Add(GetOperatorDeclaration(Full));
  4352. ProcType.GetArguments(S);
  4353. If Assigned((Proctype as TPasFunctionType).ResultEl) then
  4354. if Assigned(TPasFunctionType(ProcType).ResultEl.ResultType) then
  4355. With TPasFunctionType(ProcType).ResultEl.ResultType do
  4356. begin
  4357. T:=' : ';
  4358. If (Name<>'') then
  4359. T:=T+SafeName
  4360. else
  4361. T:=T+GetDeclaration(False);
  4362. S.Add(T);
  4363. end;
  4364. GetModifiers(S);
  4365. Result:=IndentStrings(S,Length(S[0]));
  4366. finally
  4367. S.Free;
  4368. end;
  4369. end;
  4370. function TPasOperator.TypeName: TPasTreeString;
  4371. begin
  4372. Result:='operator';
  4373. end;
  4374. function TPasOperator.GetProcTypeEnum: TProcType;
  4375. begin
  4376. Result:=ptOperator;
  4377. end;
  4378. function TPasClassProcedure.TypeName: TPasTreeString;
  4379. begin
  4380. Result:='class procedure';
  4381. end;
  4382. function TPasClassProcedure.GetProcTypeEnum: TProcType;
  4383. begin
  4384. Result:=ptClassProcedure;
  4385. end;
  4386. function TPasClassFunction.TypeName: TPasTreeString;
  4387. begin
  4388. Result:='class function';
  4389. end;
  4390. function TPasClassFunction.GetProcTypeEnum: TProcType;
  4391. begin
  4392. Result:=ptClassFunction;
  4393. end;
  4394. function TPasConstructor.TypeName: TPasTreeString;
  4395. begin
  4396. Result:='constructor';
  4397. end;
  4398. function TPasConstructor.GetProcTypeEnum: TProcType;
  4399. begin
  4400. Result:=ptConstructor;
  4401. end;
  4402. function TPasDestructor.TypeName: TPasTreeString;
  4403. begin
  4404. Result:='destructor';
  4405. end;
  4406. function TPasDestructor.GetProcTypeEnum: TProcType;
  4407. begin
  4408. Result:=ptDestructor;
  4409. end;
  4410. { TPassTreeVisitor }
  4411. procedure TPassTreeVisitor.Visit(obj: TPasElement);
  4412. begin
  4413. // Needs to be implemented by descendents.
  4414. if Obj=nil then ;
  4415. end;
  4416. { TPasSection }
  4417. constructor TPasSection.Create(const AName: TPasTreeString; AParent: TPasElement);
  4418. begin
  4419. inherited Create(AName, AParent);
  4420. UsesList := TFPList.Create;
  4421. end;
  4422. destructor TPasSection.Destroy;
  4423. begin
  4424. FreeAndNil(UsesList);
  4425. {$IFDEF VerbosePasTreeMem}writeln('TPasSection.Destroy inherited');{$ENDIF}
  4426. inherited Destroy;
  4427. {$IFDEF VerbosePasTreeMem}writeln('TPasSection.Destroy END');{$ENDIF}
  4428. end;
  4429. procedure TPasSection.FreeChildren(Prepare: boolean);
  4430. var
  4431. i: Integer;
  4432. begin
  4433. FreeChildList(UsesList,Prepare);
  4434. for i := 0 to high(UsesClause) do
  4435. UsesClause[i]:=TPasUsesUnit(FreeChild(UsesClause[i],Prepare));
  4436. inherited FreeChildren(Prepare);
  4437. end;
  4438. function TPasSection.AddUnitToUsesList(const AUnitName: TPasTreeString;
  4439. aName: TPasExpr; InFilename: TPrimitiveExpr; aModule: TPasElement;
  4440. UsesUnit: TPasUsesUnit): TPasUsesUnit;
  4441. var
  4442. l: Integer;
  4443. begin
  4444. if (InFilename<>nil) and (InFilename.Kind<>pekString) then
  4445. raise EPasTree.Create('Wrong In expression for '+aUnitName);
  4446. if aModule=nil then
  4447. aModule:=TPasUnresolvedUnitRef.Create(AUnitName, Self);
  4448. l:=length(UsesClause);
  4449. SetLength(UsesClause,l+1);
  4450. if UsesUnit=nil then
  4451. begin
  4452. UsesUnit:=TPasUsesUnit.Create(AUnitName,Self);
  4453. if aName<>nil then
  4454. begin
  4455. UsesUnit.SourceFilename:=aName.SourceFilename;
  4456. UsesUnit.SourceLinenumber:=aName.SourceLinenumber;
  4457. end;
  4458. end;
  4459. UsesClause[l]:=UsesUnit;
  4460. UsesUnit.Expr:=aName;
  4461. UsesUnit.InFilename:=InFilename;
  4462. UsesUnit.Module:=aModule;
  4463. Result:=UsesUnit;
  4464. UsesList.Add(aModule);
  4465. end;
  4466. function TPasSection.ElementTypeName: TPasTreeString;
  4467. begin
  4468. Result := SPasTreeSection;
  4469. end;
  4470. procedure TPasSection.ForEachCall(const aMethodCall: TOnForEachPasElement;
  4471. const Arg: Pointer);
  4472. var
  4473. i: Integer;
  4474. begin
  4475. inherited ForEachCall(aMethodCall, Arg);
  4476. for i:=0 to length(UsesClause)-1 do
  4477. ForEachChildCall(aMethodCall,Arg,UsesClause[i],false);
  4478. end;
  4479. { TProcedureBody }
  4480. procedure TProcedureBody.FreeChildren(Prepare: boolean);
  4481. begin
  4482. Body:=TPasImplBlock(FreeChild(Body,Prepare));
  4483. inherited FreeChildren(Prepare);
  4484. end;
  4485. procedure TProcedureBody.ForEachCall(const aMethodCall: TOnForEachPasElement;
  4486. const Arg: Pointer);
  4487. begin
  4488. inherited ForEachCall(aMethodCall, Arg);
  4489. ForEachChildCall(aMethodCall,Arg,Body,false);
  4490. end;
  4491. { TPasImplWhileDo }
  4492. procedure TPasImplWhileDo.FreeChildren(Prepare: boolean);
  4493. begin
  4494. ConditionExpr:=TPasExpr(FreeChild(ConditionExpr,Prepare));
  4495. Body:=TPasImplElement(FreeChild(Body,Prepare));
  4496. inherited FreeChildren(Prepare);
  4497. end;
  4498. procedure TPasImplWhileDo.AddElement(Element: TPasImplElement);
  4499. begin
  4500. inherited AddElement(Element);
  4501. if Body=nil then
  4502. begin
  4503. Body:=Element;
  4504. end
  4505. else
  4506. raise EPasTree.Create('TPasImplWhileDo.AddElement body already set');
  4507. end;
  4508. procedure TPasImplWhileDo.ForEachCall(const aMethodCall: TOnForEachPasElement;
  4509. const Arg: Pointer);
  4510. begin
  4511. ForEachChildCall(aMethodCall,Arg,ConditionExpr,false);
  4512. if Elements.IndexOf(Body)<0 then
  4513. ForEachChildCall(aMethodCall,Arg,Body,false);
  4514. inherited ForEachCall(aMethodCall, Arg);
  4515. end;
  4516. function TPasImplWhileDo.Condition: TPasTreeString;
  4517. begin
  4518. If Assigned(ConditionExpr) then
  4519. Result:=ConditionExpr.GetDeclaration(True)
  4520. else
  4521. Result:='';
  4522. end;
  4523. { TPasImplCaseOf }
  4524. procedure TPasImplCaseOf.FreeChildren(Prepare: boolean);
  4525. begin
  4526. CaseExpr:=TPasExpr(FreeChild(CaseExpr,Prepare));
  4527. ElseBranch:=TPasImplCaseElse(FreeChild(ElseBranch,Prepare));
  4528. inherited FreeChildren(Prepare);
  4529. end;
  4530. function TPasImplCaseOf.AddCase(const Expression: TPasExpr
  4531. ): TPasImplCaseStatement;
  4532. begin
  4533. Result:=TPasImplCaseStatement.Create('',Self);
  4534. Result.AddExpression(Expression);
  4535. AddElement(Result);
  4536. end;
  4537. function TPasImplCaseOf.AddElse: TPasImplCaseElse;
  4538. begin
  4539. Result:=TPasImplCaseElse.Create('',Self);
  4540. ElseBranch:=Result;
  4541. AddElement(Result);
  4542. end;
  4543. procedure TPasImplCaseOf.ForEachCall(const aMethodCall: TOnForEachPasElement;
  4544. const Arg: Pointer);
  4545. begin
  4546. ForEachChildCall(aMethodCall,Arg,CaseExpr,false);
  4547. if Elements.IndexOf(ElseBranch)<0 then
  4548. ForEachChildCall(aMethodCall,Arg,ElseBranch,false);
  4549. inherited ForEachCall(aMethodCall, Arg);
  4550. end;
  4551. function TPasImplCaseOf.Expression: TPasTreeString;
  4552. begin
  4553. if Assigned(CaseExpr) then
  4554. Result:=CaseExpr.GetDeclaration(True)
  4555. else
  4556. Result:='';
  4557. end;
  4558. { TPasImplCaseStatement }
  4559. constructor TPasImplCaseStatement.Create(const AName: TPasTreeString;
  4560. AParent: TPasElement);
  4561. begin
  4562. inherited Create(AName, AParent);
  4563. Expressions:=TFPList.Create;
  4564. end;
  4565. destructor TPasImplCaseStatement.Destroy;
  4566. begin
  4567. FreeAndNil(Expressions);
  4568. inherited Destroy;
  4569. end;
  4570. procedure TPasImplCaseStatement.FreeChildren(Prepare: boolean);
  4571. begin
  4572. FreeChildList(Expressions,Prepare);
  4573. Body:=TPasImplElement(FreeChild(Body,Prepare));
  4574. inherited FreeChildren(Prepare);
  4575. end;
  4576. procedure TPasImplCaseStatement.AddElement(Element: TPasImplElement);
  4577. begin
  4578. inherited AddElement(Element);
  4579. if Body=nil then
  4580. begin
  4581. Body:=Element;
  4582. end
  4583. else
  4584. raise EPasTree.Create('TPasImplCaseStatement.AddElement body already set');
  4585. end;
  4586. procedure TPasImplCaseStatement.AddExpression(const Expr: TPasExpr);
  4587. begin
  4588. Expressions.Add(Expr);
  4589. Expr.Parent:=Self;
  4590. end;
  4591. procedure TPasImplCaseStatement.ForEachCall(
  4592. const aMethodCall: TOnForEachPasElement; const Arg: Pointer);
  4593. var
  4594. i: Integer;
  4595. begin
  4596. for i:=0 to Expressions.Count-1 do
  4597. ForEachChildCall(aMethodCall,Arg,TPasElement(Expressions[i]),false);
  4598. if Elements.IndexOf(Body)<0 then
  4599. ForEachChildCall(aMethodCall,Arg,Body,false);
  4600. inherited ForEachCall(aMethodCall, Arg);
  4601. end;
  4602. { TPasImplWithDo }
  4603. constructor TPasImplWithDo.Create(const AName: TPasTreeString; AParent: TPasElement);
  4604. begin
  4605. inherited Create(AName, AParent);
  4606. Expressions:=TFPList.Create;
  4607. end;
  4608. destructor TPasImplWithDo.Destroy;
  4609. begin
  4610. FreeAndNil(Expressions);
  4611. inherited Destroy;
  4612. end;
  4613. procedure TPasImplWithDo.FreeChildren(Prepare: boolean);
  4614. begin
  4615. FreeChildList(Expressions,Prepare);
  4616. Body:=TPasImplElement(FreeChild(Body,Prepare));
  4617. inherited FreeChildren(Prepare);
  4618. end;
  4619. procedure TPasImplWithDo.AddElement(Element: TPasImplElement);
  4620. begin
  4621. inherited AddElement(Element);
  4622. if Body=nil then
  4623. begin
  4624. Body:=Element;
  4625. end
  4626. else
  4627. raise EPasTree.Create('TPasImplWithDo.AddElement body already set');
  4628. end;
  4629. procedure TPasImplWithDo.AddExpression(const Expression: TPasExpr);
  4630. begin
  4631. Expressions.Add(Expression);
  4632. if Expression.Parent=nil then
  4633. Expression.Parent:=Self;
  4634. end;
  4635. procedure TPasImplWithDo.ForEachCall(const aMethodCall: TOnForEachPasElement;
  4636. const Arg: Pointer);
  4637. var
  4638. i: Integer;
  4639. begin
  4640. for i:=0 to Expressions.Count-1 do
  4641. ForEachChildCall(aMethodCall,Arg,TPasElement(Expressions[i]),false);
  4642. if Elements.IndexOf(Body)<0 then
  4643. ForEachChildCall(aMethodCall,Arg,Body,false);
  4644. inherited ForEachCall(aMethodCall, Arg);
  4645. end;
  4646. { TPasInlineVarDeclStatement }
  4647. constructor TPasInlineVarDeclStatement.Create(const aName: TPasTreeString; aParent: TPasElement);
  4648. begin
  4649. inherited Create(aName,aParent);
  4650. Declarations:=TFPList.Create;
  4651. end;
  4652. procedure TPasInlineVarDeclStatement.FreeChildren(Prepare: boolean);
  4653. begin
  4654. FreeChildList(Declarations,Prepare);
  4655. inherited FreeChildren(Prepare);
  4656. end;
  4657. destructor TPasInlineVarDeclStatement.Destroy;
  4658. begin
  4659. inherited Destroy;
  4660. FreeAndNil(Declarations)
  4661. end;
  4662. { TPasImplTry }
  4663. procedure TPasImplTry.FreeChildren(Prepare: boolean);
  4664. begin
  4665. FinallyExcept:=TPasImplTryHandler(FreeChild(FinallyExcept,Prepare));
  4666. ElseBranch:=TPasImplTryExceptElse(FreeChild(ElseBranch,Prepare));
  4667. inherited FreeChildren(Prepare);
  4668. end;
  4669. function TPasImplTry.AddFinally: TPasImplTryFinally;
  4670. begin
  4671. Result:=TPasImplTryFinally.Create('',Self);
  4672. FinallyExcept:=Result;
  4673. end;
  4674. function TPasImplTry.AddExcept: TPasImplTryExcept;
  4675. begin
  4676. Result:=TPasImplTryExcept.Create('',Self);
  4677. FinallyExcept:=Result;
  4678. end;
  4679. function TPasImplTry.AddExceptElse: TPasImplTryExceptElse;
  4680. begin
  4681. Result:=TPasImplTryExceptElse.Create('',Self);
  4682. ElseBranch:=Result;
  4683. end;
  4684. procedure TPasImplTry.ForEachCall(const aMethodCall: TOnForEachPasElement;
  4685. const Arg: Pointer);
  4686. begin
  4687. inherited ForEachCall(aMethodCall, Arg);
  4688. ForEachChildCall(aMethodCall,Arg,FinallyExcept,false);
  4689. ForEachChildCall(aMethodCall,Arg,ElseBranch,false);
  4690. end;
  4691. { TPasImplExceptOn }
  4692. procedure TPasImplExceptOn.FreeChildren(Prepare: boolean);
  4693. begin
  4694. VarEl:=TPasVariable(FreeChild(VarEl,Prepare));
  4695. TypeEl:=TPasType(FreeChild(TypeEl,Prepare));
  4696. Body:=TPasImplElement(FreeChild(Body,Prepare));
  4697. inherited FreeChildren(Prepare);
  4698. end;
  4699. procedure TPasImplExceptOn.AddElement(Element: TPasImplElement);
  4700. begin
  4701. inherited AddElement(Element);
  4702. if Body=nil then
  4703. Body:=Element;
  4704. end;
  4705. procedure TPasImplExceptOn.ForEachCall(const aMethodCall: TOnForEachPasElement;
  4706. const Arg: Pointer);
  4707. begin
  4708. ForEachChildCall(aMethodCall,Arg,VarEl,false);
  4709. ForEachChildCall(aMethodCall,Arg,TypeEl,true);
  4710. if Elements.IndexOf(Body)<0 then
  4711. ForEachChildCall(aMethodCall,Arg,Body,false);
  4712. inherited ForEachCall(aMethodCall, Arg);
  4713. end;
  4714. procedure TPasImplExceptOn.ClearTypeReferences(aType: TPasElement);
  4715. begin
  4716. if TypeEl=aType then
  4717. TypeEl:=nil;
  4718. end;
  4719. function TPasImplExceptOn.VariableName: TPasTreeString;
  4720. begin
  4721. If assigned(VarEl) then
  4722. Result:=VarEl.Name
  4723. else
  4724. Result:='';
  4725. end;
  4726. function TPasImplExceptOn.TypeName: TPasTreeString;
  4727. begin
  4728. If assigned(TypeEl) then
  4729. Result:=TypeEl.GetDeclaration(True)
  4730. else
  4731. Result:='';
  4732. end;
  4733. { TPasImplStatement }
  4734. function TPasImplStatement.CloseOnSemicolon: boolean;
  4735. begin
  4736. Result:=true;
  4737. end;
  4738. { TPasExpr }
  4739. constructor TPasExpr.Create(AParent: TPasElement; AKind: TPasExprKind;
  4740. AOpCode: TExprOpCode);
  4741. begin
  4742. inherited Create(ClassName, AParent);
  4743. Kind:=AKind;
  4744. OpCode:=AOpCode;
  4745. end;
  4746. procedure TPasExpr.FreeChildren(Prepare: boolean);
  4747. begin
  4748. Format1:=TPasExpr(FreeChild(Format1,Prepare));
  4749. Format2:=TPasExpr(FreeChild(Format2,Prepare));
  4750. inherited FreeChildren(Prepare);
  4751. end;
  4752. { TPrimitiveExpr }
  4753. function TPrimitiveExpr.GetDeclaration(full: Boolean): TPasTreeString;
  4754. begin
  4755. Result:=Value;
  4756. if full then ;
  4757. end;
  4758. constructor TPrimitiveExpr.Create(AParent : TPasElement; AKind: TPasExprKind; const AValue : TPasTreeString);
  4759. begin
  4760. inherited Create(AParent,AKind, eopNone);
  4761. Value:=AValue;
  4762. end;
  4763. { TBoolConstExpr }
  4764. constructor TBoolConstExpr.Create(AParent : TPasElement; AKind: TPasExprKind; const ABoolValue : Boolean);
  4765. begin
  4766. inherited Create(AParent,AKind, eopNone);
  4767. Value:=ABoolValue;
  4768. end;
  4769. function TBoolConstExpr.GetDeclaration(full: Boolean): TPasTreeString;
  4770. begin
  4771. If Value then
  4772. Result:='True'
  4773. else
  4774. Result:='False';
  4775. if full then ;
  4776. end;
  4777. { TUnaryExpr }
  4778. function TUnaryExpr.GetDeclaration(full: Boolean): TPasTreeString;
  4779. Const
  4780. WordOpcodes = [eopDiv,eopMod,eopshr,eopshl,eopNot,eopAnd,eopOr,eopXor];
  4781. begin
  4782. Result:=OpCodeStrings[Opcode];
  4783. if OpCode in WordOpCodes then
  4784. Result:=Result+' ';
  4785. If Assigned(Operand) then
  4786. Result:=Result+' '+Operand.GetDeclaration(Full);
  4787. end;
  4788. constructor TUnaryExpr.Create(AParent : TPasElement; AOperand: TPasExpr; AOpCode: TExprOpCode);
  4789. begin
  4790. inherited Create(AParent,pekUnary, AOpCode);
  4791. Operand:=AOperand;
  4792. Operand.Parent:=Self;
  4793. end;
  4794. procedure TUnaryExpr.FreeChildren(Prepare: boolean);
  4795. begin
  4796. Operand:=TPasExpr(FreeChild(Operand,Prepare));
  4797. inherited FreeChildren(Prepare);
  4798. end;
  4799. procedure TUnaryExpr.ForEachCall(const aMethodCall: TOnForEachPasElement;
  4800. const Arg: Pointer);
  4801. begin
  4802. inherited ForEachCall(aMethodCall, Arg);
  4803. ForEachChildCall(aMethodCall,Arg,Operand,false);
  4804. end;
  4805. { TBinaryExpr }
  4806. function TBinaryExpr.GetDeclaration(full: Boolean): TPasTreeString;
  4807. function OpLevel(op: TPasExpr): Integer;
  4808. begin
  4809. case op.OpCode of
  4810. eopNot,eopAddress:
  4811. Result := 4;
  4812. eopMultiply, eopDivide, eopDiv, eopMod, eopAnd, eopShl,
  4813. eopShr, eopAs, eopPower:
  4814. Result := 3;
  4815. eopAdd, eopSubtract, eopOr, eopXor:
  4816. Result := 2;
  4817. eopEqual, eopNotEqual, eopLessThan, eopLessthanEqual, eopGreaterThan,
  4818. eopGreaterThanEqual, eopIn, eopIs:
  4819. Result := 1;
  4820. else
  4821. Result := 5; // Numbers and Identifiers
  4822. end;
  4823. end;
  4824. var op: TPasTreeString;
  4825. begin
  4826. If Kind=pekRange then
  4827. Result:='..'
  4828. else
  4829. begin
  4830. Result:=OpcodeStrings[Opcode];
  4831. if Not (OpCode in [eopAddress,eopDeref,eopSubIdent]) then
  4832. Result:=' '+Result+' ';
  4833. end;
  4834. If Assigned(Left) then
  4835. begin
  4836. op := Left.GetDeclaration(Full);
  4837. if OpLevel(Left) < OpLevel(Self) then
  4838. Result := '(' + op + ')' + Result
  4839. else
  4840. Result := op + Result;
  4841. end;
  4842. If Assigned(Right) then
  4843. begin
  4844. op := Right.GetDeclaration(Full);
  4845. if OpLevel(Left) < OpLevel(Self) then
  4846. Result := Result + '(' + op + ')'
  4847. else
  4848. Result := Result + op;
  4849. end;
  4850. end;
  4851. constructor TBinaryExpr.Create(AParent : TPasElement; xleft,xright:TPasExpr; AOpCode:TExprOpCode);
  4852. begin
  4853. inherited Create(AParent,pekBinary, AOpCode);
  4854. Left:=xleft;
  4855. Left.Parent:=Self;
  4856. Right:=xright;
  4857. Right.Parent:=Self;
  4858. end;
  4859. constructor TBinaryExpr.CreateRange(AParent : TPasElement; xleft,xright:TPasExpr);
  4860. begin
  4861. inherited Create(AParent,pekRange, eopNone);
  4862. Left:=xleft;
  4863. Left.Parent:=Self;
  4864. Right:=xright;
  4865. Right.Parent:=Self;
  4866. end;
  4867. procedure TBinaryExpr.FreeChildren(Prepare: boolean);
  4868. var
  4869. El: TPasExpr;
  4870. SubBin: TBinaryExpr;
  4871. begin
  4872. // handle Left of binary chains without stack
  4873. El:=Left;
  4874. while El is TBinaryExpr do
  4875. begin
  4876. SubBin:=TBinaryExpr(El);
  4877. El:=SubBin.Left;
  4878. if (El=nil) or (El.Parent<>SubBin) then
  4879. begin
  4880. El:=SubBin;
  4881. break;
  4882. end;
  4883. end;
  4884. repeat
  4885. if El=Left then
  4886. SubBin:=Self
  4887. else
  4888. SubBin:=TBinaryExpr(El.Parent);
  4889. if SubBin.Left<>nil then
  4890. begin
  4891. if Prepare then
  4892. begin
  4893. if SubBin.Left.Parent<>SubBin then
  4894. SubBin.Left:=nil; // clear reference
  4895. end
  4896. else
  4897. begin
  4898. SubBin.Left.FreeChildren(false);
  4899. SubBin.Left.Free;
  4900. SubBin.Left:=nil;
  4901. end;
  4902. end;
  4903. SubBin.Right:=TPasExpr(SubBin.FreeChild(SubBin.Right,Prepare));
  4904. El:=SubBin;
  4905. until El=Self;
  4906. inherited FreeChildren(Prepare);
  4907. end;
  4908. procedure TBinaryExpr.ForEachCall(const aMethodCall: TOnForEachPasElement;
  4909. const Arg: Pointer);
  4910. begin
  4911. inherited ForEachCall(aMethodCall, Arg);
  4912. ForEachChildCall(aMethodCall,Arg,Left,false);
  4913. ForEachChildCall(aMethodCall,Arg,Right,false);
  4914. end;
  4915. class function TBinaryExpr.IsRightSubIdent(El: TPasElement): boolean;
  4916. var
  4917. Bin: TBinaryExpr;
  4918. begin
  4919. if (El=nil) or not (El.Parent is TBinaryExpr) then exit(false);
  4920. Bin:=TBinaryExpr(El.Parent);
  4921. Result:=(Bin.Right=El) and (Bin.OpCode=eopSubIdent);
  4922. end;
  4923. { TParamsExpr }
  4924. function TParamsExpr.GetDeclaration(full: Boolean): TPasTreeString;
  4925. Var
  4926. I : Integer;
  4927. begin
  4928. Result := '';
  4929. For I:=0 to High(Params) do
  4930. begin
  4931. If (Result<>'') then
  4932. Result:=Result+', ';
  4933. Result:=Result+Params[I].GetDeclaration(Full);
  4934. if Assigned(Params[I].Format1) then
  4935. Result:=Result+':'+Params[I].Format1.GetDeclaration(false);
  4936. if Assigned(Params[I].Format2) then
  4937. Result:=Result+':'+Params[I].Format2.GetDeclaration(false);
  4938. end;
  4939. if Kind in [pekSet,pekArrayParams] then
  4940. Result := '[' + Result + ']'
  4941. else
  4942. Result := '(' + Result + ')';
  4943. if full and Assigned(Value) then
  4944. Result:=Value.GetDeclaration(True)+Result;
  4945. end;
  4946. procedure TParamsExpr.AddParam(xp:TPasExpr);
  4947. var
  4948. i : Integer;
  4949. begin
  4950. i:=Length(Params);
  4951. SetLength(Params, i+1);
  4952. Params[i]:=xp;
  4953. end;
  4954. procedure TParamsExpr.ForEachCall(const aMethodCall: TOnForEachPasElement;
  4955. const Arg: Pointer);
  4956. var
  4957. i: Integer;
  4958. begin
  4959. inherited ForEachCall(aMethodCall, Arg);
  4960. ForEachChildCall(aMethodCall,Arg,Value,false);
  4961. for i:=0 to High(Params) do
  4962. ForEachChildCall(aMethodCall,Arg,Params[i],false);
  4963. end;
  4964. constructor TParamsExpr.Create(AParent : TPasElement; AKind: TPasExprKind);
  4965. begin
  4966. inherited Create(AParent,AKind, eopNone);
  4967. end;
  4968. procedure TParamsExpr.FreeChildren(Prepare: boolean);
  4969. begin
  4970. Value:=TPasExpr(FreeChild(Value,Prepare));
  4971. FreePasExprArray(Self,Params,Prepare);
  4972. inherited FreeChildren(Prepare);
  4973. end;
  4974. { TRecordValues }
  4975. function TRecordValues.GetDeclaration(full: Boolean): TPasTreeString;
  4976. Var
  4977. I : Integer;
  4978. begin
  4979. Result := '';
  4980. For I:=0 to High(Fields) do
  4981. begin
  4982. If Result<>'' then
  4983. Result:=Result+'; ';
  4984. Result:=Result+EscapeKeyWord(Fields[I].Name)+': '+Fields[i].ValueExp.getDeclaration(Full);
  4985. end;
  4986. Result:='('+Result+')';
  4987. end;
  4988. procedure TRecordValues.ForEachCall(const aMethodCall: TOnForEachPasElement;
  4989. const Arg: Pointer);
  4990. var
  4991. i: Integer;
  4992. begin
  4993. inherited ForEachCall(aMethodCall, Arg);
  4994. for i:=0 to length(Fields)-1 do
  4995. with Fields[i] do
  4996. begin
  4997. if NameExp<>nil then
  4998. ForEachChildCall(aMethodCall,Arg,NameExp,false);
  4999. if ValueExp<>nil then
  5000. ForEachChildCall(aMethodCall,Arg,ValueExp,false);
  5001. end;
  5002. end;
  5003. constructor TRecordValues.Create(AParent : TPasElement);
  5004. begin
  5005. inherited Create(AParent,pekListOfExp, eopNone);
  5006. end;
  5007. destructor TRecordValues.Destroy;
  5008. begin
  5009. Fields:=nil;
  5010. inherited Destroy;
  5011. end;
  5012. procedure TRecordValues.FreeChildren(Prepare: boolean);
  5013. var
  5014. i: Integer;
  5015. begin
  5016. for i:=0 to High(Fields) do
  5017. begin
  5018. Fields[i].NameExp:=TPrimitiveExpr(FreeChild(Fields[i].NameExp,Prepare));
  5019. Fields[i].ValueExp:=TPasExpr(FreeChild(Fields[i].ValueExp,Prepare));
  5020. end;
  5021. inherited FreeChildren(Prepare);
  5022. end;
  5023. procedure TRecordValues.AddField(AName: TPrimitiveExpr; Value: TPasExpr);
  5024. var
  5025. i : Integer;
  5026. begin
  5027. i:=length(Fields);
  5028. SetLength(Fields, i+1);
  5029. Fields[i].Name:=AName.Value;
  5030. Fields[i].NameExp:=AName;
  5031. AName.Parent:=Self;
  5032. Fields[i].ValueExp:=Value;
  5033. Value.Parent:=Self;
  5034. end;
  5035. { TNilExpr }
  5036. function TNilExpr.GetDeclaration(full: Boolean): TPasTreeString;
  5037. begin
  5038. Result:='Nil';
  5039. if full then ;
  5040. end;
  5041. { TInheritedExpr }
  5042. function TInheritedExpr.GetDeclaration(full: Boolean): TPasTreeString;
  5043. begin
  5044. Result:='Inherited';
  5045. if full then ;
  5046. end;
  5047. { TSelfExpr }
  5048. function TSelfExpr.GetDeclaration(full: Boolean): TPasTreeString;
  5049. begin
  5050. Result:='Self';
  5051. if full then ;
  5052. end;
  5053. { TArrayValues }
  5054. function TArrayValues.GetDeclaration(full: Boolean): TPasTreeString;
  5055. Var
  5056. I : Integer;
  5057. begin
  5058. Result := '';
  5059. For I:=0 to High(Values) do
  5060. begin
  5061. If Result<>'' then
  5062. Result:=Result+', ';
  5063. Result:=Result+Values[i].getDeclaration(Full);
  5064. end;
  5065. Result:='('+Result+')';
  5066. end;
  5067. procedure TArrayValues.ForEachCall(const aMethodCall: TOnForEachPasElement;
  5068. const Arg: Pointer);
  5069. var
  5070. i: Integer;
  5071. begin
  5072. inherited ForEachCall(aMethodCall, Arg);
  5073. for i:=0 to length(Values)-1 do
  5074. ForEachChildCall(aMethodCall,Arg,Values[i],false);
  5075. end;
  5076. constructor TArrayValues.Create(AParent : TPasElement);
  5077. begin
  5078. inherited Create(AParent,pekListOfExp, eopNone);
  5079. end;
  5080. destructor TArrayValues.Destroy;
  5081. begin
  5082. Values:=nil;
  5083. inherited Destroy;
  5084. end;
  5085. procedure TArrayValues.FreeChildren(Prepare: boolean);
  5086. begin
  5087. FreePasExprArray(Self,Values,Prepare);
  5088. inherited FreeChildren(Prepare);
  5089. end;
  5090. procedure TArrayValues.AddValues(AValue:TPasExpr);
  5091. var
  5092. i : Integer;
  5093. begin
  5094. i:=length(Values);
  5095. SetLength(Values, i+1);
  5096. Values[i]:=AValue;
  5097. AValue.Parent:=Self;
  5098. end;
  5099. { TNilExpr }
  5100. constructor TNilExpr.Create(AParent : TPasElement);
  5101. begin
  5102. inherited Create(AParent,pekNil, eopNone);
  5103. end;
  5104. { TInheritedExpr }
  5105. constructor TInheritedExpr.Create(AParent : TPasElement);
  5106. begin
  5107. inherited Create(AParent,pekInherited, eopNone);
  5108. end;
  5109. { TSelfExpr }
  5110. constructor TSelfExpr.Create(AParent : TPasElement);
  5111. begin
  5112. inherited Create(AParent,pekSelf, eopNone);
  5113. end;
  5114. { TPasLabels }
  5115. constructor TPasLabels.Create(const AName:TPasTreeString;AParent:TPasElement);
  5116. begin
  5117. inherited Create(AName,AParent);
  5118. Labels := TStringList.Create;
  5119. end;
  5120. destructor TPasLabels.Destroy;
  5121. begin
  5122. FreeAndNil(Labels);
  5123. inherited Destroy;
  5124. end;
  5125. end.