symdef.pas 174 KB

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