symdef.pas 167 KB

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