symdef.pas 175 KB

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