symdef.pas 170 KB

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