symdef.pas 168 KB

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