symdef.pas 175 KB

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