symdef.pas 173 KB

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