symdef.pas 193 KB

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