symdef.pas 171 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520
  1. {
  2. Symbol table implementation for the definitions
  3. Copyright (c) 1998-2005 by Florian Klaempfl, Pierre Muller
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. ****************************************************************************
  16. }
  17. unit symdef;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. { common }
  22. cutils,cclasses,
  23. { global }
  24. globtype,globals,tokens,
  25. { symtable }
  26. symconst,symbase,symtype,
  27. { ppu }
  28. ppu,
  29. { node }
  30. node,
  31. { aasm }
  32. aasmbase,aasmtai,aasmdata,
  33. cpubase,cpuinfo,
  34. cgbase,cgutils,
  35. parabase
  36. ;
  37. type
  38. {************************************************
  39. TDef
  40. ************************************************}
  41. tstoreddef = class(tdef)
  42. protected
  43. typesymderef : tderef;
  44. public
  45. { persistent (available across units) rtti and init tables }
  46. rttitablesym,
  47. inittablesym : tsym; {trttisym}
  48. rttitablesymderef,
  49. inittablesymderef : tderef;
  50. { local (per module) rtti and init tables }
  51. localrttilab : array[trttitype] of tasmlabel;
  52. {$ifdef EXTDEBUG}
  53. fileinfo : tfileposinfo;
  54. {$endif}
  55. { generic support }
  56. genericdef : tstoreddef;
  57. genericdefderef : tderef;
  58. generictokenbuf : tdynamicarray;
  59. constructor create(dt:tdeftype);
  60. constructor ppuload(dt:tdeftype;ppufile:tcompilerppufile);
  61. destructor destroy;override;
  62. procedure reset;virtual;
  63. function getcopy : tstoreddef;virtual;
  64. procedure ppuwrite(ppufile:tcompilerppufile);virtual;
  65. procedure buildderef;override;
  66. procedure buildderefimpl;override;
  67. procedure deref;override;
  68. procedure derefimpl;override;
  69. function size:aint;override;
  70. function getvartype:longint;override;
  71. function alignment:shortint;override;
  72. function is_publishable : boolean;override;
  73. function needs_inittable : boolean;override;
  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. { generics }
  83. procedure initgeneric;
  84. private
  85. savesize : aint;
  86. end;
  87. tfiletyp = (ft_text,ft_typed,ft_untyped);
  88. tfiledef = class(tstoreddef)
  89. filetyp : tfiletyp;
  90. typedfiletype : ttype;
  91. constructor createtext;
  92. constructor createuntyped;
  93. constructor createtyped(const tt : ttype);
  94. constructor ppuload(ppufile:tcompilerppufile);
  95. function getcopy : tstoreddef;override;
  96. procedure ppuwrite(ppufile:tcompilerppufile);override;
  97. procedure buildderef;override;
  98. procedure deref;override;
  99. function gettypename:string;override;
  100. function getmangledparaname:string;override;
  101. procedure setsize;
  102. end;
  103. tvariantdef = class(tstoreddef)
  104. varianttype : tvarianttype;
  105. constructor create(v : tvarianttype);
  106. constructor ppuload(ppufile:tcompilerppufile);
  107. function getcopy : tstoreddef;override;
  108. function gettypename:string;override;
  109. procedure ppuwrite(ppufile:tcompilerppufile);override;
  110. procedure setsize;
  111. function is_publishable : boolean;override;
  112. function needs_inittable : boolean;override;
  113. procedure write_rtti_data(rt:trttitype);override;
  114. end;
  115. tformaldef = class(tstoreddef)
  116. constructor create;
  117. constructor ppuload(ppufile:tcompilerppufile);
  118. procedure ppuwrite(ppufile:tcompilerppufile);override;
  119. function gettypename:string;override;
  120. end;
  121. tforwarddef = class(tstoreddef)
  122. tosymname : pstring;
  123. forwardpos : tfileposinfo;
  124. constructor create(const s:string;const pos : tfileposinfo);
  125. destructor destroy;override;
  126. function gettypename:string;override;
  127. end;
  128. tundefineddef = class(tstoreddef)
  129. constructor create;
  130. constructor ppuload(ppufile:tcompilerppufile);
  131. procedure ppuwrite(ppufile:tcompilerppufile);override;
  132. function gettypename:string;override;
  133. end;
  134. terrordef = class(tstoreddef)
  135. constructor create;
  136. procedure ppuwrite(ppufile:tcompilerppufile);override;
  137. function gettypename:string;override;
  138. function getmangledparaname : string;override;
  139. end;
  140. tabstractpointerdef = class(tstoreddef)
  141. pointertype : ttype;
  142. constructor create(dt:tdeftype;const tt : ttype);
  143. constructor ppuload(dt:tdeftype;ppufile:tcompilerppufile);
  144. procedure ppuwrite(ppufile:tcompilerppufile);override;
  145. procedure buildderef;override;
  146. procedure deref;override;
  147. end;
  148. tpointerdef = class(tabstractpointerdef)
  149. is_far : boolean;
  150. constructor create(const tt : ttype);
  151. constructor createfar(const tt : ttype);
  152. function getcopy : tstoreddef;override;
  153. constructor ppuload(ppufile:tcompilerppufile);
  154. procedure ppuwrite(ppufile:tcompilerppufile);override;
  155. function gettypename:string;override;
  156. end;
  157. tabstractrecorddef= class(tstoreddef)
  158. private
  159. Count : integer;
  160. FRTTIType : trttitype;
  161. procedure count_field_rtti(sym : tnamedindexitem;arg:pointer);
  162. procedure write_field_rtti(sym : tnamedindexitem;arg:pointer);
  163. procedure generate_field_rtti(sym : tnamedindexitem;arg:pointer);
  164. public
  165. symtable : tsymtable;
  166. procedure reset;override;
  167. function getsymtable(t:tgetsymtable):tsymtable;override;
  168. procedure buildderefimpl;override;
  169. procedure derefimpl;override;
  170. end;
  171. trecorddef = class(tabstractrecorddef)
  172. public
  173. isunion : boolean;
  174. constructor create(p : tsymtable);
  175. constructor ppuload(ppufile:tcompilerppufile);
  176. destructor destroy;override;
  177. function getcopy : tstoreddef;override;
  178. procedure ppuwrite(ppufile:tcompilerppufile);override;
  179. procedure buildderef;override;
  180. procedure deref;override;
  181. function size:aint;override;
  182. function alignment : shortint;override;
  183. function padalignment: shortint;
  184. function gettypename:string;override;
  185. { debug }
  186. function needs_inittable : boolean;override;
  187. { rtti }
  188. procedure write_child_rtti_data(rt:trttitype);override;
  189. procedure write_rtti_data(rt:trttitype);override;
  190. end;
  191. tprocdef = class;
  192. tobjectdef = class;
  193. timplementedinterfaces = class;
  194. timplintfentry = class(TNamedIndexItem)
  195. intf : tobjectdef;
  196. intfderef : tderef;
  197. ioffset : longint;
  198. implindex : longint;
  199. namemappings : tdictionary;
  200. procdefs : TIndexArray;
  201. constructor create(aintf: tobjectdef);
  202. constructor create_deref(const d:tderef);
  203. destructor destroy; override;
  204. end;
  205. tobjectdef = class(tabstractrecorddef)
  206. private
  207. procedure count_published_properties(sym:tnamedindexitem;arg:pointer);
  208. procedure collect_published_properties(sym:tnamedindexitem;arg:pointer);
  209. procedure write_property_info(sym : tnamedindexitem;arg:pointer);
  210. procedure generate_published_child_rtti(sym : tnamedindexitem;arg:pointer);
  211. procedure count_published_fields(sym:tnamedindexitem;arg:pointer);
  212. procedure writefields(sym:tnamedindexitem;arg:pointer);
  213. public
  214. childof : tobjectdef;
  215. childofderef : tderef;
  216. objname,
  217. objrealname : pstring;
  218. objectoptions : tobjectoptions;
  219. { to be able to have a variable vmt position }
  220. { and no vmt field for objects without virtuals }
  221. vmt_offset : longint;
  222. writing_class_record_dbginfo : boolean;
  223. objecttype : tobjectdeftype;
  224. iidguid: pguid;
  225. iidstr: pstring;
  226. lastvtableindex: longint;
  227. { store implemented interfaces defs and name mappings }
  228. implementedinterfaces: timplementedinterfaces;
  229. constructor create(ot : tobjectdeftype;const n : string;c : tobjectdef);
  230. constructor ppuload(ppufile:tcompilerppufile);
  231. destructor destroy;override;
  232. function getcopy : tstoreddef;override;
  233. procedure ppuwrite(ppufile:tcompilerppufile);override;
  234. function gettypename:string;override;
  235. procedure buildderef;override;
  236. procedure deref;override;
  237. function getparentdef:tdef;override;
  238. function size : aint;override;
  239. function alignment:shortint;override;
  240. function vmtmethodoffset(index:longint):longint;
  241. function members_need_inittable : boolean;
  242. { this should be called when this class implements an interface }
  243. procedure prepareguid;
  244. function is_publishable : boolean;override;
  245. function needs_inittable : boolean;override;
  246. function vmt_mangledname : string;
  247. function rtti_name : string;
  248. procedure check_forwards;
  249. function is_related(d : tdef) : boolean;override;
  250. procedure insertvmt;
  251. procedure set_parent(c : tobjectdef);
  252. function searchdestructor : tprocdef;
  253. { rtti }
  254. procedure write_child_rtti_data(rt:trttitype);override;
  255. procedure write_rtti_data(rt:trttitype);override;
  256. function generate_field_table : tasmlabel;
  257. end;
  258. timplementedinterfaces = class
  259. constructor create;
  260. destructor destroy; override;
  261. function count: longint;
  262. function interfaces(intfindex: longint): tobjectdef;
  263. function interfacesderef(intfindex: longint): tderef;
  264. function ioffsets(intfindex: longint): longint;
  265. procedure setioffsets(intfindex,iofs:longint);
  266. function implindex(intfindex:longint):longint;
  267. procedure setimplindex(intfindex,implidx:longint);
  268. function searchintf(def: tdef): longint;
  269. procedure addintf(def: tdef);
  270. procedure buildderef;
  271. procedure deref;
  272. { add interface reference loaded from ppu }
  273. procedure addintf_deref(const d:tderef;iofs:longint);
  274. procedure addintf_ioffset(d:tdef;iofs:longint);
  275. procedure clearmappings;
  276. procedure addmappings(intfindex: longint; const origname, newname: string);
  277. function getmappings(intfindex: longint; const origname: string; var nextexist: pointer): string;
  278. procedure addimplproc(intfindex: longint; procdef: tprocdef);
  279. function implproccount(intfindex: longint): longint;
  280. function implprocs(intfindex: longint; procindex: longint): tprocdef;
  281. function isimplmergepossible(intfindex, remainindex: longint; var weight: longint): boolean;
  282. private
  283. finterfaces: tindexarray;
  284. procedure checkindex(intfindex: longint);
  285. end;
  286. tclassrefdef = class(tabstractpointerdef)
  287. constructor create(const t:ttype);
  288. constructor ppuload(ppufile:tcompilerppufile);
  289. procedure ppuwrite(ppufile:tcompilerppufile);override;
  290. function gettypename:string;override;
  291. function is_publishable : boolean;override;
  292. end;
  293. tarraydef = class(tstoreddef)
  294. lowrange,
  295. highrange : aint;
  296. rangetype : ttype;
  297. arrayoptions : tarraydefoptions;
  298. protected
  299. _elementtype : ttype;
  300. public
  301. function elesize : aint;
  302. function elecount : aint;
  303. constructor create_from_pointer(const elemt : ttype);
  304. constructor create(l,h : aint;const t : ttype);
  305. constructor ppuload(ppufile:tcompilerppufile);
  306. function getcopy : tstoreddef;override;
  307. procedure ppuwrite(ppufile:tcompilerppufile);override;
  308. function gettypename:string;override;
  309. function getmangledparaname : string;override;
  310. procedure setelementtype(t: ttype);
  311. procedure buildderef;override;
  312. procedure deref;override;
  313. function size : aint;override;
  314. function alignment : shortint;override;
  315. { returns the label of the range check string }
  316. function needs_inittable : boolean;override;
  317. procedure write_child_rtti_data(rt:trttitype);override;
  318. procedure write_rtti_data(rt:trttitype);override;
  319. property elementtype : ttype Read _ElementType;
  320. end;
  321. torddef = class(tstoreddef)
  322. low,high : TConstExprInt;
  323. typ : tbasetype;
  324. constructor create(t : tbasetype;v,b : TConstExprInt);
  325. constructor ppuload(ppufile:tcompilerppufile);
  326. function getcopy : tstoreddef;override;
  327. procedure ppuwrite(ppufile:tcompilerppufile);override;
  328. function is_publishable : boolean;override;
  329. function gettypename:string;override;
  330. function alignment:shortint;override;
  331. procedure setsize;
  332. function getvartype : longint;override;
  333. { rtti }
  334. procedure write_rtti_data(rt:trttitype);override;
  335. end;
  336. tfloatdef = class(tstoreddef)
  337. typ : tfloattype;
  338. constructor create(t : tfloattype);
  339. constructor ppuload(ppufile:tcompilerppufile);
  340. function getcopy : tstoreddef;override;
  341. procedure ppuwrite(ppufile:tcompilerppufile);override;
  342. function gettypename:string;override;
  343. function is_publishable : boolean;override;
  344. function alignment:shortint;override;
  345. procedure setsize;
  346. function getvartype:longint;override;
  347. { rtti }
  348. procedure write_rtti_data(rt:trttitype);override;
  349. end;
  350. tabstractprocdef = class(tstoreddef)
  351. { saves a definition to the return type }
  352. rettype : ttype;
  353. parast : tsymtable;
  354. paras : tparalist;
  355. proctypeoption : tproctypeoption;
  356. proccalloption : tproccalloption;
  357. procoptions : tprocoptions;
  358. requiredargarea : aint;
  359. { number of user visibile parameters }
  360. maxparacount,
  361. minparacount : byte;
  362. {$ifdef i386}
  363. fpu_used : longint; { how many stack fpu must be empty }
  364. {$endif i386}
  365. {$ifdef m68k}
  366. exp_funcretloc : tregister; { explicit funcretloc for AmigaOS }
  367. {$endif}
  368. funcretloc : array[tcallercallee] of TLocation;
  369. has_paraloc_info : boolean; { paraloc info is available }
  370. constructor create(dt:tdeftype;level:byte);
  371. constructor ppuload(dt:tdeftype;ppufile:tcompilerppufile);
  372. destructor destroy;override;
  373. procedure ppuwrite(ppufile:tcompilerppufile);override;
  374. procedure buildderef;override;
  375. procedure deref;override;
  376. procedure releasemem;
  377. procedure calcparas;
  378. function typename_paras(showhidden:boolean): string;
  379. procedure test_if_fpu_result;
  380. function is_methodpointer:boolean;virtual;
  381. function is_addressonly:boolean;virtual;
  382. private
  383. procedure count_para(p:tnamedindexitem;arg:pointer);
  384. procedure insert_para(p:tnamedindexitem;arg:pointer);
  385. end;
  386. tprocvardef = class(tabstractprocdef)
  387. constructor create(level:byte);
  388. constructor ppuload(ppufile:tcompilerppufile);
  389. function getcopy : tstoreddef;override;
  390. procedure ppuwrite(ppufile:tcompilerppufile);override;
  391. procedure buildderef;override;
  392. procedure deref;override;
  393. function getsymtable(t:tgetsymtable):tsymtable;override;
  394. function size : aint;override;
  395. function gettypename:string;override;
  396. function is_publishable : boolean;override;
  397. function is_methodpointer:boolean;override;
  398. function is_addressonly:boolean;override;
  399. function getmangledparaname:string;override;
  400. { rtti }
  401. procedure write_rtti_data(rt:trttitype);override;
  402. end;
  403. tmessageinf = record
  404. case integer of
  405. 0 : (str : pchar);
  406. 1 : (i : longint);
  407. end;
  408. tinlininginfo = record
  409. { node tree }
  410. code : tnode;
  411. flags : tprocinfoflags;
  412. end;
  413. pinlininginfo = ^tinlininginfo;
  414. {$ifdef oldregvars}
  415. { register variables }
  416. pregvarinfo = ^tregvarinfo;
  417. tregvarinfo = record
  418. regvars : array[1..maxvarregs] of tsym;
  419. regvars_para : array[1..maxvarregs] of boolean;
  420. regvars_refs : array[1..maxvarregs] of longint;
  421. fpuregvars : array[1..maxfpuvarregs] of tsym;
  422. fpuregvars_para : array[1..maxfpuvarregs] of boolean;
  423. fpuregvars_refs : array[1..maxfpuvarregs] of longint;
  424. end;
  425. {$endif oldregvars}
  426. tprocdef = class(tabstractprocdef)
  427. private
  428. _mangledname : pstring;
  429. public
  430. extnumber : word;
  431. messageinf : tmessageinf;
  432. {$ifndef EXTDEBUG}
  433. { where is this function defined and what were the symbol
  434. flags, needed here because there
  435. is only one symbol for all overloaded functions
  436. EXTDEBUG has fileinfo in tdef (PFV) }
  437. fileinfo : tfileposinfo;
  438. {$endif}
  439. symoptions : tsymoptions;
  440. { symbol owning this definition }
  441. procsym : tsym;
  442. procsymderef : tderef;
  443. { alias names }
  444. aliasnames : tstringlist;
  445. { symtables }
  446. localst : tsymtable;
  447. funcretsym : tsym;
  448. funcretsymderef : tderef;
  449. { browser info }
  450. lastref,
  451. defref,
  452. lastwritten : tref;
  453. refcount : longint;
  454. _class : tobjectdef;
  455. _classderef : tderef;
  456. {$if defined(powerpc) or defined(m68k)}
  457. { library symbol for AmigaOS/MorphOS }
  458. libsym : tsym;
  459. libsymderef : tderef;
  460. {$endif powerpc or m68k}
  461. { name of the result variable to insert in the localsymtable }
  462. resultname : stringid;
  463. { true, if the procedure is only declared
  464. (forward procedure) }
  465. forwarddef,
  466. { true if the procedure is declared in the interface }
  467. interfacedef : boolean;
  468. { true if the procedure has a forward declaration }
  469. hasforward : boolean;
  470. { import info }
  471. import_dll,
  472. import_name : pstring;
  473. import_nr : word;
  474. { info for inlining the subroutine, if this pointer is nil,
  475. the procedure can't be inlined }
  476. inlininginfo : pinlininginfo;
  477. {$ifdef oldregvars}
  478. regvarinfo: pregvarinfo;
  479. {$endif oldregvars}
  480. { position in aasmoutput list }
  481. procstarttai,
  482. procendtai : tai;
  483. constructor create(level:byte);
  484. constructor ppuload(ppufile:tcompilerppufile);
  485. destructor destroy;override;
  486. procedure ppuwrite(ppufile:tcompilerppufile);override;
  487. procedure buildderef;override;
  488. procedure buildderefimpl;override;
  489. procedure deref;override;
  490. procedure derefimpl;override;
  491. procedure reset;override;
  492. function getsymtable(t:tgetsymtable):tsymtable;override;
  493. function gettypename : string;override;
  494. function mangledname : string;
  495. procedure setmangledname(const s : string);
  496. procedure load_references(ppufile:tcompilerppufile;locals:boolean);
  497. function write_references(ppufile:tcompilerppufile;locals:boolean):boolean;
  498. { inserts the local symbol table, if this is not
  499. no local symbol table is built. Should be called only
  500. when we are sure that a local symbol table will be required.
  501. }
  502. procedure insert_localst;
  503. function fullprocname(showhidden:boolean):string;
  504. function cplusplusmangledname : string;
  505. function is_methodpointer:boolean;override;
  506. function is_addressonly:boolean;override;
  507. function is_visible_for_object(currobjdef:tobjectdef):boolean;
  508. end;
  509. { single linked list of overloaded procs }
  510. pprocdeflist = ^tprocdeflist;
  511. tprocdeflist = record
  512. def : tprocdef;
  513. defderef : tderef;
  514. next : pprocdeflist;
  515. end;
  516. tstringdef = class(tstoreddef)
  517. string_typ : tstringtype;
  518. len : aint;
  519. constructor createshort(l : byte);
  520. constructor loadshort(ppufile:tcompilerppufile);
  521. constructor createlong(l : aint);
  522. constructor loadlong(ppufile:tcompilerppufile);
  523. constructor createansi(l : aint);
  524. constructor loadansi(ppufile:tcompilerppufile);
  525. constructor createwide(l : aint);
  526. constructor loadwide(ppufile:tcompilerppufile);
  527. function getcopy : tstoreddef;override;
  528. function stringtypname:string;
  529. procedure ppuwrite(ppufile:tcompilerppufile);override;
  530. function gettypename:string;override;
  531. function getmangledparaname:string;override;
  532. function is_publishable : boolean;override;
  533. function alignment : shortint;override;
  534. { init/final }
  535. function needs_inittable : boolean;override;
  536. { rtti }
  537. procedure write_rtti_data(rt:trttitype);override;
  538. end;
  539. tenumdef = class(tstoreddef)
  540. minval,
  541. maxval : aint;
  542. has_jumps : boolean;
  543. firstenum : tsym; {tenumsym}
  544. basedef : tenumdef;
  545. basedefderef : tderef;
  546. constructor create;
  547. constructor create_subrange(_basedef:tenumdef;_min,_max:aint);
  548. constructor ppuload(ppufile:tcompilerppufile);
  549. destructor destroy;override;
  550. function getcopy : tstoreddef;override;
  551. procedure ppuwrite(ppufile:tcompilerppufile);override;
  552. procedure buildderef;override;
  553. procedure deref;override;
  554. procedure derefimpl;override;
  555. function gettypename:string;override;
  556. function is_publishable : boolean;override;
  557. procedure calcsavesize;
  558. procedure setmax(_max:aint);
  559. procedure setmin(_min:aint);
  560. function min:aint;
  561. function max:aint;
  562. { rtti }
  563. procedure write_rtti_data(rt:trttitype);override;
  564. procedure write_child_rtti_data(rt:trttitype);override;
  565. end;
  566. tsetdef = class(tstoreddef)
  567. elementtype : ttype;
  568. settype : tsettype;
  569. setbase,
  570. setmax : aint;
  571. constructor create(const t:ttype;high : aint);
  572. constructor ppuload(ppufile:tcompilerppufile);
  573. destructor destroy;override;
  574. function getcopy : tstoreddef;override;
  575. procedure ppuwrite(ppufile:tcompilerppufile);override;
  576. procedure buildderef;override;
  577. procedure deref;override;
  578. function gettypename:string;override;
  579. function is_publishable : boolean;override;
  580. { rtti }
  581. procedure write_rtti_data(rt:trttitype);override;
  582. procedure write_child_rtti_data(rt:trttitype);override;
  583. end;
  584. Tdefmatch=(dm_exact,dm_equal,dm_convertl1);
  585. var
  586. aktobjectdef : tobjectdef; { used for private functions check !! }
  587. { default types }
  588. generrortype, { error in definition }
  589. voidpointertype, { pointer for Void-Pointerdef }
  590. charpointertype, { pointer for Char-Pointerdef }
  591. widecharpointertype, { pointer for WideChar-Pointerdef }
  592. voidfarpointertype,
  593. cundefinedtype,
  594. cformaltype, { unique formal definition }
  595. voidtype, { Void (procedure) }
  596. cchartype, { Char }
  597. cwidechartype, { WideChar }
  598. booltype, { boolean type }
  599. u8inttype, { 8-Bit unsigned integer }
  600. s8inttype, { 8-Bit signed integer }
  601. u16inttype, { 16-Bit unsigned integer }
  602. s16inttype, { 16-Bit signed integer }
  603. u32inttype, { 32-Bit unsigned integer }
  604. s32inttype, { 32-Bit signed integer }
  605. u64inttype, { 64-bit unsigned integer }
  606. s64inttype, { 64-bit signed integer }
  607. s32floattype, { pointer for realconstn }
  608. s64floattype, { pointer for realconstn }
  609. s80floattype, { pointer to type of temp. floats }
  610. s64currencytype, { pointer to a currency type }
  611. cshortstringtype, { pointer to type of short string const }
  612. clongstringtype, { pointer to type of long string const }
  613. cansistringtype, { pointer to type of ansi string const }
  614. cwidestringtype, { pointer to type of wide string const }
  615. openshortstringtype, { pointer to type of an open shortstring,
  616. needed for readln() }
  617. openchararraytype, { pointer to type of an open array of char,
  618. needed for readln() }
  619. cfiletype, { get the same definition for all file }
  620. { used for stabs }
  621. methodpointertype, { typecasting of methodpointers to extract self }
  622. { we use only one variant def for every variant class }
  623. cvarianttype,
  624. colevarianttype,
  625. { default integer type s32inttype on 32 bit systems, s64bittype on 64 bit systems }
  626. sinttype,
  627. uinttype,
  628. { unsigned ord type with the same size as a pointer }
  629. ptrinttype,
  630. { several types to simulate more or less C++ objects for GDB }
  631. vmttype,
  632. vmtarraytype,
  633. pvmttype : ttype; { type of classrefs, used for stabs }
  634. { pointer to the anchestor of all classes }
  635. class_tobject : tobjectdef;
  636. { pointer to the ancestor of all COM interfaces }
  637. interface_iunknown : tobjectdef;
  638. { pointer to the TGUID type
  639. of all interfaces }
  640. rec_tguid : trecorddef;
  641. const
  642. {$ifdef i386}
  643. pbestrealtype : ^ttype = @s80floattype;
  644. {$endif}
  645. {$ifdef x86_64}
  646. pbestrealtype : ^ttype = @s80floattype;
  647. {$endif}
  648. {$ifdef m68k}
  649. pbestrealtype : ^ttype = @s64floattype;
  650. {$endif}
  651. {$ifdef alpha}
  652. pbestrealtype : ^ttype = @s64floattype;
  653. {$endif}
  654. {$ifdef powerpc}
  655. pbestrealtype : ^ttype = @s64floattype;
  656. {$endif}
  657. {$ifdef POWERPC64}
  658. pbestrealtype : ^ttype = @s64floattype;
  659. {$endif}
  660. {$ifdef ia64}
  661. pbestrealtype : ^ttype = @s64floattype;
  662. {$endif}
  663. {$ifdef SPARC}
  664. pbestrealtype : ^ttype = @s64floattype;
  665. {$endif SPARC}
  666. {$ifdef vis}
  667. pbestrealtype : ^ttype = @s64floattype;
  668. {$endif vis}
  669. {$ifdef ARM}
  670. pbestrealtype : ^ttype = @s64floattype;
  671. {$endif ARM}
  672. {$ifdef MIPS}
  673. pbestrealtype : ^ttype = @s64floattype;
  674. {$endif MIPS}
  675. function make_mangledname(const typeprefix:string;st:tsymtable;const suffix:string):string;
  676. { should be in the types unit, but the types unit uses the node stuff :( }
  677. function is_interfacecom(def: tdef): boolean;
  678. function is_interfacecorba(def: tdef): boolean;
  679. function is_interface(def: tdef): boolean;
  680. function is_object(def: tdef): boolean;
  681. function is_class(def: tdef): boolean;
  682. function is_cppclass(def: tdef): boolean;
  683. function is_class_or_interface(def: tdef): boolean;
  684. function is_class_or_interface_or_dispinterface(def: tdef): boolean;
  685. {$ifdef x86}
  686. function use_sse(def : tdef) : boolean;
  687. {$endif x86}
  688. implementation
  689. uses
  690. strings,
  691. { global }
  692. verbose,
  693. { target }
  694. systems,aasmcpu,paramgr,
  695. { symtable }
  696. symsym,symtable,symutil,defutil,
  697. { module }
  698. fmodule,
  699. { other }
  700. gendef,
  701. fpccrc
  702. ;
  703. {****************************************************************************
  704. Constants
  705. ****************************************************************************}
  706. const
  707. varempty = 0;
  708. varnull = 1;
  709. varsmallint = 2;
  710. varinteger = 3;
  711. varsingle = 4;
  712. vardouble = 5;
  713. varcurrency = 6;
  714. vardate = 7;
  715. varolestr = 8;
  716. vardispatch = 9;
  717. varerror = 10;
  718. varboolean = 11;
  719. varvariant = 12;
  720. varunknown = 13;
  721. vardecimal = 14;
  722. varshortint = 16;
  723. varbyte = 17;
  724. varword = 18;
  725. varlongword = 19;
  726. varint64 = 20;
  727. varqword = 21;
  728. varUndefined = -1;
  729. varstrarg = $48;
  730. varstring = $100;
  731. varany = $101;
  732. vartypemask = $fff;
  733. vararray = $2000;
  734. varbyref = $4000;
  735. {****************************************************************************
  736. Helpers
  737. ****************************************************************************}
  738. function make_mangledname(const typeprefix:string;st:tsymtable;const suffix:string):string;
  739. var
  740. s,hs,
  741. prefix : string;
  742. oldlen,
  743. newlen,
  744. i : longint;
  745. crc : dword;
  746. hp : tparavarsym;
  747. begin
  748. prefix:='';
  749. if not assigned(st) then
  750. internalerror(200204212);
  751. { sub procedures }
  752. while (st.symtabletype=localsymtable) do
  753. begin
  754. if st.defowner.deftype<>procdef then
  755. internalerror(200204173);
  756. { Add the full mangledname of procedure to prevent
  757. conflicts with 2 overloads having both a nested procedure
  758. with the same name, see tb0314 (PFV) }
  759. s:=tprocdef(st.defowner).procsym.name;
  760. oldlen:=length(s);
  761. for i:=0 to tprocdef(st.defowner).paras.count-1 do
  762. begin
  763. hp:=tparavarsym(tprocdef(st.defowner).paras[i]);
  764. if not(vo_is_hidden_para in hp.varoptions) then
  765. s:=s+'$'+hp.vartype.def.mangledparaname;
  766. end;
  767. if not is_void(tprocdef(st.defowner).rettype.def) then
  768. s:=s+'$$'+tprocdef(st.defowner).rettype.def.mangledparaname;
  769. newlen:=length(s);
  770. { Replace with CRC if the parameter line is very long }
  771. if (newlen-oldlen>12) and
  772. ((newlen>128) or (newlen-oldlen>64)) then
  773. begin
  774. crc:=$ffffffff;
  775. for i:=0 to tprocdef(st.defowner).paras.count-1 do
  776. begin
  777. hp:=tparavarsym(tprocdef(st.defowner).paras[i]);
  778. if not(vo_is_hidden_para in hp.varoptions) then
  779. begin
  780. hs:=hp.vartype.def.mangledparaname;
  781. crc:=UpdateCrc32(crc,hs[1],length(hs));
  782. end;
  783. end;
  784. hs:=hp.vartype.def.mangledparaname;
  785. crc:=UpdateCrc32(crc,hs[1],length(hs));
  786. s:=Copy(s,1,oldlen)+'$crc'+hexstr(crc,8);
  787. end;
  788. if prefix<>'' then
  789. prefix:=s+'_'+prefix
  790. else
  791. prefix:=s;
  792. st:=st.defowner.owner;
  793. end;
  794. { object/classes symtable }
  795. if (st.symtabletype=objectsymtable) then
  796. begin
  797. if st.defowner.deftype<>objectdef then
  798. internalerror(200204174);
  799. prefix:=tobjectdef(st.defowner).objname^+'_$_'+prefix;
  800. st:=st.defowner.owner;
  801. end;
  802. { symtable must now be static or global }
  803. if not(st.symtabletype in [staticsymtable,globalsymtable]) then
  804. internalerror(200204175);
  805. result:='';
  806. if typeprefix<>'' then
  807. result:=result+typeprefix+'_';
  808. { Add P$ for program, which can have the same name as
  809. a unit }
  810. if (tsymtable(main_module.localsymtable)=st) and
  811. (not main_module.is_unit) then
  812. result:=result+'P$'+st.name^
  813. else
  814. result:=result+st.name^;
  815. if prefix<>'' then
  816. result:=result+'_'+prefix;
  817. if suffix<>'' then
  818. result:=result+'_'+suffix;
  819. { the Darwin assembler assumes that all symbols starting with 'L' are local }
  820. if (target_info.system in [system_powerpc_darwin,system_i386_darwin]) and
  821. (result[1] = 'L') then
  822. result := '_' + result;
  823. end;
  824. {****************************************************************************
  825. TDEF (base class for definitions)
  826. ****************************************************************************}
  827. constructor tstoreddef.create(dt:tdeftype);
  828. var
  829. insertstack : psymtablestackitem;
  830. begin
  831. inherited create(dt);
  832. savesize := 0;
  833. {$ifdef EXTDEBUG}
  834. fileinfo := aktfilepos;
  835. {$endif}
  836. fillchar(localrttilab,sizeof(localrttilab),0);
  837. generictokenbuf:=nil;
  838. genericdef:=nil;
  839. { Register in symtable stack.
  840. Don't register forwarddefs, they are disposed at the
  841. end of an type block }
  842. if assigned(symtablestack) and
  843. (dt<>forwarddef) then
  844. begin
  845. insertstack:=symtablestack.stack;
  846. while assigned(insertstack) and
  847. (insertstack^.symtable.symtabletype=withsymtable) do
  848. insertstack:=insertstack^.next;
  849. if not assigned(insertstack) then
  850. internalerror(200602044);
  851. insertstack^.symtable.insertdef(self);
  852. end;
  853. end;
  854. destructor tstoreddef.destroy;
  855. begin
  856. { remove also index from symtable }
  857. if assigned(owner) then
  858. owner.deletedef(self);
  859. if assigned(generictokenbuf) then
  860. generictokenbuf.free;
  861. inherited destroy;
  862. end;
  863. constructor tstoreddef.ppuload(dt:tdeftype;ppufile:tcompilerppufile);
  864. var
  865. sizeleft,i : longint;
  866. buf : array[0..255] of byte;
  867. begin
  868. inherited create(dt);
  869. {$ifdef EXTDEBUG}
  870. fillchar(fileinfo,sizeof(fileinfo),0);
  871. {$endif}
  872. fillchar(localrttilab,sizeof(localrttilab),0);
  873. { load }
  874. indexnr:=ppufile.getword;
  875. ppufile.getderef(typesymderef);
  876. ppufile.getsmallset(defoptions);
  877. if df_has_rttitable in defoptions then
  878. ppufile.getderef(rttitablesymderef);
  879. if df_has_inittable in defoptions then
  880. ppufile.getderef(inittablesymderef);
  881. if df_generic in defoptions then
  882. begin
  883. sizeleft:=ppufile.getlongint;
  884. initgeneric;
  885. while sizeleft>0 do
  886. begin
  887. if sizeleft>sizeof(buf) then
  888. i:=sizeof(buf)
  889. else
  890. i:=sizeleft;
  891. ppufile.getdata(buf,i);
  892. generictokenbuf.write(buf,i);
  893. dec(sizeleft,i);
  894. end;
  895. end;
  896. if df_specialization in defoptions then
  897. ppufile.getderef(genericdefderef);
  898. end;
  899. procedure Tstoreddef.reset;
  900. begin
  901. if assigned(rttitablesym) then
  902. trttisym(rttitablesym).lab := nil;
  903. if assigned(inittablesym) then
  904. trttisym(inittablesym).lab := nil;
  905. localrttilab[initrtti]:=nil;
  906. localrttilab[fullrtti]:=nil;
  907. end;
  908. function tstoreddef.getcopy : tstoreddef;
  909. begin
  910. Message(sym_e_cant_create_unique_type);
  911. getcopy:=terrordef.create;
  912. end;
  913. procedure tstoreddef.ppuwrite(ppufile:tcompilerppufile);
  914. var
  915. sizeleft,i : longint;
  916. buf : array[0..255] of byte;
  917. oldintfcrc : boolean;
  918. begin
  919. ppufile.putword(indexnr);
  920. ppufile.putderef(typesymderef);
  921. ppufile.putsmallset(defoptions);
  922. if df_has_rttitable in defoptions then
  923. ppufile.putderef(rttitablesymderef);
  924. if df_has_inittable in defoptions then
  925. ppufile.putderef(inittablesymderef);
  926. if df_generic in defoptions then
  927. begin
  928. oldintfcrc:=ppufile.do_interface_crc;
  929. ppufile.do_interface_crc:=false;
  930. if assigned(generictokenbuf) then
  931. begin
  932. sizeleft:=generictokenbuf.size;
  933. generictokenbuf.seek(0);
  934. end
  935. else
  936. sizeleft:=0;
  937. ppufile.putlongint(sizeleft);
  938. while sizeleft>0 do
  939. begin
  940. if sizeleft>sizeof(buf) then
  941. i:=sizeof(buf)
  942. else
  943. i:=sizeleft;
  944. generictokenbuf.read(buf,i);
  945. ppufile.putdata(buf,i);
  946. dec(sizeleft,i);
  947. end;
  948. ppufile.do_interface_crc:=oldintfcrc;
  949. end;
  950. if df_specialization in defoptions then
  951. ppufile.putderef(genericdefderef);
  952. end;
  953. procedure tstoreddef.buildderef;
  954. begin
  955. typesymderef.build(typesym);
  956. rttitablesymderef.build(rttitablesym);
  957. inittablesymderef.build(inittablesym);
  958. genericdefderef.build(genericdef);
  959. end;
  960. procedure tstoreddef.buildderefimpl;
  961. begin
  962. end;
  963. procedure tstoreddef.deref;
  964. begin
  965. typesym:=ttypesym(typesymderef.resolve);
  966. if df_has_rttitable in defoptions then
  967. rttitablesym:=trttisym(rttitablesymderef.resolve);
  968. if df_has_inittable in defoptions then
  969. inittablesym:=trttisym(inittablesymderef.resolve);
  970. if df_specialization in defoptions then
  971. genericdef:=tstoreddef(genericdefderef.resolve);
  972. end;
  973. procedure tstoreddef.derefimpl;
  974. begin
  975. end;
  976. function tstoreddef.size : aint;
  977. begin
  978. size:=savesize;
  979. end;
  980. function tstoreddef.getvartype:longint;
  981. begin
  982. result:=varUndefined;
  983. end;
  984. function tstoreddef.alignment : shortint;
  985. begin
  986. { natural alignment by default }
  987. alignment:=size_2_align(savesize);
  988. end;
  989. procedure tstoreddef.write_rtti_name;
  990. var
  991. str : string;
  992. begin
  993. { name }
  994. if assigned(typesym) then
  995. begin
  996. str:=ttypesym(typesym).realname;
  997. current_asmdata.asmlists[al_rtti].concat(Tai_string.Create(chr(length(str))+str));
  998. end
  999. else
  1000. current_asmdata.asmlists[al_rtti].concat(Tai_string.Create(#0))
  1001. end;
  1002. procedure tstoreddef.write_rtti_data(rt:trttitype);
  1003. begin
  1004. current_asmdata.asmlists[al_rtti].concat(tai_const.create_8bit(tkUnknown));
  1005. write_rtti_name;
  1006. end;
  1007. procedure tstoreddef.write_child_rtti_data(rt:trttitype);
  1008. begin
  1009. end;
  1010. function tstoreddef.get_rtti_label(rt:trttitype) : tasmsymbol;
  1011. begin
  1012. { try to reuse persistent rtti data }
  1013. if (rt=fullrtti) and (df_has_rttitable in defoptions) then
  1014. get_rtti_label:=trttisym(rttitablesym).get_label
  1015. else
  1016. if (rt=initrtti) and (df_has_inittable in defoptions) then
  1017. get_rtti_label:=trttisym(inittablesym).get_label
  1018. else
  1019. begin
  1020. if not assigned(localrttilab[rt]) then
  1021. begin
  1022. current_asmdata.getdatalabel(localrttilab[rt]);
  1023. write_child_rtti_data(rt);
  1024. maybe_new_object_file(current_asmdata.asmlists[al_rtti]);
  1025. new_section(current_asmdata.asmlists[al_rtti],sec_rodata,localrttilab[rt].name,const_align(sizeof(aint)));
  1026. current_asmdata.asmlists[al_rtti].concat(Tai_symbol.Create_global(localrttilab[rt],0));
  1027. write_rtti_data(rt);
  1028. current_asmdata.asmlists[al_rtti].concat(Tai_symbol_end.Create(localrttilab[rt]));
  1029. end;
  1030. get_rtti_label:=localrttilab[rt];
  1031. end;
  1032. end;
  1033. { returns true, if the definition can be published }
  1034. function tstoreddef.is_publishable : boolean;
  1035. begin
  1036. is_publishable:=false;
  1037. end;
  1038. { needs an init table }
  1039. function tstoreddef.needs_inittable : boolean;
  1040. begin
  1041. needs_inittable:=false;
  1042. end;
  1043. function tstoreddef.is_intregable : boolean;
  1044. begin
  1045. is_intregable:=false;
  1046. case deftype of
  1047. orddef,
  1048. pointerdef,
  1049. enumdef,
  1050. classrefdef:
  1051. is_intregable:=true;
  1052. procvardef :
  1053. is_intregable:=not(po_methodpointer in tprocvardef(self).procoptions);
  1054. objectdef:
  1055. is_intregable:=is_class(self) or is_interface(self);
  1056. setdef:
  1057. is_intregable:=(tsetdef(self).settype=smallset);
  1058. end;
  1059. end;
  1060. function tstoreddef.is_fpuregable : boolean;
  1061. begin
  1062. {$ifdef x86}
  1063. result:=use_sse(self);
  1064. {$else x86}
  1065. result:=(deftype=floatdef) and not(cs_fp_emulation in aktmoduleswitches);
  1066. {$endif x86}
  1067. end;
  1068. procedure tstoreddef.initgeneric;
  1069. begin
  1070. if assigned(generictokenbuf) then
  1071. internalerror(200512131);
  1072. generictokenbuf:=tdynamicarray.create(256);
  1073. end;
  1074. {****************************************************************************
  1075. Tstringdef
  1076. ****************************************************************************}
  1077. constructor tstringdef.createshort(l : byte);
  1078. begin
  1079. inherited create(stringdef);
  1080. string_typ:=st_shortstring;
  1081. len:=l;
  1082. savesize:=len+1;
  1083. end;
  1084. constructor tstringdef.loadshort(ppufile:tcompilerppufile);
  1085. begin
  1086. inherited ppuload(stringdef,ppufile);
  1087. string_typ:=st_shortstring;
  1088. len:=ppufile.getbyte;
  1089. savesize:=len+1;
  1090. end;
  1091. constructor tstringdef.createlong(l : aint);
  1092. begin
  1093. inherited create(stringdef);
  1094. string_typ:=st_longstring;
  1095. len:=l;
  1096. savesize:=sizeof(aint);
  1097. end;
  1098. constructor tstringdef.loadlong(ppufile:tcompilerppufile);
  1099. begin
  1100. inherited ppuload(stringdef,ppufile);
  1101. string_typ:=st_longstring;
  1102. len:=ppufile.getaint;
  1103. savesize:=sizeof(aint);
  1104. end;
  1105. constructor tstringdef.createansi(l:aint);
  1106. begin
  1107. inherited create(stringdef);
  1108. string_typ:=st_ansistring;
  1109. len:=l;
  1110. savesize:=sizeof(aint);
  1111. end;
  1112. constructor tstringdef.loadansi(ppufile:tcompilerppufile);
  1113. begin
  1114. inherited ppuload(stringdef,ppufile);
  1115. string_typ:=st_ansistring;
  1116. len:=ppufile.getaint;
  1117. savesize:=sizeof(aint);
  1118. end;
  1119. constructor tstringdef.createwide(l : aint);
  1120. begin
  1121. inherited create(stringdef);
  1122. string_typ:=st_widestring;
  1123. len:=l;
  1124. savesize:=sizeof(aint);
  1125. end;
  1126. constructor tstringdef.loadwide(ppufile:tcompilerppufile);
  1127. begin
  1128. inherited ppuload(stringdef,ppufile);
  1129. string_typ:=st_widestring;
  1130. len:=ppufile.getaint;
  1131. savesize:=sizeof(aint);
  1132. end;
  1133. function tstringdef.getcopy : tstoreddef;
  1134. begin
  1135. result:=tstringdef.create(deftype);
  1136. result.deftype:=stringdef;
  1137. tstringdef(result).string_typ:=string_typ;
  1138. tstringdef(result).len:=len;
  1139. tstringdef(result).savesize:=savesize;
  1140. end;
  1141. function tstringdef.stringtypname:string;
  1142. const
  1143. typname:array[tstringtype] of string[8]=(
  1144. 'shortstr','longstr','ansistr','widestr'
  1145. );
  1146. begin
  1147. stringtypname:=typname[string_typ];
  1148. end;
  1149. procedure tstringdef.ppuwrite(ppufile:tcompilerppufile);
  1150. begin
  1151. inherited ppuwrite(ppufile);
  1152. if string_typ=st_shortstring then
  1153. begin
  1154. {$ifdef extdebug}
  1155. if len > 255 then internalerror(12122002);
  1156. {$endif}
  1157. ppufile.putbyte(byte(len))
  1158. end
  1159. else
  1160. ppufile.putaint(len);
  1161. case string_typ of
  1162. st_shortstring : ppufile.writeentry(ibshortstringdef);
  1163. st_longstring : ppufile.writeentry(iblongstringdef);
  1164. st_ansistring : ppufile.writeentry(ibansistringdef);
  1165. st_widestring : ppufile.writeentry(ibwidestringdef);
  1166. end;
  1167. end;
  1168. function tstringdef.needs_inittable : boolean;
  1169. begin
  1170. needs_inittable:=string_typ in [st_ansistring,st_widestring];
  1171. end;
  1172. function tstringdef.gettypename : string;
  1173. const
  1174. names : array[tstringtype] of string[11] = (
  1175. 'ShortString','LongString','AnsiString','WideString');
  1176. begin
  1177. gettypename:=names[string_typ];
  1178. end;
  1179. function tstringdef.alignment : shortint;
  1180. begin
  1181. case string_typ of
  1182. st_widestring,
  1183. st_ansistring:
  1184. alignment:=size_2_align(savesize);
  1185. st_longstring,
  1186. st_shortstring:
  1187. {$ifdef cpurequiresproperalignment}
  1188. { char to string accesses byte 0 and 1 with one word access }
  1189. alignment:=size_2_align(2);
  1190. {$else cpurequiresproperalignment}
  1191. alignment:=size_2_align(1);
  1192. {$endif cpurequiresproperalignment}
  1193. else
  1194. internalerror(200412301);
  1195. end;
  1196. end;
  1197. procedure tstringdef.write_rtti_data(rt:trttitype);
  1198. begin
  1199. case string_typ of
  1200. st_ansistring:
  1201. begin
  1202. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_8bit(tkAString));
  1203. write_rtti_name;
  1204. end;
  1205. st_widestring:
  1206. begin
  1207. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_8bit(tkWString));
  1208. write_rtti_name;
  1209. end;
  1210. st_longstring:
  1211. begin
  1212. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_8bit(tkLString));
  1213. write_rtti_name;
  1214. end;
  1215. st_shortstring:
  1216. begin
  1217. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_8bit(tkSString));
  1218. write_rtti_name;
  1219. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_8bit(len));
  1220. {$ifdef cpurequiresproperalignment}
  1221. current_asmdata.asmlists[al_rtti].concat(Tai_align.Create(sizeof(TConstPtrUInt)));
  1222. {$endif cpurequiresproperalignment}
  1223. end;
  1224. end;
  1225. end;
  1226. function tstringdef.getmangledparaname : string;
  1227. begin
  1228. getmangledparaname:='STRING';
  1229. end;
  1230. function tstringdef.is_publishable : boolean;
  1231. begin
  1232. is_publishable:=true;
  1233. end;
  1234. {****************************************************************************
  1235. TENUMDEF
  1236. ****************************************************************************}
  1237. constructor tenumdef.create;
  1238. begin
  1239. inherited create(enumdef);
  1240. minval:=0;
  1241. maxval:=0;
  1242. calcsavesize;
  1243. has_jumps:=false;
  1244. basedef:=nil;
  1245. firstenum:=nil;
  1246. end;
  1247. constructor tenumdef.create_subrange(_basedef:tenumdef;_min,_max:aint);
  1248. begin
  1249. inherited create(enumdef);
  1250. minval:=_min;
  1251. maxval:=_max;
  1252. basedef:=_basedef;
  1253. calcsavesize;
  1254. has_jumps:=false;
  1255. firstenum:=basedef.firstenum;
  1256. while assigned(firstenum) and (tenumsym(firstenum).value<>minval) do
  1257. firstenum:=tenumsym(firstenum).nextenum;
  1258. end;
  1259. constructor tenumdef.ppuload(ppufile:tcompilerppufile);
  1260. begin
  1261. inherited ppuload(enumdef,ppufile);
  1262. ppufile.getderef(basedefderef);
  1263. minval:=ppufile.getaint;
  1264. maxval:=ppufile.getaint;
  1265. savesize:=ppufile.getaint;
  1266. has_jumps:=false;
  1267. firstenum:=Nil;
  1268. end;
  1269. function tenumdef.getcopy : tstoreddef;
  1270. begin
  1271. if assigned(basedef) then
  1272. result:=tenumdef.create_subrange(basedef,minval,maxval)
  1273. else
  1274. begin
  1275. result:=tenumdef.create;
  1276. tenumdef(result).minval:=minval;
  1277. tenumdef(result).maxval:=maxval;
  1278. end;
  1279. tenumdef(result).has_jumps:=has_jumps;
  1280. tenumdef(result).firstenum:=firstenum;
  1281. tenumdef(result).basedefderef:=basedefderef;
  1282. end;
  1283. procedure tenumdef.calcsavesize;
  1284. begin
  1285. if (aktpackenum=8) or (min<low(longint)) or (int64(max)>high(cardinal)) then
  1286. savesize:=8
  1287. else
  1288. if (aktpackenum=4) or (min<low(smallint)) or (max>high(word)) then
  1289. savesize:=4
  1290. else
  1291. if (aktpackenum=2) or (min<low(shortint)) or (max>high(byte)) then
  1292. savesize:=2
  1293. else
  1294. savesize:=1;
  1295. end;
  1296. procedure tenumdef.setmax(_max:aint);
  1297. begin
  1298. maxval:=_max;
  1299. calcsavesize;
  1300. end;
  1301. procedure tenumdef.setmin(_min:aint);
  1302. begin
  1303. minval:=_min;
  1304. calcsavesize;
  1305. end;
  1306. function tenumdef.min:aint;
  1307. begin
  1308. min:=minval;
  1309. end;
  1310. function tenumdef.max:aint;
  1311. begin
  1312. max:=maxval;
  1313. end;
  1314. procedure tenumdef.buildderef;
  1315. begin
  1316. inherited buildderef;
  1317. basedefderef.build(basedef);
  1318. end;
  1319. procedure tenumdef.deref;
  1320. begin
  1321. inherited deref;
  1322. basedef:=tenumdef(basedefderef.resolve);
  1323. { restart ordering }
  1324. firstenum:=nil;
  1325. end;
  1326. procedure tenumdef.derefimpl;
  1327. begin
  1328. if assigned(basedef) and
  1329. (firstenum=nil) then
  1330. begin
  1331. firstenum:=basedef.firstenum;
  1332. while assigned(firstenum) and (tenumsym(firstenum).value<>minval) do
  1333. firstenum:=tenumsym(firstenum).nextenum;
  1334. end;
  1335. end;
  1336. destructor tenumdef.destroy;
  1337. begin
  1338. inherited destroy;
  1339. end;
  1340. procedure tenumdef.ppuwrite(ppufile:tcompilerppufile);
  1341. begin
  1342. inherited ppuwrite(ppufile);
  1343. ppufile.putderef(basedefderef);
  1344. ppufile.putaint(min);
  1345. ppufile.putaint(max);
  1346. ppufile.putaint(savesize);
  1347. ppufile.writeentry(ibenumdef);
  1348. end;
  1349. procedure tenumdef.write_child_rtti_data(rt:trttitype);
  1350. begin
  1351. if assigned(basedef) then
  1352. basedef.get_rtti_label(rt);
  1353. end;
  1354. procedure tenumdef.write_rtti_data(rt:trttitype);
  1355. var
  1356. hp : tenumsym;
  1357. begin
  1358. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_8bit(tkEnumeration));
  1359. write_rtti_name;
  1360. {$ifdef cpurequiresproperalignment}
  1361. current_asmdata.asmlists[al_rtti].concat(Tai_align.Create(sizeof(TConstPtrUInt)));
  1362. {$endif cpurequiresproperalignment}
  1363. case longint(savesize) of
  1364. 1:
  1365. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_8bit(otUByte));
  1366. 2:
  1367. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_8bit(otUWord));
  1368. 4:
  1369. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_8bit(otULong));
  1370. end;
  1371. {$ifdef cpurequiresproperalignment}
  1372. current_asmdata.asmlists[al_rtti].concat(Tai_align.Create(4));
  1373. {$endif cpurequiresproperalignment}
  1374. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_32bit(min));
  1375. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_32bit(max));
  1376. if assigned(basedef) then
  1377. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_sym(basedef.get_rtti_label(rt)))
  1378. else
  1379. current_asmdata.asmlists[al_rtti].concat(Tai_const.create_sym(nil));
  1380. hp:=tenumsym(firstenum);
  1381. while assigned(hp) do
  1382. begin
  1383. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_8bit(length(hp.realname)));
  1384. current_asmdata.asmlists[al_rtti].concat(Tai_string.Create(hp.realname));
  1385. hp:=hp.nextenum;
  1386. end;
  1387. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_8bit(0));
  1388. end;
  1389. function tenumdef.is_publishable : boolean;
  1390. begin
  1391. is_publishable:=true;
  1392. end;
  1393. function tenumdef.gettypename : string;
  1394. begin
  1395. gettypename:='<enumeration type>';
  1396. end;
  1397. {****************************************************************************
  1398. TORDDEF
  1399. ****************************************************************************}
  1400. constructor torddef.create(t : tbasetype;v,b : TConstExprInt);
  1401. begin
  1402. inherited create(orddef);
  1403. low:=v;
  1404. high:=b;
  1405. typ:=t;
  1406. setsize;
  1407. end;
  1408. constructor torddef.ppuload(ppufile:tcompilerppufile);
  1409. begin
  1410. inherited ppuload(orddef,ppufile);
  1411. typ:=tbasetype(ppufile.getbyte);
  1412. if sizeof(TConstExprInt)=8 then
  1413. begin
  1414. low:=ppufile.getint64;
  1415. high:=ppufile.getint64;
  1416. end
  1417. else
  1418. begin
  1419. low:=ppufile.getlongint;
  1420. high:=ppufile.getlongint;
  1421. end;
  1422. setsize;
  1423. end;
  1424. function torddef.getcopy : tstoreddef;
  1425. begin
  1426. result:=torddef.create(typ,low,high);
  1427. result.deftype:=orddef;
  1428. torddef(result).low:=low;
  1429. torddef(result).high:=high;
  1430. torddef(result).typ:=typ;
  1431. torddef(result).savesize:=savesize;
  1432. end;
  1433. function torddef.alignment:shortint;
  1434. begin
  1435. if (target_info.system = system_i386_darwin) and
  1436. (typ in [s64bit,u64bit]) then
  1437. result := 4
  1438. else
  1439. result := inherited alignment;
  1440. end;
  1441. procedure torddef.setsize;
  1442. const
  1443. sizetbl : array[tbasetype] of longint = (
  1444. 0,
  1445. 1,2,4,8,
  1446. 1,2,4,8,
  1447. 1,2,4,
  1448. 1,2,8
  1449. );
  1450. begin
  1451. savesize:=sizetbl[typ];
  1452. end;
  1453. function torddef.getvartype : longint;
  1454. const
  1455. basetype2vartype : array[tbasetype] of longint = (
  1456. varUndefined,
  1457. varbyte,varqword,varlongword,varqword,
  1458. varshortint,varsmallint,varinteger,varint64,
  1459. varboolean,varUndefined,varUndefined,
  1460. varUndefined,varUndefined,varCurrency);
  1461. begin
  1462. result:=basetype2vartype[typ];
  1463. end;
  1464. procedure torddef.ppuwrite(ppufile:tcompilerppufile);
  1465. begin
  1466. inherited ppuwrite(ppufile);
  1467. ppufile.putbyte(byte(typ));
  1468. if sizeof(TConstExprInt)=8 then
  1469. begin
  1470. ppufile.putint64(low);
  1471. ppufile.putint64(high);
  1472. end
  1473. else
  1474. begin
  1475. ppufile.putlongint(low);
  1476. ppufile.putlongint(high);
  1477. end;
  1478. ppufile.writeentry(iborddef);
  1479. end;
  1480. procedure torddef.write_rtti_data(rt:trttitype);
  1481. procedure dointeger;
  1482. const
  1483. trans : array[tbasetype] of byte =
  1484. (otUByte{otNone},
  1485. otUByte,otUWord,otULong,otUByte{otNone},
  1486. otSByte,otSWord,otSLong,otUByte{otNone},
  1487. otUByte,otUWord,otULong,
  1488. otUByte,otUWord,otUByte);
  1489. begin
  1490. write_rtti_name;
  1491. {$ifdef cpurequiresproperalignment}
  1492. current_asmdata.asmlists[al_rtti].concat(Tai_align.Create(sizeof(TConstPtrUInt)));
  1493. {$endif cpurequiresproperalignment}
  1494. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_8bit(byte(trans[typ])));
  1495. {$ifdef cpurequiresproperalignment}
  1496. current_asmdata.asmlists[al_rtti].concat(Tai_align.Create(4));
  1497. {$endif cpurequiresproperalignment}
  1498. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_32bit(longint(low)));
  1499. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_32bit(longint(high)));
  1500. end;
  1501. begin
  1502. case typ of
  1503. s64bit :
  1504. begin
  1505. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_8bit(tkInt64));
  1506. write_rtti_name;
  1507. {$ifdef cpurequiresproperalignment}
  1508. current_asmdata.asmlists[al_rtti].concat(Tai_align.Create(sizeof(TConstPtrUInt)));
  1509. {$endif cpurequiresproperalignment}
  1510. { low }
  1511. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_64bit(int64($80000000) shl 32));
  1512. { high }
  1513. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_64bit((int64($7fffffff) shl 32) or int64($ffffffff)));
  1514. end;
  1515. u64bit :
  1516. begin
  1517. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_8bit(tkQWord));
  1518. write_rtti_name;
  1519. {$ifdef cpurequiresproperalignment}
  1520. current_asmdata.asmlists[al_rtti].concat(Tai_align.Create(sizeof(TConstPtrUInt)));
  1521. {$endif cpurequiresproperalignment}
  1522. { low }
  1523. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_64bit(0));
  1524. { high }
  1525. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_64bit(int64((int64($ffffffff) shl 32) or int64($ffffffff))));
  1526. end;
  1527. bool8bit:
  1528. begin
  1529. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_8bit(tkBool));
  1530. dointeger;
  1531. end;
  1532. uchar:
  1533. begin
  1534. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_8bit(tkChar));
  1535. dointeger;
  1536. end;
  1537. uwidechar:
  1538. begin
  1539. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_8bit(tkWChar));
  1540. dointeger;
  1541. end;
  1542. else
  1543. begin
  1544. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_8bit(tkInteger));
  1545. dointeger;
  1546. end;
  1547. end;
  1548. end;
  1549. function torddef.is_publishable : boolean;
  1550. begin
  1551. is_publishable:=(typ<>uvoid);
  1552. end;
  1553. function torddef.gettypename : string;
  1554. const
  1555. names : array[tbasetype] of string[20] = (
  1556. 'untyped',
  1557. 'Byte','Word','DWord','QWord',
  1558. 'ShortInt','SmallInt','LongInt','Int64',
  1559. 'Boolean','WordBool','LongBool',
  1560. 'Char','WideChar','Currency');
  1561. begin
  1562. gettypename:=names[typ];
  1563. end;
  1564. {****************************************************************************
  1565. TFLOATDEF
  1566. ****************************************************************************}
  1567. constructor tfloatdef.create(t : tfloattype);
  1568. begin
  1569. inherited create(floatdef);
  1570. typ:=t;
  1571. setsize;
  1572. end;
  1573. constructor tfloatdef.ppuload(ppufile:tcompilerppufile);
  1574. begin
  1575. inherited ppuload(floatdef,ppufile);
  1576. typ:=tfloattype(ppufile.getbyte);
  1577. setsize;
  1578. end;
  1579. function tfloatdef.getcopy : tstoreddef;
  1580. begin
  1581. result:=tfloatdef.create(typ);
  1582. result.deftype:=floatdef;
  1583. tfloatdef(result).savesize:=savesize;
  1584. end;
  1585. function tfloatdef.alignment:shortint;
  1586. begin
  1587. if (target_info.system = system_i386_darwin) then
  1588. case typ of
  1589. s80real : result:=16;
  1590. s64real,
  1591. s64currency,
  1592. s64comp : result:=4;
  1593. else
  1594. result := inherited alignment;
  1595. end
  1596. else
  1597. result := inherited alignment;
  1598. end;
  1599. procedure tfloatdef.setsize;
  1600. begin
  1601. case typ of
  1602. s32real : savesize:=4;
  1603. s80real : savesize:=10;
  1604. s64real,
  1605. s64currency,
  1606. s64comp : savesize:=8;
  1607. else
  1608. savesize:=0;
  1609. end;
  1610. end;
  1611. function tfloatdef.getvartype : longint;
  1612. const
  1613. floattype2vartype : array[tfloattype] of longint = (
  1614. varSingle,varDouble,varUndefined,
  1615. varUndefined,varCurrency,varUndefined);
  1616. begin
  1617. if (upper(typename)='TDATETIME') and
  1618. assigned(owner) and
  1619. assigned(owner.name) and
  1620. (owner.name^='SYSTEM') then
  1621. result:=varDate
  1622. else
  1623. result:=floattype2vartype[typ];
  1624. end;
  1625. procedure tfloatdef.ppuwrite(ppufile:tcompilerppufile);
  1626. begin
  1627. inherited ppuwrite(ppufile);
  1628. ppufile.putbyte(byte(typ));
  1629. ppufile.writeentry(ibfloatdef);
  1630. end;
  1631. procedure tfloatdef.write_rtti_data(rt:trttitype);
  1632. const
  1633. {tfloattype = (s32real,s64real,s80real,s64bit,s128bit);}
  1634. translate : array[tfloattype] of byte =
  1635. (ftSingle,ftDouble,ftExtended,ftComp,ftCurr,ftFloat128);
  1636. begin
  1637. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_8bit(tkFloat));
  1638. write_rtti_name;
  1639. {$ifdef cpurequiresproperalignment}
  1640. current_asmdata.asmlists[al_rtti].concat(Tai_align.Create(sizeof(TConstPtrUInt)));
  1641. {$endif cpurequiresproperalignment}
  1642. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_8bit(translate[typ]));
  1643. end;
  1644. function tfloatdef.is_publishable : boolean;
  1645. begin
  1646. is_publishable:=true;
  1647. end;
  1648. function tfloatdef.gettypename : string;
  1649. const
  1650. names : array[tfloattype] of string[20] = (
  1651. 'Single','Double','Extended','Comp','Currency','Float128');
  1652. begin
  1653. gettypename:=names[typ];
  1654. end;
  1655. {****************************************************************************
  1656. TFILEDEF
  1657. ****************************************************************************}
  1658. constructor tfiledef.createtext;
  1659. begin
  1660. inherited create(filedef);
  1661. filetyp:=ft_text;
  1662. typedfiletype.reset;
  1663. setsize;
  1664. end;
  1665. constructor tfiledef.createuntyped;
  1666. begin
  1667. inherited create(filedef);
  1668. filetyp:=ft_untyped;
  1669. typedfiletype.reset;
  1670. setsize;
  1671. end;
  1672. constructor tfiledef.createtyped(const tt : ttype);
  1673. begin
  1674. inherited create(filedef);
  1675. filetyp:=ft_typed;
  1676. typedfiletype:=tt;
  1677. setsize;
  1678. end;
  1679. constructor tfiledef.ppuload(ppufile:tcompilerppufile);
  1680. begin
  1681. inherited ppuload(filedef,ppufile);
  1682. filetyp:=tfiletyp(ppufile.getbyte);
  1683. if filetyp=ft_typed then
  1684. ppufile.gettype(typedfiletype)
  1685. else
  1686. typedfiletype.reset;
  1687. setsize;
  1688. end;
  1689. function tfiledef.getcopy : tstoreddef;
  1690. begin
  1691. case filetyp of
  1692. ft_typed:
  1693. result:=tfiledef.createtyped(typedfiletype);
  1694. ft_untyped:
  1695. result:=tfiledef.createuntyped;
  1696. ft_text:
  1697. result:=tfiledef.createtext;
  1698. else
  1699. internalerror(2004121201);
  1700. end;
  1701. end;
  1702. procedure tfiledef.buildderef;
  1703. begin
  1704. inherited buildderef;
  1705. if filetyp=ft_typed then
  1706. typedfiletype.buildderef;
  1707. end;
  1708. procedure tfiledef.deref;
  1709. begin
  1710. inherited deref;
  1711. if filetyp=ft_typed then
  1712. typedfiletype.resolve;
  1713. end;
  1714. procedure tfiledef.setsize;
  1715. begin
  1716. {$ifdef cpu64bit}
  1717. case filetyp of
  1718. ft_text :
  1719. if target_info.system in [system_x86_64_win64,system_ia64_win64] then
  1720. savesize:=632
  1721. else
  1722. savesize:=628;
  1723. ft_typed,
  1724. ft_untyped :
  1725. if target_info.system in [system_x86_64_win64,system_ia64_win64] then
  1726. savesize:=372
  1727. else
  1728. savesize:=368;
  1729. end;
  1730. {$else cpu64bit}
  1731. case filetyp of
  1732. ft_text :
  1733. savesize:=592;
  1734. ft_typed,
  1735. ft_untyped :
  1736. savesize:=332;
  1737. end;
  1738. {$endif cpu64bit}
  1739. end;
  1740. procedure tfiledef.ppuwrite(ppufile:tcompilerppufile);
  1741. begin
  1742. inherited ppuwrite(ppufile);
  1743. ppufile.putbyte(byte(filetyp));
  1744. if filetyp=ft_typed then
  1745. ppufile.puttype(typedfiletype);
  1746. ppufile.writeentry(ibfiledef);
  1747. end;
  1748. function tfiledef.gettypename : string;
  1749. begin
  1750. case filetyp of
  1751. ft_untyped:
  1752. gettypename:='File';
  1753. ft_typed:
  1754. gettypename:='File Of '+typedfiletype.def.typename;
  1755. ft_text:
  1756. gettypename:='Text'
  1757. end;
  1758. end;
  1759. function tfiledef.getmangledparaname : string;
  1760. begin
  1761. case filetyp of
  1762. ft_untyped:
  1763. getmangledparaname:='FILE';
  1764. ft_typed:
  1765. getmangledparaname:='FILE$OF$'+typedfiletype.def.mangledparaname;
  1766. ft_text:
  1767. getmangledparaname:='TEXT'
  1768. end;
  1769. end;
  1770. {****************************************************************************
  1771. TVARIANTDEF
  1772. ****************************************************************************}
  1773. constructor tvariantdef.create(v : tvarianttype);
  1774. begin
  1775. inherited create(variantdef);
  1776. varianttype:=v;
  1777. setsize;
  1778. end;
  1779. constructor tvariantdef.ppuload(ppufile:tcompilerppufile);
  1780. begin
  1781. inherited ppuload(variantdef,ppufile);
  1782. varianttype:=tvarianttype(ppufile.getbyte);
  1783. setsize;
  1784. end;
  1785. function tvariantdef.getcopy : tstoreddef;
  1786. begin
  1787. result:=tvariantdef.create(varianttype);
  1788. end;
  1789. procedure tvariantdef.ppuwrite(ppufile:tcompilerppufile);
  1790. begin
  1791. inherited ppuwrite(ppufile);
  1792. ppufile.putbyte(byte(varianttype));
  1793. ppufile.writeentry(ibvariantdef);
  1794. end;
  1795. procedure tvariantdef.setsize;
  1796. begin
  1797. savesize:=16;
  1798. end;
  1799. function tvariantdef.gettypename : string;
  1800. begin
  1801. case varianttype of
  1802. vt_normalvariant:
  1803. gettypename:='Variant';
  1804. vt_olevariant:
  1805. gettypename:='OleVariant';
  1806. end;
  1807. end;
  1808. procedure tvariantdef.write_rtti_data(rt:trttitype);
  1809. begin
  1810. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_8bit(tkVariant));
  1811. end;
  1812. function tvariantdef.needs_inittable : boolean;
  1813. begin
  1814. needs_inittable:=true;
  1815. end;
  1816. function tvariantdef.is_publishable : boolean;
  1817. begin
  1818. is_publishable:=true;
  1819. end;
  1820. {****************************************************************************
  1821. TABSTRACTPOINTERDEF
  1822. ****************************************************************************}
  1823. constructor tabstractpointerdef.create(dt:tdeftype;const tt : ttype);
  1824. begin
  1825. inherited create(dt);
  1826. pointertype:=tt;
  1827. savesize:=sizeof(aint);
  1828. end;
  1829. constructor tabstractpointerdef.ppuload(dt:tdeftype;ppufile:tcompilerppufile);
  1830. begin
  1831. inherited ppuload(dt,ppufile);
  1832. ppufile.gettype(pointertype);
  1833. savesize:=sizeof(aint);
  1834. end;
  1835. procedure tabstractpointerdef.buildderef;
  1836. begin
  1837. inherited buildderef;
  1838. pointertype.buildderef;
  1839. end;
  1840. procedure tabstractpointerdef.deref;
  1841. begin
  1842. inherited deref;
  1843. pointertype.resolve;
  1844. end;
  1845. procedure tabstractpointerdef.ppuwrite(ppufile:tcompilerppufile);
  1846. begin
  1847. inherited ppuwrite(ppufile);
  1848. ppufile.puttype(pointertype);
  1849. end;
  1850. {****************************************************************************
  1851. TPOINTERDEF
  1852. ****************************************************************************}
  1853. constructor tpointerdef.create(const tt : ttype);
  1854. begin
  1855. inherited create(pointerdef,tt);
  1856. is_far:=false;
  1857. end;
  1858. constructor tpointerdef.createfar(const tt : ttype);
  1859. begin
  1860. inherited create(pointerdef,tt);
  1861. is_far:=true;
  1862. end;
  1863. constructor tpointerdef.ppuload(ppufile:tcompilerppufile);
  1864. begin
  1865. inherited ppuload(pointerdef,ppufile);
  1866. is_far:=(ppufile.getbyte<>0);
  1867. end;
  1868. function tpointerdef.getcopy : tstoreddef;
  1869. begin
  1870. result:=tpointerdef.create(pointertype);
  1871. tpointerdef(result).is_far:=is_far;
  1872. tpointerdef(result).savesize:=savesize;
  1873. end;
  1874. procedure tpointerdef.ppuwrite(ppufile:tcompilerppufile);
  1875. begin
  1876. inherited ppuwrite(ppufile);
  1877. ppufile.putbyte(byte(is_far));
  1878. ppufile.writeentry(ibpointerdef);
  1879. end;
  1880. function tpointerdef.gettypename : string;
  1881. begin
  1882. if is_far then
  1883. gettypename:='^'+pointertype.def.typename+';far'
  1884. else
  1885. gettypename:='^'+pointertype.def.typename;
  1886. end;
  1887. {****************************************************************************
  1888. TCLASSREFDEF
  1889. ****************************************************************************}
  1890. constructor tclassrefdef.create(const t:ttype);
  1891. begin
  1892. inherited create(classrefdef,t);
  1893. end;
  1894. constructor tclassrefdef.ppuload(ppufile:tcompilerppufile);
  1895. begin
  1896. inherited ppuload(classrefdef,ppufile);
  1897. end;
  1898. procedure tclassrefdef.ppuwrite(ppufile:tcompilerppufile);
  1899. begin
  1900. inherited ppuwrite(ppufile);
  1901. ppufile.writeentry(ibclassrefdef);
  1902. end;
  1903. function tclassrefdef.gettypename : string;
  1904. begin
  1905. gettypename:='Class Of '+pointertype.def.typename;
  1906. end;
  1907. function tclassrefdef.is_publishable : boolean;
  1908. begin
  1909. result:=true;
  1910. end;
  1911. {***************************************************************************
  1912. TSETDEF
  1913. ***************************************************************************}
  1914. constructor tsetdef.create(const t:ttype;high : aint);
  1915. begin
  1916. inherited create(setdef);
  1917. elementtype:=t;
  1918. // setbase:=low;
  1919. setmax:=high;
  1920. if high<32 then
  1921. begin
  1922. settype:=smallset;
  1923. {$ifdef testvarsets}
  1924. if aktsetalloc=0 THEN { $PACKSET Fixed?}
  1925. {$endif}
  1926. savesize:=Sizeof(longint)
  1927. {$ifdef testvarsets}
  1928. else {No, use $PACKSET VALUE for rounding}
  1929. savesize:=aktsetalloc*((high+aktsetalloc*8-1) DIV (aktsetalloc*8))
  1930. {$endif}
  1931. ;
  1932. end
  1933. else
  1934. if high<256 then
  1935. begin
  1936. settype:=normset;
  1937. savesize:=32;
  1938. end
  1939. else
  1940. {$ifdef testvarsets}
  1941. if high<$10000 then
  1942. begin
  1943. settype:=varset;
  1944. savesize:=4*((high+31) div 32);
  1945. end
  1946. else
  1947. {$endif testvarsets}
  1948. Message(sym_e_ill_type_decl_set);
  1949. end;
  1950. constructor tsetdef.ppuload(ppufile:tcompilerppufile);
  1951. begin
  1952. inherited ppuload(setdef,ppufile);
  1953. ppufile.gettype(elementtype);
  1954. settype:=tsettype(ppufile.getbyte);
  1955. case settype of
  1956. normset : savesize:=32;
  1957. varset : savesize:=ppufile.getlongint;
  1958. smallset : savesize:=Sizeof(longint);
  1959. end;
  1960. end;
  1961. destructor tsetdef.destroy;
  1962. begin
  1963. inherited destroy;
  1964. end;
  1965. function tsetdef.getcopy : tstoreddef;
  1966. begin
  1967. case settype of
  1968. smallset:
  1969. result:=tsetdef.create(elementtype,31);
  1970. normset:
  1971. result:=tsetdef.create(elementtype,255);
  1972. else
  1973. internalerror(2004121202);
  1974. end;
  1975. end;
  1976. procedure tsetdef.ppuwrite(ppufile:tcompilerppufile);
  1977. begin
  1978. inherited ppuwrite(ppufile);
  1979. ppufile.puttype(elementtype);
  1980. ppufile.putbyte(byte(settype));
  1981. if settype=varset then
  1982. ppufile.putlongint(savesize);
  1983. if settype=normset then
  1984. ppufile.putaint(savesize);
  1985. ppufile.writeentry(ibsetdef);
  1986. end;
  1987. procedure tsetdef.buildderef;
  1988. begin
  1989. inherited buildderef;
  1990. elementtype.buildderef;
  1991. end;
  1992. procedure tsetdef.deref;
  1993. begin
  1994. inherited deref;
  1995. elementtype.resolve;
  1996. end;
  1997. procedure tsetdef.write_child_rtti_data(rt:trttitype);
  1998. begin
  1999. tstoreddef(elementtype.def).get_rtti_label(rt);
  2000. end;
  2001. procedure tsetdef.write_rtti_data(rt:trttitype);
  2002. begin
  2003. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_8bit(tkSet));
  2004. write_rtti_name;
  2005. {$ifdef cpurequiresproperalignment}
  2006. current_asmdata.asmlists[al_rtti].concat(Tai_align.Create(sizeof(TConstPtrUInt)));
  2007. {$endif cpurequiresproperalignment}
  2008. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_8bit(otULong));
  2009. {$ifdef cpurequiresproperalignment}
  2010. current_asmdata.asmlists[al_rtti].concat(Tai_align.Create(sizeof(TConstPtrUInt)));
  2011. {$endif cpurequiresproperalignment}
  2012. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_sym(tstoreddef(elementtype.def).get_rtti_label(rt)));
  2013. end;
  2014. function tsetdef.is_publishable : boolean;
  2015. begin
  2016. is_publishable:=(settype=smallset);
  2017. end;
  2018. function tsetdef.gettypename : string;
  2019. begin
  2020. if assigned(elementtype.def) then
  2021. gettypename:='Set Of '+elementtype.def.typename
  2022. else
  2023. gettypename:='Empty Set';
  2024. end;
  2025. {***************************************************************************
  2026. TFORMALDEF
  2027. ***************************************************************************}
  2028. constructor tformaldef.create;
  2029. begin
  2030. inherited create(formaldef);
  2031. savesize:=0;
  2032. end;
  2033. constructor tformaldef.ppuload(ppufile:tcompilerppufile);
  2034. begin
  2035. inherited ppuload(formaldef,ppufile);
  2036. savesize:=0;
  2037. end;
  2038. procedure tformaldef.ppuwrite(ppufile:tcompilerppufile);
  2039. begin
  2040. inherited ppuwrite(ppufile);
  2041. ppufile.writeentry(ibformaldef);
  2042. end;
  2043. function tformaldef.gettypename : string;
  2044. begin
  2045. gettypename:='<Formal type>';
  2046. end;
  2047. {***************************************************************************
  2048. TARRAYDEF
  2049. ***************************************************************************}
  2050. constructor tarraydef.create(l,h : aint;const t : ttype);
  2051. begin
  2052. inherited create(arraydef);
  2053. lowrange:=l;
  2054. highrange:=h;
  2055. rangetype:=t;
  2056. elementtype.reset;
  2057. arrayoptions:=[];
  2058. end;
  2059. constructor tarraydef.create_from_pointer(const elemt : ttype);
  2060. begin
  2061. self.create(0,$7fffffff,s32inttype);
  2062. arrayoptions:=[ado_IsConvertedPointer];
  2063. setelementtype(elemt);
  2064. end;
  2065. constructor tarraydef.ppuload(ppufile:tcompilerppufile);
  2066. begin
  2067. inherited ppuload(arraydef,ppufile);
  2068. { the addresses are calculated later }
  2069. ppufile.gettype(_elementtype);
  2070. ppufile.gettype(rangetype);
  2071. lowrange:=ppufile.getaint;
  2072. highrange:=ppufile.getaint;
  2073. ppufile.getsmallset(arrayoptions);
  2074. end;
  2075. function tarraydef.getcopy : tstoreddef;
  2076. begin
  2077. result:=tarraydef.create(lowrange,highrange,rangetype);
  2078. tarraydef(result).arrayoptions:=arrayoptions;
  2079. tarraydef(result)._elementtype:=_elementtype;
  2080. end;
  2081. procedure tarraydef.buildderef;
  2082. begin
  2083. inherited buildderef;
  2084. _elementtype.buildderef;
  2085. rangetype.buildderef;
  2086. end;
  2087. procedure tarraydef.deref;
  2088. begin
  2089. inherited deref;
  2090. _elementtype.resolve;
  2091. rangetype.resolve;
  2092. end;
  2093. procedure tarraydef.ppuwrite(ppufile:tcompilerppufile);
  2094. begin
  2095. inherited ppuwrite(ppufile);
  2096. ppufile.puttype(_elementtype);
  2097. ppufile.puttype(rangetype);
  2098. ppufile.putaint(lowrange);
  2099. ppufile.putaint(highrange);
  2100. ppufile.putsmallset(arrayoptions);
  2101. ppufile.writeentry(ibarraydef);
  2102. end;
  2103. function tarraydef.elesize : aint;
  2104. begin
  2105. elesize:=_elementtype.def.size;
  2106. end;
  2107. function tarraydef.elecount : aint;
  2108. var
  2109. qhigh,qlow : qword;
  2110. begin
  2111. if ado_IsDynamicArray in arrayoptions then
  2112. begin
  2113. result:=0;
  2114. exit;
  2115. end;
  2116. if (highrange>0) and (lowrange<0) then
  2117. begin
  2118. qhigh:=highrange;
  2119. qlow:=qword(-lowrange);
  2120. { prevent overflow, return -1 to indicate overflow }
  2121. if qhigh+qlow>qword(high(aint)-1) then
  2122. result:=-1
  2123. else
  2124. result:=qhigh+qlow+1;
  2125. end
  2126. else
  2127. result:=int64(highrange)-lowrange+1;
  2128. end;
  2129. function tarraydef.size : aint;
  2130. var
  2131. cachedelecount,
  2132. cachedelesize : aint;
  2133. begin
  2134. if ado_IsDynamicArray in arrayoptions then
  2135. begin
  2136. size:=sizeof(aint);
  2137. exit;
  2138. end;
  2139. { Tarraydef.size may never be called for an open array! }
  2140. if highrange<lowrange then
  2141. internalerror(99080501);
  2142. cachedelesize:=elesize;
  2143. cachedelecount:=elecount;
  2144. { prevent overflow, return -1 to indicate overflow }
  2145. if (cachedelesize <> 0) and
  2146. (
  2147. (cachedelecount < 0) or
  2148. ((high(aint) div cachedelesize) < cachedelecount) or
  2149. { also lowrange*elesize must be < high(aint) to prevent overflow when
  2150. accessing the array, see ncgmem (PFV) }
  2151. ((high(aint) div cachedelesize) < abs(lowrange))
  2152. ) then
  2153. result:=-1
  2154. else
  2155. result:=cachedelesize*cachedelecount;
  2156. end;
  2157. procedure tarraydef.setelementtype(t: ttype);
  2158. begin
  2159. _elementtype:=t;
  2160. if not((ado_IsDynamicArray in arrayoptions) or
  2161. (ado_IsConvertedPointer in arrayoptions) or
  2162. (highrange<lowrange)) then
  2163. begin
  2164. if (size=-1) then
  2165. Message(sym_e_segment_too_large);
  2166. end;
  2167. end;
  2168. function tarraydef.alignment : shortint;
  2169. begin
  2170. { alignment is the size of the elements }
  2171. if (elementtype.def.deftype in [arraydef,recorddef]) or
  2172. ((elementtype.def.deftype=objectdef) and
  2173. is_object(elementtype.def)) then
  2174. alignment:=elementtype.def.alignment
  2175. else
  2176. alignment:=size_2_align(elesize);
  2177. end;
  2178. function tarraydef.needs_inittable : boolean;
  2179. begin
  2180. needs_inittable:=(ado_IsDynamicArray in arrayoptions) or elementtype.def.needs_inittable;
  2181. end;
  2182. procedure tarraydef.write_child_rtti_data(rt:trttitype);
  2183. begin
  2184. tstoreddef(elementtype.def).get_rtti_label(rt);
  2185. end;
  2186. procedure tarraydef.write_rtti_data(rt:trttitype);
  2187. begin
  2188. if ado_IsDynamicArray in arrayoptions then
  2189. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_8bit(tkdynarray))
  2190. else
  2191. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_8bit(tkarray));
  2192. write_rtti_name;
  2193. {$ifdef cpurequiresproperalignment}
  2194. current_asmdata.asmlists[al_rtti].concat(Tai_align.Create(sizeof(TConstPtrUInt)));
  2195. {$endif cpurequiresproperalignment}
  2196. { size of elements }
  2197. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_aint(elesize));
  2198. if not(ado_IsDynamicArray in arrayoptions) then
  2199. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_aint(elecount));
  2200. { element type }
  2201. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_sym(tstoreddef(elementtype.def).get_rtti_label(rt)));
  2202. { variant type }
  2203. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_32bit(tstoreddef(elementtype.def).getvartype));
  2204. end;
  2205. function tarraydef.gettypename : string;
  2206. begin
  2207. if (ado_IsConstString in arrayoptions) then
  2208. result:='Constant String'
  2209. else if (ado_isarrayofconst in arrayoptions) or
  2210. (ado_isConstructor in arrayoptions) then
  2211. begin
  2212. if (ado_isvariant in arrayoptions) or ((highrange=-1) and (lowrange=0)) then
  2213. gettypename:='Array Of Const'
  2214. else
  2215. gettypename:='Array Of '+elementtype.def.typename;
  2216. end
  2217. else if ((highrange=-1) and (lowrange=0)) or (ado_IsDynamicArray in arrayoptions) then
  2218. gettypename:='Array Of '+elementtype.def.typename
  2219. else
  2220. begin
  2221. if rangetype.def.deftype=enumdef then
  2222. gettypename:='Array['+rangetype.def.typename+'] Of '+elementtype.def.typename
  2223. else
  2224. gettypename:='Array['+tostr(lowrange)+'..'+
  2225. tostr(highrange)+'] Of '+elementtype.def.typename
  2226. end;
  2227. end;
  2228. function tarraydef.getmangledparaname : string;
  2229. begin
  2230. if ado_isarrayofconst in arrayoptions then
  2231. getmangledparaname:='array_of_const'
  2232. else
  2233. if ((highrange=-1) and (lowrange=0)) then
  2234. getmangledparaname:='array_of_'+elementtype.def.mangledparaname
  2235. else
  2236. internalerror(200204176);
  2237. end;
  2238. {***************************************************************************
  2239. tabstractrecorddef
  2240. ***************************************************************************}
  2241. function tabstractrecorddef.getsymtable(t:tgetsymtable):tsymtable;
  2242. begin
  2243. if t=gs_record then
  2244. getsymtable:=symtable
  2245. else
  2246. getsymtable:=nil;
  2247. end;
  2248. procedure tabstractrecorddef.reset;
  2249. begin
  2250. inherited reset;
  2251. tstoredsymtable(symtable).reset_all_defs;
  2252. end;
  2253. procedure tabstractrecorddef.count_field_rtti(sym : tnamedindexitem;arg:pointer);
  2254. begin
  2255. if (FRTTIType=fullrtti) or
  2256. ((tsym(sym).typ=fieldvarsym) and
  2257. tfieldvarsym(sym).vartype.def.needs_inittable) then
  2258. inc(Count);
  2259. end;
  2260. procedure tabstractrecorddef.generate_field_rtti(sym:tnamedindexitem;arg:pointer);
  2261. begin
  2262. if (FRTTIType=fullrtti) or
  2263. ((tsym(sym).typ=fieldvarsym) and
  2264. tfieldvarsym(sym).vartype.def.needs_inittable) then
  2265. tstoreddef(tfieldvarsym(sym).vartype.def).get_rtti_label(FRTTIType);
  2266. end;
  2267. procedure tabstractrecorddef.write_field_rtti(sym : tnamedindexitem;arg:pointer);
  2268. begin
  2269. if (FRTTIType=fullrtti) or
  2270. ((tsym(sym).typ=fieldvarsym) and
  2271. tfieldvarsym(sym).vartype.def.needs_inittable) then
  2272. begin
  2273. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_sym(tstoreddef(tfieldvarsym(sym).vartype.def).get_rtti_label(FRTTIType)));
  2274. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_32bit(tfieldvarsym(sym).fieldoffset));
  2275. end;
  2276. end;
  2277. procedure tabstractrecorddef.buildderefimpl;
  2278. begin
  2279. inherited buildderefimpl;
  2280. tstoredsymtable(symtable).buildderefimpl;
  2281. end;
  2282. procedure tabstractrecorddef.derefimpl;
  2283. var
  2284. storesymtable : tsymtable;
  2285. begin
  2286. inherited derefimpl;
  2287. tstoredsymtable(symtable).derefimpl;
  2288. end;
  2289. {***************************************************************************
  2290. trecorddef
  2291. ***************************************************************************}
  2292. constructor trecorddef.create(p : tsymtable);
  2293. begin
  2294. inherited create(recorddef);
  2295. symtable:=p;
  2296. symtable.defowner:=self;
  2297. isunion:=false;
  2298. end;
  2299. constructor trecorddef.ppuload(ppufile:tcompilerppufile);
  2300. begin
  2301. inherited ppuload(recorddef,ppufile);
  2302. symtable:=trecordsymtable.create(0);
  2303. trecordsymtable(symtable).datasize:=ppufile.getaint;
  2304. trecordsymtable(symtable).fieldalignment:=shortint(ppufile.getbyte);
  2305. trecordsymtable(symtable).recordalignment:=shortint(ppufile.getbyte);
  2306. trecordsymtable(symtable).padalignment:=shortint(ppufile.getbyte);
  2307. trecordsymtable(symtable).ppuload(ppufile);
  2308. symtable.defowner:=self;
  2309. isunion:=false;
  2310. end;
  2311. destructor trecorddef.destroy;
  2312. begin
  2313. if assigned(symtable) then
  2314. symtable.free;
  2315. inherited destroy;
  2316. end;
  2317. function trecorddef.getcopy : tstoreddef;
  2318. begin
  2319. result:=trecorddef.create(symtable.getcopy);
  2320. trecorddef(result).isunion:=isunion;
  2321. end;
  2322. function trecorddef.needs_inittable : boolean;
  2323. begin
  2324. needs_inittable:=trecordsymtable(symtable).needs_init_final
  2325. end;
  2326. procedure trecorddef.buildderef;
  2327. var
  2328. oldrecsyms : tsymtable;
  2329. begin
  2330. inherited buildderef;
  2331. oldrecsyms:=aktrecordsymtable;
  2332. aktrecordsymtable:=symtable;
  2333. { now build the definitions }
  2334. tstoredsymtable(symtable).buildderef;
  2335. aktrecordsymtable:=oldrecsyms;
  2336. end;
  2337. procedure trecorddef.deref;
  2338. var
  2339. oldrecsyms : tsymtable;
  2340. begin
  2341. inherited deref;
  2342. oldrecsyms:=aktrecordsymtable;
  2343. aktrecordsymtable:=symtable;
  2344. { now dereference the definitions }
  2345. tstoredsymtable(symtable).deref;
  2346. aktrecordsymtable:=oldrecsyms;
  2347. { assign TGUID? load only from system unit }
  2348. if not(assigned(rec_tguid)) and
  2349. (upper(typename)='TGUID') and
  2350. assigned(owner) and
  2351. assigned(owner.name) and
  2352. (owner.name^='SYSTEM') then
  2353. rec_tguid:=self;
  2354. end;
  2355. procedure trecorddef.ppuwrite(ppufile:tcompilerppufile);
  2356. begin
  2357. inherited ppuwrite(ppufile);
  2358. ppufile.putaint(trecordsymtable(symtable).datasize);
  2359. ppufile.putbyte(byte(trecordsymtable(symtable).fieldalignment));
  2360. ppufile.putbyte(byte(trecordsymtable(symtable).recordalignment));
  2361. ppufile.putbyte(byte(trecordsymtable(symtable).padalignment));
  2362. ppufile.writeentry(ibrecorddef);
  2363. trecordsymtable(symtable).ppuwrite(ppufile);
  2364. end;
  2365. function trecorddef.size:aint;
  2366. begin
  2367. result:=trecordsymtable(symtable).datasize;
  2368. end;
  2369. function trecorddef.alignment:shortint;
  2370. begin
  2371. alignment:=trecordsymtable(symtable).recordalignment;
  2372. end;
  2373. function trecorddef.padalignment:shortint;
  2374. begin
  2375. padalignment := trecordsymtable(symtable).padalignment;
  2376. end;
  2377. procedure trecorddef.write_child_rtti_data(rt:trttitype);
  2378. begin
  2379. FRTTIType:=rt;
  2380. symtable.foreach(@generate_field_rtti,nil);
  2381. end;
  2382. procedure trecorddef.write_rtti_data(rt:trttitype);
  2383. begin
  2384. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_8bit(tkrecord));
  2385. write_rtti_name;
  2386. {$ifdef cpurequiresproperalignment}
  2387. current_asmdata.asmlists[al_rtti].concat(Tai_align.Create(sizeof(TConstPtrUInt)));
  2388. {$endif cpurequiresproperalignment}
  2389. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_32bit(size));
  2390. Count:=0;
  2391. FRTTIType:=rt;
  2392. symtable.foreach(@count_field_rtti,nil);
  2393. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_32bit(Count));
  2394. symtable.foreach(@write_field_rtti,nil);
  2395. end;
  2396. function trecorddef.gettypename : string;
  2397. begin
  2398. gettypename:='<record type>'
  2399. end;
  2400. {***************************************************************************
  2401. TABSTRACTPROCDEF
  2402. ***************************************************************************}
  2403. constructor tabstractprocdef.create(dt:tdeftype;level:byte);
  2404. begin
  2405. inherited create(dt);
  2406. parast:=tparasymtable.create(level);
  2407. parast.defowner:=self;
  2408. paras:=nil;
  2409. minparacount:=0;
  2410. maxparacount:=0;
  2411. proctypeoption:=potype_none;
  2412. proccalloption:=pocall_none;
  2413. procoptions:=[];
  2414. rettype:=voidtype;
  2415. {$ifdef i386}
  2416. fpu_used:=0;
  2417. {$endif i386}
  2418. savesize:=sizeof(aint);
  2419. requiredargarea:=0;
  2420. has_paraloc_info:=false;
  2421. location_reset(funcretloc[callerside],LOC_INVALID,OS_NO);
  2422. location_reset(funcretloc[calleeside],LOC_INVALID,OS_NO);
  2423. end;
  2424. destructor tabstractprocdef.destroy;
  2425. begin
  2426. if assigned(paras) then
  2427. begin
  2428. {$ifdef MEMDEBUG}
  2429. memprocpara.start;
  2430. {$endif MEMDEBUG}
  2431. paras.free;
  2432. {$ifdef MEMDEBUG}
  2433. memprocpara.stop;
  2434. {$endif MEMDEBUG}
  2435. end;
  2436. if assigned(parast) then
  2437. begin
  2438. {$ifdef MEMDEBUG}
  2439. memprocparast.start;
  2440. {$endif MEMDEBUG}
  2441. parast.free;
  2442. {$ifdef MEMDEBUG}
  2443. memprocparast.stop;
  2444. {$endif MEMDEBUG}
  2445. end;
  2446. inherited destroy;
  2447. end;
  2448. procedure tabstractprocdef.releasemem;
  2449. begin
  2450. if assigned(paras) then
  2451. begin
  2452. paras.free;
  2453. paras:=nil;
  2454. end;
  2455. parast.free;
  2456. parast:=nil;
  2457. end;
  2458. procedure tabstractprocdef.count_para(p:tnamedindexitem;arg:pointer);
  2459. begin
  2460. if (tsym(p).typ<>paravarsym) then
  2461. exit;
  2462. inc(plongint(arg)^);
  2463. if not(vo_is_hidden_para in tparavarsym(p).varoptions) then
  2464. begin
  2465. if not assigned(tparavarsym(p).defaultconstsym) then
  2466. inc(minparacount);
  2467. inc(maxparacount);
  2468. end;
  2469. end;
  2470. procedure tabstractprocdef.insert_para(p:tnamedindexitem;arg:pointer);
  2471. begin
  2472. if (tsym(p).typ<>paravarsym) then
  2473. exit;
  2474. paras.add(p);
  2475. end;
  2476. procedure tabstractprocdef.calcparas;
  2477. var
  2478. paracount : longint;
  2479. begin
  2480. { This can already be assigned when
  2481. we need to reresolve this unit (PFV) }
  2482. if assigned(paras) then
  2483. paras.free;
  2484. paras:=tparalist.create(false);
  2485. paracount:=0;
  2486. minparacount:=0;
  2487. maxparacount:=0;
  2488. parast.foreach(@count_para,@paracount);
  2489. paras.capacity:=paracount;
  2490. { Insert parameters in table }
  2491. parast.foreach(@insert_para,nil);
  2492. { Order parameters }
  2493. paras.sortparas;
  2494. end;
  2495. { all functions returning in FPU are
  2496. assume to use 2 FPU registers
  2497. until the function implementation
  2498. is processed PM }
  2499. procedure tabstractprocdef.test_if_fpu_result;
  2500. begin
  2501. {$ifdef i386}
  2502. if assigned(rettype.def) and
  2503. (rettype.def.deftype=floatdef) then
  2504. fpu_used:=maxfpuregs;
  2505. {$endif i386}
  2506. end;
  2507. procedure tabstractprocdef.buildderef;
  2508. begin
  2509. { released procdef? }
  2510. if not assigned(parast) then
  2511. exit;
  2512. inherited buildderef;
  2513. rettype.buildderef;
  2514. { parast }
  2515. tparasymtable(parast).buildderef;
  2516. end;
  2517. procedure tabstractprocdef.deref;
  2518. begin
  2519. inherited deref;
  2520. rettype.resolve;
  2521. { parast }
  2522. tparasymtable(parast).deref;
  2523. { recalculated parameters }
  2524. calcparas;
  2525. end;
  2526. constructor tabstractprocdef.ppuload(dt:tdeftype;ppufile:tcompilerppufile);
  2527. var
  2528. b : byte;
  2529. begin
  2530. inherited ppuload(dt,ppufile);
  2531. parast:=nil;
  2532. Paras:=nil;
  2533. minparacount:=0;
  2534. maxparacount:=0;
  2535. ppufile.gettype(rettype);
  2536. {$ifdef i386}
  2537. fpu_used:=ppufile.getbyte;
  2538. {$else}
  2539. ppufile.getbyte;
  2540. {$endif i386}
  2541. proctypeoption:=tproctypeoption(ppufile.getbyte);
  2542. proccalloption:=tproccalloption(ppufile.getbyte);
  2543. ppufile.getnormalset(procoptions);
  2544. location_reset(funcretloc[callerside],LOC_INVALID,OS_NO);
  2545. location_reset(funcretloc[calleeside],LOC_INVALID,OS_NO);
  2546. if po_explicitparaloc in procoptions then
  2547. begin
  2548. b:=ppufile.getbyte;
  2549. if b<>sizeof(funcretloc[callerside]) then
  2550. internalerror(200411154);
  2551. ppufile.getdata(funcretloc[callerside],sizeof(funcretloc[callerside]));
  2552. end;
  2553. savesize:=sizeof(aint);
  2554. has_paraloc_info:=(po_explicitparaloc in procoptions);
  2555. end;
  2556. procedure tabstractprocdef.ppuwrite(ppufile:tcompilerppufile);
  2557. var
  2558. oldintfcrc : boolean;
  2559. begin
  2560. { released procdef? }
  2561. if not assigned(parast) then
  2562. exit;
  2563. inherited ppuwrite(ppufile);
  2564. ppufile.puttype(rettype);
  2565. oldintfcrc:=ppufile.do_interface_crc;
  2566. ppufile.do_interface_crc:=false;
  2567. {$ifdef i386}
  2568. if simplify_ppu then
  2569. fpu_used:=0;
  2570. ppufile.putbyte(fpu_used);
  2571. {$else}
  2572. ppufile.putbyte(0);
  2573. {$endif}
  2574. ppufile.putbyte(ord(proctypeoption));
  2575. ppufile.putbyte(ord(proccalloption));
  2576. ppufile.putnormalset(procoptions);
  2577. ppufile.do_interface_crc:=oldintfcrc;
  2578. if (po_explicitparaloc in procoptions) then
  2579. begin
  2580. { Make a 'valid' funcretloc for procedures }
  2581. ppufile.putbyte(sizeof(funcretloc[callerside]));
  2582. ppufile.putdata(funcretloc[callerside],sizeof(funcretloc[callerside]));
  2583. end;
  2584. end;
  2585. function tabstractprocdef.typename_paras(showhidden:boolean) : string;
  2586. var
  2587. hs,s : string;
  2588. hp : TParavarsym;
  2589. hpc : tconstsym;
  2590. first : boolean;
  2591. i : integer;
  2592. begin
  2593. s:='';
  2594. first:=true;
  2595. for i:=0 to paras.count-1 do
  2596. begin
  2597. hp:=tparavarsym(paras[i]);
  2598. if not(vo_is_hidden_para in hp.varoptions) or
  2599. (showhidden) then
  2600. begin
  2601. if first then
  2602. begin
  2603. s:=s+'(';
  2604. first:=false;
  2605. end
  2606. else
  2607. s:=s+',';
  2608. case hp.varspez of
  2609. vs_var :
  2610. s:=s+'var';
  2611. vs_const :
  2612. s:=s+'const';
  2613. vs_out :
  2614. s:=s+'out';
  2615. end;
  2616. if assigned(hp.vartype.def.typesym) then
  2617. begin
  2618. if s<>'(' then
  2619. s:=s+' ';
  2620. hs:=hp.vartype.def.typesym.realname;
  2621. if hs[1]<>'$' then
  2622. s:=s+hp.vartype.def.typesym.realname
  2623. else
  2624. s:=s+hp.vartype.def.gettypename;
  2625. end
  2626. else
  2627. s:=s+hp.vartype.def.gettypename;
  2628. { default value }
  2629. if assigned(hp.defaultconstsym) then
  2630. begin
  2631. hpc:=tconstsym(hp.defaultconstsym);
  2632. hs:='';
  2633. case hpc.consttyp of
  2634. conststring,
  2635. constresourcestring :
  2636. hs:=strpas(pchar(hpc.value.valueptr));
  2637. constreal :
  2638. str(pbestreal(hpc.value.valueptr)^,hs);
  2639. constpointer :
  2640. hs:=tostr(hpc.value.valueordptr);
  2641. constord :
  2642. begin
  2643. if is_boolean(hpc.consttype.def) then
  2644. begin
  2645. if hpc.value.valueord<>0 then
  2646. hs:='TRUE'
  2647. else
  2648. hs:='FALSE';
  2649. end
  2650. else
  2651. hs:=tostr(hpc.value.valueord);
  2652. end;
  2653. constnil :
  2654. hs:='nil';
  2655. constset :
  2656. hs:='<set>';
  2657. end;
  2658. if hs<>'' then
  2659. s:=s+'="'+hs+'"';
  2660. end;
  2661. end;
  2662. end;
  2663. if not first then
  2664. s:=s+')';
  2665. if (po_varargs in procoptions) then
  2666. s:=s+';VarArgs';
  2667. typename_paras:=s;
  2668. end;
  2669. function tabstractprocdef.is_methodpointer:boolean;
  2670. begin
  2671. result:=false;
  2672. end;
  2673. function tabstractprocdef.is_addressonly:boolean;
  2674. begin
  2675. result:=true;
  2676. end;
  2677. {***************************************************************************
  2678. TPROCDEF
  2679. ***************************************************************************}
  2680. constructor tprocdef.create(level:byte);
  2681. begin
  2682. inherited create(procdef,level);
  2683. _mangledname:=nil;
  2684. fileinfo:=aktfilepos;
  2685. extnumber:=$ffff;
  2686. aliasnames:=tstringlist.create;
  2687. funcretsym:=nil;
  2688. localst := nil;
  2689. defref:=nil;
  2690. lastwritten:=nil;
  2691. refcount:=0;
  2692. if (cs_browser in aktmoduleswitches) and make_ref then
  2693. begin
  2694. defref:=tref.create(defref,@akttokenpos);
  2695. inc(refcount);
  2696. end;
  2697. lastref:=defref;
  2698. forwarddef:=true;
  2699. interfacedef:=false;
  2700. hasforward:=false;
  2701. _class := nil;
  2702. import_dll:=nil;
  2703. import_name:=nil;
  2704. import_nr:=0;
  2705. inlininginfo:=nil;
  2706. end;
  2707. constructor tprocdef.ppuload(ppufile:tcompilerppufile);
  2708. var
  2709. level : byte;
  2710. begin
  2711. inherited ppuload(procdef,ppufile);
  2712. if po_has_mangledname in procoptions then
  2713. _mangledname:=stringdup(ppufile.getstring)
  2714. else
  2715. _mangledname:=nil;
  2716. extnumber:=ppufile.getword;
  2717. level:=ppufile.getbyte;
  2718. ppufile.getderef(_classderef);
  2719. ppufile.getderef(procsymderef);
  2720. ppufile.getposinfo(fileinfo);
  2721. ppufile.getsmallset(symoptions);
  2722. {$ifdef powerpc}
  2723. { library symbol for AmigaOS/MorphOS }
  2724. ppufile.getderef(libsymderef);
  2725. {$endif powerpc}
  2726. { import stuff }
  2727. if po_has_importdll in procoptions then
  2728. import_dll:=stringdup(ppufile.getstring)
  2729. else
  2730. import_dll:=nil;
  2731. if po_has_importname in procoptions then
  2732. import_name:=stringdup(ppufile.getstring)
  2733. else
  2734. import_name:=nil;
  2735. import_nr:=ppufile.getword;
  2736. { inline stuff }
  2737. if (po_has_inlininginfo in procoptions) then
  2738. begin
  2739. ppufile.getderef(funcretsymderef);
  2740. new(inlininginfo);
  2741. ppufile.getsmallset(inlininginfo^.flags);
  2742. end
  2743. else
  2744. begin
  2745. inlininginfo:=nil;
  2746. funcretsym:=nil;
  2747. end;
  2748. { load para symtable }
  2749. parast:=tparasymtable.create(level);
  2750. tparasymtable(parast).ppuload(ppufile);
  2751. parast.defowner:=self;
  2752. { load local symtable }
  2753. if (po_has_inlininginfo in procoptions) or
  2754. ((current_module.flags and uf_local_browser)<>0) then
  2755. begin
  2756. localst:=tlocalsymtable.create(level);
  2757. tlocalsymtable(localst).ppuload(ppufile);
  2758. localst.defowner:=self;
  2759. end
  2760. else
  2761. localst:=nil;
  2762. { inline stuff }
  2763. if (po_has_inlininginfo in procoptions) then
  2764. inlininginfo^.code:=ppuloadnodetree(ppufile);
  2765. { default values for no persistent data }
  2766. if (cs_link_deffile in aktglobalswitches) and
  2767. (tf_need_export in target_info.flags) and
  2768. (po_exports in procoptions) then
  2769. deffile.AddExport(mangledname);
  2770. aliasnames:=tstringlist.create;
  2771. forwarddef:=false;
  2772. interfacedef:=false;
  2773. hasforward:=false;
  2774. lastref:=nil;
  2775. lastwritten:=nil;
  2776. defref:=nil;
  2777. refcount:=0;
  2778. { Disable po_has_inlining until the derefimpl is done }
  2779. exclude(procoptions,po_has_inlininginfo);
  2780. end;
  2781. destructor tprocdef.destroy;
  2782. begin
  2783. if assigned(defref) then
  2784. begin
  2785. defref.freechain;
  2786. defref.free;
  2787. end;
  2788. aliasnames.free;
  2789. if assigned(localst) and (localst.symtabletype<>staticsymtable) then
  2790. begin
  2791. {$ifdef MEMDEBUG}
  2792. memproclocalst.start;
  2793. {$endif MEMDEBUG}
  2794. localst.free;
  2795. {$ifdef MEMDEBUG}
  2796. memproclocalst.start;
  2797. {$endif MEMDEBUG}
  2798. end;
  2799. if assigned(inlininginfo) then
  2800. begin
  2801. {$ifdef MEMDEBUG}
  2802. memprocnodetree.start;
  2803. {$endif MEMDEBUG}
  2804. tnode(inlininginfo^.code).free;
  2805. {$ifdef MEMDEBUG}
  2806. memprocnodetree.start;
  2807. {$endif MEMDEBUG}
  2808. dispose(inlininginfo);
  2809. end;
  2810. stringdispose(import_dll);
  2811. stringdispose(import_name);
  2812. if (po_msgstr in procoptions) then
  2813. strdispose(messageinf.str);
  2814. if assigned(_mangledname) then
  2815. begin
  2816. {$ifdef MEMDEBUG}
  2817. memmanglednames.start;
  2818. {$endif MEMDEBUG}
  2819. stringdispose(_mangledname);
  2820. {$ifdef MEMDEBUG}
  2821. memmanglednames.stop;
  2822. {$endif MEMDEBUG}
  2823. end;
  2824. inherited destroy;
  2825. end;
  2826. procedure tprocdef.ppuwrite(ppufile:tcompilerppufile);
  2827. var
  2828. oldintfcrc : boolean;
  2829. oldparasymtable,
  2830. oldlocalsymtable : tsymtable;
  2831. begin
  2832. { released procdef? }
  2833. if not assigned(parast) then
  2834. exit;
  2835. oldparasymtable:=aktparasymtable;
  2836. oldlocalsymtable:=aktlocalsymtable;
  2837. aktparasymtable:=parast;
  2838. aktlocalsymtable:=localst;
  2839. inherited ppuwrite(ppufile);
  2840. oldintfcrc:=ppufile.do_interface_crc;
  2841. ppufile.do_interface_crc:=false;
  2842. ppufile.do_interface_crc:=oldintfcrc;
  2843. if po_has_mangledname in procoptions then
  2844. ppufile.putstring(_mangledname^);
  2845. ppufile.putword(extnumber);
  2846. ppufile.putbyte(parast.symtablelevel);
  2847. ppufile.putderef(_classderef);
  2848. ppufile.putderef(procsymderef);
  2849. ppufile.putposinfo(fileinfo);
  2850. ppufile.putsmallset(symoptions);
  2851. {$ifdef powerpc}
  2852. { library symbol for AmigaOS/MorphOS }
  2853. ppufile.putderef(libsymderef);
  2854. {$endif powerpc}
  2855. { import }
  2856. if po_has_importdll in procoptions then
  2857. ppufile.putstring(import_dll^);
  2858. if po_has_importname in procoptions then
  2859. ppufile.putstring(import_name^);
  2860. ppufile.putword(import_nr);
  2861. { inline stuff }
  2862. oldintfcrc:=ppufile.do_crc;
  2863. ppufile.do_crc:=false;
  2864. if (po_has_inlininginfo in procoptions) then
  2865. begin
  2866. ppufile.putderef(funcretsymderef);
  2867. ppufile.putsmallset(inlininginfo^.flags);
  2868. end;
  2869. ppufile.do_crc:=oldintfcrc;
  2870. { write this entry }
  2871. ppufile.writeentry(ibprocdef);
  2872. { Save the para symtable, this is taken from the interface }
  2873. tparasymtable(parast).ppuwrite(ppufile);
  2874. { save localsymtable for inline procedures or when local
  2875. browser info is requested, this has no influence on the crc }
  2876. if (po_has_inlininginfo in procoptions) or
  2877. ((current_module.flags and uf_local_browser)<>0) then
  2878. begin
  2879. { we must write a localsymtable }
  2880. if not assigned(localst) then
  2881. insert_localst;
  2882. oldintfcrc:=ppufile.do_crc;
  2883. ppufile.do_crc:=false;
  2884. tlocalsymtable(localst).ppuwrite(ppufile);
  2885. ppufile.do_crc:=oldintfcrc;
  2886. end;
  2887. { node tree for inlining }
  2888. oldintfcrc:=ppufile.do_crc;
  2889. ppufile.do_crc:=false;
  2890. if (po_has_inlininginfo in procoptions) then
  2891. ppuwritenodetree(ppufile,inlininginfo^.code);
  2892. ppufile.do_crc:=oldintfcrc;
  2893. aktparasymtable:=oldparasymtable;
  2894. aktlocalsymtable:=oldlocalsymtable;
  2895. end;
  2896. procedure tprocdef.reset;
  2897. begin
  2898. inherited reset;
  2899. procstarttai:=nil;
  2900. procendtai:=nil;
  2901. end;
  2902. procedure tprocdef.insert_localst;
  2903. begin
  2904. localst:=tlocalsymtable.create(parast.symtablelevel);
  2905. localst.defowner:=self;
  2906. end;
  2907. function tprocdef.fullprocname(showhidden:boolean):string;
  2908. var
  2909. s : string;
  2910. t : ttoken;
  2911. begin
  2912. {$ifdef EXTDEBUG}
  2913. showhidden:=true;
  2914. {$endif EXTDEBUG}
  2915. s:='';
  2916. if owner.symtabletype=localsymtable then
  2917. s:=s+'local ';
  2918. if assigned(_class) then
  2919. begin
  2920. if po_classmethod in procoptions then
  2921. s:=s+'class ';
  2922. s:=s+_class.objrealname^+'.';
  2923. end;
  2924. if proctypeoption=potype_operator then
  2925. begin
  2926. for t:=NOTOKEN to last_overloaded do
  2927. if procsym.realname='$'+overloaded_names[t] then
  2928. begin
  2929. s:='operator '+arraytokeninfo[t].str+typename_paras(showhidden);
  2930. break;
  2931. end;
  2932. end
  2933. else
  2934. s:=s+procsym.realname+typename_paras(showhidden);
  2935. case proctypeoption of
  2936. potype_constructor:
  2937. s:='constructor '+s;
  2938. potype_destructor:
  2939. s:='destructor '+s;
  2940. else
  2941. if assigned(rettype.def) and
  2942. not(is_void(rettype.def)) then
  2943. s:=s+':'+rettype.def.gettypename;
  2944. end;
  2945. { forced calling convention? }
  2946. if (po_hascallingconvention in procoptions) then
  2947. s:=s+';'+ProcCallOptionStr[proccalloption];
  2948. fullprocname:=s;
  2949. end;
  2950. function tprocdef.is_methodpointer:boolean;
  2951. begin
  2952. result:=assigned(_class);
  2953. end;
  2954. function tprocdef.is_addressonly:boolean;
  2955. begin
  2956. result:=assigned(owner) and
  2957. (owner.symtabletype<>objectsymtable);
  2958. end;
  2959. function tprocdef.is_visible_for_object(currobjdef:tobjectdef):boolean;
  2960. begin
  2961. is_visible_for_object:=false;
  2962. { private symbols are allowed when we are in the same
  2963. module as they are defined }
  2964. if (sp_private in symoptions) and
  2965. (owner.defowner.owner.symtabletype in [globalsymtable,staticsymtable]) and
  2966. not(owner.defowner.owner.iscurrentunit) then
  2967. exit;
  2968. if (sp_strictprivate in symoptions) then
  2969. begin
  2970. result:=currobjdef=tobjectdef(owner.defowner);
  2971. exit;
  2972. end;
  2973. if (sp_strictprotected in symoptions) then
  2974. begin
  2975. result:=assigned(currobjdef) and
  2976. currobjdef.is_related(tobjectdef(owner.defowner));
  2977. exit;
  2978. end;
  2979. { protected symbols are visible in the module that defines them and
  2980. also visible to related objects. The related object must be defined
  2981. in the current module }
  2982. if (sp_protected in symoptions) and
  2983. (
  2984. (
  2985. (owner.defowner.owner.symtabletype in [globalsymtable,staticsymtable]) and
  2986. not(owner.defowner.owner.iscurrentunit)
  2987. ) and
  2988. not(
  2989. assigned(currobjdef) and
  2990. (currobjdef.owner.symtabletype in [globalsymtable,staticsymtable]) and
  2991. (currobjdef.owner.iscurrentunit) and
  2992. currobjdef.is_related(tobjectdef(owner.defowner))
  2993. )
  2994. ) then
  2995. exit;
  2996. is_visible_for_object:=true;
  2997. end;
  2998. function tprocdef.getsymtable(t:tgetsymtable):tsymtable;
  2999. begin
  3000. case t of
  3001. gs_local :
  3002. getsymtable:=localst;
  3003. gs_para :
  3004. getsymtable:=parast;
  3005. else
  3006. getsymtable:=nil;
  3007. end;
  3008. end;
  3009. procedure tprocdef.load_references(ppufile:tcompilerppufile;locals:boolean);
  3010. var
  3011. pos : tfileposinfo;
  3012. move_last : boolean;
  3013. oldparasymtable,
  3014. oldlocalsymtable : tsymtable;
  3015. begin
  3016. oldparasymtable:=aktparasymtable;
  3017. oldlocalsymtable:=aktlocalsymtable;
  3018. aktparasymtable:=parast;
  3019. aktlocalsymtable:=localst;
  3020. move_last:=lastwritten=lastref;
  3021. while (not ppufile.endofentry) do
  3022. begin
  3023. ppufile.getposinfo(pos);
  3024. inc(refcount);
  3025. lastref:=tref.create(lastref,@pos);
  3026. lastref.is_written:=true;
  3027. if refcount=1 then
  3028. defref:=lastref;
  3029. end;
  3030. if move_last then
  3031. lastwritten:=lastref;
  3032. if ((current_module.flags and uf_local_browser)<>0) and
  3033. assigned(localst) and
  3034. locals then
  3035. begin
  3036. tparasymtable(parast).load_references(ppufile,locals);
  3037. tlocalsymtable(localst).load_references(ppufile,locals);
  3038. end;
  3039. aktparasymtable:=oldparasymtable;
  3040. aktlocalsymtable:=oldlocalsymtable;
  3041. end;
  3042. Const
  3043. local_symtable_index : word = $8001;
  3044. function tprocdef.write_references(ppufile:tcompilerppufile;locals:boolean):boolean;
  3045. var
  3046. ref : tref;
  3047. {$ifdef supportbrowser}
  3048. pdo : tobjectdef;
  3049. {$endif supportbrowser}
  3050. move_last : boolean;
  3051. d : tderef;
  3052. oldparasymtable,
  3053. oldlocalsymtable : tsymtable;
  3054. begin
  3055. d.reset;
  3056. move_last:=lastwritten=lastref;
  3057. if move_last and
  3058. (((current_module.flags and uf_local_browser)=0) or
  3059. not locals) then
  3060. exit;
  3061. oldparasymtable:=aktparasymtable;
  3062. oldlocalsymtable:=aktlocalsymtable;
  3063. aktparasymtable:=parast;
  3064. aktlocalsymtable:=localst;
  3065. { write address of this symbol }
  3066. d.build(self);
  3067. ppufile.putderef(d);
  3068. { write refs }
  3069. if assigned(lastwritten) then
  3070. ref:=lastwritten
  3071. else
  3072. ref:=defref;
  3073. while assigned(ref) do
  3074. begin
  3075. if ref.moduleindex=current_module.unit_index then
  3076. begin
  3077. ppufile.putposinfo(ref.posinfo);
  3078. ref.is_written:=true;
  3079. if move_last then
  3080. lastwritten:=ref;
  3081. end
  3082. else if not ref.is_written then
  3083. move_last:=false
  3084. else if move_last then
  3085. lastwritten:=ref;
  3086. ref:=ref.nextref;
  3087. end;
  3088. ppufile.writeentry(ibdefref);
  3089. write_references:=true;
  3090. {$ifdef supportbrowser}
  3091. if ((current_module.flags and uf_local_browser)<>0) and
  3092. assigned(localst) and
  3093. locals then
  3094. begin
  3095. pdo:=_class;
  3096. if (owner.symtabletype<>localsymtable) then
  3097. while assigned(pdo) do
  3098. begin
  3099. if pdo.symtable<>aktrecordsymtable then
  3100. begin
  3101. pdo.symtable.moduleid:=local_symtable_index;
  3102. inc(local_symtable_index);
  3103. end;
  3104. pdo:=pdo.childof;
  3105. end;
  3106. parast.moduleid:=local_symtable_index;
  3107. inc(local_symtable_index);
  3108. localst.moduleid:=local_symtable_index;
  3109. inc(local_symtable_index);
  3110. tstoredsymtable(parast).write_references(ppufile,locals);
  3111. tstoredsymtable(localst).write_references(ppufile,locals);
  3112. { decrement for }
  3113. local_symtable_index:=local_symtable_index-2;
  3114. pdo:=_class;
  3115. if (owner.symtabletype<>localsymtable) then
  3116. while assigned(pdo) do
  3117. begin
  3118. if pdo.symtable<>aktrecordsymtable then
  3119. dec(local_symtable_index);
  3120. pdo:=pdo.childof;
  3121. end;
  3122. end;
  3123. {$endif supportbrowser}
  3124. aktparasymtable:=oldparasymtable;
  3125. aktlocalsymtable:=oldlocalsymtable;
  3126. end;
  3127. procedure tprocdef.buildderef;
  3128. var
  3129. oldparasymtable,
  3130. oldlocalsymtable : tsymtable;
  3131. begin
  3132. oldparasymtable:=aktparasymtable;
  3133. oldlocalsymtable:=aktlocalsymtable;
  3134. aktparasymtable:=parast;
  3135. aktlocalsymtable:=localst;
  3136. inherited buildderef;
  3137. _classderef.build(_class);
  3138. { procsym that originaly defined this definition, should be in the
  3139. same symtable }
  3140. procsymderef.build(procsym);
  3141. {$ifdef powerpc}
  3142. { library symbol for AmigaOS/MorphOS }
  3143. libsymderef.build(libsym);
  3144. {$endif powerpc}
  3145. aktparasymtable:=oldparasymtable;
  3146. aktlocalsymtable:=oldlocalsymtable;
  3147. end;
  3148. procedure tprocdef.buildderefimpl;
  3149. var
  3150. oldparasymtable,
  3151. oldlocalsymtable : tsymtable;
  3152. begin
  3153. { released procdef? }
  3154. if not assigned(parast) then
  3155. exit;
  3156. oldparasymtable:=aktparasymtable;
  3157. oldlocalsymtable:=aktlocalsymtable;
  3158. aktparasymtable:=parast;
  3159. aktlocalsymtable:=localst;
  3160. inherited buildderefimpl;
  3161. { Locals }
  3162. if assigned(localst) and
  3163. ((po_has_inlininginfo in procoptions) or
  3164. ((current_module.flags and uf_local_browser)<>0)) then
  3165. begin
  3166. tlocalsymtable(localst).buildderef;
  3167. tlocalsymtable(localst).buildderefimpl;
  3168. end;
  3169. { inline tree }
  3170. if (po_has_inlininginfo in procoptions) then
  3171. begin
  3172. funcretsymderef.build(funcretsym);
  3173. inlininginfo^.code.buildderefimpl;
  3174. end;
  3175. aktparasymtable:=oldparasymtable;
  3176. aktlocalsymtable:=oldlocalsymtable;
  3177. end;
  3178. procedure tprocdef.deref;
  3179. var
  3180. oldparasymtable,
  3181. oldlocalsymtable : tsymtable;
  3182. begin
  3183. { released procdef? }
  3184. if not assigned(parast) then
  3185. exit;
  3186. oldparasymtable:=aktparasymtable;
  3187. oldlocalsymtable:=aktlocalsymtable;
  3188. aktparasymtable:=parast;
  3189. aktlocalsymtable:=localst;
  3190. inherited deref;
  3191. _class:=tobjectdef(_classderef.resolve);
  3192. { procsym that originaly defined this definition, should be in the
  3193. same symtable }
  3194. procsym:=tprocsym(procsymderef.resolve);
  3195. {$ifdef powerpc}
  3196. { library symbol for AmigaOS/MorphOS }
  3197. libsym:=tsym(libsymderef.resolve);
  3198. {$endif powerpc}
  3199. aktparasymtable:=oldparasymtable;
  3200. aktlocalsymtable:=oldlocalsymtable;
  3201. end;
  3202. procedure tprocdef.derefimpl;
  3203. var
  3204. oldparasymtable,
  3205. oldlocalsymtable : tsymtable;
  3206. begin
  3207. oldparasymtable:=aktparasymtable;
  3208. oldlocalsymtable:=aktlocalsymtable;
  3209. aktparasymtable:=parast;
  3210. aktlocalsymtable:=localst;
  3211. { Enable has_inlininginfo when the inlininginfo
  3212. structure is available. The has_inlininginfo was disabled
  3213. after the load, since the data was invalid }
  3214. if assigned(inlininginfo) then
  3215. include(procoptions,po_has_inlininginfo);
  3216. { Locals }
  3217. if assigned(localst) then
  3218. begin
  3219. tlocalsymtable(localst).deref;
  3220. tlocalsymtable(localst).derefimpl;
  3221. end;
  3222. { Inline }
  3223. if (po_has_inlininginfo in procoptions) then
  3224. begin
  3225. inlininginfo^.code.derefimpl;
  3226. { funcretsym, this is always located in the localst }
  3227. funcretsym:=tsym(funcretsymderef.resolve);
  3228. end
  3229. else
  3230. begin
  3231. { safety }
  3232. funcretsym:=nil;
  3233. end;
  3234. aktparasymtable:=oldparasymtable;
  3235. aktlocalsymtable:=oldlocalsymtable;
  3236. end;
  3237. function tprocdef.gettypename : string;
  3238. begin
  3239. gettypename := FullProcName(false);
  3240. end;
  3241. function tprocdef.mangledname : string;
  3242. var
  3243. hp : TParavarsym;
  3244. hs : string;
  3245. crc : dword;
  3246. newlen,
  3247. oldlen,
  3248. i : integer;
  3249. begin
  3250. if assigned(_mangledname) then
  3251. begin
  3252. {$ifdef compress}
  3253. mangledname:=minilzw_decode(_mangledname^);
  3254. {$else}
  3255. mangledname:=_mangledname^;
  3256. {$endif}
  3257. exit;
  3258. end;
  3259. { we need to use the symtable where the procsym is inserted,
  3260. because that is visible to the world }
  3261. mangledname:=make_mangledname('',procsym.owner,procsym.name);
  3262. oldlen:=length(mangledname);
  3263. { add parameter types }
  3264. for i:=0 to paras.count-1 do
  3265. begin
  3266. hp:=tparavarsym(paras[i]);
  3267. if not(vo_is_hidden_para in hp.varoptions) then
  3268. mangledname:=mangledname+'$'+hp.vartype.def.mangledparaname;
  3269. end;
  3270. { add resulttype, add $$ as separator to make it unique from a
  3271. parameter separator }
  3272. if not is_void(rettype.def) then
  3273. mangledname:=mangledname+'$$'+rettype.def.mangledparaname;
  3274. newlen:=length(mangledname);
  3275. { Replace with CRC if the parameter line is very long }
  3276. if (newlen-oldlen>12) and
  3277. ((newlen>128) or (newlen-oldlen>64)) then
  3278. begin
  3279. crc:=$ffffffff;
  3280. for i:=0 to paras.count-1 do
  3281. begin
  3282. hp:=tparavarsym(paras[i]);
  3283. if not(vo_is_hidden_para in hp.varoptions) then
  3284. begin
  3285. hs:=hp.vartype.def.mangledparaname;
  3286. crc:=UpdateCrc32(crc,hs[1],length(hs));
  3287. end;
  3288. end;
  3289. hs:=hp.vartype.def.mangledparaname;
  3290. crc:=UpdateCrc32(crc,hs[1],length(hs));
  3291. mangledname:=Copy(mangledname,1,oldlen)+'$crc'+hexstr(crc,8);
  3292. end;
  3293. {$ifdef compress}
  3294. _mangledname:=stringdup(minilzw_encode(mangledname));
  3295. {$else}
  3296. _mangledname:=stringdup(mangledname);
  3297. {$endif}
  3298. end;
  3299. function tprocdef.cplusplusmangledname : string;
  3300. function getcppparaname(p : tdef) : string;
  3301. const
  3302. ordtype2str : array[tbasetype] of string[2] = (
  3303. '',
  3304. 'Uc','Us','Ui','Us',
  3305. 'Sc','s','i','x',
  3306. 'b','b','b',
  3307. 'c','w','x');
  3308. var
  3309. s : string;
  3310. begin
  3311. case p.deftype of
  3312. orddef:
  3313. s:=ordtype2str[torddef(p).typ];
  3314. pointerdef:
  3315. s:='P'+getcppparaname(tpointerdef(p).pointertype.def);
  3316. else
  3317. internalerror(2103001);
  3318. end;
  3319. getcppparaname:=s;
  3320. end;
  3321. var
  3322. s,s2 : string;
  3323. hp : TParavarsym;
  3324. i : integer;
  3325. begin
  3326. s := procsym.realname;
  3327. if procsym.owner.symtabletype=objectsymtable then
  3328. begin
  3329. s2:=upper(tobjectdef(procsym.owner.defowner).typesym.realname);
  3330. case proctypeoption of
  3331. potype_destructor:
  3332. s:='_$_'+tostr(length(s2))+s2;
  3333. potype_constructor:
  3334. s:='___'+tostr(length(s2))+s2;
  3335. else
  3336. s:='_'+s+'__'+tostr(length(s2))+s2;
  3337. end;
  3338. end
  3339. else s:=s+'__';
  3340. s:=s+'F';
  3341. { concat modifiers }
  3342. { !!!!! }
  3343. { now we handle the parameters }
  3344. if maxparacount>0 then
  3345. begin
  3346. for i:=0 to paras.count-1 do
  3347. begin
  3348. hp:=tparavarsym(paras[i]);
  3349. s2:=getcppparaname(hp.vartype.def);
  3350. if hp.varspez in [vs_var,vs_out] then
  3351. s2:='R'+s2;
  3352. s:=s+s2;
  3353. end;
  3354. end
  3355. else
  3356. s:=s+'v';
  3357. cplusplusmangledname:=s;
  3358. end;
  3359. procedure tprocdef.setmangledname(const s : string);
  3360. begin
  3361. { This is not allowed anymore, the forward declaration
  3362. already needs to create the correct mangledname, no changes
  3363. afterwards are allowed (PFV) }
  3364. { Exception: interface definitions in mode macpas, since in that }
  3365. { case no reference to the old name can exist yet (JM) }
  3366. if assigned(_mangledname) then
  3367. if ((m_mac in aktmodeswitches) and
  3368. (interfacedef)) then
  3369. stringdispose(_mangledname)
  3370. else
  3371. internalerror(200411171);
  3372. {$ifdef compress}
  3373. _mangledname:=stringdup(minilzw_encode(s));
  3374. {$else}
  3375. _mangledname:=stringdup(s);
  3376. {$endif}
  3377. include(procoptions,po_has_mangledname);
  3378. end;
  3379. {***************************************************************************
  3380. TPROCVARDEF
  3381. ***************************************************************************}
  3382. constructor tprocvardef.create(level:byte);
  3383. begin
  3384. inherited create(procvardef,level);
  3385. end;
  3386. constructor tprocvardef.ppuload(ppufile:tcompilerppufile);
  3387. begin
  3388. inherited ppuload(procvardef,ppufile);
  3389. { load para symtable }
  3390. parast:=tparasymtable.create(unknown_level);
  3391. tparasymtable(parast).ppuload(ppufile);
  3392. parast.defowner:=self;
  3393. end;
  3394. function tprocvardef.getcopy : tstoreddef;
  3395. begin
  3396. result:=self;
  3397. (*
  3398. { saves a definition to the return type }
  3399. rettype : ttype;
  3400. parast : tsymtable;
  3401. paras : tparalist;
  3402. proctypeoption : tproctypeoption;
  3403. proccalloption : tproccalloption;
  3404. procoptions : tprocoptions;
  3405. requiredargarea : aint;
  3406. { number of user visibile parameters }
  3407. maxparacount,
  3408. minparacount : byte;
  3409. {$ifdef i386}
  3410. fpu_used : longint; { how many stack fpu must be empty }
  3411. {$endif i386}
  3412. funcretloc : array[tcallercallee] of TLocation;
  3413. has_paraloc_info : boolean; { paraloc info is available }
  3414. tprocvardef = class(tabstractprocdef)
  3415. constructor create(level:byte);
  3416. constructor ppuload(ppufile:tcompilerppufile);
  3417. function getcopy : tstoreddef;override;
  3418. *)
  3419. end;
  3420. procedure tprocvardef.ppuwrite(ppufile:tcompilerppufile);
  3421. var
  3422. oldparasymtable,
  3423. oldlocalsymtable : tsymtable;
  3424. begin
  3425. oldparasymtable:=aktparasymtable;
  3426. oldlocalsymtable:=aktlocalsymtable;
  3427. aktparasymtable:=parast;
  3428. aktlocalsymtable:=nil;
  3429. { here we cannot get a real good value so just give something }
  3430. { plausible (PM) }
  3431. { a more secure way would be
  3432. to allways store in a temp }
  3433. {$ifdef i386}
  3434. if is_fpu(rettype.def) then
  3435. fpu_used:={2}maxfpuregs
  3436. else
  3437. fpu_used:=0;
  3438. {$endif i386}
  3439. inherited ppuwrite(ppufile);
  3440. { Write this entry }
  3441. ppufile.writeentry(ibprocvardef);
  3442. { Save the para symtable, this is taken from the interface }
  3443. tparasymtable(parast).ppuwrite(ppufile);
  3444. aktparasymtable:=oldparasymtable;
  3445. aktlocalsymtable:=oldlocalsymtable;
  3446. end;
  3447. procedure tprocvardef.buildderef;
  3448. var
  3449. oldparasymtable,
  3450. oldlocalsymtable : tsymtable;
  3451. begin
  3452. oldparasymtable:=aktparasymtable;
  3453. oldlocalsymtable:=aktlocalsymtable;
  3454. aktparasymtable:=parast;
  3455. aktlocalsymtable:=nil;
  3456. inherited buildderef;
  3457. aktparasymtable:=oldparasymtable;
  3458. aktlocalsymtable:=oldlocalsymtable;
  3459. end;
  3460. procedure tprocvardef.deref;
  3461. var
  3462. oldparasymtable,
  3463. oldlocalsymtable : tsymtable;
  3464. begin
  3465. oldparasymtable:=aktparasymtable;
  3466. oldlocalsymtable:=aktlocalsymtable;
  3467. aktparasymtable:=parast;
  3468. aktlocalsymtable:=nil;
  3469. inherited deref;
  3470. aktparasymtable:=oldparasymtable;
  3471. aktlocalsymtable:=oldlocalsymtable;
  3472. end;
  3473. function tprocvardef.getsymtable(t:tgetsymtable):tsymtable;
  3474. begin
  3475. case t of
  3476. gs_para :
  3477. getsymtable:=parast;
  3478. else
  3479. getsymtable:=nil;
  3480. end;
  3481. end;
  3482. function tprocvardef.size : aint;
  3483. begin
  3484. if (po_methodpointer in procoptions) and
  3485. not(po_addressonly in procoptions) then
  3486. size:=2*sizeof(aint)
  3487. else
  3488. size:=sizeof(aint);
  3489. end;
  3490. function tprocvardef.is_methodpointer:boolean;
  3491. begin
  3492. result:=(po_methodpointer in procoptions);
  3493. end;
  3494. function tprocvardef.is_addressonly:boolean;
  3495. begin
  3496. result:=not(po_methodpointer in procoptions) or
  3497. (po_addressonly in procoptions);
  3498. end;
  3499. function tprocvardef.getmangledparaname:string;
  3500. begin
  3501. result:='procvar';
  3502. end;
  3503. procedure tprocvardef.write_rtti_data(rt:trttitype);
  3504. procedure write_para(parasym:tparavarsym);
  3505. var
  3506. paraspec : byte;
  3507. begin
  3508. { only store user visible parameters }
  3509. if not(vo_is_hidden_para in parasym.varoptions) then
  3510. begin
  3511. case parasym.varspez of
  3512. vs_value: paraspec := 0;
  3513. vs_const: paraspec := pfConst;
  3514. vs_var : paraspec := pfVar;
  3515. vs_out : paraspec := pfOut;
  3516. end;
  3517. { write flags for current parameter }
  3518. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_8bit(paraspec));
  3519. { write name of current parameter }
  3520. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_8bit(length(parasym.realname)));
  3521. current_asmdata.asmlists[al_rtti].concat(Tai_string.Create(parasym.realname));
  3522. { write name of type of current parameter }
  3523. tstoreddef(parasym.vartype.def).write_rtti_name;
  3524. end;
  3525. end;
  3526. var
  3527. methodkind : byte;
  3528. i : integer;
  3529. begin
  3530. if po_methodpointer in procoptions then
  3531. begin
  3532. { write method id and name }
  3533. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_8bit(tkmethod));
  3534. write_rtti_name;
  3535. {$ifdef cpurequiresproperalignment}
  3536. current_asmdata.asmlists[al_rtti].concat(Tai_align.Create(sizeof(TConstPtrUInt)));
  3537. {$endif cpurequiresproperalignment}
  3538. { write kind of method (can only be function or procedure)}
  3539. if rettype.def = voidtype.def then
  3540. methodkind := mkProcedure
  3541. else
  3542. methodkind := mkFunction;
  3543. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_8bit(methodkind));
  3544. { get # of parameters }
  3545. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_8bit(maxparacount));
  3546. { write parameter info. The parameters must be written in reverse order
  3547. if this method uses right to left parameter pushing! }
  3548. if proccalloption in pushleftright_pocalls then
  3549. begin
  3550. for i:=0 to paras.count-1 do
  3551. write_para(tparavarsym(paras[i]));
  3552. end
  3553. else
  3554. begin
  3555. for i:=paras.count-1 downto 0 do
  3556. write_para(tparavarsym(paras[i]));
  3557. end;
  3558. { write name of result type }
  3559. tstoreddef(rettype.def).write_rtti_name;
  3560. end
  3561. else
  3562. begin
  3563. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_8bit(tkprocvar));
  3564. write_rtti_name;
  3565. end;
  3566. end;
  3567. function tprocvardef.is_publishable : boolean;
  3568. begin
  3569. is_publishable:=(po_methodpointer in procoptions);
  3570. end;
  3571. function tprocvardef.gettypename : string;
  3572. var
  3573. s: string;
  3574. showhidden : boolean;
  3575. begin
  3576. {$ifdef EXTDEBUG}
  3577. showhidden:=true;
  3578. {$else EXTDEBUG}
  3579. showhidden:=false;
  3580. {$endif EXTDEBUG}
  3581. s:='<';
  3582. if po_classmethod in procoptions then
  3583. s := s+'class method type of'
  3584. else
  3585. if po_addressonly in procoptions then
  3586. s := s+'address of'
  3587. else
  3588. s := s+'procedure variable type of';
  3589. if po_local in procoptions then
  3590. s := s+' local';
  3591. if assigned(rettype.def) and
  3592. (rettype.def<>voidtype.def) then
  3593. s:=s+' function'+typename_paras(showhidden)+':'+rettype.def.gettypename
  3594. else
  3595. s:=s+' procedure'+typename_paras(showhidden);
  3596. if po_methodpointer in procoptions then
  3597. s := s+' of object';
  3598. gettypename := s+';'+ProcCallOptionStr[proccalloption]+'>';
  3599. end;
  3600. {***************************************************************************
  3601. TOBJECTDEF
  3602. ***************************************************************************}
  3603. type
  3604. tproptablelistitem = class(TLinkedListItem)
  3605. index : longint;
  3606. def : tobjectdef;
  3607. end;
  3608. tpropnamelistitem = class(TLinkedListItem)
  3609. index : longint;
  3610. name : stringid;
  3611. owner : tsymtable;
  3612. end;
  3613. var
  3614. proptablelist : tlinkedlist;
  3615. propnamelist : tlinkedlist;
  3616. function searchproptablelist(p : tobjectdef) : tproptablelistitem;
  3617. var
  3618. hp : tproptablelistitem;
  3619. begin
  3620. hp:=tproptablelistitem(proptablelist.first);
  3621. while assigned(hp) do
  3622. if hp.def=p then
  3623. begin
  3624. result:=hp;
  3625. exit;
  3626. end
  3627. else
  3628. hp:=tproptablelistitem(hp.next);
  3629. result:=nil;
  3630. end;
  3631. function searchpropnamelist(const n:string) : tpropnamelistitem;
  3632. var
  3633. hp : tpropnamelistitem;
  3634. begin
  3635. hp:=tpropnamelistitem(propnamelist.first);
  3636. while assigned(hp) do
  3637. if hp.name=n then
  3638. begin
  3639. result:=hp;
  3640. exit;
  3641. end
  3642. else
  3643. hp:=tpropnamelistitem(hp.next);
  3644. result:=nil;
  3645. end;
  3646. constructor tobjectdef.create(ot : tobjectdeftype;const n : string;c : tobjectdef);
  3647. begin
  3648. inherited create(objectdef);
  3649. objecttype:=ot;
  3650. objectoptions:=[];
  3651. childof:=nil;
  3652. symtable:=tobjectsymtable.create(n,aktpackrecords);
  3653. { create space for vmt !! }
  3654. vmt_offset:=0;
  3655. symtable.defowner:=self;
  3656. lastvtableindex:=0;
  3657. set_parent(c);
  3658. objname:=stringdup(upper(n));
  3659. objrealname:=stringdup(n);
  3660. if objecttype in [odt_interfacecorba,odt_interfacecom,odt_dispinterface] then
  3661. prepareguid;
  3662. { setup implemented interfaces }
  3663. if objecttype in [odt_class,odt_interfacecorba] then
  3664. implementedinterfaces:=timplementedinterfaces.create
  3665. else
  3666. implementedinterfaces:=nil;
  3667. writing_class_record_dbginfo:=false;
  3668. end;
  3669. constructor tobjectdef.ppuload(ppufile:tcompilerppufile);
  3670. var
  3671. i,implintfcount: longint;
  3672. d : tderef;
  3673. begin
  3674. inherited ppuload(objectdef,ppufile);
  3675. objecttype:=tobjectdeftype(ppufile.getbyte);
  3676. objrealname:=stringdup(ppufile.getstring);
  3677. objname:=stringdup(upper(objrealname^));
  3678. symtable:=tobjectsymtable.create(objrealname^,0);
  3679. tobjectsymtable(symtable).datasize:=ppufile.getaint;
  3680. tobjectsymtable(symtable).fieldalignment:=ppufile.getbyte;
  3681. tobjectsymtable(symtable).recordalignment:=ppufile.getbyte;
  3682. vmt_offset:=ppufile.getlongint;
  3683. ppufile.getderef(childofderef);
  3684. ppufile.getsmallset(objectoptions);
  3685. { load guid }
  3686. iidstr:=nil;
  3687. if objecttype in [odt_interfacecom,odt_interfacecorba,odt_dispinterface] then
  3688. begin
  3689. new(iidguid);
  3690. ppufile.getguid(iidguid^);
  3691. iidstr:=stringdup(ppufile.getstring);
  3692. lastvtableindex:=ppufile.getlongint;
  3693. end;
  3694. { load implemented interfaces }
  3695. if objecttype in [odt_class,odt_interfacecorba] then
  3696. begin
  3697. implementedinterfaces:=timplementedinterfaces.create;
  3698. implintfcount:=ppufile.getlongint;
  3699. for i:=1 to implintfcount do
  3700. begin
  3701. ppufile.getderef(d);
  3702. implementedinterfaces.addintf_deref(d,ppufile.getlongint);
  3703. end;
  3704. end
  3705. else
  3706. implementedinterfaces:=nil;
  3707. tobjectsymtable(symtable).ppuload(ppufile);
  3708. symtable.defowner:=self;
  3709. { handles the predefined class tobject }
  3710. { the last TOBJECT which is loaded gets }
  3711. { it ! }
  3712. if (childof=nil) and
  3713. (objecttype=odt_class) and
  3714. (objname^='TOBJECT') then
  3715. class_tobject:=self;
  3716. if (childof=nil) and
  3717. (objecttype=odt_interfacecom) and
  3718. (objname^='IUNKNOWN') then
  3719. interface_iunknown:=self;
  3720. writing_class_record_dbginfo:=false;
  3721. end;
  3722. destructor tobjectdef.destroy;
  3723. begin
  3724. if assigned(symtable) then
  3725. symtable.free;
  3726. stringdispose(objname);
  3727. stringdispose(objrealname);
  3728. if assigned(iidstr) then
  3729. stringdispose(iidstr);
  3730. if assigned(implementedinterfaces) then
  3731. implementedinterfaces.free;
  3732. if assigned(iidguid) then
  3733. dispose(iidguid);
  3734. inherited destroy;
  3735. end;
  3736. function tobjectdef.getcopy : tstoreddef;
  3737. var
  3738. i,
  3739. implintfcount : longint;
  3740. begin
  3741. result:=tobjectdef.create(objecttype,objname^,childof);
  3742. tobjectdef(result).symtable:=symtable.getcopy;
  3743. if assigned(objname) then
  3744. tobjectdef(result).objname:=stringdup(objname^);
  3745. if assigned(objrealname) then
  3746. tobjectdef(result).objrealname:=stringdup(objrealname^);
  3747. tobjectdef(result).objectoptions:=objectoptions;
  3748. tobjectdef(result).vmt_offset:=vmt_offset;
  3749. if assigned(iidguid) then
  3750. begin
  3751. new(tobjectdef(result).iidguid);
  3752. move(iidguid^,tobjectdef(result).iidguid^,sizeof(iidguid^));
  3753. end;
  3754. if assigned(iidstr) then
  3755. tobjectdef(result).iidstr:=stringdup(iidstr^);
  3756. tobjectdef(result).lastvtableindex:=lastvtableindex;
  3757. if assigned(implementedinterfaces) then
  3758. begin
  3759. implintfcount:=implementedinterfaces.count;
  3760. for i:=1 to implintfcount do
  3761. begin
  3762. tobjectdef(result).implementedinterfaces.addintf_ioffset(implementedinterfaces.interfaces(i),
  3763. implementedinterfaces.ioffsets(i));
  3764. end;
  3765. end;
  3766. end;
  3767. procedure tobjectdef.ppuwrite(ppufile:tcompilerppufile);
  3768. var
  3769. implintfcount : longint;
  3770. i : longint;
  3771. begin
  3772. inherited ppuwrite(ppufile);
  3773. ppufile.putbyte(byte(objecttype));
  3774. ppufile.putstring(objrealname^);
  3775. ppufile.putaint(tobjectsymtable(symtable).datasize);
  3776. ppufile.putbyte(tobjectsymtable(symtable).fieldalignment);
  3777. ppufile.putbyte(tobjectsymtable(symtable).recordalignment);
  3778. ppufile.putlongint(vmt_offset);
  3779. ppufile.putderef(childofderef);
  3780. ppufile.putsmallset(objectoptions);
  3781. if objecttype in [odt_interfacecom,odt_interfacecorba,odt_dispinterface] then
  3782. begin
  3783. ppufile.putguid(iidguid^);
  3784. ppufile.putstring(iidstr^);
  3785. ppufile.putlongint(lastvtableindex);
  3786. end;
  3787. if objecttype in [odt_class,odt_interfacecorba] then
  3788. begin
  3789. implintfcount:=implementedinterfaces.count;
  3790. ppufile.putlongint(implintfcount);
  3791. for i:=1 to implintfcount do
  3792. begin
  3793. ppufile.putderef(implementedinterfaces.interfacesderef(i));
  3794. ppufile.putlongint(implementedinterfaces.ioffsets(i));
  3795. end;
  3796. end;
  3797. ppufile.writeentry(ibobjectdef);
  3798. tobjectsymtable(symtable).ppuwrite(ppufile);
  3799. end;
  3800. function tobjectdef.gettypename:string;
  3801. begin
  3802. if (self <> aktobjectdef) then
  3803. gettypename:=typename
  3804. else
  3805. { in this case we will go in endless recursion, because then }
  3806. { there is no tsym associated yet with the def. It can occur }
  3807. { (tests/webtbf/tw4757.pp), so for now give a generic name }
  3808. { instead of the actual type name }
  3809. gettypename:='<Currently Parsed Class>';
  3810. end;
  3811. procedure tobjectdef.buildderef;
  3812. var
  3813. oldrecsyms : tsymtable;
  3814. begin
  3815. inherited buildderef;
  3816. childofderef.build(childof);
  3817. oldrecsyms:=aktrecordsymtable;
  3818. aktrecordsymtable:=symtable;
  3819. tstoredsymtable(symtable).buildderef;
  3820. aktrecordsymtable:=oldrecsyms;
  3821. if objecttype in [odt_class,odt_interfacecorba] then
  3822. implementedinterfaces.buildderef;
  3823. end;
  3824. procedure tobjectdef.deref;
  3825. var
  3826. oldrecsyms : tsymtable;
  3827. begin
  3828. inherited deref;
  3829. childof:=tobjectdef(childofderef.resolve);
  3830. oldrecsyms:=aktrecordsymtable;
  3831. aktrecordsymtable:=symtable;
  3832. tstoredsymtable(symtable).deref;
  3833. aktrecordsymtable:=oldrecsyms;
  3834. if objecttype in [odt_class,odt_interfacecorba] then
  3835. implementedinterfaces.deref;
  3836. end;
  3837. function tobjectdef.getparentdef:tdef;
  3838. begin
  3839. {$warning TODO Remove getparentdef hack}
  3840. { With 2 forward declared classes with the child class before the
  3841. parent class the child class is written earlier to the ppu. Leaving it
  3842. possible to have a reference to the parent class for property overriding,
  3843. but the parent class still has the childof not resolved yet (PFV) }
  3844. if childof=nil then
  3845. childof:=tobjectdef(childofderef.resolve);
  3846. result:=childof;
  3847. end;
  3848. procedure tobjectdef.prepareguid;
  3849. begin
  3850. { set up guid }
  3851. if not assigned(iidguid) then
  3852. begin
  3853. new(iidguid);
  3854. fillchar(iidguid^,sizeof(iidguid^),0); { default null guid }
  3855. end;
  3856. { setup iidstring }
  3857. if not assigned(iidstr) then
  3858. iidstr:=stringdup(''); { default is empty string }
  3859. end;
  3860. procedure tobjectdef.set_parent( c : tobjectdef);
  3861. begin
  3862. { nothing to do if the parent was not forward !}
  3863. if assigned(childof) then
  3864. exit;
  3865. childof:=c;
  3866. { some options are inherited !! }
  3867. if assigned(c) then
  3868. begin
  3869. { only important for classes }
  3870. lastvtableindex:=c.lastvtableindex;
  3871. objectoptions:=objectoptions+(c.objectoptions*
  3872. inherited_objectoptions);
  3873. if not (objecttype in [odt_interfacecom,odt_interfacecorba,odt_dispinterface]) then
  3874. begin
  3875. { add the data of the anchestor class }
  3876. inc(tobjectsymtable(symtable).datasize,tobjectsymtable(c.symtable).datasize);
  3877. if (oo_has_vmt in objectoptions) and
  3878. (oo_has_vmt in c.objectoptions) then
  3879. dec(tobjectsymtable(symtable).datasize,sizeof(aint));
  3880. { if parent has a vmt field then
  3881. the offset is the same for the child PM }
  3882. if (oo_has_vmt in c.objectoptions) or is_class(self) then
  3883. begin
  3884. vmt_offset:=c.vmt_offset;
  3885. include(objectoptions,oo_has_vmt);
  3886. end;
  3887. end;
  3888. end;
  3889. end;
  3890. procedure tobjectdef.insertvmt;
  3891. begin
  3892. if objecttype in [odt_interfacecom,odt_interfacecorba,odt_dispinterface] then
  3893. exit;
  3894. if (oo_has_vmt in objectoptions) then
  3895. internalerror(12345)
  3896. else
  3897. begin
  3898. tobjectsymtable(symtable).datasize:=align(tobjectsymtable(symtable).datasize,
  3899. tobjectsymtable(symtable).fieldalignment);
  3900. {$ifdef cpurequiresproperalignment}
  3901. tobjectsymtable(symtable).datasize:=align(tobjectsymtable(symtable).datasize,sizeof(aint));
  3902. {$endif cpurequiresproperalignment}
  3903. vmt_offset:=tobjectsymtable(symtable).datasize;
  3904. inc(tobjectsymtable(symtable).datasize,sizeof(aint));
  3905. include(objectoptions,oo_has_vmt);
  3906. end;
  3907. end;
  3908. procedure tobjectdef.check_forwards;
  3909. begin
  3910. if not(objecttype in [odt_interfacecom,odt_interfacecorba,odt_dispinterface]) then
  3911. tstoredsymtable(symtable).check_forwards;
  3912. if (oo_is_forward in objectoptions) then
  3913. begin
  3914. { ok, in future, the forward can be resolved }
  3915. Message1(sym_e_class_forward_not_resolved,objrealname^);
  3916. exclude(objectoptions,oo_is_forward);
  3917. end;
  3918. end;
  3919. { true, if self inherits from d (or if they are equal) }
  3920. function tobjectdef.is_related(d : tdef) : boolean;
  3921. var
  3922. hp : tobjectdef;
  3923. begin
  3924. hp:=self;
  3925. while assigned(hp) do
  3926. begin
  3927. if hp=d then
  3928. begin
  3929. is_related:=true;
  3930. exit;
  3931. end;
  3932. hp:=hp.childof;
  3933. end;
  3934. is_related:=false;
  3935. end;
  3936. procedure _searchdestructor(sym:Tnamedindexitem;sd:pointer);
  3937. begin
  3938. { if we found already a destructor, then we exit }
  3939. if (ppointer(sd)^=nil) and
  3940. (Tsym(sym).typ=procsym) then
  3941. ppointer(sd)^:=Tprocsym(sym).search_procdef_bytype(potype_destructor);
  3942. end;
  3943. function tobjectdef.searchdestructor : tprocdef;
  3944. var
  3945. o : tobjectdef;
  3946. sd : tprocdef;
  3947. begin
  3948. searchdestructor:=nil;
  3949. o:=self;
  3950. sd:=nil;
  3951. while assigned(o) do
  3952. begin
  3953. o.symtable.foreach_static(@_searchdestructor,@sd);
  3954. if assigned(sd) then
  3955. begin
  3956. searchdestructor:=sd;
  3957. exit;
  3958. end;
  3959. o:=o.childof;
  3960. end;
  3961. end;
  3962. function tobjectdef.size : aint;
  3963. begin
  3964. if objecttype in [odt_class,odt_interfacecom,odt_interfacecorba,odt_dispinterface] then
  3965. result:=sizeof(aint)
  3966. else
  3967. result:=tobjectsymtable(symtable).datasize;
  3968. end;
  3969. function tobjectdef.alignment:shortint;
  3970. begin
  3971. if objecttype in [odt_class,odt_interfacecom,odt_interfacecorba,odt_dispinterface] then
  3972. alignment:=sizeof(aint)
  3973. else
  3974. alignment:=tobjectsymtable(symtable).recordalignment;
  3975. end;
  3976. function tobjectdef.vmtmethodoffset(index:longint):longint;
  3977. begin
  3978. { for offset of methods for classes, see rtl/inc/objpash.inc }
  3979. case objecttype of
  3980. odt_class:
  3981. { the +2*sizeof(Aint) is size and -size }
  3982. vmtmethodoffset:=(index+10)*sizeof(aint)+2*sizeof(AInt);
  3983. odt_interfacecom,odt_interfacecorba:
  3984. vmtmethodoffset:=index*sizeof(aint);
  3985. else
  3986. {$ifdef WITHDMT}
  3987. vmtmethodoffset:=(index+4)*sizeof(aint);
  3988. {$else WITHDMT}
  3989. vmtmethodoffset:=(index+3)*sizeof(aint);
  3990. {$endif WITHDMT}
  3991. end;
  3992. end;
  3993. function tobjectdef.vmt_mangledname : string;
  3994. begin
  3995. if not(oo_has_vmt in objectoptions) then
  3996. Message1(parser_n_object_has_no_vmt,objrealname^);
  3997. vmt_mangledname:=make_mangledname('VMT',owner,objname^);
  3998. end;
  3999. function tobjectdef.rtti_name : string;
  4000. begin
  4001. rtti_name:=make_mangledname('RTTI',owner,objname^);
  4002. end;
  4003. function tobjectdef.needs_inittable : boolean;
  4004. begin
  4005. case objecttype of
  4006. odt_dispinterface,
  4007. odt_class :
  4008. needs_inittable:=false;
  4009. odt_interfacecom:
  4010. needs_inittable:=true;
  4011. odt_interfacecorba:
  4012. needs_inittable:=is_related(interface_iunknown);
  4013. odt_object:
  4014. needs_inittable:=tobjectsymtable(symtable).needs_init_final;
  4015. else
  4016. internalerror(200108267);
  4017. end;
  4018. end;
  4019. function tobjectdef.members_need_inittable : boolean;
  4020. begin
  4021. members_need_inittable:=tobjectsymtable(symtable).needs_init_final;
  4022. end;
  4023. procedure tobjectdef.collect_published_properties(sym:tnamedindexitem;arg:pointer);
  4024. var
  4025. hp : tpropnamelistitem;
  4026. begin
  4027. if (tsym(sym).typ=propertysym) and
  4028. (sp_published in tsym(sym).symoptions) then
  4029. begin
  4030. hp:=searchpropnamelist(tsym(sym).name);
  4031. if not(assigned(hp)) then
  4032. begin
  4033. hp:=tpropnamelistitem.create;
  4034. hp.name:=tsym(sym).name;
  4035. hp.index:=propnamelist.count;
  4036. hp.owner:=tsym(sym).owner;
  4037. propnamelist.concat(hp);
  4038. end;
  4039. end;
  4040. end;
  4041. procedure tobjectdef.count_published_properties(sym:tnamedindexitem;arg:pointer);
  4042. begin
  4043. if (tsym(sym).typ=propertysym) and
  4044. (sp_published in tsym(sym).symoptions) then
  4045. inc(plongint(arg)^);
  4046. end;
  4047. procedure tobjectdef.write_property_info(sym : tnamedindexitem;arg:pointer);
  4048. var
  4049. proctypesinfo : byte;
  4050. propnameitem : tpropnamelistitem;
  4051. procedure writeproc(proc : tsymlist; shiftvalue : byte);
  4052. var
  4053. typvalue : byte;
  4054. hp : psymlistitem;
  4055. address : longint;
  4056. def : tdef;
  4057. begin
  4058. if not(assigned(proc) and assigned(proc.firstsym)) then
  4059. begin
  4060. current_asmdata.asmlists[al_rtti].concat(Tai_const.create(aitconst_ptr,1));
  4061. typvalue:=3;
  4062. end
  4063. else if proc.firstsym^.sym.typ=fieldvarsym then
  4064. begin
  4065. address:=0;
  4066. hp:=proc.firstsym;
  4067. def:=nil;
  4068. while assigned(hp) do
  4069. begin
  4070. case hp^.sltype of
  4071. sl_load :
  4072. begin
  4073. def:=tfieldvarsym(hp^.sym).vartype.def;
  4074. inc(address,tfieldvarsym(hp^.sym).fieldoffset);
  4075. end;
  4076. sl_subscript :
  4077. begin
  4078. if not(assigned(def) and (def.deftype=recorddef)) then
  4079. internalerror(200402171);
  4080. inc(address,tfieldvarsym(hp^.sym).fieldoffset);
  4081. def:=tfieldvarsym(hp^.sym).vartype.def;
  4082. end;
  4083. sl_vec :
  4084. begin
  4085. if not(assigned(def) and (def.deftype=arraydef)) then
  4086. internalerror(200402172);
  4087. def:=tarraydef(def).elementtype.def;
  4088. inc(address,def.size*hp^.value);
  4089. end;
  4090. end;
  4091. hp:=hp^.next;
  4092. end;
  4093. current_asmdata.asmlists[al_rtti].concat(Tai_const.create(aitconst_ptr,address));
  4094. typvalue:=0;
  4095. end
  4096. else
  4097. begin
  4098. { When there was an error then procdef is not assigned }
  4099. if not assigned(proc.procdef) then
  4100. exit;
  4101. if not(po_virtualmethod in tprocdef(proc.procdef).procoptions) then
  4102. begin
  4103. current_asmdata.asmlists[al_rtti].concat(Tai_const.createname(tprocdef(proc.procdef).mangledname,0));
  4104. typvalue:=1;
  4105. end
  4106. else
  4107. begin
  4108. { virtual method, write vmt offset }
  4109. current_asmdata.asmlists[al_rtti].concat(Tai_const.create(aitconst_ptr,
  4110. tprocdef(proc.procdef)._class.vmtmethodoffset(tprocdef(proc.procdef).extnumber)));
  4111. typvalue:=2;
  4112. end;
  4113. end;
  4114. proctypesinfo:=proctypesinfo or (typvalue shl shiftvalue);
  4115. end;
  4116. begin
  4117. if (tsym(sym).typ=propertysym) and
  4118. (sp_published in tsym(sym).symoptions) then
  4119. begin
  4120. if ppo_indexed in tpropertysym(sym).propoptions then
  4121. proctypesinfo:=$40
  4122. else
  4123. proctypesinfo:=0;
  4124. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_sym(tstoreddef(tpropertysym(sym).proptype.def).get_rtti_label(fullrtti)));
  4125. writeproc(tpropertysym(sym).readaccess,0);
  4126. writeproc(tpropertysym(sym).writeaccess,2);
  4127. { isn't it stored ? }
  4128. if not(ppo_stored in tpropertysym(sym).propoptions) then
  4129. begin
  4130. current_asmdata.asmlists[al_rtti].concat(Tai_const.create_sym(nil));
  4131. proctypesinfo:=proctypesinfo or (3 shl 4);
  4132. end
  4133. else
  4134. writeproc(tpropertysym(sym).storedaccess,4);
  4135. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_32bit(tpropertysym(sym).index));
  4136. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_32bit(tpropertysym(sym).default));
  4137. propnameitem:=searchpropnamelist(tpropertysym(sym).name);
  4138. if not assigned(propnameitem) then
  4139. internalerror(200512201);
  4140. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_16bit(propnameitem.index));
  4141. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_8bit(proctypesinfo));
  4142. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_8bit(length(tpropertysym(sym).realname)));
  4143. current_asmdata.asmlists[al_rtti].concat(Tai_string.Create(tpropertysym(sym).realname));
  4144. {$ifdef cpurequiresproperalignment}
  4145. current_asmdata.asmlists[al_rtti].concat(Tai_align.Create(sizeof(TConstPtrUInt)));
  4146. {$endif cpurequiresproperalignment}
  4147. end;
  4148. end;
  4149. procedure tobjectdef.generate_published_child_rtti(sym : tnamedindexitem;arg:pointer);
  4150. begin
  4151. if needs_prop_entry(tsym(sym)) then
  4152. begin
  4153. case tsym(sym).typ of
  4154. propertysym:
  4155. tstoreddef(tpropertysym(sym).proptype.def).get_rtti_label(fullrtti);
  4156. fieldvarsym:
  4157. tstoreddef(tfieldvarsym(sym).vartype.def).get_rtti_label(fullrtti);
  4158. else
  4159. internalerror(1509991);
  4160. end;
  4161. end;
  4162. end;
  4163. procedure tobjectdef.write_child_rtti_data(rt:trttitype);
  4164. begin
  4165. FRTTIType:=rt;
  4166. case rt of
  4167. initrtti :
  4168. symtable.foreach(@generate_field_rtti,nil);
  4169. fullrtti :
  4170. symtable.foreach(@generate_published_child_rtti,nil);
  4171. else
  4172. internalerror(200108301);
  4173. end;
  4174. end;
  4175. procedure tobjectdef.count_published_fields(sym:tnamedindexitem;arg:pointer);
  4176. var
  4177. hp : tproptablelistitem;
  4178. begin
  4179. if (tsym(sym).typ=fieldvarsym) and
  4180. (sp_published in tsym(sym).symoptions) then
  4181. begin
  4182. if tfieldvarsym(sym).vartype.def.deftype<>objectdef then
  4183. internalerror(0206001);
  4184. hp:=searchproptablelist(tobjectdef(tfieldvarsym(sym).vartype.def));
  4185. if not(assigned(hp)) then
  4186. begin
  4187. hp:=tproptablelistitem.create;
  4188. hp.def:=tobjectdef(tfieldvarsym(sym).vartype.def);
  4189. hp.index:=proptablelist.count+1;
  4190. proptablelist.concat(hp);
  4191. end;
  4192. inc(plongint(arg)^);
  4193. end;
  4194. end;
  4195. procedure tobjectdef.writefields(sym:tnamedindexitem;arg:pointer);
  4196. var
  4197. hp : tproptablelistitem;
  4198. begin
  4199. if needs_prop_entry(tsym(sym)) and
  4200. (tsym(sym).typ=fieldvarsym) then
  4201. begin
  4202. {$ifdef cpurequiresproperalignment}
  4203. current_asmdata.asmlists[al_rtti].concat(Tai_align.Create(sizeof(AInt)));
  4204. {$endif cpurequiresproperalignment}
  4205. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_aint(tfieldvarsym(sym).fieldoffset));
  4206. hp:=searchproptablelist(tobjectdef(tfieldvarsym(sym).vartype.def));
  4207. if not(assigned(hp)) then
  4208. internalerror(0206002);
  4209. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_16bit(hp.index));
  4210. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_8bit(length(tfieldvarsym(sym).realname)));
  4211. current_asmdata.asmlists[al_rtti].concat(Tai_string.Create(tfieldvarsym(sym).realname));
  4212. end;
  4213. end;
  4214. function tobjectdef.generate_field_table : tasmlabel;
  4215. var
  4216. fieldtable,
  4217. classtable : tasmlabel;
  4218. hp : tproptablelistitem;
  4219. fieldcount : longint;
  4220. begin
  4221. proptablelist:=TLinkedList.Create;
  4222. current_asmdata.getdatalabel(fieldtable);
  4223. current_asmdata.getdatalabel(classtable);
  4224. maybe_new_object_file(current_asmdata.asmlists[al_rtti]);
  4225. new_section(current_asmdata.asmlists[al_rtti],sec_rodata,classtable.name,const_align(sizeof(aint)));
  4226. { fields }
  4227. fieldcount:=0;
  4228. symtable.foreach(@count_published_fields,@fieldcount);
  4229. current_asmdata.asmlists[al_rtti].concat(Tai_label.Create(fieldtable));
  4230. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_16bit(fieldcount));
  4231. {$ifdef cpurequiresproperalignment}
  4232. current_asmdata.asmlists[al_rtti].concat(Tai_align.Create(sizeof(TConstPtrUInt)));
  4233. {$endif cpurequiresproperalignment}
  4234. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_sym(classtable));
  4235. symtable.foreach(@writefields,nil);
  4236. { generate the class table }
  4237. current_asmdata.asmlists[al_rtti].concat(tai_align.create(const_align(sizeof(aint))));
  4238. current_asmdata.asmlists[al_rtti].concat(Tai_label.Create(classtable));
  4239. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_16bit(proptablelist.count));
  4240. {$ifdef cpurequiresproperalignment}
  4241. current_asmdata.asmlists[al_rtti].concat(Tai_align.Create(sizeof(TConstPtrUInt)));
  4242. {$endif cpurequiresproperalignment}
  4243. hp:=tproptablelistitem(proptablelist.first);
  4244. while assigned(hp) do
  4245. begin
  4246. current_asmdata.asmlists[al_rtti].concat(Tai_const.Createname(tobjectdef(hp.def).vmt_mangledname,0));
  4247. hp:=tproptablelistitem(hp.next);
  4248. end;
  4249. generate_field_table:=fieldtable;
  4250. proptablelist.free;
  4251. proptablelist:=nil;
  4252. end;
  4253. procedure tobjectdef.write_rtti_data(rt:trttitype);
  4254. procedure collect_unique_published_props(pd:tobjectdef);
  4255. begin
  4256. if assigned(pd.childof) then
  4257. collect_unique_published_props(pd.childof);
  4258. pd.symtable.foreach(@collect_published_properties,nil);
  4259. end;
  4260. var
  4261. i : longint;
  4262. propcount : longint;
  4263. begin
  4264. case objecttype of
  4265. odt_class:
  4266. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_8bit(tkclass));
  4267. odt_object:
  4268. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_8bit(tkobject));
  4269. odt_interfacecom:
  4270. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_8bit(tkinterface));
  4271. odt_interfacecorba:
  4272. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_8bit(tkinterfaceCorba));
  4273. else
  4274. exit;
  4275. end;
  4276. { generate the name }
  4277. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_8bit(length(objrealname^)));
  4278. current_asmdata.asmlists[al_rtti].concat(Tai_string.Create(objrealname^));
  4279. {$ifdef cpurequiresproperalignment}
  4280. current_asmdata.asmlists[al_rtti].concat(Tai_align.Create(sizeof(TConstPtrUInt)));
  4281. {$endif cpurequiresproperalignment}
  4282. case rt of
  4283. initrtti :
  4284. begin
  4285. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_32bit(size));
  4286. if objecttype in [odt_class,odt_object] then
  4287. begin
  4288. count:=0;
  4289. FRTTIType:=rt;
  4290. symtable.foreach(@count_field_rtti,nil);
  4291. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_32bit(count));
  4292. symtable.foreach(@write_field_rtti,nil);
  4293. end;
  4294. end;
  4295. fullrtti :
  4296. begin
  4297. { Collect unique property names with nameindex }
  4298. propnamelist:=TLinkedList.Create;
  4299. collect_unique_published_props(self);
  4300. if not(objecttype in [odt_interfacecom,odt_interfacecorba]) then
  4301. begin
  4302. if (oo_has_vmt in objectoptions) then
  4303. current_asmdata.asmlists[al_rtti].concat(Tai_const.Createname(vmt_mangledname,0))
  4304. else
  4305. current_asmdata.asmlists[al_rtti].concat(Tai_const.create_sym(nil));
  4306. end;
  4307. { write parent typeinfo }
  4308. if assigned(childof) and ((oo_can_have_published in childof.objectoptions) or
  4309. (objecttype in [odt_interfacecom,odt_interfacecorba])) then
  4310. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_sym(childof.get_rtti_label(fullrtti)))
  4311. else
  4312. current_asmdata.asmlists[al_rtti].concat(Tai_const.create_sym(nil));
  4313. if objecttype in [odt_object,odt_class] then
  4314. begin
  4315. { total number of unique properties }
  4316. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_16bit(propnamelist.count));
  4317. end
  4318. else
  4319. { interface: write flags, iid and iidstr }
  4320. begin
  4321. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_32bit(
  4322. { ugly, but working }
  4323. longint([
  4324. TCompilerIntfFlag(ord(ifHasGuid)*ord(assigned(iidguid))),
  4325. TCompilerIntfFlag(ord(ifHasStrGUID)*ord(assigned(iidstr)))
  4326. ])
  4327. {
  4328. ifDispInterface,
  4329. ifDispatch, }
  4330. ));
  4331. {$ifdef cpurequiresproperalignment}
  4332. current_asmdata.asmlists[al_rtti].concat(Tai_align.Create(sizeof(TConstPtrUInt)));
  4333. {$endif cpurequiresproperalignment}
  4334. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_32bit(longint(iidguid^.D1)));
  4335. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_16bit(iidguid^.D2));
  4336. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_16bit(iidguid^.D3));
  4337. for i:=Low(iidguid^.D4) to High(iidguid^.D4) do
  4338. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_8bit(iidguid^.D4[i]));
  4339. end;
  4340. { write unit name }
  4341. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_8bit(length(current_module.realmodulename^)));
  4342. current_asmdata.asmlists[al_rtti].concat(Tai_string.Create(current_module.realmodulename^));
  4343. {$ifdef cpurequiresproperalignment}
  4344. current_asmdata.asmlists[al_rtti].concat(Tai_align.Create(sizeof(TConstPtrUInt)));
  4345. {$endif cpurequiresproperalignment}
  4346. { write iidstr }
  4347. if objecttype in [odt_interfacecom,odt_interfacecorba] then
  4348. begin
  4349. if assigned(iidstr) then
  4350. begin
  4351. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_8bit(length(iidstr^)));
  4352. current_asmdata.asmlists[al_rtti].concat(Tai_string.Create(iidstr^));
  4353. end
  4354. else
  4355. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_8bit(0));
  4356. {$ifdef cpurequiresproperalignment}
  4357. current_asmdata.asmlists[al_rtti].concat(Tai_align.Create(sizeof(TConstPtrUInt)));
  4358. {$endif cpurequiresproperalignment}
  4359. end;
  4360. { write published properties for this object }
  4361. if objecttype in [odt_object,odt_class] then
  4362. begin
  4363. propcount:=0;
  4364. symtable.foreach(@count_published_properties,@propcount);
  4365. current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_16bit(propcount));
  4366. {$ifdef cpurequiresproperalignment}
  4367. current_asmdata.asmlists[al_rtti].concat(Tai_align.Create(sizeof(TConstPtrUInt)));
  4368. {$endif cpurequiresproperalignment}
  4369. end;
  4370. symtable.foreach(@write_property_info,nil);
  4371. propnamelist.free;
  4372. propnamelist:=nil;
  4373. end;
  4374. end;
  4375. end;
  4376. function tobjectdef.is_publishable : boolean;
  4377. begin
  4378. is_publishable:=objecttype in [odt_class,odt_interfacecom,odt_interfacecorba];
  4379. end;
  4380. {****************************************************************************
  4381. TIMPLEMENTEDINTERFACES
  4382. ****************************************************************************}
  4383. type
  4384. tnamemap = class(TNamedIndexItem)
  4385. listnext : TNamedIndexItem;
  4386. newname: pstring;
  4387. constructor create(const aname, anewname: string);
  4388. destructor destroy; override;
  4389. end;
  4390. constructor tnamemap.create(const aname, anewname: string);
  4391. begin
  4392. inherited createname(aname);
  4393. newname:=stringdup(anewname);
  4394. end;
  4395. destructor tnamemap.destroy;
  4396. begin
  4397. stringdispose(newname);
  4398. inherited destroy;
  4399. end;
  4400. type
  4401. tprocdefstore = class(TNamedIndexItem)
  4402. procdef: tprocdef;
  4403. constructor create(aprocdef: tprocdef);
  4404. end;
  4405. constructor tprocdefstore.create(aprocdef: tprocdef);
  4406. begin
  4407. inherited create;
  4408. procdef:=aprocdef;
  4409. end;
  4410. constructor timplintfentry.create(aintf: tobjectdef);
  4411. begin
  4412. inherited create;
  4413. intf:=aintf;
  4414. ioffset:=-1;
  4415. namemappings:=nil;
  4416. procdefs:=nil;
  4417. end;
  4418. constructor timplintfentry.create_deref(const d:tderef);
  4419. begin
  4420. inherited create;
  4421. intf:=nil;
  4422. intfderef:=d;
  4423. ioffset:=-1;
  4424. namemappings:=nil;
  4425. procdefs:=nil;
  4426. end;
  4427. destructor timplintfentry.destroy;
  4428. begin
  4429. if assigned(namemappings) then
  4430. namemappings.free;
  4431. if assigned(procdefs) then
  4432. procdefs.free;
  4433. inherited destroy;
  4434. end;
  4435. constructor timplementedinterfaces.create;
  4436. begin
  4437. finterfaces:=tindexarray.create(1);
  4438. end;
  4439. destructor timplementedinterfaces.destroy;
  4440. begin
  4441. finterfaces.destroy;
  4442. end;
  4443. function timplementedinterfaces.count: longint;
  4444. begin
  4445. count:=finterfaces.count;
  4446. end;
  4447. procedure timplementedinterfaces.checkindex(intfindex: longint);
  4448. begin
  4449. if (intfindex<1) or (intfindex>count) then
  4450. InternalError(200006123);
  4451. end;
  4452. function timplementedinterfaces.interfaces(intfindex: longint): tobjectdef;
  4453. begin
  4454. checkindex(intfindex);
  4455. interfaces:=timplintfentry(finterfaces.search(intfindex)).intf;
  4456. end;
  4457. function timplementedinterfaces.interfacesderef(intfindex: longint): tderef;
  4458. begin
  4459. checkindex(intfindex);
  4460. interfacesderef:=timplintfentry(finterfaces.search(intfindex)).intfderef;
  4461. end;
  4462. function timplementedinterfaces.ioffsets(intfindex: longint): longint;
  4463. begin
  4464. checkindex(intfindex);
  4465. ioffsets:=timplintfentry(finterfaces.search(intfindex)).ioffset;
  4466. end;
  4467. procedure timplementedinterfaces.setioffsets(intfindex,iofs:longint);
  4468. begin
  4469. checkindex(intfindex);
  4470. timplintfentry(finterfaces.search(intfindex)).ioffset:=iofs;
  4471. end;
  4472. function timplementedinterfaces.implindex(intfindex:longint):longint;
  4473. begin
  4474. checkindex(intfindex);
  4475. result:=timplintfentry(finterfaces.search(intfindex)).implindex;
  4476. end;
  4477. procedure timplementedinterfaces.setimplindex(intfindex,implidx:longint);
  4478. begin
  4479. checkindex(intfindex);
  4480. timplintfentry(finterfaces.search(intfindex)).implindex:=implidx;
  4481. end;
  4482. function timplementedinterfaces.searchintf(def: tdef): longint;
  4483. var
  4484. i: longint;
  4485. begin
  4486. i:=1;
  4487. while (i<=count) and (tdef(interfaces(i))<>def) do inc(i);
  4488. if i<=count then
  4489. searchintf:=i
  4490. else
  4491. searchintf:=-1;
  4492. end;
  4493. procedure timplementedinterfaces.buildderef;
  4494. var
  4495. i: longint;
  4496. begin
  4497. for i:=1 to count do
  4498. with timplintfentry(finterfaces.search(i)) do
  4499. intfderef.build(intf);
  4500. end;
  4501. procedure timplementedinterfaces.deref;
  4502. var
  4503. i: longint;
  4504. begin
  4505. for i:=1 to count do
  4506. with timplintfentry(finterfaces.search(i)) do
  4507. intf:=tobjectdef(intfderef.resolve);
  4508. end;
  4509. procedure timplementedinterfaces.addintf_deref(const d:tderef;iofs:longint);
  4510. var
  4511. hintf : timplintfentry;
  4512. begin
  4513. hintf:=timplintfentry.create_deref(d);
  4514. hintf.ioffset:=iofs;
  4515. finterfaces.insert(hintf);
  4516. end;
  4517. procedure timplementedinterfaces.addintf_ioffset(d:tdef;iofs:longint);
  4518. var
  4519. hintf : timplintfentry;
  4520. begin
  4521. hintf:=timplintfentry.create(tobjectdef(d));
  4522. hintf.ioffset:=iofs;
  4523. finterfaces.insert(hintf);
  4524. end;
  4525. procedure timplementedinterfaces.addintf(def: tdef);
  4526. begin
  4527. if not assigned(def) or (searchintf(def)<>-1) or (def.deftype<>objectdef) or
  4528. not (tobjectdef(def).objecttype in [odt_interfacecom,odt_interfacecorba]) then
  4529. internalerror(200006124);
  4530. finterfaces.insert(timplintfentry.create(tobjectdef(def)));
  4531. end;
  4532. procedure timplementedinterfaces.clearmappings;
  4533. var
  4534. i: longint;
  4535. begin
  4536. for i:=1 to count do
  4537. with timplintfentry(finterfaces.search(i)) do
  4538. begin
  4539. if assigned(namemappings) then
  4540. namemappings.free;
  4541. namemappings:=nil;
  4542. end;
  4543. end;
  4544. procedure timplementedinterfaces.addmappings(intfindex: longint; const origname, newname: string);
  4545. begin
  4546. checkindex(intfindex);
  4547. with timplintfentry(finterfaces.search(intfindex)) do
  4548. begin
  4549. if not assigned(namemappings) then
  4550. namemappings:=tdictionary.create;
  4551. namemappings.insert(tnamemap.create(origname,newname));
  4552. end;
  4553. end;
  4554. function timplementedinterfaces.getmappings(intfindex: longint; const origname: string; var nextexist: pointer): string;
  4555. begin
  4556. checkindex(intfindex);
  4557. if not assigned(nextexist) then
  4558. with timplintfentry(finterfaces.search(intfindex)) do
  4559. begin
  4560. if assigned(namemappings) then
  4561. nextexist:=namemappings.search(origname)
  4562. else
  4563. nextexist:=nil;
  4564. end;
  4565. if assigned(nextexist) then
  4566. begin
  4567. getmappings:=tnamemap(nextexist).newname^;
  4568. nextexist:=tnamemap(nextexist).listnext;
  4569. end
  4570. else
  4571. getmappings:='';
  4572. end;
  4573. procedure timplementedinterfaces.addimplproc(intfindex: longint; procdef: tprocdef);
  4574. var
  4575. found : boolean;
  4576. i : longint;
  4577. begin
  4578. checkindex(intfindex);
  4579. with timplintfentry(finterfaces.search(intfindex)) do
  4580. begin
  4581. if not assigned(procdefs) then
  4582. procdefs:=tindexarray.create(4);
  4583. { No duplicate entries of the same procdef }
  4584. found:=false;
  4585. for i:=1 to procdefs.count do
  4586. if tprocdefstore(procdefs.search(i)).procdef=procdef then
  4587. begin
  4588. found:=true;
  4589. break;
  4590. end;
  4591. if not found then
  4592. procdefs.insert(tprocdefstore.create(procdef));
  4593. end;
  4594. end;
  4595. function timplementedinterfaces.implproccount(intfindex: longint): longint;
  4596. begin
  4597. checkindex(intfindex);
  4598. with timplintfentry(finterfaces.search(intfindex)) do
  4599. if assigned(procdefs) then
  4600. implproccount:=procdefs.count
  4601. else
  4602. implproccount:=0;
  4603. end;
  4604. function timplementedinterfaces.implprocs(intfindex: longint; procindex: longint): tprocdef;
  4605. begin
  4606. checkindex(intfindex);
  4607. with timplintfentry(finterfaces.search(intfindex)) do
  4608. if assigned(procdefs) then
  4609. implprocs:=tprocdefstore(procdefs.search(procindex)).procdef
  4610. else
  4611. internalerror(200006131);
  4612. end;
  4613. function timplementedinterfaces.isimplmergepossible(intfindex, remainindex: longint; var weight: longint): boolean;
  4614. var
  4615. possible: boolean;
  4616. i: longint;
  4617. iiep1: TIndexArray;
  4618. iiep2: TIndexArray;
  4619. begin
  4620. checkindex(intfindex);
  4621. checkindex(remainindex);
  4622. iiep1:=timplintfentry(finterfaces.search(intfindex)).procdefs;
  4623. iiep2:=timplintfentry(finterfaces.search(remainindex)).procdefs;
  4624. if not assigned(iiep1) then { empty interface is mergeable :-) }
  4625. begin
  4626. possible:=true;
  4627. weight:=0;
  4628. end
  4629. else
  4630. begin
  4631. possible:=assigned(iiep2) and (iiep1.count<=iiep2.count);
  4632. i:=1;
  4633. while (possible) and (i<=iiep1.count) do
  4634. begin
  4635. possible:=
  4636. (tprocdefstore(iiep1.search(i)).procdef=tprocdefstore(iiep2.search(i)).procdef);
  4637. inc(i);
  4638. end;
  4639. if possible then
  4640. weight:=iiep1.count;
  4641. end;
  4642. isimplmergepossible:=possible;
  4643. end;
  4644. {****************************************************************************
  4645. TFORWARDDEF
  4646. ****************************************************************************}
  4647. constructor tforwarddef.create(const s:string;const pos : tfileposinfo);
  4648. begin
  4649. inherited create(forwarddef);
  4650. tosymname:=stringdup(s);
  4651. forwardpos:=pos;
  4652. end;
  4653. function tforwarddef.gettypename:string;
  4654. begin
  4655. gettypename:='unresolved forward to '+tosymname^;
  4656. end;
  4657. destructor tforwarddef.destroy;
  4658. begin
  4659. if assigned(tosymname) then
  4660. stringdispose(tosymname);
  4661. inherited destroy;
  4662. end;
  4663. {****************************************************************************
  4664. TUNDEFINEDDEF
  4665. ****************************************************************************}
  4666. constructor tundefineddef.create;
  4667. begin
  4668. inherited create(undefineddef);
  4669. end;
  4670. constructor tundefineddef.ppuload(ppufile:tcompilerppufile);
  4671. begin
  4672. inherited ppuload(undefineddef,ppufile);
  4673. end;
  4674. function tundefineddef.gettypename:string;
  4675. begin
  4676. gettypename:='<undefined type>';
  4677. end;
  4678. procedure tundefineddef.ppuwrite(ppufile:tcompilerppufile);
  4679. begin
  4680. inherited ppuwrite(ppufile);
  4681. ppufile.writeentry(ibundefineddef);
  4682. end;
  4683. {****************************************************************************
  4684. TERRORDEF
  4685. ****************************************************************************}
  4686. constructor terrordef.create;
  4687. begin
  4688. inherited create(errordef);
  4689. end;
  4690. procedure terrordef.ppuwrite(ppufile:tcompilerppufile);
  4691. begin
  4692. { Can't write errordefs to ppu }
  4693. internalerror(200411063);
  4694. end;
  4695. function terrordef.gettypename:string;
  4696. begin
  4697. gettypename:='<erroneous type>';
  4698. end;
  4699. function terrordef.getmangledparaname:string;
  4700. begin
  4701. getmangledparaname:='error';
  4702. end;
  4703. {****************************************************************************
  4704. Definition Helpers
  4705. ****************************************************************************}
  4706. function is_interfacecom(def: tdef): boolean;
  4707. begin
  4708. is_interfacecom:=
  4709. assigned(def) and
  4710. (def.deftype=objectdef) and
  4711. (tobjectdef(def).objecttype=odt_interfacecom);
  4712. end;
  4713. function is_interfacecorba(def: tdef): boolean;
  4714. begin
  4715. is_interfacecorba:=
  4716. assigned(def) and
  4717. (def.deftype=objectdef) and
  4718. (tobjectdef(def).objecttype=odt_interfacecorba);
  4719. end;
  4720. function is_interface(def: tdef): boolean;
  4721. begin
  4722. is_interface:=
  4723. assigned(def) and
  4724. (def.deftype=objectdef) and
  4725. (tobjectdef(def).objecttype in [odt_interfacecom,odt_interfacecorba]);
  4726. end;
  4727. function is_class(def: tdef): boolean;
  4728. begin
  4729. is_class:=
  4730. assigned(def) and
  4731. (def.deftype=objectdef) and
  4732. (tobjectdef(def).objecttype=odt_class);
  4733. end;
  4734. function is_object(def: tdef): boolean;
  4735. begin
  4736. is_object:=
  4737. assigned(def) and
  4738. (def.deftype=objectdef) and
  4739. (tobjectdef(def).objecttype=odt_object);
  4740. end;
  4741. function is_cppclass(def: tdef): boolean;
  4742. begin
  4743. is_cppclass:=
  4744. assigned(def) and
  4745. (def.deftype=objectdef) and
  4746. (tobjectdef(def).objecttype=odt_cppclass);
  4747. end;
  4748. function is_class_or_interface(def: tdef): boolean;
  4749. begin
  4750. is_class_or_interface:=
  4751. assigned(def) and
  4752. (def.deftype=objectdef) and
  4753. (tobjectdef(def).objecttype in [odt_class,odt_interfacecom,odt_interfacecorba]);
  4754. end;
  4755. function is_class_or_interface_or_dispinterface(def: tdef): boolean;
  4756. begin
  4757. result:=
  4758. assigned(def) and
  4759. (def.deftype=objectdef) and
  4760. (tobjectdef(def).objecttype in [odt_class,odt_interfacecom,odt_interfacecorba,odt_dispinterface]);
  4761. end;
  4762. {$ifdef x86}
  4763. function use_sse(def : tdef) : boolean;
  4764. begin
  4765. use_sse:=(is_single(def) and (aktfputype in sse_singlescalar)) or
  4766. (is_double(def) and (aktfputype in sse_doublescalar));
  4767. end;
  4768. {$endif x86}
  4769. end.