symdef.pas 192 KB

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