symdef.pas 190 KB

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