symdef.pas 176 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682
  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. is_cdecl : boolean;
  2792. begin
  2793. l:=0;
  2794. is_cdecl:=(proccalloption in [pocall_cdecl,pocall_cppdecl]);
  2795. pdc:=TParaItem(Para.first);
  2796. while assigned(pdc) do
  2797. begin
  2798. case pdc.paratyp of
  2799. vs_out,
  2800. vs_var : inc(l,POINTER_SIZE);
  2801. vs_value,
  2802. vs_const : if paramanager.push_addr_param(pdc.paratype.def,is_cdecl) then
  2803. inc(l,POINTER_SIZE)
  2804. else
  2805. inc(l,pdc.paratype.def.size);
  2806. end;
  2807. l:=align(l,alignsize);
  2808. pdc:=TParaItem(pdc.next);
  2809. end;
  2810. para_size:=l;
  2811. end;
  2812. function tabstractprocdef.typename_paras : string;
  2813. var
  2814. hs,s : string;
  2815. hp : TParaItem;
  2816. hpc : tconstsym;
  2817. begin
  2818. hp:=TParaItem(Para.last);
  2819. if not(assigned(hp)) then
  2820. begin
  2821. typename_paras:='';
  2822. exit;
  2823. end;
  2824. s:='(';
  2825. while assigned(hp) do
  2826. begin
  2827. if hp.paratyp=vs_var then
  2828. s:=s+'var'
  2829. else if hp.paratyp=vs_const then
  2830. s:=s+'const'
  2831. else if hp.paratyp=vs_out then
  2832. s:=s+'out';
  2833. if assigned(hp.paratype.def.typesym) then
  2834. begin
  2835. if hp.paratyp in [vs_var,vs_const,vs_out] then
  2836. s := s + ' ';
  2837. hs:=hp.paratype.def.typesym.realname;
  2838. if hs[1]<>'$' then
  2839. s:=s+hp.paratype.def.typesym.realname
  2840. else
  2841. s:=s+hp.paratype.def.gettypename;
  2842. end;
  2843. { default value }
  2844. if assigned(hp.defaultvalue) then
  2845. begin
  2846. hpc:=tconstsym(hp.defaultvalue);
  2847. hs:='';
  2848. case hpc.consttyp of
  2849. conststring,
  2850. constresourcestring :
  2851. hs:=strpas(pchar(hpc.valueptr));
  2852. constreal :
  2853. str(pbestreal(hpc.valueptr)^,hs);
  2854. constord :
  2855. hs:=tostr(hpc.valueord);
  2856. constpointer :
  2857. hs:=tostr(hpc.valueordptr);
  2858. constbool :
  2859. begin
  2860. if hpc.valueord<>0 then
  2861. hs:='TRUE'
  2862. else
  2863. hs:='FALSE';
  2864. end;
  2865. constnil :
  2866. hs:='nil';
  2867. constchar :
  2868. hs:=chr(hpc.valueord);
  2869. constset :
  2870. hs:='<set>';
  2871. end;
  2872. if hs<>'' then
  2873. s:=s+'="'+hs+'"';
  2874. end;
  2875. hp:=TParaItem(hp.previous);
  2876. if assigned(hp) then
  2877. s:=s+',';
  2878. end;
  2879. s:=s+')';
  2880. if (po_varargs in procoptions) then
  2881. s:=s+';VarArgs';
  2882. typename_paras:=s;
  2883. end;
  2884. {$ifdef GDB}
  2885. function tabstractprocdef.stabstring : pchar;
  2886. begin
  2887. stabstring := strpnew('abstractproc'+numberstring+';');
  2888. end;
  2889. procedure tabstractprocdef.concatstabto(asmlist : taasmoutput);
  2890. begin
  2891. if (not assigned(typesym) or ttypesym(typesym).isusedinstab or (cs_gdb_dbx in aktglobalswitches))
  2892. and (is_def_stab_written = not_written) then
  2893. begin
  2894. if assigned(rettype.def) then forcestabto(asmlist,rettype.def);
  2895. inherited concatstabto(asmlist);
  2896. end;
  2897. end;
  2898. {$endif GDB}
  2899. {***************************************************************************
  2900. TPROCDEF
  2901. ***************************************************************************}
  2902. constructor tprocdef.create;
  2903. begin
  2904. inherited create;
  2905. deftype:=procdef;
  2906. has_mangledname:=false;
  2907. _mangledname:=nil;
  2908. fileinfo:=aktfilepos;
  2909. extnumber:=$ffff;
  2910. aliasnames:=tstringlist.create;
  2911. localst:=tlocalsymtable.create;
  2912. parast:=tparasymtable.create;
  2913. funcretsym:=nil;
  2914. localst.defowner:=self;
  2915. parast.defowner:=self;
  2916. { this is used by insert
  2917. to check same names in parast and localst }
  2918. localst.next:=parast;
  2919. defref:=nil;
  2920. crossref:=nil;
  2921. lastwritten:=nil;
  2922. refcount:=0;
  2923. if (cs_browser in aktmoduleswitches) and make_ref then
  2924. begin
  2925. defref:=tref.create(defref,@akttokenpos);
  2926. inc(refcount);
  2927. end;
  2928. lastref:=defref;
  2929. { first, we assume that all registers are used }
  2930. usedregisters:=ALL_REGISTERS;
  2931. forwarddef:=true;
  2932. interfacedef:=false;
  2933. hasforward:=false;
  2934. _class := nil;
  2935. code:=nil;
  2936. regvarinfo := nil;
  2937. overloadnumber:=0;
  2938. {$ifdef GDB}
  2939. isstabwritten := false;
  2940. {$endif GDB}
  2941. end;
  2942. constructor tprocdef.ppuload(ppufile:tcompilerppufile);
  2943. begin
  2944. inherited ppuload(ppufile);
  2945. deftype:=procdef;
  2946. ppufile.getnormalset(usedregisters);
  2947. has_mangledname:=boolean(ppufile.getbyte);
  2948. if has_mangledname then
  2949. _mangledname:=stringdup(ppufile.getstring)
  2950. else
  2951. _mangledname:=nil;
  2952. overloadnumber:=ppufile.getword;
  2953. extnumber:=ppufile.getword;
  2954. _class := tobjectdef(ppufile.getderef);
  2955. procsym := tsym(ppufile.getderef);
  2956. ppufile.getposinfo(fileinfo);
  2957. { inline stuff }
  2958. if proccalloption=pocall_inline then
  2959. begin
  2960. funcretsym:=tsym(ppufile.getderef);
  2961. code:=ppuloadnode(ppufile);
  2962. end
  2963. else
  2964. begin
  2965. code := nil;
  2966. funcretsym:=nil;
  2967. end;
  2968. { load para and local symtables }
  2969. parast:=tparasymtable.create;
  2970. tparasymtable(parast).ppuload(ppufile);
  2971. parast.defowner:=self;
  2972. if (proccalloption=pocall_inline) or
  2973. ((current_module.flags and uf_local_browser)<>0) then
  2974. begin
  2975. localst:=tlocalsymtable.create;
  2976. tlocalsymtable(localst).ppuload(ppufile);
  2977. localst.defowner:=self;
  2978. end
  2979. else
  2980. localst:=nil;
  2981. { default values for no persistent data }
  2982. if (cs_link_deffile in aktglobalswitches) and
  2983. (tf_need_export in target_info.flags) and
  2984. (po_exports in procoptions) then
  2985. deffile.AddExport(mangledname);
  2986. aliasnames:=tstringlist.create;
  2987. forwarddef:=false;
  2988. interfacedef:=false;
  2989. hasforward:=false;
  2990. regvarinfo := nil;
  2991. lastref:=nil;
  2992. lastwritten:=nil;
  2993. defref:=nil;
  2994. refcount:=0;
  2995. {$ifdef GDB}
  2996. isstabwritten := false;
  2997. {$endif GDB}
  2998. end;
  2999. destructor tprocdef.destroy;
  3000. begin
  3001. if assigned(defref) then
  3002. begin
  3003. defref.freechain;
  3004. defref.free;
  3005. end;
  3006. aliasnames.free;
  3007. if assigned(parast) then
  3008. parast.free;
  3009. if assigned(localst) and (localst.symtabletype<>staticsymtable) then
  3010. localst.free;
  3011. if (proccalloption=pocall_inline) and assigned(code) then
  3012. tnode(code).free;
  3013. if assigned(regvarinfo) then
  3014. dispose(pregvarinfo(regvarinfo));
  3015. if (po_msgstr in procoptions) then
  3016. strdispose(messageinf.str);
  3017. if assigned(_mangledname) then
  3018. stringdispose(_mangledname);
  3019. inherited destroy;
  3020. end;
  3021. procedure tprocdef.ppuwrite(ppufile:tcompilerppufile);
  3022. var
  3023. oldintfcrc : boolean;
  3024. begin
  3025. inherited ppuwrite(ppufile);
  3026. oldintfcrc:=ppufile.do_interface_crc;
  3027. ppufile.do_interface_crc:=false;
  3028. { set all registers to used for simplified compilation PM }
  3029. if simplify_ppu then
  3030. begin
  3031. usedregisters:=ALL_REGISTERS;
  3032. end;
  3033. ppufile.putnormalset(usedregisters);
  3034. ppufile.do_interface_crc:=oldintfcrc;
  3035. ppufile.putbyte(byte(has_mangledname));
  3036. if has_mangledname then
  3037. ppufile.putstring(mangledname);
  3038. ppufile.putword(overloadnumber);
  3039. ppufile.putword(extnumber);
  3040. ppufile.putderef(_class);
  3041. ppufile.putderef(procsym);
  3042. ppufile.putposinfo(fileinfo);
  3043. { inline stuff references to localsymtable, no influence
  3044. on the crc }
  3045. oldintfcrc:=ppufile.do_crc;
  3046. ppufile.do_crc:=false;
  3047. { inline stuff }
  3048. if proccalloption=pocall_inline then
  3049. begin
  3050. ppufile.putderef(funcretsym);
  3051. ppuwritenode(ppufile,code);
  3052. end;
  3053. ppufile.do_crc:=oldintfcrc;
  3054. { write this entry }
  3055. ppufile.writeentry(ibprocdef);
  3056. { Save the para symtable, this is taken from the interface }
  3057. if not assigned(parast) then
  3058. begin
  3059. parast:=tparasymtable.create;
  3060. parast.defowner:=self;
  3061. end;
  3062. tparasymtable(parast).ppuwrite(ppufile);
  3063. { save localsymtable for inline procedures or when local
  3064. browser info is requested, this has no influence on the crc }
  3065. if (proccalloption=pocall_inline) or
  3066. ((current_module.flags and uf_local_browser)<>0) then
  3067. begin
  3068. oldintfcrc:=ppufile.do_crc;
  3069. ppufile.do_crc:=false;
  3070. if not assigned(localst) then
  3071. begin
  3072. localst:=tlocalsymtable.create;
  3073. localst.defowner:=self;
  3074. end;
  3075. tlocalsymtable(localst).ppuwrite(ppufile);
  3076. ppufile.do_crc:=oldintfcrc;
  3077. end;
  3078. end;
  3079. function tprocdef.fullprocname:string;
  3080. var
  3081. s : string;
  3082. begin
  3083. s:='';
  3084. if assigned(_class) then
  3085. s:=_class.objrealname^+'.';
  3086. s:=s+procsym.realname+typename_paras;
  3087. fullprocname:=s;
  3088. end;
  3089. function tprocdef.fullprocnamewithret:string;
  3090. var
  3091. s : string;
  3092. begin
  3093. s:=fullprocname;
  3094. if assigned(rettype.def) and
  3095. not(is_equal(rettype.def,voidtype.def)) then
  3096. s:=s+' : '+rettype.def.gettypename;
  3097. fullprocnamewithret:=s;
  3098. end;
  3099. function tprocdef.getsymtable(t:tgetsymtable):tsymtable;
  3100. begin
  3101. case t of
  3102. gs_local :
  3103. getsymtable:=localst;
  3104. gs_para :
  3105. getsymtable:=parast;
  3106. else
  3107. getsymtable:=nil;
  3108. end;
  3109. end;
  3110. procedure tprocdef.load_references(ppufile:tcompilerppufile;locals:boolean);
  3111. var
  3112. pos : tfileposinfo;
  3113. move_last : boolean;
  3114. begin
  3115. move_last:=lastwritten=lastref;
  3116. while (not ppufile.endofentry) do
  3117. begin
  3118. ppufile.getposinfo(pos);
  3119. inc(refcount);
  3120. lastref:=tref.create(lastref,@pos);
  3121. lastref.is_written:=true;
  3122. if refcount=1 then
  3123. defref:=lastref;
  3124. end;
  3125. if move_last then
  3126. lastwritten:=lastref;
  3127. if ((current_module.flags and uf_local_browser)<>0) and
  3128. locals then
  3129. begin
  3130. tparasymtable(parast).load_references(ppufile,locals);
  3131. tlocalsymtable(localst).load_references(ppufile,locals);
  3132. end;
  3133. end;
  3134. Const
  3135. local_symtable_index : longint = $8001;
  3136. function tprocdef.write_references(ppufile:tcompilerppufile;locals:boolean):boolean;
  3137. var
  3138. ref : tref;
  3139. pdo : tobjectdef;
  3140. move_last : boolean;
  3141. begin
  3142. move_last:=lastwritten=lastref;
  3143. if move_last and
  3144. (((current_module.flags and uf_local_browser)=0) or
  3145. not locals) then
  3146. exit;
  3147. { write address of this symbol }
  3148. ppufile.putderef(self);
  3149. { write refs }
  3150. if assigned(lastwritten) then
  3151. ref:=lastwritten
  3152. else
  3153. ref:=defref;
  3154. while assigned(ref) do
  3155. begin
  3156. if ref.moduleindex=current_module.unit_index then
  3157. begin
  3158. ppufile.putposinfo(ref.posinfo);
  3159. ref.is_written:=true;
  3160. if move_last then
  3161. lastwritten:=ref;
  3162. end
  3163. else if not ref.is_written then
  3164. move_last:=false
  3165. else if move_last then
  3166. lastwritten:=ref;
  3167. ref:=ref.nextref;
  3168. end;
  3169. ppufile.writeentry(ibdefref);
  3170. write_references:=true;
  3171. if ((current_module.flags and uf_local_browser)<>0) and
  3172. locals then
  3173. begin
  3174. pdo:=_class;
  3175. if (owner.symtabletype<>localsymtable) then
  3176. while assigned(pdo) do
  3177. begin
  3178. if pdo.symtable<>aktrecordsymtable then
  3179. begin
  3180. pdo.symtable.unitid:=local_symtable_index;
  3181. inc(local_symtable_index);
  3182. end;
  3183. pdo:=pdo.childof;
  3184. end;
  3185. parast.unitid:=local_symtable_index;
  3186. inc(local_symtable_index);
  3187. localst.unitid:=local_symtable_index;
  3188. inc(local_symtable_index);
  3189. tstoredsymtable(parast).write_references(ppufile,locals);
  3190. tstoredsymtable(localst).write_references(ppufile,locals);
  3191. { decrement for }
  3192. local_symtable_index:=local_symtable_index-2;
  3193. pdo:=_class;
  3194. if (owner.symtabletype<>localsymtable) then
  3195. while assigned(pdo) do
  3196. begin
  3197. if pdo.symtable<>aktrecordsymtable then
  3198. dec(local_symtable_index);
  3199. pdo:=pdo.childof;
  3200. end;
  3201. end;
  3202. end;
  3203. function tprocdef.haspara:boolean;
  3204. begin
  3205. haspara:=assigned(parast.symindex.first);
  3206. end;
  3207. {$ifdef GDB}
  3208. {$ifdef unused}
  3209. { procedure addparaname(p : tsym);
  3210. var vs : char;
  3211. begin
  3212. if tvarsym(p).varspez = vs_value then vs := '1'
  3213. else vs := '0';
  3214. strpcopy(strend(StabRecString),p^.name+':'+tstoreddef(tvarsym(p).vartype.def).numberstring+','+vs+';');
  3215. end; }
  3216. function tprocdef.stabstring : pchar;
  3217. var
  3218. i : longint;
  3219. stabrecstring : pchar;
  3220. begin
  3221. getmem(StabRecString,1024);
  3222. strpcopy(StabRecString,'f'+tstoreddef(rettype.def).numberstring);
  3223. i:=maxparacount;
  3224. if i>0 then
  3225. begin
  3226. strpcopy(strend(StabRecString),','+tostr(i)+';');
  3227. (* confuse gdb !! PM
  3228. if assigned(parast) then
  3229. parast.foreach({$ifdef FPCPROCVAR}@{$endif}addparaname)
  3230. else
  3231. begin
  3232. param := para1;
  3233. i := 0;
  3234. while assigned(param) do
  3235. begin
  3236. inc(i);
  3237. if param^.paratyp = vs_value then vartyp := '1' else vartyp := '0';
  3238. {Here we have lost the parameter names !!}
  3239. {using lower case parameters }
  3240. strpcopy(strend(stabrecstring),'p'+tostr(i)
  3241. +':'+param^.paratype.def.numberstring+','+vartyp+';');
  3242. param := param^.next;
  3243. end;
  3244. end; *)
  3245. {strpcopy(strend(StabRecString),';');}
  3246. end;
  3247. stabstring := strnew(stabrecstring);
  3248. freemem(stabrecstring,1024);
  3249. end;
  3250. {$endif unused}
  3251. function tprocdef.stabstring: pchar;
  3252. Var RType : Char;
  3253. Obj,Info : String;
  3254. stabsstr : string;
  3255. p : pchar;
  3256. begin
  3257. obj := procsym.name;
  3258. info := '';
  3259. if tprocsym(procsym).is_global then
  3260. RType := 'F'
  3261. else
  3262. RType := 'f';
  3263. if assigned(owner) then
  3264. begin
  3265. if (owner.symtabletype = objectsymtable) then
  3266. obj := upper(owner.name^)+'__'+procsym.name;
  3267. { this code was correct only as long as the local symboltable
  3268. of the parent had the same name as the function
  3269. but this is no true anymore !! PM
  3270. if (owner.symtabletype=localsymtable) and assigned(owner.name) then
  3271. info := ','+name+','+owner.name^; }
  3272. if (owner.symtabletype=localsymtable) and
  3273. assigned(owner.defowner) and
  3274. assigned(tprocdef(owner.defowner).procsym) then
  3275. info := ','+procsym.name+','+tprocdef(owner.defowner).procsym.name;
  3276. end;
  3277. stabsstr:=mangledname;
  3278. getmem(p,length(stabsstr)+255);
  3279. strpcopy(p,'"'+obj+':'+RType
  3280. +tstoreddef(rettype.def).numberstring+info+'",'+tostr(n_function)
  3281. +',0,'+
  3282. tostr(fileinfo.line)
  3283. +',');
  3284. strpcopy(strend(p),stabsstr);
  3285. stabstring:=strnew(p);
  3286. freemem(p,length(stabsstr)+255);
  3287. end;
  3288. procedure tprocdef.concatstabto(asmlist : taasmoutput);
  3289. begin
  3290. if (proccalloption=pocall_internproc) then
  3291. exit;
  3292. if not isstabwritten then
  3293. asmList.concat(Tai_stabs.Create(stabstring));
  3294. isstabwritten := true;
  3295. if assigned(parast) then
  3296. tstoredsymtable(parast).concatstabto(asmlist);
  3297. { local type defs and vars should not be written
  3298. inside the main proc stab }
  3299. if assigned(localst) and
  3300. (lexlevel>main_program_level) then
  3301. tstoredsymtable(localst).concatstabto(asmlist);
  3302. is_def_stab_written := written;
  3303. end;
  3304. {$endif GDB}
  3305. procedure tprocdef.deref;
  3306. var
  3307. oldlocalsymtable : tsymtable;
  3308. begin
  3309. inherited deref;
  3310. resolvedef(pointer(_class));
  3311. { parast }
  3312. oldlocalsymtable:=aktlocalsymtable;
  3313. aktlocalsymtable:=parast;
  3314. tparasymtable(parast).deref;
  3315. aktlocalsymtable:=oldlocalsymtable;
  3316. { procsym that originaly defined this definition, should be in the
  3317. same symtable }
  3318. resolvesym(pointer(procsym));
  3319. end;
  3320. procedure tprocdef.derefimpl;
  3321. var
  3322. oldlocalsymtable : tsymtable;
  3323. begin
  3324. { locals }
  3325. if assigned(localst) then
  3326. begin
  3327. { localst }
  3328. oldlocalsymtable:=aktlocalsymtable;
  3329. aktlocalsymtable:=localst;
  3330. { we can deref both interface and implementation parts }
  3331. tlocalsymtable(localst).deref;
  3332. tlocalsymtable(localst).derefimpl;
  3333. aktlocalsymtable:=oldlocalsymtable;
  3334. { funcretsym, this is always located in the localst }
  3335. resolvesym(pointer(funcretsym));
  3336. end
  3337. else
  3338. begin
  3339. { safety }
  3340. funcretsym:=nil;
  3341. end;
  3342. { inline tree }
  3343. if (proccalloption=pocall_inline) then
  3344. code.derefimpl;
  3345. end;
  3346. function tprocdef.mangledname : string;
  3347. var
  3348. s : string;
  3349. hp : TParaItem;
  3350. begin
  3351. if assigned(_mangledname) then
  3352. begin
  3353. mangledname:=_mangledname^;
  3354. exit;
  3355. end;
  3356. { we need to use the symtable where the procsym is inserted,
  3357. because that is visible to the world }
  3358. s:=mangledname_prefix('',procsym.owner)+procsym.name+'$';
  3359. if overloadnumber>0 then
  3360. s:=s+tostr(overloadnumber)+'$';
  3361. { add parameter types }
  3362. hp:=TParaItem(Para.last);
  3363. while assigned(hp) do
  3364. begin
  3365. s:=s+hp.paratype.def.mangledparaname;
  3366. hp:=TParaItem(hp.previous);
  3367. if assigned(hp) then
  3368. s:=s+'$';
  3369. end;
  3370. _mangledname:=stringdup(s);
  3371. mangledname:=_mangledname^;
  3372. end;
  3373. function tprocdef.cplusplusmangledname : string;
  3374. function getcppparaname(p : tdef) : string;
  3375. const
  3376. ordtype2str : array[tbasetype] of string[2] = (
  3377. '',
  3378. 'Uc','Us','Ui','Us',
  3379. 'Sc','s','i','x',
  3380. 'b','b','b',
  3381. 'c','w');
  3382. var
  3383. s : string;
  3384. begin
  3385. case p.deftype of
  3386. orddef:
  3387. s:=ordtype2str[torddef(p).typ];
  3388. pointerdef:
  3389. s:='P'+getcppparaname(tpointerdef(p).pointertype.def);
  3390. else
  3391. internalerror(2103001);
  3392. end;
  3393. getcppparaname:=s;
  3394. end;
  3395. var
  3396. s,s2 : string;
  3397. param : TParaItem;
  3398. begin
  3399. s := procsym.realname;
  3400. if procsym.owner.symtabletype=objectsymtable then
  3401. begin
  3402. s2:=upper(tobjectdef(procsym.owner.defowner).typesym.realname);
  3403. case proctypeoption of
  3404. potype_destructor:
  3405. s:='_$_'+tostr(length(s2))+s2;
  3406. potype_constructor:
  3407. s:='___'+tostr(length(s2))+s2;
  3408. else
  3409. s:='_'+s+'__'+tostr(length(s2))+s2;
  3410. end;
  3411. end
  3412. else s:=s+'__';
  3413. s:=s+'F';
  3414. { concat modifiers }
  3415. { !!!!! }
  3416. { now we handle the parameters }
  3417. param := TParaItem(Para.first);
  3418. if assigned(param) then
  3419. while assigned(param) do
  3420. begin
  3421. s2:=getcppparaname(param.paratype.def);
  3422. if param.paratyp in [vs_var,vs_out] then
  3423. s2:='R'+s2;
  3424. s:=s+s2;
  3425. param:=TParaItem(param.next);
  3426. end
  3427. else
  3428. s:=s+'v';
  3429. cplusplusmangledname:=s;
  3430. end;
  3431. procedure tprocdef.setmangledname(const s : string);
  3432. begin
  3433. stringdispose(_mangledname);
  3434. _mangledname:=stringdup(s);
  3435. has_mangledname:=true;
  3436. end;
  3437. {***************************************************************************
  3438. TPROCVARDEF
  3439. ***************************************************************************}
  3440. constructor tprocvardef.create;
  3441. begin
  3442. inherited create;
  3443. deftype:=procvardef;
  3444. end;
  3445. constructor tprocvardef.ppuload(ppufile:tcompilerppufile);
  3446. begin
  3447. inherited ppuload(ppufile);
  3448. deftype:=procvardef;
  3449. end;
  3450. procedure tprocvardef.ppuwrite(ppufile:tcompilerppufile);
  3451. begin
  3452. { here we cannot get a real good value so just give something }
  3453. { plausible (PM) }
  3454. { a more secure way would be
  3455. to allways store in a temp }
  3456. if is_fpu(rettype.def) then
  3457. {$ifdef FAST_FPU}
  3458. fpu_used:=3
  3459. {$else : not FAST_FPU, i.e. SAFE_FPU}
  3460. fpu_used:={2}maxfpuregs
  3461. {$endif FAST_FPU}
  3462. else
  3463. fpu_used:=0;
  3464. inherited ppuwrite(ppufile);
  3465. ppufile.writeentry(ibprocvardef);
  3466. end;
  3467. function tprocvardef.size : longint;
  3468. begin
  3469. if (po_methodpointer in procoptions) then
  3470. size:=2*POINTER_SIZE
  3471. else
  3472. size:=POINTER_SIZE;
  3473. end;
  3474. {$ifdef GDB}
  3475. function tprocvardef.stabstring : pchar;
  3476. var
  3477. nss : pchar;
  3478. { i : longint; }
  3479. begin
  3480. { i := maxparacount; }
  3481. getmem(nss,1024);
  3482. { it is not a function but a function pointer !! (PM) }
  3483. strpcopy(nss,'*f'+tstoreddef(rettype.def).numberstring{+','+tostr(i)}+';');
  3484. { this confuses gdb !!
  3485. we should use 'F' instead of 'f' but
  3486. as we use c++ language mode
  3487. it does not like that either
  3488. Please do not remove this part
  3489. might be used once
  3490. gdb for pascal is ready PM }
  3491. (*
  3492. param := para1;
  3493. i := 0;
  3494. while assigned(param) do
  3495. begin
  3496. inc(i);
  3497. if param^.paratyp = vs_value then vartyp := '1' else vartyp := '0';
  3498. {Here we have lost the parameter names !!}
  3499. pst := strpnew('p'+tostr(i)+':'+param^.paratype.def.numberstring+','+vartyp+';');
  3500. strcat(nss,pst);
  3501. strdispose(pst);
  3502. param := param^.next;
  3503. end; *)
  3504. {strpcopy(strend(nss),';');}
  3505. stabstring := strnew(nss);
  3506. freemem(nss,1024);
  3507. end;
  3508. procedure tprocvardef.concatstabto(asmlist : taasmoutput);
  3509. begin
  3510. if ( not assigned(typesym) or ttypesym(typesym).isusedinstab or (cs_gdb_dbx in aktglobalswitches))
  3511. and (is_def_stab_written = not_written) then
  3512. inherited concatstabto(asmlist);
  3513. is_def_stab_written:=written;
  3514. end;
  3515. {$endif GDB}
  3516. procedure tprocvardef.write_rtti_data(rt:trttitype);
  3517. var
  3518. pdc : TParaItem;
  3519. methodkind, paraspec : byte;
  3520. begin
  3521. if po_methodpointer in procoptions then
  3522. begin
  3523. { write method id and name }
  3524. rttiList.concat(Tai_const.Create_8bit(tkmethod));
  3525. write_rtti_name;
  3526. { write kind of method (can only be function or procedure)}
  3527. if rettype.def = voidtype.def then
  3528. methodkind := mkProcedure
  3529. else
  3530. methodkind := mkFunction;
  3531. rttiList.concat(Tai_const.Create_8bit(methodkind));
  3532. { get # of parameters }
  3533. rttiList.concat(Tai_const.Create_8bit(maxparacount));
  3534. { write parameter info. The parameters must be written in reverse order
  3535. if this method uses right to left parameter pushing! }
  3536. if (po_leftright in procoptions) then
  3537. pdc:=TParaItem(Para.last)
  3538. else
  3539. pdc:=TParaItem(Para.first);
  3540. while assigned(pdc) do
  3541. begin
  3542. case pdc.paratyp of
  3543. vs_value: paraspec := 0;
  3544. vs_const: paraspec := pfConst;
  3545. vs_var : paraspec := pfVar;
  3546. vs_out : paraspec := pfOut;
  3547. end;
  3548. { write flags for current parameter }
  3549. rttiList.concat(Tai_const.Create_8bit(paraspec));
  3550. { write name of current parameter ### how can I get this??? (sg)}
  3551. rttiList.concat(Tai_const.Create_8bit(0));
  3552. { write name of type of current parameter }
  3553. tstoreddef(pdc.paratype.def).write_rtti_name;
  3554. if (po_leftright in procoptions) then
  3555. pdc:=TParaItem(pdc.previous)
  3556. else
  3557. pdc:=TParaItem(pdc.next);
  3558. end;
  3559. { write name of result type }
  3560. tstoreddef(rettype.def).write_rtti_name;
  3561. end;
  3562. end;
  3563. function tprocvardef.is_publishable : boolean;
  3564. begin
  3565. is_publishable:=(po_methodpointer in procoptions);
  3566. end;
  3567. function tprocvardef.gettypename : string;
  3568. var
  3569. s: string;
  3570. begin
  3571. if assigned(rettype.def) and
  3572. (rettype.def<>voidtype.def) then
  3573. s:='<procedure variable type of function'+typename_paras+
  3574. ':'+rettype.def.gettypename
  3575. else
  3576. s:='<procedure variable type of procedure'+typename_paras;
  3577. if po_methodpointer in procoptions then
  3578. s := s+' of object';
  3579. gettypename := s+';'+ProcCallOptionStr[proccalloption]+'>';
  3580. end;
  3581. {***************************************************************************
  3582. TOBJECTDEF
  3583. ***************************************************************************}
  3584. {$ifdef GDB}
  3585. const
  3586. vtabletype : word = 0;
  3587. vtableassigned : boolean = false;
  3588. {$endif GDB}
  3589. constructor tobjectdef.create(ot : tobjectdeftype;const n : string;c : tobjectdef);
  3590. begin
  3591. inherited create;
  3592. objecttype:=ot;
  3593. deftype:=objectdef;
  3594. objectoptions:=[];
  3595. childof:=nil;
  3596. symtable:=tobjectsymtable.create(n);
  3597. { create space for vmt !! }
  3598. vmt_offset:=0;
  3599. symtable.datasize:=0;
  3600. symtable.defowner:=self;
  3601. { recordalign -1 means C record packing, that starts
  3602. with an alignment of 1 }
  3603. if aktalignment.recordalignmax=-1 then
  3604. symtable.dataalignment:=1
  3605. else
  3606. symtable.dataalignment:=aktalignment.recordalignmax;
  3607. lastvtableindex:=0;
  3608. set_parent(c);
  3609. objname:=stringdup(upper(n));
  3610. objrealname:=stringdup(n);
  3611. { set up guid }
  3612. isiidguidvalid:=true; { default null guid }
  3613. fillchar(iidguid,sizeof(iidguid),0); { default null guid }
  3614. iidstr:=stringdup(''); { default is empty string }
  3615. { setup implemented interfaces }
  3616. if objecttype in [odt_class,odt_interfacecorba] then
  3617. implementedinterfaces:=timplementedinterfaces.create
  3618. else
  3619. implementedinterfaces:=nil;
  3620. {$ifdef GDB}
  3621. writing_class_record_stab:=false;
  3622. {$endif GDB}
  3623. end;
  3624. constructor tobjectdef.ppuload(ppufile:tcompilerppufile);
  3625. var
  3626. oldread_member : boolean;
  3627. i,implintfcount: longint;
  3628. begin
  3629. inherited ppuloaddef(ppufile);
  3630. deftype:=objectdef;
  3631. objecttype:=tobjectdeftype(ppufile.getbyte);
  3632. savesize:=ppufile.getlongint;
  3633. vmt_offset:=ppufile.getlongint;
  3634. objrealname:=stringdup(ppufile.getstring);
  3635. objname:=stringdup(upper(objrealname^));
  3636. childof:=tobjectdef(ppufile.getderef);
  3637. ppufile.getsmallset(objectoptions);
  3638. { load guid }
  3639. iidstr:=nil;
  3640. if objecttype in [odt_interfacecom,odt_interfacecorba] then
  3641. begin
  3642. isiidguidvalid:=boolean(ppufile.getbyte);
  3643. ppufile.getguid(iidguid);
  3644. iidstr:=stringdup(ppufile.getstring);
  3645. lastvtableindex:=ppufile.getlongint;
  3646. end;
  3647. { load implemented interfaces }
  3648. if objecttype in [odt_class,odt_interfacecorba] then
  3649. begin
  3650. implementedinterfaces:=timplementedinterfaces.create;
  3651. implintfcount:=ppufile.getlongint;
  3652. for i:=1 to implintfcount do
  3653. begin
  3654. implementedinterfaces.addintfref(ppufile.getderef);
  3655. implementedinterfaces.ioffsets(i)^:=ppufile.getlongint;
  3656. end;
  3657. end
  3658. else
  3659. implementedinterfaces:=nil;
  3660. oldread_member:=read_member;
  3661. read_member:=true;
  3662. symtable:=tobjectsymtable.create(objrealname^);
  3663. tobjectsymtable(symtable).ppuload(ppufile);
  3664. read_member:=oldread_member;
  3665. symtable.defowner:=self;
  3666. { handles the predefined class tobject }
  3667. { the last TOBJECT which is loaded gets }
  3668. { it ! }
  3669. if (childof=nil) and
  3670. (objecttype=odt_class) and
  3671. (objname^='TOBJECT') then
  3672. class_tobject:=self;
  3673. if (childof=nil) and
  3674. (objecttype=odt_interfacecom) and
  3675. (objname^='IUNKNOWN') then
  3676. interface_iunknown:=self;
  3677. {$ifdef GDB}
  3678. writing_class_record_stab:=false;
  3679. {$endif GDB}
  3680. end;
  3681. destructor tobjectdef.destroy;
  3682. begin
  3683. if assigned(symtable) then
  3684. symtable.free;
  3685. stringdispose(objname);
  3686. stringdispose(objrealname);
  3687. stringdispose(iidstr);
  3688. if assigned(implementedinterfaces) then
  3689. implementedinterfaces.free;
  3690. inherited destroy;
  3691. end;
  3692. procedure tobjectdef.ppuwrite(ppufile:tcompilerppufile);
  3693. var
  3694. oldread_member : boolean;
  3695. implintfcount : longint;
  3696. i : longint;
  3697. begin
  3698. inherited ppuwritedef(ppufile);
  3699. ppufile.putbyte(byte(objecttype));
  3700. ppufile.putlongint(size);
  3701. ppufile.putlongint(vmt_offset);
  3702. ppufile.putstring(objrealname^);
  3703. ppufile.putderef(childof);
  3704. ppufile.putsmallset(objectoptions);
  3705. if objecttype in [odt_interfacecom,odt_interfacecorba] then
  3706. begin
  3707. ppufile.putbyte(byte(isiidguidvalid));
  3708. ppufile.putguid(iidguid);
  3709. ppufile.putstring(iidstr^);
  3710. ppufile.putlongint(lastvtableindex);
  3711. end;
  3712. if objecttype in [odt_class,odt_interfacecorba] then
  3713. begin
  3714. implintfcount:=implementedinterfaces.count;
  3715. ppufile.putlongint(implintfcount);
  3716. for i:=1 to implintfcount do
  3717. begin
  3718. ppufile.putderef(implementedinterfaces.interfaces(i));
  3719. ppufile.putlongint(implementedinterfaces.ioffsets(i)^);
  3720. end;
  3721. end;
  3722. ppufile.writeentry(ibobjectdef);
  3723. oldread_member:=read_member;
  3724. read_member:=true;
  3725. tobjectsymtable(symtable).ppuwrite(ppufile);
  3726. read_member:=oldread_member;
  3727. end;
  3728. procedure tobjectdef.deref;
  3729. var
  3730. oldrecsyms : tsymtable;
  3731. begin
  3732. inherited deref;
  3733. resolvedef(pointer(childof));
  3734. oldrecsyms:=aktrecordsymtable;
  3735. aktrecordsymtable:=symtable;
  3736. tstoredsymtable(symtable).deref;
  3737. aktrecordsymtable:=oldrecsyms;
  3738. if objecttype in [odt_class,odt_interfacecorba] then
  3739. implementedinterfaces.deref;
  3740. end;
  3741. procedure tobjectdef.set_parent( c : tobjectdef);
  3742. begin
  3743. { nothing to do if the parent was not forward !}
  3744. if assigned(childof) then
  3745. exit;
  3746. childof:=c;
  3747. { some options are inherited !! }
  3748. if assigned(c) then
  3749. begin
  3750. { only important for classes }
  3751. lastvtableindex:=c.lastvtableindex;
  3752. objectoptions:=objectoptions+(c.objectoptions*
  3753. [oo_has_virtual,oo_has_private,oo_has_protected,
  3754. oo_has_constructor,oo_has_destructor]);
  3755. if not (objecttype in [odt_interfacecom,odt_interfacecorba]) then
  3756. begin
  3757. { add the data of the anchestor class }
  3758. inc(symtable.datasize,c.symtable.datasize);
  3759. if (oo_has_vmt in objectoptions) and
  3760. (oo_has_vmt in c.objectoptions) then
  3761. dec(symtable.datasize,POINTER_SIZE);
  3762. { if parent has a vmt field then
  3763. the offset is the same for the child PM }
  3764. if (oo_has_vmt in c.objectoptions) or is_class(self) then
  3765. begin
  3766. vmt_offset:=c.vmt_offset;
  3767. include(objectoptions,oo_has_vmt);
  3768. end;
  3769. end;
  3770. end;
  3771. savesize := symtable.datasize;
  3772. end;
  3773. procedure tobjectdef.insertvmt;
  3774. begin
  3775. if objecttype in [odt_interfacecom,odt_interfacecorba] then
  3776. exit;
  3777. if (oo_has_vmt in objectoptions) then
  3778. internalerror(12345)
  3779. else
  3780. begin
  3781. symtable.datasize:=align(symtable.datasize,symtable.dataalignment);
  3782. vmt_offset:=symtable.datasize;
  3783. inc(symtable.datasize,POINTER_SIZE);
  3784. include(objectoptions,oo_has_vmt);
  3785. end;
  3786. end;
  3787. procedure tobjectdef.check_forwards;
  3788. begin
  3789. if not(objecttype in [odt_interfacecom,odt_interfacecorba]) then
  3790. tstoredsymtable(symtable).check_forwards;
  3791. if (oo_is_forward in objectoptions) then
  3792. begin
  3793. { ok, in future, the forward can be resolved }
  3794. Message1(sym_e_class_forward_not_resolved,objrealname^);
  3795. exclude(objectoptions,oo_is_forward);
  3796. end;
  3797. end;
  3798. { true, if self inherits from d (or if they are equal) }
  3799. function tobjectdef.is_related(d : tobjectdef) : boolean;
  3800. var
  3801. hp : tobjectdef;
  3802. begin
  3803. hp:=self;
  3804. while assigned(hp) do
  3805. begin
  3806. if hp=d then
  3807. begin
  3808. is_related:=true;
  3809. exit;
  3810. end;
  3811. hp:=hp.childof;
  3812. end;
  3813. is_related:=false;
  3814. end;
  3815. (* procedure tobjectdef._searchdestructor(sym : tnamedindexitem;arg:pointer);
  3816. var
  3817. p : pprocdeflist;
  3818. begin
  3819. { if we found already a destructor, then we exit }
  3820. if assigned(sd) then
  3821. exit;
  3822. if tsym(sym).typ=procsym then
  3823. begin
  3824. p:=tprocsym(sym).defs;
  3825. while assigned(p) do
  3826. begin
  3827. if p^.def.proctypeoption=potype_destructor then
  3828. begin
  3829. sd:=p^.def;
  3830. exit;
  3831. end;
  3832. p:=p^.next;
  3833. end;
  3834. end;
  3835. end;*)
  3836. procedure Tobjectdef._searchdestructor(sym:Tnamedindexitem;arg:pointer);
  3837. begin
  3838. { if we found already a destructor, then we exit }
  3839. if (sd=nil) and (Tsym(sym).typ=procsym) then
  3840. sd:=Tprocsym(sym).search_procdef_bytype(potype_destructor);
  3841. end;
  3842. function tobjectdef.searchdestructor : tprocdef;
  3843. var
  3844. o : tobjectdef;
  3845. begin
  3846. searchdestructor:=nil;
  3847. o:=self;
  3848. sd:=nil;
  3849. while assigned(o) do
  3850. begin
  3851. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}_searchdestructor,nil);
  3852. if assigned(sd) then
  3853. begin
  3854. searchdestructor:=sd;
  3855. exit;
  3856. end;
  3857. o:=o.childof;
  3858. end;
  3859. end;
  3860. function tobjectdef.size : longint;
  3861. begin
  3862. if objecttype in [odt_class,odt_interfacecom,odt_interfacecorba] then
  3863. size:=POINTER_SIZE
  3864. else
  3865. size:=symtable.datasize;
  3866. end;
  3867. function tobjectdef.alignment:longint;
  3868. begin
  3869. alignment:=symtable.dataalignment;
  3870. end;
  3871. function tobjectdef.vmtmethodoffset(index:longint):longint;
  3872. begin
  3873. { for offset of methods for classes, see rtl/inc/objpash.inc }
  3874. case objecttype of
  3875. odt_class:
  3876. vmtmethodoffset:=(index+12)*POINTER_SIZE;
  3877. odt_interfacecom,odt_interfacecorba:
  3878. vmtmethodoffset:=index*POINTER_SIZE;
  3879. else
  3880. {$ifdef WITHDMT}
  3881. vmtmethodoffset:=(index+4)*POINTER_SIZE;
  3882. {$else WITHDMT}
  3883. vmtmethodoffset:=(index+3)*POINTER_SIZE;
  3884. {$endif WITHDMT}
  3885. end;
  3886. end;
  3887. function tobjectdef.vmt_mangledname : string;
  3888. begin
  3889. if not(oo_has_vmt in objectoptions) then
  3890. Message1(parser_object_has_no_vmt,objrealname^);
  3891. vmt_mangledname:=mangledname_prefix('VMT',owner)+objname^;
  3892. end;
  3893. function tobjectdef.rtti_name : string;
  3894. begin
  3895. rtti_name:=mangledname_prefix('RTTI',owner)+objname^;
  3896. end;
  3897. {$ifdef GDB}
  3898. procedure tobjectdef.addprocname(p :tnamedindexitem;arg:pointer);
  3899. var virtualind,argnames : string;
  3900. news, newrec : pchar;
  3901. pd,ipd : tprocdef;
  3902. lindex : longint;
  3903. para : TParaItem;
  3904. arglength : byte;
  3905. sp : char;
  3906. begin
  3907. If tsym(p).typ = procsym then
  3908. begin
  3909. pd := tprocsym(p).first_procdef;
  3910. { this will be used for full implementation of object stabs
  3911. not yet done }
  3912. ipd := Tprocsym(p).last_procdef;
  3913. if (po_virtualmethod in pd.procoptions) then
  3914. begin
  3915. lindex := pd.extnumber;
  3916. {doesnt seem to be necessary
  3917. lindex := lindex or $80000000;}
  3918. virtualind := '*'+tostr(lindex)+';'+ipd._class.classnumberstring+';'
  3919. end
  3920. else
  3921. virtualind := '.';
  3922. { used by gdbpas to recognize constructor and destructors }
  3923. if (pd.proctypeoption=potype_constructor) then
  3924. argnames:='__ct__'
  3925. else if (pd.proctypeoption=potype_destructor) then
  3926. argnames:='__dt__'
  3927. else
  3928. argnames := '';
  3929. { arguments are not listed here }
  3930. {we don't need another definition}
  3931. para := TParaItem(pd.Para.first);
  3932. while assigned(para) do
  3933. begin
  3934. if Para.paratype.def.deftype = formaldef then
  3935. begin
  3936. if Para.paratyp=vs_var then
  3937. argnames := argnames+'3var'
  3938. else if Para.paratyp=vs_const then
  3939. argnames:=argnames+'5const'
  3940. else if Para.paratyp=vs_out then
  3941. argnames:=argnames+'3out';
  3942. end
  3943. else
  3944. begin
  3945. { if the arg definition is like (v: ^byte;..
  3946. there is no sym attached to data !!! }
  3947. if assigned(Para.paratype.def.typesym) then
  3948. begin
  3949. arglength := length(Para.paratype.def.typesym.name);
  3950. argnames := argnames + tostr(arglength)+Para.paratype.def.typesym.name;
  3951. end
  3952. else
  3953. begin
  3954. argnames:=argnames+'11unnamedtype';
  3955. end;
  3956. end;
  3957. para := TParaItem(Para.next);
  3958. end;
  3959. ipd.is_def_stab_written := written;
  3960. { here 2A must be changed for private and protected }
  3961. { 0 is private 1 protected and 2 public }
  3962. if (sp_private in tsym(p).symoptions) then sp:='0'
  3963. else if (sp_protected in tsym(p).symoptions) then sp:='1'
  3964. else sp:='2';
  3965. newrec := strpnew(p.name+'::'+ipd.numberstring
  3966. +'=##'+tstoreddef(pd.rettype.def).numberstring+';:'+argnames+';'+sp+'A'
  3967. +virtualind+';');
  3968. { get spare place for a string at the end }
  3969. if strlen(StabRecString) + strlen(newrec) >= StabRecSize-256 then
  3970. begin
  3971. getmem(news,stabrecsize+memsizeinc);
  3972. strcopy(news,stabrecstring);
  3973. freemem(stabrecstring,stabrecsize);
  3974. stabrecsize:=stabrecsize+memsizeinc;
  3975. stabrecstring:=news;
  3976. end;
  3977. strcat(StabRecstring,newrec);
  3978. {freemem(newrec,memsizeinc); }
  3979. strdispose(newrec);
  3980. {This should be used for case !!
  3981. RecOffset := RecOffset + pd.size;}
  3982. end;
  3983. end;
  3984. function tobjectdef.stabstring : pchar;
  3985. var anc : tobjectdef;
  3986. oldrec : pchar;
  3987. oldrecsize,oldrecoffset : longint;
  3988. str_end : string;
  3989. begin
  3990. if not (objecttype=odt_class) or writing_class_record_stab then
  3991. begin
  3992. oldrec := stabrecstring;
  3993. oldrecsize:=stabrecsize;
  3994. stabrecsize:=memsizeinc;
  3995. GetMem(stabrecstring,stabrecsize);
  3996. strpcopy(stabRecString,'s'+tostr(symtable.datasize));
  3997. if assigned(childof) then
  3998. begin
  3999. {only one ancestor not virtual, public, at base offset 0 }
  4000. { !1 , 0 2 0 , }
  4001. strpcopy(strend(stabrecstring),'!1,020,'+childof.classnumberstring+';');
  4002. end;
  4003. {virtual table to implement yet}
  4004. OldRecOffset:=RecOffset;
  4005. RecOffset := 0;
  4006. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}addname,nil);
  4007. RecOffset:=OldRecOffset;
  4008. if (oo_has_vmt in objectoptions) then
  4009. if not assigned(childof) or not(oo_has_vmt in childof.objectoptions) then
  4010. begin
  4011. strpcopy(strend(stabrecstring),'$vf'+classnumberstring+':'+typeglobalnumber('vtblarray')
  4012. +','+tostr(vmt_offset*8)+';');
  4013. end;
  4014. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}addprocname,nil);
  4015. if (oo_has_vmt in objectoptions) then
  4016. begin
  4017. anc := self;
  4018. while assigned(anc.childof) and (oo_has_vmt in anc.childof.objectoptions) do
  4019. anc := anc.childof;
  4020. { just in case anc = self }
  4021. str_end:=';~%'+anc.classnumberstring+';';
  4022. end
  4023. else
  4024. str_end:=';';
  4025. strpcopy(strend(stabrecstring),str_end);
  4026. stabstring := strnew(StabRecString);
  4027. freemem(stabrecstring,stabrecsize);
  4028. stabrecstring := oldrec;
  4029. stabrecsize:=oldrecsize;
  4030. end
  4031. else
  4032. begin
  4033. stabstring:=strpnew('*'+classnumberstring);
  4034. end;
  4035. end;
  4036. procedure tobjectdef.set_globalnb;
  4037. begin
  4038. globalnb:=PglobalTypeCount^;
  4039. inc(PglobalTypeCount^);
  4040. { classes need two type numbers, the globalnb is set to the ptr }
  4041. if objecttype=odt_class then
  4042. begin
  4043. globalnb:=PGlobalTypeCount^;
  4044. inc(PglobalTypeCount^);
  4045. end;
  4046. end;
  4047. function tobjectdef.classnumberstring : string;
  4048. begin
  4049. { write stabs again if needed }
  4050. numberstring;
  4051. if objecttype=odt_class then
  4052. begin
  4053. dec(globalnb);
  4054. classnumberstring:=numberstring;
  4055. inc(globalnb);
  4056. end
  4057. else
  4058. classnumberstring:=numberstring;
  4059. end;
  4060. function tobjectdef.allstabstring : pchar;
  4061. var stabchar : string[2];
  4062. ss,st : pchar;
  4063. sname : string;
  4064. sym_line_no : longint;
  4065. begin
  4066. ss := stabstring;
  4067. getmem(st,strlen(ss)+512);
  4068. stabchar := 't';
  4069. if deftype in tagtypes then
  4070. stabchar := 'Tt';
  4071. if assigned(typesym) then
  4072. begin
  4073. sname := typesym.name;
  4074. sym_line_no:=typesym.fileinfo.line;
  4075. end
  4076. else
  4077. begin
  4078. sname := ' ';
  4079. sym_line_no:=0;
  4080. end;
  4081. if writing_class_record_stab then
  4082. strpcopy(st,'"'+sname+':'+stabchar+classnumberstring+'=')
  4083. else
  4084. strpcopy(st,'"'+sname+':'+stabchar+numberstring+'=');
  4085. strpcopy(strecopy(strend(st),ss),'",'+tostr(N_LSYM)+',0,'+tostr(sym_line_no)+',0');
  4086. allstabstring := strnew(st);
  4087. freemem(st,strlen(ss)+512);
  4088. strdispose(ss);
  4089. end;
  4090. procedure tobjectdef.concatstabto(asmlist : taasmoutput);
  4091. var st : pstring;
  4092. begin
  4093. if objecttype<>odt_class then
  4094. begin
  4095. inherited concatstabto(asmlist);
  4096. exit;
  4097. end;
  4098. if ((typesym=nil) or ttypesym(typesym).isusedinstab or (cs_gdb_dbx in aktglobalswitches)) and
  4099. (is_def_stab_written = not_written) then
  4100. begin
  4101. if globalnb=0 then
  4102. set_globalnb;
  4103. { Write the record class itself }
  4104. writing_class_record_stab:=true;
  4105. inherited concatstabto(asmlist);
  4106. writing_class_record_stab:=false;
  4107. { Write the invisible pointer class }
  4108. is_def_stab_written:=not_written;
  4109. if assigned(typesym) then
  4110. begin
  4111. st:=typesym.FName;
  4112. typesym.FName:=stringdup(' ');
  4113. end;
  4114. inherited concatstabto(asmlist);
  4115. if assigned(typesym) then
  4116. begin
  4117. stringdispose(typesym.FName);
  4118. typesym.FName:=st;
  4119. end;
  4120. end;
  4121. end;
  4122. {$endif GDB}
  4123. function tobjectdef.needs_inittable : boolean;
  4124. begin
  4125. case objecttype of
  4126. odt_class :
  4127. needs_inittable:=false;
  4128. odt_interfacecom:
  4129. needs_inittable:=true;
  4130. odt_interfacecorba:
  4131. needs_inittable:=is_related(interface_iunknown);
  4132. odt_object:
  4133. needs_inittable:=tobjectsymtable(symtable).needs_init_final;
  4134. else
  4135. internalerror(200108267);
  4136. end;
  4137. end;
  4138. procedure tobjectdef.count_published_properties(sym:tnamedindexitem;arg:pointer);
  4139. begin
  4140. if needs_prop_entry(tsym(sym)) and
  4141. (tsym(sym).typ<>varsym) then
  4142. inc(count);
  4143. end;
  4144. procedure tobjectdef.write_property_info(sym : tnamedindexitem;arg:pointer);
  4145. var
  4146. proctypesinfo : byte;
  4147. procedure writeproc(proc : tsymlist; shiftvalue : byte);
  4148. var
  4149. typvalue : byte;
  4150. hp : psymlistitem;
  4151. address : longint;
  4152. begin
  4153. if not(assigned(proc) and assigned(proc.firstsym)) then
  4154. begin
  4155. rttiList.concat(Tai_const.Create_32bit(1));
  4156. typvalue:=3;
  4157. end
  4158. else if proc.firstsym^.sym.typ=varsym then
  4159. begin
  4160. address:=0;
  4161. hp:=proc.firstsym;
  4162. while assigned(hp) do
  4163. begin
  4164. inc(address,tvarsym(hp^.sym).address);
  4165. hp:=hp^.next;
  4166. end;
  4167. rttiList.concat(Tai_const.Create_32bit(address));
  4168. typvalue:=0;
  4169. end
  4170. else
  4171. begin
  4172. if not(po_virtualmethod in tprocdef(proc.def).procoptions) then
  4173. begin
  4174. rttiList.concat(Tai_const_symbol.Createname(tprocdef(proc.def).mangledname));
  4175. typvalue:=1;
  4176. end
  4177. else
  4178. begin
  4179. { virtual method, write vmt offset }
  4180. rttiList.concat(Tai_const.Create_32bit(
  4181. tprocdef(proc.def)._class.vmtmethodoffset(tprocdef(proc.def).extnumber)));
  4182. typvalue:=2;
  4183. end;
  4184. end;
  4185. proctypesinfo:=proctypesinfo or (typvalue shl shiftvalue);
  4186. end;
  4187. begin
  4188. if needs_prop_entry(tsym(sym)) then
  4189. case tsym(sym).typ of
  4190. varsym:
  4191. begin
  4192. {$ifdef dummy}
  4193. if not(tvarsym(sym).vartype.def.deftype=objectdef) or
  4194. not(tobjectdef(tvarsym(sym).vartype.def).is_class) then
  4195. internalerror(1509992);
  4196. { access to implicit class property as field }
  4197. proctypesinfo:=(0 shl 0) or (0 shl 2) or (0 shl 4);
  4198. rttiList.concat(Tai_const_symbol.Createname(tvarsym(sym.vartype.def.get_rtti_label)));
  4199. rttiList.concat(Tai_const.Create_32bit(tvarsym(sym.address)));
  4200. rttiList.concat(Tai_const.Create_32bit(tvarsym(sym.address)));
  4201. { per default stored }
  4202. rttiList.concat(Tai_const.Create_32bit(1));
  4203. { index as well as ... }
  4204. rttiList.concat(Tai_const.Create_32bit(0));
  4205. { default value are zero }
  4206. rttiList.concat(Tai_const.Create_32bit(0));
  4207. rttiList.concat(Tai_const.Create_16bit(count));
  4208. inc(count);
  4209. rttiList.concat(Tai_const.Create_8bit(proctypesinfo));
  4210. rttiList.concat(Tai_const.Create_8bit(length(tvarsym(sym.realname))));
  4211. rttiList.concat(Tai_string.Create(tvarsym(sym.realname)));
  4212. {$endif dummy}
  4213. end;
  4214. propertysym:
  4215. begin
  4216. if ppo_indexed in tpropertysym(sym).propoptions then
  4217. proctypesinfo:=$40
  4218. else
  4219. proctypesinfo:=0;
  4220. rttiList.concat(Tai_const_symbol.Create(tstoreddef(tpropertysym(sym).proptype.def).get_rtti_label(fullrtti)));
  4221. writeproc(tpropertysym(sym).readaccess,0);
  4222. writeproc(tpropertysym(sym).writeaccess,2);
  4223. { isn't it stored ? }
  4224. if not(ppo_stored in tpropertysym(sym).propoptions) then
  4225. begin
  4226. rttiList.concat(Tai_const.Create_32bit(0));
  4227. proctypesinfo:=proctypesinfo or (3 shl 4);
  4228. end
  4229. else
  4230. writeproc(tpropertysym(sym).storedaccess,4);
  4231. rttiList.concat(Tai_const.Create_32bit(tpropertysym(sym).index));
  4232. rttiList.concat(Tai_const.Create_32bit(tpropertysym(sym).default));
  4233. rttiList.concat(Tai_const.Create_16bit(count));
  4234. inc(count);
  4235. rttiList.concat(Tai_const.Create_8bit(proctypesinfo));
  4236. rttiList.concat(Tai_const.Create_8bit(length(tpropertysym(sym).realname)));
  4237. rttiList.concat(Tai_string.Create(tpropertysym(sym).realname));
  4238. end;
  4239. else internalerror(1509992);
  4240. end;
  4241. end;
  4242. procedure tobjectdef.generate_published_child_rtti(sym : tnamedindexitem;arg:pointer);
  4243. begin
  4244. if needs_prop_entry(tsym(sym)) then
  4245. begin
  4246. case tsym(sym).typ of
  4247. propertysym:
  4248. tstoreddef(tpropertysym(sym).proptype.def).get_rtti_label(fullrtti);
  4249. varsym:
  4250. tstoreddef(tvarsym(sym).vartype.def).get_rtti_label(fullrtti);
  4251. else
  4252. internalerror(1509991);
  4253. end;
  4254. end;
  4255. end;
  4256. procedure tobjectdef.write_child_rtti_data(rt:trttitype);
  4257. begin
  4258. FRTTIType:=rt;
  4259. case rt of
  4260. initrtti :
  4261. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}generate_field_rtti,nil);
  4262. fullrtti :
  4263. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}generate_published_child_rtti,nil);
  4264. else
  4265. internalerror(200108301);
  4266. end;
  4267. end;
  4268. type
  4269. tclasslistitem = class(TLinkedListItem)
  4270. index : longint;
  4271. p : tobjectdef;
  4272. end;
  4273. var
  4274. classtablelist : tlinkedlist;
  4275. tablecount : longint;
  4276. function searchclasstablelist(p : tobjectdef) : tclasslistitem;
  4277. var
  4278. hp : tclasslistitem;
  4279. begin
  4280. hp:=tclasslistitem(classtablelist.first);
  4281. while assigned(hp) do
  4282. if hp.p=p then
  4283. begin
  4284. searchclasstablelist:=hp;
  4285. exit;
  4286. end
  4287. else
  4288. hp:=tclasslistitem(hp.next);
  4289. searchclasstablelist:=nil;
  4290. end;
  4291. procedure tobjectdef.count_published_fields(sym:tnamedindexitem;arg:pointer);
  4292. var
  4293. hp : tclasslistitem;
  4294. begin
  4295. if needs_prop_entry(tsym(sym)) and
  4296. (tsym(sym).typ=varsym) then
  4297. begin
  4298. if tvarsym(sym).vartype.def.deftype<>objectdef then
  4299. internalerror(0206001);
  4300. hp:=searchclasstablelist(tobjectdef(tvarsym(sym).vartype.def));
  4301. if not(assigned(hp)) then
  4302. begin
  4303. hp:=tclasslistitem.create;
  4304. hp.p:=tobjectdef(tvarsym(sym).vartype.def);
  4305. hp.index:=tablecount;
  4306. classtablelist.concat(hp);
  4307. inc(tablecount);
  4308. end;
  4309. inc(count);
  4310. end;
  4311. end;
  4312. procedure tobjectdef.writefields(sym:tnamedindexitem;arg:pointer);
  4313. var
  4314. hp : tclasslistitem;
  4315. begin
  4316. if needs_prop_entry(tsym(sym)) and
  4317. (tsym(sym).typ=varsym) then
  4318. begin
  4319. rttiList.concat(Tai_const.Create_32bit(tvarsym(sym).address));
  4320. hp:=searchclasstablelist(tobjectdef(tvarsym(sym).vartype.def));
  4321. if not(assigned(hp)) then
  4322. internalerror(0206002);
  4323. rttiList.concat(Tai_const.Create_16bit(hp.index));
  4324. rttiList.concat(Tai_const.Create_8bit(length(tvarsym(sym).realname)));
  4325. rttiList.concat(Tai_string.Create(tvarsym(sym).realname));
  4326. end;
  4327. end;
  4328. function tobjectdef.generate_field_table : tasmlabel;
  4329. var
  4330. fieldtable,
  4331. classtable : tasmlabel;
  4332. hp : tclasslistitem;
  4333. begin
  4334. classtablelist:=TLinkedList.Create;
  4335. objectlibrary.getdatalabel(fieldtable);
  4336. objectlibrary.getdatalabel(classtable);
  4337. count:=0;
  4338. tablecount:=0;
  4339. symtable.foreach({$ifdef FPC}@{$endif}count_published_fields,nil);
  4340. if (cs_create_smart in aktmoduleswitches) then
  4341. rttiList.concat(Tai_cut.Create);
  4342. rttiList.concat(Tai_label.Create(fieldtable));
  4343. rttiList.concat(Tai_const.Create_16bit(count));
  4344. rttiList.concat(Tai_const_symbol.Create(classtable));
  4345. symtable.foreach({$ifdef FPC}@{$endif}writefields,nil);
  4346. { generate the class table }
  4347. rttiList.concat(Tai_label.Create(classtable));
  4348. rttiList.concat(Tai_const.Create_16bit(tablecount));
  4349. hp:=tclasslistitem(classtablelist.first);
  4350. while assigned(hp) do
  4351. begin
  4352. rttiList.concat(Tai_const_symbol.Createname(tobjectdef(hp.p).vmt_mangledname));
  4353. hp:=tclasslistitem(hp.next);
  4354. end;
  4355. generate_field_table:=fieldtable;
  4356. classtablelist.free;
  4357. end;
  4358. function tobjectdef.next_free_name_index : longint;
  4359. var
  4360. i : longint;
  4361. begin
  4362. if assigned(childof) and (oo_can_have_published in childof.objectoptions) then
  4363. i:=childof.next_free_name_index
  4364. else
  4365. i:=0;
  4366. count:=0;
  4367. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}count_published_properties,nil);
  4368. next_free_name_index:=i+count;
  4369. end;
  4370. procedure tobjectdef.write_rtti_data(rt:trttitype);
  4371. begin
  4372. case objecttype of
  4373. odt_class:
  4374. rttiList.concat(Tai_const.Create_8bit(tkclass));
  4375. odt_object:
  4376. rttiList.concat(Tai_const.Create_8bit(tkobject));
  4377. odt_interfacecom:
  4378. rttiList.concat(Tai_const.Create_8bit(tkinterface));
  4379. odt_interfacecorba:
  4380. rttiList.concat(Tai_const.Create_8bit(tkinterfaceCorba));
  4381. else
  4382. exit;
  4383. end;
  4384. { generate the name }
  4385. rttiList.concat(Tai_const.Create_8bit(length(objrealname^)));
  4386. rttiList.concat(Tai_string.Create(objrealname^));
  4387. case rt of
  4388. initrtti :
  4389. begin
  4390. rttiList.concat(Tai_const.Create_32bit(size));
  4391. if objecttype in [odt_class,odt_object] then
  4392. begin
  4393. count:=0;
  4394. FRTTIType:=rt;
  4395. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}count_field_rtti,nil);
  4396. rttiList.concat(Tai_const.Create_32bit(count));
  4397. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}write_field_rtti,nil);
  4398. end;
  4399. end;
  4400. fullrtti :
  4401. begin
  4402. if objecttype in [odt_interfacecom,odt_interfacecorba] then
  4403. rttiList.concat(Tai_const.Create_32bit(0))
  4404. else
  4405. rttiList.concat(Tai_const_symbol.Createname(vmt_mangledname));
  4406. { write owner typeinfo }
  4407. if assigned(childof) and (oo_can_have_published in childof.objectoptions) then
  4408. rttiList.concat(Tai_const_symbol.Create(childof.get_rtti_label(fullrtti)))
  4409. else
  4410. rttiList.concat(Tai_const.Create_32bit(0));
  4411. { count total number of properties }
  4412. if assigned(childof) and (oo_can_have_published in childof.objectoptions) then
  4413. count:=childof.next_free_name_index
  4414. else
  4415. count:=0;
  4416. { write it }
  4417. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}count_published_properties,nil);
  4418. rttiList.concat(Tai_const.Create_16bit(count));
  4419. { write unit name }
  4420. rttiList.concat(Tai_const.Create_8bit(length(current_module.realmodulename^)));
  4421. rttiList.concat(Tai_string.Create(current_module.realmodulename^));
  4422. { write published properties count }
  4423. count:=0;
  4424. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}count_published_properties,nil);
  4425. rttiList.concat(Tai_const.Create_16bit(count));
  4426. { count is used to write nameindex }
  4427. { but we need an offset of the owner }
  4428. { to give each property an own slot }
  4429. if assigned(childof) and (oo_can_have_published in childof.objectoptions) then
  4430. count:=childof.next_free_name_index
  4431. else
  4432. count:=0;
  4433. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}write_property_info,nil);
  4434. end;
  4435. end;
  4436. end;
  4437. function tobjectdef.is_publishable : boolean;
  4438. begin
  4439. is_publishable:=objecttype in [odt_class,odt_interfacecom,odt_interfacecorba];
  4440. end;
  4441. {****************************************************************************
  4442. TIMPLEMENTEDINTERFACES
  4443. ****************************************************************************}
  4444. type
  4445. tnamemap = class(TNamedIndexItem)
  4446. newname: pstring;
  4447. constructor create(const aname, anewname: string);
  4448. destructor destroy; override;
  4449. end;
  4450. constructor tnamemap.create(const aname, anewname: string);
  4451. begin
  4452. inherited createname(name);
  4453. newname:=stringdup(anewname);
  4454. end;
  4455. destructor tnamemap.destroy;
  4456. begin
  4457. stringdispose(newname);
  4458. inherited destroy;
  4459. end;
  4460. type
  4461. tprocdefstore = class(TNamedIndexItem)
  4462. procdef: tprocdef;
  4463. constructor create(aprocdef: tprocdef);
  4464. end;
  4465. constructor tprocdefstore.create(aprocdef: tprocdef);
  4466. begin
  4467. inherited create;
  4468. procdef:=aprocdef;
  4469. end;
  4470. type
  4471. timplintfentry = class(TNamedIndexItem)
  4472. intf: tobjectdef;
  4473. ioffs: longint;
  4474. namemappings: tdictionary;
  4475. procdefs: TIndexArray;
  4476. constructor create(aintf: tobjectdef);
  4477. destructor destroy; override;
  4478. end;
  4479. constructor timplintfentry.create(aintf: tobjectdef);
  4480. begin
  4481. inherited create;
  4482. intf:=aintf;
  4483. ioffs:=-1;
  4484. namemappings:=nil;
  4485. procdefs:=nil;
  4486. end;
  4487. destructor timplintfentry.destroy;
  4488. begin
  4489. if assigned(namemappings) then
  4490. namemappings.free;
  4491. if assigned(procdefs) then
  4492. procdefs.free;
  4493. inherited destroy;
  4494. end;
  4495. constructor timplementedinterfaces.create;
  4496. begin
  4497. finterfaces:=tindexarray.create(1);
  4498. end;
  4499. destructor timplementedinterfaces.destroy;
  4500. begin
  4501. finterfaces.destroy;
  4502. end;
  4503. function timplementedinterfaces.count: longint;
  4504. begin
  4505. count:=finterfaces.count;
  4506. end;
  4507. procedure timplementedinterfaces.checkindex(intfindex: longint);
  4508. begin
  4509. if (intfindex<1) or (intfindex>count) then
  4510. InternalError(200006123);
  4511. end;
  4512. function timplementedinterfaces.interfaces(intfindex: longint): tobjectdef;
  4513. begin
  4514. checkindex(intfindex);
  4515. interfaces:=timplintfentry(finterfaces.search(intfindex)).intf;
  4516. end;
  4517. function timplementedinterfaces.ioffsets(intfindex: longint): plongint;
  4518. begin
  4519. checkindex(intfindex);
  4520. ioffsets:=@timplintfentry(finterfaces.search(intfindex)).ioffs;
  4521. end;
  4522. function timplementedinterfaces.searchintf(def: tdef): longint;
  4523. var
  4524. i: longint;
  4525. begin
  4526. i:=1;
  4527. while (i<=count) and (tdef(interfaces(i))<>def) do inc(i);
  4528. if i<=count then
  4529. searchintf:=i
  4530. else
  4531. searchintf:=-1;
  4532. end;
  4533. procedure timplementedinterfaces.deref;
  4534. var
  4535. i: longint;
  4536. begin
  4537. for i:=1 to count do
  4538. with timplintfentry(finterfaces.search(i)) do
  4539. resolvedef(pointer(intf));
  4540. end;
  4541. procedure timplementedinterfaces.addintfref(def: pointer);
  4542. begin
  4543. finterfaces.insert(timplintfentry.create(tobjectdef(def)));
  4544. end;
  4545. procedure timplementedinterfaces.addintf(def: tdef);
  4546. begin
  4547. if not assigned(def) or (searchintf(def)<>-1) or (def.deftype<>objectdef) or
  4548. not (tobjectdef(def).objecttype in [odt_interfacecom,odt_interfacecorba]) then
  4549. internalerror(200006124);
  4550. finterfaces.insert(timplintfentry.create(tobjectdef(def)));
  4551. end;
  4552. procedure timplementedinterfaces.clearmappings;
  4553. var
  4554. i: longint;
  4555. begin
  4556. for i:=1 to count do
  4557. with timplintfentry(finterfaces.search(i)) do
  4558. begin
  4559. if assigned(namemappings) then
  4560. namemappings.free;
  4561. namemappings:=nil;
  4562. end;
  4563. end;
  4564. procedure timplementedinterfaces.addmappings(intfindex: longint; const name, newname: string);
  4565. begin
  4566. checkindex(intfindex);
  4567. with timplintfentry(finterfaces.search(intfindex)) do
  4568. begin
  4569. if not assigned(namemappings) then
  4570. namemappings:=tdictionary.create;
  4571. namemappings.insert(tnamemap.create(name,newname));
  4572. end;
  4573. end;
  4574. function timplementedinterfaces.getmappings(intfindex: longint; const name: string; var nextexist: pointer): string;
  4575. begin
  4576. checkindex(intfindex);
  4577. if not assigned(nextexist) then
  4578. with timplintfentry(finterfaces.search(intfindex)) do
  4579. begin
  4580. if assigned(namemappings) then
  4581. nextexist:=namemappings.search(name)
  4582. else
  4583. nextexist:=nil;
  4584. end;
  4585. if assigned(nextexist) then
  4586. begin
  4587. getmappings:=tnamemap(nextexist).newname^;
  4588. nextexist:=tnamemap(nextexist).listnext;
  4589. end
  4590. else
  4591. getmappings:='';
  4592. end;
  4593. procedure timplementedinterfaces.clearimplprocs;
  4594. var
  4595. i: longint;
  4596. begin
  4597. for i:=1 to count do
  4598. with timplintfentry(finterfaces.search(i)) do
  4599. begin
  4600. if assigned(procdefs) then
  4601. procdefs.free;
  4602. procdefs:=nil;
  4603. end;
  4604. end;
  4605. procedure timplementedinterfaces.addimplproc(intfindex: longint; procdef: tprocdef);
  4606. begin
  4607. checkindex(intfindex);
  4608. with timplintfentry(finterfaces.search(intfindex)) do
  4609. begin
  4610. if not assigned(procdefs) then
  4611. procdefs:=tindexarray.create(4);
  4612. procdefs.insert(tprocdefstore.create(procdef));
  4613. end;
  4614. end;
  4615. function timplementedinterfaces.implproccount(intfindex: longint): longint;
  4616. begin
  4617. checkindex(intfindex);
  4618. with timplintfentry(finterfaces.search(intfindex)) do
  4619. if assigned(procdefs) then
  4620. implproccount:=procdefs.count
  4621. else
  4622. implproccount:=0;
  4623. end;
  4624. function timplementedinterfaces.implprocs(intfindex: longint; procindex: longint): tprocdef;
  4625. begin
  4626. checkindex(intfindex);
  4627. with timplintfentry(finterfaces.search(intfindex)) do
  4628. if assigned(procdefs) then
  4629. implprocs:=tprocdefstore(procdefs.search(procindex)).procdef
  4630. else
  4631. internalerror(200006131);
  4632. end;
  4633. function timplementedinterfaces.isimplmergepossible(intfindex, remainindex: longint; var weight: longint): boolean;
  4634. var
  4635. possible: boolean;
  4636. i: longint;
  4637. iiep1: TIndexArray;
  4638. iiep2: TIndexArray;
  4639. begin
  4640. checkindex(intfindex);
  4641. checkindex(remainindex);
  4642. iiep1:=timplintfentry(finterfaces.search(intfindex)).procdefs;
  4643. iiep2:=timplintfentry(finterfaces.search(remainindex)).procdefs;
  4644. if not assigned(iiep1) then { empty interface is mergeable :-) }
  4645. begin
  4646. possible:=true;
  4647. weight:=0;
  4648. end
  4649. else
  4650. begin
  4651. possible:=assigned(iiep2) and (iiep1.count<=iiep2.count);
  4652. i:=1;
  4653. while (possible) and (i<=iiep1.count) do
  4654. begin
  4655. possible:=
  4656. (tprocdefstore(iiep1.search(i)).procdef=tprocdefstore(iiep2.search(i)).procdef);
  4657. inc(i);
  4658. end;
  4659. if possible then
  4660. weight:=iiep1.count;
  4661. end;
  4662. isimplmergepossible:=possible;
  4663. end;
  4664. {****************************************************************************
  4665. TFORWARDDEF
  4666. ****************************************************************************}
  4667. constructor tforwarddef.create(const s:string;const pos : tfileposinfo);
  4668. var
  4669. oldregisterdef : boolean;
  4670. begin
  4671. { never register the forwarddefs, they are disposed at the
  4672. end of the type declaration block }
  4673. oldregisterdef:=registerdef;
  4674. registerdef:=false;
  4675. inherited create;
  4676. registerdef:=oldregisterdef;
  4677. deftype:=forwarddef;
  4678. tosymname:=s;
  4679. forwardpos:=pos;
  4680. end;
  4681. function tforwarddef.gettypename:string;
  4682. begin
  4683. gettypename:='unresolved forward to '+tosymname;
  4684. end;
  4685. {****************************************************************************
  4686. TERRORDEF
  4687. ****************************************************************************}
  4688. constructor terrordef.create;
  4689. begin
  4690. inherited create;
  4691. deftype:=errordef;
  4692. end;
  4693. {$ifdef GDB}
  4694. function terrordef.stabstring : pchar;
  4695. begin
  4696. stabstring:=strpnew('error'+numberstring);
  4697. end;
  4698. {$endif GDB}
  4699. function terrordef.gettypename:string;
  4700. begin
  4701. gettypename:='<erroneous type>';
  4702. end;
  4703. {****************************************************************************
  4704. GDB Helpers
  4705. ****************************************************************************}
  4706. {$ifdef GDB}
  4707. function typeglobalnumber(const s : string) : string;
  4708. var st : string;
  4709. symt : tsymtable;
  4710. srsym : tsym;
  4711. srsymtable : tsymtable;
  4712. old_make_ref : boolean;
  4713. begin
  4714. old_make_ref:=make_ref;
  4715. make_ref:=false;
  4716. typeglobalnumber := '0';
  4717. srsym := nil;
  4718. if pos('.',s) > 0 then
  4719. begin
  4720. st := copy(s,1,pos('.',s)-1);
  4721. searchsym(st,srsym,srsymtable);
  4722. st := copy(s,pos('.',s)+1,255);
  4723. if assigned(srsym) then
  4724. begin
  4725. if srsym.typ = unitsym then
  4726. begin
  4727. symt := tunitsym(srsym).unitsymtable;
  4728. srsym := tsym(symt.search(st));
  4729. end else srsym := nil;
  4730. end;
  4731. end else st := s;
  4732. if srsym = nil then
  4733. searchsym(st,srsym,srsymtable);
  4734. if (srsym=nil) or
  4735. (srsym.typ<>typesym) then
  4736. begin
  4737. Message(type_e_type_id_expected);
  4738. exit;
  4739. end;
  4740. typeglobalnumber := tstoreddef(ttypesym(srsym).restype.def).numberstring;
  4741. make_ref:=old_make_ref;
  4742. end;
  4743. {$endif GDB}
  4744. {****************************************************************************
  4745. Definition Helpers
  4746. ****************************************************************************}
  4747. procedure reset_global_defs;
  4748. var
  4749. def : tstoreddef;
  4750. {$ifdef debug}
  4751. prevdef : tstoreddef;
  4752. {$endif debug}
  4753. begin
  4754. {$ifdef debug}
  4755. prevdef:=nil;
  4756. {$endif debug}
  4757. {$ifdef GDB}
  4758. pglobaltypecount:=@globaltypecount;
  4759. {$endif GDB}
  4760. def:=firstglobaldef;
  4761. while assigned(def) do
  4762. begin
  4763. {$ifdef GDB}
  4764. if assigned(def.typesym) then
  4765. ttypesym(def.typesym).isusedinstab:=false;
  4766. def.is_def_stab_written:=not_written;
  4767. {$endif GDB}
  4768. { reset rangenr's }
  4769. case def.deftype of
  4770. orddef : torddef(def).rangenr:=0;
  4771. enumdef : tenumdef(def).rangenr:=0;
  4772. arraydef : tarraydef(def).rangenr:=0;
  4773. end;
  4774. if assigned(def.rttitablesym) then
  4775. trttisym(def.rttitablesym).lab := nil;
  4776. if assigned(def.inittablesym) then
  4777. trttisym(def.inittablesym).lab := nil;
  4778. def.localrttilab[initrtti]:=nil;
  4779. def.localrttilab[fullrtti]:=nil;
  4780. {$ifdef debug}
  4781. prevdef:=def;
  4782. {$endif debug}
  4783. def:=def.nextglobal;
  4784. end;
  4785. end;
  4786. function is_interfacecom(def: tdef): boolean;
  4787. begin
  4788. is_interfacecom:=
  4789. assigned(def) and
  4790. (def.deftype=objectdef) and
  4791. (tobjectdef(def).objecttype=odt_interfacecom);
  4792. end;
  4793. function is_interfacecorba(def: tdef): boolean;
  4794. begin
  4795. is_interfacecorba:=
  4796. assigned(def) and
  4797. (def.deftype=objectdef) and
  4798. (tobjectdef(def).objecttype=odt_interfacecorba);
  4799. end;
  4800. function is_interface(def: tdef): boolean;
  4801. begin
  4802. is_interface:=
  4803. assigned(def) and
  4804. (def.deftype=objectdef) and
  4805. (tobjectdef(def).objecttype in [odt_interfacecom,odt_interfacecorba]);
  4806. end;
  4807. function is_class(def: tdef): boolean;
  4808. begin
  4809. is_class:=
  4810. assigned(def) and
  4811. (def.deftype=objectdef) and
  4812. (tobjectdef(def).objecttype=odt_class);
  4813. end;
  4814. function is_object(def: tdef): boolean;
  4815. begin
  4816. is_object:=
  4817. assigned(def) and
  4818. (def.deftype=objectdef) and
  4819. (tobjectdef(def).objecttype=odt_object);
  4820. end;
  4821. function is_cppclass(def: tdef): boolean;
  4822. begin
  4823. is_cppclass:=
  4824. assigned(def) and
  4825. (def.deftype=objectdef) and
  4826. (tobjectdef(def).objecttype=odt_cppclass);
  4827. end;
  4828. function is_class_or_interface(def: tdef): boolean;
  4829. begin
  4830. is_class_or_interface:=
  4831. assigned(def) and
  4832. (def.deftype=objectdef) and
  4833. (tobjectdef(def).objecttype in [odt_class,odt_interfacecom,odt_interfacecorba]);
  4834. end;
  4835. end.
  4836. {
  4837. $Log$
  4838. Revision 1.91 2002-08-25 19:25:20 peter
  4839. * sym.insert_in_data removed
  4840. * symtable.insertvardata/insertconstdata added
  4841. * removed insert_in_data call from symtable.insert, it needs to be
  4842. called separatly. This allows to deref the address calculation
  4843. * procedures now calculate the parast addresses after the procedure
  4844. directives are parsed. This fixes the cdecl parast problem
  4845. * push_addr_param has an extra argument that specifies if cdecl is used
  4846. or not
  4847. Revision 1.90 2002/08/18 20:06:25 peter
  4848. * inlining is now also allowed in interface
  4849. * renamed write/load to ppuwrite/ppuload
  4850. * tnode storing in ppu
  4851. * nld,ncon,nbas are already updated for storing in ppu
  4852. Revision 1.89 2002/08/11 15:28:00 florian
  4853. + support of explicit type case <any ordinal type>->pointer
  4854. (delphi mode only)
  4855. Revision 1.88 2002/08/11 14:32:28 peter
  4856. * renamed current_library to objectlibrary
  4857. Revision 1.87 2002/08/11 13:24:13 peter
  4858. * saving of asmsymbols in ppu supported
  4859. * asmsymbollist global is removed and moved into a new class
  4860. tasmlibrarydata that will hold the info of a .a file which
  4861. corresponds with a single module. Added librarydata to tmodule
  4862. to keep the library info stored for the module. In the future the
  4863. objectfiles will also be stored to the tasmlibrarydata class
  4864. * all getlabel/newasmsymbol and friends are moved to the new class
  4865. Revision 1.86 2002/08/09 07:33:03 florian
  4866. * a couple of interface related fixes
  4867. Revision 1.85 2002/07/23 09:51:24 daniel
  4868. * Tried to make Tprocsym.defs protected. I didn't succeed but the cleanups
  4869. are worth comitting.
  4870. Revision 1.84 2002/07/20 11:57:57 florian
  4871. * types.pas renamed to defbase.pas because D6 contains a types
  4872. unit so this would conflicts if D6 programms are compiled
  4873. + Willamette/SSE2 instructions to assembler added
  4874. Revision 1.83 2002/07/11 14:41:30 florian
  4875. * start of the new generic parameter handling
  4876. Revision 1.82 2002/07/07 09:52:32 florian
  4877. * powerpc target fixed, very simple units can be compiled
  4878. * some basic stuff for better callparanode handling, far from being finished
  4879. Revision 1.81 2002/07/01 18:46:26 peter
  4880. * internal linker
  4881. * reorganized aasm layer
  4882. Revision 1.80 2002/07/01 16:23:54 peter
  4883. * cg64 patch
  4884. * basics for currency
  4885. * asnode updates for class and interface (not finished)
  4886. Revision 1.79 2002/05/18 13:34:18 peter
  4887. * readded missing revisions
  4888. Revision 1.78 2002/05/16 19:46:44 carl
  4889. + defines.inc -> fpcdefs.inc to avoid conflicts if compiling by hand
  4890. + try to fix temp allocation (still in ifdef)
  4891. + generic constructor calls
  4892. + start of tassembler / tmodulebase class cleanup
  4893. Revision 1.76 2002/05/12 16:53:10 peter
  4894. * moved entry and exitcode to ncgutil and cgobj
  4895. * foreach gets extra argument for passing local data to the
  4896. iterator function
  4897. * -CR checks also class typecasts at runtime by changing them
  4898. into as
  4899. * fixed compiler to cycle with the -CR option
  4900. * fixed stabs with elf writer, finally the global variables can
  4901. be watched
  4902. * removed a lot of routines from cga unit and replaced them by
  4903. calls to cgobj
  4904. * u32bit-s32bit updates for and,or,xor nodes. When one element is
  4905. u32bit then the other is typecasted also to u32bit without giving
  4906. a rangecheck warning/error.
  4907. * fixed pascal calling method with reversing also the high tree in
  4908. the parast, detected by tcalcst3 test
  4909. Revision 1.75 2002/04/25 20:16:39 peter
  4910. * moved more routines from cga/n386util
  4911. Revision 1.74 2002/04/23 19:16:35 peter
  4912. * add pinline unit that inserts compiler supported functions using
  4913. one or more statements
  4914. * moved finalize and setlength from ninl to pinline
  4915. Revision 1.73 2002/04/21 19:02:05 peter
  4916. * removed newn and disposen nodes, the code is now directly
  4917. inlined from pexpr
  4918. * -an option that will write the secondpass nodes to the .s file, this
  4919. requires EXTDEBUG define to actually write the info
  4920. * fixed various internal errors and crashes due recent code changes
  4921. Revision 1.72 2002/04/20 21:32:25 carl
  4922. + generic FPC_CHECKPOINTER
  4923. + first parameter offset in stack now portable
  4924. * rename some constants
  4925. + move some cpu stuff to other units
  4926. - remove unused constents
  4927. * fix stacksize for some targets
  4928. * fix generic size problems which depend now on EXTEND_SIZE constant
  4929. Revision 1.71 2002/04/19 15:46:03 peter
  4930. * mangledname rewrite, tprocdef.mangledname is now created dynamicly
  4931. in most cases and not written to the ppu
  4932. * add mangeledname_prefix() routine to generate the prefix of
  4933. manglednames depending on the current procedure, object and module
  4934. * removed static procprefix since the mangledname is now build only
  4935. on demand from tprocdef.mangledname
  4936. Revision 1.70 2002/04/15 19:06:34 carl
  4937. + target_info.size_of_pointer -> pointer_Size
  4938. Revision 1.69 2002/04/14 16:55:43 carl
  4939. + replace some stuff by ALL_REGISTERS
  4940. Revision 1.68 2002/04/02 17:11:29 peter
  4941. * tlocation,treference update
  4942. * LOC_CONSTANT added for better constant handling
  4943. * secondadd splitted in multiple routines
  4944. * location_force_reg added for loading a location to a register
  4945. of a specified size
  4946. * secondassignment parses now first the right and then the left node
  4947. (this is compatible with Kylix). This saves a lot of push/pop especially
  4948. with string operations
  4949. * adapted some routines to use the new cg methods
  4950. Revision 1.67 2002/03/31 20:26:36 jonas
  4951. + a_loadfpu_* and a_loadmm_* methods in tcg
  4952. * register allocation is now handled by a class and is mostly processor
  4953. independent (+rgobj.pas and i386/rgcpu.pas)
  4954. * temp allocation is now handled by a class (+tgobj.pas, -i386\tgcpu.pas)
  4955. * some small improvements and fixes to the optimizer
  4956. * some register allocation fixes
  4957. * some fpuvaroffset fixes in the unary minus node
  4958. * push/popusedregisters is now called rg.save/restoreusedregisters and
  4959. (for i386) uses temps instead of push/pop's when using -Op3 (that code is
  4960. also better optimizable)
  4961. * fixed and optimized register saving/restoring for new/dispose nodes
  4962. * LOC_FPU locations now also require their "register" field to be set to
  4963. R_ST, not R_ST0 (the latter is used for LOC_CFPUREGISTER locations only)
  4964. - list field removed of the tnode class because it's not used currently
  4965. and can cause hard-to-find bugs
  4966. Revision 1.66 2002/03/24 19:10:14 carl
  4967. + patch for SPARC from Mazen NEIFER
  4968. Revision 1.65 2002/02/04 08:16:07 jonas
  4969. * fixed severe slowdown when compiling a program with arrays that have
  4970. a lot (15+) dimensions ("merged")
  4971. Revision 1.64 2002/01/19 15:12:34 peter
  4972. * check for unresolved forward classes in the interface
  4973. Revision 1.63 2002/01/06 21:52:30 peter
  4974. * fixed previous commit
  4975. Revision 1.62 2002/01/06 12:08:15 peter
  4976. * removed uauto from orddef, use new range_to_basetype generating
  4977. the correct ordinal type for a range
  4978. }