symdef.pas 189 KB

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