symdef.pas 172 KB

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