symdef.pas 167 KB

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