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