symdef.pas 192 KB

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