symdef.pas 178 KB

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