pastree.pp 162 KB

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