symdef.pas 189 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180
  1. {
  2. $Id$
  3. Copyright (c) 1998-2002 by Florian Klaempfl, Pierre Muller
  4. Symbol table implementation for the definitions
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. ****************************************************************************
  17. }
  18. unit symdef;
  19. {$i fpcdefs.inc}
  20. interface
  21. uses
  22. { common }
  23. cutils,cclasses,
  24. { global }
  25. globtype,globals,tokens,
  26. { symtable }
  27. symconst,symbase,symtype,
  28. { ppu }
  29. ppu,
  30. { node }
  31. node,
  32. { aasm }
  33. aasmbase,aasmtai,
  34. cpubase,cpuinfo,
  35. cgbase
  36. {$ifdef Delphi}
  37. ,dmisc
  38. {$endif}
  39. ;
  40. type
  41. {************************************************
  42. TDef
  43. ************************************************}
  44. tstoreddef = class(tdef)
  45. protected
  46. typesymderef : tderef;
  47. public
  48. { persistent (available across units) rtti and init tables }
  49. rttitablesym,
  50. inittablesym : tsym; {trttisym}
  51. rttitablesymderef,
  52. inittablesymderef : tderef;
  53. { local (per module) rtti and init tables }
  54. localrttilab : array[trttitype] of tasmlabel;
  55. { linked list of global definitions }
  56. {$ifdef EXTDEBUG}
  57. fileinfo : tfileposinfo;
  58. {$endif}
  59. {$ifdef GDB}
  60. globalnb : word;
  61. stab_state : tdefstabstatus;
  62. {$endif GDB}
  63. constructor create;
  64. constructor ppuloaddef(ppufile:tcompilerppufile);
  65. procedure reset;
  66. function getcopy : tstoreddef;virtual;
  67. procedure ppuwritedef(ppufile:tcompilerppufile);
  68. procedure ppuwrite(ppufile:tcompilerppufile);virtual;abstract;
  69. procedure buildderef;override;
  70. procedure buildderefimpl;override;
  71. procedure deref;override;
  72. procedure derefimpl;override;
  73. function size:longint;override;
  74. function alignment:longint;override;
  75. function is_publishable : boolean;override;
  76. function needs_inittable : boolean;override;
  77. { debug }
  78. {$ifdef GDB}
  79. function get_var_value(const s:string):string;
  80. function stabstr_evaluate(const s:string;const vars:array of string):Pchar;
  81. function stabstring : pchar;virtual;
  82. procedure concatstabto(asmlist : taasmoutput);virtual;
  83. function numberstring:string;virtual;
  84. procedure set_globalnb;virtual;
  85. function allstabstring : pchar;virtual;
  86. {$endif GDB}
  87. { rtti generation }
  88. procedure write_rtti_name;
  89. procedure write_rtti_data(rt:trttitype);virtual;
  90. procedure write_child_rtti_data(rt:trttitype);virtual;
  91. function get_rtti_label(rt:trttitype):tasmsymbol;
  92. { regvars }
  93. function is_intregable : boolean;
  94. function is_fpuregable : boolean;
  95. private
  96. savesize : longint;
  97. end;
  98. tparaitem = class(TLinkedListItem)
  99. paratype : ttype; { required for procvar }
  100. parasym : tsym;
  101. parasymderef : tderef;
  102. defaultvalue : tsym; { tconstsym }
  103. defaultvaluederef : tderef;
  104. paratyp : tvarspez; { required for procvar }
  105. paraloc : array[tcallercallee] of tparalocation;
  106. is_hidden : boolean; { is this a hidden (implicit) parameter }
  107. {$ifdef EXTDEBUG}
  108. eqval : tequaltype;
  109. {$endif EXTDEBUG}
  110. end;
  111. tfiletyp = (ft_text,ft_typed,ft_untyped);
  112. tfiledef = class(tstoreddef)
  113. filetyp : tfiletyp;
  114. typedfiletype : ttype;
  115. constructor createtext;
  116. constructor createuntyped;
  117. constructor createtyped(const tt : ttype);
  118. constructor ppuload(ppufile:tcompilerppufile);
  119. procedure ppuwrite(ppufile:tcompilerppufile);override;
  120. procedure buildderef;override;
  121. procedure deref;override;
  122. function gettypename:string;override;
  123. function getmangledparaname:string;override;
  124. procedure setsize;
  125. { debug }
  126. {$ifdef GDB}
  127. function stabstring : pchar;override;
  128. procedure concatstabto(asmlist : taasmoutput);override;
  129. {$endif GDB}
  130. end;
  131. tvariantdef = class(tstoreddef)
  132. varianttype : tvarianttype;
  133. constructor create(v : tvarianttype);
  134. constructor ppuload(ppufile:tcompilerppufile);
  135. function gettypename:string;override;
  136. procedure ppuwrite(ppufile:tcompilerppufile);override;
  137. procedure setsize;
  138. function needs_inittable : boolean;override;
  139. procedure write_rtti_data(rt:trttitype);override;
  140. {$ifdef GDB}
  141. function numberstring:string;override;
  142. function stabstring : pchar;override;
  143. procedure concatstabto(asmlist : taasmoutput);override;
  144. {$endif GDB}
  145. end;
  146. tformaldef = class(tstoreddef)
  147. constructor create;
  148. constructor ppuload(ppufile:tcompilerppufile);
  149. procedure ppuwrite(ppufile:tcompilerppufile);override;
  150. function gettypename:string;override;
  151. {$ifdef GDB}
  152. function numberstring:string;override;
  153. function stabstring : pchar;override;
  154. procedure concatstabto(asmlist : taasmoutput);override;
  155. {$endif GDB}
  156. end;
  157. tforwarddef = class(tstoreddef)
  158. tosymname : pstring;
  159. forwardpos : tfileposinfo;
  160. constructor create(const s:string;const pos : tfileposinfo);
  161. destructor destroy;override;
  162. function gettypename:string;override;
  163. end;
  164. terrordef = class(tstoreddef)
  165. constructor create;
  166. function gettypename:string;override;
  167. function getmangledparaname : string;override;
  168. { debug }
  169. {$ifdef GDB}
  170. function stabstring : pchar;override;
  171. procedure concatstabto(asmlist : taasmoutput);override;
  172. {$endif GDB}
  173. end;
  174. { tpointerdef and tclassrefdef should get a common
  175. base class, but I derived tclassrefdef from tpointerdef
  176. to avoid problems with bugs (FK)
  177. }
  178. tpointerdef = class(tstoreddef)
  179. pointertype : ttype;
  180. is_far : boolean;
  181. constructor create(const tt : ttype);
  182. constructor createfar(const tt : ttype);
  183. constructor ppuload(ppufile:tcompilerppufile);
  184. procedure ppuwrite(ppufile:tcompilerppufile);override;
  185. procedure buildderef;override;
  186. procedure deref;override;
  187. function gettypename:string;override;
  188. { debug }
  189. {$ifdef GDB}
  190. function stabstring : pchar;override;
  191. procedure concatstabto(asmlist : taasmoutput);override;
  192. {$endif GDB}
  193. end;
  194. Trecord_stabgen_state=record
  195. stabstring:Pchar;
  196. stabsize,staballoc,recoffset:integer;
  197. end;
  198. tabstractrecorddef= class(tstoreddef)
  199. private
  200. Count : integer;
  201. FRTTIType : trttitype;
  202. {$ifdef GDB}
  203. procedure field_addname(p:Tnamedindexitem;arg:pointer);
  204. procedure field_concatstabto(p:Tnamedindexitem;arg:pointer);
  205. {$endif}
  206. procedure count_field_rtti(sym : tnamedindexitem;arg:pointer);
  207. procedure write_field_rtti(sym : tnamedindexitem;arg:pointer);
  208. procedure generate_field_rtti(sym : tnamedindexitem;arg:pointer);
  209. public
  210. symtable : tsymtable;
  211. function getsymtable(t:tgetsymtable):tsymtable;override;
  212. end;
  213. trecorddef = class(tabstractrecorddef)
  214. public
  215. isunion : boolean;
  216. constructor create(p : tsymtable);
  217. constructor ppuload(ppufile:tcompilerppufile);
  218. destructor destroy;override;
  219. procedure ppuwrite(ppufile:tcompilerppufile);override;
  220. procedure buildderef;override;
  221. procedure deref;override;
  222. function size:longint;override;
  223. function alignment : longint;override;
  224. function gettypename:string;override;
  225. { debug }
  226. {$ifdef GDB}
  227. function stabstring : pchar;override;
  228. procedure concatstabto(asmlist:taasmoutput);override;
  229. {$endif GDB}
  230. function needs_inittable : boolean;override;
  231. { rtti }
  232. procedure write_child_rtti_data(rt:trttitype);override;
  233. procedure write_rtti_data(rt:trttitype);override;
  234. end;
  235. tprocdef = class;
  236. timplementedinterfaces = class;
  237. tobjectdef = class(tabstractrecorddef)
  238. private
  239. {$ifdef GDB}
  240. procedure proc_addname(p :tnamedindexitem;arg:pointer);
  241. procedure proc_concatstabto(p :tnamedindexitem;arg:pointer);
  242. {$endif GDB}
  243. procedure count_published_properties(sym:tnamedindexitem;arg:pointer);
  244. procedure write_property_info(sym : tnamedindexitem;arg:pointer);
  245. procedure generate_published_child_rtti(sym : tnamedindexitem;arg:pointer);
  246. procedure count_published_fields(sym:tnamedindexitem;arg:pointer);
  247. procedure writefields(sym:tnamedindexitem;arg:pointer);
  248. public
  249. childof : tobjectdef;
  250. childofderef : tderef;
  251. objname,
  252. objrealname : pstring;
  253. objectoptions : tobjectoptions;
  254. { to be able to have a variable vmt position }
  255. { and no vmt field for objects without virtuals }
  256. vmt_offset : longint;
  257. {$ifdef GDB}
  258. writing_class_record_stab : boolean;
  259. {$endif GDB}
  260. objecttype : tobjectdeftype;
  261. iidguid: pguid;
  262. iidstr: pstring;
  263. lastvtableindex: longint;
  264. { store implemented interfaces defs and name mappings }
  265. implementedinterfaces: timplementedinterfaces;
  266. constructor create(ot : tobjectdeftype;const n : string;c : tobjectdef);
  267. constructor ppuload(ppufile:tcompilerppufile);
  268. destructor destroy;override;
  269. procedure ppuwrite(ppufile:tcompilerppufile);override;
  270. function gettypename:string;override;
  271. procedure buildderef;override;
  272. procedure deref;override;
  273. function getparentdef:tdef;override;
  274. function size : longint;override;
  275. function alignment:longint;override;
  276. function vmtmethodoffset(index:longint):longint;
  277. function members_need_inittable : boolean;
  278. { this should be called when this class implements an interface }
  279. procedure prepareguid;
  280. function is_publishable : boolean;override;
  281. function needs_inittable : boolean;override;
  282. function vmt_mangledname : string;
  283. function rtti_name : string;
  284. procedure check_forwards;
  285. function is_related(d : tobjectdef) : boolean;
  286. function next_free_name_index : longint;
  287. procedure insertvmt;
  288. procedure set_parent(c : tobjectdef);
  289. function searchdestructor : tprocdef;
  290. { debug }
  291. {$ifdef GDB}
  292. function stabstring : pchar;override;
  293. procedure set_globalnb;override;
  294. function classnumberstring : string;
  295. procedure concatstabto(asmlist : taasmoutput);override;
  296. function allstabstring : pchar;override;
  297. {$endif GDB}
  298. { rtti }
  299. procedure write_child_rtti_data(rt:trttitype);override;
  300. procedure write_rtti_data(rt:trttitype);override;
  301. function generate_field_table : tasmlabel;
  302. end;
  303. timplementedinterfaces = class
  304. constructor create;
  305. destructor destroy; override;
  306. function count: longint;
  307. function interfaces(intfindex: longint): tobjectdef;
  308. function interfacesderef(intfindex: longint): tderef;
  309. function ioffsets(intfindex: longint): plongint;
  310. function searchintf(def: tdef): longint;
  311. procedure addintf(def: tdef);
  312. procedure buildderef;
  313. procedure deref;
  314. { add interface reference loaded from ppu }
  315. procedure addintf_deref(const d:tderef);
  316. procedure clearmappings;
  317. procedure addmappings(intfindex: longint; const name, newname: string);
  318. function getmappings(intfindex: longint; const name: string; var nextexist: pointer): string;
  319. procedure clearimplprocs;
  320. procedure addimplproc(intfindex: longint; procdef: tprocdef);
  321. function implproccount(intfindex: longint): longint;
  322. function implprocs(intfindex: longint; procindex: longint): tprocdef;
  323. function isimplmergepossible(intfindex, remainindex: longint; var weight: longint): boolean;
  324. private
  325. finterfaces: tindexarray;
  326. procedure checkindex(intfindex: longint);
  327. end;
  328. tclassrefdef = class(tpointerdef)
  329. constructor create(const t:ttype);
  330. constructor ppuload(ppufile:tcompilerppufile);
  331. procedure ppuwrite(ppufile:tcompilerppufile);override;
  332. function gettypename:string;override;
  333. { debug }
  334. {$ifdef GDB}
  335. function stabstring : pchar;override;
  336. {$endif GDB}
  337. end;
  338. tarraydef = class(tstoreddef)
  339. lowrange,
  340. highrange : longint;
  341. rangetype : ttype;
  342. IsConvertedPointer,
  343. IsDynamicArray,
  344. IsVariant,
  345. IsConstructor,
  346. IsArrayOfConst : boolean;
  347. protected
  348. _elementtype : ttype;
  349. public
  350. function elesize : longint;
  351. constructor create_from_pointer(const elemt : ttype);
  352. constructor create(l,h : longint;const t : ttype);
  353. constructor ppuload(ppufile:tcompilerppufile);
  354. procedure ppuwrite(ppufile:tcompilerppufile);override;
  355. function gettypename:string;override;
  356. function getmangledparaname : string;override;
  357. procedure setelementtype(t: ttype);
  358. {$ifdef GDB}
  359. function stabstring : pchar;override;
  360. procedure concatstabto(asmlist : taasmoutput);override;
  361. {$endif GDB}
  362. procedure buildderef;override;
  363. procedure deref;override;
  364. function size : longint;override;
  365. function alignment : longint;override;
  366. { returns the label of the range check string }
  367. function needs_inittable : boolean;override;
  368. procedure write_child_rtti_data(rt:trttitype);override;
  369. procedure write_rtti_data(rt:trttitype);override;
  370. property elementtype : ttype Read _ElementType;
  371. end;
  372. torddef = class(tstoreddef)
  373. low,high : TConstExprInt;
  374. typ : tbasetype;
  375. constructor create(t : tbasetype;v,b : TConstExprInt);
  376. constructor ppuload(ppufile:tcompilerppufile);
  377. function getcopy : tstoreddef;override;
  378. procedure ppuwrite(ppufile:tcompilerppufile);override;
  379. function is_publishable : boolean;override;
  380. function gettypename:string;override;
  381. procedure setsize;
  382. { debug }
  383. {$ifdef GDB}
  384. function stabstring : pchar;override;
  385. {$endif GDB}
  386. { rtti }
  387. procedure write_rtti_data(rt:trttitype);override;
  388. end;
  389. tfloatdef = class(tstoreddef)
  390. typ : tfloattype;
  391. constructor create(t : tfloattype);
  392. constructor ppuload(ppufile:tcompilerppufile);
  393. function getcopy : tstoreddef;override;
  394. procedure ppuwrite(ppufile:tcompilerppufile);override;
  395. function gettypename:string;override;
  396. function is_publishable : boolean;override;
  397. procedure setsize;
  398. { debug }
  399. {$ifdef GDB}
  400. function stabstring : pchar;override;
  401. procedure concatstabto(asmlist:taasmoutput);override;
  402. {$endif GDB}
  403. { rtti }
  404. procedure write_rtti_data(rt:trttitype);override;
  405. end;
  406. tabstractprocdef = class(tstoreddef)
  407. { saves a definition to the return type }
  408. rettype : ttype;
  409. parast : tsymtable;
  410. para : tlinkedlist;
  411. proctypeoption : tproctypeoption;
  412. proccalloption : tproccalloption;
  413. procoptions : tprocoptions;
  414. requiredargarea : aint;
  415. maxparacount,
  416. minparacount : byte;
  417. {$ifdef i386}
  418. fpu_used : byte; { how many stack fpu must be empty }
  419. {$endif i386}
  420. funcret_paraloc : packed array[tcallercallee] of tparalocation;
  421. has_paraloc_info : boolean; { paraloc info is available }
  422. constructor create(level:byte);
  423. constructor ppuload(ppufile:tcompilerppufile);
  424. destructor destroy;override;
  425. procedure ppuwrite(ppufile:tcompilerppufile);override;
  426. procedure buildderef;override;
  427. procedure deref;override;
  428. procedure releasemem;
  429. function concatpara(afterpara:tparaitem;const tt:ttype;sym : tsym;defval:tsym;vhidden:boolean):tparaitem;
  430. function insertpara(const tt:ttype;sym : tsym;defval:tsym;vhidden:boolean):tparaitem;
  431. procedure removepara(currpara:tparaitem);
  432. function typename_paras(showhidden:boolean): string;
  433. procedure test_if_fpu_result;
  434. function is_methodpointer:boolean;virtual;
  435. function is_addressonly:boolean;virtual;
  436. { debug }
  437. {$ifdef GDB}
  438. function stabstring : pchar;override;
  439. {$endif GDB}
  440. end;
  441. tprocvardef = class(tabstractprocdef)
  442. constructor create(level:byte);
  443. constructor ppuload(ppufile:tcompilerppufile);
  444. procedure ppuwrite(ppufile:tcompilerppufile);override;
  445. procedure buildderef;override;
  446. procedure deref;override;
  447. function getsymtable(t:tgetsymtable):tsymtable;override;
  448. function size : longint;override;
  449. function gettypename:string;override;
  450. function is_publishable : boolean;override;
  451. function is_methodpointer:boolean;override;
  452. function is_addressonly:boolean;override;
  453. { debug }
  454. {$ifdef GDB}
  455. function stabstring : pchar;override;
  456. procedure concatstabto(asmlist:taasmoutput);override;
  457. {$endif GDB}
  458. { rtti }
  459. procedure write_rtti_data(rt:trttitype);override;
  460. end;
  461. tmessageinf = record
  462. case integer of
  463. 0 : (str : pchar);
  464. 1 : (i : longint);
  465. end;
  466. tinlininginfo = record
  467. { node tree }
  468. code : tnode;
  469. flags : tprocinfoflags;
  470. inlinenode : boolean;
  471. end;
  472. pinlininginfo = ^tinlininginfo;
  473. {$ifdef oldregvars}
  474. { register variables }
  475. pregvarinfo = ^tregvarinfo;
  476. tregvarinfo = record
  477. regvars : array[1..maxvarregs] of tsym;
  478. regvars_para : array[1..maxvarregs] of boolean;
  479. regvars_refs : array[1..maxvarregs] of longint;
  480. fpuregvars : array[1..maxfpuvarregs] of tsym;
  481. fpuregvars_para : array[1..maxfpuvarregs] of boolean;
  482. fpuregvars_refs : array[1..maxfpuvarregs] of longint;
  483. end;
  484. {$endif oldregvars}
  485. tprocdef = class(tabstractprocdef)
  486. private
  487. _mangledname : pstring;
  488. {$ifdef GDB}
  489. isstabwritten : boolean;
  490. {$endif GDB}
  491. public
  492. extnumber : word;
  493. overloadnumber : word;
  494. messageinf : tmessageinf;
  495. {$ifndef EXTDEBUG}
  496. { where is this function defined and what were the symbol
  497. flags, needed here because there
  498. is only one symbol for all overloaded functions
  499. EXTDEBUG has fileinfo in tdef (PFV) }
  500. fileinfo : tfileposinfo;
  501. {$endif}
  502. symoptions : tsymoptions;
  503. { symbol owning this definition }
  504. procsym : tsym;
  505. procsymderef : tderef;
  506. { alias names }
  507. aliasnames : tstringlist;
  508. { symtables }
  509. localst : tsymtable;
  510. funcretsym : tsym;
  511. funcretsymderef : tderef;
  512. { browser info }
  513. lastref,
  514. defref,
  515. lastwritten : tref;
  516. refcount : longint;
  517. _class : tobjectdef;
  518. _classderef : tderef;
  519. {$ifdef powerpc}
  520. { library symbol for AmigaOS/MorphOS }
  521. libsym : tsym;
  522. libsymderef : tderef;
  523. {$endif powerpc}
  524. { name of the result variable to insert in the localsymtable }
  525. resultname : stringid;
  526. { true, if the procedure is only declared
  527. (forward procedure) }
  528. forwarddef,
  529. { true if the procedure is declared in the interface }
  530. interfacedef : boolean;
  531. { true if the procedure has a forward declaration }
  532. hasforward : boolean;
  533. { check the problems of manglednames }
  534. has_mangledname : boolean;
  535. { info for inlining the subroutine, if this pointer is nil,
  536. the procedure can't be inlined }
  537. inlininginfo : pinlininginfo;
  538. {$ifdef oldregvars}
  539. regvarinfo: pregvarinfo;
  540. {$endif oldregvars}
  541. constructor create(level:byte);
  542. constructor ppuload(ppufile:tcompilerppufile);
  543. destructor destroy;override;
  544. procedure ppuwrite(ppufile:tcompilerppufile);override;
  545. procedure buildderef;override;
  546. procedure buildderefimpl;override;
  547. procedure deref;override;
  548. procedure derefimpl;override;
  549. function getsymtable(t:tgetsymtable):tsymtable;override;
  550. function gettypename : string;override;
  551. function mangledname : string;
  552. procedure setmangledname(const s : string);
  553. procedure load_references(ppufile:tcompilerppufile;locals:boolean);
  554. function write_references(ppufile:tcompilerppufile;locals:boolean):boolean;
  555. { inserts the local symbol table, if this is not
  556. no local symbol table is built. Should be called only
  557. when we are sure that a local symbol table will be required.
  558. }
  559. procedure insert_localst;
  560. function fullprocname(showhidden:boolean):string;
  561. function cplusplusmangledname : string;
  562. function is_methodpointer:boolean;override;
  563. function is_addressonly:boolean;override;
  564. function is_visible_for_object(currobjdef:tobjectdef):boolean;
  565. { debug }
  566. {$ifdef GDB}
  567. function numberstring:string;override;
  568. function stabstring : pchar;override;
  569. procedure concatstabto(asmlist : taasmoutput);override;
  570. {$endif GDB}
  571. end;
  572. { single linked list of overloaded procs }
  573. pprocdeflist = ^tprocdeflist;
  574. tprocdeflist = record
  575. def : tprocdef;
  576. defderef : tderef;
  577. own : boolean;
  578. next : pprocdeflist;
  579. end;
  580. tstringdef = class(tstoreddef)
  581. string_typ : tstringtype;
  582. len : longint;
  583. constructor createshort(l : byte);
  584. constructor loadshort(ppufile:tcompilerppufile);
  585. constructor createlong(l : longint);
  586. constructor loadlong(ppufile:tcompilerppufile);
  587. {$ifdef ansistring_bits}
  588. constructor createansi(l:longint;bits:Tstringbits);
  589. constructor loadansi(ppufile:tcompilerppufile;bits:Tstringbits);
  590. {$else}
  591. constructor createansi(l : longint);
  592. constructor loadansi(ppufile:tcompilerppufile);
  593. {$endif}
  594. constructor createwide(l : longint);
  595. constructor loadwide(ppufile:tcompilerppufile);
  596. function getcopy : tstoreddef;override;
  597. function stringtypname:string;
  598. procedure ppuwrite(ppufile:tcompilerppufile);override;
  599. function gettypename:string;override;
  600. function getmangledparaname:string;override;
  601. function is_publishable : boolean;override;
  602. { debug }
  603. {$ifdef GDB}
  604. function stabstring : pchar;override;
  605. procedure concatstabto(asmlist : taasmoutput);override;
  606. {$endif GDB}
  607. { init/final }
  608. function needs_inittable : boolean;override;
  609. { rtti }
  610. procedure write_rtti_data(rt:trttitype);override;
  611. end;
  612. tenumdef = class(tstoreddef)
  613. minval,
  614. maxval : longint;
  615. has_jumps : boolean;
  616. firstenum : tsym; {tenumsym}
  617. basedef : tenumdef;
  618. basedefderef : tderef;
  619. constructor create;
  620. constructor create_subrange(_basedef:tenumdef;_min,_max:longint);
  621. constructor ppuload(ppufile:tcompilerppufile);
  622. destructor destroy;override;
  623. procedure ppuwrite(ppufile:tcompilerppufile);override;
  624. procedure buildderef;override;
  625. procedure deref;override;
  626. function gettypename:string;override;
  627. function is_publishable : boolean;override;
  628. procedure calcsavesize;
  629. procedure setmax(_max:longint);
  630. procedure setmin(_min:longint);
  631. function min:longint;
  632. function max:longint;
  633. { debug }
  634. {$ifdef GDB}
  635. function stabstring : pchar;override;
  636. {$endif GDB}
  637. { rtti }
  638. procedure write_rtti_data(rt:trttitype);override;
  639. procedure write_child_rtti_data(rt:trttitype);override;
  640. private
  641. procedure correct_owner_symtable;
  642. end;
  643. tsetdef = class(tstoreddef)
  644. elementtype : ttype;
  645. settype : tsettype;
  646. constructor create(const t:ttype;high : longint);
  647. constructor ppuload(ppufile:tcompilerppufile);
  648. destructor destroy;override;
  649. procedure ppuwrite(ppufile:tcompilerppufile);override;
  650. procedure buildderef;override;
  651. procedure deref;override;
  652. function gettypename:string;override;
  653. function is_publishable : boolean;override;
  654. { debug }
  655. {$ifdef GDB}
  656. function stabstring : pchar;override;
  657. procedure concatstabto(asmlist : taasmoutput);override;
  658. {$endif GDB}
  659. { rtti }
  660. procedure write_rtti_data(rt:trttitype);override;
  661. procedure write_child_rtti_data(rt:trttitype);override;
  662. end;
  663. Tdefmatch=(dm_exact,dm_equal,dm_convertl1);
  664. var
  665. aktobjectdef : tobjectdef; { used for private functions check !! }
  666. {$ifdef GDB}
  667. writing_def_stabs : boolean;
  668. { for STAB debugging }
  669. globaltypecount : word;
  670. pglobaltypecount : pword;
  671. {$endif GDB}
  672. { default types }
  673. generrortype, { error in definition }
  674. voidpointertype, { pointer for Void-Pointerdef }
  675. charpointertype, { pointer for Char-Pointerdef }
  676. voidfarpointertype,
  677. cformaltype, { unique formal definition }
  678. voidtype, { Void (procedure) }
  679. cchartype, { Char }
  680. cwidechartype, { WideChar }
  681. booltype, { boolean type }
  682. u8inttype, { 8-Bit unsigned integer }
  683. s8inttype, { 8-Bit signed integer }
  684. u16inttype, { 16-Bit unsigned integer }
  685. s16inttype, { 16-Bit signed integer }
  686. u32inttype, { 32-Bit unsigned integer }
  687. s32inttype, { 32-Bit signed integer }
  688. u64inttype, { 64-bit unsigned integer }
  689. s64inttype, { 64-bit signed integer }
  690. s32floattype, { pointer for realconstn }
  691. s64floattype, { pointer for realconstn }
  692. s80floattype, { pointer to type of temp. floats }
  693. s64currencytype, { pointer to a currency type }
  694. cshortstringtype, { pointer to type of short string const }
  695. clongstringtype, { pointer to type of long string const }
  696. {$ifdef ansistring_bits}
  697. cansistringtype16, { pointer to type of ansi string const }
  698. cansistringtype32, { pointer to type of ansi string const }
  699. cansistringtype64, { pointer to type of ansi string const }
  700. {$else}
  701. cansistringtype, { pointer to type of ansi string const }
  702. {$endif}
  703. cwidestringtype, { pointer to type of wide string const }
  704. openshortstringtype, { pointer to type of an open shortstring,
  705. needed for readln() }
  706. openchararraytype, { pointer to type of an open array of char,
  707. needed for readln() }
  708. cfiletype, { get the same definition for all file }
  709. { used for stabs }
  710. methodpointertype, { typecasting of methodpointers to extract self }
  711. { we use only one variant def for every variant class }
  712. cvarianttype,
  713. colevarianttype,
  714. { default integer type s32inttype on 32 bit systems, s64bittype on 64 bit systems }
  715. sinttype,
  716. uinttype,
  717. { unsigned ord type with the same size as a pointer }
  718. ptrinttype,
  719. { several types to simulate more or less C++ objects for GDB }
  720. vmttype,
  721. vmtarraytype,
  722. pvmttype : ttype; { type of classrefs, used for stabs }
  723. { pointer to the anchestor of all classes }
  724. class_tobject : tobjectdef;
  725. { pointer to the ancestor of all COM interfaces }
  726. interface_iunknown : tobjectdef;
  727. { pointer to the TGUID type
  728. of all interfaces }
  729. rec_tguid : trecorddef;
  730. const
  731. {$ifdef i386}
  732. pbestrealtype : ^ttype = @s80floattype;
  733. {$endif}
  734. {$ifdef x86_64}
  735. pbestrealtype : ^ttype = @s80floattype;
  736. {$endif}
  737. {$ifdef m68k}
  738. pbestrealtype : ^ttype = @s64floattype;
  739. {$endif}
  740. {$ifdef alpha}
  741. pbestrealtype : ^ttype = @s64floattype;
  742. {$endif}
  743. {$ifdef powerpc}
  744. pbestrealtype : ^ttype = @s64floattype;
  745. {$endif}
  746. {$ifdef ia64}
  747. pbestrealtype : ^ttype = @s64floattype;
  748. {$endif}
  749. {$ifdef SPARC}
  750. pbestrealtype : ^ttype = @s64floattype;
  751. {$endif SPARC}
  752. {$ifdef vis}
  753. pbestrealtype : ^ttype = @s64floattype;
  754. {$endif vis}
  755. {$ifdef ARM}
  756. pbestrealtype : ^ttype = @s64floattype;
  757. {$endif ARM}
  758. function reverseparaitems(p: tparaitem): tparaitem;
  759. function make_mangledname(const typeprefix:string;st:tsymtable;const suffix:string):string;
  760. { should be in the types unit, but the types unit uses the node stuff :( }
  761. function is_interfacecom(def: tdef): boolean;
  762. function is_interfacecorba(def: tdef): boolean;
  763. function is_interface(def: tdef): boolean;
  764. function is_object(def: tdef): boolean;
  765. function is_class(def: tdef): boolean;
  766. function is_cppclass(def: tdef): boolean;
  767. function is_class_or_interface(def: tdef): boolean;
  768. implementation
  769. uses
  770. {$ifdef Delphi}
  771. sysutils,
  772. {$else Delphi}
  773. strings,
  774. {$endif Delphi}
  775. { global }
  776. verbose,
  777. { target }
  778. systems,aasmcpu,paramgr,
  779. { symtable }
  780. symsym,symtable,symutil,defutil,
  781. { module }
  782. {$ifdef GDB}
  783. gdb,
  784. {$endif GDB}
  785. fmodule,
  786. { other }
  787. gendef
  788. ;
  789. {****************************************************************************
  790. Helpers
  791. ****************************************************************************}
  792. function reverseparaitems(p: tparaitem): tparaitem;
  793. var
  794. hp1, hp2: tparaitem;
  795. begin
  796. hp1:=nil;
  797. while assigned(p) do
  798. begin
  799. { pull out }
  800. hp2:=p;
  801. p:=tparaitem(p.next);
  802. { pull in }
  803. hp2.next:=hp1;
  804. hp1:=hp2;
  805. end;
  806. reverseparaitems:=hp1;
  807. end;
  808. function make_mangledname(const typeprefix:string;st:tsymtable;const suffix:string):string;
  809. var
  810. s,
  811. prefix : string;
  812. begin
  813. prefix:='';
  814. if not assigned(st) then
  815. internalerror(200204212);
  816. { sub procedures }
  817. while (st.symtabletype=localsymtable) do
  818. begin
  819. if st.defowner.deftype<>procdef then
  820. internalerror(200204173);
  821. s:=tprocdef(st.defowner).procsym.name;
  822. if tprocdef(st.defowner).overloadnumber>0 then
  823. s:=s+'$'+tostr(tprocdef(st.defowner).overloadnumber);
  824. prefix:=s+'$'+prefix;
  825. st:=st.defowner.owner;
  826. end;
  827. { object/classes symtable }
  828. if (st.symtabletype=objectsymtable) then
  829. begin
  830. if st.defowner.deftype<>objectdef then
  831. internalerror(200204174);
  832. prefix:=tobjectdef(st.defowner).objname^+'_$_'+prefix;
  833. st:=st.defowner.owner;
  834. end;
  835. { symtable must now be static or global }
  836. if not(st.symtabletype in [staticsymtable,globalsymtable]) then
  837. internalerror(200204175);
  838. result:='';
  839. if typeprefix<>'' then
  840. result:=result+typeprefix+'_';
  841. { Add P$ for program, which can have the same name as
  842. a unit }
  843. if (tsymtable(main_module.localsymtable)=st) and
  844. (not main_module.is_unit) then
  845. result:=result+'P$'+st.name^
  846. else
  847. result:=result+st.name^;
  848. if prefix<>'' then
  849. result:=result+'_'+prefix;
  850. if suffix<>'' then
  851. result:=result+'_'+suffix;
  852. { the Darwin assembler assumes that all symbols starting with 'L' are local }
  853. if (target_info.system = system_powerpc_darwin) and
  854. (result[1] = 'L') then
  855. result := '_' + result;
  856. end;
  857. {****************************************************************************
  858. TDEF (base class for definitions)
  859. ****************************************************************************}
  860. constructor tstoreddef.create;
  861. begin
  862. inherited create;
  863. savesize := 0;
  864. {$ifdef EXTDEBUG}
  865. fileinfo := aktfilepos;
  866. {$endif}
  867. if registerdef then
  868. symtablestack.registerdef(self);
  869. {$ifdef GDB}
  870. stab_state:=stab_state_unused;
  871. globalnb := 0;
  872. {$endif GDB}
  873. fillchar(localrttilab,sizeof(localrttilab),0);
  874. end;
  875. constructor tstoreddef.ppuloaddef(ppufile:tcompilerppufile);
  876. begin
  877. inherited create;
  878. {$ifdef EXTDEBUG}
  879. fillchar(fileinfo,sizeof(fileinfo),0);
  880. {$endif}
  881. {$ifdef GDB}
  882. stab_state:=stab_state_unused;
  883. globalnb := 0;
  884. {$endif GDB}
  885. fillchar(localrttilab,sizeof(localrttilab),0);
  886. { load }
  887. indexnr:=ppufile.getword;
  888. ppufile.getderef(typesymderef);
  889. ppufile.getsmallset(defoptions);
  890. if df_has_rttitable in defoptions then
  891. ppufile.getderef(rttitablesymderef);
  892. if df_has_inittable in defoptions then
  893. ppufile.getderef(inittablesymderef);
  894. end;
  895. procedure Tstoreddef.reset;
  896. begin
  897. {$ifdef GDB}
  898. stab_state:=stab_state_unused;
  899. {$endif GDB}
  900. if assigned(rttitablesym) then
  901. trttisym(rttitablesym).lab := nil;
  902. if assigned(inittablesym) then
  903. trttisym(inittablesym).lab := nil;
  904. localrttilab[initrtti]:=nil;
  905. localrttilab[fullrtti]:=nil;
  906. end;
  907. function tstoreddef.getcopy : tstoreddef;
  908. begin
  909. Message(sym_e_cant_create_unique_type);
  910. getcopy:=terrordef.create;
  911. end;
  912. procedure tstoreddef.ppuwritedef(ppufile:tcompilerppufile);
  913. begin
  914. ppufile.putword(indexnr);
  915. ppufile.putderef(typesymderef);
  916. ppufile.putsmallset(defoptions);
  917. if df_has_rttitable in defoptions then
  918. ppufile.putderef(rttitablesymderef);
  919. if df_has_inittable in defoptions then
  920. ppufile.putderef(inittablesymderef);
  921. {$ifdef GDB}
  922. if globalnb=0 then
  923. begin
  924. if (cs_gdb_dbx in aktglobalswitches) and
  925. assigned(owner) then
  926. globalnb := owner.getnewtypecount
  927. else
  928. set_globalnb;
  929. end;
  930. {$endif GDB}
  931. end;
  932. procedure tstoreddef.buildderef;
  933. begin
  934. typesymderef.build(typesym);
  935. rttitablesymderef.build(rttitablesym);
  936. inittablesymderef.build(inittablesym);
  937. end;
  938. procedure tstoreddef.buildderefimpl;
  939. begin
  940. end;
  941. procedure tstoreddef.deref;
  942. begin
  943. typesym:=ttypesym(typesymderef.resolve);
  944. if df_has_rttitable in defoptions then
  945. rttitablesym:=trttisym(rttitablesymderef.resolve);
  946. if df_has_inittable in defoptions then
  947. inittablesym:=trttisym(inittablesymderef.resolve);
  948. end;
  949. procedure tstoreddef.derefimpl;
  950. begin
  951. end;
  952. function tstoreddef.size : longint;
  953. begin
  954. size:=savesize;
  955. end;
  956. function tstoreddef.alignment : longint;
  957. begin
  958. { natural alignment by default }
  959. alignment:=size_2_align(savesize);
  960. end;
  961. {$ifdef GDB}
  962. procedure tstoreddef.set_globalnb;
  963. begin
  964. globalnb:=PGlobalTypeCount^;
  965. inc(PglobalTypeCount^);
  966. end;
  967. function Tstoreddef.get_var_value(const s:string):string;
  968. begin
  969. if s='numberstring' then
  970. get_var_value:=numberstring
  971. else if s='sym_name' then
  972. if assigned(typesym) then
  973. get_var_value:=Ttypesym(typesym).name
  974. else
  975. get_var_value:=' '
  976. else if s='N_LSYM' then
  977. get_var_value:=tostr(N_LSYM)
  978. else if s='savesize' then
  979. get_var_value:=tostr(savesize);
  980. end;
  981. function Tstoreddef.stabstr_evaluate(const s:string;const vars:array of string):Pchar;
  982. begin
  983. stabstr_evaluate:=string_evaluate(s,@get_var_value,vars);
  984. end;
  985. function tstoreddef.stabstring : pchar;
  986. begin
  987. stabstring:=stabstr_evaluate('t${numberstring};',[]);
  988. end;
  989. function tstoreddef.numberstring : string;
  990. begin
  991. { Stab must already be written, or we must be busy writing it }
  992. if writing_def_stabs and
  993. not(stab_state in [stab_state_writing,stab_state_written]) then
  994. internalerror(200403091);
  995. { Keep track of used stabs, this info is only usefull for stabs
  996. referenced by the symbols. Definitions will always include all
  997. required stabs }
  998. if stab_state=stab_state_unused then
  999. stab_state:=stab_state_used;
  1000. { Need a new number? }
  1001. if globalnb=0 then
  1002. begin
  1003. if (cs_gdb_dbx in aktglobalswitches) and
  1004. assigned(owner) then
  1005. globalnb := owner.getnewtypecount
  1006. else
  1007. set_globalnb;
  1008. end;
  1009. if (cs_gdb_dbx in aktglobalswitches) and
  1010. assigned(typesym) and
  1011. (ttypesym(typesym).owner.unitid<>0) then
  1012. result:='('+tostr(ttypesym(typesym).owner.unitid)+','+tostr(tstoreddef(ttypesym(typesym).restype.def).globalnb)+')'
  1013. else
  1014. result:=tostr(globalnb);
  1015. end;
  1016. function tstoreddef.allstabstring : pchar;
  1017. var
  1018. stabchar : string[2];
  1019. ss,st,su : pchar;
  1020. begin
  1021. ss := stabstring;
  1022. stabchar := 't';
  1023. if deftype in tagtypes then
  1024. stabchar := 'Tt';
  1025. { Here we maybe generate a type, so we have to use numberstring }
  1026. st:=stabstr_evaluate('"${sym_name}:$1$2=',[stabchar,numberstring]);
  1027. reallocmem(st,strlen(ss)+512);
  1028. { line info is set to 0 for all defs, because the def can be in an other
  1029. unit and then the linenumber is invalid in the current sourcefile }
  1030. su:=stabstr_evaluate('",${N_LSYM},0,0,0',[]);
  1031. strcopy(strecopy(strend(st),ss),su);
  1032. reallocmem(st,strlen(st)+1);
  1033. allstabstring:=st;
  1034. strdispose(ss);
  1035. strdispose(su);
  1036. end;
  1037. procedure tstoreddef.concatstabto(asmlist : taasmoutput);
  1038. var
  1039. stab_str : pchar;
  1040. begin
  1041. if (stab_state in [stab_state_writing,stab_state_written]) then
  1042. exit;
  1043. If cs_gdb_dbx in aktglobalswitches then
  1044. begin
  1045. { otherwise you get two of each def }
  1046. If assigned(typesym) then
  1047. begin
  1048. if (ttypesym(typesym).owner = nil) or
  1049. ((ttypesym(typesym).owner.symtabletype = globalsymtable) and
  1050. tglobalsymtable(ttypesym(typesym).owner).dbx_count_ok) then
  1051. begin
  1052. {with DBX we get the definition from the other objects }
  1053. stab_state := stab_state_written;
  1054. exit;
  1055. end;
  1056. end;
  1057. end;
  1058. { to avoid infinite loops }
  1059. stab_state := stab_state_writing;
  1060. stab_str := allstabstring;
  1061. asmList.concat(Tai_stabs.Create(stab_str));
  1062. stab_state := stab_state_written;
  1063. end;
  1064. {$endif GDB}
  1065. procedure tstoreddef.write_rtti_name;
  1066. var
  1067. str : string;
  1068. begin
  1069. { name }
  1070. if assigned(typesym) then
  1071. begin
  1072. str:=ttypesym(typesym).realname;
  1073. rttiList.concat(Tai_string.Create(chr(length(str))+str));
  1074. end
  1075. else
  1076. rttiList.concat(Tai_string.Create(#0))
  1077. end;
  1078. procedure tstoreddef.write_rtti_data(rt:trttitype);
  1079. begin
  1080. rttilist.concat(tai_const.create_8bit(tkUnknown));
  1081. write_rtti_name;
  1082. end;
  1083. procedure tstoreddef.write_child_rtti_data(rt:trttitype);
  1084. begin
  1085. end;
  1086. function tstoreddef.get_rtti_label(rt:trttitype) : tasmsymbol;
  1087. begin
  1088. { try to reuse persistent rtti data }
  1089. if (rt=fullrtti) and (df_has_rttitable in defoptions) then
  1090. get_rtti_label:=trttisym(rttitablesym).get_label
  1091. else
  1092. if (rt=initrtti) and (df_has_inittable in defoptions) then
  1093. get_rtti_label:=trttisym(inittablesym).get_label
  1094. else
  1095. begin
  1096. if not assigned(localrttilab[rt]) then
  1097. begin
  1098. objectlibrary.getdatalabel(localrttilab[rt]);
  1099. write_child_rtti_data(rt);
  1100. maybe_new_object_file(rttiList);
  1101. new_section(rttiList,sec_rodata,localrttilab[rt].name,const_align(sizeof(aint)));
  1102. rttiList.concat(Tai_symbol.Create_global(localrttilab[rt],0));
  1103. write_rtti_data(rt);
  1104. rttiList.concat(Tai_symbol_end.Create(localrttilab[rt]));
  1105. end;
  1106. get_rtti_label:=localrttilab[rt];
  1107. end;
  1108. end;
  1109. { returns true, if the definition can be published }
  1110. function tstoreddef.is_publishable : boolean;
  1111. begin
  1112. is_publishable:=false;
  1113. end;
  1114. { needs an init table }
  1115. function tstoreddef.needs_inittable : boolean;
  1116. begin
  1117. needs_inittable:=false;
  1118. end;
  1119. function tstoreddef.is_intregable : boolean;
  1120. begin
  1121. is_intregable:=false;
  1122. case deftype of
  1123. pointerdef,
  1124. enumdef:
  1125. is_intregable:=true;
  1126. procvardef :
  1127. is_intregable:=not(po_methodpointer in tprocvardef(self).procoptions);
  1128. orddef :
  1129. case torddef(self).typ of
  1130. bool8bit,bool16bit,bool32bit,
  1131. u8bit,u16bit,u32bit,
  1132. s8bit,s16bit,s32bit,
  1133. uchar, uwidechar:
  1134. is_intregable:=true;
  1135. end;
  1136. objectdef:
  1137. is_intregable:=is_class(self) or is_interface(self);
  1138. setdef:
  1139. is_intregable:=(tsetdef(self).settype=smallset);
  1140. end;
  1141. end;
  1142. function tstoreddef.is_fpuregable : boolean;
  1143. begin
  1144. is_fpuregable:=(deftype=floatdef);
  1145. end;
  1146. {****************************************************************************
  1147. Tstringdef
  1148. ****************************************************************************}
  1149. constructor tstringdef.createshort(l : byte);
  1150. begin
  1151. inherited create;
  1152. string_typ:=st_shortstring;
  1153. deftype:=stringdef;
  1154. len:=l;
  1155. savesize:=len+1;
  1156. end;
  1157. constructor tstringdef.loadshort(ppufile:tcompilerppufile);
  1158. begin
  1159. inherited ppuloaddef(ppufile);
  1160. string_typ:=st_shortstring;
  1161. deftype:=stringdef;
  1162. len:=ppufile.getbyte;
  1163. savesize:=len+1;
  1164. end;
  1165. constructor tstringdef.createlong(l : longint);
  1166. begin
  1167. inherited create;
  1168. string_typ:=st_longstring;
  1169. deftype:=stringdef;
  1170. len:=l;
  1171. savesize:=sizeof(aint);
  1172. end;
  1173. constructor tstringdef.loadlong(ppufile:tcompilerppufile);
  1174. begin
  1175. inherited ppuloaddef(ppufile);
  1176. deftype:=stringdef;
  1177. string_typ:=st_longstring;
  1178. len:=ppufile.getlongint;
  1179. savesize:=sizeof(aint);
  1180. end;
  1181. {$ifdef ansistring_bits}
  1182. constructor tstringdef.createansi(l:longint;bits:Tstringbits);
  1183. begin
  1184. inherited create;
  1185. case bits of
  1186. sb_16:
  1187. string_typ:=st_ansistring16;
  1188. sb_32:
  1189. string_typ:=st_ansistring32;
  1190. sb_64:
  1191. string_typ:=st_ansistring64;
  1192. end;
  1193. deftype:=stringdef;
  1194. len:=l;
  1195. savesize:=POINTER_SIZE;
  1196. end;
  1197. constructor tstringdef.loadansi(ppufile:tcompilerppufile;bits:Tstringbits);
  1198. begin
  1199. inherited ppuloaddef(ppufile);
  1200. deftype:=stringdef;
  1201. case bits of
  1202. sb_16:
  1203. string_typ:=st_ansistring16;
  1204. sb_32:
  1205. string_typ:=st_ansistring32;
  1206. sb_64:
  1207. string_typ:=st_ansistring64;
  1208. end;
  1209. len:=ppufile.getlongint;
  1210. savesize:=POINTER_SIZE;
  1211. end;
  1212. {$else}
  1213. constructor tstringdef.createansi(l:longint);
  1214. begin
  1215. inherited create;
  1216. string_typ:=st_ansistring;
  1217. deftype:=stringdef;
  1218. len:=l;
  1219. savesize:=sizeof(aint);
  1220. end;
  1221. constructor tstringdef.loadansi(ppufile:tcompilerppufile);
  1222. begin
  1223. inherited ppuloaddef(ppufile);
  1224. deftype:=stringdef;
  1225. string_typ:=st_ansistring;
  1226. len:=ppufile.getlongint;
  1227. savesize:=sizeof(aint);
  1228. end;
  1229. {$endif}
  1230. constructor tstringdef.createwide(l : longint);
  1231. begin
  1232. inherited create;
  1233. string_typ:=st_widestring;
  1234. deftype:=stringdef;
  1235. len:=l;
  1236. savesize:=sizeof(aint);
  1237. end;
  1238. constructor tstringdef.loadwide(ppufile:tcompilerppufile);
  1239. begin
  1240. inherited ppuloaddef(ppufile);
  1241. deftype:=stringdef;
  1242. string_typ:=st_widestring;
  1243. len:=ppufile.getlongint;
  1244. savesize:=sizeof(aint);
  1245. end;
  1246. function tstringdef.getcopy : tstoreddef;
  1247. begin
  1248. result:=tstringdef.create;
  1249. result.deftype:=stringdef;
  1250. tstringdef(result).string_typ:=string_typ;
  1251. tstringdef(result).len:=len;
  1252. tstringdef(result).savesize:=savesize;
  1253. end;
  1254. function tstringdef.stringtypname:string;
  1255. {$ifdef ansistring_bits}
  1256. const
  1257. typname:array[tstringtype] of string[9]=('',
  1258. 'shortstr','longstr','ansistr16','ansistr32','ansistr64','widestr'
  1259. );
  1260. {$else}
  1261. const
  1262. typname:array[tstringtype] of string[8]=('',
  1263. 'shortstr','longstr','ansistr','widestr'
  1264. );
  1265. {$endif}
  1266. begin
  1267. stringtypname:=typname[string_typ];
  1268. end;
  1269. procedure tstringdef.ppuwrite(ppufile:tcompilerppufile);
  1270. begin
  1271. inherited ppuwritedef(ppufile);
  1272. if string_typ=st_shortstring then
  1273. begin
  1274. {$ifdef extdebug}
  1275. if len > 255 then internalerror(12122002);
  1276. {$endif}
  1277. ppufile.putbyte(byte(len))
  1278. end
  1279. else
  1280. ppufile.putlongint(len);
  1281. case string_typ of
  1282. st_shortstring : ppufile.writeentry(ibshortstringdef);
  1283. st_longstring : ppufile.writeentry(iblongstringdef);
  1284. {$ifdef ansistring_bits}
  1285. st_ansistring16 : ppufile.writeentry(ibansistring16def);
  1286. st_ansistring32 : ppufile.writeentry(ibansistring32def);
  1287. st_ansistring64 : ppufile.writeentry(ibansistring64def);
  1288. {$else}
  1289. st_ansistring : ppufile.writeentry(ibansistringdef);
  1290. {$endif}
  1291. st_widestring : ppufile.writeentry(ibwidestringdef);
  1292. end;
  1293. end;
  1294. {$ifdef GDB}
  1295. function tstringdef.stabstring : pchar;
  1296. var
  1297. bytest,charst,longst : string;
  1298. slen : longint;
  1299. begin
  1300. case string_typ of
  1301. st_shortstring:
  1302. begin
  1303. charst:=tstoreddef(cchartype.def).numberstring;
  1304. { this is what I found in stabs.texinfo but
  1305. gdb 4.12 for go32 doesn't understand that !! }
  1306. {$IfDef GDBknowsstrings}
  1307. stabstring:=stabstr_evaluate('n$1;$2',[charst,tostr(len)]);
  1308. {$else}
  1309. { fix length of openshortstring }
  1310. slen:=len;
  1311. if slen=0 then
  1312. slen:=255;
  1313. bytest:=tstoreddef(u8inttype.def).numberstring;
  1314. stabstring:=stabstr_evaluate('s$1length:$2,0,8;st:ar$2;1;$3;$4,8,$5;;',
  1315. [tostr(slen+1),bytest,tostr(slen),charst,tostr(slen*8)]);
  1316. {$EndIf}
  1317. end;
  1318. st_longstring:
  1319. begin
  1320. charst:=tstoreddef(cchartype.def).numberstring;
  1321. { this is what I found in stabs.texinfo but
  1322. gdb 4.12 for go32 doesn't understand that !! }
  1323. {$IfDef GDBknowsstrings}
  1324. stabstring:=stabstr_evaluate('n$1;$2',[charst,tostr(len)]);
  1325. {$else}
  1326. bytest:=tstoreddef(u8inttype.def).numberstring;
  1327. longst:=tstoreddef(u32inttype.def).numberstring;
  1328. stabstring:=stabstr_evaluate('s$1length:$2,0,32;dummy:$6,32,8;st:ar$2;1;$3;$4,40,$5;;',
  1329. [tostr(len+5),longst,tostr(len),charst,tostr(len*8),bytest]);
  1330. {$EndIf}
  1331. end;
  1332. {$ifdef ansistring_bits}
  1333. st_ansistring16,st_ansistring32,st_ansistring64:
  1334. {$else}
  1335. st_ansistring:
  1336. {$endif}
  1337. begin
  1338. { an ansi string looks like a pchar easy !! }
  1339. charst:=tstoreddef(cchartype.def).numberstring;
  1340. stabstring:=strpnew('*'+charst);
  1341. end;
  1342. st_widestring:
  1343. begin
  1344. { an ansi string looks like a pwidechar easy !! }
  1345. charst:=tstoreddef(cwidechartype.def).numberstring;
  1346. stabstring:=strpnew('*'+charst);
  1347. end;
  1348. end;
  1349. end;
  1350. procedure tstringdef.concatstabto(asmlist:taasmoutput);
  1351. begin
  1352. if (stab_state in [stab_state_writing,stab_state_written]) then
  1353. exit;
  1354. case string_typ of
  1355. st_shortstring:
  1356. begin
  1357. tstoreddef(cchartype.def).concatstabto(asmlist);
  1358. {$IfNDef GDBknowsstrings}
  1359. tstoreddef(u8inttype.def).concatstabto(asmlist);
  1360. {$EndIf}
  1361. end;
  1362. st_longstring:
  1363. begin
  1364. tstoreddef(cchartype.def).concatstabto(asmlist);
  1365. {$IfNDef GDBknowsstrings}
  1366. tstoreddef(u8inttype.def).concatstabto(asmlist);
  1367. tstoreddef(u32inttype.def).concatstabto(asmlist);
  1368. {$EndIf}
  1369. end;
  1370. {$ifdef ansistring_bits}
  1371. st_ansistring16,st_ansistring32,st_ansistring64:
  1372. {$else}
  1373. st_ansistring:
  1374. {$endif}
  1375. tstoreddef(cchartype.def).concatstabto(asmlist);
  1376. st_widestring:
  1377. tstoreddef(cwidechartype.def).concatstabto(asmlist);
  1378. end;
  1379. inherited concatstabto(asmlist);
  1380. end;
  1381. {$endif GDB}
  1382. function tstringdef.needs_inittable : boolean;
  1383. begin
  1384. {$ifdef ansistring_bits}
  1385. needs_inittable:=string_typ in [st_ansistring16,st_ansistring32,st_ansistring64,st_widestring];
  1386. {$else}
  1387. needs_inittable:=string_typ in [st_ansistring,st_widestring];
  1388. {$endif}
  1389. end;
  1390. function tstringdef.gettypename : string;
  1391. {$ifdef ansistring_bits}
  1392. const
  1393. names : array[tstringtype] of string[20] = ('',
  1394. 'shortstring','longstring','ansistring16','ansistring32','ansistring64','widestring');
  1395. {$else}
  1396. const
  1397. names : array[tstringtype] of string[20] = ('',
  1398. 'ShortString','LongString','AnsiString','WideString');
  1399. {$endif}
  1400. begin
  1401. gettypename:=names[string_typ];
  1402. end;
  1403. procedure tstringdef.write_rtti_data(rt:trttitype);
  1404. begin
  1405. case string_typ of
  1406. {$ifdef ansistring_bits}
  1407. st_ansistring16:
  1408. begin
  1409. rttiList.concat(Tai_const.Create_8bit(tkA16String));
  1410. write_rtti_name;
  1411. end;
  1412. st_ansistring32:
  1413. begin
  1414. rttiList.concat(Tai_const.Create_8bit(tkA32String));
  1415. write_rtti_name;
  1416. end;
  1417. st_ansistring64:
  1418. begin
  1419. rttiList.concat(Tai_const.Create_8bit(tkA64String));
  1420. write_rtti_name;
  1421. end;
  1422. {$else}
  1423. st_ansistring:
  1424. begin
  1425. rttiList.concat(Tai_const.Create_8bit(tkAString));
  1426. write_rtti_name;
  1427. end;
  1428. {$endif}
  1429. st_widestring:
  1430. begin
  1431. rttiList.concat(Tai_const.Create_8bit(tkWString));
  1432. write_rtti_name;
  1433. end;
  1434. st_longstring:
  1435. begin
  1436. rttiList.concat(Tai_const.Create_8bit(tkLString));
  1437. write_rtti_name;
  1438. end;
  1439. st_shortstring:
  1440. begin
  1441. rttiList.concat(Tai_const.Create_8bit(tkSString));
  1442. write_rtti_name;
  1443. rttiList.concat(Tai_const.Create_8bit(len));
  1444. end;
  1445. end;
  1446. end;
  1447. function tstringdef.getmangledparaname : string;
  1448. begin
  1449. getmangledparaname:='STRING';
  1450. end;
  1451. function tstringdef.is_publishable : boolean;
  1452. begin
  1453. is_publishable:=true;
  1454. end;
  1455. {****************************************************************************
  1456. TENUMDEF
  1457. ****************************************************************************}
  1458. constructor tenumdef.create;
  1459. begin
  1460. inherited create;
  1461. deftype:=enumdef;
  1462. minval:=0;
  1463. maxval:=0;
  1464. calcsavesize;
  1465. has_jumps:=false;
  1466. basedef:=nil;
  1467. firstenum:=nil;
  1468. correct_owner_symtable;
  1469. end;
  1470. constructor tenumdef.create_subrange(_basedef:tenumdef;_min,_max:longint);
  1471. begin
  1472. inherited create;
  1473. deftype:=enumdef;
  1474. minval:=_min;
  1475. maxval:=_max;
  1476. basedef:=_basedef;
  1477. calcsavesize;
  1478. has_jumps:=false;
  1479. firstenum:=basedef.firstenum;
  1480. while assigned(firstenum) and (tenumsym(firstenum).value<>minval) do
  1481. firstenum:=tenumsym(firstenum).nextenum;
  1482. correct_owner_symtable;
  1483. end;
  1484. constructor tenumdef.ppuload(ppufile:tcompilerppufile);
  1485. begin
  1486. inherited ppuloaddef(ppufile);
  1487. deftype:=enumdef;
  1488. ppufile.getderef(basedefderef);
  1489. minval:=ppufile.getlongint;
  1490. maxval:=ppufile.getlongint;
  1491. savesize:=ppufile.getlongint;
  1492. has_jumps:=false;
  1493. firstenum:=Nil;
  1494. end;
  1495. procedure tenumdef.calcsavesize;
  1496. begin
  1497. if (aktpackenum=4) or (min<0) or (max>65535) then
  1498. savesize:=4
  1499. else
  1500. if (aktpackenum=2) or (min<0) or (max>255) then
  1501. savesize:=2
  1502. else
  1503. savesize:=1;
  1504. end;
  1505. procedure tenumdef.setmax(_max:longint);
  1506. begin
  1507. maxval:=_max;
  1508. calcsavesize;
  1509. end;
  1510. procedure tenumdef.setmin(_min:longint);
  1511. begin
  1512. minval:=_min;
  1513. calcsavesize;
  1514. end;
  1515. function tenumdef.min:longint;
  1516. begin
  1517. min:=minval;
  1518. end;
  1519. function tenumdef.max:longint;
  1520. begin
  1521. max:=maxval;
  1522. end;
  1523. procedure tenumdef.buildderef;
  1524. begin
  1525. inherited buildderef;
  1526. basedefderef.build(basedef);
  1527. end;
  1528. procedure tenumdef.deref;
  1529. begin
  1530. inherited deref;
  1531. basedef:=tenumdef(basedefderef.resolve);
  1532. end;
  1533. destructor tenumdef.destroy;
  1534. begin
  1535. inherited destroy;
  1536. end;
  1537. procedure tenumdef.ppuwrite(ppufile:tcompilerppufile);
  1538. begin
  1539. inherited ppuwritedef(ppufile);
  1540. ppufile.putderef(basedefderef);
  1541. ppufile.putlongint(min);
  1542. ppufile.putlongint(max);
  1543. ppufile.putlongint(savesize);
  1544. ppufile.writeentry(ibenumdef);
  1545. end;
  1546. { used for enumdef because the symbols are
  1547. inserted in the owner symtable }
  1548. procedure tenumdef.correct_owner_symtable;
  1549. var
  1550. st : tsymtable;
  1551. begin
  1552. if assigned(owner) and
  1553. (owner.symtabletype in [recordsymtable,objectsymtable]) then
  1554. begin
  1555. owner.defindex.deleteindex(self);
  1556. st:=owner;
  1557. while (st.symtabletype in [recordsymtable,objectsymtable]) do
  1558. st:=st.next;
  1559. st.registerdef(self);
  1560. end;
  1561. end;
  1562. {$ifdef GDB}
  1563. function tenumdef.stabstring : pchar;
  1564. var st:Pchar;
  1565. p:Tenumsym;
  1566. s:string;
  1567. memsize,stl:cardinal;
  1568. begin
  1569. memsize:=memsizeinc;
  1570. getmem(st,memsize);
  1571. { we can specify the size with @s<size>; prefix PM }
  1572. if savesize <> std_param_align then
  1573. strpcopy(st,'@s'+tostr(savesize*8)+';e')
  1574. else
  1575. strpcopy(st,'e');
  1576. p := tenumsym(firstenum);
  1577. stl:=strlen(st);
  1578. while assigned(p) do
  1579. begin
  1580. s :=p.name+':'+tostr(p.value)+',';
  1581. { place for the ending ';' also }
  1582. if (stl+length(s)+1>=memsize) then
  1583. begin
  1584. inc(memsize,memsizeinc);
  1585. reallocmem(st,memsize);
  1586. end;
  1587. strpcopy(st+stl,s);
  1588. inc(stl,length(s));
  1589. p:=p.nextenum;
  1590. end;
  1591. st[stl]:=';';
  1592. st[stl+1]:=#0;
  1593. reallocmem(st,stl+2);
  1594. stabstring:=st;
  1595. end;
  1596. {$endif GDB}
  1597. procedure tenumdef.write_child_rtti_data(rt:trttitype);
  1598. begin
  1599. if assigned(basedef) then
  1600. basedef.get_rtti_label(rt);
  1601. end;
  1602. procedure tenumdef.write_rtti_data(rt:trttitype);
  1603. var
  1604. hp : tenumsym;
  1605. begin
  1606. rttiList.concat(Tai_const.Create_8bit(tkEnumeration));
  1607. write_rtti_name;
  1608. case savesize of
  1609. 1:
  1610. rttiList.concat(Tai_const.Create_8bit(otUByte));
  1611. 2:
  1612. rttiList.concat(Tai_const.Create_8bit(otUWord));
  1613. 4:
  1614. rttiList.concat(Tai_const.Create_8bit(otULong));
  1615. end;
  1616. rttiList.concat(Tai_const.Create_32bit(min));
  1617. rttiList.concat(Tai_const.Create_32bit(max));
  1618. if assigned(basedef) then
  1619. rttiList.concat(Tai_const.Create_sym(basedef.get_rtti_label(rt)))
  1620. else
  1621. rttiList.concat(Tai_const.create_sym(nil));
  1622. hp:=tenumsym(firstenum);
  1623. while assigned(hp) do
  1624. begin
  1625. rttiList.concat(Tai_const.Create_8bit(length(hp.realname)));
  1626. rttiList.concat(Tai_string.Create(hp.realname));
  1627. hp:=hp.nextenum;
  1628. end;
  1629. rttiList.concat(Tai_const.Create_8bit(0));
  1630. end;
  1631. function tenumdef.is_publishable : boolean;
  1632. begin
  1633. is_publishable:=true;
  1634. end;
  1635. function tenumdef.gettypename : string;
  1636. begin
  1637. gettypename:='<enumeration type>';
  1638. end;
  1639. {****************************************************************************
  1640. TORDDEF
  1641. ****************************************************************************}
  1642. constructor torddef.create(t : tbasetype;v,b : TConstExprInt);
  1643. begin
  1644. inherited create;
  1645. deftype:=orddef;
  1646. low:=v;
  1647. high:=b;
  1648. typ:=t;
  1649. setsize;
  1650. end;
  1651. constructor torddef.ppuload(ppufile:tcompilerppufile);
  1652. begin
  1653. inherited ppuloaddef(ppufile);
  1654. deftype:=orddef;
  1655. typ:=tbasetype(ppufile.getbyte);
  1656. if sizeof(TConstExprInt)=8 then
  1657. begin
  1658. low:=ppufile.getint64;
  1659. high:=ppufile.getint64;
  1660. end
  1661. else
  1662. begin
  1663. low:=ppufile.getlongint;
  1664. high:=ppufile.getlongint;
  1665. end;
  1666. setsize;
  1667. end;
  1668. function torddef.getcopy : tstoreddef;
  1669. begin
  1670. result:=torddef.create(typ,low,high);
  1671. result.deftype:=orddef;
  1672. torddef(result).low:=low;
  1673. torddef(result).high:=high;
  1674. torddef(result).typ:=typ;
  1675. torddef(result).savesize:=savesize;
  1676. end;
  1677. procedure torddef.setsize;
  1678. const
  1679. sizetbl : array[tbasetype] of longint = (
  1680. 0,
  1681. 1,2,4,8,
  1682. 1,2,4,8,
  1683. 1,2,4,
  1684. 1,2,8
  1685. );
  1686. begin
  1687. savesize:=sizetbl[typ];
  1688. end;
  1689. procedure torddef.ppuwrite(ppufile:tcompilerppufile);
  1690. begin
  1691. inherited ppuwritedef(ppufile);
  1692. ppufile.putbyte(byte(typ));
  1693. if sizeof(TConstExprInt)=8 then
  1694. begin
  1695. ppufile.putint64(low);
  1696. ppufile.putint64(high);
  1697. end
  1698. else
  1699. begin
  1700. ppufile.putlongint(low);
  1701. ppufile.putlongint(high);
  1702. end;
  1703. ppufile.writeentry(iborddef);
  1704. end;
  1705. {$ifdef GDB}
  1706. function torddef.stabstring : pchar;
  1707. begin
  1708. if cs_gdb_valgrind in aktglobalswitches then
  1709. begin
  1710. case typ of
  1711. uvoid :
  1712. stabstring := strpnew(numberstring);
  1713. bool8bit,
  1714. bool16bit,
  1715. bool32bit :
  1716. stabstring := stabstr_evaluate('r${numberstring};0;255;',[]);
  1717. u32bit,
  1718. s64bit,
  1719. u64bit :
  1720. stabstring:=stabstr_evaluate('r${numberstring};0;-1;',[]);
  1721. else
  1722. stabstring:=stabstr_evaluate('r${numberstring};$1;$2;',[tostr(longint(low)),tostr(longint(high))]);
  1723. end;
  1724. end
  1725. else
  1726. begin
  1727. case typ of
  1728. uvoid :
  1729. stabstring := strpnew(numberstring);
  1730. uchar :
  1731. stabstring := strpnew('-20;');
  1732. uwidechar :
  1733. stabstring := strpnew('-30;');
  1734. bool8bit :
  1735. stabstring := strpnew('-21;');
  1736. bool16bit :
  1737. stabstring := strpnew('-22;');
  1738. bool32bit :
  1739. stabstring := strpnew('-23;');
  1740. u64bit :
  1741. stabstring := strpnew('-32;');
  1742. s64bit :
  1743. stabstring := strpnew('-31;');
  1744. {u32bit : stabstring := tstoreddef(s32inttype.def).numberstring+';0;-1;'); }
  1745. else
  1746. stabstring:=stabstr_evaluate('r${numberstring};$1;$2;',[tostr(longint(low)),tostr(longint(high))]);
  1747. end;
  1748. end;
  1749. end;
  1750. {$endif GDB}
  1751. procedure torddef.write_rtti_data(rt:trttitype);
  1752. procedure dointeger;
  1753. const
  1754. trans : array[tbasetype] of byte =
  1755. (otUByte{otNone},
  1756. otUByte,otUWord,otULong,otUByte{otNone},
  1757. otSByte,otSWord,otSLong,otUByte{otNone},
  1758. otUByte,otUWord,otULong,
  1759. otUByte,otUWord,otUByte);
  1760. begin
  1761. write_rtti_name;
  1762. rttiList.concat(Tai_const.Create_8bit(byte(trans[typ])));
  1763. rttiList.concat(Tai_const.Create_32bit(longint(low)));
  1764. rttiList.concat(Tai_const.Create_32bit(longint(high)));
  1765. end;
  1766. begin
  1767. case typ of
  1768. s64bit :
  1769. begin
  1770. rttiList.concat(Tai_const.Create_8bit(tkInt64));
  1771. write_rtti_name;
  1772. { low }
  1773. rttiList.concat(Tai_const.Create_64bit(int64($80000000) shl 32));
  1774. { high }
  1775. rttiList.concat(Tai_const.Create_64bit((int64($7fffffff) shl 32) or int64($ffffffff)));
  1776. end;
  1777. u64bit :
  1778. begin
  1779. rttiList.concat(Tai_const.Create_8bit(tkQWord));
  1780. write_rtti_name;
  1781. { low }
  1782. rttiList.concat(Tai_const.Create_64bit(0));
  1783. { high }
  1784. rttiList.concat(Tai_const.Create_64bit(int64((int64($ffffffff) shl 32) or int64($ffffffff))));
  1785. end;
  1786. bool8bit:
  1787. begin
  1788. rttiList.concat(Tai_const.Create_8bit(tkBool));
  1789. dointeger;
  1790. end;
  1791. uchar:
  1792. begin
  1793. rttiList.concat(Tai_const.Create_8bit(tkChar));
  1794. dointeger;
  1795. end;
  1796. uwidechar:
  1797. begin
  1798. rttiList.concat(Tai_const.Create_8bit(tkWChar));
  1799. dointeger;
  1800. end;
  1801. else
  1802. begin
  1803. rttiList.concat(Tai_const.Create_8bit(tkInteger));
  1804. dointeger;
  1805. end;
  1806. end;
  1807. end;
  1808. function torddef.is_publishable : boolean;
  1809. begin
  1810. is_publishable:=(typ<>uvoid);
  1811. end;
  1812. function torddef.gettypename : string;
  1813. const
  1814. names : array[tbasetype] of string[20] = (
  1815. 'untyped',
  1816. 'Byte','Word','DWord','QWord',
  1817. 'ShortInt','SmallInt','LongInt','Int64',
  1818. 'Boolean','WordBool','LongBool',
  1819. 'Char','WideChar','Currency');
  1820. begin
  1821. gettypename:=names[typ];
  1822. end;
  1823. {****************************************************************************
  1824. TFLOATDEF
  1825. ****************************************************************************}
  1826. constructor tfloatdef.create(t : tfloattype);
  1827. begin
  1828. inherited create;
  1829. deftype:=floatdef;
  1830. typ:=t;
  1831. setsize;
  1832. end;
  1833. constructor tfloatdef.ppuload(ppufile:tcompilerppufile);
  1834. begin
  1835. inherited ppuloaddef(ppufile);
  1836. deftype:=floatdef;
  1837. typ:=tfloattype(ppufile.getbyte);
  1838. setsize;
  1839. end;
  1840. function tfloatdef.getcopy : tstoreddef;
  1841. begin
  1842. result:=tfloatdef.create(typ);
  1843. result.deftype:=floatdef;
  1844. tfloatdef(result).savesize:=savesize;
  1845. end;
  1846. procedure tfloatdef.setsize;
  1847. begin
  1848. case typ of
  1849. s32real : savesize:=4;
  1850. s80real : savesize:=extended_size;
  1851. s64real,
  1852. s64currency,
  1853. s64comp : savesize:=8;
  1854. else
  1855. savesize:=0;
  1856. end;
  1857. end;
  1858. procedure tfloatdef.ppuwrite(ppufile:tcompilerppufile);
  1859. begin
  1860. inherited ppuwritedef(ppufile);
  1861. ppufile.putbyte(byte(typ));
  1862. ppufile.writeentry(ibfloatdef);
  1863. end;
  1864. {$ifdef GDB}
  1865. function Tfloatdef.stabstring:Pchar;
  1866. begin
  1867. case typ of
  1868. s32real,s64real:
  1869. { found this solution in stabsread.c from GDB v4.16 }
  1870. stabstring:=stabstr_evaluate('r$1;${savesize};0;',[tstoreddef(s32inttype.def).numberstring]);
  1871. s64currency,s64comp:
  1872. stabstring:=stabstr_evaluate('r$1;-${savesize};0;',[tstoreddef(s32inttype.def).numberstring]);
  1873. s80real:
  1874. { under dos at least you must give a size of twelve instead of 10 !! }
  1875. { this is probably do to the fact that in gcc all is pushed in 4 bytes size }
  1876. stabstring:=stabstr_evaluate('r$1;12;0;',[tstoreddef(s32inttype.def).numberstring]);
  1877. else
  1878. internalerror(10005);
  1879. end;
  1880. end;
  1881. procedure tfloatdef.concatstabto(asmlist:taasmoutput);
  1882. begin
  1883. if (stab_state in [stab_state_writing,stab_state_written]) then
  1884. exit;
  1885. tstoreddef(s32inttype.def).concatstabto(asmlist);
  1886. inherited concatstabto(asmlist);
  1887. end;
  1888. {$endif GDB}
  1889. procedure tfloatdef.write_rtti_data(rt:trttitype);
  1890. const
  1891. {tfloattype = (s32real,s64real,s80real,s64bit,s128bit);}
  1892. translate : array[tfloattype] of byte =
  1893. (ftSingle,ftDouble,ftExtended,ftComp,ftCurr,ftFloat128);
  1894. begin
  1895. rttiList.concat(Tai_const.Create_8bit(tkFloat));
  1896. write_rtti_name;
  1897. rttiList.concat(Tai_const.Create_8bit(translate[typ]));
  1898. end;
  1899. function tfloatdef.is_publishable : boolean;
  1900. begin
  1901. is_publishable:=true;
  1902. end;
  1903. function tfloatdef.gettypename : string;
  1904. const
  1905. names : array[tfloattype] of string[20] = (
  1906. 'Single','Double','Extended','Comp','Currency','Float128');
  1907. begin
  1908. gettypename:=names[typ];
  1909. end;
  1910. {****************************************************************************
  1911. TFILEDEF
  1912. ****************************************************************************}
  1913. constructor tfiledef.createtext;
  1914. begin
  1915. inherited create;
  1916. deftype:=filedef;
  1917. filetyp:=ft_text;
  1918. typedfiletype.reset;
  1919. setsize;
  1920. end;
  1921. constructor tfiledef.createuntyped;
  1922. begin
  1923. inherited create;
  1924. deftype:=filedef;
  1925. filetyp:=ft_untyped;
  1926. typedfiletype.reset;
  1927. setsize;
  1928. end;
  1929. constructor tfiledef.createtyped(const tt : ttype);
  1930. begin
  1931. inherited create;
  1932. deftype:=filedef;
  1933. filetyp:=ft_typed;
  1934. typedfiletype:=tt;
  1935. setsize;
  1936. end;
  1937. constructor tfiledef.ppuload(ppufile:tcompilerppufile);
  1938. begin
  1939. inherited ppuloaddef(ppufile);
  1940. deftype:=filedef;
  1941. filetyp:=tfiletyp(ppufile.getbyte);
  1942. if filetyp=ft_typed then
  1943. ppufile.gettype(typedfiletype)
  1944. else
  1945. typedfiletype.reset;
  1946. setsize;
  1947. end;
  1948. procedure tfiledef.buildderef;
  1949. begin
  1950. inherited buildderef;
  1951. if filetyp=ft_typed then
  1952. typedfiletype.buildderef;
  1953. end;
  1954. procedure tfiledef.deref;
  1955. begin
  1956. inherited deref;
  1957. if filetyp=ft_typed then
  1958. typedfiletype.resolve;
  1959. end;
  1960. procedure tfiledef.setsize;
  1961. begin
  1962. {$ifdef cpu64bit}
  1963. case filetyp of
  1964. ft_text :
  1965. savesize:=608;
  1966. ft_typed,
  1967. ft_untyped :
  1968. savesize:=320;
  1969. end;
  1970. {$else cpu64bit}
  1971. case filetyp of
  1972. ft_text :
  1973. savesize:=572;
  1974. ft_typed,
  1975. ft_untyped :
  1976. savesize:=316;
  1977. end;
  1978. {$endif cpu64bit}
  1979. end;
  1980. procedure tfiledef.ppuwrite(ppufile:tcompilerppufile);
  1981. begin
  1982. inherited ppuwritedef(ppufile);
  1983. ppufile.putbyte(byte(filetyp));
  1984. if filetyp=ft_typed then
  1985. ppufile.puttype(typedfiletype);
  1986. ppufile.writeentry(ibfiledef);
  1987. end;
  1988. {$ifdef GDB}
  1989. function tfiledef.stabstring : pchar;
  1990. begin
  1991. {$IfDef GDBknowsfiles}
  1992. case filetyp of
  1993. ft_typed :
  1994. stabstring := strpnew('d'+typedfiletype.def.numberstring{+';'});
  1995. ft_untyped :
  1996. stabstring := strpnew('d'+voiddef.numberstring{+';'});
  1997. ft_text :
  1998. stabstring := strpnew('d'+cchartype^.numberstring{+';'});
  1999. end;
  2000. {$Else}
  2001. {$ifdef cpu64bit}
  2002. stabstring:=stabstr_evaluate('s${savesize}HANDLE:$1,0,32;MODE:$1,32,32;RECSIZE:$2,64,64;'+
  2003. '_PRIVATE:ar$1;1;64;$3,128,256;USERDATA:ar$1;1;16;$3,384,128;'+
  2004. 'NAME:ar$1;0;255;$4,512,2048;;',[tstoreddef(s32inttype.def).numberstring,
  2005. tstoreddef(s64inttype.def).numberstring,
  2006. tstoreddef(u8inttype.def).numberstring,
  2007. tstoreddef(cchartype.def).numberstring]);
  2008. {$else cpu64bit}
  2009. stabstring:=stabstr_evaluate('s${savesize}HANDLE:$1,0,32;MODE:$1,32,32;RECSIZE:$1,64,32;'+
  2010. '_PRIVATE:ar$1;1;32;$3,96,256;USERDATA:ar$1;1;16;$2,352,128;'+
  2011. 'NAME:ar$1;0;255;$3,480,2048;;',[tstoreddef(s32inttype.def).numberstring,
  2012. tstoreddef(u8inttype.def).numberstring,
  2013. tstoreddef(cchartype.def).numberstring]);
  2014. {$endif cpu64bit}
  2015. {$EndIf}
  2016. end;
  2017. procedure tfiledef.concatstabto(asmlist:taasmoutput);
  2018. begin
  2019. if (stab_state in [stab_state_writing,stab_state_written]) then
  2020. exit;
  2021. {$IfDef GDBknowsfiles}
  2022. case filetyp of
  2023. ft_typed :
  2024. tstoreddef(typedfiletype.def).concatstabto(asmlist);
  2025. ft_untyped :
  2026. tstoreddef(voidtype.def).concatstabto(asmlist);
  2027. ft_text :
  2028. tstoreddef(cchartype.def).concatstabto(asmlist);
  2029. end;
  2030. {$Else}
  2031. tstoreddef(s32inttype.def).concatstabto(asmlist);
  2032. {$ifdef cpu64bit}
  2033. tstoreddef(s64inttype.def).concatstabto(asmlist);
  2034. {$endif cpu64bit}
  2035. tstoreddef(u8inttype.def).concatstabto(asmlist);
  2036. tstoreddef(cchartype.def).concatstabto(asmlist);
  2037. {$EndIf}
  2038. inherited concatstabto(asmlist);
  2039. end;
  2040. {$endif GDB}
  2041. function tfiledef.gettypename : string;
  2042. begin
  2043. case filetyp of
  2044. ft_untyped:
  2045. gettypename:='File';
  2046. ft_typed:
  2047. gettypename:='File Of '+typedfiletype.def.typename;
  2048. ft_text:
  2049. gettypename:='Text'
  2050. end;
  2051. end;
  2052. function tfiledef.getmangledparaname : string;
  2053. begin
  2054. case filetyp of
  2055. ft_untyped:
  2056. getmangledparaname:='FILE';
  2057. ft_typed:
  2058. getmangledparaname:='FILE$OF$'+typedfiletype.def.mangledparaname;
  2059. ft_text:
  2060. getmangledparaname:='TEXT'
  2061. end;
  2062. end;
  2063. {****************************************************************************
  2064. TVARIANTDEF
  2065. ****************************************************************************}
  2066. constructor tvariantdef.create(v : tvarianttype);
  2067. begin
  2068. inherited create;
  2069. varianttype:=v;
  2070. deftype:=variantdef;
  2071. setsize;
  2072. end;
  2073. constructor tvariantdef.ppuload(ppufile:tcompilerppufile);
  2074. begin
  2075. inherited ppuloaddef(ppufile);
  2076. varianttype:=tvarianttype(ppufile.getbyte);
  2077. deftype:=variantdef;
  2078. setsize;
  2079. end;
  2080. procedure tvariantdef.ppuwrite(ppufile:tcompilerppufile);
  2081. begin
  2082. inherited ppuwritedef(ppufile);
  2083. ppufile.putbyte(byte(varianttype));
  2084. ppufile.writeentry(ibvariantdef);
  2085. end;
  2086. procedure tvariantdef.setsize;
  2087. begin
  2088. savesize:=16;
  2089. end;
  2090. function tvariantdef.gettypename : string;
  2091. begin
  2092. case varianttype of
  2093. vt_normalvariant:
  2094. gettypename:='Variant';
  2095. vt_olevariant:
  2096. gettypename:='OleVariant';
  2097. end;
  2098. end;
  2099. procedure tvariantdef.write_rtti_data(rt:trttitype);
  2100. begin
  2101. rttiList.concat(Tai_const.Create_8bit(tkVariant));
  2102. end;
  2103. function tvariantdef.needs_inittable : boolean;
  2104. begin
  2105. needs_inittable:=true;
  2106. end;
  2107. {$ifdef GDB}
  2108. function tvariantdef.stabstring : pchar;
  2109. begin
  2110. stabstring:=stabstr_evaluate('formal${numberstring};',[]);
  2111. end;
  2112. function tvariantdef.numberstring:string;
  2113. begin
  2114. result:=tstoreddef(voidtype.def).numberstring;
  2115. end;
  2116. procedure tvariantdef.concatstabto(asmlist : taasmoutput);
  2117. begin
  2118. { don't know how to handle this }
  2119. end;
  2120. {$endif GDB}
  2121. {****************************************************************************
  2122. TPOINTERDEF
  2123. ****************************************************************************}
  2124. constructor tpointerdef.create(const tt : ttype);
  2125. begin
  2126. inherited create;
  2127. deftype:=pointerdef;
  2128. pointertype:=tt;
  2129. is_far:=false;
  2130. savesize:=sizeof(aint);
  2131. end;
  2132. constructor tpointerdef.createfar(const tt : ttype);
  2133. begin
  2134. inherited create;
  2135. deftype:=pointerdef;
  2136. pointertype:=tt;
  2137. is_far:=true;
  2138. savesize:=sizeof(aint);
  2139. end;
  2140. constructor tpointerdef.ppuload(ppufile:tcompilerppufile);
  2141. begin
  2142. inherited ppuloaddef(ppufile);
  2143. deftype:=pointerdef;
  2144. ppufile.gettype(pointertype);
  2145. is_far:=(ppufile.getbyte<>0);
  2146. savesize:=sizeof(aint);
  2147. end;
  2148. procedure tpointerdef.buildderef;
  2149. begin
  2150. inherited buildderef;
  2151. pointertype.buildderef;
  2152. end;
  2153. procedure tpointerdef.deref;
  2154. begin
  2155. inherited deref;
  2156. pointertype.resolve;
  2157. end;
  2158. procedure tpointerdef.ppuwrite(ppufile:tcompilerppufile);
  2159. begin
  2160. inherited ppuwritedef(ppufile);
  2161. ppufile.puttype(pointertype);
  2162. ppufile.putbyte(byte(is_far));
  2163. ppufile.writeentry(ibpointerdef);
  2164. end;
  2165. {$ifdef GDB}
  2166. function tpointerdef.stabstring : pchar;
  2167. begin
  2168. stabstring := strpnew('*'+tstoreddef(pointertype.def).numberstring);
  2169. end;
  2170. procedure tpointerdef.concatstabto(asmlist : taasmoutput);
  2171. var st,nb : string;
  2172. begin
  2173. if (stab_state in [stab_state_writing,stab_state_written]) then
  2174. exit;
  2175. stab_state:=stab_state_writing;
  2176. tstoreddef(pointertype.def).concatstabto(asmlist);
  2177. if (pointertype.def.deftype in [recorddef,objectdef]) then
  2178. begin
  2179. if pointertype.def.deftype=objectdef then
  2180. nb:=tobjectdef(pointertype.def).classnumberstring
  2181. else
  2182. nb:=tstoreddef(pointertype.def).numberstring;
  2183. {to avoid infinite recursion in record with next-like fields }
  2184. if tstoreddef(pointertype.def).stab_state=stab_state_writing then
  2185. begin
  2186. if assigned(pointertype.def.typesym) then
  2187. begin
  2188. if assigned(typesym) then
  2189. st := ttypesym(typesym).name
  2190. else
  2191. st := ' ';
  2192. asmlist.concat(Tai_stabs.create(stabstr_evaluate(
  2193. '"$1:t${numberstring}=*$2=xs$3:",${N_LSYM},0,0,0',
  2194. [st,nb,pointertype.def.typesym.name])));
  2195. end;
  2196. stab_state:=stab_state_written;
  2197. end
  2198. else
  2199. begin
  2200. stab_state:=stab_state_used;
  2201. inherited concatstabto(asmlist);
  2202. end;
  2203. end
  2204. else
  2205. begin
  2206. stab_state:=stab_state_used;
  2207. inherited concatstabto(asmlist);
  2208. end;
  2209. end;
  2210. {$endif GDB}
  2211. function tpointerdef.gettypename : string;
  2212. begin
  2213. if is_far then
  2214. gettypename:='^'+pointertype.def.typename+';far'
  2215. else
  2216. gettypename:='^'+pointertype.def.typename;
  2217. end;
  2218. {****************************************************************************
  2219. TCLASSREFDEF
  2220. ****************************************************************************}
  2221. constructor tclassrefdef.create(const t:ttype);
  2222. begin
  2223. inherited create(t);
  2224. deftype:=classrefdef;
  2225. end;
  2226. constructor tclassrefdef.ppuload(ppufile:tcompilerppufile);
  2227. begin
  2228. { be careful, tclassdefref inherits from tpointerdef }
  2229. inherited ppuloaddef(ppufile);
  2230. deftype:=classrefdef;
  2231. ppufile.gettype(pointertype);
  2232. is_far:=false;
  2233. savesize:=sizeof(aint);
  2234. end;
  2235. procedure tclassrefdef.ppuwrite(ppufile:tcompilerppufile);
  2236. begin
  2237. { be careful, tclassdefref inherits from tpointerdef }
  2238. inherited ppuwritedef(ppufile);
  2239. ppufile.puttype(pointertype);
  2240. ppufile.writeentry(ibclassrefdef);
  2241. end;
  2242. {$ifdef GDB}
  2243. function tclassrefdef.stabstring : pchar;
  2244. begin
  2245. stabstring:=strpnew(tstoreddef(pvmttype.def).numberstring);
  2246. end;
  2247. {$endif GDB}
  2248. function tclassrefdef.gettypename : string;
  2249. begin
  2250. gettypename:='Class Of '+pointertype.def.typename;
  2251. end;
  2252. {***************************************************************************
  2253. TSETDEF
  2254. ***************************************************************************}
  2255. constructor tsetdef.create(const t:ttype;high : longint);
  2256. begin
  2257. inherited create;
  2258. deftype:=setdef;
  2259. elementtype:=t;
  2260. if high<32 then
  2261. begin
  2262. settype:=smallset;
  2263. {$ifdef testvarsets}
  2264. if aktsetalloc=0 THEN { $PACKSET Fixed?}
  2265. {$endif}
  2266. savesize:=Sizeof(longint)
  2267. {$ifdef testvarsets}
  2268. else {No, use $PACKSET VALUE for rounding}
  2269. savesize:=aktsetalloc*((high+aktsetalloc*8-1) DIV (aktsetalloc*8))
  2270. {$endif}
  2271. ;
  2272. end
  2273. else
  2274. if high<256 then
  2275. begin
  2276. settype:=normset;
  2277. savesize:=32;
  2278. end
  2279. else
  2280. {$ifdef testvarsets}
  2281. if high<$10000 then
  2282. begin
  2283. settype:=varset;
  2284. savesize:=4*((high+31) div 32);
  2285. end
  2286. else
  2287. {$endif testvarsets}
  2288. Message(sym_e_ill_type_decl_set);
  2289. end;
  2290. constructor tsetdef.ppuload(ppufile:tcompilerppufile);
  2291. begin
  2292. inherited ppuloaddef(ppufile);
  2293. deftype:=setdef;
  2294. ppufile.gettype(elementtype);
  2295. settype:=tsettype(ppufile.getbyte);
  2296. case settype of
  2297. normset : savesize:=32;
  2298. varset : savesize:=ppufile.getlongint;
  2299. smallset : savesize:=Sizeof(longint);
  2300. end;
  2301. end;
  2302. destructor tsetdef.destroy;
  2303. begin
  2304. inherited destroy;
  2305. end;
  2306. procedure tsetdef.ppuwrite(ppufile:tcompilerppufile);
  2307. begin
  2308. inherited ppuwritedef(ppufile);
  2309. ppufile.puttype(elementtype);
  2310. ppufile.putbyte(byte(settype));
  2311. if settype=varset then
  2312. ppufile.putlongint(savesize);
  2313. ppufile.writeentry(ibsetdef);
  2314. end;
  2315. {$ifdef GDB}
  2316. function tsetdef.stabstring : pchar;
  2317. begin
  2318. stabstring:=stabstr_evaluate('@s$1;S$2',[tostr(savesize*8),tstoreddef(elementtype.def).numberstring]);
  2319. end;
  2320. procedure tsetdef.concatstabto(asmlist:taasmoutput);
  2321. begin
  2322. if (stab_state in [stab_state_writing,stab_state_written]) then
  2323. exit;
  2324. tstoreddef(elementtype.def).concatstabto(asmlist);
  2325. inherited concatstabto(asmlist);
  2326. end;
  2327. {$endif GDB}
  2328. procedure tsetdef.buildderef;
  2329. begin
  2330. inherited buildderef;
  2331. elementtype.buildderef;
  2332. end;
  2333. procedure tsetdef.deref;
  2334. begin
  2335. inherited deref;
  2336. elementtype.resolve;
  2337. end;
  2338. procedure tsetdef.write_child_rtti_data(rt:trttitype);
  2339. begin
  2340. tstoreddef(elementtype.def).get_rtti_label(rt);
  2341. end;
  2342. procedure tsetdef.write_rtti_data(rt:trttitype);
  2343. begin
  2344. rttiList.concat(Tai_const.Create_8bit(tkSet));
  2345. write_rtti_name;
  2346. rttiList.concat(Tai_const.Create_8bit(otULong));
  2347. rttiList.concat(Tai_const.Create_sym(tstoreddef(elementtype.def).get_rtti_label(rt)));
  2348. end;
  2349. function tsetdef.is_publishable : boolean;
  2350. begin
  2351. is_publishable:=(settype=smallset);
  2352. end;
  2353. function tsetdef.gettypename : string;
  2354. begin
  2355. if assigned(elementtype.def) then
  2356. gettypename:='Set Of '+elementtype.def.typename
  2357. else
  2358. gettypename:='Empty Set';
  2359. end;
  2360. {***************************************************************************
  2361. TFORMALDEF
  2362. ***************************************************************************}
  2363. constructor tformaldef.create;
  2364. var
  2365. stregdef : boolean;
  2366. begin
  2367. stregdef:=registerdef;
  2368. registerdef:=false;
  2369. inherited create;
  2370. deftype:=formaldef;
  2371. registerdef:=stregdef;
  2372. { formaldef must be registered at unit level !! }
  2373. if registerdef and assigned(current_module) then
  2374. if assigned(current_module.localsymtable) then
  2375. tsymtable(current_module.localsymtable).registerdef(self)
  2376. else if assigned(current_module.globalsymtable) then
  2377. tsymtable(current_module.globalsymtable).registerdef(self);
  2378. savesize:=0;
  2379. end;
  2380. constructor tformaldef.ppuload(ppufile:tcompilerppufile);
  2381. begin
  2382. inherited ppuloaddef(ppufile);
  2383. deftype:=formaldef;
  2384. savesize:=0;
  2385. end;
  2386. procedure tformaldef.ppuwrite(ppufile:tcompilerppufile);
  2387. begin
  2388. inherited ppuwritedef(ppufile);
  2389. ppufile.writeentry(ibformaldef);
  2390. end;
  2391. {$ifdef GDB}
  2392. function tformaldef.stabstring : pchar;
  2393. begin
  2394. stabstring:=stabstr_evaluate('formal${numberstring};',[]);
  2395. end;
  2396. function tformaldef.numberstring:string;
  2397. begin
  2398. result:=tstoreddef(voidtype.def).numberstring;
  2399. end;
  2400. procedure tformaldef.concatstabto(asmlist : taasmoutput);
  2401. begin
  2402. { formaldef can't be stab'ed !}
  2403. end;
  2404. {$endif GDB}
  2405. function tformaldef.gettypename : string;
  2406. begin
  2407. gettypename:='<Formal type>';
  2408. end;
  2409. {***************************************************************************
  2410. TARRAYDEF
  2411. ***************************************************************************}
  2412. constructor tarraydef.create(l,h : longint;const t : ttype);
  2413. begin
  2414. inherited create;
  2415. deftype:=arraydef;
  2416. lowrange:=l;
  2417. highrange:=h;
  2418. rangetype:=t;
  2419. elementtype.reset;
  2420. IsVariant:=false;
  2421. IsConstructor:=false;
  2422. IsArrayOfConst:=false;
  2423. IsDynamicArray:=false;
  2424. IsConvertedPointer:=false;
  2425. end;
  2426. constructor tarraydef.create_from_pointer(const elemt : ttype);
  2427. begin
  2428. self.create(0,$7fffffff,s32inttype);
  2429. IsConvertedPointer:=true;
  2430. setelementtype(elemt);
  2431. end;
  2432. constructor tarraydef.ppuload(ppufile:tcompilerppufile);
  2433. begin
  2434. inherited ppuloaddef(ppufile);
  2435. deftype:=arraydef;
  2436. { the addresses are calculated later }
  2437. ppufile.gettype(_elementtype);
  2438. ppufile.gettype(rangetype);
  2439. lowrange:=ppufile.getlongint;
  2440. highrange:=ppufile.getlongint;
  2441. IsArrayOfConst:=boolean(ppufile.getbyte);
  2442. IsDynamicArray:=boolean(ppufile.getbyte);
  2443. IsVariant:=false;
  2444. IsConstructor:=false;
  2445. end;
  2446. procedure tarraydef.buildderef;
  2447. begin
  2448. inherited buildderef;
  2449. _elementtype.buildderef;
  2450. rangetype.buildderef;
  2451. end;
  2452. procedure tarraydef.deref;
  2453. begin
  2454. inherited deref;
  2455. _elementtype.resolve;
  2456. rangetype.resolve;
  2457. end;
  2458. procedure tarraydef.ppuwrite(ppufile:tcompilerppufile);
  2459. begin
  2460. inherited ppuwritedef(ppufile);
  2461. ppufile.puttype(_elementtype);
  2462. ppufile.puttype(rangetype);
  2463. ppufile.putlongint(lowrange);
  2464. ppufile.putlongint(highrange);
  2465. ppufile.putbyte(byte(IsArrayOfConst));
  2466. ppufile.putbyte(byte(IsDynamicArray));
  2467. ppufile.writeentry(ibarraydef);
  2468. end;
  2469. {$ifdef GDB}
  2470. function tarraydef.stabstring : pchar;
  2471. begin
  2472. stabstring:=stabstr_evaluate('ar$1;$2;$3;$4',[Tstoreddef(rangetype.def).numberstring,
  2473. tostr(lowrange),tostr(highrange),Tstoreddef(_elementtype.def).numberstring]);
  2474. end;
  2475. procedure tarraydef.concatstabto(asmlist:taasmoutput);
  2476. begin
  2477. if (stab_state in [stab_state_writing,stab_state_written]) then
  2478. exit;
  2479. tstoreddef(rangetype.def).concatstabto(asmlist);
  2480. tstoreddef(_elementtype.def).concatstabto(asmlist);
  2481. inherited concatstabto(asmlist);
  2482. end;
  2483. {$endif GDB}
  2484. function tarraydef.elesize : longint;
  2485. begin
  2486. elesize:=_elementtype.def.size;
  2487. end;
  2488. function tarraydef.size : longint;
  2489. var
  2490. newsize : TConstExprInt;
  2491. begin
  2492. if IsDynamicArray then
  2493. begin
  2494. size:=sizeof(aint);
  2495. exit;
  2496. end;
  2497. {Tarraydef.size may never be called for an open array!}
  2498. if highrange<lowrange then
  2499. internalerror(99080501);
  2500. newsize:=(int64(highrange)-int64(lowrange)+1)*elesize;
  2501. { prevent an overflow }
  2502. if newsize>high(longint) then
  2503. result:=high(longint)
  2504. else
  2505. result:=newsize;
  2506. end;
  2507. procedure tarraydef.setelementtype(t: ttype);
  2508. var
  2509. cachedsize : TConstExprInt;
  2510. begin
  2511. _elementtype:=t;
  2512. if not(IsDynamicArray or
  2513. IsConvertedPointer or
  2514. (highrange<lowrange)) then
  2515. begin
  2516. { cache element size for performance on multidimensional arrays }
  2517. cachedsize := elesize;
  2518. if (cachedsize>0) and
  2519. (
  2520. {$ifdef cpu64bit}
  2521. {$ifdef VER1_0}
  2522. { 1.0.x can't handle this and while bootstrapping with 1.0.x we can forget about it }
  2523. false
  2524. {$else}
  2525. (TConstExprInt(highrange)-TConstExprInt(lowrange) > $7fffffffffffffff) or
  2526. { () are needed around cachedsize-1 to avoid a possible
  2527. integer overflow for cachedsize=1 !! PM }
  2528. (($7fffffffffffffff div cachedsize + (cachedsize -1)) < (int64(highrange) - int64(lowrange)))
  2529. {$endif VER1_0}
  2530. {$else cpu64bit}
  2531. (TConstExprInt(highrange)-TConstExprInt(lowrange) > $7fffffff) or
  2532. { () are needed around cachedsize-1 to avoid a possible
  2533. integer overflow for cachedsize=1 !! PM }
  2534. (($7fffffff div cachedsize + (cachedsize -1)) < (int64(highrange) - int64(lowrange)))
  2535. {$endif cpu64bit}
  2536. ) Then
  2537. Message(sym_e_segment_too_large);
  2538. end;
  2539. end;
  2540. function tarraydef.alignment : longint;
  2541. begin
  2542. { alignment is the size of the elements }
  2543. if elementtype.def.deftype=recorddef then
  2544. alignment:=elementtype.def.alignment
  2545. else
  2546. alignment:=elesize;
  2547. end;
  2548. function tarraydef.needs_inittable : boolean;
  2549. begin
  2550. needs_inittable:=IsDynamicArray or elementtype.def.needs_inittable;
  2551. end;
  2552. procedure tarraydef.write_child_rtti_data(rt:trttitype);
  2553. begin
  2554. tstoreddef(elementtype.def).get_rtti_label(rt);
  2555. end;
  2556. procedure tarraydef.write_rtti_data(rt:trttitype);
  2557. begin
  2558. if IsDynamicArray then
  2559. rttiList.concat(Tai_const.Create_8bit(tkdynarray))
  2560. else
  2561. rttiList.concat(Tai_const.Create_8bit(tkarray));
  2562. write_rtti_name;
  2563. { size of elements }
  2564. rttiList.concat(Tai_const.Create_32bit(elesize));
  2565. { count of elements, prevent overflow for 0..maxlongint }
  2566. if not(IsDynamicArray) then
  2567. rttiList.concat(Tai_const.Create_32bit(min(int64(highrange)-lowrange+1,maxlongint)));
  2568. { element type }
  2569. rttiList.concat(Tai_const.Create_sym(tstoreddef(elementtype.def).get_rtti_label(rt)));
  2570. { variant type }
  2571. // !!!!!!!!!!!!!!!!
  2572. end;
  2573. function tarraydef.gettypename : string;
  2574. begin
  2575. if isarrayofconst or isConstructor then
  2576. begin
  2577. if isvariant or ((highrange=-1) and (lowrange=0)) then
  2578. gettypename:='Array Of Const'
  2579. else
  2580. gettypename:='Array Of '+elementtype.def.typename;
  2581. end
  2582. else if ((highrange=-1) and (lowrange=0)) or IsDynamicArray then
  2583. gettypename:='Array Of '+elementtype.def.typename
  2584. else
  2585. begin
  2586. if rangetype.def.deftype=enumdef then
  2587. gettypename:='Array['+rangetype.def.typename+'] Of '+elementtype.def.typename
  2588. else
  2589. gettypename:='Array['+tostr(lowrange)+'..'+
  2590. tostr(highrange)+'] Of '+elementtype.def.typename
  2591. end;
  2592. end;
  2593. function tarraydef.getmangledparaname : string;
  2594. begin
  2595. if isarrayofconst then
  2596. getmangledparaname:='array_of_const'
  2597. else
  2598. if ((highrange=-1) and (lowrange=0)) then
  2599. getmangledparaname:='array_of_'+elementtype.def.mangledparaname
  2600. else
  2601. internalerror(200204176);
  2602. end;
  2603. {***************************************************************************
  2604. tabstractrecorddef
  2605. ***************************************************************************}
  2606. function tabstractrecorddef.getsymtable(t:tgetsymtable):tsymtable;
  2607. begin
  2608. if t=gs_record then
  2609. getsymtable:=symtable
  2610. else
  2611. getsymtable:=nil;
  2612. end;
  2613. {$ifdef GDB}
  2614. procedure tabstractrecorddef.field_addname(p:Tnamedindexitem;arg:pointer);
  2615. var
  2616. newrec:Pchar;
  2617. spec:string[3];
  2618. varsize:longint;
  2619. state:^Trecord_stabgen_state;
  2620. begin
  2621. state:=arg;
  2622. { static variables from objects are like global objects }
  2623. if (Tsym(p).typ=varsym) and not (sp_static in Tsym(p).symoptions) then
  2624. begin
  2625. if (sp_protected in tsym(p).symoptions) then
  2626. spec:='/1'
  2627. else if (sp_private in tsym(p).symoptions) then
  2628. spec:='/0'
  2629. else
  2630. spec:='';
  2631. varsize:=tvarsym(p).vartype.def.size;
  2632. { open arrays made overflows !! }
  2633. if varsize>$fffffff then
  2634. varsize:=$fffffff;
  2635. newrec:=stabstr_evaluate('$1:$2,$3,$4;',[p.name,
  2636. spec+tstoreddef(tvarsym(p).vartype.def).numberstring,
  2637. tostr(tvarsym(p).fieldoffset*8),tostr(varsize*8)]);
  2638. if state^.stabsize+strlen(newrec)>=state^.staballoc-256 then
  2639. begin
  2640. inc(state^.staballoc,memsizeinc);
  2641. reallocmem(state^.stabstring,state^.staballoc);
  2642. end;
  2643. strcopy(state^.stabstring+state^.stabsize,newrec);
  2644. inc(state^.stabsize,strlen(newrec));
  2645. strdispose(newrec);
  2646. {This should be used for case !!}
  2647. inc(state^.recoffset,Tvarsym(p).vartype.def.size);
  2648. end;
  2649. end;
  2650. procedure tabstractrecorddef.field_concatstabto(p:Tnamedindexitem;arg:pointer);
  2651. begin
  2652. if (Tsym(p).typ=varsym) and not (sp_static in Tsym(p).symoptions) then
  2653. tstoreddef(tvarsym(p).vartype.def).concatstabto(taasmoutput(arg));
  2654. end;
  2655. {$endif GDB}
  2656. procedure tabstractrecorddef.count_field_rtti(sym : tnamedindexitem;arg:pointer);
  2657. begin
  2658. if (FRTTIType=fullrtti) or
  2659. ((tsym(sym).typ=varsym) and
  2660. tvarsym(sym).vartype.def.needs_inittable) then
  2661. inc(Count);
  2662. end;
  2663. procedure tabstractrecorddef.generate_field_rtti(sym:tnamedindexitem;arg:pointer);
  2664. begin
  2665. if (FRTTIType=fullrtti) or
  2666. ((tsym(sym).typ=varsym) and
  2667. tvarsym(sym).vartype.def.needs_inittable) then
  2668. tstoreddef(tvarsym(sym).vartype.def).get_rtti_label(FRTTIType);
  2669. end;
  2670. procedure tabstractrecorddef.write_field_rtti(sym : tnamedindexitem;arg:pointer);
  2671. begin
  2672. if (FRTTIType=fullrtti) or
  2673. ((tsym(sym).typ=varsym) and
  2674. tvarsym(sym).vartype.def.needs_inittable) then
  2675. begin
  2676. rttiList.concat(Tai_const.Create_sym(tstoreddef(tvarsym(sym).vartype.def).get_rtti_label(FRTTIType)));
  2677. rttiList.concat(Tai_const.Create_32bit(tvarsym(sym).fieldoffset));
  2678. end;
  2679. end;
  2680. {***************************************************************************
  2681. trecorddef
  2682. ***************************************************************************}
  2683. constructor trecorddef.create(p : tsymtable);
  2684. begin
  2685. inherited create;
  2686. deftype:=recorddef;
  2687. symtable:=p;
  2688. symtable.defowner:=self;
  2689. isunion:=false;
  2690. end;
  2691. constructor trecorddef.ppuload(ppufile:tcompilerppufile);
  2692. begin
  2693. inherited ppuloaddef(ppufile);
  2694. deftype:=recorddef;
  2695. symtable:=trecordsymtable.create(0);
  2696. trecordsymtable(symtable).datasize:=ppufile.getlongint;
  2697. trecordsymtable(symtable).fieldalignment:=ppufile.getbyte;
  2698. trecordsymtable(symtable).recordalignment:=ppufile.getbyte;
  2699. trecordsymtable(symtable).ppuload(ppufile);
  2700. symtable.defowner:=self;
  2701. isunion:=false;
  2702. end;
  2703. destructor trecorddef.destroy;
  2704. begin
  2705. if assigned(symtable) then
  2706. symtable.free;
  2707. inherited destroy;
  2708. end;
  2709. function trecorddef.needs_inittable : boolean;
  2710. begin
  2711. needs_inittable:=trecordsymtable(symtable).needs_init_final
  2712. end;
  2713. procedure trecorddef.buildderef;
  2714. var
  2715. oldrecsyms : tsymtable;
  2716. begin
  2717. inherited buildderef;
  2718. oldrecsyms:=aktrecordsymtable;
  2719. aktrecordsymtable:=symtable;
  2720. { now build the definitions }
  2721. tstoredsymtable(symtable).buildderef;
  2722. aktrecordsymtable:=oldrecsyms;
  2723. end;
  2724. procedure trecorddef.deref;
  2725. var
  2726. oldrecsyms : tsymtable;
  2727. begin
  2728. inherited deref;
  2729. oldrecsyms:=aktrecordsymtable;
  2730. aktrecordsymtable:=symtable;
  2731. { now dereference the definitions }
  2732. tstoredsymtable(symtable).deref;
  2733. aktrecordsymtable:=oldrecsyms;
  2734. { assign TGUID? load only from system unit (unitid=1) }
  2735. if not(assigned(rec_tguid)) and
  2736. (upper(typename)='TGUID') and
  2737. assigned(owner) and
  2738. assigned(owner.name) and
  2739. (owner.name^='SYSTEM') then
  2740. rec_tguid:=self;
  2741. end;
  2742. procedure trecorddef.ppuwrite(ppufile:tcompilerppufile);
  2743. begin
  2744. inherited ppuwritedef(ppufile);
  2745. ppufile.putlongint(trecordsymtable(symtable).datasize);
  2746. ppufile.putbyte(trecordsymtable(symtable).fieldalignment);
  2747. ppufile.putbyte(trecordsymtable(symtable).recordalignment);
  2748. ppufile.writeentry(ibrecorddef);
  2749. trecordsymtable(symtable).ppuwrite(ppufile);
  2750. end;
  2751. function trecorddef.size:longint;
  2752. begin
  2753. result:=trecordsymtable(symtable).datasize;
  2754. end;
  2755. function trecorddef.alignment:longint;
  2756. begin
  2757. alignment:=trecordsymtable(symtable).recordalignment;
  2758. end;
  2759. {$ifdef GDB}
  2760. function trecorddef.stabstring : pchar;
  2761. var
  2762. state:Trecord_stabgen_state;
  2763. begin
  2764. getmem(state.stabstring,memsizeinc);
  2765. state.staballoc:=memsizeinc;
  2766. strpcopy(state.stabstring,'s'+tostr(size));
  2767. state.recoffset:=0;
  2768. state.stabsize:=strlen(state.stabstring);
  2769. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}field_addname,@state);
  2770. state.stabstring[state.stabsize]:=';';
  2771. state.stabstring[state.stabsize+1]:=#0;
  2772. reallocmem(state.stabstring,state.stabsize+2);
  2773. stabstring:=state.stabstring;
  2774. end;
  2775. procedure trecorddef.concatstabto(asmlist:taasmoutput);
  2776. begin
  2777. if (stab_state in [stab_state_writing,stab_state_written]) then
  2778. exit;
  2779. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}field_concatstabto,asmlist);
  2780. inherited concatstabto(asmlist);
  2781. end;
  2782. {$endif GDB}
  2783. procedure trecorddef.write_child_rtti_data(rt:trttitype);
  2784. begin
  2785. FRTTIType:=rt;
  2786. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}generate_field_rtti,nil);
  2787. end;
  2788. procedure trecorddef.write_rtti_data(rt:trttitype);
  2789. begin
  2790. rttiList.concat(Tai_const.Create_8bit(tkrecord));
  2791. write_rtti_name;
  2792. rttiList.concat(Tai_const.Create_32bit(size));
  2793. Count:=0;
  2794. FRTTIType:=rt;
  2795. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}count_field_rtti,nil);
  2796. rttiList.concat(Tai_const.Create_32bit(Count));
  2797. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}write_field_rtti,nil);
  2798. end;
  2799. function trecorddef.gettypename : string;
  2800. begin
  2801. gettypename:='<record type>'
  2802. end;
  2803. {***************************************************************************
  2804. TABSTRACTPROCDEF
  2805. ***************************************************************************}
  2806. constructor tabstractprocdef.create(level:byte);
  2807. begin
  2808. inherited create;
  2809. parast:=tparasymtable.create(level);
  2810. parast.defowner:=self;
  2811. parast.next:=owner;
  2812. para:=TLinkedList.Create;
  2813. minparacount:=0;
  2814. maxparacount:=0;
  2815. proctypeoption:=potype_none;
  2816. proccalloption:=pocall_none;
  2817. procoptions:=[];
  2818. rettype:=voidtype;
  2819. {$ifdef i386}
  2820. fpu_used:=0;
  2821. {$endif i386}
  2822. savesize:=sizeof(aint);
  2823. requiredargarea:=0;
  2824. has_paraloc_info:=false;
  2825. end;
  2826. destructor tabstractprocdef.destroy;
  2827. begin
  2828. if assigned(para) then
  2829. begin
  2830. {$ifdef MEMDEBUG}
  2831. memprocpara.start;
  2832. {$endif MEMDEBUG}
  2833. para.free;
  2834. {$ifdef MEMDEBUG}
  2835. memprocpara.stop;
  2836. {$endif MEMDEBUG}
  2837. end;
  2838. if assigned(parast) then
  2839. begin
  2840. {$ifdef MEMDEBUG}
  2841. memprocparast.start;
  2842. {$endif MEMDEBUG}
  2843. parast.free;
  2844. {$ifdef MEMDEBUG}
  2845. memprocparast.stop;
  2846. {$endif MEMDEBUG}
  2847. end;
  2848. inherited destroy;
  2849. end;
  2850. procedure tabstractprocdef.releasemem;
  2851. begin
  2852. para.free;
  2853. para:=nil;
  2854. parast.free;
  2855. parast:=nil;
  2856. end;
  2857. function tabstractprocdef.concatpara(afterpara:tparaitem;const tt:ttype;sym : tsym;defval:tsym;vhidden:boolean):tparaitem;
  2858. var
  2859. hp : TParaItem;
  2860. begin
  2861. hp:=TParaItem.Create;
  2862. hp.paratyp:=tvarsym(sym).varspez;
  2863. hp.parasym:=sym;
  2864. hp.paratype:=tt;
  2865. hp.is_hidden:=vhidden;
  2866. hp.defaultvalue:=defval;
  2867. { Parameters are stored from left to right }
  2868. if assigned(afterpara) then
  2869. Para.insertafter(hp,afterpara)
  2870. else
  2871. Para.concat(hp);
  2872. { Don't count hidden parameters }
  2873. if not vhidden then
  2874. begin
  2875. if not assigned(defval) then
  2876. inc(minparacount);
  2877. inc(maxparacount);
  2878. end;
  2879. concatpara:=hp;
  2880. end;
  2881. function tabstractprocdef.insertpara(const tt:ttype;sym : tsym;defval:tsym;vhidden:boolean):tparaitem;
  2882. var
  2883. hp : TParaItem;
  2884. begin
  2885. hp:=TParaItem.Create;
  2886. hp.paratyp:=tvarsym(sym).varspez;
  2887. hp.parasym:=sym;
  2888. hp.paratype:=tt;
  2889. hp.is_hidden:=vhidden;
  2890. hp.defaultvalue:=defval;
  2891. { Parameters are stored from left to right }
  2892. Para.insert(hp);
  2893. { Don't count hidden parameters }
  2894. if (not vhidden) then
  2895. begin
  2896. if not assigned(defval) then
  2897. inc(minparacount);
  2898. inc(maxparacount);
  2899. end;
  2900. insertpara:=hp;
  2901. end;
  2902. procedure tabstractprocdef.removepara(currpara:tparaitem);
  2903. begin
  2904. { Don't count hidden parameters }
  2905. if (not currpara.is_hidden) then
  2906. begin
  2907. if not assigned(currpara.defaultvalue) then
  2908. dec(minparacount);
  2909. dec(maxparacount);
  2910. end;
  2911. Para.Remove(currpara);
  2912. currpara.free;
  2913. end;
  2914. { all functions returning in FPU are
  2915. assume to use 2 FPU registers
  2916. until the function implementation
  2917. is processed PM }
  2918. procedure tabstractprocdef.test_if_fpu_result;
  2919. begin
  2920. {$ifdef i386}
  2921. if assigned(rettype.def) and
  2922. (rettype.def.deftype=floatdef) then
  2923. fpu_used:=maxfpuregs;
  2924. {$endif i386}
  2925. end;
  2926. procedure tabstractprocdef.buildderef;
  2927. var
  2928. hp : TParaItem;
  2929. begin
  2930. { released procdef? }
  2931. if not assigned(parast) then
  2932. exit;
  2933. inherited buildderef;
  2934. rettype.buildderef;
  2935. { parast }
  2936. tparasymtable(parast).buildderef;
  2937. { paraitems }
  2938. hp:=TParaItem(Para.first);
  2939. while assigned(hp) do
  2940. begin
  2941. hp.paratype.buildderef;
  2942. hp.defaultvaluederef.build(hp.defaultvalue);
  2943. hp.parasymderef.build(hp.parasym);
  2944. hp:=TParaItem(hp.next);
  2945. end;
  2946. end;
  2947. procedure tabstractprocdef.deref;
  2948. var
  2949. hp : TParaItem;
  2950. begin
  2951. inherited deref;
  2952. rettype.resolve;
  2953. { parast }
  2954. tparasymtable(parast).deref;
  2955. { paraitems }
  2956. minparacount:=0;
  2957. maxparacount:=0;
  2958. hp:=TParaItem(Para.first);
  2959. while assigned(hp) do
  2960. begin
  2961. hp.paratype.resolve;
  2962. hp.defaultvalue:=tsym(hp.defaultvaluederef.resolve);
  2963. hp.parasym:=tvarsym(hp.parasymderef.resolve);
  2964. { connect parasym to paraitem }
  2965. tvarsym(hp.parasym).paraitem:=hp;
  2966. { Don't count hidden parameters }
  2967. if (not hp.is_hidden) then
  2968. begin
  2969. if not assigned(hp.defaultvalue) then
  2970. inc(minparacount);
  2971. inc(maxparacount);
  2972. end;
  2973. hp:=TParaItem(hp.next);
  2974. end;
  2975. end;
  2976. constructor tabstractprocdef.ppuload(ppufile:tcompilerppufile);
  2977. var
  2978. hp : TParaItem;
  2979. count,i : word;
  2980. begin
  2981. inherited ppuloaddef(ppufile);
  2982. parast:=nil;
  2983. Para:=TLinkedList.Create;
  2984. minparacount:=0;
  2985. maxparacount:=0;
  2986. ppufile.gettype(rettype);
  2987. {$ifdef i386}
  2988. fpu_used:=ppufile.getbyte;
  2989. {$else}
  2990. ppufile.getbyte;
  2991. {$endif i386}
  2992. proctypeoption:=tproctypeoption(ppufile.getbyte);
  2993. proccalloption:=tproccalloption(ppufile.getbyte);
  2994. ppufile.getsmallset(procoptions);
  2995. if po_explicitparaloc in procoptions then
  2996. ppufile.getdata(funcret_paraloc,sizeof(funcret_paraloc));
  2997. { get the number of parameters }
  2998. count:=ppufile.getbyte;
  2999. savesize:=sizeof(aint);
  3000. has_paraloc_info:=false;
  3001. for i:=1 to count do
  3002. begin
  3003. hp:=TParaItem.Create;
  3004. hp.paratyp:=tvarspez(ppufile.getbyte);
  3005. ppufile.gettype(hp.paratype);
  3006. ppufile.getderef(hp.defaultvaluederef);
  3007. hp.defaultvalue:=nil;
  3008. ppufile.getderef(hp.parasymderef);
  3009. hp.parasym:=nil;
  3010. hp.is_hidden:=boolean(ppufile.getbyte);
  3011. if po_explicitparaloc in procoptions then
  3012. begin
  3013. ppufile.getdata(hp.paraloc,sizeof(hp.paraloc));
  3014. has_paraloc_info:=true;
  3015. end;
  3016. { Parameters are stored left to right in both ppu and memory }
  3017. Para.concat(hp);
  3018. end;
  3019. end;
  3020. procedure tabstractprocdef.ppuwrite(ppufile:tcompilerppufile);
  3021. var
  3022. hp : TParaItem;
  3023. oldintfcrc : boolean;
  3024. begin
  3025. { released procdef? }
  3026. if not assigned(parast) then
  3027. exit;
  3028. inherited ppuwritedef(ppufile);
  3029. ppufile.puttype(rettype);
  3030. oldintfcrc:=ppufile.do_interface_crc;
  3031. ppufile.do_interface_crc:=false;
  3032. {$ifdef i386}
  3033. if simplify_ppu then
  3034. fpu_used:=0;
  3035. ppufile.putbyte(fpu_used);
  3036. {$else}
  3037. ppufile.putbyte(0);
  3038. {$endif}
  3039. ppufile.putbyte(ord(proctypeoption));
  3040. ppufile.putbyte(ord(proccalloption));
  3041. ppufile.putsmallset(procoptions);
  3042. ppufile.do_interface_crc:=oldintfcrc;
  3043. if po_explicitparaloc in procoptions then
  3044. ppufile.putdata(funcret_paraloc,sizeof(funcret_paraloc));
  3045. { we need to store the count including vs_hidden }
  3046. ppufile.putbyte(para.count);
  3047. hp:=TParaItem(Para.first);
  3048. while assigned(hp) do
  3049. begin
  3050. ppufile.putbyte(byte(hp.paratyp));
  3051. ppufile.puttype(hp.paratype);
  3052. ppufile.putderef(hp.defaultvaluederef);
  3053. ppufile.putderef(hp.parasymderef);
  3054. ppufile.putbyte(byte(hp.is_hidden));
  3055. if po_explicitparaloc in procoptions then
  3056. ppufile.putdata(hp.paraloc,sizeof(hp.paraloc));
  3057. hp:=TParaItem(hp.next);
  3058. end;
  3059. end;
  3060. function tabstractprocdef.typename_paras(showhidden:boolean) : string;
  3061. var
  3062. hs,s : string;
  3063. hp : TParaItem;
  3064. hpc : tconstsym;
  3065. first : boolean;
  3066. begin
  3067. hp:=TParaItem(Para.first);
  3068. s:='';
  3069. first:=true;
  3070. while assigned(hp) do
  3071. begin
  3072. if (not hp.is_hidden) or
  3073. (showhidden) then
  3074. begin
  3075. if first then
  3076. begin
  3077. s:=s+'(';
  3078. first:=false;
  3079. end
  3080. else
  3081. s:=s+',';
  3082. case hp.paratyp of
  3083. vs_var :
  3084. s:=s+'var';
  3085. vs_const :
  3086. s:=s+'const';
  3087. vs_out :
  3088. s:=s+'out';
  3089. end;
  3090. if assigned(hp.paratype.def.typesym) then
  3091. begin
  3092. if s<>'(' then
  3093. s:=s+' ';
  3094. hs:=hp.paratype.def.typesym.realname;
  3095. if hs[1]<>'$' then
  3096. s:=s+hp.paratype.def.typesym.realname
  3097. else
  3098. s:=s+hp.paratype.def.gettypename;
  3099. end
  3100. else
  3101. s:=s+hp.paratype.def.gettypename;
  3102. { default value }
  3103. if assigned(hp.defaultvalue) then
  3104. begin
  3105. hpc:=tconstsym(hp.defaultvalue);
  3106. hs:='';
  3107. case hpc.consttyp of
  3108. conststring,
  3109. constresourcestring :
  3110. hs:=strpas(pchar(hpc.value.valueptr));
  3111. constreal :
  3112. str(pbestreal(hpc.value.valueptr)^,hs);
  3113. constpointer :
  3114. hs:=tostr(hpc.value.valueordptr);
  3115. constord :
  3116. begin
  3117. if is_boolean(hpc.consttype.def) then
  3118. begin
  3119. if hpc.value.valueord<>0 then
  3120. hs:='TRUE'
  3121. else
  3122. hs:='FALSE';
  3123. end
  3124. else
  3125. hs:=tostr(hpc.value.valueord);
  3126. end;
  3127. constnil :
  3128. hs:='nil';
  3129. constset :
  3130. hs:='<set>';
  3131. end;
  3132. if hs<>'' then
  3133. s:=s+'="'+hs+'"';
  3134. end;
  3135. end;
  3136. hp:=TParaItem(hp.next);
  3137. end;
  3138. if not first then
  3139. s:=s+')';
  3140. if (po_varargs in procoptions) then
  3141. s:=s+';VarArgs';
  3142. typename_paras:=s;
  3143. end;
  3144. function tabstractprocdef.is_methodpointer:boolean;
  3145. begin
  3146. result:=false;
  3147. end;
  3148. function tabstractprocdef.is_addressonly:boolean;
  3149. begin
  3150. result:=true;
  3151. end;
  3152. {$ifdef GDB}
  3153. function tabstractprocdef.stabstring : pchar;
  3154. begin
  3155. stabstring := strpnew('abstractproc'+numberstring+';');
  3156. end;
  3157. {$endif GDB}
  3158. {***************************************************************************
  3159. TPROCDEF
  3160. ***************************************************************************}
  3161. constructor tprocdef.create(level:byte);
  3162. begin
  3163. inherited create(level);
  3164. deftype:=procdef;
  3165. has_mangledname:=false;
  3166. _mangledname:=nil;
  3167. fileinfo:=aktfilepos;
  3168. extnumber:=$ffff;
  3169. aliasnames:=tstringlist.create;
  3170. funcretsym:=nil;
  3171. localst := nil;
  3172. defref:=nil;
  3173. lastwritten:=nil;
  3174. refcount:=0;
  3175. if (cs_browser in aktmoduleswitches) and make_ref then
  3176. begin
  3177. defref:=tref.create(defref,@akttokenpos);
  3178. inc(refcount);
  3179. end;
  3180. lastref:=defref;
  3181. forwarddef:=true;
  3182. interfacedef:=false;
  3183. hasforward:=false;
  3184. _class := nil;
  3185. new(inlininginfo);
  3186. fillchar(inlininginfo^,sizeof(tinlininginfo),0);
  3187. overloadnumber:=0;
  3188. {$ifdef GDB}
  3189. isstabwritten := false;
  3190. {$endif GDB}
  3191. end;
  3192. constructor tprocdef.ppuload(ppufile:tcompilerppufile);
  3193. var
  3194. level : byte;
  3195. begin
  3196. inherited ppuload(ppufile);
  3197. deftype:=procdef;
  3198. has_mangledname:=boolean(ppufile.getbyte);
  3199. if has_mangledname then
  3200. _mangledname:=stringdup(ppufile.getstring)
  3201. else
  3202. _mangledname:=nil;
  3203. overloadnumber:=ppufile.getword;
  3204. extnumber:=ppufile.getword;
  3205. level:=ppufile.getbyte;
  3206. ppufile.getderef(_classderef);
  3207. ppufile.getderef(procsymderef);
  3208. ppufile.getposinfo(fileinfo);
  3209. ppufile.getsmallset(symoptions);
  3210. {$ifdef powerpc}
  3211. { library symbol for AmigaOS/MorphOS }
  3212. ppufile.getderef(libsymderef);
  3213. {$endif powerpc}
  3214. { inline stuff }
  3215. if proccalloption=pocall_inline then
  3216. begin
  3217. ppufile.getderef(funcretsymderef);
  3218. new(inlininginfo);
  3219. ppufile.getsmallset(inlininginfo^.flags);
  3220. inlininginfo^.inlinenode:=boolean(ppufile.getbyte);
  3221. end
  3222. else
  3223. funcretsym:=nil;
  3224. { load para symtable }
  3225. parast:=tparasymtable.create(level);
  3226. tparasymtable(parast).ppuload(ppufile);
  3227. parast.defowner:=self;
  3228. { load local symtable }
  3229. if ((proccalloption=pocall_inline) or
  3230. ((current_module.flags and uf_local_browser)<>0)) then
  3231. begin
  3232. localst:=tlocalsymtable.create(level);
  3233. tlocalsymtable(localst).ppuload(ppufile);
  3234. localst.defowner:=self;
  3235. end
  3236. else
  3237. localst:=nil;
  3238. { inline stuff }
  3239. if proccalloption=pocall_inline then
  3240. inlininginfo^.code:=ppuloadnodetree(ppufile)
  3241. else
  3242. inlininginfo := nil;
  3243. { default values for no persistent data }
  3244. if (cs_link_deffile in aktglobalswitches) and
  3245. (tf_need_export in target_info.flags) and
  3246. (po_exports in procoptions) then
  3247. deffile.AddExport(mangledname);
  3248. aliasnames:=tstringlist.create;
  3249. forwarddef:=false;
  3250. interfacedef:=false;
  3251. hasforward:=false;
  3252. lastref:=nil;
  3253. lastwritten:=nil;
  3254. defref:=nil;
  3255. refcount:=0;
  3256. {$ifdef GDB}
  3257. isstabwritten := false;
  3258. {$endif GDB}
  3259. end;
  3260. destructor tprocdef.destroy;
  3261. begin
  3262. if assigned(defref) then
  3263. begin
  3264. defref.freechain;
  3265. defref.free;
  3266. end;
  3267. aliasnames.free;
  3268. if assigned(localst) and (localst.symtabletype<>staticsymtable) then
  3269. begin
  3270. {$ifdef MEMDEBUG}
  3271. memproclocalst.start;
  3272. {$endif MEMDEBUG}
  3273. localst.free;
  3274. {$ifdef MEMDEBUG}
  3275. memproclocalst.start;
  3276. {$endif MEMDEBUG}
  3277. end;
  3278. if (proccalloption=pocall_inline) and assigned(inlininginfo) then
  3279. begin
  3280. {$ifdef MEMDEBUG}
  3281. memprocnodetree.start;
  3282. {$endif MEMDEBUG}
  3283. tnode(inlininginfo^.code).free;
  3284. {$ifdef MEMDEBUG}
  3285. memprocnodetree.start;
  3286. {$endif MEMDEBUG}
  3287. end;
  3288. if assigned(inlininginfo) then
  3289. dispose(inlininginfo);
  3290. if (po_msgstr in procoptions) then
  3291. strdispose(messageinf.str);
  3292. if assigned(_mangledname) then
  3293. begin
  3294. {$ifdef MEMDEBUG}
  3295. memmanglednames.start;
  3296. {$endif MEMDEBUG}
  3297. stringdispose(_mangledname);
  3298. {$ifdef MEMDEBUG}
  3299. memmanglednames.stop;
  3300. {$endif MEMDEBUG}
  3301. end;
  3302. inherited destroy;
  3303. end;
  3304. procedure tprocdef.ppuwrite(ppufile:tcompilerppufile);
  3305. var
  3306. oldintfcrc : boolean;
  3307. oldparasymtable,
  3308. oldlocalsymtable : tsymtable;
  3309. begin
  3310. { released procdef? }
  3311. if not assigned(parast) then
  3312. exit;
  3313. oldparasymtable:=aktparasymtable;
  3314. oldlocalsymtable:=aktlocalsymtable;
  3315. aktparasymtable:=parast;
  3316. aktlocalsymtable:=localst;
  3317. inherited ppuwrite(ppufile);
  3318. oldintfcrc:=ppufile.do_interface_crc;
  3319. ppufile.do_interface_crc:=false;
  3320. ppufile.do_interface_crc:=oldintfcrc;
  3321. ppufile.putbyte(byte(has_mangledname));
  3322. if has_mangledname then
  3323. ppufile.putstring(_mangledname^);
  3324. ppufile.putword(overloadnumber);
  3325. ppufile.putword(extnumber);
  3326. ppufile.putbyte(parast.symtablelevel);
  3327. ppufile.putderef(_classderef);
  3328. ppufile.putderef(procsymderef);
  3329. ppufile.putposinfo(fileinfo);
  3330. ppufile.putsmallset(symoptions);
  3331. {$ifdef powerpc}
  3332. { library symbol for AmigaOS/MorphOS }
  3333. ppufile.putderef(libsymderef);
  3334. {$endif powerpc}
  3335. { inline stuff }
  3336. oldintfcrc:=ppufile.do_crc;
  3337. ppufile.do_crc:=false;
  3338. if proccalloption=pocall_inline then
  3339. begin
  3340. ppufile.putderef(funcretsymderef);
  3341. ppufile.putsmallset(inlininginfo^.flags);
  3342. ppufile.putbyte(byte(inlininginfo^.inlinenode));
  3343. end;
  3344. ppufile.do_crc:=oldintfcrc;
  3345. { write this entry }
  3346. ppufile.writeentry(ibprocdef);
  3347. { Save the para symtable, this is taken from the interface }
  3348. tparasymtable(parast).ppuwrite(ppufile);
  3349. { save localsymtable for inline procedures or when local
  3350. browser info is requested, this has no influence on the crc }
  3351. if assigned(localst) and
  3352. ((proccalloption=pocall_inline) or
  3353. ((current_module.flags and uf_local_browser)<>0)) then
  3354. begin
  3355. oldintfcrc:=ppufile.do_crc;
  3356. ppufile.do_crc:=false;
  3357. tlocalsymtable(localst).ppuwrite(ppufile);
  3358. ppufile.do_crc:=oldintfcrc;
  3359. end;
  3360. { node tree for inlining }
  3361. oldintfcrc:=ppufile.do_crc;
  3362. ppufile.do_crc:=false;
  3363. if proccalloption=pocall_inline then
  3364. ppuwritenodetree(ppufile,inlininginfo^.code);
  3365. ppufile.do_crc:=oldintfcrc;
  3366. aktparasymtable:=oldparasymtable;
  3367. aktlocalsymtable:=oldlocalsymtable;
  3368. end;
  3369. procedure tprocdef.insert_localst;
  3370. begin
  3371. localst:=tlocalsymtable.create(parast.symtablelevel);
  3372. localst.defowner:=self;
  3373. { this is used by insert
  3374. to check same names in parast and localst }
  3375. localst.next:=parast;
  3376. end;
  3377. function tprocdef.fullprocname(showhidden:boolean):string;
  3378. var
  3379. s : string;
  3380. t : ttoken;
  3381. begin
  3382. {$ifdef EXTDEBUG}
  3383. showhidden:=true;
  3384. {$endif EXTDEBUG}
  3385. s:='';
  3386. if assigned(_class) then
  3387. begin
  3388. if po_classmethod in procoptions then
  3389. s:=s+'class ';
  3390. s:=s+_class.objrealname^+'.';
  3391. end;
  3392. if proctypeoption=potype_operator then
  3393. begin
  3394. for t:=NOTOKEN to last_overloaded do
  3395. if procsym.realname='$'+overloaded_names[t] then
  3396. begin
  3397. s:='operator '+arraytokeninfo[t].str+typename_paras(showhidden);
  3398. break;
  3399. end;
  3400. end
  3401. else
  3402. s:=s+procsym.realname+typename_paras(showhidden);
  3403. case proctypeoption of
  3404. potype_constructor:
  3405. s:='constructor '+s;
  3406. potype_destructor:
  3407. s:='destructor '+s;
  3408. else
  3409. if assigned(rettype.def) and
  3410. not(is_void(rettype.def)) then
  3411. s:=s+':'+rettype.def.gettypename;
  3412. end;
  3413. { forced calling convention? }
  3414. if (po_hascallingconvention in procoptions) then
  3415. s:=s+';'+ProcCallOptionStr[proccalloption];
  3416. fullprocname:=s;
  3417. end;
  3418. function tprocdef.is_methodpointer:boolean;
  3419. begin
  3420. result:=assigned(_class);
  3421. end;
  3422. function tprocdef.is_addressonly:boolean;
  3423. begin
  3424. result:=assigned(owner) and
  3425. (owner.symtabletype<>objectsymtable);
  3426. end;
  3427. function tprocdef.is_visible_for_object(currobjdef:tobjectdef):boolean;
  3428. begin
  3429. is_visible_for_object:=false;
  3430. { private symbols are allowed when we are in the same
  3431. module as they are defined }
  3432. if (sp_private in symoptions) and
  3433. (owner.defowner.owner.symtabletype in [globalsymtable,staticsymtable]) and
  3434. (owner.defowner.owner.unitid<>0) then
  3435. exit;
  3436. { protected symbols are vissible in the module that defines them and
  3437. also visible to related objects. The related object must be defined
  3438. in the current module }
  3439. if (sp_protected in symoptions) and
  3440. (
  3441. (
  3442. (owner.defowner.owner.symtabletype in [globalsymtable,staticsymtable]) and
  3443. (owner.defowner.owner.unitid<>0)
  3444. ) and
  3445. not(
  3446. assigned(currobjdef) and
  3447. (currobjdef.owner.unitid=0) and
  3448. currobjdef.is_related(tobjectdef(owner.defowner))
  3449. )
  3450. ) then
  3451. exit;
  3452. is_visible_for_object:=true;
  3453. end;
  3454. function tprocdef.getsymtable(t:tgetsymtable):tsymtable;
  3455. begin
  3456. case t of
  3457. gs_local :
  3458. getsymtable:=localst;
  3459. gs_para :
  3460. getsymtable:=parast;
  3461. else
  3462. getsymtable:=nil;
  3463. end;
  3464. end;
  3465. procedure tprocdef.load_references(ppufile:tcompilerppufile;locals:boolean);
  3466. var
  3467. pos : tfileposinfo;
  3468. move_last : boolean;
  3469. oldparasymtable,
  3470. oldlocalsymtable : tsymtable;
  3471. begin
  3472. oldparasymtable:=aktparasymtable;
  3473. oldlocalsymtable:=aktlocalsymtable;
  3474. aktparasymtable:=parast;
  3475. aktlocalsymtable:=localst;
  3476. move_last:=lastwritten=lastref;
  3477. while (not ppufile.endofentry) do
  3478. begin
  3479. ppufile.getposinfo(pos);
  3480. inc(refcount);
  3481. lastref:=tref.create(lastref,@pos);
  3482. lastref.is_written:=true;
  3483. if refcount=1 then
  3484. defref:=lastref;
  3485. end;
  3486. if move_last then
  3487. lastwritten:=lastref;
  3488. if ((current_module.flags and uf_local_browser)<>0) and
  3489. assigned(localst) and
  3490. locals then
  3491. begin
  3492. tparasymtable(parast).load_references(ppufile,locals);
  3493. tlocalsymtable(localst).load_references(ppufile,locals);
  3494. end;
  3495. aktparasymtable:=oldparasymtable;
  3496. aktlocalsymtable:=oldlocalsymtable;
  3497. end;
  3498. Const
  3499. local_symtable_index : word = $8001;
  3500. function tprocdef.write_references(ppufile:tcompilerppufile;locals:boolean):boolean;
  3501. var
  3502. ref : tref;
  3503. pdo : tobjectdef;
  3504. move_last : boolean;
  3505. d : tderef;
  3506. oldparasymtable,
  3507. oldlocalsymtable : tsymtable;
  3508. begin
  3509. d.reset;
  3510. move_last:=lastwritten=lastref;
  3511. if move_last and
  3512. (((current_module.flags and uf_local_browser)=0) or
  3513. not locals) then
  3514. exit;
  3515. oldparasymtable:=aktparasymtable;
  3516. oldlocalsymtable:=aktlocalsymtable;
  3517. aktparasymtable:=parast;
  3518. aktlocalsymtable:=localst;
  3519. { write address of this symbol }
  3520. d.build(self);
  3521. ppufile.putderef(d);
  3522. { write refs }
  3523. if assigned(lastwritten) then
  3524. ref:=lastwritten
  3525. else
  3526. ref:=defref;
  3527. while assigned(ref) do
  3528. begin
  3529. if ref.moduleindex=current_module.unit_index then
  3530. begin
  3531. ppufile.putposinfo(ref.posinfo);
  3532. ref.is_written:=true;
  3533. if move_last then
  3534. lastwritten:=ref;
  3535. end
  3536. else if not ref.is_written then
  3537. move_last:=false
  3538. else if move_last then
  3539. lastwritten:=ref;
  3540. ref:=ref.nextref;
  3541. end;
  3542. ppufile.writeentry(ibdefref);
  3543. write_references:=true;
  3544. if ((current_module.flags and uf_local_browser)<>0) and
  3545. assigned(localst) and
  3546. locals then
  3547. begin
  3548. pdo:=_class;
  3549. if (owner.symtabletype<>localsymtable) then
  3550. while assigned(pdo) do
  3551. begin
  3552. if pdo.symtable<>aktrecordsymtable then
  3553. begin
  3554. pdo.symtable.unitid:=local_symtable_index;
  3555. inc(local_symtable_index);
  3556. end;
  3557. pdo:=pdo.childof;
  3558. end;
  3559. parast.unitid:=local_symtable_index;
  3560. inc(local_symtable_index);
  3561. localst.unitid:=local_symtable_index;
  3562. inc(local_symtable_index);
  3563. tstoredsymtable(parast).write_references(ppufile,locals);
  3564. tstoredsymtable(localst).write_references(ppufile,locals);
  3565. { decrement for }
  3566. local_symtable_index:=local_symtable_index-2;
  3567. pdo:=_class;
  3568. if (owner.symtabletype<>localsymtable) then
  3569. while assigned(pdo) do
  3570. begin
  3571. if pdo.symtable<>aktrecordsymtable then
  3572. dec(local_symtable_index);
  3573. pdo:=pdo.childof;
  3574. end;
  3575. end;
  3576. aktparasymtable:=oldparasymtable;
  3577. aktlocalsymtable:=oldlocalsymtable;
  3578. end;
  3579. {$ifdef GDB}
  3580. function tprocdef.numberstring : string;
  3581. begin
  3582. { procdefs are always available }
  3583. stab_state:=stab_state_written;
  3584. result:=inherited numberstring;
  3585. end;
  3586. function tprocdef.stabstring: pchar;
  3587. Var
  3588. RType : Char;
  3589. Obj,Info : String;
  3590. stabsstr : string;
  3591. p : pchar;
  3592. begin
  3593. obj := procsym.name;
  3594. info := '';
  3595. if tprocsym(procsym).is_global then
  3596. RType := 'F'
  3597. else
  3598. RType := 'f';
  3599. if assigned(owner) then
  3600. begin
  3601. if (owner.symtabletype = objectsymtable) then
  3602. obj := owner.name^+'__'+procsym.name;
  3603. if not(cs_gdb_valgrind in aktglobalswitches) and
  3604. (owner.symtabletype=localsymtable) and
  3605. assigned(owner.defowner) and
  3606. assigned(tprocdef(owner.defowner).procsym) then
  3607. info := ','+procsym.name+','+tprocdef(owner.defowner).procsym.name;
  3608. end;
  3609. stabsstr:=mangledname;
  3610. getmem(p,length(stabsstr)+255);
  3611. strpcopy(p,'"'+obj+':'+RType
  3612. +tstoreddef(rettype.def).numberstring+info+'",'+tostr(n_function)
  3613. +',0,'+
  3614. tostr(fileinfo.line)
  3615. +',');
  3616. strpcopy(strend(p),stabsstr);
  3617. stabstring:=strnew(p);
  3618. freemem(p,length(stabsstr)+255);
  3619. end;
  3620. procedure tprocdef.concatstabto(asmlist : taasmoutput);
  3621. begin
  3622. { released procdef? }
  3623. if not assigned(parast) then
  3624. exit;
  3625. if (proccalloption=pocall_internproc) then
  3626. exit;
  3627. { be sure to have a number assigned for this def }
  3628. numberstring;
  3629. { write stabs }
  3630. stab_state:=stab_state_writing;
  3631. asmList.concat(Tai_stabs.Create(stabstring));
  3632. if not(po_external in procoptions) then
  3633. begin
  3634. tstoredsymtable(parast).concatstabto(asmlist);
  3635. { local type defs and vars should not be written
  3636. inside the main proc stab }
  3637. if assigned(localst) and
  3638. (localst.symtablelevel>main_program_level) then
  3639. tstoredsymtable(localst).concatstabto(asmlist);
  3640. end;
  3641. stab_state:=stab_state_written;
  3642. end;
  3643. {$endif GDB}
  3644. procedure tprocdef.buildderef;
  3645. var
  3646. oldparasymtable,
  3647. oldlocalsymtable : tsymtable;
  3648. begin
  3649. oldparasymtable:=aktparasymtable;
  3650. oldlocalsymtable:=aktlocalsymtable;
  3651. aktparasymtable:=parast;
  3652. aktlocalsymtable:=localst;
  3653. inherited buildderef;
  3654. _classderef.build(_class);
  3655. { procsym that originaly defined this definition, should be in the
  3656. same symtable }
  3657. procsymderef.build(procsym);
  3658. {$ifdef powerpc}
  3659. { library symbol for AmigaOS/MorphOS }
  3660. libsymderef.build(libsym);
  3661. {$endif powerpc}
  3662. aktparasymtable:=oldparasymtable;
  3663. aktlocalsymtable:=oldlocalsymtable;
  3664. end;
  3665. procedure tprocdef.buildderefimpl;
  3666. var
  3667. oldparasymtable,
  3668. oldlocalsymtable : tsymtable;
  3669. begin
  3670. { released procdef? }
  3671. if not assigned(parast) then
  3672. exit;
  3673. oldparasymtable:=aktparasymtable;
  3674. oldlocalsymtable:=aktlocalsymtable;
  3675. aktparasymtable:=parast;
  3676. aktlocalsymtable:=localst;
  3677. inherited buildderefimpl;
  3678. { Locals }
  3679. if assigned(localst) and
  3680. ((proccalloption=pocall_inline) or
  3681. ((current_module.flags and uf_local_browser)<>0)) then
  3682. begin
  3683. tlocalsymtable(localst).buildderef;
  3684. tlocalsymtable(localst).buildderefimpl;
  3685. end;
  3686. { inline tree }
  3687. if (proccalloption=pocall_inline) then
  3688. begin
  3689. funcretsymderef.build(funcretsym);
  3690. inlininginfo^.code.buildderefimpl;
  3691. end;
  3692. aktparasymtable:=oldparasymtable;
  3693. aktlocalsymtable:=oldlocalsymtable;
  3694. end;
  3695. procedure tprocdef.deref;
  3696. var
  3697. oldparasymtable,
  3698. oldlocalsymtable : tsymtable;
  3699. begin
  3700. { released procdef? }
  3701. if not assigned(parast) then
  3702. exit;
  3703. oldparasymtable:=aktparasymtable;
  3704. oldlocalsymtable:=aktlocalsymtable;
  3705. aktparasymtable:=parast;
  3706. aktlocalsymtable:=localst;
  3707. inherited deref;
  3708. _class:=tobjectdef(_classderef.resolve);
  3709. { procsym that originaly defined this definition, should be in the
  3710. same symtable }
  3711. procsym:=tprocsym(procsymderef.resolve);
  3712. {$ifdef powerpc}
  3713. { library symbol for AmigaOS/MorphOS }
  3714. libsym:=tvarsym(libsymderef.resolve);
  3715. {$endif powerpc}
  3716. aktparasymtable:=oldparasymtable;
  3717. aktlocalsymtable:=oldlocalsymtable;
  3718. end;
  3719. procedure tprocdef.derefimpl;
  3720. var
  3721. oldparasymtable,
  3722. oldlocalsymtable : tsymtable;
  3723. begin
  3724. oldparasymtable:=aktparasymtable;
  3725. oldlocalsymtable:=aktlocalsymtable;
  3726. aktparasymtable:=parast;
  3727. aktlocalsymtable:=localst;
  3728. { Locals }
  3729. if assigned(localst) then
  3730. begin
  3731. tlocalsymtable(localst).deref;
  3732. tlocalsymtable(localst).derefimpl;
  3733. end;
  3734. { Inline }
  3735. if (proccalloption=pocall_inline) then
  3736. begin
  3737. inlininginfo^.code.derefimpl;
  3738. { funcretsym, this is always located in the localst }
  3739. funcretsym:=tsym(funcretsymderef.resolve);
  3740. end
  3741. else
  3742. begin
  3743. { safety }
  3744. funcretsym:=nil;
  3745. end;
  3746. aktparasymtable:=oldparasymtable;
  3747. aktlocalsymtable:=oldlocalsymtable;
  3748. end;
  3749. function tprocdef.gettypename : string;
  3750. begin
  3751. gettypename := FullProcName(false);
  3752. end;
  3753. function tprocdef.mangledname : string;
  3754. var
  3755. hp : TParaItem;
  3756. begin
  3757. if assigned(_mangledname) then
  3758. begin
  3759. {$ifdef compress}
  3760. mangledname:=minilzw_decode(_mangledname^);
  3761. {$else}
  3762. mangledname:=_mangledname^;
  3763. {$endif}
  3764. exit;
  3765. end;
  3766. { we need to use the symtable where the procsym is inserted,
  3767. because that is visible to the world }
  3768. mangledname:=make_mangledname('',procsym.owner,procsym.name);
  3769. if overloadnumber>0 then
  3770. mangledname:=mangledname+'$'+tostr(overloadnumber);
  3771. { add parameter types }
  3772. hp:=TParaItem(Para.first);
  3773. while assigned(hp) do
  3774. begin
  3775. if not hp.is_hidden then
  3776. mangledname:=mangledname+'$'+hp.paratype.def.mangledparaname;
  3777. hp:=TParaItem(hp.next);
  3778. end;
  3779. {$ifdef compress}
  3780. _mangledname:=stringdup(minilzw_encode(mangledname));
  3781. {$else}
  3782. _mangledname:=stringdup(mangledname);
  3783. {$endif}
  3784. end;
  3785. function tprocdef.cplusplusmangledname : string;
  3786. function getcppparaname(p : tdef) : string;
  3787. const
  3788. ordtype2str : array[tbasetype] of string[2] = (
  3789. '',
  3790. 'Uc','Us','Ui','Us',
  3791. 'Sc','s','i','x',
  3792. 'b','b','b',
  3793. 'c','w','x');
  3794. var
  3795. s : string;
  3796. begin
  3797. case p.deftype of
  3798. orddef:
  3799. s:=ordtype2str[torddef(p).typ];
  3800. pointerdef:
  3801. s:='P'+getcppparaname(tpointerdef(p).pointertype.def);
  3802. else
  3803. internalerror(2103001);
  3804. end;
  3805. getcppparaname:=s;
  3806. end;
  3807. var
  3808. s,s2 : string;
  3809. param : TParaItem;
  3810. begin
  3811. s := procsym.realname;
  3812. if procsym.owner.symtabletype=objectsymtable then
  3813. begin
  3814. s2:=upper(tobjectdef(procsym.owner.defowner).typesym.realname);
  3815. case proctypeoption of
  3816. potype_destructor:
  3817. s:='_$_'+tostr(length(s2))+s2;
  3818. potype_constructor:
  3819. s:='___'+tostr(length(s2))+s2;
  3820. else
  3821. s:='_'+s+'__'+tostr(length(s2))+s2;
  3822. end;
  3823. end
  3824. else s:=s+'__';
  3825. s:=s+'F';
  3826. { concat modifiers }
  3827. { !!!!! }
  3828. { now we handle the parameters }
  3829. param := TParaItem(Para.first);
  3830. if assigned(param) then
  3831. while assigned(param) do
  3832. begin
  3833. s2:=getcppparaname(param.paratype.def);
  3834. if param.paratyp in [vs_var,vs_out] then
  3835. s2:='R'+s2;
  3836. s:=s+s2;
  3837. param:=TParaItem(param.next);
  3838. end
  3839. else
  3840. s:=s+'v';
  3841. cplusplusmangledname:=s;
  3842. end;
  3843. procedure tprocdef.setmangledname(const s : string);
  3844. begin
  3845. stringdispose(_mangledname);
  3846. {$ifdef compress}
  3847. _mangledname:=stringdup(minilzw_encode(s));
  3848. {$else}
  3849. _mangledname:=stringdup(s);
  3850. {$endif}
  3851. has_mangledname:=true;
  3852. end;
  3853. {***************************************************************************
  3854. TPROCVARDEF
  3855. ***************************************************************************}
  3856. constructor tprocvardef.create(level:byte);
  3857. begin
  3858. inherited create(level);
  3859. deftype:=procvardef;
  3860. end;
  3861. constructor tprocvardef.ppuload(ppufile:tcompilerppufile);
  3862. begin
  3863. inherited ppuload(ppufile);
  3864. deftype:=procvardef;
  3865. { load para symtable }
  3866. parast:=tparasymtable.create(unknown_level);
  3867. tparasymtable(parast).ppuload(ppufile);
  3868. parast.defowner:=self;
  3869. end;
  3870. procedure tprocvardef.ppuwrite(ppufile:tcompilerppufile);
  3871. var
  3872. oldparasymtable,
  3873. oldlocalsymtable : tsymtable;
  3874. begin
  3875. oldparasymtable:=aktparasymtable;
  3876. oldlocalsymtable:=aktlocalsymtable;
  3877. aktparasymtable:=parast;
  3878. aktlocalsymtable:=nil;
  3879. { here we cannot get a real good value so just give something }
  3880. { plausible (PM) }
  3881. { a more secure way would be
  3882. to allways store in a temp }
  3883. {$ifdef i386}
  3884. if is_fpu(rettype.def) then
  3885. fpu_used:={2}maxfpuregs
  3886. else
  3887. fpu_used:=0;
  3888. {$endif i386}
  3889. inherited ppuwrite(ppufile);
  3890. { Write this entry }
  3891. ppufile.writeentry(ibprocvardef);
  3892. { Save the para symtable, this is taken from the interface }
  3893. tparasymtable(parast).ppuwrite(ppufile);
  3894. aktparasymtable:=oldparasymtable;
  3895. aktlocalsymtable:=oldlocalsymtable;
  3896. end;
  3897. procedure tprocvardef.buildderef;
  3898. var
  3899. oldparasymtable,
  3900. oldlocalsymtable : tsymtable;
  3901. begin
  3902. oldparasymtable:=aktparasymtable;
  3903. oldlocalsymtable:=aktlocalsymtable;
  3904. aktparasymtable:=parast;
  3905. aktlocalsymtable:=nil;
  3906. inherited buildderef;
  3907. aktparasymtable:=oldparasymtable;
  3908. aktlocalsymtable:=oldlocalsymtable;
  3909. end;
  3910. procedure tprocvardef.deref;
  3911. var
  3912. oldparasymtable,
  3913. oldlocalsymtable : tsymtable;
  3914. begin
  3915. oldparasymtable:=aktparasymtable;
  3916. oldlocalsymtable:=aktlocalsymtable;
  3917. aktparasymtable:=parast;
  3918. aktlocalsymtable:=nil;
  3919. inherited deref;
  3920. aktparasymtable:=oldparasymtable;
  3921. aktlocalsymtable:=oldlocalsymtable;
  3922. end;
  3923. function tprocvardef.getsymtable(t:tgetsymtable):tsymtable;
  3924. begin
  3925. case t of
  3926. gs_para :
  3927. getsymtable:=parast;
  3928. else
  3929. getsymtable:=nil;
  3930. end;
  3931. end;
  3932. function tprocvardef.size : longint;
  3933. begin
  3934. if (po_methodpointer in procoptions) and
  3935. not(po_addressonly in procoptions) then
  3936. size:=2*sizeof(aint)
  3937. else
  3938. size:=sizeof(aint);
  3939. end;
  3940. function tprocvardef.is_methodpointer:boolean;
  3941. begin
  3942. result:=(po_methodpointer in procoptions);
  3943. end;
  3944. function tprocvardef.is_addressonly:boolean;
  3945. begin
  3946. result:=not(po_methodpointer in procoptions) or
  3947. (po_addressonly in procoptions);
  3948. end;
  3949. {$ifdef GDB}
  3950. function tprocvardef.stabstring : pchar;
  3951. var
  3952. nss : pchar;
  3953. { i : longint; }
  3954. begin
  3955. { i := maxparacount; }
  3956. getmem(nss,1024);
  3957. { it is not a function but a function pointer !! (PM) }
  3958. strpcopy(nss,'*f'+tstoreddef(rettype.def).numberstring{+','+tostr(i)});
  3959. { this confuses gdb !!
  3960. we should use 'F' instead of 'f' but
  3961. as we use c++ language mode
  3962. it does not like that either
  3963. Please do not remove this part
  3964. might be used once
  3965. gdb for pascal is ready PM }
  3966. {$ifdef disabled}
  3967. param := para1;
  3968. i := 0;
  3969. while assigned(param) do
  3970. begin
  3971. inc(i);
  3972. if param^.paratyp = vs_value then vartyp := '1' else vartyp := '0';
  3973. {Here we have lost the parameter names !!}
  3974. pst := strpnew('p'+tostr(i)+':'+param^.paratype.def.numberstring+','+vartyp+';');
  3975. strcat(nss,pst);
  3976. strdispose(pst);
  3977. param := param^.next;
  3978. end;
  3979. {$endif}
  3980. {strpcopy(strend(nss),';');}
  3981. stabstring := strnew(nss);
  3982. freemem(nss,1024);
  3983. end;
  3984. procedure tprocvardef.concatstabto(asmlist : taasmoutput);
  3985. begin
  3986. if (stab_state in [stab_state_writing,stab_state_written]) then
  3987. exit;
  3988. tstoreddef(rettype.def).concatstabto(asmlist);
  3989. inherited concatstabto(asmlist);
  3990. end;
  3991. {$endif GDB}
  3992. procedure tprocvardef.write_rtti_data(rt:trttitype);
  3993. var
  3994. pdc : TParaItem;
  3995. methodkind, paraspec : byte;
  3996. begin
  3997. if po_methodpointer in procoptions then
  3998. begin
  3999. { write method id and name }
  4000. rttiList.concat(Tai_const.Create_8bit(tkmethod));
  4001. write_rtti_name;
  4002. { write kind of method (can only be function or procedure)}
  4003. if rettype.def = voidtype.def then
  4004. methodkind := mkProcedure
  4005. else
  4006. methodkind := mkFunction;
  4007. rttiList.concat(Tai_const.Create_8bit(methodkind));
  4008. { get # of parameters }
  4009. rttiList.concat(Tai_const.Create_8bit(maxparacount));
  4010. { write parameter info. The parameters must be written in reverse order
  4011. if this method uses right to left parameter pushing! }
  4012. if proccalloption in pushleftright_pocalls then
  4013. pdc:=TParaItem(Para.first)
  4014. else
  4015. pdc:=TParaItem(Para.last);
  4016. while assigned(pdc) do
  4017. begin
  4018. { only store user visible parameters }
  4019. if not pdc.is_hidden then
  4020. begin
  4021. case pdc.paratyp of
  4022. vs_value: paraspec := 0;
  4023. vs_const: paraspec := pfConst;
  4024. vs_var : paraspec := pfVar;
  4025. vs_out : paraspec := pfOut;
  4026. end;
  4027. { write flags for current parameter }
  4028. rttiList.concat(Tai_const.Create_8bit(paraspec));
  4029. { write name of current parameter }
  4030. if assigned(pdc.parasym) then
  4031. begin
  4032. rttiList.concat(Tai_const.Create_8bit(length(pdc.parasym.realname)));
  4033. rttiList.concat(Tai_string.Create(pdc.parasym.realname));
  4034. end
  4035. else
  4036. rttiList.concat(Tai_const.Create_8bit(0));
  4037. { write name of type of current parameter }
  4038. tstoreddef(pdc.paratype.def).write_rtti_name;
  4039. end;
  4040. if proccalloption in pushleftright_pocalls then
  4041. pdc:=TParaItem(pdc.next)
  4042. else
  4043. pdc:=TParaItem(pdc.previous);
  4044. end;
  4045. { write name of result type }
  4046. tstoreddef(rettype.def).write_rtti_name;
  4047. end;
  4048. end;
  4049. function tprocvardef.is_publishable : boolean;
  4050. begin
  4051. is_publishable:=(po_methodpointer in procoptions);
  4052. end;
  4053. function tprocvardef.gettypename : string;
  4054. var
  4055. s: string;
  4056. showhidden : boolean;
  4057. begin
  4058. {$ifdef EXTDEBUG}
  4059. showhidden:=true;
  4060. {$else EXTDEBUG}
  4061. showhidden:=false;
  4062. {$endif EXTDEBUG}
  4063. s:='<';
  4064. if po_classmethod in procoptions then
  4065. s := s+'class method type of'
  4066. else
  4067. if po_addressonly in procoptions then
  4068. s := s+'address of'
  4069. else
  4070. s := s+'procedure variable type of';
  4071. if assigned(rettype.def) and
  4072. (rettype.def<>voidtype.def) then
  4073. s:=s+' function'+typename_paras(showhidden)+':'+rettype.def.gettypename
  4074. else
  4075. s:=s+' procedure'+typename_paras(showhidden);
  4076. if po_methodpointer in procoptions then
  4077. s := s+' of object';
  4078. gettypename := s+';'+ProcCallOptionStr[proccalloption]+'>';
  4079. end;
  4080. {***************************************************************************
  4081. TOBJECTDEF
  4082. ***************************************************************************}
  4083. constructor tobjectdef.create(ot : tobjectdeftype;const n : string;c : tobjectdef);
  4084. begin
  4085. inherited create;
  4086. objecttype:=ot;
  4087. deftype:=objectdef;
  4088. objectoptions:=[];
  4089. childof:=nil;
  4090. symtable:=tobjectsymtable.create(n,aktpackrecords);
  4091. { create space for vmt !! }
  4092. vmt_offset:=0;
  4093. symtable.defowner:=self;
  4094. lastvtableindex:=0;
  4095. set_parent(c);
  4096. objname:=stringdup(upper(n));
  4097. objrealname:=stringdup(n);
  4098. if objecttype in [odt_interfacecorba,odt_interfacecom] then
  4099. prepareguid;
  4100. { setup implemented interfaces }
  4101. if objecttype in [odt_class,odt_interfacecorba] then
  4102. implementedinterfaces:=timplementedinterfaces.create
  4103. else
  4104. implementedinterfaces:=nil;
  4105. {$ifdef GDB}
  4106. writing_class_record_stab:=false;
  4107. {$endif GDB}
  4108. end;
  4109. constructor tobjectdef.ppuload(ppufile:tcompilerppufile);
  4110. var
  4111. i,implintfcount: longint;
  4112. d : tderef;
  4113. begin
  4114. inherited ppuloaddef(ppufile);
  4115. deftype:=objectdef;
  4116. objecttype:=tobjectdeftype(ppufile.getbyte);
  4117. objrealname:=stringdup(ppufile.getstring);
  4118. objname:=stringdup(upper(objrealname^));
  4119. symtable:=tobjectsymtable.create(objrealname^,0);
  4120. tobjectsymtable(symtable).datasize:=ppufile.getlongint;
  4121. tobjectsymtable(symtable).fieldalignment:=ppufile.getbyte;
  4122. tobjectsymtable(symtable).recordalignment:=ppufile.getbyte;
  4123. vmt_offset:=ppufile.getlongint;
  4124. ppufile.getderef(childofderef);
  4125. ppufile.getsmallset(objectoptions);
  4126. { load guid }
  4127. iidstr:=nil;
  4128. if objecttype in [odt_interfacecom,odt_interfacecorba] then
  4129. begin
  4130. new(iidguid);
  4131. ppufile.getguid(iidguid^);
  4132. iidstr:=stringdup(ppufile.getstring);
  4133. lastvtableindex:=ppufile.getlongint;
  4134. end;
  4135. { load implemented interfaces }
  4136. if objecttype in [odt_class,odt_interfacecorba] then
  4137. begin
  4138. implementedinterfaces:=timplementedinterfaces.create;
  4139. implintfcount:=ppufile.getlongint;
  4140. for i:=1 to implintfcount do
  4141. begin
  4142. ppufile.getderef(d);
  4143. implementedinterfaces.addintf_deref(d);
  4144. implementedinterfaces.ioffsets(i)^:=ppufile.getlongint;
  4145. end;
  4146. end
  4147. else
  4148. implementedinterfaces:=nil;
  4149. tobjectsymtable(symtable).ppuload(ppufile);
  4150. symtable.defowner:=self;
  4151. { handles the predefined class tobject }
  4152. { the last TOBJECT which is loaded gets }
  4153. { it ! }
  4154. if (childof=nil) and
  4155. (objecttype=odt_class) and
  4156. (objname^='TOBJECT') then
  4157. class_tobject:=self;
  4158. if (childof=nil) and
  4159. (objecttype=odt_interfacecom) and
  4160. (objname^='IUNKNOWN') then
  4161. interface_iunknown:=self;
  4162. {$ifdef GDB}
  4163. writing_class_record_stab:=false;
  4164. {$endif GDB}
  4165. end;
  4166. destructor tobjectdef.destroy;
  4167. begin
  4168. if assigned(symtable) then
  4169. symtable.free;
  4170. stringdispose(objname);
  4171. stringdispose(objrealname);
  4172. if assigned(iidstr) then
  4173. stringdispose(iidstr);
  4174. if assigned(implementedinterfaces) then
  4175. implementedinterfaces.free;
  4176. if assigned(iidguid) then
  4177. dispose(iidguid);
  4178. inherited destroy;
  4179. end;
  4180. procedure tobjectdef.ppuwrite(ppufile:tcompilerppufile);
  4181. var
  4182. implintfcount : longint;
  4183. i : longint;
  4184. begin
  4185. inherited ppuwritedef(ppufile);
  4186. ppufile.putbyte(byte(objecttype));
  4187. ppufile.putstring(objrealname^);
  4188. ppufile.putlongint(tobjectsymtable(symtable).datasize);
  4189. ppufile.putbyte(tobjectsymtable(symtable).fieldalignment);
  4190. ppufile.putbyte(tobjectsymtable(symtable).recordalignment);
  4191. ppufile.putlongint(vmt_offset);
  4192. ppufile.putderef(childofderef);
  4193. ppufile.putsmallset(objectoptions);
  4194. if objecttype in [odt_interfacecom,odt_interfacecorba] then
  4195. begin
  4196. ppufile.putguid(iidguid^);
  4197. ppufile.putstring(iidstr^);
  4198. ppufile.putlongint(lastvtableindex);
  4199. end;
  4200. if objecttype in [odt_class,odt_interfacecorba] then
  4201. begin
  4202. implintfcount:=implementedinterfaces.count;
  4203. ppufile.putlongint(implintfcount);
  4204. for i:=1 to implintfcount do
  4205. begin
  4206. ppufile.putderef(implementedinterfaces.interfacesderef(i));
  4207. ppufile.putlongint(implementedinterfaces.ioffsets(i)^);
  4208. end;
  4209. end;
  4210. ppufile.writeentry(ibobjectdef);
  4211. tobjectsymtable(symtable).ppuwrite(ppufile);
  4212. end;
  4213. function tobjectdef.gettypename:string;
  4214. begin
  4215. gettypename:=typename;
  4216. end;
  4217. procedure tobjectdef.buildderef;
  4218. var
  4219. oldrecsyms : tsymtable;
  4220. begin
  4221. inherited buildderef;
  4222. childofderef.build(childof);
  4223. oldrecsyms:=aktrecordsymtable;
  4224. aktrecordsymtable:=symtable;
  4225. tstoredsymtable(symtable).buildderef;
  4226. aktrecordsymtable:=oldrecsyms;
  4227. if objecttype in [odt_class,odt_interfacecorba] then
  4228. implementedinterfaces.buildderef;
  4229. end;
  4230. procedure tobjectdef.deref;
  4231. var
  4232. oldrecsyms : tsymtable;
  4233. begin
  4234. inherited deref;
  4235. childof:=tobjectdef(childofderef.resolve);
  4236. oldrecsyms:=aktrecordsymtable;
  4237. aktrecordsymtable:=symtable;
  4238. tstoredsymtable(symtable).deref;
  4239. aktrecordsymtable:=oldrecsyms;
  4240. if objecttype in [odt_class,odt_interfacecorba] then
  4241. implementedinterfaces.deref;
  4242. end;
  4243. function tobjectdef.getparentdef:tdef;
  4244. begin
  4245. result:=childof;
  4246. end;
  4247. procedure tobjectdef.prepareguid;
  4248. begin
  4249. { set up guid }
  4250. if not assigned(iidguid) then
  4251. begin
  4252. new(iidguid);
  4253. fillchar(iidguid^,sizeof(iidguid^),0); { default null guid }
  4254. end;
  4255. { setup iidstring }
  4256. if not assigned(iidstr) then
  4257. iidstr:=stringdup(''); { default is empty string }
  4258. end;
  4259. procedure tobjectdef.set_parent( c : tobjectdef);
  4260. begin
  4261. { nothing to do if the parent was not forward !}
  4262. if assigned(childof) then
  4263. exit;
  4264. childof:=c;
  4265. { some options are inherited !! }
  4266. if assigned(c) then
  4267. begin
  4268. { only important for classes }
  4269. lastvtableindex:=c.lastvtableindex;
  4270. objectoptions:=objectoptions+(c.objectoptions*
  4271. [oo_has_virtual,oo_has_private,oo_has_protected,
  4272. oo_has_constructor,oo_has_destructor]);
  4273. if not (objecttype in [odt_interfacecom,odt_interfacecorba]) then
  4274. begin
  4275. { add the data of the anchestor class }
  4276. inc(tobjectsymtable(symtable).datasize,tobjectsymtable(c.symtable).datasize);
  4277. if (oo_has_vmt in objectoptions) and
  4278. (oo_has_vmt in c.objectoptions) then
  4279. dec(tobjectsymtable(symtable).datasize,sizeof(aint));
  4280. { if parent has a vmt field then
  4281. the offset is the same for the child PM }
  4282. if (oo_has_vmt in c.objectoptions) or is_class(self) then
  4283. begin
  4284. vmt_offset:=c.vmt_offset;
  4285. include(objectoptions,oo_has_vmt);
  4286. end;
  4287. end;
  4288. end;
  4289. end;
  4290. procedure tobjectdef.insertvmt;
  4291. begin
  4292. if objecttype in [odt_interfacecom,odt_interfacecorba] then
  4293. exit;
  4294. if (oo_has_vmt in objectoptions) then
  4295. internalerror(12345)
  4296. else
  4297. begin
  4298. tobjectsymtable(symtable).datasize:=align(tobjectsymtable(symtable).datasize,
  4299. tobjectsymtable(symtable).fieldalignment);
  4300. vmt_offset:=tobjectsymtable(symtable).datasize;
  4301. inc(tobjectsymtable(symtable).datasize,sizeof(aint));
  4302. include(objectoptions,oo_has_vmt);
  4303. end;
  4304. end;
  4305. procedure tobjectdef.check_forwards;
  4306. begin
  4307. if not(objecttype in [odt_interfacecom,odt_interfacecorba]) then
  4308. tstoredsymtable(symtable).check_forwards;
  4309. if (oo_is_forward in objectoptions) then
  4310. begin
  4311. { ok, in future, the forward can be resolved }
  4312. Message1(sym_e_class_forward_not_resolved,objrealname^);
  4313. exclude(objectoptions,oo_is_forward);
  4314. end;
  4315. end;
  4316. { true, if self inherits from d (or if they are equal) }
  4317. function tobjectdef.is_related(d : tobjectdef) : boolean;
  4318. var
  4319. hp : tobjectdef;
  4320. begin
  4321. hp:=self;
  4322. while assigned(hp) do
  4323. begin
  4324. if hp=d then
  4325. begin
  4326. is_related:=true;
  4327. exit;
  4328. end;
  4329. hp:=hp.childof;
  4330. end;
  4331. is_related:=false;
  4332. end;
  4333. (* procedure tobjectdef._searchdestructor(sym : tnamedindexitem;arg:pointer);
  4334. var
  4335. p : pprocdeflist;
  4336. begin
  4337. { if we found already a destructor, then we exit }
  4338. if assigned(sd) then
  4339. exit;
  4340. if tsym(sym).typ=procsym then
  4341. begin
  4342. p:=tprocsym(sym).defs;
  4343. while assigned(p) do
  4344. begin
  4345. if p^.def.proctypeoption=potype_destructor then
  4346. begin
  4347. sd:=p^.def;
  4348. exit;
  4349. end;
  4350. p:=p^.next;
  4351. end;
  4352. end;
  4353. end;*)
  4354. procedure _searchdestructor(sym:Tnamedindexitem;sd:pointer);
  4355. begin
  4356. { if we found already a destructor, then we exit }
  4357. if (ppointer(sd)^=nil) and
  4358. (Tsym(sym).typ=procsym) then
  4359. ppointer(sd)^:=Tprocsym(sym).search_procdef_bytype(potype_destructor);
  4360. end;
  4361. function tobjectdef.searchdestructor : tprocdef;
  4362. var
  4363. o : tobjectdef;
  4364. sd : tprocdef;
  4365. begin
  4366. searchdestructor:=nil;
  4367. o:=self;
  4368. sd:=nil;
  4369. while assigned(o) do
  4370. begin
  4371. o.symtable.foreach_static({$ifdef FPCPROCVAR}@{$endif}_searchdestructor,@sd);
  4372. if assigned(sd) then
  4373. begin
  4374. searchdestructor:=sd;
  4375. exit;
  4376. end;
  4377. o:=o.childof;
  4378. end;
  4379. end;
  4380. function tobjectdef.size : longint;
  4381. begin
  4382. if objecttype in [odt_class,odt_interfacecom,odt_interfacecorba] then
  4383. result:=sizeof(aint)
  4384. else
  4385. result:=tobjectsymtable(symtable).datasize;
  4386. end;
  4387. function tobjectdef.alignment:longint;
  4388. begin
  4389. if objecttype in [odt_class,odt_interfacecom,odt_interfacecorba] then
  4390. alignment:=sizeof(aint)
  4391. else
  4392. alignment:=tobjectsymtable(symtable).recordalignment;
  4393. end;
  4394. function tobjectdef.vmtmethodoffset(index:longint):longint;
  4395. begin
  4396. { for offset of methods for classes, see rtl/inc/objpash.inc }
  4397. case objecttype of
  4398. odt_class:
  4399. { the +2*sizeof(Aint) is size and -size }
  4400. vmtmethodoffset:=(index+10)*sizeof(aint)+2*sizeof(AInt);
  4401. odt_interfacecom,odt_interfacecorba:
  4402. vmtmethodoffset:=index*sizeof(aint);
  4403. else
  4404. {$ifdef WITHDMT}
  4405. vmtmethodoffset:=(index+4)*sizeof(aint);
  4406. {$else WITHDMT}
  4407. vmtmethodoffset:=(index+3)*sizeof(aint);
  4408. {$endif WITHDMT}
  4409. end;
  4410. end;
  4411. function tobjectdef.vmt_mangledname : string;
  4412. begin
  4413. if not(oo_has_vmt in objectoptions) then
  4414. Message1(parser_n_object_has_no_vmt,objrealname^);
  4415. vmt_mangledname:=make_mangledname('VMT',owner,objname^);
  4416. end;
  4417. function tobjectdef.rtti_name : string;
  4418. begin
  4419. rtti_name:=make_mangledname('RTTI',owner,objname^);
  4420. end;
  4421. {$ifdef GDB}
  4422. procedure tobjectdef.proc_addname(p :tnamedindexitem;arg:pointer);
  4423. var virtualind,argnames : string;
  4424. newrec : pchar;
  4425. pd : tprocdef;
  4426. lindex : longint;
  4427. para : TParaItem;
  4428. arglength : byte;
  4429. sp : char;
  4430. state:^Trecord_stabgen_state;
  4431. olds:integer;
  4432. begin
  4433. state:=arg;
  4434. if tsym(p).typ = procsym then
  4435. begin
  4436. pd := tprocsym(p).first_procdef;
  4437. if (po_virtualmethod in pd.procoptions) then
  4438. begin
  4439. lindex := pd.extnumber;
  4440. {doesnt seem to be necessary
  4441. lindex := lindex or $80000000;}
  4442. virtualind := '*'+tostr(lindex)+';'+pd._class.classnumberstring+';'
  4443. end
  4444. else
  4445. virtualind := '.';
  4446. { used by gdbpas to recognize constructor and destructors }
  4447. if (pd.proctypeoption=potype_constructor) then
  4448. argnames:='__ct__'
  4449. else if (pd.proctypeoption=potype_destructor) then
  4450. argnames:='__dt__'
  4451. else
  4452. argnames := '';
  4453. { arguments are not listed here }
  4454. {we don't need another definition}
  4455. para := TParaItem(pd.Para.first);
  4456. while assigned(para) do
  4457. begin
  4458. if Para.paratype.def.deftype = formaldef then
  4459. begin
  4460. case Para.paratyp of
  4461. vs_var :
  4462. argnames := argnames+'3var';
  4463. vs_const :
  4464. argnames:=argnames+'5const';
  4465. vs_out :
  4466. argnames:=argnames+'3out';
  4467. end;
  4468. end
  4469. else
  4470. begin
  4471. { if the arg definition is like (v: ^byte;..
  4472. there is no sym attached to data !!! }
  4473. if assigned(Para.paratype.def.typesym) then
  4474. begin
  4475. arglength := length(Para.paratype.def.typesym.name);
  4476. argnames := argnames + tostr(arglength)+Para.paratype.def.typesym.name;
  4477. end
  4478. else
  4479. argnames:=argnames+'11unnamedtype';
  4480. end;
  4481. para := TParaItem(Para.next);
  4482. end;
  4483. { here 2A must be changed for private and protected }
  4484. { 0 is private 1 protected and 2 public }
  4485. if (sp_private in tsym(p).symoptions) then
  4486. sp:='0'
  4487. else if (sp_protected in tsym(p).symoptions) then
  4488. sp:='1'
  4489. else
  4490. sp:='2';
  4491. newrec:=stabstr_evaluate('$1::$2=##$3;:$4;$5A$6;',[p.name,pd.numberstring,
  4492. Tstoreddef(pd.rettype.def).numberstring,argnames,sp,
  4493. virtualind]);
  4494. { get spare place for a string at the end }
  4495. olds:=state^.stabsize;
  4496. inc(state^.stabsize,strlen(newrec));
  4497. if state^.stabsize>=state^.staballoc-256 then
  4498. begin
  4499. inc(state^.staballoc,memsizeinc);
  4500. reallocmem(state^.stabstring,state^.staballoc);
  4501. end;
  4502. strcopy(state^.stabstring+olds,newrec);
  4503. strdispose(newrec);
  4504. {This should be used for case !!
  4505. RecOffset := RecOffset + pd.size;}
  4506. end;
  4507. end;
  4508. procedure tobjectdef.proc_concatstabto(p :tnamedindexitem;arg:pointer);
  4509. var
  4510. pd : tprocdef;
  4511. begin
  4512. if tsym(p).typ = procsym then
  4513. begin
  4514. pd := tprocsym(p).first_procdef;
  4515. tstoreddef(pd.rettype.def).concatstabto(taasmoutput(arg));
  4516. end;
  4517. end;
  4518. function tobjectdef.stabstring : pchar;
  4519. var anc : tobjectdef;
  4520. state:Trecord_stabgen_state;
  4521. ts : string;
  4522. begin
  4523. if not (objecttype=odt_class) or writing_class_record_stab then
  4524. begin
  4525. state.staballoc:=memsizeinc;
  4526. getmem(state.stabstring,state.staballoc);
  4527. strpcopy(state.stabstring,'s'+tostr(tobjectsymtable(symtable).datasize));
  4528. if assigned(childof) then
  4529. begin
  4530. {only one ancestor not virtual, public, at base offset 0 }
  4531. { !1 , 0 2 0 , }
  4532. strpcopy(strend(state.stabstring),'!1,020,'+childof.classnumberstring+';');
  4533. end;
  4534. {virtual table to implement yet}
  4535. state.recoffset:=0;
  4536. state.stabsize:=strlen(state.stabstring);
  4537. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}field_addname,@state);
  4538. if (oo_has_vmt in objectoptions) then
  4539. if not assigned(childof) or not(oo_has_vmt in childof.objectoptions) then
  4540. begin
  4541. ts:='$vf'+classnumberstring+':'+tstoreddef(vmtarraytype.def).numberstring+','+tostr(vmt_offset*8)+';';
  4542. strpcopy(state.stabstring+state.stabsize,ts);
  4543. inc(state.stabsize,length(ts));
  4544. end;
  4545. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}proc_addname,@state);
  4546. if (oo_has_vmt in objectoptions) then
  4547. begin
  4548. anc := self;
  4549. while assigned(anc.childof) and (oo_has_vmt in anc.childof.objectoptions) do
  4550. anc := anc.childof;
  4551. { just in case anc = self }
  4552. ts:=';~%'+anc.classnumberstring+';';
  4553. end
  4554. else
  4555. ts:=';';
  4556. strpcopy(state.stabstring+state.stabsize,ts);
  4557. inc(state.stabsize,length(ts));
  4558. reallocmem(state.stabstring,state.stabsize+1);
  4559. stabstring:=state.stabstring;
  4560. end
  4561. else
  4562. begin
  4563. stabstring:=strpnew('*'+classnumberstring);
  4564. end;
  4565. end;
  4566. procedure tobjectdef.set_globalnb;
  4567. begin
  4568. globalnb:=PglobalTypeCount^;
  4569. inc(PglobalTypeCount^);
  4570. { classes need two type numbers, the globalnb is set to the ptr }
  4571. if objecttype=odt_class then
  4572. begin
  4573. globalnb:=PGlobalTypeCount^;
  4574. inc(PglobalTypeCount^);
  4575. end;
  4576. end;
  4577. function tobjectdef.classnumberstring : string;
  4578. begin
  4579. if objecttype=odt_class then
  4580. begin
  4581. if globalnb=0 then
  4582. numberstring;
  4583. dec(globalnb);
  4584. classnumberstring:=numberstring;
  4585. inc(globalnb);
  4586. end
  4587. else
  4588. classnumberstring:=numberstring;
  4589. end;
  4590. function tobjectdef.allstabstring : pchar;
  4591. var
  4592. stabchar : string[2];
  4593. ss,st : pchar;
  4594. sname : string;
  4595. begin
  4596. ss := stabstring;
  4597. getmem(st,strlen(ss)+512);
  4598. stabchar := 't';
  4599. if deftype in tagtypes then
  4600. stabchar := 'Tt';
  4601. if assigned(typesym) then
  4602. sname := typesym.name
  4603. else
  4604. sname := ' ';
  4605. if writing_class_record_stab then
  4606. strpcopy(st,'"'+sname+':'+stabchar+classnumberstring+'=')
  4607. else
  4608. strpcopy(st,'"'+sname+':'+stabchar+numberstring+'=');
  4609. strpcopy(strecopy(strend(st),ss),'",'+tostr(N_LSYM)+',0,0,0');
  4610. allstabstring := strnew(st);
  4611. freemem(st,strlen(ss)+512);
  4612. strdispose(ss);
  4613. end;
  4614. procedure tobjectdef.concatstabto(asmlist : taasmoutput);
  4615. var
  4616. oldtypesym : tsym;
  4617. stab_str : pchar;
  4618. anc : tobjectdef;
  4619. begin
  4620. if (stab_state in [stab_state_writing,stab_state_written]) then
  4621. exit;
  4622. stab_state:=stab_state_writing;
  4623. tstoreddef(vmtarraytype.def).concatstabto(asmlist);
  4624. { first the parents }
  4625. anc:=self;
  4626. while assigned(anc.childof) do
  4627. begin
  4628. anc:=anc.childof;
  4629. anc.concatstabto(asmlist);
  4630. end;
  4631. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}field_concatstabto,asmlist);
  4632. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}proc_concatstabto,asmlist);
  4633. stab_state:=stab_state_used;
  4634. if objecttype=odt_class then
  4635. begin
  4636. { Write the record class itself }
  4637. writing_class_record_stab:=true;
  4638. inherited concatstabto(asmlist);
  4639. writing_class_record_stab:=false;
  4640. { Write the invisible pointer class }
  4641. oldtypesym:=typesym;
  4642. typesym:=nil;
  4643. stab_str := allstabstring;
  4644. asmList.concat(Tai_stabs.Create(stab_str));
  4645. typesym:=oldtypesym;
  4646. end
  4647. else
  4648. inherited concatstabto(asmlist);
  4649. end;
  4650. {$endif GDB}
  4651. function tobjectdef.needs_inittable : boolean;
  4652. begin
  4653. case objecttype of
  4654. odt_class :
  4655. needs_inittable:=false;
  4656. odt_interfacecom:
  4657. needs_inittable:=true;
  4658. odt_interfacecorba:
  4659. needs_inittable:=is_related(interface_iunknown);
  4660. odt_object:
  4661. needs_inittable:=tobjectsymtable(symtable).needs_init_final;
  4662. else
  4663. internalerror(200108267);
  4664. end;
  4665. end;
  4666. function tobjectdef.members_need_inittable : boolean;
  4667. begin
  4668. members_need_inittable:=tobjectsymtable(symtable).needs_init_final;
  4669. end;
  4670. procedure tobjectdef.count_published_properties(sym:tnamedindexitem;arg:pointer);
  4671. begin
  4672. if needs_prop_entry(tsym(sym)) and
  4673. (tsym(sym).typ<>varsym) then
  4674. inc(count);
  4675. end;
  4676. procedure tobjectdef.write_property_info(sym : tnamedindexitem;arg:pointer);
  4677. var
  4678. proctypesinfo : byte;
  4679. procedure writeproc(proc : tsymlist; shiftvalue : byte);
  4680. var
  4681. typvalue : byte;
  4682. hp : psymlistitem;
  4683. address : longint;
  4684. def : tdef;
  4685. begin
  4686. if not(assigned(proc) and assigned(proc.firstsym)) then
  4687. begin
  4688. rttiList.concat(Tai_const.create(ait_const_ptr,1));
  4689. typvalue:=3;
  4690. end
  4691. else if proc.firstsym^.sym.typ=varsym then
  4692. begin
  4693. address:=0;
  4694. hp:=proc.firstsym;
  4695. def:=nil;
  4696. while assigned(hp) do
  4697. begin
  4698. case hp^.sltype of
  4699. sl_load :
  4700. begin
  4701. def:=tvarsym(hp^.sym).vartype.def;
  4702. inc(address,tvarsym(hp^.sym).fieldoffset);
  4703. end;
  4704. sl_subscript :
  4705. begin
  4706. if not(assigned(def) and (def.deftype=recorddef)) then
  4707. internalerror(200402171);
  4708. inc(address,tvarsym(hp^.sym).fieldoffset);
  4709. def:=tvarsym(hp^.sym).vartype.def;
  4710. end;
  4711. sl_vec :
  4712. begin
  4713. if not(assigned(def) and (def.deftype=arraydef)) then
  4714. internalerror(200402172);
  4715. def:=tarraydef(def).elementtype.def;
  4716. inc(address,def.size*hp^.value);
  4717. end;
  4718. end;
  4719. hp:=hp^.next;
  4720. end;
  4721. rttiList.concat(Tai_const.create(ait_const_ptr,address));
  4722. typvalue:=0;
  4723. end
  4724. else
  4725. begin
  4726. { When there was an error then procdef is not assigned }
  4727. if not assigned(proc.procdef) then
  4728. exit;
  4729. if not(po_virtualmethod in tprocdef(proc.procdef).procoptions) then
  4730. begin
  4731. rttiList.concat(Tai_const.createname(tprocdef(proc.procdef).mangledname,AT_FUNCTION,0));
  4732. typvalue:=1;
  4733. end
  4734. else
  4735. begin
  4736. { virtual method, write vmt offset }
  4737. rttiList.concat(Tai_const.create(ait_const_ptr,
  4738. tprocdef(proc.procdef)._class.vmtmethodoffset(tprocdef(proc.procdef).extnumber)));
  4739. typvalue:=2;
  4740. end;
  4741. end;
  4742. proctypesinfo:=proctypesinfo or (typvalue shl shiftvalue);
  4743. end;
  4744. begin
  4745. if needs_prop_entry(tsym(sym)) then
  4746. case tsym(sym).typ of
  4747. varsym:
  4748. begin
  4749. {$ifdef dummy}
  4750. if not(tvarsym(sym).vartype.def.deftype=objectdef) or
  4751. not(tobjectdef(tvarsym(sym).vartype.def).is_class) then
  4752. internalerror(1509992);
  4753. { access to implicit class property as field }
  4754. proctypesinfo:=(0 shl 0) or (0 shl 2) or (0 shl 4);
  4755. rttiList.concat(Tai_const_symbol.Createname(tvarsym(sym.vartype.def.get_rtti_label),AT_DATA,0));
  4756. rttiList.concat(Tai_const.create(ait_const_ptr,tvarsym(sym.address)));
  4757. rttiList.concat(Tai_const.create(ait_const_ptr,tvarsym(sym.address)));
  4758. { by default stored }
  4759. rttiList.concat(Tai_const.Create_32bit(1));
  4760. { index as well as ... }
  4761. rttiList.concat(Tai_const.Create_32bit(0));
  4762. { default value are zero }
  4763. rttiList.concat(Tai_const.Create_32bit(0));
  4764. rttiList.concat(Tai_const.Create_16bit(count));
  4765. inc(count);
  4766. rttiList.concat(Tai_const.Create_8bit(proctypesinfo));
  4767. rttiList.concat(Tai_const.Create_8bit(length(tvarsym(sym.realname))));
  4768. rttiList.concat(Tai_string.Create(tvarsym(sym.realname)));
  4769. {$endif dummy}
  4770. end;
  4771. propertysym:
  4772. begin
  4773. if ppo_indexed in tpropertysym(sym).propoptions then
  4774. proctypesinfo:=$40
  4775. else
  4776. proctypesinfo:=0;
  4777. rttiList.concat(Tai_const.Create_sym(tstoreddef(tpropertysym(sym).proptype.def).get_rtti_label(fullrtti)));
  4778. writeproc(tpropertysym(sym).readaccess,0);
  4779. writeproc(tpropertysym(sym).writeaccess,2);
  4780. { isn't it stored ? }
  4781. if not(ppo_stored in tpropertysym(sym).propoptions) then
  4782. begin
  4783. rttiList.concat(Tai_const.create_sym(nil));
  4784. proctypesinfo:=proctypesinfo or (3 shl 4);
  4785. end
  4786. else
  4787. writeproc(tpropertysym(sym).storedaccess,4);
  4788. rttiList.concat(Tai_const.Create_32bit(tpropertysym(sym).index));
  4789. rttiList.concat(Tai_const.Create_32bit(tpropertysym(sym).default));
  4790. rttiList.concat(Tai_const.Create_16bit(count));
  4791. inc(count);
  4792. rttiList.concat(Tai_const.Create_8bit(proctypesinfo));
  4793. rttiList.concat(Tai_const.Create_8bit(length(tpropertysym(sym).realname)));
  4794. rttiList.concat(Tai_string.Create(tpropertysym(sym).realname));
  4795. end;
  4796. else internalerror(1509992);
  4797. end;
  4798. end;
  4799. procedure tobjectdef.generate_published_child_rtti(sym : tnamedindexitem;arg:pointer);
  4800. begin
  4801. if needs_prop_entry(tsym(sym)) then
  4802. begin
  4803. case tsym(sym).typ of
  4804. propertysym:
  4805. tstoreddef(tpropertysym(sym).proptype.def).get_rtti_label(fullrtti);
  4806. varsym:
  4807. tstoreddef(tvarsym(sym).vartype.def).get_rtti_label(fullrtti);
  4808. else
  4809. internalerror(1509991);
  4810. end;
  4811. end;
  4812. end;
  4813. procedure tobjectdef.write_child_rtti_data(rt:trttitype);
  4814. begin
  4815. FRTTIType:=rt;
  4816. case rt of
  4817. initrtti :
  4818. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}generate_field_rtti,nil);
  4819. fullrtti :
  4820. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}generate_published_child_rtti,nil);
  4821. else
  4822. internalerror(200108301);
  4823. end;
  4824. end;
  4825. type
  4826. tclasslistitem = class(TLinkedListItem)
  4827. index : longint;
  4828. p : tobjectdef;
  4829. end;
  4830. var
  4831. classtablelist : tlinkedlist;
  4832. tablecount : longint;
  4833. function searchclasstablelist(p : tobjectdef) : tclasslistitem;
  4834. var
  4835. hp : tclasslistitem;
  4836. begin
  4837. hp:=tclasslistitem(classtablelist.first);
  4838. while assigned(hp) do
  4839. if hp.p=p then
  4840. begin
  4841. searchclasstablelist:=hp;
  4842. exit;
  4843. end
  4844. else
  4845. hp:=tclasslistitem(hp.next);
  4846. searchclasstablelist:=nil;
  4847. end;
  4848. procedure tobjectdef.count_published_fields(sym:tnamedindexitem;arg:pointer);
  4849. var
  4850. hp : tclasslistitem;
  4851. begin
  4852. if needs_prop_entry(tsym(sym)) and
  4853. (tsym(sym).typ=varsym) then
  4854. begin
  4855. if tvarsym(sym).vartype.def.deftype<>objectdef then
  4856. internalerror(0206001);
  4857. hp:=searchclasstablelist(tobjectdef(tvarsym(sym).vartype.def));
  4858. if not(assigned(hp)) then
  4859. begin
  4860. hp:=tclasslistitem.create;
  4861. hp.p:=tobjectdef(tvarsym(sym).vartype.def);
  4862. hp.index:=tablecount;
  4863. classtablelist.concat(hp);
  4864. inc(tablecount);
  4865. end;
  4866. inc(count);
  4867. end;
  4868. end;
  4869. procedure tobjectdef.writefields(sym:tnamedindexitem;arg:pointer);
  4870. var
  4871. hp : tclasslistitem;
  4872. begin
  4873. if needs_prop_entry(tsym(sym)) and
  4874. (tsym(sym).typ=varsym) then
  4875. begin
  4876. rttiList.concat(Tai_const.Create_32bit(tvarsym(sym).fieldoffset));
  4877. hp:=searchclasstablelist(tobjectdef(tvarsym(sym).vartype.def));
  4878. if not(assigned(hp)) then
  4879. internalerror(0206002);
  4880. rttiList.concat(Tai_const.Create_16bit(hp.index));
  4881. rttiList.concat(Tai_const.Create_8bit(length(tvarsym(sym).realname)));
  4882. rttiList.concat(Tai_string.Create(tvarsym(sym).realname));
  4883. end;
  4884. end;
  4885. function tobjectdef.generate_field_table : tasmlabel;
  4886. var
  4887. fieldtable,
  4888. classtable : tasmlabel;
  4889. hp : tclasslistitem;
  4890. begin
  4891. classtablelist:=TLinkedList.Create;
  4892. objectlibrary.getdatalabel(fieldtable);
  4893. objectlibrary.getdatalabel(classtable);
  4894. count:=0;
  4895. tablecount:=0;
  4896. maybe_new_object_file(rttiList);
  4897. new_section(rttiList,sec_rodata,classtable.name,const_align(sizeof(aint)));
  4898. { fields }
  4899. symtable.foreach({$ifdef FPC}@{$endif}count_published_fields,nil);
  4900. rttiList.concat(Tai_label.Create(fieldtable));
  4901. rttiList.concat(Tai_const.Create_16bit(count));
  4902. rttiList.concat(Tai_const.Create_sym(classtable));
  4903. symtable.foreach({$ifdef FPC}@{$endif}writefields,nil);
  4904. { generate the class table }
  4905. rttilist.concat(tai_align.create(const_align(sizeof(aint))));
  4906. rttiList.concat(Tai_label.Create(classtable));
  4907. rttiList.concat(Tai_const.Create_16bit(tablecount));
  4908. hp:=tclasslistitem(classtablelist.first);
  4909. while assigned(hp) do
  4910. begin
  4911. rttiList.concat(Tai_const.Createname(tobjectdef(hp.p).vmt_mangledname,AT_DATA,0));
  4912. hp:=tclasslistitem(hp.next);
  4913. end;
  4914. generate_field_table:=fieldtable;
  4915. classtablelist.free;
  4916. end;
  4917. function tobjectdef.next_free_name_index : longint;
  4918. var
  4919. i : longint;
  4920. begin
  4921. if assigned(childof) and (oo_can_have_published in childof.objectoptions) then
  4922. i:=childof.next_free_name_index
  4923. else
  4924. i:=0;
  4925. count:=0;
  4926. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}count_published_properties,nil);
  4927. next_free_name_index:=i+count;
  4928. end;
  4929. procedure tobjectdef.write_rtti_data(rt:trttitype);
  4930. begin
  4931. case objecttype of
  4932. odt_class:
  4933. rttiList.concat(Tai_const.Create_8bit(tkclass));
  4934. odt_object:
  4935. rttiList.concat(Tai_const.Create_8bit(tkobject));
  4936. odt_interfacecom:
  4937. rttiList.concat(Tai_const.Create_8bit(tkinterface));
  4938. odt_interfacecorba:
  4939. rttiList.concat(Tai_const.Create_8bit(tkinterfaceCorba));
  4940. else
  4941. exit;
  4942. end;
  4943. { generate the name }
  4944. rttiList.concat(Tai_const.Create_8bit(length(objrealname^)));
  4945. rttiList.concat(Tai_string.Create(objrealname^));
  4946. case rt of
  4947. initrtti :
  4948. begin
  4949. rttiList.concat(Tai_const.Create_32bit(size));
  4950. if objecttype in [odt_class,odt_object] then
  4951. begin
  4952. count:=0;
  4953. FRTTIType:=rt;
  4954. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}count_field_rtti,nil);
  4955. rttiList.concat(Tai_const.Create_32bit(count));
  4956. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}write_field_rtti,nil);
  4957. end;
  4958. end;
  4959. fullrtti :
  4960. begin
  4961. if (oo_has_vmt in objectoptions) and
  4962. not(objecttype in [odt_interfacecom,odt_interfacecorba]) then
  4963. rttiList.concat(Tai_const.Createname(vmt_mangledname,AT_DATA,0))
  4964. else
  4965. rttiList.concat(Tai_const.create_sym(nil));
  4966. { write owner typeinfo }
  4967. if assigned(childof) and (oo_can_have_published in childof.objectoptions) then
  4968. rttiList.concat(Tai_const.Create_sym(childof.get_rtti_label(fullrtti)))
  4969. else
  4970. rttiList.concat(Tai_const.create_sym(nil));
  4971. { count total number of properties }
  4972. if assigned(childof) and (oo_can_have_published in childof.objectoptions) then
  4973. count:=childof.next_free_name_index
  4974. else
  4975. count:=0;
  4976. { write it }
  4977. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}count_published_properties,nil);
  4978. rttiList.concat(Tai_const.Create_16bit(count));
  4979. { write unit name }
  4980. rttiList.concat(Tai_const.Create_8bit(length(current_module.realmodulename^)));
  4981. rttiList.concat(Tai_string.Create(current_module.realmodulename^));
  4982. { write published properties count }
  4983. count:=0;
  4984. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}count_published_properties,nil);
  4985. rttiList.concat(Tai_const.Create_16bit(count));
  4986. { count is used to write nameindex }
  4987. { but we need an offset of the owner }
  4988. { to give each property an own slot }
  4989. if assigned(childof) and (oo_can_have_published in childof.objectoptions) then
  4990. count:=childof.next_free_name_index
  4991. else
  4992. count:=0;
  4993. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}write_property_info,nil);
  4994. end;
  4995. end;
  4996. end;
  4997. function tobjectdef.is_publishable : boolean;
  4998. begin
  4999. is_publishable:=objecttype in [odt_class,odt_interfacecom,odt_interfacecorba];
  5000. end;
  5001. {****************************************************************************
  5002. TIMPLEMENTEDINTERFACES
  5003. ****************************************************************************}
  5004. type
  5005. tnamemap = class(TNamedIndexItem)
  5006. newname: pstring;
  5007. constructor create(const aname, anewname: string);
  5008. destructor destroy; override;
  5009. end;
  5010. constructor tnamemap.create(const aname, anewname: string);
  5011. begin
  5012. inherited createname(name);
  5013. newname:=stringdup(anewname);
  5014. end;
  5015. destructor tnamemap.destroy;
  5016. begin
  5017. stringdispose(newname);
  5018. inherited destroy;
  5019. end;
  5020. type
  5021. tprocdefstore = class(TNamedIndexItem)
  5022. procdef: tprocdef;
  5023. constructor create(aprocdef: tprocdef);
  5024. end;
  5025. constructor tprocdefstore.create(aprocdef: tprocdef);
  5026. begin
  5027. inherited create;
  5028. procdef:=aprocdef;
  5029. end;
  5030. type
  5031. timplintfentry = class(TNamedIndexItem)
  5032. intf: tobjectdef;
  5033. intfderef : tderef;
  5034. ioffs: longint;
  5035. namemappings: tdictionary;
  5036. procdefs: TIndexArray;
  5037. constructor create(aintf: tobjectdef);
  5038. constructor create_deref(const d:tderef);
  5039. destructor destroy; override;
  5040. end;
  5041. constructor timplintfentry.create(aintf: tobjectdef);
  5042. begin
  5043. inherited create;
  5044. intf:=aintf;
  5045. ioffs:=-1;
  5046. namemappings:=nil;
  5047. procdefs:=nil;
  5048. end;
  5049. constructor timplintfentry.create_deref(const d:tderef);
  5050. begin
  5051. inherited create;
  5052. intf:=nil;
  5053. intfderef:=d;
  5054. ioffs:=-1;
  5055. namemappings:=nil;
  5056. procdefs:=nil;
  5057. end;
  5058. destructor timplintfentry.destroy;
  5059. begin
  5060. if assigned(namemappings) then
  5061. namemappings.free;
  5062. if assigned(procdefs) then
  5063. procdefs.free;
  5064. inherited destroy;
  5065. end;
  5066. constructor timplementedinterfaces.create;
  5067. begin
  5068. finterfaces:=tindexarray.create(1);
  5069. end;
  5070. destructor timplementedinterfaces.destroy;
  5071. begin
  5072. finterfaces.destroy;
  5073. end;
  5074. function timplementedinterfaces.count: longint;
  5075. begin
  5076. count:=finterfaces.count;
  5077. end;
  5078. procedure timplementedinterfaces.checkindex(intfindex: longint);
  5079. begin
  5080. if (intfindex<1) or (intfindex>count) then
  5081. InternalError(200006123);
  5082. end;
  5083. function timplementedinterfaces.interfaces(intfindex: longint): tobjectdef;
  5084. begin
  5085. checkindex(intfindex);
  5086. interfaces:=timplintfentry(finterfaces.search(intfindex)).intf;
  5087. end;
  5088. function timplementedinterfaces.interfacesderef(intfindex: longint): tderef;
  5089. begin
  5090. checkindex(intfindex);
  5091. interfacesderef:=timplintfentry(finterfaces.search(intfindex)).intfderef;
  5092. end;
  5093. function timplementedinterfaces.ioffsets(intfindex: longint): plongint;
  5094. begin
  5095. checkindex(intfindex);
  5096. ioffsets:=@timplintfentry(finterfaces.search(intfindex)).ioffs;
  5097. end;
  5098. function timplementedinterfaces.searchintf(def: tdef): longint;
  5099. var
  5100. i: longint;
  5101. begin
  5102. i:=1;
  5103. while (i<=count) and (tdef(interfaces(i))<>def) do inc(i);
  5104. if i<=count then
  5105. searchintf:=i
  5106. else
  5107. searchintf:=-1;
  5108. end;
  5109. procedure timplementedinterfaces.buildderef;
  5110. var
  5111. i: longint;
  5112. begin
  5113. for i:=1 to count do
  5114. with timplintfentry(finterfaces.search(i)) do
  5115. intfderef.build(intf);
  5116. end;
  5117. procedure timplementedinterfaces.deref;
  5118. var
  5119. i: longint;
  5120. begin
  5121. for i:=1 to count do
  5122. with timplintfentry(finterfaces.search(i)) do
  5123. intf:=tobjectdef(intfderef.resolve);
  5124. end;
  5125. procedure timplementedinterfaces.addintf_deref(const d:tderef);
  5126. begin
  5127. finterfaces.insert(timplintfentry.create_deref(d));
  5128. end;
  5129. procedure timplementedinterfaces.addintf(def: tdef);
  5130. begin
  5131. if not assigned(def) or (searchintf(def)<>-1) or (def.deftype<>objectdef) or
  5132. not (tobjectdef(def).objecttype in [odt_interfacecom,odt_interfacecorba]) then
  5133. internalerror(200006124);
  5134. finterfaces.insert(timplintfentry.create(tobjectdef(def)));
  5135. end;
  5136. procedure timplementedinterfaces.clearmappings;
  5137. var
  5138. i: longint;
  5139. begin
  5140. for i:=1 to count do
  5141. with timplintfentry(finterfaces.search(i)) do
  5142. begin
  5143. if assigned(namemappings) then
  5144. namemappings.free;
  5145. namemappings:=nil;
  5146. end;
  5147. end;
  5148. procedure timplementedinterfaces.addmappings(intfindex: longint; const name, newname: string);
  5149. begin
  5150. checkindex(intfindex);
  5151. with timplintfentry(finterfaces.search(intfindex)) do
  5152. begin
  5153. if not assigned(namemappings) then
  5154. namemappings:=tdictionary.create;
  5155. namemappings.insert(tnamemap.create(name,newname));
  5156. end;
  5157. end;
  5158. function timplementedinterfaces.getmappings(intfindex: longint; const name: string; var nextexist: pointer): string;
  5159. begin
  5160. checkindex(intfindex);
  5161. if not assigned(nextexist) then
  5162. with timplintfentry(finterfaces.search(intfindex)) do
  5163. begin
  5164. if assigned(namemappings) then
  5165. nextexist:=namemappings.search(name)
  5166. else
  5167. nextexist:=nil;
  5168. end;
  5169. if assigned(nextexist) then
  5170. begin
  5171. getmappings:=tnamemap(nextexist).newname^;
  5172. nextexist:=tnamemap(nextexist).listnext;
  5173. end
  5174. else
  5175. getmappings:='';
  5176. end;
  5177. procedure timplementedinterfaces.clearimplprocs;
  5178. var
  5179. i: longint;
  5180. begin
  5181. for i:=1 to count do
  5182. with timplintfentry(finterfaces.search(i)) do
  5183. begin
  5184. if assigned(procdefs) then
  5185. procdefs.free;
  5186. procdefs:=nil;
  5187. end;
  5188. end;
  5189. procedure timplementedinterfaces.addimplproc(intfindex: longint; procdef: tprocdef);
  5190. begin
  5191. checkindex(intfindex);
  5192. with timplintfentry(finterfaces.search(intfindex)) do
  5193. begin
  5194. if not assigned(procdefs) then
  5195. procdefs:=tindexarray.create(4);
  5196. procdefs.insert(tprocdefstore.create(procdef));
  5197. end;
  5198. end;
  5199. function timplementedinterfaces.implproccount(intfindex: longint): longint;
  5200. begin
  5201. checkindex(intfindex);
  5202. with timplintfentry(finterfaces.search(intfindex)) do
  5203. if assigned(procdefs) then
  5204. implproccount:=procdefs.count
  5205. else
  5206. implproccount:=0;
  5207. end;
  5208. function timplementedinterfaces.implprocs(intfindex: longint; procindex: longint): tprocdef;
  5209. begin
  5210. checkindex(intfindex);
  5211. with timplintfentry(finterfaces.search(intfindex)) do
  5212. if assigned(procdefs) then
  5213. implprocs:=tprocdefstore(procdefs.search(procindex)).procdef
  5214. else
  5215. internalerror(200006131);
  5216. end;
  5217. function timplementedinterfaces.isimplmergepossible(intfindex, remainindex: longint; var weight: longint): boolean;
  5218. var
  5219. possible: boolean;
  5220. i: longint;
  5221. iiep1: TIndexArray;
  5222. iiep2: TIndexArray;
  5223. begin
  5224. checkindex(intfindex);
  5225. checkindex(remainindex);
  5226. iiep1:=timplintfentry(finterfaces.search(intfindex)).procdefs;
  5227. iiep2:=timplintfentry(finterfaces.search(remainindex)).procdefs;
  5228. if not assigned(iiep1) then { empty interface is mergeable :-) }
  5229. begin
  5230. possible:=true;
  5231. weight:=0;
  5232. end
  5233. else
  5234. begin
  5235. possible:=assigned(iiep2) and (iiep1.count<=iiep2.count);
  5236. i:=1;
  5237. while (possible) and (i<=iiep1.count) do
  5238. begin
  5239. possible:=
  5240. (tprocdefstore(iiep1.search(i)).procdef=tprocdefstore(iiep2.search(i)).procdef);
  5241. inc(i);
  5242. end;
  5243. if possible then
  5244. weight:=iiep1.count;
  5245. end;
  5246. isimplmergepossible:=possible;
  5247. end;
  5248. {****************************************************************************
  5249. TFORWARDDEF
  5250. ****************************************************************************}
  5251. constructor tforwarddef.create(const s:string;const pos : tfileposinfo);
  5252. var
  5253. oldregisterdef : boolean;
  5254. begin
  5255. { never register the forwarddefs, they are disposed at the
  5256. end of the type declaration block }
  5257. oldregisterdef:=registerdef;
  5258. registerdef:=false;
  5259. inherited create;
  5260. registerdef:=oldregisterdef;
  5261. deftype:=forwarddef;
  5262. tosymname:=stringdup(s);
  5263. forwardpos:=pos;
  5264. end;
  5265. function tforwarddef.gettypename:string;
  5266. begin
  5267. gettypename:='unresolved forward to '+tosymname^;
  5268. end;
  5269. destructor tforwarddef.destroy;
  5270. begin
  5271. if assigned(tosymname) then
  5272. stringdispose(tosymname);
  5273. inherited destroy;
  5274. end;
  5275. {****************************************************************************
  5276. TERRORDEF
  5277. ****************************************************************************}
  5278. constructor terrordef.create;
  5279. begin
  5280. inherited create;
  5281. deftype:=errordef;
  5282. end;
  5283. {$ifdef GDB}
  5284. function terrordef.stabstring : pchar;
  5285. begin
  5286. stabstring:=strpnew('error'+numberstring);
  5287. end;
  5288. procedure terrordef.concatstabto(asmlist : taasmoutput);
  5289. begin
  5290. { No internal error needed, an normal error is already
  5291. thrown }
  5292. end;
  5293. {$endif GDB}
  5294. function terrordef.gettypename:string;
  5295. begin
  5296. gettypename:='<erroneous type>';
  5297. end;
  5298. function terrordef.getmangledparaname:string;
  5299. begin
  5300. getmangledparaname:='error';
  5301. end;
  5302. {****************************************************************************
  5303. Definition Helpers
  5304. ****************************************************************************}
  5305. function is_interfacecom(def: tdef): boolean;
  5306. begin
  5307. is_interfacecom:=
  5308. assigned(def) and
  5309. (def.deftype=objectdef) and
  5310. (tobjectdef(def).objecttype=odt_interfacecom);
  5311. end;
  5312. function is_interfacecorba(def: tdef): boolean;
  5313. begin
  5314. is_interfacecorba:=
  5315. assigned(def) and
  5316. (def.deftype=objectdef) and
  5317. (tobjectdef(def).objecttype=odt_interfacecorba);
  5318. end;
  5319. function is_interface(def: tdef): boolean;
  5320. begin
  5321. is_interface:=
  5322. assigned(def) and
  5323. (def.deftype=objectdef) and
  5324. (tobjectdef(def).objecttype in [odt_interfacecom,odt_interfacecorba]);
  5325. end;
  5326. function is_class(def: tdef): boolean;
  5327. begin
  5328. is_class:=
  5329. assigned(def) and
  5330. (def.deftype=objectdef) and
  5331. (tobjectdef(def).objecttype=odt_class);
  5332. end;
  5333. function is_object(def: tdef): boolean;
  5334. begin
  5335. is_object:=
  5336. assigned(def) and
  5337. (def.deftype=objectdef) and
  5338. (tobjectdef(def).objecttype=odt_object);
  5339. end;
  5340. function is_cppclass(def: tdef): boolean;
  5341. begin
  5342. is_cppclass:=
  5343. assigned(def) and
  5344. (def.deftype=objectdef) and
  5345. (tobjectdef(def).objecttype=odt_cppclass);
  5346. end;
  5347. function is_class_or_interface(def: tdef): boolean;
  5348. begin
  5349. is_class_or_interface:=
  5350. assigned(def) and
  5351. (def.deftype=objectdef) and
  5352. (tobjectdef(def).objecttype in [odt_class,odt_interfacecom,odt_interfacecorba]);
  5353. end;
  5354. end.
  5355. {
  5356. $Log$
  5357. Revision 1.248 2004-07-19 19:15:50 florian
  5358. * fixed funcret_paraloc writing in units
  5359. Revision 1.247 2004/07/14 21:37:41 olle
  5360. - removed unused types
  5361. Revision 1.246 2004/07/12 09:14:04 jonas
  5362. * inline procedures at the node tree level, but only under some very
  5363. limited circumstances for now (only procedures, and only if they have
  5364. no or only vs_out/vs_var parameters).
  5365. * fixed ppudump for inline procedures
  5366. * fixed ppudump for ppc
  5367. Revision 1.245 2004/07/09 22:17:32 peter
  5368. * revert has_localst patch
  5369. * replace aktstaticsymtable/aktglobalsymtable with current_module
  5370. Revision 1.244 2004/07/06 19:52:04 peter
  5371. * fix storing of localst in ppu
  5372. Revision 1.243 2004/06/20 08:55:30 florian
  5373. * logs truncated
  5374. Revision 1.242 2004/06/18 15:16:46 peter
  5375. * remove obsolete cardinal() typecasts
  5376. Revision 1.241 2004/06/16 20:07:09 florian
  5377. * dwarf branch merged
  5378. Revision 1.240 2004/05/25 18:51:14 peter
  5379. * range check error
  5380. Revision 1.239 2004/05/23 20:57:10 peter
  5381. * removed unused voidprocdef
  5382. Revision 1.238 2004/05/23 15:23:30 peter
  5383. * fixed qword(longint) that removed sign from the number
  5384. * removed code in the compiler that relied on wrong qword(longint)
  5385. code generation
  5386. }