symdef.pas 175 KB

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