symdef.pas 173 KB

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