symdef.pas 171 KB

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