symdef.pas 174 KB

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