symdef.pas 189 KB

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