symdef.pas 180 KB

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