symdef.pas 172 KB

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