symdef.pas 172 KB

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