symdef.pas 190 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225
  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. { restart ordering }
  1535. firstenum:=nil;
  1536. end;
  1537. destructor tenumdef.destroy;
  1538. begin
  1539. inherited destroy;
  1540. end;
  1541. procedure tenumdef.ppuwrite(ppufile:tcompilerppufile);
  1542. begin
  1543. inherited ppuwritedef(ppufile);
  1544. ppufile.putderef(basedefderef);
  1545. ppufile.putlongint(min);
  1546. ppufile.putlongint(max);
  1547. ppufile.putlongint(savesize);
  1548. ppufile.writeentry(ibenumdef);
  1549. end;
  1550. { used for enumdef because the symbols are
  1551. inserted in the owner symtable }
  1552. procedure tenumdef.correct_owner_symtable;
  1553. var
  1554. st : tsymtable;
  1555. begin
  1556. if assigned(owner) and
  1557. (owner.symtabletype in [recordsymtable,objectsymtable]) then
  1558. begin
  1559. owner.defindex.deleteindex(self);
  1560. st:=owner;
  1561. while (st.symtabletype in [recordsymtable,objectsymtable]) do
  1562. st:=st.next;
  1563. st.registerdef(self);
  1564. end;
  1565. end;
  1566. {$ifdef GDB}
  1567. function tenumdef.stabstring : pchar;
  1568. var st:Pchar;
  1569. p:Tenumsym;
  1570. s:string;
  1571. memsize,stl:cardinal;
  1572. begin
  1573. memsize:=memsizeinc;
  1574. getmem(st,memsize);
  1575. { we can specify the size with @s<size>; prefix PM }
  1576. if savesize <> std_param_align then
  1577. strpcopy(st,'@s'+tostr(savesize*8)+';e')
  1578. else
  1579. strpcopy(st,'e');
  1580. p := tenumsym(firstenum);
  1581. stl:=strlen(st);
  1582. while assigned(p) do
  1583. begin
  1584. s :=p.name+':'+tostr(p.value)+',';
  1585. { place for the ending ';' also }
  1586. if (stl+length(s)+1>=memsize) then
  1587. begin
  1588. inc(memsize,memsizeinc);
  1589. reallocmem(st,memsize);
  1590. end;
  1591. strpcopy(st+stl,s);
  1592. inc(stl,length(s));
  1593. p:=p.nextenum;
  1594. end;
  1595. st[stl]:=';';
  1596. st[stl+1]:=#0;
  1597. reallocmem(st,stl+2);
  1598. stabstring:=st;
  1599. end;
  1600. {$endif GDB}
  1601. procedure tenumdef.write_child_rtti_data(rt:trttitype);
  1602. begin
  1603. if assigned(basedef) then
  1604. basedef.get_rtti_label(rt);
  1605. end;
  1606. procedure tenumdef.write_rtti_data(rt:trttitype);
  1607. var
  1608. hp : tenumsym;
  1609. begin
  1610. rttiList.concat(Tai_const.Create_8bit(tkEnumeration));
  1611. write_rtti_name;
  1612. case savesize of
  1613. 1:
  1614. rttiList.concat(Tai_const.Create_8bit(otUByte));
  1615. 2:
  1616. rttiList.concat(Tai_const.Create_8bit(otUWord));
  1617. 4:
  1618. rttiList.concat(Tai_const.Create_8bit(otULong));
  1619. end;
  1620. rttiList.concat(Tai_const.Create_32bit(min));
  1621. rttiList.concat(Tai_const.Create_32bit(max));
  1622. if assigned(basedef) then
  1623. rttiList.concat(Tai_const.Create_sym(basedef.get_rtti_label(rt)))
  1624. else
  1625. rttiList.concat(Tai_const.create_sym(nil));
  1626. hp:=tenumsym(firstenum);
  1627. while assigned(hp) do
  1628. begin
  1629. rttiList.concat(Tai_const.Create_8bit(length(hp.realname)));
  1630. rttiList.concat(Tai_string.Create(hp.realname));
  1631. hp:=hp.nextenum;
  1632. end;
  1633. rttiList.concat(Tai_const.Create_8bit(0));
  1634. end;
  1635. function tenumdef.is_publishable : boolean;
  1636. begin
  1637. is_publishable:=true;
  1638. end;
  1639. function tenumdef.gettypename : string;
  1640. begin
  1641. gettypename:='<enumeration type>';
  1642. end;
  1643. {****************************************************************************
  1644. TORDDEF
  1645. ****************************************************************************}
  1646. constructor torddef.create(t : tbasetype;v,b : TConstExprInt);
  1647. begin
  1648. inherited create;
  1649. deftype:=orddef;
  1650. low:=v;
  1651. high:=b;
  1652. typ:=t;
  1653. setsize;
  1654. end;
  1655. constructor torddef.ppuload(ppufile:tcompilerppufile);
  1656. begin
  1657. inherited ppuloaddef(ppufile);
  1658. deftype:=orddef;
  1659. typ:=tbasetype(ppufile.getbyte);
  1660. if sizeof(TConstExprInt)=8 then
  1661. begin
  1662. low:=ppufile.getint64;
  1663. high:=ppufile.getint64;
  1664. end
  1665. else
  1666. begin
  1667. low:=ppufile.getlongint;
  1668. high:=ppufile.getlongint;
  1669. end;
  1670. setsize;
  1671. end;
  1672. function torddef.getcopy : tstoreddef;
  1673. begin
  1674. result:=torddef.create(typ,low,high);
  1675. result.deftype:=orddef;
  1676. torddef(result).low:=low;
  1677. torddef(result).high:=high;
  1678. torddef(result).typ:=typ;
  1679. torddef(result).savesize:=savesize;
  1680. end;
  1681. procedure torddef.setsize;
  1682. const
  1683. sizetbl : array[tbasetype] of longint = (
  1684. 0,
  1685. 1,2,4,8,
  1686. 1,2,4,8,
  1687. 1,2,4,
  1688. 1,2,8
  1689. );
  1690. begin
  1691. savesize:=sizetbl[typ];
  1692. end;
  1693. procedure torddef.ppuwrite(ppufile:tcompilerppufile);
  1694. begin
  1695. inherited ppuwritedef(ppufile);
  1696. ppufile.putbyte(byte(typ));
  1697. if sizeof(TConstExprInt)=8 then
  1698. begin
  1699. ppufile.putint64(low);
  1700. ppufile.putint64(high);
  1701. end
  1702. else
  1703. begin
  1704. ppufile.putlongint(low);
  1705. ppufile.putlongint(high);
  1706. end;
  1707. ppufile.writeentry(iborddef);
  1708. end;
  1709. {$ifdef GDB}
  1710. function torddef.stabstring : pchar;
  1711. begin
  1712. if cs_gdb_valgrind in aktglobalswitches then
  1713. begin
  1714. case typ of
  1715. uvoid :
  1716. stabstring := strpnew(numberstring);
  1717. bool8bit,
  1718. bool16bit,
  1719. bool32bit :
  1720. stabstring := stabstr_evaluate('r${numberstring};0;255;',[]);
  1721. u32bit,
  1722. s64bit,
  1723. u64bit :
  1724. stabstring:=stabstr_evaluate('r${numberstring};0;-1;',[]);
  1725. else
  1726. stabstring:=stabstr_evaluate('r${numberstring};$1;$2;',[tostr(longint(low)),tostr(longint(high))]);
  1727. end;
  1728. end
  1729. else
  1730. begin
  1731. case typ of
  1732. uvoid :
  1733. stabstring := strpnew(numberstring);
  1734. uchar :
  1735. stabstring := strpnew('-20;');
  1736. uwidechar :
  1737. stabstring := strpnew('-30;');
  1738. bool8bit :
  1739. stabstring := strpnew('-21;');
  1740. bool16bit :
  1741. stabstring := strpnew('-22;');
  1742. bool32bit :
  1743. stabstring := strpnew('-23;');
  1744. u64bit :
  1745. stabstring := strpnew('-32;');
  1746. s64bit :
  1747. stabstring := strpnew('-31;');
  1748. {u32bit : stabstring := tstoreddef(s32inttype.def).numberstring+';0;-1;'); }
  1749. else
  1750. stabstring:=stabstr_evaluate('r${numberstring};$1;$2;',[tostr(longint(low)),tostr(longint(high))]);
  1751. end;
  1752. end;
  1753. end;
  1754. {$endif GDB}
  1755. procedure torddef.write_rtti_data(rt:trttitype);
  1756. procedure dointeger;
  1757. const
  1758. trans : array[tbasetype] of byte =
  1759. (otUByte{otNone},
  1760. otUByte,otUWord,otULong,otUByte{otNone},
  1761. otSByte,otSWord,otSLong,otUByte{otNone},
  1762. otUByte,otUWord,otULong,
  1763. otUByte,otUWord,otUByte);
  1764. begin
  1765. write_rtti_name;
  1766. rttiList.concat(Tai_const.Create_8bit(byte(trans[typ])));
  1767. rttiList.concat(Tai_const.Create_32bit(longint(low)));
  1768. rttiList.concat(Tai_const.Create_32bit(longint(high)));
  1769. end;
  1770. begin
  1771. case typ of
  1772. s64bit :
  1773. begin
  1774. rttiList.concat(Tai_const.Create_8bit(tkInt64));
  1775. write_rtti_name;
  1776. { low }
  1777. rttiList.concat(Tai_const.Create_64bit(int64($80000000) shl 32));
  1778. { high }
  1779. rttiList.concat(Tai_const.Create_64bit((int64($7fffffff) shl 32) or int64($ffffffff)));
  1780. end;
  1781. u64bit :
  1782. begin
  1783. rttiList.concat(Tai_const.Create_8bit(tkQWord));
  1784. write_rtti_name;
  1785. { low }
  1786. rttiList.concat(Tai_const.Create_64bit(0));
  1787. { high }
  1788. rttiList.concat(Tai_const.Create_64bit(int64((int64($ffffffff) shl 32) or int64($ffffffff))));
  1789. end;
  1790. bool8bit:
  1791. begin
  1792. rttiList.concat(Tai_const.Create_8bit(tkBool));
  1793. dointeger;
  1794. end;
  1795. uchar:
  1796. begin
  1797. rttiList.concat(Tai_const.Create_8bit(tkChar));
  1798. dointeger;
  1799. end;
  1800. uwidechar:
  1801. begin
  1802. rttiList.concat(Tai_const.Create_8bit(tkWChar));
  1803. dointeger;
  1804. end;
  1805. else
  1806. begin
  1807. rttiList.concat(Tai_const.Create_8bit(tkInteger));
  1808. dointeger;
  1809. end;
  1810. end;
  1811. end;
  1812. function torddef.is_publishable : boolean;
  1813. begin
  1814. is_publishable:=(typ<>uvoid);
  1815. end;
  1816. function torddef.gettypename : string;
  1817. const
  1818. names : array[tbasetype] of string[20] = (
  1819. 'untyped',
  1820. 'Byte','Word','DWord','QWord',
  1821. 'ShortInt','SmallInt','LongInt','Int64',
  1822. 'Boolean','WordBool','LongBool',
  1823. 'Char','WideChar','Currency');
  1824. begin
  1825. gettypename:=names[typ];
  1826. end;
  1827. {****************************************************************************
  1828. TFLOATDEF
  1829. ****************************************************************************}
  1830. constructor tfloatdef.create(t : tfloattype);
  1831. begin
  1832. inherited create;
  1833. deftype:=floatdef;
  1834. typ:=t;
  1835. setsize;
  1836. end;
  1837. constructor tfloatdef.ppuload(ppufile:tcompilerppufile);
  1838. begin
  1839. inherited ppuloaddef(ppufile);
  1840. deftype:=floatdef;
  1841. typ:=tfloattype(ppufile.getbyte);
  1842. setsize;
  1843. end;
  1844. function tfloatdef.getcopy : tstoreddef;
  1845. begin
  1846. result:=tfloatdef.create(typ);
  1847. result.deftype:=floatdef;
  1848. tfloatdef(result).savesize:=savesize;
  1849. end;
  1850. procedure tfloatdef.setsize;
  1851. begin
  1852. case typ of
  1853. s32real : savesize:=4;
  1854. s80real : savesize:=extended_size;
  1855. s64real,
  1856. s64currency,
  1857. s64comp : savesize:=8;
  1858. else
  1859. savesize:=0;
  1860. end;
  1861. end;
  1862. procedure tfloatdef.ppuwrite(ppufile:tcompilerppufile);
  1863. begin
  1864. inherited ppuwritedef(ppufile);
  1865. ppufile.putbyte(byte(typ));
  1866. ppufile.writeentry(ibfloatdef);
  1867. end;
  1868. {$ifdef GDB}
  1869. function Tfloatdef.stabstring:Pchar;
  1870. begin
  1871. case typ of
  1872. s32real,s64real:
  1873. { found this solution in stabsread.c from GDB v4.16 }
  1874. stabstring:=stabstr_evaluate('r$1;${savesize};0;',[tstoreddef(s32inttype.def).numberstring]);
  1875. s64currency,s64comp:
  1876. stabstring:=stabstr_evaluate('r$1;-${savesize};0;',[tstoreddef(s32inttype.def).numberstring]);
  1877. s80real:
  1878. { under dos at least you must give a size of twelve instead of 10 !! }
  1879. { this is probably do to the fact that in gcc all is pushed in 4 bytes size }
  1880. stabstring:=stabstr_evaluate('r$1;12;0;',[tstoreddef(s32inttype.def).numberstring]);
  1881. else
  1882. internalerror(10005);
  1883. end;
  1884. end;
  1885. procedure tfloatdef.concatstabto(asmlist:taasmoutput);
  1886. begin
  1887. if (stab_state in [stab_state_writing,stab_state_written]) then
  1888. exit;
  1889. tstoreddef(s32inttype.def).concatstabto(asmlist);
  1890. inherited concatstabto(asmlist);
  1891. end;
  1892. {$endif GDB}
  1893. procedure tfloatdef.write_rtti_data(rt:trttitype);
  1894. const
  1895. {tfloattype = (s32real,s64real,s80real,s64bit,s128bit);}
  1896. translate : array[tfloattype] of byte =
  1897. (ftSingle,ftDouble,ftExtended,ftComp,ftCurr,ftFloat128);
  1898. begin
  1899. rttiList.concat(Tai_const.Create_8bit(tkFloat));
  1900. write_rtti_name;
  1901. rttiList.concat(Tai_const.Create_8bit(translate[typ]));
  1902. end;
  1903. function tfloatdef.is_publishable : boolean;
  1904. begin
  1905. is_publishable:=true;
  1906. end;
  1907. function tfloatdef.gettypename : string;
  1908. const
  1909. names : array[tfloattype] of string[20] = (
  1910. 'Single','Double','Extended','Comp','Currency','Float128');
  1911. begin
  1912. gettypename:=names[typ];
  1913. end;
  1914. {****************************************************************************
  1915. TFILEDEF
  1916. ****************************************************************************}
  1917. constructor tfiledef.createtext;
  1918. begin
  1919. inherited create;
  1920. deftype:=filedef;
  1921. filetyp:=ft_text;
  1922. typedfiletype.reset;
  1923. setsize;
  1924. end;
  1925. constructor tfiledef.createuntyped;
  1926. begin
  1927. inherited create;
  1928. deftype:=filedef;
  1929. filetyp:=ft_untyped;
  1930. typedfiletype.reset;
  1931. setsize;
  1932. end;
  1933. constructor tfiledef.createtyped(const tt : ttype);
  1934. begin
  1935. inherited create;
  1936. deftype:=filedef;
  1937. filetyp:=ft_typed;
  1938. typedfiletype:=tt;
  1939. setsize;
  1940. end;
  1941. constructor tfiledef.ppuload(ppufile:tcompilerppufile);
  1942. begin
  1943. inherited ppuloaddef(ppufile);
  1944. deftype:=filedef;
  1945. filetyp:=tfiletyp(ppufile.getbyte);
  1946. if filetyp=ft_typed then
  1947. ppufile.gettype(typedfiletype)
  1948. else
  1949. typedfiletype.reset;
  1950. setsize;
  1951. end;
  1952. procedure tfiledef.buildderef;
  1953. begin
  1954. inherited buildderef;
  1955. if filetyp=ft_typed then
  1956. typedfiletype.buildderef;
  1957. end;
  1958. procedure tfiledef.deref;
  1959. begin
  1960. inherited deref;
  1961. if filetyp=ft_typed then
  1962. typedfiletype.resolve;
  1963. end;
  1964. procedure tfiledef.setsize;
  1965. begin
  1966. {$ifdef cpu64bit}
  1967. case filetyp of
  1968. ft_text :
  1969. savesize:=608;
  1970. ft_typed,
  1971. ft_untyped :
  1972. savesize:=320;
  1973. end;
  1974. {$else cpu64bit}
  1975. case filetyp of
  1976. ft_text :
  1977. savesize:=572;
  1978. ft_typed,
  1979. ft_untyped :
  1980. savesize:=316;
  1981. end;
  1982. {$endif cpu64bit}
  1983. end;
  1984. procedure tfiledef.ppuwrite(ppufile:tcompilerppufile);
  1985. begin
  1986. inherited ppuwritedef(ppufile);
  1987. ppufile.putbyte(byte(filetyp));
  1988. if filetyp=ft_typed then
  1989. ppufile.puttype(typedfiletype);
  1990. ppufile.writeentry(ibfiledef);
  1991. end;
  1992. {$ifdef GDB}
  1993. function tfiledef.stabstring : pchar;
  1994. begin
  1995. {$IfDef GDBknowsfiles}
  1996. case filetyp of
  1997. ft_typed :
  1998. stabstring := strpnew('d'+typedfiletype.def.numberstring{+';'});
  1999. ft_untyped :
  2000. stabstring := strpnew('d'+voiddef.numberstring{+';'});
  2001. ft_text :
  2002. stabstring := strpnew('d'+cchartype^.numberstring{+';'});
  2003. end;
  2004. {$Else}
  2005. {$ifdef cpu64bit}
  2006. stabstring:=stabstr_evaluate('s${savesize}HANDLE:$1,0,32;MODE:$1,32,32;RECSIZE:$2,64,64;'+
  2007. '_PRIVATE:ar$1;1;64;$3,128,256;USERDATA:ar$1;1;16;$3,384,128;'+
  2008. 'NAME:ar$1;0;255;$4,512,2048;;',[tstoreddef(s32inttype.def).numberstring,
  2009. tstoreddef(s64inttype.def).numberstring,
  2010. tstoreddef(u8inttype.def).numberstring,
  2011. tstoreddef(cchartype.def).numberstring]);
  2012. {$else cpu64bit}
  2013. stabstring:=stabstr_evaluate('s${savesize}HANDLE:$1,0,32;MODE:$1,32,32;RECSIZE:$1,64,32;'+
  2014. '_PRIVATE:ar$1;1;32;$3,96,256;USERDATA:ar$1;1;16;$2,352,128;'+
  2015. 'NAME:ar$1;0;255;$3,480,2048;;',[tstoreddef(s32inttype.def).numberstring,
  2016. tstoreddef(u8inttype.def).numberstring,
  2017. tstoreddef(cchartype.def).numberstring]);
  2018. {$endif cpu64bit}
  2019. {$EndIf}
  2020. end;
  2021. procedure tfiledef.concatstabto(asmlist:taasmoutput);
  2022. begin
  2023. if (stab_state in [stab_state_writing,stab_state_written]) then
  2024. exit;
  2025. {$IfDef GDBknowsfiles}
  2026. case filetyp of
  2027. ft_typed :
  2028. tstoreddef(typedfiletype.def).concatstabto(asmlist);
  2029. ft_untyped :
  2030. tstoreddef(voidtype.def).concatstabto(asmlist);
  2031. ft_text :
  2032. tstoreddef(cchartype.def).concatstabto(asmlist);
  2033. end;
  2034. {$Else}
  2035. tstoreddef(s32inttype.def).concatstabto(asmlist);
  2036. {$ifdef cpu64bit}
  2037. tstoreddef(s64inttype.def).concatstabto(asmlist);
  2038. {$endif cpu64bit}
  2039. tstoreddef(u8inttype.def).concatstabto(asmlist);
  2040. tstoreddef(cchartype.def).concatstabto(asmlist);
  2041. {$EndIf}
  2042. inherited concatstabto(asmlist);
  2043. end;
  2044. {$endif GDB}
  2045. function tfiledef.gettypename : string;
  2046. begin
  2047. case filetyp of
  2048. ft_untyped:
  2049. gettypename:='File';
  2050. ft_typed:
  2051. gettypename:='File Of '+typedfiletype.def.typename;
  2052. ft_text:
  2053. gettypename:='Text'
  2054. end;
  2055. end;
  2056. function tfiledef.getmangledparaname : string;
  2057. begin
  2058. case filetyp of
  2059. ft_untyped:
  2060. getmangledparaname:='FILE';
  2061. ft_typed:
  2062. getmangledparaname:='FILE$OF$'+typedfiletype.def.mangledparaname;
  2063. ft_text:
  2064. getmangledparaname:='TEXT'
  2065. end;
  2066. end;
  2067. {****************************************************************************
  2068. TVARIANTDEF
  2069. ****************************************************************************}
  2070. constructor tvariantdef.create(v : tvarianttype);
  2071. begin
  2072. inherited create;
  2073. varianttype:=v;
  2074. deftype:=variantdef;
  2075. setsize;
  2076. end;
  2077. constructor tvariantdef.ppuload(ppufile:tcompilerppufile);
  2078. begin
  2079. inherited ppuloaddef(ppufile);
  2080. varianttype:=tvarianttype(ppufile.getbyte);
  2081. deftype:=variantdef;
  2082. setsize;
  2083. end;
  2084. procedure tvariantdef.ppuwrite(ppufile:tcompilerppufile);
  2085. begin
  2086. inherited ppuwritedef(ppufile);
  2087. ppufile.putbyte(byte(varianttype));
  2088. ppufile.writeentry(ibvariantdef);
  2089. end;
  2090. procedure tvariantdef.setsize;
  2091. begin
  2092. savesize:=16;
  2093. end;
  2094. function tvariantdef.gettypename : string;
  2095. begin
  2096. case varianttype of
  2097. vt_normalvariant:
  2098. gettypename:='Variant';
  2099. vt_olevariant:
  2100. gettypename:='OleVariant';
  2101. end;
  2102. end;
  2103. procedure tvariantdef.write_rtti_data(rt:trttitype);
  2104. begin
  2105. rttiList.concat(Tai_const.Create_8bit(tkVariant));
  2106. end;
  2107. function tvariantdef.needs_inittable : boolean;
  2108. begin
  2109. needs_inittable:=true;
  2110. end;
  2111. {$ifdef GDB}
  2112. function tvariantdef.stabstring : pchar;
  2113. begin
  2114. stabstring:=stabstr_evaluate('formal${numberstring};',[]);
  2115. end;
  2116. function tvariantdef.numberstring:string;
  2117. begin
  2118. result:=tstoreddef(voidtype.def).numberstring;
  2119. end;
  2120. procedure tvariantdef.concatstabto(asmlist : taasmoutput);
  2121. begin
  2122. { don't know how to handle this }
  2123. end;
  2124. {$endif GDB}
  2125. {****************************************************************************
  2126. TPOINTERDEF
  2127. ****************************************************************************}
  2128. constructor tpointerdef.create(const tt : ttype);
  2129. begin
  2130. inherited create;
  2131. deftype:=pointerdef;
  2132. pointertype:=tt;
  2133. is_far:=false;
  2134. savesize:=sizeof(aint);
  2135. end;
  2136. constructor tpointerdef.createfar(const tt : ttype);
  2137. begin
  2138. inherited create;
  2139. deftype:=pointerdef;
  2140. pointertype:=tt;
  2141. is_far:=true;
  2142. savesize:=sizeof(aint);
  2143. end;
  2144. constructor tpointerdef.ppuload(ppufile:tcompilerppufile);
  2145. begin
  2146. inherited ppuloaddef(ppufile);
  2147. deftype:=pointerdef;
  2148. ppufile.gettype(pointertype);
  2149. is_far:=(ppufile.getbyte<>0);
  2150. savesize:=sizeof(aint);
  2151. end;
  2152. function tpointerdef.getcopy : tstoreddef;
  2153. begin
  2154. result:=tpointerdef.create(pointertype);
  2155. tpointerdef(result).is_far:=is_far;
  2156. tpointerdef(result).savesize:=savesize;
  2157. end;
  2158. procedure tpointerdef.buildderef;
  2159. begin
  2160. inherited buildderef;
  2161. pointertype.buildderef;
  2162. end;
  2163. procedure tpointerdef.deref;
  2164. begin
  2165. inherited deref;
  2166. pointertype.resolve;
  2167. end;
  2168. procedure tpointerdef.ppuwrite(ppufile:tcompilerppufile);
  2169. begin
  2170. inherited ppuwritedef(ppufile);
  2171. ppufile.puttype(pointertype);
  2172. ppufile.putbyte(byte(is_far));
  2173. ppufile.writeentry(ibpointerdef);
  2174. end;
  2175. {$ifdef GDB}
  2176. function tpointerdef.stabstring : pchar;
  2177. begin
  2178. stabstring := strpnew('*'+tstoreddef(pointertype.def).numberstring);
  2179. end;
  2180. procedure tpointerdef.concatstabto(asmlist : taasmoutput);
  2181. var st,nb : string;
  2182. begin
  2183. if (stab_state in [stab_state_writing,stab_state_written]) then
  2184. exit;
  2185. stab_state:=stab_state_writing;
  2186. tstoreddef(pointertype.def).concatstabto(asmlist);
  2187. if (pointertype.def.deftype in [recorddef,objectdef]) then
  2188. begin
  2189. if pointertype.def.deftype=objectdef then
  2190. nb:=tobjectdef(pointertype.def).classnumberstring
  2191. else
  2192. nb:=tstoreddef(pointertype.def).numberstring;
  2193. {to avoid infinite recursion in record with next-like fields }
  2194. if tstoreddef(pointertype.def).stab_state=stab_state_writing then
  2195. begin
  2196. if assigned(pointertype.def.typesym) then
  2197. begin
  2198. if assigned(typesym) then
  2199. st := ttypesym(typesym).name
  2200. else
  2201. st := ' ';
  2202. asmlist.concat(Tai_stabs.create(stabstr_evaluate(
  2203. '"$1:t${numberstring}=*$2=xs$3:",${N_LSYM},0,0,0',
  2204. [st,nb,pointertype.def.typesym.name])));
  2205. end;
  2206. stab_state:=stab_state_written;
  2207. end
  2208. else
  2209. begin
  2210. stab_state:=stab_state_used;
  2211. inherited concatstabto(asmlist);
  2212. end;
  2213. end
  2214. else
  2215. begin
  2216. stab_state:=stab_state_used;
  2217. inherited concatstabto(asmlist);
  2218. end;
  2219. end;
  2220. {$endif GDB}
  2221. function tpointerdef.gettypename : string;
  2222. begin
  2223. if is_far then
  2224. gettypename:='^'+pointertype.def.typename+';far'
  2225. else
  2226. gettypename:='^'+pointertype.def.typename;
  2227. end;
  2228. {****************************************************************************
  2229. TCLASSREFDEF
  2230. ****************************************************************************}
  2231. constructor tclassrefdef.create(const t:ttype);
  2232. begin
  2233. inherited create(t);
  2234. deftype:=classrefdef;
  2235. end;
  2236. constructor tclassrefdef.ppuload(ppufile:tcompilerppufile);
  2237. begin
  2238. { be careful, tclassdefref inherits from tpointerdef }
  2239. inherited ppuloaddef(ppufile);
  2240. deftype:=classrefdef;
  2241. ppufile.gettype(pointertype);
  2242. is_far:=false;
  2243. savesize:=sizeof(aint);
  2244. end;
  2245. procedure tclassrefdef.ppuwrite(ppufile:tcompilerppufile);
  2246. begin
  2247. { be careful, tclassdefref inherits from tpointerdef }
  2248. inherited ppuwritedef(ppufile);
  2249. ppufile.puttype(pointertype);
  2250. ppufile.writeentry(ibclassrefdef);
  2251. end;
  2252. {$ifdef GDB}
  2253. function tclassrefdef.stabstring : pchar;
  2254. begin
  2255. stabstring:=strpnew(tstoreddef(pvmttype.def).numberstring);
  2256. end;
  2257. {$endif GDB}
  2258. function tclassrefdef.gettypename : string;
  2259. begin
  2260. gettypename:='Class Of '+pointertype.def.typename;
  2261. end;
  2262. {***************************************************************************
  2263. TSETDEF
  2264. ***************************************************************************}
  2265. constructor tsetdef.create(const t:ttype;high : longint);
  2266. begin
  2267. inherited create;
  2268. deftype:=setdef;
  2269. elementtype:=t;
  2270. if high<32 then
  2271. begin
  2272. settype:=smallset;
  2273. {$ifdef testvarsets}
  2274. if aktsetalloc=0 THEN { $PACKSET Fixed?}
  2275. {$endif}
  2276. savesize:=Sizeof(longint)
  2277. {$ifdef testvarsets}
  2278. else {No, use $PACKSET VALUE for rounding}
  2279. savesize:=aktsetalloc*((high+aktsetalloc*8-1) DIV (aktsetalloc*8))
  2280. {$endif}
  2281. ;
  2282. end
  2283. else
  2284. if high<256 then
  2285. begin
  2286. settype:=normset;
  2287. savesize:=32;
  2288. end
  2289. else
  2290. {$ifdef testvarsets}
  2291. if high<$10000 then
  2292. begin
  2293. settype:=varset;
  2294. savesize:=4*((high+31) div 32);
  2295. end
  2296. else
  2297. {$endif testvarsets}
  2298. Message(sym_e_ill_type_decl_set);
  2299. end;
  2300. constructor tsetdef.ppuload(ppufile:tcompilerppufile);
  2301. begin
  2302. inherited ppuloaddef(ppufile);
  2303. deftype:=setdef;
  2304. ppufile.gettype(elementtype);
  2305. settype:=tsettype(ppufile.getbyte);
  2306. case settype of
  2307. normset : savesize:=32;
  2308. varset : savesize:=ppufile.getlongint;
  2309. smallset : savesize:=Sizeof(longint);
  2310. end;
  2311. end;
  2312. destructor tsetdef.destroy;
  2313. begin
  2314. inherited destroy;
  2315. end;
  2316. procedure tsetdef.ppuwrite(ppufile:tcompilerppufile);
  2317. begin
  2318. inherited ppuwritedef(ppufile);
  2319. ppufile.puttype(elementtype);
  2320. ppufile.putbyte(byte(settype));
  2321. if settype=varset then
  2322. ppufile.putlongint(savesize);
  2323. ppufile.writeentry(ibsetdef);
  2324. end;
  2325. {$ifdef GDB}
  2326. function tsetdef.stabstring : pchar;
  2327. begin
  2328. stabstring:=stabstr_evaluate('@s$1;S$2',[tostr(savesize*8),tstoreddef(elementtype.def).numberstring]);
  2329. end;
  2330. procedure tsetdef.concatstabto(asmlist:taasmoutput);
  2331. begin
  2332. if (stab_state in [stab_state_writing,stab_state_written]) then
  2333. exit;
  2334. tstoreddef(elementtype.def).concatstabto(asmlist);
  2335. inherited concatstabto(asmlist);
  2336. end;
  2337. {$endif GDB}
  2338. procedure tsetdef.buildderef;
  2339. begin
  2340. inherited buildderef;
  2341. elementtype.buildderef;
  2342. end;
  2343. procedure tsetdef.deref;
  2344. begin
  2345. inherited deref;
  2346. elementtype.resolve;
  2347. end;
  2348. procedure tsetdef.write_child_rtti_data(rt:trttitype);
  2349. begin
  2350. tstoreddef(elementtype.def).get_rtti_label(rt);
  2351. end;
  2352. procedure tsetdef.write_rtti_data(rt:trttitype);
  2353. begin
  2354. rttiList.concat(Tai_const.Create_8bit(tkSet));
  2355. write_rtti_name;
  2356. rttiList.concat(Tai_const.Create_8bit(otULong));
  2357. rttiList.concat(Tai_const.Create_sym(tstoreddef(elementtype.def).get_rtti_label(rt)));
  2358. end;
  2359. function tsetdef.is_publishable : boolean;
  2360. begin
  2361. is_publishable:=(settype=smallset);
  2362. end;
  2363. function tsetdef.gettypename : string;
  2364. begin
  2365. if assigned(elementtype.def) then
  2366. gettypename:='Set Of '+elementtype.def.typename
  2367. else
  2368. gettypename:='Empty Set';
  2369. end;
  2370. {***************************************************************************
  2371. TFORMALDEF
  2372. ***************************************************************************}
  2373. constructor tformaldef.create;
  2374. var
  2375. stregdef : boolean;
  2376. begin
  2377. stregdef:=registerdef;
  2378. registerdef:=false;
  2379. inherited create;
  2380. deftype:=formaldef;
  2381. registerdef:=stregdef;
  2382. { formaldef must be registered at unit level !! }
  2383. if registerdef and assigned(current_module) then
  2384. if assigned(current_module.localsymtable) then
  2385. tsymtable(current_module.localsymtable).registerdef(self)
  2386. else if assigned(current_module.globalsymtable) then
  2387. tsymtable(current_module.globalsymtable).registerdef(self);
  2388. savesize:=0;
  2389. end;
  2390. constructor tformaldef.ppuload(ppufile:tcompilerppufile);
  2391. begin
  2392. inherited ppuloaddef(ppufile);
  2393. deftype:=formaldef;
  2394. savesize:=0;
  2395. end;
  2396. procedure tformaldef.ppuwrite(ppufile:tcompilerppufile);
  2397. begin
  2398. inherited ppuwritedef(ppufile);
  2399. ppufile.writeentry(ibformaldef);
  2400. end;
  2401. {$ifdef GDB}
  2402. function tformaldef.stabstring : pchar;
  2403. begin
  2404. stabstring:=stabstr_evaluate('formal${numberstring};',[]);
  2405. end;
  2406. function tformaldef.numberstring:string;
  2407. begin
  2408. result:=tstoreddef(voidtype.def).numberstring;
  2409. end;
  2410. procedure tformaldef.concatstabto(asmlist : taasmoutput);
  2411. begin
  2412. { formaldef can't be stab'ed !}
  2413. end;
  2414. {$endif GDB}
  2415. function tformaldef.gettypename : string;
  2416. begin
  2417. gettypename:='<Formal type>';
  2418. end;
  2419. {***************************************************************************
  2420. TARRAYDEF
  2421. ***************************************************************************}
  2422. constructor tarraydef.create(l,h : longint;const t : ttype);
  2423. begin
  2424. inherited create;
  2425. deftype:=arraydef;
  2426. lowrange:=l;
  2427. highrange:=h;
  2428. rangetype:=t;
  2429. elementtype.reset;
  2430. IsVariant:=false;
  2431. IsConstructor:=false;
  2432. IsArrayOfConst:=false;
  2433. IsDynamicArray:=false;
  2434. IsConvertedPointer:=false;
  2435. end;
  2436. constructor tarraydef.create_from_pointer(const elemt : ttype);
  2437. begin
  2438. self.create(0,$7fffffff,s32inttype);
  2439. IsConvertedPointer:=true;
  2440. setelementtype(elemt);
  2441. end;
  2442. constructor tarraydef.ppuload(ppufile:tcompilerppufile);
  2443. begin
  2444. inherited ppuloaddef(ppufile);
  2445. deftype:=arraydef;
  2446. { the addresses are calculated later }
  2447. ppufile.gettype(_elementtype);
  2448. ppufile.gettype(rangetype);
  2449. lowrange:=ppufile.getlongint;
  2450. highrange:=ppufile.getlongint;
  2451. IsArrayOfConst:=boolean(ppufile.getbyte);
  2452. IsDynamicArray:=boolean(ppufile.getbyte);
  2453. IsVariant:=false;
  2454. IsConstructor:=false;
  2455. end;
  2456. procedure tarraydef.buildderef;
  2457. begin
  2458. inherited buildderef;
  2459. _elementtype.buildderef;
  2460. rangetype.buildderef;
  2461. end;
  2462. procedure tarraydef.deref;
  2463. begin
  2464. inherited deref;
  2465. _elementtype.resolve;
  2466. rangetype.resolve;
  2467. end;
  2468. procedure tarraydef.ppuwrite(ppufile:tcompilerppufile);
  2469. begin
  2470. inherited ppuwritedef(ppufile);
  2471. ppufile.puttype(_elementtype);
  2472. ppufile.puttype(rangetype);
  2473. ppufile.putlongint(lowrange);
  2474. ppufile.putlongint(highrange);
  2475. ppufile.putbyte(byte(IsArrayOfConst));
  2476. ppufile.putbyte(byte(IsDynamicArray));
  2477. ppufile.writeentry(ibarraydef);
  2478. end;
  2479. {$ifdef GDB}
  2480. function tarraydef.stabstring : pchar;
  2481. begin
  2482. stabstring:=stabstr_evaluate('ar$1;$2;$3;$4',[Tstoreddef(rangetype.def).numberstring,
  2483. tostr(lowrange),tostr(highrange),Tstoreddef(_elementtype.def).numberstring]);
  2484. end;
  2485. procedure tarraydef.concatstabto(asmlist:taasmoutput);
  2486. begin
  2487. if (stab_state in [stab_state_writing,stab_state_written]) then
  2488. exit;
  2489. tstoreddef(rangetype.def).concatstabto(asmlist);
  2490. tstoreddef(_elementtype.def).concatstabto(asmlist);
  2491. inherited concatstabto(asmlist);
  2492. end;
  2493. {$endif GDB}
  2494. function tarraydef.elesize : longint;
  2495. begin
  2496. elesize:=_elementtype.def.size;
  2497. end;
  2498. function tarraydef.size : longint;
  2499. var
  2500. newsize : TConstExprInt;
  2501. begin
  2502. if IsDynamicArray then
  2503. begin
  2504. size:=sizeof(aint);
  2505. exit;
  2506. end;
  2507. {Tarraydef.size may never be called for an open array!}
  2508. if highrange<lowrange then
  2509. internalerror(99080501);
  2510. newsize:=(int64(highrange)-int64(lowrange)+1)*elesize;
  2511. { prevent an overflow }
  2512. if newsize>high(longint) then
  2513. result:=high(longint)
  2514. else
  2515. result:=newsize;
  2516. end;
  2517. procedure tarraydef.setelementtype(t: ttype);
  2518. var
  2519. cachedsize : TConstExprInt;
  2520. begin
  2521. _elementtype:=t;
  2522. if not(IsDynamicArray or
  2523. IsConvertedPointer or
  2524. (highrange<lowrange)) then
  2525. begin
  2526. { cache element size for performance on multidimensional arrays }
  2527. cachedsize := elesize;
  2528. if (cachedsize>0) and
  2529. (
  2530. {$ifdef cpu64bit}
  2531. {$ifdef VER1_0}
  2532. { 1.0.x can't handle this and while bootstrapping with 1.0.x we can forget about it }
  2533. false
  2534. {$else}
  2535. (TConstExprInt(highrange)-TConstExprInt(lowrange) > $7fffffffffffffff) or
  2536. { () are needed around cachedsize-1 to avoid a possible
  2537. integer overflow for cachedsize=1 !! PM }
  2538. (($7fffffffffffffff div cachedsize + (cachedsize -1)) < (int64(highrange) - int64(lowrange)))
  2539. {$endif VER1_0}
  2540. {$else cpu64bit}
  2541. (TConstExprInt(highrange)-TConstExprInt(lowrange) > $7fffffff) or
  2542. { () are needed around cachedsize-1 to avoid a possible
  2543. integer overflow for cachedsize=1 !! PM }
  2544. (($7fffffff div cachedsize + (cachedsize -1)) < (int64(highrange) - int64(lowrange)))
  2545. {$endif cpu64bit}
  2546. ) Then
  2547. Message(sym_e_segment_too_large);
  2548. end;
  2549. end;
  2550. function tarraydef.alignment : longint;
  2551. begin
  2552. { alignment is the size of the elements }
  2553. if elementtype.def.deftype=recorddef then
  2554. alignment:=elementtype.def.alignment
  2555. else
  2556. alignment:=elesize;
  2557. end;
  2558. function tarraydef.needs_inittable : boolean;
  2559. begin
  2560. needs_inittable:=IsDynamicArray or elementtype.def.needs_inittable;
  2561. end;
  2562. procedure tarraydef.write_child_rtti_data(rt:trttitype);
  2563. begin
  2564. tstoreddef(elementtype.def).get_rtti_label(rt);
  2565. end;
  2566. procedure tarraydef.write_rtti_data(rt:trttitype);
  2567. begin
  2568. if IsDynamicArray then
  2569. rttiList.concat(Tai_const.Create_8bit(tkdynarray))
  2570. else
  2571. rttiList.concat(Tai_const.Create_8bit(tkarray));
  2572. write_rtti_name;
  2573. { size of elements }
  2574. rttiList.concat(Tai_const.Create_32bit(elesize));
  2575. { count of elements, prevent overflow for 0..maxlongint }
  2576. if not(IsDynamicArray) then
  2577. rttiList.concat(Tai_const.Create_32bit(min(int64(highrange)-lowrange+1,maxlongint)));
  2578. { element type }
  2579. rttiList.concat(Tai_const.Create_sym(tstoreddef(elementtype.def).get_rtti_label(rt)));
  2580. { variant type }
  2581. // !!!!!!!!!!!!!!!!
  2582. end;
  2583. function tarraydef.gettypename : string;
  2584. begin
  2585. if isarrayofconst or isConstructor then
  2586. begin
  2587. if isvariant or ((highrange=-1) and (lowrange=0)) then
  2588. gettypename:='Array Of Const'
  2589. else
  2590. gettypename:='Array Of '+elementtype.def.typename;
  2591. end
  2592. else if ((highrange=-1) and (lowrange=0)) or IsDynamicArray then
  2593. gettypename:='Array Of '+elementtype.def.typename
  2594. else
  2595. begin
  2596. if rangetype.def.deftype=enumdef then
  2597. gettypename:='Array['+rangetype.def.typename+'] Of '+elementtype.def.typename
  2598. else
  2599. gettypename:='Array['+tostr(lowrange)+'..'+
  2600. tostr(highrange)+'] Of '+elementtype.def.typename
  2601. end;
  2602. end;
  2603. function tarraydef.getmangledparaname : string;
  2604. begin
  2605. if isarrayofconst then
  2606. getmangledparaname:='array_of_const'
  2607. else
  2608. if ((highrange=-1) and (lowrange=0)) then
  2609. getmangledparaname:='array_of_'+elementtype.def.mangledparaname
  2610. else
  2611. internalerror(200204176);
  2612. end;
  2613. {***************************************************************************
  2614. tabstractrecorddef
  2615. ***************************************************************************}
  2616. function tabstractrecorddef.getsymtable(t:tgetsymtable):tsymtable;
  2617. begin
  2618. if t=gs_record then
  2619. getsymtable:=symtable
  2620. else
  2621. getsymtable:=nil;
  2622. end;
  2623. {$ifdef GDB}
  2624. procedure tabstractrecorddef.field_addname(p:Tnamedindexitem;arg:pointer);
  2625. var
  2626. newrec:Pchar;
  2627. spec:string[3];
  2628. varsize:longint;
  2629. state:^Trecord_stabgen_state;
  2630. begin
  2631. state:=arg;
  2632. { static variables from objects are like global objects }
  2633. if (Tsym(p).typ=varsym) and not (sp_static in Tsym(p).symoptions) then
  2634. begin
  2635. if (sp_protected in tsym(p).symoptions) then
  2636. spec:='/1'
  2637. else if (sp_private in tsym(p).symoptions) then
  2638. spec:='/0'
  2639. else
  2640. spec:='';
  2641. varsize:=tvarsym(p).vartype.def.size;
  2642. { open arrays made overflows !! }
  2643. if varsize>$fffffff then
  2644. varsize:=$fffffff;
  2645. newrec:=stabstr_evaluate('$1:$2,$3,$4;',[p.name,
  2646. spec+tstoreddef(tvarsym(p).vartype.def).numberstring,
  2647. tostr(tvarsym(p).fieldoffset*8),tostr(varsize*8)]);
  2648. if state^.stabsize+strlen(newrec)>=state^.staballoc-256 then
  2649. begin
  2650. inc(state^.staballoc,memsizeinc);
  2651. reallocmem(state^.stabstring,state^.staballoc);
  2652. end;
  2653. strcopy(state^.stabstring+state^.stabsize,newrec);
  2654. inc(state^.stabsize,strlen(newrec));
  2655. strdispose(newrec);
  2656. {This should be used for case !!}
  2657. inc(state^.recoffset,Tvarsym(p).vartype.def.size);
  2658. end;
  2659. end;
  2660. procedure tabstractrecorddef.field_concatstabto(p:Tnamedindexitem;arg:pointer);
  2661. begin
  2662. if (Tsym(p).typ=varsym) and not (sp_static in Tsym(p).symoptions) then
  2663. tstoreddef(tvarsym(p).vartype.def).concatstabto(taasmoutput(arg));
  2664. end;
  2665. {$endif GDB}
  2666. procedure tabstractrecorddef.count_field_rtti(sym : tnamedindexitem;arg:pointer);
  2667. begin
  2668. if (FRTTIType=fullrtti) or
  2669. ((tsym(sym).typ=varsym) and
  2670. tvarsym(sym).vartype.def.needs_inittable) then
  2671. inc(Count);
  2672. end;
  2673. procedure tabstractrecorddef.generate_field_rtti(sym:tnamedindexitem;arg:pointer);
  2674. begin
  2675. if (FRTTIType=fullrtti) or
  2676. ((tsym(sym).typ=varsym) and
  2677. tvarsym(sym).vartype.def.needs_inittable) then
  2678. tstoreddef(tvarsym(sym).vartype.def).get_rtti_label(FRTTIType);
  2679. end;
  2680. procedure tabstractrecorddef.write_field_rtti(sym : tnamedindexitem;arg:pointer);
  2681. begin
  2682. if (FRTTIType=fullrtti) or
  2683. ((tsym(sym).typ=varsym) and
  2684. tvarsym(sym).vartype.def.needs_inittable) then
  2685. begin
  2686. rttiList.concat(Tai_const.Create_sym(tstoreddef(tvarsym(sym).vartype.def).get_rtti_label(FRTTIType)));
  2687. rttiList.concat(Tai_const.Create_32bit(tvarsym(sym).fieldoffset));
  2688. end;
  2689. end;
  2690. {***************************************************************************
  2691. trecorddef
  2692. ***************************************************************************}
  2693. constructor trecorddef.create(p : tsymtable);
  2694. begin
  2695. inherited create;
  2696. deftype:=recorddef;
  2697. symtable:=p;
  2698. symtable.defowner:=self;
  2699. isunion:=false;
  2700. end;
  2701. constructor trecorddef.ppuload(ppufile:tcompilerppufile);
  2702. begin
  2703. inherited ppuloaddef(ppufile);
  2704. deftype:=recorddef;
  2705. symtable:=trecordsymtable.create(0);
  2706. trecordsymtable(symtable).datasize:=ppufile.getlongint;
  2707. trecordsymtable(symtable).fieldalignment:=shortint(ppufile.getbyte);
  2708. trecordsymtable(symtable).recordalignment:=shortint(ppufile.getbyte);
  2709. trecordsymtable(symtable).padalignment:=shortint(ppufile.getbyte);
  2710. trecordsymtable(symtable).ppuload(ppufile);
  2711. symtable.defowner:=self;
  2712. isunion:=false;
  2713. end;
  2714. destructor trecorddef.destroy;
  2715. begin
  2716. if assigned(symtable) then
  2717. symtable.free;
  2718. inherited destroy;
  2719. end;
  2720. function trecorddef.needs_inittable : boolean;
  2721. begin
  2722. needs_inittable:=trecordsymtable(symtable).needs_init_final
  2723. end;
  2724. procedure trecorddef.buildderef;
  2725. var
  2726. oldrecsyms : tsymtable;
  2727. begin
  2728. inherited buildderef;
  2729. oldrecsyms:=aktrecordsymtable;
  2730. aktrecordsymtable:=symtable;
  2731. { now build the definitions }
  2732. tstoredsymtable(symtable).buildderef;
  2733. aktrecordsymtable:=oldrecsyms;
  2734. end;
  2735. procedure trecorddef.deref;
  2736. var
  2737. oldrecsyms : tsymtable;
  2738. begin
  2739. inherited deref;
  2740. oldrecsyms:=aktrecordsymtable;
  2741. aktrecordsymtable:=symtable;
  2742. { now dereference the definitions }
  2743. tstoredsymtable(symtable).deref;
  2744. aktrecordsymtable:=oldrecsyms;
  2745. { assign TGUID? load only from system unit (unitid=1) }
  2746. if not(assigned(rec_tguid)) and
  2747. (upper(typename)='TGUID') and
  2748. assigned(owner) and
  2749. assigned(owner.name) and
  2750. (owner.name^='SYSTEM') then
  2751. rec_tguid:=self;
  2752. end;
  2753. procedure trecorddef.ppuwrite(ppufile:tcompilerppufile);
  2754. begin
  2755. inherited ppuwritedef(ppufile);
  2756. ppufile.putlongint(trecordsymtable(symtable).datasize);
  2757. ppufile.putbyte(byte(trecordsymtable(symtable).fieldalignment));
  2758. ppufile.putbyte(byte(trecordsymtable(symtable).recordalignment));
  2759. ppufile.putbyte(byte(trecordsymtable(symtable).padalignment));
  2760. ppufile.writeentry(ibrecorddef);
  2761. trecordsymtable(symtable).ppuwrite(ppufile);
  2762. end;
  2763. function trecorddef.size:longint;
  2764. begin
  2765. result:=trecordsymtable(symtable).datasize;
  2766. end;
  2767. function trecorddef.alignment:longint;
  2768. begin
  2769. alignment:=trecordsymtable(symtable).recordalignment;
  2770. end;
  2771. function trecorddef.padalignment:longint;
  2772. begin
  2773. padalignment := trecordsymtable(symtable).padalignment;
  2774. end;
  2775. {$ifdef GDB}
  2776. function trecorddef.stabstring : pchar;
  2777. var
  2778. state:Trecord_stabgen_state;
  2779. begin
  2780. getmem(state.stabstring,memsizeinc);
  2781. state.staballoc:=memsizeinc;
  2782. strpcopy(state.stabstring,'s'+tostr(size));
  2783. state.recoffset:=0;
  2784. state.stabsize:=strlen(state.stabstring);
  2785. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}field_addname,@state);
  2786. state.stabstring[state.stabsize]:=';';
  2787. state.stabstring[state.stabsize+1]:=#0;
  2788. reallocmem(state.stabstring,state.stabsize+2);
  2789. stabstring:=state.stabstring;
  2790. end;
  2791. procedure trecorddef.concatstabto(asmlist:taasmoutput);
  2792. begin
  2793. if (stab_state in [stab_state_writing,stab_state_written]) then
  2794. exit;
  2795. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}field_concatstabto,asmlist);
  2796. inherited concatstabto(asmlist);
  2797. end;
  2798. {$endif GDB}
  2799. procedure trecorddef.write_child_rtti_data(rt:trttitype);
  2800. begin
  2801. FRTTIType:=rt;
  2802. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}generate_field_rtti,nil);
  2803. end;
  2804. procedure trecorddef.write_rtti_data(rt:trttitype);
  2805. begin
  2806. rttiList.concat(Tai_const.Create_8bit(tkrecord));
  2807. write_rtti_name;
  2808. rttiList.concat(Tai_const.Create_32bit(size));
  2809. Count:=0;
  2810. FRTTIType:=rt;
  2811. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}count_field_rtti,nil);
  2812. rttiList.concat(Tai_const.Create_32bit(Count));
  2813. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}write_field_rtti,nil);
  2814. end;
  2815. function trecorddef.gettypename : string;
  2816. begin
  2817. gettypename:='<record type>'
  2818. end;
  2819. {***************************************************************************
  2820. TABSTRACTPROCDEF
  2821. ***************************************************************************}
  2822. constructor tabstractprocdef.create(level:byte);
  2823. begin
  2824. inherited create;
  2825. parast:=tparasymtable.create(level);
  2826. parast.defowner:=self;
  2827. parast.next:=owner;
  2828. para:=TLinkedList.Create;
  2829. minparacount:=0;
  2830. maxparacount:=0;
  2831. proctypeoption:=potype_none;
  2832. proccalloption:=pocall_none;
  2833. procoptions:=[];
  2834. rettype:=voidtype;
  2835. {$ifdef i386}
  2836. fpu_used:=0;
  2837. {$endif i386}
  2838. savesize:=sizeof(aint);
  2839. requiredargarea:=0;
  2840. has_paraloc_info:=false;
  2841. end;
  2842. destructor tabstractprocdef.destroy;
  2843. begin
  2844. if assigned(para) then
  2845. begin
  2846. {$ifdef MEMDEBUG}
  2847. memprocpara.start;
  2848. {$endif MEMDEBUG}
  2849. para.free;
  2850. {$ifdef MEMDEBUG}
  2851. memprocpara.stop;
  2852. {$endif MEMDEBUG}
  2853. end;
  2854. if assigned(parast) then
  2855. begin
  2856. {$ifdef MEMDEBUG}
  2857. memprocparast.start;
  2858. {$endif MEMDEBUG}
  2859. parast.free;
  2860. {$ifdef MEMDEBUG}
  2861. memprocparast.stop;
  2862. {$endif MEMDEBUG}
  2863. end;
  2864. inherited destroy;
  2865. end;
  2866. procedure tabstractprocdef.releasemem;
  2867. begin
  2868. para.free;
  2869. para:=nil;
  2870. parast.free;
  2871. parast:=nil;
  2872. end;
  2873. function tabstractprocdef.concatpara(afterpara:tparaitem;const tt:ttype;sym : tsym;defval:tsym;vhidden:boolean):tparaitem;
  2874. var
  2875. hp : TParaItem;
  2876. begin
  2877. hp:=TParaItem.Create;
  2878. hp.paratyp:=tvarsym(sym).varspez;
  2879. hp.parasym:=sym;
  2880. hp.paratype:=tt;
  2881. hp.is_hidden:=vhidden;
  2882. hp.defaultvalue:=defval;
  2883. { Parameters are stored from left to right }
  2884. if assigned(afterpara) then
  2885. Para.insertafter(hp,afterpara)
  2886. else
  2887. Para.concat(hp);
  2888. { Don't count hidden parameters }
  2889. if not vhidden then
  2890. begin
  2891. if not assigned(defval) then
  2892. inc(minparacount);
  2893. inc(maxparacount);
  2894. end;
  2895. concatpara:=hp;
  2896. end;
  2897. function tabstractprocdef.insertpara(const tt:ttype;sym : tsym;defval:tsym;vhidden:boolean):tparaitem;
  2898. var
  2899. hp : TParaItem;
  2900. begin
  2901. hp:=TParaItem.Create;
  2902. hp.paratyp:=tvarsym(sym).varspez;
  2903. hp.parasym:=sym;
  2904. hp.paratype:=tt;
  2905. hp.is_hidden:=vhidden;
  2906. hp.defaultvalue:=defval;
  2907. { Parameters are stored from left to right }
  2908. Para.insert(hp);
  2909. { Don't count hidden parameters }
  2910. if (not vhidden) then
  2911. begin
  2912. if not assigned(defval) then
  2913. inc(minparacount);
  2914. inc(maxparacount);
  2915. end;
  2916. insertpara:=hp;
  2917. end;
  2918. procedure tabstractprocdef.removepara(currpara:tparaitem);
  2919. begin
  2920. { Don't count hidden parameters }
  2921. if (not currpara.is_hidden) then
  2922. begin
  2923. if not assigned(currpara.defaultvalue) then
  2924. dec(minparacount);
  2925. dec(maxparacount);
  2926. end;
  2927. Para.Remove(currpara);
  2928. currpara.free;
  2929. end;
  2930. { all functions returning in FPU are
  2931. assume to use 2 FPU registers
  2932. until the function implementation
  2933. is processed PM }
  2934. procedure tabstractprocdef.test_if_fpu_result;
  2935. begin
  2936. {$ifdef i386}
  2937. if assigned(rettype.def) and
  2938. (rettype.def.deftype=floatdef) then
  2939. fpu_used:=maxfpuregs;
  2940. {$endif i386}
  2941. end;
  2942. procedure tabstractprocdef.buildderef;
  2943. var
  2944. hp : TParaItem;
  2945. begin
  2946. { released procdef? }
  2947. if not assigned(parast) then
  2948. exit;
  2949. inherited buildderef;
  2950. rettype.buildderef;
  2951. { parast }
  2952. tparasymtable(parast).buildderef;
  2953. { paraitems }
  2954. hp:=TParaItem(Para.first);
  2955. while assigned(hp) do
  2956. begin
  2957. hp.paratype.buildderef;
  2958. hp.defaultvaluederef.build(hp.defaultvalue);
  2959. hp.parasymderef.build(hp.parasym);
  2960. hp:=TParaItem(hp.next);
  2961. end;
  2962. end;
  2963. procedure tabstractprocdef.deref;
  2964. var
  2965. hp : TParaItem;
  2966. begin
  2967. inherited deref;
  2968. rettype.resolve;
  2969. { parast }
  2970. tparasymtable(parast).deref;
  2971. { paraitems }
  2972. minparacount:=0;
  2973. maxparacount:=0;
  2974. hp:=TParaItem(Para.first);
  2975. while assigned(hp) do
  2976. begin
  2977. hp.paratype.resolve;
  2978. hp.defaultvalue:=tsym(hp.defaultvaluederef.resolve);
  2979. hp.parasym:=tvarsym(hp.parasymderef.resolve);
  2980. { connect parasym to paraitem }
  2981. tvarsym(hp.parasym).paraitem:=hp;
  2982. { Don't count hidden parameters }
  2983. if (not hp.is_hidden) then
  2984. begin
  2985. if not assigned(hp.defaultvalue) then
  2986. inc(minparacount);
  2987. inc(maxparacount);
  2988. end;
  2989. hp:=TParaItem(hp.next);
  2990. end;
  2991. end;
  2992. constructor tabstractprocdef.ppuload(ppufile:tcompilerppufile);
  2993. var
  2994. hp : TParaItem;
  2995. count,i : word;
  2996. begin
  2997. inherited ppuloaddef(ppufile);
  2998. parast:=nil;
  2999. Para:=TLinkedList.Create;
  3000. minparacount:=0;
  3001. maxparacount:=0;
  3002. ppufile.gettype(rettype);
  3003. {$ifdef i386}
  3004. fpu_used:=ppufile.getbyte;
  3005. {$else}
  3006. ppufile.getbyte;
  3007. {$endif i386}
  3008. proctypeoption:=tproctypeoption(ppufile.getbyte);
  3009. proccalloption:=tproccalloption(ppufile.getbyte);
  3010. ppufile.getsmallset(procoptions);
  3011. if po_explicitparaloc in procoptions then
  3012. ppufile.getdata(funcret_paraloc,sizeof(funcret_paraloc));
  3013. { get the number of parameters }
  3014. count:=ppufile.getbyte;
  3015. savesize:=sizeof(aint);
  3016. has_paraloc_info:=false;
  3017. for i:=1 to count do
  3018. begin
  3019. hp:=TParaItem.Create;
  3020. hp.paratyp:=tvarspez(ppufile.getbyte);
  3021. ppufile.gettype(hp.paratype);
  3022. ppufile.getderef(hp.defaultvaluederef);
  3023. hp.defaultvalue:=nil;
  3024. ppufile.getderef(hp.parasymderef);
  3025. hp.parasym:=nil;
  3026. hp.is_hidden:=boolean(ppufile.getbyte);
  3027. if po_explicitparaloc in procoptions then
  3028. begin
  3029. ppufile.getdata(hp.paraloc,sizeof(hp.paraloc));
  3030. has_paraloc_info:=true;
  3031. end;
  3032. { Parameters are stored left to right in both ppu and memory }
  3033. Para.concat(hp);
  3034. end;
  3035. end;
  3036. procedure tabstractprocdef.ppuwrite(ppufile:tcompilerppufile);
  3037. var
  3038. hp : TParaItem;
  3039. oldintfcrc : boolean;
  3040. begin
  3041. { released procdef? }
  3042. if not assigned(parast) then
  3043. exit;
  3044. inherited ppuwritedef(ppufile);
  3045. ppufile.puttype(rettype);
  3046. oldintfcrc:=ppufile.do_interface_crc;
  3047. ppufile.do_interface_crc:=false;
  3048. {$ifdef i386}
  3049. if simplify_ppu then
  3050. fpu_used:=0;
  3051. ppufile.putbyte(fpu_used);
  3052. {$else}
  3053. ppufile.putbyte(0);
  3054. {$endif}
  3055. ppufile.putbyte(ord(proctypeoption));
  3056. ppufile.putbyte(ord(proccalloption));
  3057. ppufile.putsmallset(procoptions);
  3058. ppufile.do_interface_crc:=oldintfcrc;
  3059. if po_explicitparaloc in procoptions then
  3060. ppufile.putdata(funcret_paraloc,sizeof(funcret_paraloc));
  3061. { we need to store the count including vs_hidden }
  3062. ppufile.putbyte(para.count);
  3063. hp:=TParaItem(Para.first);
  3064. while assigned(hp) do
  3065. begin
  3066. ppufile.putbyte(byte(hp.paratyp));
  3067. ppufile.puttype(hp.paratype);
  3068. ppufile.putderef(hp.defaultvaluederef);
  3069. ppufile.putderef(hp.parasymderef);
  3070. ppufile.putbyte(byte(hp.is_hidden));
  3071. if po_explicitparaloc in procoptions then
  3072. ppufile.putdata(hp.paraloc,sizeof(hp.paraloc));
  3073. hp:=TParaItem(hp.next);
  3074. end;
  3075. end;
  3076. function tabstractprocdef.typename_paras(showhidden:boolean) : string;
  3077. var
  3078. hs,s : string;
  3079. hp : TParaItem;
  3080. hpc : tconstsym;
  3081. first : boolean;
  3082. begin
  3083. hp:=TParaItem(Para.first);
  3084. s:='';
  3085. first:=true;
  3086. while assigned(hp) do
  3087. begin
  3088. if (not hp.is_hidden) or
  3089. (showhidden) then
  3090. begin
  3091. if first then
  3092. begin
  3093. s:=s+'(';
  3094. first:=false;
  3095. end
  3096. else
  3097. s:=s+',';
  3098. case hp.paratyp of
  3099. vs_var :
  3100. s:=s+'var';
  3101. vs_const :
  3102. s:=s+'const';
  3103. vs_out :
  3104. s:=s+'out';
  3105. end;
  3106. if assigned(hp.paratype.def.typesym) then
  3107. begin
  3108. if s<>'(' then
  3109. s:=s+' ';
  3110. hs:=hp.paratype.def.typesym.realname;
  3111. if hs[1]<>'$' then
  3112. s:=s+hp.paratype.def.typesym.realname
  3113. else
  3114. s:=s+hp.paratype.def.gettypename;
  3115. end
  3116. else
  3117. s:=s+hp.paratype.def.gettypename;
  3118. { default value }
  3119. if assigned(hp.defaultvalue) then
  3120. begin
  3121. hpc:=tconstsym(hp.defaultvalue);
  3122. hs:='';
  3123. case hpc.consttyp of
  3124. conststring,
  3125. constresourcestring :
  3126. hs:=strpas(pchar(hpc.value.valueptr));
  3127. constreal :
  3128. str(pbestreal(hpc.value.valueptr)^,hs);
  3129. constpointer :
  3130. hs:=tostr(hpc.value.valueordptr);
  3131. constord :
  3132. begin
  3133. if is_boolean(hpc.consttype.def) then
  3134. begin
  3135. if hpc.value.valueord<>0 then
  3136. hs:='TRUE'
  3137. else
  3138. hs:='FALSE';
  3139. end
  3140. else
  3141. hs:=tostr(hpc.value.valueord);
  3142. end;
  3143. constnil :
  3144. hs:='nil';
  3145. constset :
  3146. hs:='<set>';
  3147. end;
  3148. if hs<>'' then
  3149. s:=s+'="'+hs+'"';
  3150. end;
  3151. end;
  3152. hp:=TParaItem(hp.next);
  3153. end;
  3154. if not first then
  3155. s:=s+')';
  3156. if (po_varargs in procoptions) then
  3157. s:=s+';VarArgs';
  3158. typename_paras:=s;
  3159. end;
  3160. function tabstractprocdef.is_methodpointer:boolean;
  3161. begin
  3162. result:=false;
  3163. end;
  3164. function tabstractprocdef.is_addressonly:boolean;
  3165. begin
  3166. result:=true;
  3167. end;
  3168. {$ifdef GDB}
  3169. function tabstractprocdef.stabstring : pchar;
  3170. begin
  3171. stabstring := strpnew('abstractproc'+numberstring+';');
  3172. end;
  3173. {$endif GDB}
  3174. {***************************************************************************
  3175. TPROCDEF
  3176. ***************************************************************************}
  3177. constructor tprocdef.create(level:byte);
  3178. begin
  3179. inherited create(level);
  3180. deftype:=procdef;
  3181. has_mangledname:=false;
  3182. _mangledname:=nil;
  3183. fileinfo:=aktfilepos;
  3184. extnumber:=$ffff;
  3185. aliasnames:=tstringlist.create;
  3186. funcretsym:=nil;
  3187. localst := nil;
  3188. defref:=nil;
  3189. lastwritten:=nil;
  3190. refcount:=0;
  3191. if (cs_browser in aktmoduleswitches) and make_ref then
  3192. begin
  3193. defref:=tref.create(defref,@akttokenpos);
  3194. inc(refcount);
  3195. end;
  3196. lastref:=defref;
  3197. forwarddef:=true;
  3198. interfacedef:=false;
  3199. hasforward:=false;
  3200. _class := nil;
  3201. new(inlininginfo);
  3202. fillchar(inlininginfo^,sizeof(tinlininginfo),0);
  3203. overloadnumber:=0;
  3204. {$ifdef GDB}
  3205. isstabwritten := false;
  3206. {$endif GDB}
  3207. end;
  3208. constructor tprocdef.ppuload(ppufile:tcompilerppufile);
  3209. var
  3210. level : byte;
  3211. begin
  3212. inherited ppuload(ppufile);
  3213. deftype:=procdef;
  3214. has_mangledname:=boolean(ppufile.getbyte);
  3215. if has_mangledname then
  3216. _mangledname:=stringdup(ppufile.getstring)
  3217. else
  3218. _mangledname:=nil;
  3219. overloadnumber:=ppufile.getword;
  3220. extnumber:=ppufile.getword;
  3221. level:=ppufile.getbyte;
  3222. ppufile.getderef(_classderef);
  3223. ppufile.getderef(procsymderef);
  3224. ppufile.getposinfo(fileinfo);
  3225. ppufile.getsmallset(symoptions);
  3226. {$ifdef powerpc}
  3227. { library symbol for AmigaOS/MorphOS }
  3228. ppufile.getderef(libsymderef);
  3229. {$endif powerpc}
  3230. { inline stuff }
  3231. if proccalloption=pocall_inline then
  3232. begin
  3233. ppufile.getderef(funcretsymderef);
  3234. new(inlininginfo);
  3235. ppufile.getsmallset(inlininginfo^.flags);
  3236. inlininginfo^.inlinenode:=boolean(ppufile.getbyte);
  3237. end
  3238. else
  3239. funcretsym:=nil;
  3240. { load para symtable }
  3241. parast:=tparasymtable.create(level);
  3242. tparasymtable(parast).ppuload(ppufile);
  3243. parast.defowner:=self;
  3244. { load local symtable }
  3245. if ((proccalloption=pocall_inline) or
  3246. ((current_module.flags and uf_local_browser)<>0)) then
  3247. begin
  3248. localst:=tlocalsymtable.create(level);
  3249. tlocalsymtable(localst).ppuload(ppufile);
  3250. localst.defowner:=self;
  3251. end
  3252. else
  3253. localst:=nil;
  3254. { inline stuff }
  3255. if proccalloption=pocall_inline then
  3256. inlininginfo^.code:=ppuloadnodetree(ppufile)
  3257. else
  3258. inlininginfo := nil;
  3259. { default values for no persistent data }
  3260. if (cs_link_deffile in aktglobalswitches) and
  3261. (tf_need_export in target_info.flags) and
  3262. (po_exports in procoptions) then
  3263. deffile.AddExport(mangledname);
  3264. aliasnames:=tstringlist.create;
  3265. forwarddef:=false;
  3266. interfacedef:=false;
  3267. hasforward:=false;
  3268. lastref:=nil;
  3269. lastwritten:=nil;
  3270. defref:=nil;
  3271. refcount:=0;
  3272. {$ifdef GDB}
  3273. isstabwritten := false;
  3274. {$endif GDB}
  3275. end;
  3276. destructor tprocdef.destroy;
  3277. begin
  3278. if assigned(defref) then
  3279. begin
  3280. defref.freechain;
  3281. defref.free;
  3282. end;
  3283. aliasnames.free;
  3284. if assigned(localst) and (localst.symtabletype<>staticsymtable) then
  3285. begin
  3286. {$ifdef MEMDEBUG}
  3287. memproclocalst.start;
  3288. {$endif MEMDEBUG}
  3289. localst.free;
  3290. {$ifdef MEMDEBUG}
  3291. memproclocalst.start;
  3292. {$endif MEMDEBUG}
  3293. end;
  3294. if (proccalloption=pocall_inline) and assigned(inlininginfo) then
  3295. begin
  3296. {$ifdef MEMDEBUG}
  3297. memprocnodetree.start;
  3298. {$endif MEMDEBUG}
  3299. tnode(inlininginfo^.code).free;
  3300. {$ifdef MEMDEBUG}
  3301. memprocnodetree.start;
  3302. {$endif MEMDEBUG}
  3303. end;
  3304. if assigned(inlininginfo) then
  3305. dispose(inlininginfo);
  3306. if (po_msgstr in procoptions) then
  3307. strdispose(messageinf.str);
  3308. if assigned(_mangledname) then
  3309. begin
  3310. {$ifdef MEMDEBUG}
  3311. memmanglednames.start;
  3312. {$endif MEMDEBUG}
  3313. stringdispose(_mangledname);
  3314. {$ifdef MEMDEBUG}
  3315. memmanglednames.stop;
  3316. {$endif MEMDEBUG}
  3317. end;
  3318. inherited destroy;
  3319. end;
  3320. procedure tprocdef.ppuwrite(ppufile:tcompilerppufile);
  3321. var
  3322. oldintfcrc : boolean;
  3323. oldparasymtable,
  3324. oldlocalsymtable : tsymtable;
  3325. begin
  3326. { released procdef? }
  3327. if not assigned(parast) then
  3328. exit;
  3329. oldparasymtable:=aktparasymtable;
  3330. oldlocalsymtable:=aktlocalsymtable;
  3331. aktparasymtable:=parast;
  3332. aktlocalsymtable:=localst;
  3333. inherited ppuwrite(ppufile);
  3334. oldintfcrc:=ppufile.do_interface_crc;
  3335. ppufile.do_interface_crc:=false;
  3336. ppufile.do_interface_crc:=oldintfcrc;
  3337. ppufile.putbyte(byte(has_mangledname));
  3338. if has_mangledname then
  3339. ppufile.putstring(_mangledname^);
  3340. ppufile.putword(overloadnumber);
  3341. ppufile.putword(extnumber);
  3342. ppufile.putbyte(parast.symtablelevel);
  3343. ppufile.putderef(_classderef);
  3344. ppufile.putderef(procsymderef);
  3345. ppufile.putposinfo(fileinfo);
  3346. ppufile.putsmallset(symoptions);
  3347. {$ifdef powerpc}
  3348. { library symbol for AmigaOS/MorphOS }
  3349. ppufile.putderef(libsymderef);
  3350. {$endif powerpc}
  3351. { inline stuff }
  3352. oldintfcrc:=ppufile.do_crc;
  3353. ppufile.do_crc:=false;
  3354. if proccalloption=pocall_inline then
  3355. begin
  3356. ppufile.putderef(funcretsymderef);
  3357. ppufile.putsmallset(inlininginfo^.flags);
  3358. ppufile.putbyte(byte(inlininginfo^.inlinenode));
  3359. end;
  3360. ppufile.do_crc:=oldintfcrc;
  3361. { write this entry }
  3362. ppufile.writeentry(ibprocdef);
  3363. { Save the para symtable, this is taken from the interface }
  3364. tparasymtable(parast).ppuwrite(ppufile);
  3365. { save localsymtable for inline procedures or when local
  3366. browser info is requested, this has no influence on the crc }
  3367. if (proccalloption=pocall_inline) or
  3368. ((current_module.flags and uf_local_browser)<>0) then
  3369. begin
  3370. { we must write a localsymtable }
  3371. if not assigned(localst) then
  3372. insert_localst;
  3373. oldintfcrc:=ppufile.do_crc;
  3374. ppufile.do_crc:=false;
  3375. tlocalsymtable(localst).ppuwrite(ppufile);
  3376. ppufile.do_crc:=oldintfcrc;
  3377. end;
  3378. { node tree for inlining }
  3379. oldintfcrc:=ppufile.do_crc;
  3380. ppufile.do_crc:=false;
  3381. if proccalloption=pocall_inline then
  3382. ppuwritenodetree(ppufile,inlininginfo^.code);
  3383. ppufile.do_crc:=oldintfcrc;
  3384. aktparasymtable:=oldparasymtable;
  3385. aktlocalsymtable:=oldlocalsymtable;
  3386. end;
  3387. procedure tprocdef.insert_localst;
  3388. begin
  3389. localst:=tlocalsymtable.create(parast.symtablelevel);
  3390. localst.defowner:=self;
  3391. { this is used by insert
  3392. to check same names in parast and localst }
  3393. localst.next:=parast;
  3394. end;
  3395. function tprocdef.fullprocname(showhidden:boolean):string;
  3396. var
  3397. s : string;
  3398. t : ttoken;
  3399. begin
  3400. {$ifdef EXTDEBUG}
  3401. showhidden:=true;
  3402. {$endif EXTDEBUG}
  3403. s:='';
  3404. if assigned(_class) then
  3405. begin
  3406. if po_classmethod in procoptions then
  3407. s:=s+'class ';
  3408. s:=s+_class.objrealname^+'.';
  3409. end;
  3410. if proctypeoption=potype_operator then
  3411. begin
  3412. for t:=NOTOKEN to last_overloaded do
  3413. if procsym.realname='$'+overloaded_names[t] then
  3414. begin
  3415. s:='operator '+arraytokeninfo[t].str+typename_paras(showhidden);
  3416. break;
  3417. end;
  3418. end
  3419. else
  3420. s:=s+procsym.realname+typename_paras(showhidden);
  3421. case proctypeoption of
  3422. potype_constructor:
  3423. s:='constructor '+s;
  3424. potype_destructor:
  3425. s:='destructor '+s;
  3426. else
  3427. if assigned(rettype.def) and
  3428. not(is_void(rettype.def)) then
  3429. s:=s+':'+rettype.def.gettypename;
  3430. end;
  3431. { forced calling convention? }
  3432. if (po_hascallingconvention in procoptions) then
  3433. s:=s+';'+ProcCallOptionStr[proccalloption];
  3434. fullprocname:=s;
  3435. end;
  3436. function tprocdef.is_methodpointer:boolean;
  3437. begin
  3438. result:=assigned(_class);
  3439. end;
  3440. function tprocdef.is_addressonly:boolean;
  3441. begin
  3442. result:=assigned(owner) and
  3443. (owner.symtabletype<>objectsymtable);
  3444. end;
  3445. function tprocdef.is_visible_for_object(currobjdef:tobjectdef):boolean;
  3446. begin
  3447. is_visible_for_object:=false;
  3448. { private symbols are allowed when we are in the same
  3449. module as they are defined }
  3450. if (sp_private in symoptions) and
  3451. (owner.defowner.owner.symtabletype in [globalsymtable,staticsymtable]) and
  3452. (owner.defowner.owner.unitid<>0) then
  3453. exit;
  3454. { protected symbols are vissible in the module that defines them and
  3455. also visible to related objects. The related object must be defined
  3456. in the current module }
  3457. if (sp_protected in symoptions) and
  3458. (
  3459. (
  3460. (owner.defowner.owner.symtabletype in [globalsymtable,staticsymtable]) and
  3461. (owner.defowner.owner.unitid<>0)
  3462. ) and
  3463. not(
  3464. assigned(currobjdef) and
  3465. (currobjdef.owner.unitid=0) and
  3466. currobjdef.is_related(tobjectdef(owner.defowner))
  3467. )
  3468. ) then
  3469. exit;
  3470. is_visible_for_object:=true;
  3471. end;
  3472. function tprocdef.getsymtable(t:tgetsymtable):tsymtable;
  3473. begin
  3474. case t of
  3475. gs_local :
  3476. getsymtable:=localst;
  3477. gs_para :
  3478. getsymtable:=parast;
  3479. else
  3480. getsymtable:=nil;
  3481. end;
  3482. end;
  3483. procedure tprocdef.load_references(ppufile:tcompilerppufile;locals:boolean);
  3484. var
  3485. pos : tfileposinfo;
  3486. move_last : boolean;
  3487. oldparasymtable,
  3488. oldlocalsymtable : tsymtable;
  3489. begin
  3490. oldparasymtable:=aktparasymtable;
  3491. oldlocalsymtable:=aktlocalsymtable;
  3492. aktparasymtable:=parast;
  3493. aktlocalsymtable:=localst;
  3494. move_last:=lastwritten=lastref;
  3495. while (not ppufile.endofentry) do
  3496. begin
  3497. ppufile.getposinfo(pos);
  3498. inc(refcount);
  3499. lastref:=tref.create(lastref,@pos);
  3500. lastref.is_written:=true;
  3501. if refcount=1 then
  3502. defref:=lastref;
  3503. end;
  3504. if move_last then
  3505. lastwritten:=lastref;
  3506. if ((current_module.flags and uf_local_browser)<>0) and
  3507. assigned(localst) and
  3508. locals then
  3509. begin
  3510. tparasymtable(parast).load_references(ppufile,locals);
  3511. tlocalsymtable(localst).load_references(ppufile,locals);
  3512. end;
  3513. aktparasymtable:=oldparasymtable;
  3514. aktlocalsymtable:=oldlocalsymtable;
  3515. end;
  3516. Const
  3517. local_symtable_index : word = $8001;
  3518. function tprocdef.write_references(ppufile:tcompilerppufile;locals:boolean):boolean;
  3519. var
  3520. ref : tref;
  3521. pdo : tobjectdef;
  3522. move_last : boolean;
  3523. d : tderef;
  3524. oldparasymtable,
  3525. oldlocalsymtable : tsymtable;
  3526. begin
  3527. d.reset;
  3528. move_last:=lastwritten=lastref;
  3529. if move_last and
  3530. (((current_module.flags and uf_local_browser)=0) or
  3531. not locals) then
  3532. exit;
  3533. oldparasymtable:=aktparasymtable;
  3534. oldlocalsymtable:=aktlocalsymtable;
  3535. aktparasymtable:=parast;
  3536. aktlocalsymtable:=localst;
  3537. { write address of this symbol }
  3538. d.build(self);
  3539. ppufile.putderef(d);
  3540. { write refs }
  3541. if assigned(lastwritten) then
  3542. ref:=lastwritten
  3543. else
  3544. ref:=defref;
  3545. while assigned(ref) do
  3546. begin
  3547. if ref.moduleindex=current_module.unit_index then
  3548. begin
  3549. ppufile.putposinfo(ref.posinfo);
  3550. ref.is_written:=true;
  3551. if move_last then
  3552. lastwritten:=ref;
  3553. end
  3554. else if not ref.is_written then
  3555. move_last:=false
  3556. else if move_last then
  3557. lastwritten:=ref;
  3558. ref:=ref.nextref;
  3559. end;
  3560. ppufile.writeentry(ibdefref);
  3561. write_references:=true;
  3562. if ((current_module.flags and uf_local_browser)<>0) and
  3563. assigned(localst) and
  3564. locals then
  3565. begin
  3566. pdo:=_class;
  3567. if (owner.symtabletype<>localsymtable) then
  3568. while assigned(pdo) do
  3569. begin
  3570. if pdo.symtable<>aktrecordsymtable then
  3571. begin
  3572. pdo.symtable.unitid:=local_symtable_index;
  3573. inc(local_symtable_index);
  3574. end;
  3575. pdo:=pdo.childof;
  3576. end;
  3577. parast.unitid:=local_symtable_index;
  3578. inc(local_symtable_index);
  3579. localst.unitid:=local_symtable_index;
  3580. inc(local_symtable_index);
  3581. tstoredsymtable(parast).write_references(ppufile,locals);
  3582. tstoredsymtable(localst).write_references(ppufile,locals);
  3583. { decrement for }
  3584. local_symtable_index:=local_symtable_index-2;
  3585. pdo:=_class;
  3586. if (owner.symtabletype<>localsymtable) then
  3587. while assigned(pdo) do
  3588. begin
  3589. if pdo.symtable<>aktrecordsymtable then
  3590. dec(local_symtable_index);
  3591. pdo:=pdo.childof;
  3592. end;
  3593. end;
  3594. aktparasymtable:=oldparasymtable;
  3595. aktlocalsymtable:=oldlocalsymtable;
  3596. end;
  3597. {$ifdef GDB}
  3598. function tprocdef.numberstring : string;
  3599. begin
  3600. { procdefs are always available }
  3601. stab_state:=stab_state_written;
  3602. result:=inherited numberstring;
  3603. end;
  3604. function tprocdef.stabstring: pchar;
  3605. Var
  3606. RType : Char;
  3607. Obj,Info : String;
  3608. stabsstr : string;
  3609. p : pchar;
  3610. begin
  3611. obj := procsym.name;
  3612. info := '';
  3613. if tprocsym(procsym).is_global then
  3614. RType := 'F'
  3615. else
  3616. RType := 'f';
  3617. if assigned(owner) then
  3618. begin
  3619. if (owner.symtabletype = objectsymtable) then
  3620. obj := owner.name^+'__'+procsym.name;
  3621. if not(cs_gdb_valgrind in aktglobalswitches) and
  3622. (owner.symtabletype=localsymtable) and
  3623. assigned(owner.defowner) and
  3624. assigned(tprocdef(owner.defowner).procsym) then
  3625. info := ','+procsym.name+','+tprocdef(owner.defowner).procsym.name;
  3626. end;
  3627. stabsstr:=mangledname;
  3628. getmem(p,length(stabsstr)+255);
  3629. strpcopy(p,'"'+obj+':'+RType
  3630. +tstoreddef(rettype.def).numberstring+info+'",'+tostr(n_function)
  3631. +',0,'+
  3632. tostr(fileinfo.line)
  3633. +',');
  3634. strpcopy(strend(p),stabsstr);
  3635. stabstring:=strnew(p);
  3636. freemem(p,length(stabsstr)+255);
  3637. end;
  3638. procedure tprocdef.concatstabto(asmlist : taasmoutput);
  3639. begin
  3640. { released procdef? }
  3641. if not assigned(parast) then
  3642. exit;
  3643. if (proccalloption=pocall_internproc) then
  3644. exit;
  3645. { be sure to have a number assigned for this def }
  3646. numberstring;
  3647. { write stabs }
  3648. stab_state:=stab_state_writing;
  3649. asmList.concat(Tai_stabs.Create(stabstring));
  3650. if not(po_external in procoptions) then
  3651. begin
  3652. tstoredsymtable(parast).concatstabto(asmlist);
  3653. { local type defs and vars should not be written
  3654. inside the main proc stab }
  3655. if assigned(localst) and
  3656. (localst.symtablelevel>main_program_level) then
  3657. tstoredsymtable(localst).concatstabto(asmlist);
  3658. end;
  3659. stab_state:=stab_state_written;
  3660. end;
  3661. {$endif GDB}
  3662. procedure tprocdef.buildderef;
  3663. var
  3664. oldparasymtable,
  3665. oldlocalsymtable : tsymtable;
  3666. begin
  3667. oldparasymtable:=aktparasymtable;
  3668. oldlocalsymtable:=aktlocalsymtable;
  3669. aktparasymtable:=parast;
  3670. aktlocalsymtable:=localst;
  3671. inherited buildderef;
  3672. _classderef.build(_class);
  3673. { procsym that originaly defined this definition, should be in the
  3674. same symtable }
  3675. procsymderef.build(procsym);
  3676. {$ifdef powerpc}
  3677. { library symbol for AmigaOS/MorphOS }
  3678. libsymderef.build(libsym);
  3679. {$endif powerpc}
  3680. aktparasymtable:=oldparasymtable;
  3681. aktlocalsymtable:=oldlocalsymtable;
  3682. end;
  3683. procedure tprocdef.buildderefimpl;
  3684. var
  3685. oldparasymtable,
  3686. oldlocalsymtable : tsymtable;
  3687. begin
  3688. { released procdef? }
  3689. if not assigned(parast) then
  3690. exit;
  3691. oldparasymtable:=aktparasymtable;
  3692. oldlocalsymtable:=aktlocalsymtable;
  3693. aktparasymtable:=parast;
  3694. aktlocalsymtable:=localst;
  3695. inherited buildderefimpl;
  3696. { Locals }
  3697. if assigned(localst) and
  3698. ((proccalloption=pocall_inline) or
  3699. ((current_module.flags and uf_local_browser)<>0)) then
  3700. begin
  3701. tlocalsymtable(localst).buildderef;
  3702. tlocalsymtable(localst).buildderefimpl;
  3703. end;
  3704. { inline tree }
  3705. if (proccalloption=pocall_inline) then
  3706. begin
  3707. funcretsymderef.build(funcretsym);
  3708. inlininginfo^.code.buildderefimpl;
  3709. end;
  3710. aktparasymtable:=oldparasymtable;
  3711. aktlocalsymtable:=oldlocalsymtable;
  3712. end;
  3713. procedure tprocdef.deref;
  3714. var
  3715. oldparasymtable,
  3716. oldlocalsymtable : tsymtable;
  3717. begin
  3718. { released procdef? }
  3719. if not assigned(parast) then
  3720. exit;
  3721. oldparasymtable:=aktparasymtable;
  3722. oldlocalsymtable:=aktlocalsymtable;
  3723. aktparasymtable:=parast;
  3724. aktlocalsymtable:=localst;
  3725. inherited deref;
  3726. _class:=tobjectdef(_classderef.resolve);
  3727. { procsym that originaly defined this definition, should be in the
  3728. same symtable }
  3729. procsym:=tprocsym(procsymderef.resolve);
  3730. {$ifdef powerpc}
  3731. { library symbol for AmigaOS/MorphOS }
  3732. libsym:=tvarsym(libsymderef.resolve);
  3733. {$endif powerpc}
  3734. aktparasymtable:=oldparasymtable;
  3735. aktlocalsymtable:=oldlocalsymtable;
  3736. end;
  3737. procedure tprocdef.derefimpl;
  3738. var
  3739. oldparasymtable,
  3740. oldlocalsymtable : tsymtable;
  3741. begin
  3742. oldparasymtable:=aktparasymtable;
  3743. oldlocalsymtable:=aktlocalsymtable;
  3744. aktparasymtable:=parast;
  3745. aktlocalsymtable:=localst;
  3746. { Locals }
  3747. if assigned(localst) then
  3748. begin
  3749. tlocalsymtable(localst).deref;
  3750. tlocalsymtable(localst).derefimpl;
  3751. end;
  3752. { Inline }
  3753. if (proccalloption=pocall_inline) then
  3754. begin
  3755. inlininginfo^.code.derefimpl;
  3756. { funcretsym, this is always located in the localst }
  3757. funcretsym:=tsym(funcretsymderef.resolve);
  3758. end
  3759. else
  3760. begin
  3761. { safety }
  3762. funcretsym:=nil;
  3763. end;
  3764. aktparasymtable:=oldparasymtable;
  3765. aktlocalsymtable:=oldlocalsymtable;
  3766. end;
  3767. function tprocdef.gettypename : string;
  3768. begin
  3769. gettypename := FullProcName(false);
  3770. end;
  3771. function tprocdef.mangledname : string;
  3772. var
  3773. hp : TParaItem;
  3774. begin
  3775. if assigned(_mangledname) then
  3776. begin
  3777. {$ifdef compress}
  3778. mangledname:=minilzw_decode(_mangledname^);
  3779. {$else}
  3780. mangledname:=_mangledname^;
  3781. {$endif}
  3782. exit;
  3783. end;
  3784. { we need to use the symtable where the procsym is inserted,
  3785. because that is visible to the world }
  3786. mangledname:=make_mangledname('',procsym.owner,procsym.name);
  3787. if overloadnumber>0 then
  3788. mangledname:=mangledname+'$'+tostr(overloadnumber);
  3789. { add parameter types }
  3790. hp:=TParaItem(Para.first);
  3791. while assigned(hp) do
  3792. begin
  3793. if not hp.is_hidden then
  3794. mangledname:=mangledname+'$'+hp.paratype.def.mangledparaname;
  3795. hp:=TParaItem(hp.next);
  3796. end;
  3797. {$ifdef compress}
  3798. _mangledname:=stringdup(minilzw_encode(mangledname));
  3799. {$else}
  3800. _mangledname:=stringdup(mangledname);
  3801. {$endif}
  3802. end;
  3803. function tprocdef.cplusplusmangledname : string;
  3804. function getcppparaname(p : tdef) : string;
  3805. const
  3806. ordtype2str : array[tbasetype] of string[2] = (
  3807. '',
  3808. 'Uc','Us','Ui','Us',
  3809. 'Sc','s','i','x',
  3810. 'b','b','b',
  3811. 'c','w','x');
  3812. var
  3813. s : string;
  3814. begin
  3815. case p.deftype of
  3816. orddef:
  3817. s:=ordtype2str[torddef(p).typ];
  3818. pointerdef:
  3819. s:='P'+getcppparaname(tpointerdef(p).pointertype.def);
  3820. else
  3821. internalerror(2103001);
  3822. end;
  3823. getcppparaname:=s;
  3824. end;
  3825. var
  3826. s,s2 : string;
  3827. param : TParaItem;
  3828. begin
  3829. s := procsym.realname;
  3830. if procsym.owner.symtabletype=objectsymtable then
  3831. begin
  3832. s2:=upper(tobjectdef(procsym.owner.defowner).typesym.realname);
  3833. case proctypeoption of
  3834. potype_destructor:
  3835. s:='_$_'+tostr(length(s2))+s2;
  3836. potype_constructor:
  3837. s:='___'+tostr(length(s2))+s2;
  3838. else
  3839. s:='_'+s+'__'+tostr(length(s2))+s2;
  3840. end;
  3841. end
  3842. else s:=s+'__';
  3843. s:=s+'F';
  3844. { concat modifiers }
  3845. { !!!!! }
  3846. { now we handle the parameters }
  3847. param := TParaItem(Para.first);
  3848. if assigned(param) then
  3849. while assigned(param) do
  3850. begin
  3851. s2:=getcppparaname(param.paratype.def);
  3852. if param.paratyp in [vs_var,vs_out] then
  3853. s2:='R'+s2;
  3854. s:=s+s2;
  3855. param:=TParaItem(param.next);
  3856. end
  3857. else
  3858. s:=s+'v';
  3859. cplusplusmangledname:=s;
  3860. end;
  3861. procedure tprocdef.setmangledname(const s : string);
  3862. begin
  3863. stringdispose(_mangledname);
  3864. {$ifdef compress}
  3865. _mangledname:=stringdup(minilzw_encode(s));
  3866. {$else}
  3867. _mangledname:=stringdup(s);
  3868. {$endif}
  3869. has_mangledname:=true;
  3870. end;
  3871. {***************************************************************************
  3872. TPROCVARDEF
  3873. ***************************************************************************}
  3874. constructor tprocvardef.create(level:byte);
  3875. begin
  3876. inherited create(level);
  3877. deftype:=procvardef;
  3878. end;
  3879. constructor tprocvardef.ppuload(ppufile:tcompilerppufile);
  3880. begin
  3881. inherited ppuload(ppufile);
  3882. deftype:=procvardef;
  3883. { load para symtable }
  3884. parast:=tparasymtable.create(unknown_level);
  3885. tparasymtable(parast).ppuload(ppufile);
  3886. parast.defowner:=self;
  3887. end;
  3888. procedure tprocvardef.ppuwrite(ppufile:tcompilerppufile);
  3889. var
  3890. oldparasymtable,
  3891. oldlocalsymtable : tsymtable;
  3892. begin
  3893. oldparasymtable:=aktparasymtable;
  3894. oldlocalsymtable:=aktlocalsymtable;
  3895. aktparasymtable:=parast;
  3896. aktlocalsymtable:=nil;
  3897. { here we cannot get a real good value so just give something }
  3898. { plausible (PM) }
  3899. { a more secure way would be
  3900. to allways store in a temp }
  3901. {$ifdef i386}
  3902. if is_fpu(rettype.def) then
  3903. fpu_used:={2}maxfpuregs
  3904. else
  3905. fpu_used:=0;
  3906. {$endif i386}
  3907. inherited ppuwrite(ppufile);
  3908. { Write this entry }
  3909. ppufile.writeentry(ibprocvardef);
  3910. { Save the para symtable, this is taken from the interface }
  3911. tparasymtable(parast).ppuwrite(ppufile);
  3912. aktparasymtable:=oldparasymtable;
  3913. aktlocalsymtable:=oldlocalsymtable;
  3914. end;
  3915. procedure tprocvardef.buildderef;
  3916. var
  3917. oldparasymtable,
  3918. oldlocalsymtable : tsymtable;
  3919. begin
  3920. oldparasymtable:=aktparasymtable;
  3921. oldlocalsymtable:=aktlocalsymtable;
  3922. aktparasymtable:=parast;
  3923. aktlocalsymtable:=nil;
  3924. inherited buildderef;
  3925. aktparasymtable:=oldparasymtable;
  3926. aktlocalsymtable:=oldlocalsymtable;
  3927. end;
  3928. procedure tprocvardef.deref;
  3929. var
  3930. oldparasymtable,
  3931. oldlocalsymtable : tsymtable;
  3932. begin
  3933. oldparasymtable:=aktparasymtable;
  3934. oldlocalsymtable:=aktlocalsymtable;
  3935. aktparasymtable:=parast;
  3936. aktlocalsymtable:=nil;
  3937. inherited deref;
  3938. aktparasymtable:=oldparasymtable;
  3939. aktlocalsymtable:=oldlocalsymtable;
  3940. end;
  3941. function tprocvardef.getsymtable(t:tgetsymtable):tsymtable;
  3942. begin
  3943. case t of
  3944. gs_para :
  3945. getsymtable:=parast;
  3946. else
  3947. getsymtable:=nil;
  3948. end;
  3949. end;
  3950. function tprocvardef.size : longint;
  3951. begin
  3952. if (po_methodpointer in procoptions) and
  3953. not(po_addressonly in procoptions) then
  3954. size:=2*sizeof(aint)
  3955. else
  3956. size:=sizeof(aint);
  3957. end;
  3958. function tprocvardef.is_methodpointer:boolean;
  3959. begin
  3960. result:=(po_methodpointer in procoptions);
  3961. end;
  3962. function tprocvardef.is_addressonly:boolean;
  3963. begin
  3964. result:=not(po_methodpointer in procoptions) or
  3965. (po_addressonly in procoptions);
  3966. end;
  3967. {$ifdef GDB}
  3968. function tprocvardef.stabstring : pchar;
  3969. var
  3970. nss : pchar;
  3971. { i : longint; }
  3972. begin
  3973. { i := maxparacount; }
  3974. getmem(nss,1024);
  3975. { it is not a function but a function pointer !! (PM) }
  3976. strpcopy(nss,'*f'+tstoreddef(rettype.def).numberstring{+','+tostr(i)});
  3977. { this confuses gdb !!
  3978. we should use 'F' instead of 'f' but
  3979. as we use c++ language mode
  3980. it does not like that either
  3981. Please do not remove this part
  3982. might be used once
  3983. gdb for pascal is ready PM }
  3984. {$ifdef disabled}
  3985. param := para1;
  3986. i := 0;
  3987. while assigned(param) do
  3988. begin
  3989. inc(i);
  3990. if param^.paratyp = vs_value then vartyp := '1' else vartyp := '0';
  3991. {Here we have lost the parameter names !!}
  3992. pst := strpnew('p'+tostr(i)+':'+param^.paratype.def.numberstring+','+vartyp+';');
  3993. strcat(nss,pst);
  3994. strdispose(pst);
  3995. param := param^.next;
  3996. end;
  3997. {$endif}
  3998. {strpcopy(strend(nss),';');}
  3999. stabstring := strnew(nss);
  4000. freemem(nss,1024);
  4001. end;
  4002. procedure tprocvardef.concatstabto(asmlist : taasmoutput);
  4003. begin
  4004. if (stab_state in [stab_state_writing,stab_state_written]) then
  4005. exit;
  4006. tstoreddef(rettype.def).concatstabto(asmlist);
  4007. inherited concatstabto(asmlist);
  4008. end;
  4009. {$endif GDB}
  4010. procedure tprocvardef.write_rtti_data(rt:trttitype);
  4011. var
  4012. pdc : TParaItem;
  4013. methodkind, paraspec : byte;
  4014. begin
  4015. if po_methodpointer in procoptions then
  4016. begin
  4017. { write method id and name }
  4018. rttiList.concat(Tai_const.Create_8bit(tkmethod));
  4019. write_rtti_name;
  4020. { write kind of method (can only be function or procedure)}
  4021. if rettype.def = voidtype.def then
  4022. methodkind := mkProcedure
  4023. else
  4024. methodkind := mkFunction;
  4025. rttiList.concat(Tai_const.Create_8bit(methodkind));
  4026. { get # of parameters }
  4027. rttiList.concat(Tai_const.Create_8bit(maxparacount));
  4028. { write parameter info. The parameters must be written in reverse order
  4029. if this method uses right to left parameter pushing! }
  4030. if proccalloption in pushleftright_pocalls then
  4031. pdc:=TParaItem(Para.first)
  4032. else
  4033. pdc:=TParaItem(Para.last);
  4034. while assigned(pdc) do
  4035. begin
  4036. { only store user visible parameters }
  4037. if not pdc.is_hidden then
  4038. begin
  4039. case pdc.paratyp of
  4040. vs_value: paraspec := 0;
  4041. vs_const: paraspec := pfConst;
  4042. vs_var : paraspec := pfVar;
  4043. vs_out : paraspec := pfOut;
  4044. end;
  4045. { write flags for current parameter }
  4046. rttiList.concat(Tai_const.Create_8bit(paraspec));
  4047. { write name of current parameter }
  4048. if assigned(pdc.parasym) then
  4049. begin
  4050. rttiList.concat(Tai_const.Create_8bit(length(pdc.parasym.realname)));
  4051. rttiList.concat(Tai_string.Create(pdc.parasym.realname));
  4052. end
  4053. else
  4054. rttiList.concat(Tai_const.Create_8bit(0));
  4055. { write name of type of current parameter }
  4056. tstoreddef(pdc.paratype.def).write_rtti_name;
  4057. end;
  4058. if proccalloption in pushleftright_pocalls then
  4059. pdc:=TParaItem(pdc.next)
  4060. else
  4061. pdc:=TParaItem(pdc.previous);
  4062. end;
  4063. { write name of result type }
  4064. tstoreddef(rettype.def).write_rtti_name;
  4065. end;
  4066. end;
  4067. function tprocvardef.is_publishable : boolean;
  4068. begin
  4069. is_publishable:=(po_methodpointer in procoptions);
  4070. end;
  4071. function tprocvardef.gettypename : string;
  4072. var
  4073. s: string;
  4074. showhidden : boolean;
  4075. begin
  4076. {$ifdef EXTDEBUG}
  4077. showhidden:=true;
  4078. {$else EXTDEBUG}
  4079. showhidden:=false;
  4080. {$endif EXTDEBUG}
  4081. s:='<';
  4082. if po_classmethod in procoptions then
  4083. s := s+'class method type of'
  4084. else
  4085. if po_addressonly in procoptions then
  4086. s := s+'address of'
  4087. else
  4088. s := s+'procedure variable type of';
  4089. if assigned(rettype.def) and
  4090. (rettype.def<>voidtype.def) then
  4091. s:=s+' function'+typename_paras(showhidden)+':'+rettype.def.gettypename
  4092. else
  4093. s:=s+' procedure'+typename_paras(showhidden);
  4094. if po_methodpointer in procoptions then
  4095. s := s+' of object';
  4096. gettypename := s+';'+ProcCallOptionStr[proccalloption]+'>';
  4097. end;
  4098. {***************************************************************************
  4099. TOBJECTDEF
  4100. ***************************************************************************}
  4101. constructor tobjectdef.create(ot : tobjectdeftype;const n : string;c : tobjectdef);
  4102. begin
  4103. inherited create;
  4104. objecttype:=ot;
  4105. deftype:=objectdef;
  4106. objectoptions:=[];
  4107. childof:=nil;
  4108. symtable:=tobjectsymtable.create(n,aktpackrecords);
  4109. { create space for vmt !! }
  4110. vmt_offset:=0;
  4111. symtable.defowner:=self;
  4112. lastvtableindex:=0;
  4113. set_parent(c);
  4114. objname:=stringdup(upper(n));
  4115. objrealname:=stringdup(n);
  4116. if objecttype in [odt_interfacecorba,odt_interfacecom] then
  4117. prepareguid;
  4118. { setup implemented interfaces }
  4119. if objecttype in [odt_class,odt_interfacecorba] then
  4120. implementedinterfaces:=timplementedinterfaces.create
  4121. else
  4122. implementedinterfaces:=nil;
  4123. {$ifdef GDB}
  4124. writing_class_record_stab:=false;
  4125. {$endif GDB}
  4126. end;
  4127. constructor tobjectdef.ppuload(ppufile:tcompilerppufile);
  4128. var
  4129. i,implintfcount: longint;
  4130. d : tderef;
  4131. begin
  4132. inherited ppuloaddef(ppufile);
  4133. deftype:=objectdef;
  4134. objecttype:=tobjectdeftype(ppufile.getbyte);
  4135. objrealname:=stringdup(ppufile.getstring);
  4136. objname:=stringdup(upper(objrealname^));
  4137. symtable:=tobjectsymtable.create(objrealname^,0);
  4138. tobjectsymtable(symtable).datasize:=ppufile.getlongint;
  4139. tobjectsymtable(symtable).fieldalignment:=ppufile.getbyte;
  4140. tobjectsymtable(symtable).recordalignment:=ppufile.getbyte;
  4141. vmt_offset:=ppufile.getlongint;
  4142. ppufile.getderef(childofderef);
  4143. ppufile.getsmallset(objectoptions);
  4144. { load guid }
  4145. iidstr:=nil;
  4146. if objecttype in [odt_interfacecom,odt_interfacecorba] then
  4147. begin
  4148. new(iidguid);
  4149. ppufile.getguid(iidguid^);
  4150. iidstr:=stringdup(ppufile.getstring);
  4151. lastvtableindex:=ppufile.getlongint;
  4152. end;
  4153. { load implemented interfaces }
  4154. if objecttype in [odt_class,odt_interfacecorba] then
  4155. begin
  4156. implementedinterfaces:=timplementedinterfaces.create;
  4157. implintfcount:=ppufile.getlongint;
  4158. for i:=1 to implintfcount do
  4159. begin
  4160. ppufile.getderef(d);
  4161. implementedinterfaces.addintf_deref(d);
  4162. implementedinterfaces.ioffsets(i)^:=ppufile.getlongint;
  4163. end;
  4164. end
  4165. else
  4166. implementedinterfaces:=nil;
  4167. tobjectsymtable(symtable).ppuload(ppufile);
  4168. symtable.defowner:=self;
  4169. { handles the predefined class tobject }
  4170. { the last TOBJECT which is loaded gets }
  4171. { it ! }
  4172. if (childof=nil) and
  4173. (objecttype=odt_class) and
  4174. (objname^='TOBJECT') then
  4175. class_tobject:=self;
  4176. if (childof=nil) and
  4177. (objecttype=odt_interfacecom) and
  4178. (objname^='IUNKNOWN') then
  4179. interface_iunknown:=self;
  4180. {$ifdef GDB}
  4181. writing_class_record_stab:=false;
  4182. {$endif GDB}
  4183. end;
  4184. destructor tobjectdef.destroy;
  4185. begin
  4186. if assigned(symtable) then
  4187. symtable.free;
  4188. stringdispose(objname);
  4189. stringdispose(objrealname);
  4190. if assigned(iidstr) then
  4191. stringdispose(iidstr);
  4192. if assigned(implementedinterfaces) then
  4193. implementedinterfaces.free;
  4194. if assigned(iidguid) then
  4195. dispose(iidguid);
  4196. inherited destroy;
  4197. end;
  4198. procedure tobjectdef.ppuwrite(ppufile:tcompilerppufile);
  4199. var
  4200. implintfcount : longint;
  4201. i : longint;
  4202. begin
  4203. inherited ppuwritedef(ppufile);
  4204. ppufile.putbyte(byte(objecttype));
  4205. ppufile.putstring(objrealname^);
  4206. ppufile.putlongint(tobjectsymtable(symtable).datasize);
  4207. ppufile.putbyte(tobjectsymtable(symtable).fieldalignment);
  4208. ppufile.putbyte(tobjectsymtable(symtable).recordalignment);
  4209. ppufile.putlongint(vmt_offset);
  4210. ppufile.putderef(childofderef);
  4211. ppufile.putsmallset(objectoptions);
  4212. if objecttype in [odt_interfacecom,odt_interfacecorba] then
  4213. begin
  4214. ppufile.putguid(iidguid^);
  4215. ppufile.putstring(iidstr^);
  4216. ppufile.putlongint(lastvtableindex);
  4217. end;
  4218. if objecttype in [odt_class,odt_interfacecorba] then
  4219. begin
  4220. implintfcount:=implementedinterfaces.count;
  4221. ppufile.putlongint(implintfcount);
  4222. for i:=1 to implintfcount do
  4223. begin
  4224. ppufile.putderef(implementedinterfaces.interfacesderef(i));
  4225. ppufile.putlongint(implementedinterfaces.ioffsets(i)^);
  4226. end;
  4227. end;
  4228. ppufile.writeentry(ibobjectdef);
  4229. tobjectsymtable(symtable).ppuwrite(ppufile);
  4230. end;
  4231. function tobjectdef.gettypename:string;
  4232. begin
  4233. gettypename:=typename;
  4234. end;
  4235. procedure tobjectdef.buildderef;
  4236. var
  4237. oldrecsyms : tsymtable;
  4238. begin
  4239. inherited buildderef;
  4240. childofderef.build(childof);
  4241. oldrecsyms:=aktrecordsymtable;
  4242. aktrecordsymtable:=symtable;
  4243. tstoredsymtable(symtable).buildderef;
  4244. aktrecordsymtable:=oldrecsyms;
  4245. if objecttype in [odt_class,odt_interfacecorba] then
  4246. implementedinterfaces.buildderef;
  4247. end;
  4248. procedure tobjectdef.deref;
  4249. var
  4250. oldrecsyms : tsymtable;
  4251. begin
  4252. inherited deref;
  4253. childof:=tobjectdef(childofderef.resolve);
  4254. oldrecsyms:=aktrecordsymtable;
  4255. aktrecordsymtable:=symtable;
  4256. tstoredsymtable(symtable).deref;
  4257. aktrecordsymtable:=oldrecsyms;
  4258. if objecttype in [odt_class,odt_interfacecorba] then
  4259. implementedinterfaces.deref;
  4260. end;
  4261. function tobjectdef.getparentdef:tdef;
  4262. begin
  4263. result:=childof;
  4264. end;
  4265. procedure tobjectdef.prepareguid;
  4266. begin
  4267. { set up guid }
  4268. if not assigned(iidguid) then
  4269. begin
  4270. new(iidguid);
  4271. fillchar(iidguid^,sizeof(iidguid^),0); { default null guid }
  4272. end;
  4273. { setup iidstring }
  4274. if not assigned(iidstr) then
  4275. iidstr:=stringdup(''); { default is empty string }
  4276. end;
  4277. procedure tobjectdef.set_parent( c : tobjectdef);
  4278. begin
  4279. { nothing to do if the parent was not forward !}
  4280. if assigned(childof) then
  4281. exit;
  4282. childof:=c;
  4283. { some options are inherited !! }
  4284. if assigned(c) then
  4285. begin
  4286. { only important for classes }
  4287. lastvtableindex:=c.lastvtableindex;
  4288. objectoptions:=objectoptions+(c.objectoptions*
  4289. [oo_has_virtual,oo_has_private,oo_has_protected,
  4290. oo_has_constructor,oo_has_destructor]);
  4291. if not (objecttype in [odt_interfacecom,odt_interfacecorba]) then
  4292. begin
  4293. { add the data of the anchestor class }
  4294. inc(tobjectsymtable(symtable).datasize,tobjectsymtable(c.symtable).datasize);
  4295. if (oo_has_vmt in objectoptions) and
  4296. (oo_has_vmt in c.objectoptions) then
  4297. dec(tobjectsymtable(symtable).datasize,sizeof(aint));
  4298. { if parent has a vmt field then
  4299. the offset is the same for the child PM }
  4300. if (oo_has_vmt in c.objectoptions) or is_class(self) then
  4301. begin
  4302. vmt_offset:=c.vmt_offset;
  4303. include(objectoptions,oo_has_vmt);
  4304. end;
  4305. end;
  4306. end;
  4307. end;
  4308. procedure tobjectdef.insertvmt;
  4309. begin
  4310. if objecttype in [odt_interfacecom,odt_interfacecorba] then
  4311. exit;
  4312. if (oo_has_vmt in objectoptions) then
  4313. internalerror(12345)
  4314. else
  4315. begin
  4316. tobjectsymtable(symtable).datasize:=align(tobjectsymtable(symtable).datasize,
  4317. tobjectsymtable(symtable).fieldalignment);
  4318. vmt_offset:=tobjectsymtable(symtable).datasize;
  4319. inc(tobjectsymtable(symtable).datasize,sizeof(aint));
  4320. include(objectoptions,oo_has_vmt);
  4321. end;
  4322. end;
  4323. procedure tobjectdef.check_forwards;
  4324. begin
  4325. if not(objecttype in [odt_interfacecom,odt_interfacecorba]) then
  4326. tstoredsymtable(symtable).check_forwards;
  4327. if (oo_is_forward in objectoptions) then
  4328. begin
  4329. { ok, in future, the forward can be resolved }
  4330. Message1(sym_e_class_forward_not_resolved,objrealname^);
  4331. exclude(objectoptions,oo_is_forward);
  4332. end;
  4333. end;
  4334. { true, if self inherits from d (or if they are equal) }
  4335. function tobjectdef.is_related(d : tobjectdef) : boolean;
  4336. var
  4337. hp : tobjectdef;
  4338. begin
  4339. hp:=self;
  4340. while assigned(hp) do
  4341. begin
  4342. if hp=d then
  4343. begin
  4344. is_related:=true;
  4345. exit;
  4346. end;
  4347. hp:=hp.childof;
  4348. end;
  4349. is_related:=false;
  4350. end;
  4351. (* procedure tobjectdef._searchdestructor(sym : tnamedindexitem;arg:pointer);
  4352. var
  4353. p : pprocdeflist;
  4354. begin
  4355. { if we found already a destructor, then we exit }
  4356. if assigned(sd) then
  4357. exit;
  4358. if tsym(sym).typ=procsym then
  4359. begin
  4360. p:=tprocsym(sym).defs;
  4361. while assigned(p) do
  4362. begin
  4363. if p^.def.proctypeoption=potype_destructor then
  4364. begin
  4365. sd:=p^.def;
  4366. exit;
  4367. end;
  4368. p:=p^.next;
  4369. end;
  4370. end;
  4371. end;*)
  4372. procedure _searchdestructor(sym:Tnamedindexitem;sd:pointer);
  4373. begin
  4374. { if we found already a destructor, then we exit }
  4375. if (ppointer(sd)^=nil) and
  4376. (Tsym(sym).typ=procsym) then
  4377. ppointer(sd)^:=Tprocsym(sym).search_procdef_bytype(potype_destructor);
  4378. end;
  4379. function tobjectdef.searchdestructor : tprocdef;
  4380. var
  4381. o : tobjectdef;
  4382. sd : tprocdef;
  4383. begin
  4384. searchdestructor:=nil;
  4385. o:=self;
  4386. sd:=nil;
  4387. while assigned(o) do
  4388. begin
  4389. o.symtable.foreach_static({$ifdef FPCPROCVAR}@{$endif}_searchdestructor,@sd);
  4390. if assigned(sd) then
  4391. begin
  4392. searchdestructor:=sd;
  4393. exit;
  4394. end;
  4395. o:=o.childof;
  4396. end;
  4397. end;
  4398. function tobjectdef.size : longint;
  4399. begin
  4400. if objecttype in [odt_class,odt_interfacecom,odt_interfacecorba] then
  4401. result:=sizeof(aint)
  4402. else
  4403. result:=tobjectsymtable(symtable).datasize;
  4404. end;
  4405. function tobjectdef.alignment:longint;
  4406. begin
  4407. if objecttype in [odt_class,odt_interfacecom,odt_interfacecorba] then
  4408. alignment:=sizeof(aint)
  4409. else
  4410. alignment:=tobjectsymtable(symtable).recordalignment;
  4411. end;
  4412. function tobjectdef.vmtmethodoffset(index:longint):longint;
  4413. begin
  4414. { for offset of methods for classes, see rtl/inc/objpash.inc }
  4415. case objecttype of
  4416. odt_class:
  4417. { the +2*sizeof(Aint) is size and -size }
  4418. vmtmethodoffset:=(index+10)*sizeof(aint)+2*sizeof(AInt);
  4419. odt_interfacecom,odt_interfacecorba:
  4420. vmtmethodoffset:=index*sizeof(aint);
  4421. else
  4422. {$ifdef WITHDMT}
  4423. vmtmethodoffset:=(index+4)*sizeof(aint);
  4424. {$else WITHDMT}
  4425. vmtmethodoffset:=(index+3)*sizeof(aint);
  4426. {$endif WITHDMT}
  4427. end;
  4428. end;
  4429. function tobjectdef.vmt_mangledname : string;
  4430. begin
  4431. if not(oo_has_vmt in objectoptions) then
  4432. Message1(parser_n_object_has_no_vmt,objrealname^);
  4433. vmt_mangledname:=make_mangledname('VMT',owner,objname^);
  4434. end;
  4435. function tobjectdef.rtti_name : string;
  4436. begin
  4437. rtti_name:=make_mangledname('RTTI',owner,objname^);
  4438. end;
  4439. {$ifdef GDB}
  4440. procedure tobjectdef.proc_addname(p :tnamedindexitem;arg:pointer);
  4441. var virtualind,argnames : string;
  4442. newrec : pchar;
  4443. pd : tprocdef;
  4444. lindex : longint;
  4445. para : TParaItem;
  4446. arglength : byte;
  4447. sp : char;
  4448. state:^Trecord_stabgen_state;
  4449. olds:integer;
  4450. begin
  4451. state:=arg;
  4452. if tsym(p).typ = procsym then
  4453. begin
  4454. pd := tprocsym(p).first_procdef;
  4455. if (po_virtualmethod in pd.procoptions) then
  4456. begin
  4457. lindex := pd.extnumber;
  4458. {doesnt seem to be necessary
  4459. lindex := lindex or $80000000;}
  4460. virtualind := '*'+tostr(lindex)+';'+pd._class.classnumberstring+';'
  4461. end
  4462. else
  4463. virtualind := '.';
  4464. { used by gdbpas to recognize constructor and destructors }
  4465. if (pd.proctypeoption=potype_constructor) then
  4466. argnames:='__ct__'
  4467. else if (pd.proctypeoption=potype_destructor) then
  4468. argnames:='__dt__'
  4469. else
  4470. argnames := '';
  4471. { arguments are not listed here }
  4472. {we don't need another definition}
  4473. para := TParaItem(pd.Para.first);
  4474. while assigned(para) do
  4475. begin
  4476. if Para.paratype.def.deftype = formaldef then
  4477. begin
  4478. case Para.paratyp of
  4479. vs_var :
  4480. argnames := argnames+'3var';
  4481. vs_const :
  4482. argnames:=argnames+'5const';
  4483. vs_out :
  4484. argnames:=argnames+'3out';
  4485. end;
  4486. end
  4487. else
  4488. begin
  4489. { if the arg definition is like (v: ^byte;..
  4490. there is no sym attached to data !!! }
  4491. if assigned(Para.paratype.def.typesym) then
  4492. begin
  4493. arglength := length(Para.paratype.def.typesym.name);
  4494. argnames := argnames + tostr(arglength)+Para.paratype.def.typesym.name;
  4495. end
  4496. else
  4497. argnames:=argnames+'11unnamedtype';
  4498. end;
  4499. para := TParaItem(Para.next);
  4500. end;
  4501. { here 2A must be changed for private and protected }
  4502. { 0 is private 1 protected and 2 public }
  4503. if (sp_private in tsym(p).symoptions) then
  4504. sp:='0'
  4505. else if (sp_protected in tsym(p).symoptions) then
  4506. sp:='1'
  4507. else
  4508. sp:='2';
  4509. newrec:=stabstr_evaluate('$1::$2=##$3;:$4;$5A$6;',[p.name,pd.numberstring,
  4510. Tstoreddef(pd.rettype.def).numberstring,argnames,sp,
  4511. virtualind]);
  4512. { get spare place for a string at the end }
  4513. olds:=state^.stabsize;
  4514. inc(state^.stabsize,strlen(newrec));
  4515. if state^.stabsize>=state^.staballoc-256 then
  4516. begin
  4517. inc(state^.staballoc,memsizeinc);
  4518. reallocmem(state^.stabstring,state^.staballoc);
  4519. end;
  4520. strcopy(state^.stabstring+olds,newrec);
  4521. strdispose(newrec);
  4522. {This should be used for case !!
  4523. RecOffset := RecOffset + pd.size;}
  4524. end;
  4525. end;
  4526. procedure tobjectdef.proc_concatstabto(p :tnamedindexitem;arg:pointer);
  4527. var
  4528. pd : tprocdef;
  4529. begin
  4530. if tsym(p).typ = procsym then
  4531. begin
  4532. pd := tprocsym(p).first_procdef;
  4533. tstoreddef(pd.rettype.def).concatstabto(taasmoutput(arg));
  4534. end;
  4535. end;
  4536. function tobjectdef.stabstring : pchar;
  4537. var anc : tobjectdef;
  4538. state:Trecord_stabgen_state;
  4539. ts : string;
  4540. begin
  4541. if not (objecttype=odt_class) or writing_class_record_stab then
  4542. begin
  4543. state.staballoc:=memsizeinc;
  4544. getmem(state.stabstring,state.staballoc);
  4545. strpcopy(state.stabstring,'s'+tostr(tobjectsymtable(symtable).datasize));
  4546. if assigned(childof) then
  4547. begin
  4548. {only one ancestor not virtual, public, at base offset 0 }
  4549. { !1 , 0 2 0 , }
  4550. strpcopy(strend(state.stabstring),'!1,020,'+childof.classnumberstring+';');
  4551. end;
  4552. {virtual table to implement yet}
  4553. state.recoffset:=0;
  4554. state.stabsize:=strlen(state.stabstring);
  4555. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}field_addname,@state);
  4556. if (oo_has_vmt in objectoptions) then
  4557. if not assigned(childof) or not(oo_has_vmt in childof.objectoptions) then
  4558. begin
  4559. ts:='$vf'+classnumberstring+':'+tstoreddef(vmtarraytype.def).numberstring+','+tostr(vmt_offset*8)+';';
  4560. strpcopy(state.stabstring+state.stabsize,ts);
  4561. inc(state.stabsize,length(ts));
  4562. end;
  4563. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}proc_addname,@state);
  4564. if (oo_has_vmt in objectoptions) then
  4565. begin
  4566. anc := self;
  4567. while assigned(anc.childof) and (oo_has_vmt in anc.childof.objectoptions) do
  4568. anc := anc.childof;
  4569. { just in case anc = self }
  4570. ts:=';~%'+anc.classnumberstring+';';
  4571. end
  4572. else
  4573. ts:=';';
  4574. strpcopy(state.stabstring+state.stabsize,ts);
  4575. inc(state.stabsize,length(ts));
  4576. reallocmem(state.stabstring,state.stabsize+1);
  4577. stabstring:=state.stabstring;
  4578. end
  4579. else
  4580. begin
  4581. stabstring:=strpnew('*'+classnumberstring);
  4582. end;
  4583. end;
  4584. procedure tobjectdef.set_globalnb;
  4585. begin
  4586. globalnb:=PglobalTypeCount^;
  4587. inc(PglobalTypeCount^);
  4588. { classes need two type numbers, the globalnb is set to the ptr }
  4589. if objecttype=odt_class then
  4590. begin
  4591. globalnb:=PGlobalTypeCount^;
  4592. inc(PglobalTypeCount^);
  4593. end;
  4594. end;
  4595. function tobjectdef.classnumberstring : string;
  4596. begin
  4597. if objecttype=odt_class then
  4598. begin
  4599. if globalnb=0 then
  4600. numberstring;
  4601. dec(globalnb);
  4602. classnumberstring:=numberstring;
  4603. inc(globalnb);
  4604. end
  4605. else
  4606. classnumberstring:=numberstring;
  4607. end;
  4608. function tobjectdef.allstabstring : pchar;
  4609. var
  4610. stabchar : string[2];
  4611. ss,st : pchar;
  4612. sname : string;
  4613. begin
  4614. ss := stabstring;
  4615. getmem(st,strlen(ss)+512);
  4616. stabchar := 't';
  4617. if deftype in tagtypes then
  4618. stabchar := 'Tt';
  4619. if assigned(typesym) then
  4620. sname := typesym.name
  4621. else
  4622. sname := ' ';
  4623. if writing_class_record_stab then
  4624. strpcopy(st,'"'+sname+':'+stabchar+classnumberstring+'=')
  4625. else
  4626. strpcopy(st,'"'+sname+':'+stabchar+numberstring+'=');
  4627. strpcopy(strecopy(strend(st),ss),'",'+tostr(N_LSYM)+',0,0,0');
  4628. allstabstring := strnew(st);
  4629. freemem(st,strlen(ss)+512);
  4630. strdispose(ss);
  4631. end;
  4632. procedure tobjectdef.concatstabto(asmlist : taasmoutput);
  4633. var
  4634. oldtypesym : tsym;
  4635. stab_str : pchar;
  4636. anc : tobjectdef;
  4637. begin
  4638. if (stab_state in [stab_state_writing,stab_state_written]) then
  4639. exit;
  4640. stab_state:=stab_state_writing;
  4641. tstoreddef(vmtarraytype.def).concatstabto(asmlist);
  4642. { first the parents }
  4643. anc:=self;
  4644. while assigned(anc.childof) do
  4645. begin
  4646. anc:=anc.childof;
  4647. anc.concatstabto(asmlist);
  4648. end;
  4649. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}field_concatstabto,asmlist);
  4650. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}proc_concatstabto,asmlist);
  4651. stab_state:=stab_state_used;
  4652. if objecttype=odt_class then
  4653. begin
  4654. { Write the record class itself }
  4655. writing_class_record_stab:=true;
  4656. inherited concatstabto(asmlist);
  4657. writing_class_record_stab:=false;
  4658. { Write the invisible pointer class }
  4659. oldtypesym:=typesym;
  4660. typesym:=nil;
  4661. stab_str := allstabstring;
  4662. asmList.concat(Tai_stabs.Create(stab_str));
  4663. typesym:=oldtypesym;
  4664. end
  4665. else
  4666. inherited concatstabto(asmlist);
  4667. end;
  4668. {$endif GDB}
  4669. function tobjectdef.needs_inittable : boolean;
  4670. begin
  4671. case objecttype of
  4672. odt_class :
  4673. needs_inittable:=false;
  4674. odt_interfacecom:
  4675. needs_inittable:=true;
  4676. odt_interfacecorba:
  4677. needs_inittable:=is_related(interface_iunknown);
  4678. odt_object:
  4679. needs_inittable:=tobjectsymtable(symtable).needs_init_final;
  4680. else
  4681. internalerror(200108267);
  4682. end;
  4683. end;
  4684. function tobjectdef.members_need_inittable : boolean;
  4685. begin
  4686. members_need_inittable:=tobjectsymtable(symtable).needs_init_final;
  4687. end;
  4688. procedure tobjectdef.count_published_properties(sym:tnamedindexitem;arg:pointer);
  4689. begin
  4690. if needs_prop_entry(tsym(sym)) and
  4691. (tsym(sym).typ<>varsym) then
  4692. inc(count);
  4693. end;
  4694. procedure tobjectdef.write_property_info(sym : tnamedindexitem;arg:pointer);
  4695. var
  4696. proctypesinfo : byte;
  4697. procedure writeproc(proc : tsymlist; shiftvalue : byte);
  4698. var
  4699. typvalue : byte;
  4700. hp : psymlistitem;
  4701. address : longint;
  4702. def : tdef;
  4703. begin
  4704. if not(assigned(proc) and assigned(proc.firstsym)) then
  4705. begin
  4706. rttiList.concat(Tai_const.create(ait_const_ptr,1));
  4707. typvalue:=3;
  4708. end
  4709. else if proc.firstsym^.sym.typ=varsym then
  4710. begin
  4711. address:=0;
  4712. hp:=proc.firstsym;
  4713. def:=nil;
  4714. while assigned(hp) do
  4715. begin
  4716. case hp^.sltype of
  4717. sl_load :
  4718. begin
  4719. def:=tvarsym(hp^.sym).vartype.def;
  4720. inc(address,tvarsym(hp^.sym).fieldoffset);
  4721. end;
  4722. sl_subscript :
  4723. begin
  4724. if not(assigned(def) and (def.deftype=recorddef)) then
  4725. internalerror(200402171);
  4726. inc(address,tvarsym(hp^.sym).fieldoffset);
  4727. def:=tvarsym(hp^.sym).vartype.def;
  4728. end;
  4729. sl_vec :
  4730. begin
  4731. if not(assigned(def) and (def.deftype=arraydef)) then
  4732. internalerror(200402172);
  4733. def:=tarraydef(def).elementtype.def;
  4734. inc(address,def.size*hp^.value);
  4735. end;
  4736. end;
  4737. hp:=hp^.next;
  4738. end;
  4739. rttiList.concat(Tai_const.create(ait_const_ptr,address));
  4740. typvalue:=0;
  4741. end
  4742. else
  4743. begin
  4744. { When there was an error then procdef is not assigned }
  4745. if not assigned(proc.procdef) then
  4746. exit;
  4747. if not(po_virtualmethod in tprocdef(proc.procdef).procoptions) then
  4748. begin
  4749. rttiList.concat(Tai_const.createname(tprocdef(proc.procdef).mangledname,AT_FUNCTION,0));
  4750. typvalue:=1;
  4751. end
  4752. else
  4753. begin
  4754. { virtual method, write vmt offset }
  4755. rttiList.concat(Tai_const.create(ait_const_ptr,
  4756. tprocdef(proc.procdef)._class.vmtmethodoffset(tprocdef(proc.procdef).extnumber)));
  4757. typvalue:=2;
  4758. end;
  4759. end;
  4760. proctypesinfo:=proctypesinfo or (typvalue shl shiftvalue);
  4761. end;
  4762. begin
  4763. if needs_prop_entry(tsym(sym)) then
  4764. case tsym(sym).typ of
  4765. varsym:
  4766. begin
  4767. {$ifdef dummy}
  4768. if not(tvarsym(sym).vartype.def.deftype=objectdef) or
  4769. not(tobjectdef(tvarsym(sym).vartype.def).is_class) then
  4770. internalerror(1509992);
  4771. { access to implicit class property as field }
  4772. proctypesinfo:=(0 shl 0) or (0 shl 2) or (0 shl 4);
  4773. rttiList.concat(Tai_const_symbol.Createname(tvarsym(sym.vartype.def.get_rtti_label),AT_DATA,0));
  4774. rttiList.concat(Tai_const.create(ait_const_ptr,tvarsym(sym.address)));
  4775. rttiList.concat(Tai_const.create(ait_const_ptr,tvarsym(sym.address)));
  4776. { by default stored }
  4777. rttiList.concat(Tai_const.Create_32bit(1));
  4778. { index as well as ... }
  4779. rttiList.concat(Tai_const.Create_32bit(0));
  4780. { default value are zero }
  4781. rttiList.concat(Tai_const.Create_32bit(0));
  4782. rttiList.concat(Tai_const.Create_16bit(count));
  4783. inc(count);
  4784. rttiList.concat(Tai_const.Create_8bit(proctypesinfo));
  4785. rttiList.concat(Tai_const.Create_8bit(length(tvarsym(sym.realname))));
  4786. rttiList.concat(Tai_string.Create(tvarsym(sym.realname)));
  4787. {$endif dummy}
  4788. end;
  4789. propertysym:
  4790. begin
  4791. if ppo_indexed in tpropertysym(sym).propoptions then
  4792. proctypesinfo:=$40
  4793. else
  4794. proctypesinfo:=0;
  4795. rttiList.concat(Tai_const.Create_sym(tstoreddef(tpropertysym(sym).proptype.def).get_rtti_label(fullrtti)));
  4796. writeproc(tpropertysym(sym).readaccess,0);
  4797. writeproc(tpropertysym(sym).writeaccess,2);
  4798. { isn't it stored ? }
  4799. if not(ppo_stored in tpropertysym(sym).propoptions) then
  4800. begin
  4801. rttiList.concat(Tai_const.create_sym(nil));
  4802. proctypesinfo:=proctypesinfo or (3 shl 4);
  4803. end
  4804. else
  4805. writeproc(tpropertysym(sym).storedaccess,4);
  4806. rttiList.concat(Tai_const.Create_32bit(tpropertysym(sym).index));
  4807. rttiList.concat(Tai_const.Create_32bit(tpropertysym(sym).default));
  4808. rttiList.concat(Tai_const.Create_16bit(count));
  4809. inc(count);
  4810. rttiList.concat(Tai_const.Create_8bit(proctypesinfo));
  4811. rttiList.concat(Tai_const.Create_8bit(length(tpropertysym(sym).realname)));
  4812. rttiList.concat(Tai_string.Create(tpropertysym(sym).realname));
  4813. end;
  4814. else internalerror(1509992);
  4815. end;
  4816. end;
  4817. procedure tobjectdef.generate_published_child_rtti(sym : tnamedindexitem;arg:pointer);
  4818. begin
  4819. if needs_prop_entry(tsym(sym)) then
  4820. begin
  4821. case tsym(sym).typ of
  4822. propertysym:
  4823. tstoreddef(tpropertysym(sym).proptype.def).get_rtti_label(fullrtti);
  4824. varsym:
  4825. tstoreddef(tvarsym(sym).vartype.def).get_rtti_label(fullrtti);
  4826. else
  4827. internalerror(1509991);
  4828. end;
  4829. end;
  4830. end;
  4831. procedure tobjectdef.write_child_rtti_data(rt:trttitype);
  4832. begin
  4833. FRTTIType:=rt;
  4834. case rt of
  4835. initrtti :
  4836. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}generate_field_rtti,nil);
  4837. fullrtti :
  4838. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}generate_published_child_rtti,nil);
  4839. else
  4840. internalerror(200108301);
  4841. end;
  4842. end;
  4843. type
  4844. tclasslistitem = class(TLinkedListItem)
  4845. index : longint;
  4846. p : tobjectdef;
  4847. end;
  4848. var
  4849. classtablelist : tlinkedlist;
  4850. tablecount : longint;
  4851. function searchclasstablelist(p : tobjectdef) : tclasslistitem;
  4852. var
  4853. hp : tclasslistitem;
  4854. begin
  4855. hp:=tclasslistitem(classtablelist.first);
  4856. while assigned(hp) do
  4857. if hp.p=p then
  4858. begin
  4859. searchclasstablelist:=hp;
  4860. exit;
  4861. end
  4862. else
  4863. hp:=tclasslistitem(hp.next);
  4864. searchclasstablelist:=nil;
  4865. end;
  4866. procedure tobjectdef.count_published_fields(sym:tnamedindexitem;arg:pointer);
  4867. var
  4868. hp : tclasslistitem;
  4869. begin
  4870. if needs_prop_entry(tsym(sym)) and
  4871. (tsym(sym).typ=varsym) then
  4872. begin
  4873. if tvarsym(sym).vartype.def.deftype<>objectdef then
  4874. internalerror(0206001);
  4875. hp:=searchclasstablelist(tobjectdef(tvarsym(sym).vartype.def));
  4876. if not(assigned(hp)) then
  4877. begin
  4878. hp:=tclasslistitem.create;
  4879. hp.p:=tobjectdef(tvarsym(sym).vartype.def);
  4880. hp.index:=tablecount;
  4881. classtablelist.concat(hp);
  4882. inc(tablecount);
  4883. end;
  4884. inc(count);
  4885. end;
  4886. end;
  4887. procedure tobjectdef.writefields(sym:tnamedindexitem;arg:pointer);
  4888. var
  4889. hp : tclasslistitem;
  4890. begin
  4891. if needs_prop_entry(tsym(sym)) and
  4892. (tsym(sym).typ=varsym) then
  4893. begin
  4894. rttiList.concat(Tai_const.Create_32bit(tvarsym(sym).fieldoffset));
  4895. hp:=searchclasstablelist(tobjectdef(tvarsym(sym).vartype.def));
  4896. if not(assigned(hp)) then
  4897. internalerror(0206002);
  4898. rttiList.concat(Tai_const.Create_16bit(hp.index));
  4899. rttiList.concat(Tai_const.Create_8bit(length(tvarsym(sym).realname)));
  4900. rttiList.concat(Tai_string.Create(tvarsym(sym).realname));
  4901. end;
  4902. end;
  4903. function tobjectdef.generate_field_table : tasmlabel;
  4904. var
  4905. fieldtable,
  4906. classtable : tasmlabel;
  4907. hp : tclasslistitem;
  4908. begin
  4909. classtablelist:=TLinkedList.Create;
  4910. objectlibrary.getdatalabel(fieldtable);
  4911. objectlibrary.getdatalabel(classtable);
  4912. count:=0;
  4913. tablecount:=0;
  4914. maybe_new_object_file(rttiList);
  4915. new_section(rttiList,sec_rodata,classtable.name,const_align(sizeof(aint)));
  4916. { fields }
  4917. symtable.foreach({$ifdef FPC}@{$endif}count_published_fields,nil);
  4918. rttiList.concat(Tai_label.Create(fieldtable));
  4919. rttiList.concat(Tai_const.Create_16bit(count));
  4920. rttiList.concat(Tai_const.Create_sym(classtable));
  4921. symtable.foreach({$ifdef FPC}@{$endif}writefields,nil);
  4922. { generate the class table }
  4923. rttilist.concat(tai_align.create(const_align(sizeof(aint))));
  4924. rttiList.concat(Tai_label.Create(classtable));
  4925. rttiList.concat(Tai_const.Create_16bit(tablecount));
  4926. hp:=tclasslistitem(classtablelist.first);
  4927. while assigned(hp) do
  4928. begin
  4929. rttiList.concat(Tai_const.Createname(tobjectdef(hp.p).vmt_mangledname,AT_DATA,0));
  4930. hp:=tclasslistitem(hp.next);
  4931. end;
  4932. generate_field_table:=fieldtable;
  4933. classtablelist.free;
  4934. end;
  4935. function tobjectdef.next_free_name_index : longint;
  4936. var
  4937. i : longint;
  4938. begin
  4939. if assigned(childof) and (oo_can_have_published in childof.objectoptions) then
  4940. i:=childof.next_free_name_index
  4941. else
  4942. i:=0;
  4943. count:=0;
  4944. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}count_published_properties,nil);
  4945. next_free_name_index:=i+count;
  4946. end;
  4947. procedure tobjectdef.write_rtti_data(rt:trttitype);
  4948. begin
  4949. case objecttype of
  4950. odt_class:
  4951. rttiList.concat(Tai_const.Create_8bit(tkclass));
  4952. odt_object:
  4953. rttiList.concat(Tai_const.Create_8bit(tkobject));
  4954. odt_interfacecom:
  4955. rttiList.concat(Tai_const.Create_8bit(tkinterface));
  4956. odt_interfacecorba:
  4957. rttiList.concat(Tai_const.Create_8bit(tkinterfaceCorba));
  4958. else
  4959. exit;
  4960. end;
  4961. { generate the name }
  4962. rttiList.concat(Tai_const.Create_8bit(length(objrealname^)));
  4963. rttiList.concat(Tai_string.Create(objrealname^));
  4964. case rt of
  4965. initrtti :
  4966. begin
  4967. rttiList.concat(Tai_const.Create_32bit(size));
  4968. if objecttype in [odt_class,odt_object] then
  4969. begin
  4970. count:=0;
  4971. FRTTIType:=rt;
  4972. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}count_field_rtti,nil);
  4973. rttiList.concat(Tai_const.Create_32bit(count));
  4974. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}write_field_rtti,nil);
  4975. end;
  4976. end;
  4977. fullrtti :
  4978. begin
  4979. if (oo_has_vmt in objectoptions) and
  4980. not(objecttype in [odt_interfacecom,odt_interfacecorba]) then
  4981. rttiList.concat(Tai_const.Createname(vmt_mangledname,AT_DATA,0))
  4982. else
  4983. rttiList.concat(Tai_const.create_sym(nil));
  4984. { write owner typeinfo }
  4985. if assigned(childof) and (oo_can_have_published in childof.objectoptions) then
  4986. rttiList.concat(Tai_const.Create_sym(childof.get_rtti_label(fullrtti)))
  4987. else
  4988. rttiList.concat(Tai_const.create_sym(nil));
  4989. { count total number of properties }
  4990. if assigned(childof) and (oo_can_have_published in childof.objectoptions) then
  4991. count:=childof.next_free_name_index
  4992. else
  4993. count:=0;
  4994. { write it }
  4995. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}count_published_properties,nil);
  4996. rttiList.concat(Tai_const.Create_16bit(count));
  4997. { write unit name }
  4998. rttiList.concat(Tai_const.Create_8bit(length(current_module.realmodulename^)));
  4999. rttiList.concat(Tai_string.Create(current_module.realmodulename^));
  5000. { write published properties count }
  5001. count:=0;
  5002. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}count_published_properties,nil);
  5003. rttiList.concat(Tai_const.Create_16bit(count));
  5004. { count is used to write nameindex }
  5005. { but we need an offset of the owner }
  5006. { to give each property an own slot }
  5007. if assigned(childof) and (oo_can_have_published in childof.objectoptions) then
  5008. count:=childof.next_free_name_index
  5009. else
  5010. count:=0;
  5011. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}write_property_info,nil);
  5012. end;
  5013. end;
  5014. end;
  5015. function tobjectdef.is_publishable : boolean;
  5016. begin
  5017. is_publishable:=objecttype in [odt_class,odt_interfacecom,odt_interfacecorba];
  5018. end;
  5019. {****************************************************************************
  5020. TIMPLEMENTEDINTERFACES
  5021. ****************************************************************************}
  5022. type
  5023. tnamemap = class(TNamedIndexItem)
  5024. newname: pstring;
  5025. constructor create(const aname, anewname: string);
  5026. destructor destroy; override;
  5027. end;
  5028. constructor tnamemap.create(const aname, anewname: string);
  5029. begin
  5030. inherited createname(name);
  5031. newname:=stringdup(anewname);
  5032. end;
  5033. destructor tnamemap.destroy;
  5034. begin
  5035. stringdispose(newname);
  5036. inherited destroy;
  5037. end;
  5038. type
  5039. tprocdefstore = class(TNamedIndexItem)
  5040. procdef: tprocdef;
  5041. constructor create(aprocdef: tprocdef);
  5042. end;
  5043. constructor tprocdefstore.create(aprocdef: tprocdef);
  5044. begin
  5045. inherited create;
  5046. procdef:=aprocdef;
  5047. end;
  5048. type
  5049. timplintfentry = class(TNamedIndexItem)
  5050. intf: tobjectdef;
  5051. intfderef : tderef;
  5052. ioffs: longint;
  5053. namemappings: tdictionary;
  5054. procdefs: TIndexArray;
  5055. constructor create(aintf: tobjectdef);
  5056. constructor create_deref(const d:tderef);
  5057. destructor destroy; override;
  5058. end;
  5059. constructor timplintfentry.create(aintf: tobjectdef);
  5060. begin
  5061. inherited create;
  5062. intf:=aintf;
  5063. ioffs:=-1;
  5064. namemappings:=nil;
  5065. procdefs:=nil;
  5066. end;
  5067. constructor timplintfentry.create_deref(const d:tderef);
  5068. begin
  5069. inherited create;
  5070. intf:=nil;
  5071. intfderef:=d;
  5072. ioffs:=-1;
  5073. namemappings:=nil;
  5074. procdefs:=nil;
  5075. end;
  5076. destructor timplintfentry.destroy;
  5077. begin
  5078. if assigned(namemappings) then
  5079. namemappings.free;
  5080. if assigned(procdefs) then
  5081. procdefs.free;
  5082. inherited destroy;
  5083. end;
  5084. constructor timplementedinterfaces.create;
  5085. begin
  5086. finterfaces:=tindexarray.create(1);
  5087. end;
  5088. destructor timplementedinterfaces.destroy;
  5089. begin
  5090. finterfaces.destroy;
  5091. end;
  5092. function timplementedinterfaces.count: longint;
  5093. begin
  5094. count:=finterfaces.count;
  5095. end;
  5096. procedure timplementedinterfaces.checkindex(intfindex: longint);
  5097. begin
  5098. if (intfindex<1) or (intfindex>count) then
  5099. InternalError(200006123);
  5100. end;
  5101. function timplementedinterfaces.interfaces(intfindex: longint): tobjectdef;
  5102. begin
  5103. checkindex(intfindex);
  5104. interfaces:=timplintfentry(finterfaces.search(intfindex)).intf;
  5105. end;
  5106. function timplementedinterfaces.interfacesderef(intfindex: longint): tderef;
  5107. begin
  5108. checkindex(intfindex);
  5109. interfacesderef:=timplintfentry(finterfaces.search(intfindex)).intfderef;
  5110. end;
  5111. function timplementedinterfaces.ioffsets(intfindex: longint): plongint;
  5112. begin
  5113. checkindex(intfindex);
  5114. ioffsets:=@timplintfentry(finterfaces.search(intfindex)).ioffs;
  5115. end;
  5116. function timplementedinterfaces.searchintf(def: tdef): longint;
  5117. var
  5118. i: longint;
  5119. begin
  5120. i:=1;
  5121. while (i<=count) and (tdef(interfaces(i))<>def) do inc(i);
  5122. if i<=count then
  5123. searchintf:=i
  5124. else
  5125. searchintf:=-1;
  5126. end;
  5127. procedure timplementedinterfaces.buildderef;
  5128. var
  5129. i: longint;
  5130. begin
  5131. for i:=1 to count do
  5132. with timplintfentry(finterfaces.search(i)) do
  5133. intfderef.build(intf);
  5134. end;
  5135. procedure timplementedinterfaces.deref;
  5136. var
  5137. i: longint;
  5138. begin
  5139. for i:=1 to count do
  5140. with timplintfentry(finterfaces.search(i)) do
  5141. intf:=tobjectdef(intfderef.resolve);
  5142. end;
  5143. procedure timplementedinterfaces.addintf_deref(const d:tderef);
  5144. begin
  5145. finterfaces.insert(timplintfentry.create_deref(d));
  5146. end;
  5147. procedure timplementedinterfaces.addintf(def: tdef);
  5148. begin
  5149. if not assigned(def) or (searchintf(def)<>-1) or (def.deftype<>objectdef) or
  5150. not (tobjectdef(def).objecttype in [odt_interfacecom,odt_interfacecorba]) then
  5151. internalerror(200006124);
  5152. finterfaces.insert(timplintfentry.create(tobjectdef(def)));
  5153. end;
  5154. procedure timplementedinterfaces.clearmappings;
  5155. var
  5156. i: longint;
  5157. begin
  5158. for i:=1 to count do
  5159. with timplintfentry(finterfaces.search(i)) do
  5160. begin
  5161. if assigned(namemappings) then
  5162. namemappings.free;
  5163. namemappings:=nil;
  5164. end;
  5165. end;
  5166. procedure timplementedinterfaces.addmappings(intfindex: longint; const name, newname: string);
  5167. begin
  5168. checkindex(intfindex);
  5169. with timplintfentry(finterfaces.search(intfindex)) do
  5170. begin
  5171. if not assigned(namemappings) then
  5172. namemappings:=tdictionary.create;
  5173. namemappings.insert(tnamemap.create(name,newname));
  5174. end;
  5175. end;
  5176. function timplementedinterfaces.getmappings(intfindex: longint; const name: string; var nextexist: pointer): string;
  5177. begin
  5178. checkindex(intfindex);
  5179. if not assigned(nextexist) then
  5180. with timplintfentry(finterfaces.search(intfindex)) do
  5181. begin
  5182. if assigned(namemappings) then
  5183. nextexist:=namemappings.search(name)
  5184. else
  5185. nextexist:=nil;
  5186. end;
  5187. if assigned(nextexist) then
  5188. begin
  5189. getmappings:=tnamemap(nextexist).newname^;
  5190. nextexist:=tnamemap(nextexist).listnext;
  5191. end
  5192. else
  5193. getmappings:='';
  5194. end;
  5195. procedure timplementedinterfaces.clearimplprocs;
  5196. var
  5197. i: longint;
  5198. begin
  5199. for i:=1 to count do
  5200. with timplintfentry(finterfaces.search(i)) do
  5201. begin
  5202. if assigned(procdefs) then
  5203. procdefs.free;
  5204. procdefs:=nil;
  5205. end;
  5206. end;
  5207. procedure timplementedinterfaces.addimplproc(intfindex: longint; procdef: tprocdef);
  5208. begin
  5209. checkindex(intfindex);
  5210. with timplintfentry(finterfaces.search(intfindex)) do
  5211. begin
  5212. if not assigned(procdefs) then
  5213. procdefs:=tindexarray.create(4);
  5214. procdefs.insert(tprocdefstore.create(procdef));
  5215. end;
  5216. end;
  5217. function timplementedinterfaces.implproccount(intfindex: longint): longint;
  5218. begin
  5219. checkindex(intfindex);
  5220. with timplintfentry(finterfaces.search(intfindex)) do
  5221. if assigned(procdefs) then
  5222. implproccount:=procdefs.count
  5223. else
  5224. implproccount:=0;
  5225. end;
  5226. function timplementedinterfaces.implprocs(intfindex: longint; procindex: longint): tprocdef;
  5227. begin
  5228. checkindex(intfindex);
  5229. with timplintfentry(finterfaces.search(intfindex)) do
  5230. if assigned(procdefs) then
  5231. implprocs:=tprocdefstore(procdefs.search(procindex)).procdef
  5232. else
  5233. internalerror(200006131);
  5234. end;
  5235. function timplementedinterfaces.isimplmergepossible(intfindex, remainindex: longint; var weight: longint): boolean;
  5236. var
  5237. possible: boolean;
  5238. i: longint;
  5239. iiep1: TIndexArray;
  5240. iiep2: TIndexArray;
  5241. begin
  5242. checkindex(intfindex);
  5243. checkindex(remainindex);
  5244. iiep1:=timplintfentry(finterfaces.search(intfindex)).procdefs;
  5245. iiep2:=timplintfentry(finterfaces.search(remainindex)).procdefs;
  5246. if not assigned(iiep1) then { empty interface is mergeable :-) }
  5247. begin
  5248. possible:=true;
  5249. weight:=0;
  5250. end
  5251. else
  5252. begin
  5253. possible:=assigned(iiep2) and (iiep1.count<=iiep2.count);
  5254. i:=1;
  5255. while (possible) and (i<=iiep1.count) do
  5256. begin
  5257. possible:=
  5258. (tprocdefstore(iiep1.search(i)).procdef=tprocdefstore(iiep2.search(i)).procdef);
  5259. inc(i);
  5260. end;
  5261. if possible then
  5262. weight:=iiep1.count;
  5263. end;
  5264. isimplmergepossible:=possible;
  5265. end;
  5266. {****************************************************************************
  5267. TFORWARDDEF
  5268. ****************************************************************************}
  5269. constructor tforwarddef.create(const s:string;const pos : tfileposinfo);
  5270. var
  5271. oldregisterdef : boolean;
  5272. begin
  5273. { never register the forwarddefs, they are disposed at the
  5274. end of the type declaration block }
  5275. oldregisterdef:=registerdef;
  5276. registerdef:=false;
  5277. inherited create;
  5278. registerdef:=oldregisterdef;
  5279. deftype:=forwarddef;
  5280. tosymname:=stringdup(s);
  5281. forwardpos:=pos;
  5282. end;
  5283. function tforwarddef.gettypename:string;
  5284. begin
  5285. gettypename:='unresolved forward to '+tosymname^;
  5286. end;
  5287. destructor tforwarddef.destroy;
  5288. begin
  5289. if assigned(tosymname) then
  5290. stringdispose(tosymname);
  5291. inherited destroy;
  5292. end;
  5293. {****************************************************************************
  5294. TERRORDEF
  5295. ****************************************************************************}
  5296. constructor terrordef.create;
  5297. begin
  5298. inherited create;
  5299. deftype:=errordef;
  5300. end;
  5301. {$ifdef GDB}
  5302. function terrordef.stabstring : pchar;
  5303. begin
  5304. stabstring:=strpnew('error'+numberstring);
  5305. end;
  5306. procedure terrordef.concatstabto(asmlist : taasmoutput);
  5307. begin
  5308. { No internal error needed, an normal error is already
  5309. thrown }
  5310. end;
  5311. {$endif GDB}
  5312. function terrordef.gettypename:string;
  5313. begin
  5314. gettypename:='<erroneous type>';
  5315. end;
  5316. function terrordef.getmangledparaname:string;
  5317. begin
  5318. getmangledparaname:='error';
  5319. end;
  5320. {****************************************************************************
  5321. Definition Helpers
  5322. ****************************************************************************}
  5323. function is_interfacecom(def: tdef): boolean;
  5324. begin
  5325. is_interfacecom:=
  5326. assigned(def) and
  5327. (def.deftype=objectdef) and
  5328. (tobjectdef(def).objecttype=odt_interfacecom);
  5329. end;
  5330. function is_interfacecorba(def: tdef): boolean;
  5331. begin
  5332. is_interfacecorba:=
  5333. assigned(def) and
  5334. (def.deftype=objectdef) and
  5335. (tobjectdef(def).objecttype=odt_interfacecorba);
  5336. end;
  5337. function is_interface(def: tdef): boolean;
  5338. begin
  5339. is_interface:=
  5340. assigned(def) and
  5341. (def.deftype=objectdef) and
  5342. (tobjectdef(def).objecttype in [odt_interfacecom,odt_interfacecorba]);
  5343. end;
  5344. function is_class(def: tdef): boolean;
  5345. begin
  5346. is_class:=
  5347. assigned(def) and
  5348. (def.deftype=objectdef) and
  5349. (tobjectdef(def).objecttype=odt_class);
  5350. end;
  5351. function is_object(def: tdef): boolean;
  5352. begin
  5353. is_object:=
  5354. assigned(def) and
  5355. (def.deftype=objectdef) and
  5356. (tobjectdef(def).objecttype=odt_object);
  5357. end;
  5358. function is_cppclass(def: tdef): boolean;
  5359. begin
  5360. is_cppclass:=
  5361. assigned(def) and
  5362. (def.deftype=objectdef) and
  5363. (tobjectdef(def).objecttype=odt_cppclass);
  5364. end;
  5365. function is_class_or_interface(def: tdef): boolean;
  5366. begin
  5367. is_class_or_interface:=
  5368. assigned(def) and
  5369. (def.deftype=objectdef) and
  5370. (tobjectdef(def).objecttype in [odt_class,odt_interfacecom,odt_interfacecorba]);
  5371. end;
  5372. end.
  5373. {
  5374. $Log$
  5375. Revision 1.254 2004-09-14 16:33:17 peter
  5376. * restart sorting of enums when deref is called, this is needed when
  5377. a unit is reloaded
  5378. Revision 1.253 2004/08/27 21:59:26 peter
  5379. browser disabled
  5380. uf_local_symtable ppu flag when a localsymtable is stored
  5381. Revision 1.252 2004/08/17 16:29:21 jonas
  5382. + padalgingment field for recordsymtables (saved by recorddefs)
  5383. + support for Macintosh PowerPC alignment (if the first field of a record
  5384. or union has an alignment > 4, then the record or union size must be
  5385. padded to a multiple of this size)
  5386. Revision 1.251 2004/08/15 15:05:16 peter
  5387. * fixed padding of records to alignment
  5388. Revision 1.250 2004/08/14 14:50:42 florian
  5389. * fixed several sparc alignment issues
  5390. + Jonas' inline node patch; non functional yet
  5391. Revision 1.249 2004/08/07 14:52:45 florian
  5392. * fixed web bug 3226: type p = type pointer;
  5393. Revision 1.248 2004/07/19 19:15:50 florian
  5394. * fixed funcret_paraloc writing in units
  5395. Revision 1.247 2004/07/14 21:37:41 olle
  5396. - removed unused types
  5397. Revision 1.246 2004/07/12 09:14:04 jonas
  5398. * inline procedures at the node tree level, but only under some very
  5399. limited circumstances for now (only procedures, and only if they have
  5400. no or only vs_out/vs_var parameters).
  5401. * fixed ppudump for inline procedures
  5402. * fixed ppudump for ppc
  5403. Revision 1.245 2004/07/09 22:17:32 peter
  5404. * revert has_localst patch
  5405. * replace aktstaticsymtable/aktglobalsymtable with current_module
  5406. Revision 1.244 2004/07/06 19:52:04 peter
  5407. * fix storing of localst in ppu
  5408. Revision 1.243 2004/06/20 08:55:30 florian
  5409. * logs truncated
  5410. Revision 1.242 2004/06/18 15:16:46 peter
  5411. * remove obsolete cardinal() typecasts
  5412. Revision 1.241 2004/06/16 20:07:09 florian
  5413. * dwarf branch merged
  5414. Revision 1.240 2004/05/25 18:51:14 peter
  5415. * range check error
  5416. Revision 1.239 2004/05/23 20:57:10 peter
  5417. * removed unused voidprocdef
  5418. Revision 1.238 2004/05/23 15:23:30 peter
  5419. * fixed qword(longint) that removed sign from the number
  5420. * removed code in the compiler that relied on wrong qword(longint)
  5421. code generation
  5422. }