symdef.pas 171 KB

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