symdef.pas 175 KB

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