symdef.pas 190 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219
  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 (proccalloption=pocall_inline) or
  3366. ((current_module.flags and uf_local_browser)<>0) then
  3367. begin
  3368. { we must write a localsymtable }
  3369. if not assigned(localst) then
  3370. insert_localst;
  3371. oldintfcrc:=ppufile.do_crc;
  3372. ppufile.do_crc:=false;
  3373. tlocalsymtable(localst).ppuwrite(ppufile);
  3374. ppufile.do_crc:=oldintfcrc;
  3375. end;
  3376. { node tree for inlining }
  3377. oldintfcrc:=ppufile.do_crc;
  3378. ppufile.do_crc:=false;
  3379. if proccalloption=pocall_inline then
  3380. ppuwritenodetree(ppufile,inlininginfo^.code);
  3381. ppufile.do_crc:=oldintfcrc;
  3382. aktparasymtable:=oldparasymtable;
  3383. aktlocalsymtable:=oldlocalsymtable;
  3384. end;
  3385. procedure tprocdef.insert_localst;
  3386. begin
  3387. localst:=tlocalsymtable.create(parast.symtablelevel);
  3388. localst.defowner:=self;
  3389. { this is used by insert
  3390. to check same names in parast and localst }
  3391. localst.next:=parast;
  3392. end;
  3393. function tprocdef.fullprocname(showhidden:boolean):string;
  3394. var
  3395. s : string;
  3396. t : ttoken;
  3397. begin
  3398. {$ifdef EXTDEBUG}
  3399. showhidden:=true;
  3400. {$endif EXTDEBUG}
  3401. s:='';
  3402. if assigned(_class) then
  3403. begin
  3404. if po_classmethod in procoptions then
  3405. s:=s+'class ';
  3406. s:=s+_class.objrealname^+'.';
  3407. end;
  3408. if proctypeoption=potype_operator then
  3409. begin
  3410. for t:=NOTOKEN to last_overloaded do
  3411. if procsym.realname='$'+overloaded_names[t] then
  3412. begin
  3413. s:='operator '+arraytokeninfo[t].str+typename_paras(showhidden);
  3414. break;
  3415. end;
  3416. end
  3417. else
  3418. s:=s+procsym.realname+typename_paras(showhidden);
  3419. case proctypeoption of
  3420. potype_constructor:
  3421. s:='constructor '+s;
  3422. potype_destructor:
  3423. s:='destructor '+s;
  3424. else
  3425. if assigned(rettype.def) and
  3426. not(is_void(rettype.def)) then
  3427. s:=s+':'+rettype.def.gettypename;
  3428. end;
  3429. { forced calling convention? }
  3430. if (po_hascallingconvention in procoptions) then
  3431. s:=s+';'+ProcCallOptionStr[proccalloption];
  3432. fullprocname:=s;
  3433. end;
  3434. function tprocdef.is_methodpointer:boolean;
  3435. begin
  3436. result:=assigned(_class);
  3437. end;
  3438. function tprocdef.is_addressonly:boolean;
  3439. begin
  3440. result:=assigned(owner) and
  3441. (owner.symtabletype<>objectsymtable);
  3442. end;
  3443. function tprocdef.is_visible_for_object(currobjdef:tobjectdef):boolean;
  3444. begin
  3445. is_visible_for_object:=false;
  3446. { private symbols are allowed when we are in the same
  3447. module as they are defined }
  3448. if (sp_private in symoptions) and
  3449. (owner.defowner.owner.symtabletype in [globalsymtable,staticsymtable]) and
  3450. (owner.defowner.owner.unitid<>0) then
  3451. exit;
  3452. { protected symbols are vissible in the module that defines them and
  3453. also visible to related objects. The related object must be defined
  3454. in the current module }
  3455. if (sp_protected in symoptions) and
  3456. (
  3457. (
  3458. (owner.defowner.owner.symtabletype in [globalsymtable,staticsymtable]) and
  3459. (owner.defowner.owner.unitid<>0)
  3460. ) and
  3461. not(
  3462. assigned(currobjdef) and
  3463. (currobjdef.owner.unitid=0) and
  3464. currobjdef.is_related(tobjectdef(owner.defowner))
  3465. )
  3466. ) then
  3467. exit;
  3468. is_visible_for_object:=true;
  3469. end;
  3470. function tprocdef.getsymtable(t:tgetsymtable):tsymtable;
  3471. begin
  3472. case t of
  3473. gs_local :
  3474. getsymtable:=localst;
  3475. gs_para :
  3476. getsymtable:=parast;
  3477. else
  3478. getsymtable:=nil;
  3479. end;
  3480. end;
  3481. procedure tprocdef.load_references(ppufile:tcompilerppufile;locals:boolean);
  3482. var
  3483. pos : tfileposinfo;
  3484. move_last : boolean;
  3485. oldparasymtable,
  3486. oldlocalsymtable : tsymtable;
  3487. begin
  3488. oldparasymtable:=aktparasymtable;
  3489. oldlocalsymtable:=aktlocalsymtable;
  3490. aktparasymtable:=parast;
  3491. aktlocalsymtable:=localst;
  3492. move_last:=lastwritten=lastref;
  3493. while (not ppufile.endofentry) do
  3494. begin
  3495. ppufile.getposinfo(pos);
  3496. inc(refcount);
  3497. lastref:=tref.create(lastref,@pos);
  3498. lastref.is_written:=true;
  3499. if refcount=1 then
  3500. defref:=lastref;
  3501. end;
  3502. if move_last then
  3503. lastwritten:=lastref;
  3504. if ((current_module.flags and uf_local_browser)<>0) and
  3505. assigned(localst) and
  3506. locals then
  3507. begin
  3508. tparasymtable(parast).load_references(ppufile,locals);
  3509. tlocalsymtable(localst).load_references(ppufile,locals);
  3510. end;
  3511. aktparasymtable:=oldparasymtable;
  3512. aktlocalsymtable:=oldlocalsymtable;
  3513. end;
  3514. Const
  3515. local_symtable_index : word = $8001;
  3516. function tprocdef.write_references(ppufile:tcompilerppufile;locals:boolean):boolean;
  3517. var
  3518. ref : tref;
  3519. pdo : tobjectdef;
  3520. move_last : boolean;
  3521. d : tderef;
  3522. oldparasymtable,
  3523. oldlocalsymtable : tsymtable;
  3524. begin
  3525. d.reset;
  3526. move_last:=lastwritten=lastref;
  3527. if move_last and
  3528. (((current_module.flags and uf_local_browser)=0) or
  3529. not locals) then
  3530. exit;
  3531. oldparasymtable:=aktparasymtable;
  3532. oldlocalsymtable:=aktlocalsymtable;
  3533. aktparasymtable:=parast;
  3534. aktlocalsymtable:=localst;
  3535. { write address of this symbol }
  3536. d.build(self);
  3537. ppufile.putderef(d);
  3538. { write refs }
  3539. if assigned(lastwritten) then
  3540. ref:=lastwritten
  3541. else
  3542. ref:=defref;
  3543. while assigned(ref) do
  3544. begin
  3545. if ref.moduleindex=current_module.unit_index then
  3546. begin
  3547. ppufile.putposinfo(ref.posinfo);
  3548. ref.is_written:=true;
  3549. if move_last then
  3550. lastwritten:=ref;
  3551. end
  3552. else if not ref.is_written then
  3553. move_last:=false
  3554. else if move_last then
  3555. lastwritten:=ref;
  3556. ref:=ref.nextref;
  3557. end;
  3558. ppufile.writeentry(ibdefref);
  3559. write_references:=true;
  3560. if ((current_module.flags and uf_local_browser)<>0) and
  3561. assigned(localst) and
  3562. locals then
  3563. begin
  3564. pdo:=_class;
  3565. if (owner.symtabletype<>localsymtable) then
  3566. while assigned(pdo) do
  3567. begin
  3568. if pdo.symtable<>aktrecordsymtable then
  3569. begin
  3570. pdo.symtable.unitid:=local_symtable_index;
  3571. inc(local_symtable_index);
  3572. end;
  3573. pdo:=pdo.childof;
  3574. end;
  3575. parast.unitid:=local_symtable_index;
  3576. inc(local_symtable_index);
  3577. localst.unitid:=local_symtable_index;
  3578. inc(local_symtable_index);
  3579. tstoredsymtable(parast).write_references(ppufile,locals);
  3580. tstoredsymtable(localst).write_references(ppufile,locals);
  3581. { decrement for }
  3582. local_symtable_index:=local_symtable_index-2;
  3583. pdo:=_class;
  3584. if (owner.symtabletype<>localsymtable) then
  3585. while assigned(pdo) do
  3586. begin
  3587. if pdo.symtable<>aktrecordsymtable then
  3588. dec(local_symtable_index);
  3589. pdo:=pdo.childof;
  3590. end;
  3591. end;
  3592. aktparasymtable:=oldparasymtable;
  3593. aktlocalsymtable:=oldlocalsymtable;
  3594. end;
  3595. {$ifdef GDB}
  3596. function tprocdef.numberstring : string;
  3597. begin
  3598. { procdefs are always available }
  3599. stab_state:=stab_state_written;
  3600. result:=inherited numberstring;
  3601. end;
  3602. function tprocdef.stabstring: pchar;
  3603. Var
  3604. RType : Char;
  3605. Obj,Info : String;
  3606. stabsstr : string;
  3607. p : pchar;
  3608. begin
  3609. obj := procsym.name;
  3610. info := '';
  3611. if tprocsym(procsym).is_global then
  3612. RType := 'F'
  3613. else
  3614. RType := 'f';
  3615. if assigned(owner) then
  3616. begin
  3617. if (owner.symtabletype = objectsymtable) then
  3618. obj := owner.name^+'__'+procsym.name;
  3619. if not(cs_gdb_valgrind in aktglobalswitches) and
  3620. (owner.symtabletype=localsymtable) and
  3621. assigned(owner.defowner) and
  3622. assigned(tprocdef(owner.defowner).procsym) then
  3623. info := ','+procsym.name+','+tprocdef(owner.defowner).procsym.name;
  3624. end;
  3625. stabsstr:=mangledname;
  3626. getmem(p,length(stabsstr)+255);
  3627. strpcopy(p,'"'+obj+':'+RType
  3628. +tstoreddef(rettype.def).numberstring+info+'",'+tostr(n_function)
  3629. +',0,'+
  3630. tostr(fileinfo.line)
  3631. +',');
  3632. strpcopy(strend(p),stabsstr);
  3633. stabstring:=strnew(p);
  3634. freemem(p,length(stabsstr)+255);
  3635. end;
  3636. procedure tprocdef.concatstabto(asmlist : taasmoutput);
  3637. begin
  3638. { released procdef? }
  3639. if not assigned(parast) then
  3640. exit;
  3641. if (proccalloption=pocall_internproc) then
  3642. exit;
  3643. { be sure to have a number assigned for this def }
  3644. numberstring;
  3645. { write stabs }
  3646. stab_state:=stab_state_writing;
  3647. asmList.concat(Tai_stabs.Create(stabstring));
  3648. if not(po_external in procoptions) then
  3649. begin
  3650. tstoredsymtable(parast).concatstabto(asmlist);
  3651. { local type defs and vars should not be written
  3652. inside the main proc stab }
  3653. if assigned(localst) and
  3654. (localst.symtablelevel>main_program_level) then
  3655. tstoredsymtable(localst).concatstabto(asmlist);
  3656. end;
  3657. stab_state:=stab_state_written;
  3658. end;
  3659. {$endif GDB}
  3660. procedure tprocdef.buildderef;
  3661. var
  3662. oldparasymtable,
  3663. oldlocalsymtable : tsymtable;
  3664. begin
  3665. oldparasymtable:=aktparasymtable;
  3666. oldlocalsymtable:=aktlocalsymtable;
  3667. aktparasymtable:=parast;
  3668. aktlocalsymtable:=localst;
  3669. inherited buildderef;
  3670. _classderef.build(_class);
  3671. { procsym that originaly defined this definition, should be in the
  3672. same symtable }
  3673. procsymderef.build(procsym);
  3674. {$ifdef powerpc}
  3675. { library symbol for AmigaOS/MorphOS }
  3676. libsymderef.build(libsym);
  3677. {$endif powerpc}
  3678. aktparasymtable:=oldparasymtable;
  3679. aktlocalsymtable:=oldlocalsymtable;
  3680. end;
  3681. procedure tprocdef.buildderefimpl;
  3682. var
  3683. oldparasymtable,
  3684. oldlocalsymtable : tsymtable;
  3685. begin
  3686. { released procdef? }
  3687. if not assigned(parast) then
  3688. exit;
  3689. oldparasymtable:=aktparasymtable;
  3690. oldlocalsymtable:=aktlocalsymtable;
  3691. aktparasymtable:=parast;
  3692. aktlocalsymtable:=localst;
  3693. inherited buildderefimpl;
  3694. { Locals }
  3695. if assigned(localst) and
  3696. ((proccalloption=pocall_inline) or
  3697. ((current_module.flags and uf_local_browser)<>0)) then
  3698. begin
  3699. tlocalsymtable(localst).buildderef;
  3700. tlocalsymtable(localst).buildderefimpl;
  3701. end;
  3702. { inline tree }
  3703. if (proccalloption=pocall_inline) then
  3704. begin
  3705. funcretsymderef.build(funcretsym);
  3706. inlininginfo^.code.buildderefimpl;
  3707. end;
  3708. aktparasymtable:=oldparasymtable;
  3709. aktlocalsymtable:=oldlocalsymtable;
  3710. end;
  3711. procedure tprocdef.deref;
  3712. var
  3713. oldparasymtable,
  3714. oldlocalsymtable : tsymtable;
  3715. begin
  3716. { released procdef? }
  3717. if not assigned(parast) then
  3718. exit;
  3719. oldparasymtable:=aktparasymtable;
  3720. oldlocalsymtable:=aktlocalsymtable;
  3721. aktparasymtable:=parast;
  3722. aktlocalsymtable:=localst;
  3723. inherited deref;
  3724. _class:=tobjectdef(_classderef.resolve);
  3725. { procsym that originaly defined this definition, should be in the
  3726. same symtable }
  3727. procsym:=tprocsym(procsymderef.resolve);
  3728. {$ifdef powerpc}
  3729. { library symbol for AmigaOS/MorphOS }
  3730. libsym:=tvarsym(libsymderef.resolve);
  3731. {$endif powerpc}
  3732. aktparasymtable:=oldparasymtable;
  3733. aktlocalsymtable:=oldlocalsymtable;
  3734. end;
  3735. procedure tprocdef.derefimpl;
  3736. var
  3737. oldparasymtable,
  3738. oldlocalsymtable : tsymtable;
  3739. begin
  3740. oldparasymtable:=aktparasymtable;
  3741. oldlocalsymtable:=aktlocalsymtable;
  3742. aktparasymtable:=parast;
  3743. aktlocalsymtable:=localst;
  3744. { Locals }
  3745. if assigned(localst) then
  3746. begin
  3747. tlocalsymtable(localst).deref;
  3748. tlocalsymtable(localst).derefimpl;
  3749. end;
  3750. { Inline }
  3751. if (proccalloption=pocall_inline) then
  3752. begin
  3753. inlininginfo^.code.derefimpl;
  3754. { funcretsym, this is always located in the localst }
  3755. funcretsym:=tsym(funcretsymderef.resolve);
  3756. end
  3757. else
  3758. begin
  3759. { safety }
  3760. funcretsym:=nil;
  3761. end;
  3762. aktparasymtable:=oldparasymtable;
  3763. aktlocalsymtable:=oldlocalsymtable;
  3764. end;
  3765. function tprocdef.gettypename : string;
  3766. begin
  3767. gettypename := FullProcName(false);
  3768. end;
  3769. function tprocdef.mangledname : string;
  3770. var
  3771. hp : TParaItem;
  3772. begin
  3773. if assigned(_mangledname) then
  3774. begin
  3775. {$ifdef compress}
  3776. mangledname:=minilzw_decode(_mangledname^);
  3777. {$else}
  3778. mangledname:=_mangledname^;
  3779. {$endif}
  3780. exit;
  3781. end;
  3782. { we need to use the symtable where the procsym is inserted,
  3783. because that is visible to the world }
  3784. mangledname:=make_mangledname('',procsym.owner,procsym.name);
  3785. if overloadnumber>0 then
  3786. mangledname:=mangledname+'$'+tostr(overloadnumber);
  3787. { add parameter types }
  3788. hp:=TParaItem(Para.first);
  3789. while assigned(hp) do
  3790. begin
  3791. if not hp.is_hidden then
  3792. mangledname:=mangledname+'$'+hp.paratype.def.mangledparaname;
  3793. hp:=TParaItem(hp.next);
  3794. end;
  3795. {$ifdef compress}
  3796. _mangledname:=stringdup(minilzw_encode(mangledname));
  3797. {$else}
  3798. _mangledname:=stringdup(mangledname);
  3799. {$endif}
  3800. end;
  3801. function tprocdef.cplusplusmangledname : string;
  3802. function getcppparaname(p : tdef) : string;
  3803. const
  3804. ordtype2str : array[tbasetype] of string[2] = (
  3805. '',
  3806. 'Uc','Us','Ui','Us',
  3807. 'Sc','s','i','x',
  3808. 'b','b','b',
  3809. 'c','w','x');
  3810. var
  3811. s : string;
  3812. begin
  3813. case p.deftype of
  3814. orddef:
  3815. s:=ordtype2str[torddef(p).typ];
  3816. pointerdef:
  3817. s:='P'+getcppparaname(tpointerdef(p).pointertype.def);
  3818. else
  3819. internalerror(2103001);
  3820. end;
  3821. getcppparaname:=s;
  3822. end;
  3823. var
  3824. s,s2 : string;
  3825. param : TParaItem;
  3826. begin
  3827. s := procsym.realname;
  3828. if procsym.owner.symtabletype=objectsymtable then
  3829. begin
  3830. s2:=upper(tobjectdef(procsym.owner.defowner).typesym.realname);
  3831. case proctypeoption of
  3832. potype_destructor:
  3833. s:='_$_'+tostr(length(s2))+s2;
  3834. potype_constructor:
  3835. s:='___'+tostr(length(s2))+s2;
  3836. else
  3837. s:='_'+s+'__'+tostr(length(s2))+s2;
  3838. end;
  3839. end
  3840. else s:=s+'__';
  3841. s:=s+'F';
  3842. { concat modifiers }
  3843. { !!!!! }
  3844. { now we handle the parameters }
  3845. param := TParaItem(Para.first);
  3846. if assigned(param) then
  3847. while assigned(param) do
  3848. begin
  3849. s2:=getcppparaname(param.paratype.def);
  3850. if param.paratyp in [vs_var,vs_out] then
  3851. s2:='R'+s2;
  3852. s:=s+s2;
  3853. param:=TParaItem(param.next);
  3854. end
  3855. else
  3856. s:=s+'v';
  3857. cplusplusmangledname:=s;
  3858. end;
  3859. procedure tprocdef.setmangledname(const s : string);
  3860. begin
  3861. stringdispose(_mangledname);
  3862. {$ifdef compress}
  3863. _mangledname:=stringdup(minilzw_encode(s));
  3864. {$else}
  3865. _mangledname:=stringdup(s);
  3866. {$endif}
  3867. has_mangledname:=true;
  3868. end;
  3869. {***************************************************************************
  3870. TPROCVARDEF
  3871. ***************************************************************************}
  3872. constructor tprocvardef.create(level:byte);
  3873. begin
  3874. inherited create(level);
  3875. deftype:=procvardef;
  3876. end;
  3877. constructor tprocvardef.ppuload(ppufile:tcompilerppufile);
  3878. begin
  3879. inherited ppuload(ppufile);
  3880. deftype:=procvardef;
  3881. { load para symtable }
  3882. parast:=tparasymtable.create(unknown_level);
  3883. tparasymtable(parast).ppuload(ppufile);
  3884. parast.defowner:=self;
  3885. end;
  3886. procedure tprocvardef.ppuwrite(ppufile:tcompilerppufile);
  3887. var
  3888. oldparasymtable,
  3889. oldlocalsymtable : tsymtable;
  3890. begin
  3891. oldparasymtable:=aktparasymtable;
  3892. oldlocalsymtable:=aktlocalsymtable;
  3893. aktparasymtable:=parast;
  3894. aktlocalsymtable:=nil;
  3895. { here we cannot get a real good value so just give something }
  3896. { plausible (PM) }
  3897. { a more secure way would be
  3898. to allways store in a temp }
  3899. {$ifdef i386}
  3900. if is_fpu(rettype.def) then
  3901. fpu_used:={2}maxfpuregs
  3902. else
  3903. fpu_used:=0;
  3904. {$endif i386}
  3905. inherited ppuwrite(ppufile);
  3906. { Write this entry }
  3907. ppufile.writeentry(ibprocvardef);
  3908. { Save the para symtable, this is taken from the interface }
  3909. tparasymtable(parast).ppuwrite(ppufile);
  3910. aktparasymtable:=oldparasymtable;
  3911. aktlocalsymtable:=oldlocalsymtable;
  3912. end;
  3913. procedure tprocvardef.buildderef;
  3914. var
  3915. oldparasymtable,
  3916. oldlocalsymtable : tsymtable;
  3917. begin
  3918. oldparasymtable:=aktparasymtable;
  3919. oldlocalsymtable:=aktlocalsymtable;
  3920. aktparasymtable:=parast;
  3921. aktlocalsymtable:=nil;
  3922. inherited buildderef;
  3923. aktparasymtable:=oldparasymtable;
  3924. aktlocalsymtable:=oldlocalsymtable;
  3925. end;
  3926. procedure tprocvardef.deref;
  3927. var
  3928. oldparasymtable,
  3929. oldlocalsymtable : tsymtable;
  3930. begin
  3931. oldparasymtable:=aktparasymtable;
  3932. oldlocalsymtable:=aktlocalsymtable;
  3933. aktparasymtable:=parast;
  3934. aktlocalsymtable:=nil;
  3935. inherited deref;
  3936. aktparasymtable:=oldparasymtable;
  3937. aktlocalsymtable:=oldlocalsymtable;
  3938. end;
  3939. function tprocvardef.getsymtable(t:tgetsymtable):tsymtable;
  3940. begin
  3941. case t of
  3942. gs_para :
  3943. getsymtable:=parast;
  3944. else
  3945. getsymtable:=nil;
  3946. end;
  3947. end;
  3948. function tprocvardef.size : longint;
  3949. begin
  3950. if (po_methodpointer in procoptions) and
  3951. not(po_addressonly in procoptions) then
  3952. size:=2*sizeof(aint)
  3953. else
  3954. size:=sizeof(aint);
  3955. end;
  3956. function tprocvardef.is_methodpointer:boolean;
  3957. begin
  3958. result:=(po_methodpointer in procoptions);
  3959. end;
  3960. function tprocvardef.is_addressonly:boolean;
  3961. begin
  3962. result:=not(po_methodpointer in procoptions) or
  3963. (po_addressonly in procoptions);
  3964. end;
  3965. {$ifdef GDB}
  3966. function tprocvardef.stabstring : pchar;
  3967. var
  3968. nss : pchar;
  3969. { i : longint; }
  3970. begin
  3971. { i := maxparacount; }
  3972. getmem(nss,1024);
  3973. { it is not a function but a function pointer !! (PM) }
  3974. strpcopy(nss,'*f'+tstoreddef(rettype.def).numberstring{+','+tostr(i)});
  3975. { this confuses gdb !!
  3976. we should use 'F' instead of 'f' but
  3977. as we use c++ language mode
  3978. it does not like that either
  3979. Please do not remove this part
  3980. might be used once
  3981. gdb for pascal is ready PM }
  3982. {$ifdef disabled}
  3983. param := para1;
  3984. i := 0;
  3985. while assigned(param) do
  3986. begin
  3987. inc(i);
  3988. if param^.paratyp = vs_value then vartyp := '1' else vartyp := '0';
  3989. {Here we have lost the parameter names !!}
  3990. pst := strpnew('p'+tostr(i)+':'+param^.paratype.def.numberstring+','+vartyp+';');
  3991. strcat(nss,pst);
  3992. strdispose(pst);
  3993. param := param^.next;
  3994. end;
  3995. {$endif}
  3996. {strpcopy(strend(nss),';');}
  3997. stabstring := strnew(nss);
  3998. freemem(nss,1024);
  3999. end;
  4000. procedure tprocvardef.concatstabto(asmlist : taasmoutput);
  4001. begin
  4002. if (stab_state in [stab_state_writing,stab_state_written]) then
  4003. exit;
  4004. tstoreddef(rettype.def).concatstabto(asmlist);
  4005. inherited concatstabto(asmlist);
  4006. end;
  4007. {$endif GDB}
  4008. procedure tprocvardef.write_rtti_data(rt:trttitype);
  4009. var
  4010. pdc : TParaItem;
  4011. methodkind, paraspec : byte;
  4012. begin
  4013. if po_methodpointer in procoptions then
  4014. begin
  4015. { write method id and name }
  4016. rttiList.concat(Tai_const.Create_8bit(tkmethod));
  4017. write_rtti_name;
  4018. { write kind of method (can only be function or procedure)}
  4019. if rettype.def = voidtype.def then
  4020. methodkind := mkProcedure
  4021. else
  4022. methodkind := mkFunction;
  4023. rttiList.concat(Tai_const.Create_8bit(methodkind));
  4024. { get # of parameters }
  4025. rttiList.concat(Tai_const.Create_8bit(maxparacount));
  4026. { write parameter info. The parameters must be written in reverse order
  4027. if this method uses right to left parameter pushing! }
  4028. if proccalloption in pushleftright_pocalls then
  4029. pdc:=TParaItem(Para.first)
  4030. else
  4031. pdc:=TParaItem(Para.last);
  4032. while assigned(pdc) do
  4033. begin
  4034. { only store user visible parameters }
  4035. if not pdc.is_hidden then
  4036. begin
  4037. case pdc.paratyp of
  4038. vs_value: paraspec := 0;
  4039. vs_const: paraspec := pfConst;
  4040. vs_var : paraspec := pfVar;
  4041. vs_out : paraspec := pfOut;
  4042. end;
  4043. { write flags for current parameter }
  4044. rttiList.concat(Tai_const.Create_8bit(paraspec));
  4045. { write name of current parameter }
  4046. if assigned(pdc.parasym) then
  4047. begin
  4048. rttiList.concat(Tai_const.Create_8bit(length(pdc.parasym.realname)));
  4049. rttiList.concat(Tai_string.Create(pdc.parasym.realname));
  4050. end
  4051. else
  4052. rttiList.concat(Tai_const.Create_8bit(0));
  4053. { write name of type of current parameter }
  4054. tstoreddef(pdc.paratype.def).write_rtti_name;
  4055. end;
  4056. if proccalloption in pushleftright_pocalls then
  4057. pdc:=TParaItem(pdc.next)
  4058. else
  4059. pdc:=TParaItem(pdc.previous);
  4060. end;
  4061. { write name of result type }
  4062. tstoreddef(rettype.def).write_rtti_name;
  4063. end;
  4064. end;
  4065. function tprocvardef.is_publishable : boolean;
  4066. begin
  4067. is_publishable:=(po_methodpointer in procoptions);
  4068. end;
  4069. function tprocvardef.gettypename : string;
  4070. var
  4071. s: string;
  4072. showhidden : boolean;
  4073. begin
  4074. {$ifdef EXTDEBUG}
  4075. showhidden:=true;
  4076. {$else EXTDEBUG}
  4077. showhidden:=false;
  4078. {$endif EXTDEBUG}
  4079. s:='<';
  4080. if po_classmethod in procoptions then
  4081. s := s+'class method type of'
  4082. else
  4083. if po_addressonly in procoptions then
  4084. s := s+'address of'
  4085. else
  4086. s := s+'procedure variable type of';
  4087. if assigned(rettype.def) and
  4088. (rettype.def<>voidtype.def) then
  4089. s:=s+' function'+typename_paras(showhidden)+':'+rettype.def.gettypename
  4090. else
  4091. s:=s+' procedure'+typename_paras(showhidden);
  4092. if po_methodpointer in procoptions then
  4093. s := s+' of object';
  4094. gettypename := s+';'+ProcCallOptionStr[proccalloption]+'>';
  4095. end;
  4096. {***************************************************************************
  4097. TOBJECTDEF
  4098. ***************************************************************************}
  4099. constructor tobjectdef.create(ot : tobjectdeftype;const n : string;c : tobjectdef);
  4100. begin
  4101. inherited create;
  4102. objecttype:=ot;
  4103. deftype:=objectdef;
  4104. objectoptions:=[];
  4105. childof:=nil;
  4106. symtable:=tobjectsymtable.create(n,aktpackrecords);
  4107. { create space for vmt !! }
  4108. vmt_offset:=0;
  4109. symtable.defowner:=self;
  4110. lastvtableindex:=0;
  4111. set_parent(c);
  4112. objname:=stringdup(upper(n));
  4113. objrealname:=stringdup(n);
  4114. if objecttype in [odt_interfacecorba,odt_interfacecom] then
  4115. prepareguid;
  4116. { setup implemented interfaces }
  4117. if objecttype in [odt_class,odt_interfacecorba] then
  4118. implementedinterfaces:=timplementedinterfaces.create
  4119. else
  4120. implementedinterfaces:=nil;
  4121. {$ifdef GDB}
  4122. writing_class_record_stab:=false;
  4123. {$endif GDB}
  4124. end;
  4125. constructor tobjectdef.ppuload(ppufile:tcompilerppufile);
  4126. var
  4127. i,implintfcount: longint;
  4128. d : tderef;
  4129. begin
  4130. inherited ppuloaddef(ppufile);
  4131. deftype:=objectdef;
  4132. objecttype:=tobjectdeftype(ppufile.getbyte);
  4133. objrealname:=stringdup(ppufile.getstring);
  4134. objname:=stringdup(upper(objrealname^));
  4135. symtable:=tobjectsymtable.create(objrealname^,0);
  4136. tobjectsymtable(symtable).datasize:=ppufile.getlongint;
  4137. tobjectsymtable(symtable).fieldalignment:=ppufile.getbyte;
  4138. tobjectsymtable(symtable).recordalignment:=ppufile.getbyte;
  4139. vmt_offset:=ppufile.getlongint;
  4140. ppufile.getderef(childofderef);
  4141. ppufile.getsmallset(objectoptions);
  4142. { load guid }
  4143. iidstr:=nil;
  4144. if objecttype in [odt_interfacecom,odt_interfacecorba] then
  4145. begin
  4146. new(iidguid);
  4147. ppufile.getguid(iidguid^);
  4148. iidstr:=stringdup(ppufile.getstring);
  4149. lastvtableindex:=ppufile.getlongint;
  4150. end;
  4151. { load implemented interfaces }
  4152. if objecttype in [odt_class,odt_interfacecorba] then
  4153. begin
  4154. implementedinterfaces:=timplementedinterfaces.create;
  4155. implintfcount:=ppufile.getlongint;
  4156. for i:=1 to implintfcount do
  4157. begin
  4158. ppufile.getderef(d);
  4159. implementedinterfaces.addintf_deref(d);
  4160. implementedinterfaces.ioffsets(i)^:=ppufile.getlongint;
  4161. end;
  4162. end
  4163. else
  4164. implementedinterfaces:=nil;
  4165. tobjectsymtable(symtable).ppuload(ppufile);
  4166. symtable.defowner:=self;
  4167. { handles the predefined class tobject }
  4168. { the last TOBJECT which is loaded gets }
  4169. { it ! }
  4170. if (childof=nil) and
  4171. (objecttype=odt_class) and
  4172. (objname^='TOBJECT') then
  4173. class_tobject:=self;
  4174. if (childof=nil) and
  4175. (objecttype=odt_interfacecom) and
  4176. (objname^='IUNKNOWN') then
  4177. interface_iunknown:=self;
  4178. {$ifdef GDB}
  4179. writing_class_record_stab:=false;
  4180. {$endif GDB}
  4181. end;
  4182. destructor tobjectdef.destroy;
  4183. begin
  4184. if assigned(symtable) then
  4185. symtable.free;
  4186. stringdispose(objname);
  4187. stringdispose(objrealname);
  4188. if assigned(iidstr) then
  4189. stringdispose(iidstr);
  4190. if assigned(implementedinterfaces) then
  4191. implementedinterfaces.free;
  4192. if assigned(iidguid) then
  4193. dispose(iidguid);
  4194. inherited destroy;
  4195. end;
  4196. procedure tobjectdef.ppuwrite(ppufile:tcompilerppufile);
  4197. var
  4198. implintfcount : longint;
  4199. i : longint;
  4200. begin
  4201. inherited ppuwritedef(ppufile);
  4202. ppufile.putbyte(byte(objecttype));
  4203. ppufile.putstring(objrealname^);
  4204. ppufile.putlongint(tobjectsymtable(symtable).datasize);
  4205. ppufile.putbyte(tobjectsymtable(symtable).fieldalignment);
  4206. ppufile.putbyte(tobjectsymtable(symtable).recordalignment);
  4207. ppufile.putlongint(vmt_offset);
  4208. ppufile.putderef(childofderef);
  4209. ppufile.putsmallset(objectoptions);
  4210. if objecttype in [odt_interfacecom,odt_interfacecorba] then
  4211. begin
  4212. ppufile.putguid(iidguid^);
  4213. ppufile.putstring(iidstr^);
  4214. ppufile.putlongint(lastvtableindex);
  4215. end;
  4216. if objecttype in [odt_class,odt_interfacecorba] then
  4217. begin
  4218. implintfcount:=implementedinterfaces.count;
  4219. ppufile.putlongint(implintfcount);
  4220. for i:=1 to implintfcount do
  4221. begin
  4222. ppufile.putderef(implementedinterfaces.interfacesderef(i));
  4223. ppufile.putlongint(implementedinterfaces.ioffsets(i)^);
  4224. end;
  4225. end;
  4226. ppufile.writeentry(ibobjectdef);
  4227. tobjectsymtable(symtable).ppuwrite(ppufile);
  4228. end;
  4229. function tobjectdef.gettypename:string;
  4230. begin
  4231. gettypename:=typename;
  4232. end;
  4233. procedure tobjectdef.buildderef;
  4234. var
  4235. oldrecsyms : tsymtable;
  4236. begin
  4237. inherited buildderef;
  4238. childofderef.build(childof);
  4239. oldrecsyms:=aktrecordsymtable;
  4240. aktrecordsymtable:=symtable;
  4241. tstoredsymtable(symtable).buildderef;
  4242. aktrecordsymtable:=oldrecsyms;
  4243. if objecttype in [odt_class,odt_interfacecorba] then
  4244. implementedinterfaces.buildderef;
  4245. end;
  4246. procedure tobjectdef.deref;
  4247. var
  4248. oldrecsyms : tsymtable;
  4249. begin
  4250. inherited deref;
  4251. childof:=tobjectdef(childofderef.resolve);
  4252. oldrecsyms:=aktrecordsymtable;
  4253. aktrecordsymtable:=symtable;
  4254. tstoredsymtable(symtable).deref;
  4255. aktrecordsymtable:=oldrecsyms;
  4256. if objecttype in [odt_class,odt_interfacecorba] then
  4257. implementedinterfaces.deref;
  4258. end;
  4259. function tobjectdef.getparentdef:tdef;
  4260. begin
  4261. result:=childof;
  4262. end;
  4263. procedure tobjectdef.prepareguid;
  4264. begin
  4265. { set up guid }
  4266. if not assigned(iidguid) then
  4267. begin
  4268. new(iidguid);
  4269. fillchar(iidguid^,sizeof(iidguid^),0); { default null guid }
  4270. end;
  4271. { setup iidstring }
  4272. if not assigned(iidstr) then
  4273. iidstr:=stringdup(''); { default is empty string }
  4274. end;
  4275. procedure tobjectdef.set_parent( c : tobjectdef);
  4276. begin
  4277. { nothing to do if the parent was not forward !}
  4278. if assigned(childof) then
  4279. exit;
  4280. childof:=c;
  4281. { some options are inherited !! }
  4282. if assigned(c) then
  4283. begin
  4284. { only important for classes }
  4285. lastvtableindex:=c.lastvtableindex;
  4286. objectoptions:=objectoptions+(c.objectoptions*
  4287. [oo_has_virtual,oo_has_private,oo_has_protected,
  4288. oo_has_constructor,oo_has_destructor]);
  4289. if not (objecttype in [odt_interfacecom,odt_interfacecorba]) then
  4290. begin
  4291. { add the data of the anchestor class }
  4292. inc(tobjectsymtable(symtable).datasize,tobjectsymtable(c.symtable).datasize);
  4293. if (oo_has_vmt in objectoptions) and
  4294. (oo_has_vmt in c.objectoptions) then
  4295. dec(tobjectsymtable(symtable).datasize,sizeof(aint));
  4296. { if parent has a vmt field then
  4297. the offset is the same for the child PM }
  4298. if (oo_has_vmt in c.objectoptions) or is_class(self) then
  4299. begin
  4300. vmt_offset:=c.vmt_offset;
  4301. include(objectoptions,oo_has_vmt);
  4302. end;
  4303. end;
  4304. end;
  4305. end;
  4306. procedure tobjectdef.insertvmt;
  4307. begin
  4308. if objecttype in [odt_interfacecom,odt_interfacecorba] then
  4309. exit;
  4310. if (oo_has_vmt in objectoptions) then
  4311. internalerror(12345)
  4312. else
  4313. begin
  4314. tobjectsymtable(symtable).datasize:=align(tobjectsymtable(symtable).datasize,
  4315. tobjectsymtable(symtable).fieldalignment);
  4316. vmt_offset:=tobjectsymtable(symtable).datasize;
  4317. inc(tobjectsymtable(symtable).datasize,sizeof(aint));
  4318. include(objectoptions,oo_has_vmt);
  4319. end;
  4320. end;
  4321. procedure tobjectdef.check_forwards;
  4322. begin
  4323. if not(objecttype in [odt_interfacecom,odt_interfacecorba]) then
  4324. tstoredsymtable(symtable).check_forwards;
  4325. if (oo_is_forward in objectoptions) then
  4326. begin
  4327. { ok, in future, the forward can be resolved }
  4328. Message1(sym_e_class_forward_not_resolved,objrealname^);
  4329. exclude(objectoptions,oo_is_forward);
  4330. end;
  4331. end;
  4332. { true, if self inherits from d (or if they are equal) }
  4333. function tobjectdef.is_related(d : tobjectdef) : boolean;
  4334. var
  4335. hp : tobjectdef;
  4336. begin
  4337. hp:=self;
  4338. while assigned(hp) do
  4339. begin
  4340. if hp=d then
  4341. begin
  4342. is_related:=true;
  4343. exit;
  4344. end;
  4345. hp:=hp.childof;
  4346. end;
  4347. is_related:=false;
  4348. end;
  4349. (* procedure tobjectdef._searchdestructor(sym : tnamedindexitem;arg:pointer);
  4350. var
  4351. p : pprocdeflist;
  4352. begin
  4353. { if we found already a destructor, then we exit }
  4354. if assigned(sd) then
  4355. exit;
  4356. if tsym(sym).typ=procsym then
  4357. begin
  4358. p:=tprocsym(sym).defs;
  4359. while assigned(p) do
  4360. begin
  4361. if p^.def.proctypeoption=potype_destructor then
  4362. begin
  4363. sd:=p^.def;
  4364. exit;
  4365. end;
  4366. p:=p^.next;
  4367. end;
  4368. end;
  4369. end;*)
  4370. procedure _searchdestructor(sym:Tnamedindexitem;sd:pointer);
  4371. begin
  4372. { if we found already a destructor, then we exit }
  4373. if (ppointer(sd)^=nil) and
  4374. (Tsym(sym).typ=procsym) then
  4375. ppointer(sd)^:=Tprocsym(sym).search_procdef_bytype(potype_destructor);
  4376. end;
  4377. function tobjectdef.searchdestructor : tprocdef;
  4378. var
  4379. o : tobjectdef;
  4380. sd : tprocdef;
  4381. begin
  4382. searchdestructor:=nil;
  4383. o:=self;
  4384. sd:=nil;
  4385. while assigned(o) do
  4386. begin
  4387. o.symtable.foreach_static({$ifdef FPCPROCVAR}@{$endif}_searchdestructor,@sd);
  4388. if assigned(sd) then
  4389. begin
  4390. searchdestructor:=sd;
  4391. exit;
  4392. end;
  4393. o:=o.childof;
  4394. end;
  4395. end;
  4396. function tobjectdef.size : longint;
  4397. begin
  4398. if objecttype in [odt_class,odt_interfacecom,odt_interfacecorba] then
  4399. result:=sizeof(aint)
  4400. else
  4401. result:=tobjectsymtable(symtable).datasize;
  4402. end;
  4403. function tobjectdef.alignment:longint;
  4404. begin
  4405. if objecttype in [odt_class,odt_interfacecom,odt_interfacecorba] then
  4406. alignment:=sizeof(aint)
  4407. else
  4408. alignment:=tobjectsymtable(symtable).recordalignment;
  4409. end;
  4410. function tobjectdef.vmtmethodoffset(index:longint):longint;
  4411. begin
  4412. { for offset of methods for classes, see rtl/inc/objpash.inc }
  4413. case objecttype of
  4414. odt_class:
  4415. { the +2*sizeof(Aint) is size and -size }
  4416. vmtmethodoffset:=(index+10)*sizeof(aint)+2*sizeof(AInt);
  4417. odt_interfacecom,odt_interfacecorba:
  4418. vmtmethodoffset:=index*sizeof(aint);
  4419. else
  4420. {$ifdef WITHDMT}
  4421. vmtmethodoffset:=(index+4)*sizeof(aint);
  4422. {$else WITHDMT}
  4423. vmtmethodoffset:=(index+3)*sizeof(aint);
  4424. {$endif WITHDMT}
  4425. end;
  4426. end;
  4427. function tobjectdef.vmt_mangledname : string;
  4428. begin
  4429. if not(oo_has_vmt in objectoptions) then
  4430. Message1(parser_n_object_has_no_vmt,objrealname^);
  4431. vmt_mangledname:=make_mangledname('VMT',owner,objname^);
  4432. end;
  4433. function tobjectdef.rtti_name : string;
  4434. begin
  4435. rtti_name:=make_mangledname('RTTI',owner,objname^);
  4436. end;
  4437. {$ifdef GDB}
  4438. procedure tobjectdef.proc_addname(p :tnamedindexitem;arg:pointer);
  4439. var virtualind,argnames : string;
  4440. newrec : pchar;
  4441. pd : tprocdef;
  4442. lindex : longint;
  4443. para : TParaItem;
  4444. arglength : byte;
  4445. sp : char;
  4446. state:^Trecord_stabgen_state;
  4447. olds:integer;
  4448. begin
  4449. state:=arg;
  4450. if tsym(p).typ = procsym then
  4451. begin
  4452. pd := tprocsym(p).first_procdef;
  4453. if (po_virtualmethod in pd.procoptions) then
  4454. begin
  4455. lindex := pd.extnumber;
  4456. {doesnt seem to be necessary
  4457. lindex := lindex or $80000000;}
  4458. virtualind := '*'+tostr(lindex)+';'+pd._class.classnumberstring+';'
  4459. end
  4460. else
  4461. virtualind := '.';
  4462. { used by gdbpas to recognize constructor and destructors }
  4463. if (pd.proctypeoption=potype_constructor) then
  4464. argnames:='__ct__'
  4465. else if (pd.proctypeoption=potype_destructor) then
  4466. argnames:='__dt__'
  4467. else
  4468. argnames := '';
  4469. { arguments are not listed here }
  4470. {we don't need another definition}
  4471. para := TParaItem(pd.Para.first);
  4472. while assigned(para) do
  4473. begin
  4474. if Para.paratype.def.deftype = formaldef then
  4475. begin
  4476. case Para.paratyp of
  4477. vs_var :
  4478. argnames := argnames+'3var';
  4479. vs_const :
  4480. argnames:=argnames+'5const';
  4481. vs_out :
  4482. argnames:=argnames+'3out';
  4483. end;
  4484. end
  4485. else
  4486. begin
  4487. { if the arg definition is like (v: ^byte;..
  4488. there is no sym attached to data !!! }
  4489. if assigned(Para.paratype.def.typesym) then
  4490. begin
  4491. arglength := length(Para.paratype.def.typesym.name);
  4492. argnames := argnames + tostr(arglength)+Para.paratype.def.typesym.name;
  4493. end
  4494. else
  4495. argnames:=argnames+'11unnamedtype';
  4496. end;
  4497. para := TParaItem(Para.next);
  4498. end;
  4499. { here 2A must be changed for private and protected }
  4500. { 0 is private 1 protected and 2 public }
  4501. if (sp_private in tsym(p).symoptions) then
  4502. sp:='0'
  4503. else if (sp_protected in tsym(p).symoptions) then
  4504. sp:='1'
  4505. else
  4506. sp:='2';
  4507. newrec:=stabstr_evaluate('$1::$2=##$3;:$4;$5A$6;',[p.name,pd.numberstring,
  4508. Tstoreddef(pd.rettype.def).numberstring,argnames,sp,
  4509. virtualind]);
  4510. { get spare place for a string at the end }
  4511. olds:=state^.stabsize;
  4512. inc(state^.stabsize,strlen(newrec));
  4513. if state^.stabsize>=state^.staballoc-256 then
  4514. begin
  4515. inc(state^.staballoc,memsizeinc);
  4516. reallocmem(state^.stabstring,state^.staballoc);
  4517. end;
  4518. strcopy(state^.stabstring+olds,newrec);
  4519. strdispose(newrec);
  4520. {This should be used for case !!
  4521. RecOffset := RecOffset + pd.size;}
  4522. end;
  4523. end;
  4524. procedure tobjectdef.proc_concatstabto(p :tnamedindexitem;arg:pointer);
  4525. var
  4526. pd : tprocdef;
  4527. begin
  4528. if tsym(p).typ = procsym then
  4529. begin
  4530. pd := tprocsym(p).first_procdef;
  4531. tstoreddef(pd.rettype.def).concatstabto(taasmoutput(arg));
  4532. end;
  4533. end;
  4534. function tobjectdef.stabstring : pchar;
  4535. var anc : tobjectdef;
  4536. state:Trecord_stabgen_state;
  4537. ts : string;
  4538. begin
  4539. if not (objecttype=odt_class) or writing_class_record_stab then
  4540. begin
  4541. state.staballoc:=memsizeinc;
  4542. getmem(state.stabstring,state.staballoc);
  4543. strpcopy(state.stabstring,'s'+tostr(tobjectsymtable(symtable).datasize));
  4544. if assigned(childof) then
  4545. begin
  4546. {only one ancestor not virtual, public, at base offset 0 }
  4547. { !1 , 0 2 0 , }
  4548. strpcopy(strend(state.stabstring),'!1,020,'+childof.classnumberstring+';');
  4549. end;
  4550. {virtual table to implement yet}
  4551. state.recoffset:=0;
  4552. state.stabsize:=strlen(state.stabstring);
  4553. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}field_addname,@state);
  4554. if (oo_has_vmt in objectoptions) then
  4555. if not assigned(childof) or not(oo_has_vmt in childof.objectoptions) then
  4556. begin
  4557. ts:='$vf'+classnumberstring+':'+tstoreddef(vmtarraytype.def).numberstring+','+tostr(vmt_offset*8)+';';
  4558. strpcopy(state.stabstring+state.stabsize,ts);
  4559. inc(state.stabsize,length(ts));
  4560. end;
  4561. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}proc_addname,@state);
  4562. if (oo_has_vmt in objectoptions) then
  4563. begin
  4564. anc := self;
  4565. while assigned(anc.childof) and (oo_has_vmt in anc.childof.objectoptions) do
  4566. anc := anc.childof;
  4567. { just in case anc = self }
  4568. ts:=';~%'+anc.classnumberstring+';';
  4569. end
  4570. else
  4571. ts:=';';
  4572. strpcopy(state.stabstring+state.stabsize,ts);
  4573. inc(state.stabsize,length(ts));
  4574. reallocmem(state.stabstring,state.stabsize+1);
  4575. stabstring:=state.stabstring;
  4576. end
  4577. else
  4578. begin
  4579. stabstring:=strpnew('*'+classnumberstring);
  4580. end;
  4581. end;
  4582. procedure tobjectdef.set_globalnb;
  4583. begin
  4584. globalnb:=PglobalTypeCount^;
  4585. inc(PglobalTypeCount^);
  4586. { classes need two type numbers, the globalnb is set to the ptr }
  4587. if objecttype=odt_class then
  4588. begin
  4589. globalnb:=PGlobalTypeCount^;
  4590. inc(PglobalTypeCount^);
  4591. end;
  4592. end;
  4593. function tobjectdef.classnumberstring : string;
  4594. begin
  4595. if objecttype=odt_class then
  4596. begin
  4597. if globalnb=0 then
  4598. numberstring;
  4599. dec(globalnb);
  4600. classnumberstring:=numberstring;
  4601. inc(globalnb);
  4602. end
  4603. else
  4604. classnumberstring:=numberstring;
  4605. end;
  4606. function tobjectdef.allstabstring : pchar;
  4607. var
  4608. stabchar : string[2];
  4609. ss,st : pchar;
  4610. sname : string;
  4611. begin
  4612. ss := stabstring;
  4613. getmem(st,strlen(ss)+512);
  4614. stabchar := 't';
  4615. if deftype in tagtypes then
  4616. stabchar := 'Tt';
  4617. if assigned(typesym) then
  4618. sname := typesym.name
  4619. else
  4620. sname := ' ';
  4621. if writing_class_record_stab then
  4622. strpcopy(st,'"'+sname+':'+stabchar+classnumberstring+'=')
  4623. else
  4624. strpcopy(st,'"'+sname+':'+stabchar+numberstring+'=');
  4625. strpcopy(strecopy(strend(st),ss),'",'+tostr(N_LSYM)+',0,0,0');
  4626. allstabstring := strnew(st);
  4627. freemem(st,strlen(ss)+512);
  4628. strdispose(ss);
  4629. end;
  4630. procedure tobjectdef.concatstabto(asmlist : taasmoutput);
  4631. var
  4632. oldtypesym : tsym;
  4633. stab_str : pchar;
  4634. anc : tobjectdef;
  4635. begin
  4636. if (stab_state in [stab_state_writing,stab_state_written]) then
  4637. exit;
  4638. stab_state:=stab_state_writing;
  4639. tstoreddef(vmtarraytype.def).concatstabto(asmlist);
  4640. { first the parents }
  4641. anc:=self;
  4642. while assigned(anc.childof) do
  4643. begin
  4644. anc:=anc.childof;
  4645. anc.concatstabto(asmlist);
  4646. end;
  4647. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}field_concatstabto,asmlist);
  4648. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}proc_concatstabto,asmlist);
  4649. stab_state:=stab_state_used;
  4650. if objecttype=odt_class then
  4651. begin
  4652. { Write the record class itself }
  4653. writing_class_record_stab:=true;
  4654. inherited concatstabto(asmlist);
  4655. writing_class_record_stab:=false;
  4656. { Write the invisible pointer class }
  4657. oldtypesym:=typesym;
  4658. typesym:=nil;
  4659. stab_str := allstabstring;
  4660. asmList.concat(Tai_stabs.Create(stab_str));
  4661. typesym:=oldtypesym;
  4662. end
  4663. else
  4664. inherited concatstabto(asmlist);
  4665. end;
  4666. {$endif GDB}
  4667. function tobjectdef.needs_inittable : boolean;
  4668. begin
  4669. case objecttype of
  4670. odt_class :
  4671. needs_inittable:=false;
  4672. odt_interfacecom:
  4673. needs_inittable:=true;
  4674. odt_interfacecorba:
  4675. needs_inittable:=is_related(interface_iunknown);
  4676. odt_object:
  4677. needs_inittable:=tobjectsymtable(symtable).needs_init_final;
  4678. else
  4679. internalerror(200108267);
  4680. end;
  4681. end;
  4682. function tobjectdef.members_need_inittable : boolean;
  4683. begin
  4684. members_need_inittable:=tobjectsymtable(symtable).needs_init_final;
  4685. end;
  4686. procedure tobjectdef.count_published_properties(sym:tnamedindexitem;arg:pointer);
  4687. begin
  4688. if needs_prop_entry(tsym(sym)) and
  4689. (tsym(sym).typ<>varsym) then
  4690. inc(count);
  4691. end;
  4692. procedure tobjectdef.write_property_info(sym : tnamedindexitem;arg:pointer);
  4693. var
  4694. proctypesinfo : byte;
  4695. procedure writeproc(proc : tsymlist; shiftvalue : byte);
  4696. var
  4697. typvalue : byte;
  4698. hp : psymlistitem;
  4699. address : longint;
  4700. def : tdef;
  4701. begin
  4702. if not(assigned(proc) and assigned(proc.firstsym)) then
  4703. begin
  4704. rttiList.concat(Tai_const.create(ait_const_ptr,1));
  4705. typvalue:=3;
  4706. end
  4707. else if proc.firstsym^.sym.typ=varsym then
  4708. begin
  4709. address:=0;
  4710. hp:=proc.firstsym;
  4711. def:=nil;
  4712. while assigned(hp) do
  4713. begin
  4714. case hp^.sltype of
  4715. sl_load :
  4716. begin
  4717. def:=tvarsym(hp^.sym).vartype.def;
  4718. inc(address,tvarsym(hp^.sym).fieldoffset);
  4719. end;
  4720. sl_subscript :
  4721. begin
  4722. if not(assigned(def) and (def.deftype=recorddef)) then
  4723. internalerror(200402171);
  4724. inc(address,tvarsym(hp^.sym).fieldoffset);
  4725. def:=tvarsym(hp^.sym).vartype.def;
  4726. end;
  4727. sl_vec :
  4728. begin
  4729. if not(assigned(def) and (def.deftype=arraydef)) then
  4730. internalerror(200402172);
  4731. def:=tarraydef(def).elementtype.def;
  4732. inc(address,def.size*hp^.value);
  4733. end;
  4734. end;
  4735. hp:=hp^.next;
  4736. end;
  4737. rttiList.concat(Tai_const.create(ait_const_ptr,address));
  4738. typvalue:=0;
  4739. end
  4740. else
  4741. begin
  4742. { When there was an error then procdef is not assigned }
  4743. if not assigned(proc.procdef) then
  4744. exit;
  4745. if not(po_virtualmethod in tprocdef(proc.procdef).procoptions) then
  4746. begin
  4747. rttiList.concat(Tai_const.createname(tprocdef(proc.procdef).mangledname,AT_FUNCTION,0));
  4748. typvalue:=1;
  4749. end
  4750. else
  4751. begin
  4752. { virtual method, write vmt offset }
  4753. rttiList.concat(Tai_const.create(ait_const_ptr,
  4754. tprocdef(proc.procdef)._class.vmtmethodoffset(tprocdef(proc.procdef).extnumber)));
  4755. typvalue:=2;
  4756. end;
  4757. end;
  4758. proctypesinfo:=proctypesinfo or (typvalue shl shiftvalue);
  4759. end;
  4760. begin
  4761. if needs_prop_entry(tsym(sym)) then
  4762. case tsym(sym).typ of
  4763. varsym:
  4764. begin
  4765. {$ifdef dummy}
  4766. if not(tvarsym(sym).vartype.def.deftype=objectdef) or
  4767. not(tobjectdef(tvarsym(sym).vartype.def).is_class) then
  4768. internalerror(1509992);
  4769. { access to implicit class property as field }
  4770. proctypesinfo:=(0 shl 0) or (0 shl 2) or (0 shl 4);
  4771. rttiList.concat(Tai_const_symbol.Createname(tvarsym(sym.vartype.def.get_rtti_label),AT_DATA,0));
  4772. rttiList.concat(Tai_const.create(ait_const_ptr,tvarsym(sym.address)));
  4773. rttiList.concat(Tai_const.create(ait_const_ptr,tvarsym(sym.address)));
  4774. { by default stored }
  4775. rttiList.concat(Tai_const.Create_32bit(1));
  4776. { index as well as ... }
  4777. rttiList.concat(Tai_const.Create_32bit(0));
  4778. { default value are zero }
  4779. rttiList.concat(Tai_const.Create_32bit(0));
  4780. rttiList.concat(Tai_const.Create_16bit(count));
  4781. inc(count);
  4782. rttiList.concat(Tai_const.Create_8bit(proctypesinfo));
  4783. rttiList.concat(Tai_const.Create_8bit(length(tvarsym(sym.realname))));
  4784. rttiList.concat(Tai_string.Create(tvarsym(sym.realname)));
  4785. {$endif dummy}
  4786. end;
  4787. propertysym:
  4788. begin
  4789. if ppo_indexed in tpropertysym(sym).propoptions then
  4790. proctypesinfo:=$40
  4791. else
  4792. proctypesinfo:=0;
  4793. rttiList.concat(Tai_const.Create_sym(tstoreddef(tpropertysym(sym).proptype.def).get_rtti_label(fullrtti)));
  4794. writeproc(tpropertysym(sym).readaccess,0);
  4795. writeproc(tpropertysym(sym).writeaccess,2);
  4796. { isn't it stored ? }
  4797. if not(ppo_stored in tpropertysym(sym).propoptions) then
  4798. begin
  4799. rttiList.concat(Tai_const.create_sym(nil));
  4800. proctypesinfo:=proctypesinfo or (3 shl 4);
  4801. end
  4802. else
  4803. writeproc(tpropertysym(sym).storedaccess,4);
  4804. rttiList.concat(Tai_const.Create_32bit(tpropertysym(sym).index));
  4805. rttiList.concat(Tai_const.Create_32bit(tpropertysym(sym).default));
  4806. rttiList.concat(Tai_const.Create_16bit(count));
  4807. inc(count);
  4808. rttiList.concat(Tai_const.Create_8bit(proctypesinfo));
  4809. rttiList.concat(Tai_const.Create_8bit(length(tpropertysym(sym).realname)));
  4810. rttiList.concat(Tai_string.Create(tpropertysym(sym).realname));
  4811. end;
  4812. else internalerror(1509992);
  4813. end;
  4814. end;
  4815. procedure tobjectdef.generate_published_child_rtti(sym : tnamedindexitem;arg:pointer);
  4816. begin
  4817. if needs_prop_entry(tsym(sym)) then
  4818. begin
  4819. case tsym(sym).typ of
  4820. propertysym:
  4821. tstoreddef(tpropertysym(sym).proptype.def).get_rtti_label(fullrtti);
  4822. varsym:
  4823. tstoreddef(tvarsym(sym).vartype.def).get_rtti_label(fullrtti);
  4824. else
  4825. internalerror(1509991);
  4826. end;
  4827. end;
  4828. end;
  4829. procedure tobjectdef.write_child_rtti_data(rt:trttitype);
  4830. begin
  4831. FRTTIType:=rt;
  4832. case rt of
  4833. initrtti :
  4834. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}generate_field_rtti,nil);
  4835. fullrtti :
  4836. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}generate_published_child_rtti,nil);
  4837. else
  4838. internalerror(200108301);
  4839. end;
  4840. end;
  4841. type
  4842. tclasslistitem = class(TLinkedListItem)
  4843. index : longint;
  4844. p : tobjectdef;
  4845. end;
  4846. var
  4847. classtablelist : tlinkedlist;
  4848. tablecount : longint;
  4849. function searchclasstablelist(p : tobjectdef) : tclasslistitem;
  4850. var
  4851. hp : tclasslistitem;
  4852. begin
  4853. hp:=tclasslistitem(classtablelist.first);
  4854. while assigned(hp) do
  4855. if hp.p=p then
  4856. begin
  4857. searchclasstablelist:=hp;
  4858. exit;
  4859. end
  4860. else
  4861. hp:=tclasslistitem(hp.next);
  4862. searchclasstablelist:=nil;
  4863. end;
  4864. procedure tobjectdef.count_published_fields(sym:tnamedindexitem;arg:pointer);
  4865. var
  4866. hp : tclasslistitem;
  4867. begin
  4868. if needs_prop_entry(tsym(sym)) and
  4869. (tsym(sym).typ=varsym) then
  4870. begin
  4871. if tvarsym(sym).vartype.def.deftype<>objectdef then
  4872. internalerror(0206001);
  4873. hp:=searchclasstablelist(tobjectdef(tvarsym(sym).vartype.def));
  4874. if not(assigned(hp)) then
  4875. begin
  4876. hp:=tclasslistitem.create;
  4877. hp.p:=tobjectdef(tvarsym(sym).vartype.def);
  4878. hp.index:=tablecount;
  4879. classtablelist.concat(hp);
  4880. inc(tablecount);
  4881. end;
  4882. inc(count);
  4883. end;
  4884. end;
  4885. procedure tobjectdef.writefields(sym:tnamedindexitem;arg:pointer);
  4886. var
  4887. hp : tclasslistitem;
  4888. begin
  4889. if needs_prop_entry(tsym(sym)) and
  4890. (tsym(sym).typ=varsym) then
  4891. begin
  4892. rttiList.concat(Tai_const.Create_32bit(tvarsym(sym).fieldoffset));
  4893. hp:=searchclasstablelist(tobjectdef(tvarsym(sym).vartype.def));
  4894. if not(assigned(hp)) then
  4895. internalerror(0206002);
  4896. rttiList.concat(Tai_const.Create_16bit(hp.index));
  4897. rttiList.concat(Tai_const.Create_8bit(length(tvarsym(sym).realname)));
  4898. rttiList.concat(Tai_string.Create(tvarsym(sym).realname));
  4899. end;
  4900. end;
  4901. function tobjectdef.generate_field_table : tasmlabel;
  4902. var
  4903. fieldtable,
  4904. classtable : tasmlabel;
  4905. hp : tclasslistitem;
  4906. begin
  4907. classtablelist:=TLinkedList.Create;
  4908. objectlibrary.getdatalabel(fieldtable);
  4909. objectlibrary.getdatalabel(classtable);
  4910. count:=0;
  4911. tablecount:=0;
  4912. maybe_new_object_file(rttiList);
  4913. new_section(rttiList,sec_rodata,classtable.name,const_align(sizeof(aint)));
  4914. { fields }
  4915. symtable.foreach({$ifdef FPC}@{$endif}count_published_fields,nil);
  4916. rttiList.concat(Tai_label.Create(fieldtable));
  4917. rttiList.concat(Tai_const.Create_16bit(count));
  4918. rttiList.concat(Tai_const.Create_sym(classtable));
  4919. symtable.foreach({$ifdef FPC}@{$endif}writefields,nil);
  4920. { generate the class table }
  4921. rttilist.concat(tai_align.create(const_align(sizeof(aint))));
  4922. rttiList.concat(Tai_label.Create(classtable));
  4923. rttiList.concat(Tai_const.Create_16bit(tablecount));
  4924. hp:=tclasslistitem(classtablelist.first);
  4925. while assigned(hp) do
  4926. begin
  4927. rttiList.concat(Tai_const.Createname(tobjectdef(hp.p).vmt_mangledname,AT_DATA,0));
  4928. hp:=tclasslistitem(hp.next);
  4929. end;
  4930. generate_field_table:=fieldtable;
  4931. classtablelist.free;
  4932. end;
  4933. function tobjectdef.next_free_name_index : longint;
  4934. var
  4935. i : longint;
  4936. begin
  4937. if assigned(childof) and (oo_can_have_published in childof.objectoptions) then
  4938. i:=childof.next_free_name_index
  4939. else
  4940. i:=0;
  4941. count:=0;
  4942. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}count_published_properties,nil);
  4943. next_free_name_index:=i+count;
  4944. end;
  4945. procedure tobjectdef.write_rtti_data(rt:trttitype);
  4946. begin
  4947. case objecttype of
  4948. odt_class:
  4949. rttiList.concat(Tai_const.Create_8bit(tkclass));
  4950. odt_object:
  4951. rttiList.concat(Tai_const.Create_8bit(tkobject));
  4952. odt_interfacecom:
  4953. rttiList.concat(Tai_const.Create_8bit(tkinterface));
  4954. odt_interfacecorba:
  4955. rttiList.concat(Tai_const.Create_8bit(tkinterfaceCorba));
  4956. else
  4957. exit;
  4958. end;
  4959. { generate the name }
  4960. rttiList.concat(Tai_const.Create_8bit(length(objrealname^)));
  4961. rttiList.concat(Tai_string.Create(objrealname^));
  4962. case rt of
  4963. initrtti :
  4964. begin
  4965. rttiList.concat(Tai_const.Create_32bit(size));
  4966. if objecttype in [odt_class,odt_object] then
  4967. begin
  4968. count:=0;
  4969. FRTTIType:=rt;
  4970. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}count_field_rtti,nil);
  4971. rttiList.concat(Tai_const.Create_32bit(count));
  4972. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}write_field_rtti,nil);
  4973. end;
  4974. end;
  4975. fullrtti :
  4976. begin
  4977. if (oo_has_vmt in objectoptions) and
  4978. not(objecttype in [odt_interfacecom,odt_interfacecorba]) then
  4979. rttiList.concat(Tai_const.Createname(vmt_mangledname,AT_DATA,0))
  4980. else
  4981. rttiList.concat(Tai_const.create_sym(nil));
  4982. { write owner typeinfo }
  4983. if assigned(childof) and (oo_can_have_published in childof.objectoptions) then
  4984. rttiList.concat(Tai_const.Create_sym(childof.get_rtti_label(fullrtti)))
  4985. else
  4986. rttiList.concat(Tai_const.create_sym(nil));
  4987. { count total number of properties }
  4988. if assigned(childof) and (oo_can_have_published in childof.objectoptions) then
  4989. count:=childof.next_free_name_index
  4990. else
  4991. count:=0;
  4992. { write it }
  4993. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}count_published_properties,nil);
  4994. rttiList.concat(Tai_const.Create_16bit(count));
  4995. { write unit name }
  4996. rttiList.concat(Tai_const.Create_8bit(length(current_module.realmodulename^)));
  4997. rttiList.concat(Tai_string.Create(current_module.realmodulename^));
  4998. { write published properties count }
  4999. count:=0;
  5000. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}count_published_properties,nil);
  5001. rttiList.concat(Tai_const.Create_16bit(count));
  5002. { count is used to write nameindex }
  5003. { but we need an offset of the owner }
  5004. { to give each property an own slot }
  5005. if assigned(childof) and (oo_can_have_published in childof.objectoptions) then
  5006. count:=childof.next_free_name_index
  5007. else
  5008. count:=0;
  5009. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}write_property_info,nil);
  5010. end;
  5011. end;
  5012. end;
  5013. function tobjectdef.is_publishable : boolean;
  5014. begin
  5015. is_publishable:=objecttype in [odt_class,odt_interfacecom,odt_interfacecorba];
  5016. end;
  5017. {****************************************************************************
  5018. TIMPLEMENTEDINTERFACES
  5019. ****************************************************************************}
  5020. type
  5021. tnamemap = class(TNamedIndexItem)
  5022. newname: pstring;
  5023. constructor create(const aname, anewname: string);
  5024. destructor destroy; override;
  5025. end;
  5026. constructor tnamemap.create(const aname, anewname: string);
  5027. begin
  5028. inherited createname(name);
  5029. newname:=stringdup(anewname);
  5030. end;
  5031. destructor tnamemap.destroy;
  5032. begin
  5033. stringdispose(newname);
  5034. inherited destroy;
  5035. end;
  5036. type
  5037. tprocdefstore = class(TNamedIndexItem)
  5038. procdef: tprocdef;
  5039. constructor create(aprocdef: tprocdef);
  5040. end;
  5041. constructor tprocdefstore.create(aprocdef: tprocdef);
  5042. begin
  5043. inherited create;
  5044. procdef:=aprocdef;
  5045. end;
  5046. type
  5047. timplintfentry = class(TNamedIndexItem)
  5048. intf: tobjectdef;
  5049. intfderef : tderef;
  5050. ioffs: longint;
  5051. namemappings: tdictionary;
  5052. procdefs: TIndexArray;
  5053. constructor create(aintf: tobjectdef);
  5054. constructor create_deref(const d:tderef);
  5055. destructor destroy; override;
  5056. end;
  5057. constructor timplintfentry.create(aintf: tobjectdef);
  5058. begin
  5059. inherited create;
  5060. intf:=aintf;
  5061. ioffs:=-1;
  5062. namemappings:=nil;
  5063. procdefs:=nil;
  5064. end;
  5065. constructor timplintfentry.create_deref(const d:tderef);
  5066. begin
  5067. inherited create;
  5068. intf:=nil;
  5069. intfderef:=d;
  5070. ioffs:=-1;
  5071. namemappings:=nil;
  5072. procdefs:=nil;
  5073. end;
  5074. destructor timplintfentry.destroy;
  5075. begin
  5076. if assigned(namemappings) then
  5077. namemappings.free;
  5078. if assigned(procdefs) then
  5079. procdefs.free;
  5080. inherited destroy;
  5081. end;
  5082. constructor timplementedinterfaces.create;
  5083. begin
  5084. finterfaces:=tindexarray.create(1);
  5085. end;
  5086. destructor timplementedinterfaces.destroy;
  5087. begin
  5088. finterfaces.destroy;
  5089. end;
  5090. function timplementedinterfaces.count: longint;
  5091. begin
  5092. count:=finterfaces.count;
  5093. end;
  5094. procedure timplementedinterfaces.checkindex(intfindex: longint);
  5095. begin
  5096. if (intfindex<1) or (intfindex>count) then
  5097. InternalError(200006123);
  5098. end;
  5099. function timplementedinterfaces.interfaces(intfindex: longint): tobjectdef;
  5100. begin
  5101. checkindex(intfindex);
  5102. interfaces:=timplintfentry(finterfaces.search(intfindex)).intf;
  5103. end;
  5104. function timplementedinterfaces.interfacesderef(intfindex: longint): tderef;
  5105. begin
  5106. checkindex(intfindex);
  5107. interfacesderef:=timplintfentry(finterfaces.search(intfindex)).intfderef;
  5108. end;
  5109. function timplementedinterfaces.ioffsets(intfindex: longint): plongint;
  5110. begin
  5111. checkindex(intfindex);
  5112. ioffsets:=@timplintfentry(finterfaces.search(intfindex)).ioffs;
  5113. end;
  5114. function timplementedinterfaces.searchintf(def: tdef): longint;
  5115. var
  5116. i: longint;
  5117. begin
  5118. i:=1;
  5119. while (i<=count) and (tdef(interfaces(i))<>def) do inc(i);
  5120. if i<=count then
  5121. searchintf:=i
  5122. else
  5123. searchintf:=-1;
  5124. end;
  5125. procedure timplementedinterfaces.buildderef;
  5126. var
  5127. i: longint;
  5128. begin
  5129. for i:=1 to count do
  5130. with timplintfentry(finterfaces.search(i)) do
  5131. intfderef.build(intf);
  5132. end;
  5133. procedure timplementedinterfaces.deref;
  5134. var
  5135. i: longint;
  5136. begin
  5137. for i:=1 to count do
  5138. with timplintfentry(finterfaces.search(i)) do
  5139. intf:=tobjectdef(intfderef.resolve);
  5140. end;
  5141. procedure timplementedinterfaces.addintf_deref(const d:tderef);
  5142. begin
  5143. finterfaces.insert(timplintfentry.create_deref(d));
  5144. end;
  5145. procedure timplementedinterfaces.addintf(def: tdef);
  5146. begin
  5147. if not assigned(def) or (searchintf(def)<>-1) or (def.deftype<>objectdef) or
  5148. not (tobjectdef(def).objecttype in [odt_interfacecom,odt_interfacecorba]) then
  5149. internalerror(200006124);
  5150. finterfaces.insert(timplintfentry.create(tobjectdef(def)));
  5151. end;
  5152. procedure timplementedinterfaces.clearmappings;
  5153. var
  5154. i: longint;
  5155. begin
  5156. for i:=1 to count do
  5157. with timplintfentry(finterfaces.search(i)) do
  5158. begin
  5159. if assigned(namemappings) then
  5160. namemappings.free;
  5161. namemappings:=nil;
  5162. end;
  5163. end;
  5164. procedure timplementedinterfaces.addmappings(intfindex: longint; const name, newname: string);
  5165. begin
  5166. checkindex(intfindex);
  5167. with timplintfentry(finterfaces.search(intfindex)) do
  5168. begin
  5169. if not assigned(namemappings) then
  5170. namemappings:=tdictionary.create;
  5171. namemappings.insert(tnamemap.create(name,newname));
  5172. end;
  5173. end;
  5174. function timplementedinterfaces.getmappings(intfindex: longint; const name: string; var nextexist: pointer): string;
  5175. begin
  5176. checkindex(intfindex);
  5177. if not assigned(nextexist) then
  5178. with timplintfentry(finterfaces.search(intfindex)) do
  5179. begin
  5180. if assigned(namemappings) then
  5181. nextexist:=namemappings.search(name)
  5182. else
  5183. nextexist:=nil;
  5184. end;
  5185. if assigned(nextexist) then
  5186. begin
  5187. getmappings:=tnamemap(nextexist).newname^;
  5188. nextexist:=tnamemap(nextexist).listnext;
  5189. end
  5190. else
  5191. getmappings:='';
  5192. end;
  5193. procedure timplementedinterfaces.clearimplprocs;
  5194. var
  5195. i: longint;
  5196. begin
  5197. for i:=1 to count do
  5198. with timplintfentry(finterfaces.search(i)) do
  5199. begin
  5200. if assigned(procdefs) then
  5201. procdefs.free;
  5202. procdefs:=nil;
  5203. end;
  5204. end;
  5205. procedure timplementedinterfaces.addimplproc(intfindex: longint; procdef: tprocdef);
  5206. begin
  5207. checkindex(intfindex);
  5208. with timplintfentry(finterfaces.search(intfindex)) do
  5209. begin
  5210. if not assigned(procdefs) then
  5211. procdefs:=tindexarray.create(4);
  5212. procdefs.insert(tprocdefstore.create(procdef));
  5213. end;
  5214. end;
  5215. function timplementedinterfaces.implproccount(intfindex: longint): longint;
  5216. begin
  5217. checkindex(intfindex);
  5218. with timplintfentry(finterfaces.search(intfindex)) do
  5219. if assigned(procdefs) then
  5220. implproccount:=procdefs.count
  5221. else
  5222. implproccount:=0;
  5223. end;
  5224. function timplementedinterfaces.implprocs(intfindex: longint; procindex: longint): tprocdef;
  5225. begin
  5226. checkindex(intfindex);
  5227. with timplintfentry(finterfaces.search(intfindex)) do
  5228. if assigned(procdefs) then
  5229. implprocs:=tprocdefstore(procdefs.search(procindex)).procdef
  5230. else
  5231. internalerror(200006131);
  5232. end;
  5233. function timplementedinterfaces.isimplmergepossible(intfindex, remainindex: longint; var weight: longint): boolean;
  5234. var
  5235. possible: boolean;
  5236. i: longint;
  5237. iiep1: TIndexArray;
  5238. iiep2: TIndexArray;
  5239. begin
  5240. checkindex(intfindex);
  5241. checkindex(remainindex);
  5242. iiep1:=timplintfentry(finterfaces.search(intfindex)).procdefs;
  5243. iiep2:=timplintfentry(finterfaces.search(remainindex)).procdefs;
  5244. if not assigned(iiep1) then { empty interface is mergeable :-) }
  5245. begin
  5246. possible:=true;
  5247. weight:=0;
  5248. end
  5249. else
  5250. begin
  5251. possible:=assigned(iiep2) and (iiep1.count<=iiep2.count);
  5252. i:=1;
  5253. while (possible) and (i<=iiep1.count) do
  5254. begin
  5255. possible:=
  5256. (tprocdefstore(iiep1.search(i)).procdef=tprocdefstore(iiep2.search(i)).procdef);
  5257. inc(i);
  5258. end;
  5259. if possible then
  5260. weight:=iiep1.count;
  5261. end;
  5262. isimplmergepossible:=possible;
  5263. end;
  5264. {****************************************************************************
  5265. TFORWARDDEF
  5266. ****************************************************************************}
  5267. constructor tforwarddef.create(const s:string;const pos : tfileposinfo);
  5268. var
  5269. oldregisterdef : boolean;
  5270. begin
  5271. { never register the forwarddefs, they are disposed at the
  5272. end of the type declaration block }
  5273. oldregisterdef:=registerdef;
  5274. registerdef:=false;
  5275. inherited create;
  5276. registerdef:=oldregisterdef;
  5277. deftype:=forwarddef;
  5278. tosymname:=stringdup(s);
  5279. forwardpos:=pos;
  5280. end;
  5281. function tforwarddef.gettypename:string;
  5282. begin
  5283. gettypename:='unresolved forward to '+tosymname^;
  5284. end;
  5285. destructor tforwarddef.destroy;
  5286. begin
  5287. if assigned(tosymname) then
  5288. stringdispose(tosymname);
  5289. inherited destroy;
  5290. end;
  5291. {****************************************************************************
  5292. TERRORDEF
  5293. ****************************************************************************}
  5294. constructor terrordef.create;
  5295. begin
  5296. inherited create;
  5297. deftype:=errordef;
  5298. end;
  5299. {$ifdef GDB}
  5300. function terrordef.stabstring : pchar;
  5301. begin
  5302. stabstring:=strpnew('error'+numberstring);
  5303. end;
  5304. procedure terrordef.concatstabto(asmlist : taasmoutput);
  5305. begin
  5306. { No internal error needed, an normal error is already
  5307. thrown }
  5308. end;
  5309. {$endif GDB}
  5310. function terrordef.gettypename:string;
  5311. begin
  5312. gettypename:='<erroneous type>';
  5313. end;
  5314. function terrordef.getmangledparaname:string;
  5315. begin
  5316. getmangledparaname:='error';
  5317. end;
  5318. {****************************************************************************
  5319. Definition Helpers
  5320. ****************************************************************************}
  5321. function is_interfacecom(def: tdef): boolean;
  5322. begin
  5323. is_interfacecom:=
  5324. assigned(def) and
  5325. (def.deftype=objectdef) and
  5326. (tobjectdef(def).objecttype=odt_interfacecom);
  5327. end;
  5328. function is_interfacecorba(def: tdef): boolean;
  5329. begin
  5330. is_interfacecorba:=
  5331. assigned(def) and
  5332. (def.deftype=objectdef) and
  5333. (tobjectdef(def).objecttype=odt_interfacecorba);
  5334. end;
  5335. function is_interface(def: tdef): boolean;
  5336. begin
  5337. is_interface:=
  5338. assigned(def) and
  5339. (def.deftype=objectdef) and
  5340. (tobjectdef(def).objecttype in [odt_interfacecom,odt_interfacecorba]);
  5341. end;
  5342. function is_class(def: tdef): boolean;
  5343. begin
  5344. is_class:=
  5345. assigned(def) and
  5346. (def.deftype=objectdef) and
  5347. (tobjectdef(def).objecttype=odt_class);
  5348. end;
  5349. function is_object(def: tdef): boolean;
  5350. begin
  5351. is_object:=
  5352. assigned(def) and
  5353. (def.deftype=objectdef) and
  5354. (tobjectdef(def).objecttype=odt_object);
  5355. end;
  5356. function is_cppclass(def: tdef): boolean;
  5357. begin
  5358. is_cppclass:=
  5359. assigned(def) and
  5360. (def.deftype=objectdef) and
  5361. (tobjectdef(def).objecttype=odt_cppclass);
  5362. end;
  5363. function is_class_or_interface(def: tdef): boolean;
  5364. begin
  5365. is_class_or_interface:=
  5366. assigned(def) and
  5367. (def.deftype=objectdef) and
  5368. (tobjectdef(def).objecttype in [odt_class,odt_interfacecom,odt_interfacecorba]);
  5369. end;
  5370. end.
  5371. {
  5372. $Log$
  5373. Revision 1.253 2004-08-27 21:59:26 peter
  5374. browser disabled
  5375. uf_local_symtable ppu flag when a localsymtable is stored
  5376. Revision 1.252 2004/08/17 16:29:21 jonas
  5377. + padalgingment field for recordsymtables (saved by recorddefs)
  5378. + support for Macintosh PowerPC alignment (if the first field of a record
  5379. or union has an alignment > 4, then the record or union size must be
  5380. padded to a multiple of this size)
  5381. Revision 1.251 2004/08/15 15:05:16 peter
  5382. * fixed padding of records to alignment
  5383. Revision 1.250 2004/08/14 14:50:42 florian
  5384. * fixed several sparc alignment issues
  5385. + Jonas' inline node patch; non functional yet
  5386. Revision 1.249 2004/08/07 14:52:45 florian
  5387. * fixed web bug 3226: type p = type pointer;
  5388. Revision 1.248 2004/07/19 19:15:50 florian
  5389. * fixed funcret_paraloc writing in units
  5390. Revision 1.247 2004/07/14 21:37:41 olle
  5391. - removed unused types
  5392. Revision 1.246 2004/07/12 09:14:04 jonas
  5393. * inline procedures at the node tree level, but only under some very
  5394. limited circumstances for now (only procedures, and only if they have
  5395. no or only vs_out/vs_var parameters).
  5396. * fixed ppudump for inline procedures
  5397. * fixed ppudump for ppc
  5398. Revision 1.245 2004/07/09 22:17:32 peter
  5399. * revert has_localst patch
  5400. * replace aktstaticsymtable/aktglobalsymtable with current_module
  5401. Revision 1.244 2004/07/06 19:52:04 peter
  5402. * fix storing of localst in ppu
  5403. Revision 1.243 2004/06/20 08:55:30 florian
  5404. * logs truncated
  5405. Revision 1.242 2004/06/18 15:16:46 peter
  5406. * remove obsolete cardinal() typecasts
  5407. Revision 1.241 2004/06/16 20:07:09 florian
  5408. * dwarf branch merged
  5409. Revision 1.240 2004/05/25 18:51:14 peter
  5410. * range check error
  5411. Revision 1.239 2004/05/23 20:57:10 peter
  5412. * removed unused voidprocdef
  5413. Revision 1.238 2004/05/23 15:23:30 peter
  5414. * fixed qword(longint) that removed sign from the number
  5415. * removed code in the compiler that relied on wrong qword(longint)
  5416. code generation
  5417. }