symdef.pas 168 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517
  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[10] = (
  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. { Exception: interface definitions in mode macpas, since in that }
  3373. { case no reference to the old name can exist yet (JM) }
  3374. if assigned(_mangledname) then
  3375. if ((m_mac in aktmodeswitches) and
  3376. (interfacedef)) then
  3377. stringdispose(_mangledname)
  3378. else
  3379. internalerror(200411171);
  3380. {$ifdef compress}
  3381. _mangledname:=stringdup(minilzw_encode(s));
  3382. {$else}
  3383. _mangledname:=stringdup(s);
  3384. {$endif}
  3385. include(procoptions,po_has_mangledname);
  3386. end;
  3387. {***************************************************************************
  3388. TPROCVARDEF
  3389. ***************************************************************************}
  3390. constructor tprocvardef.create(level:byte);
  3391. begin
  3392. inherited create(level);
  3393. deftype:=procvardef;
  3394. end;
  3395. constructor tprocvardef.ppuload(ppufile:tcompilerppufile);
  3396. begin
  3397. inherited ppuload(ppufile);
  3398. deftype:=procvardef;
  3399. { load para symtable }
  3400. parast:=tparasymtable.create(unknown_level);
  3401. tparasymtable(parast).ppuload(ppufile);
  3402. parast.defowner:=self;
  3403. end;
  3404. function tprocvardef.getcopy : tstoreddef;
  3405. begin
  3406. result:=self;
  3407. (*
  3408. { saves a definition to the return type }
  3409. rettype : ttype;
  3410. parast : tsymtable;
  3411. paras : tparalist;
  3412. proctypeoption : tproctypeoption;
  3413. proccalloption : tproccalloption;
  3414. procoptions : tprocoptions;
  3415. requiredargarea : aint;
  3416. { number of user visibile parameters }
  3417. maxparacount,
  3418. minparacount : byte;
  3419. {$ifdef i386}
  3420. fpu_used : longint; { how many stack fpu must be empty }
  3421. {$endif i386}
  3422. funcretloc : array[tcallercallee] of TLocation;
  3423. has_paraloc_info : boolean; { paraloc info is available }
  3424. tprocvardef = class(tabstractprocdef)
  3425. constructor create(level:byte);
  3426. constructor ppuload(ppufile:tcompilerppufile);
  3427. function getcopy : tstoreddef;override;
  3428. *)
  3429. end;
  3430. procedure tprocvardef.ppuwrite(ppufile:tcompilerppufile);
  3431. var
  3432. oldparasymtable,
  3433. oldlocalsymtable : tsymtable;
  3434. begin
  3435. oldparasymtable:=aktparasymtable;
  3436. oldlocalsymtable:=aktlocalsymtable;
  3437. aktparasymtable:=parast;
  3438. aktlocalsymtable:=nil;
  3439. { here we cannot get a real good value so just give something }
  3440. { plausible (PM) }
  3441. { a more secure way would be
  3442. to allways store in a temp }
  3443. {$ifdef i386}
  3444. if is_fpu(rettype.def) then
  3445. fpu_used:={2}maxfpuregs
  3446. else
  3447. fpu_used:=0;
  3448. {$endif i386}
  3449. inherited ppuwrite(ppufile);
  3450. { Write this entry }
  3451. ppufile.writeentry(ibprocvardef);
  3452. { Save the para symtable, this is taken from the interface }
  3453. tparasymtable(parast).ppuwrite(ppufile);
  3454. aktparasymtable:=oldparasymtable;
  3455. aktlocalsymtable:=oldlocalsymtable;
  3456. end;
  3457. procedure tprocvardef.buildderef;
  3458. var
  3459. oldparasymtable,
  3460. oldlocalsymtable : tsymtable;
  3461. begin
  3462. oldparasymtable:=aktparasymtable;
  3463. oldlocalsymtable:=aktlocalsymtable;
  3464. aktparasymtable:=parast;
  3465. aktlocalsymtable:=nil;
  3466. inherited buildderef;
  3467. aktparasymtable:=oldparasymtable;
  3468. aktlocalsymtable:=oldlocalsymtable;
  3469. end;
  3470. procedure tprocvardef.deref;
  3471. var
  3472. oldparasymtable,
  3473. oldlocalsymtable : tsymtable;
  3474. begin
  3475. oldparasymtable:=aktparasymtable;
  3476. oldlocalsymtable:=aktlocalsymtable;
  3477. aktparasymtable:=parast;
  3478. aktlocalsymtable:=nil;
  3479. inherited deref;
  3480. aktparasymtable:=oldparasymtable;
  3481. aktlocalsymtable:=oldlocalsymtable;
  3482. end;
  3483. function tprocvardef.getsymtable(t:tgetsymtable):tsymtable;
  3484. begin
  3485. case t of
  3486. gs_para :
  3487. getsymtable:=parast;
  3488. else
  3489. getsymtable:=nil;
  3490. end;
  3491. end;
  3492. function tprocvardef.size : aint;
  3493. begin
  3494. if (po_methodpointer in procoptions) and
  3495. not(po_addressonly in procoptions) then
  3496. size:=2*sizeof(aint)
  3497. else
  3498. size:=sizeof(aint);
  3499. end;
  3500. function tprocvardef.is_methodpointer:boolean;
  3501. begin
  3502. result:=(po_methodpointer in procoptions);
  3503. end;
  3504. function tprocvardef.is_addressonly:boolean;
  3505. begin
  3506. result:=not(po_methodpointer in procoptions) or
  3507. (po_addressonly in procoptions);
  3508. end;
  3509. function tprocvardef.getmangledparaname:string;
  3510. begin
  3511. result:='procvar';
  3512. end;
  3513. procedure tprocvardef.write_rtti_data(rt:trttitype);
  3514. procedure write_para(parasym:tparavarsym);
  3515. var
  3516. paraspec : byte;
  3517. begin
  3518. { only store user visible parameters }
  3519. if not(vo_is_hidden_para in parasym.varoptions) then
  3520. begin
  3521. case parasym.varspez of
  3522. vs_value: paraspec := 0;
  3523. vs_const: paraspec := pfConst;
  3524. vs_var : paraspec := pfVar;
  3525. vs_out : paraspec := pfOut;
  3526. end;
  3527. { write flags for current parameter }
  3528. asmlist[al_rtti].concat(Tai_const.Create_8bit(paraspec));
  3529. { write name of current parameter }
  3530. asmlist[al_rtti].concat(Tai_const.Create_8bit(length(parasym.realname)));
  3531. asmlist[al_rtti].concat(Tai_string.Create(parasym.realname));
  3532. { write name of type of current parameter }
  3533. tstoreddef(parasym.vartype.def).write_rtti_name;
  3534. end;
  3535. end;
  3536. var
  3537. methodkind : byte;
  3538. i : integer;
  3539. begin
  3540. if po_methodpointer in procoptions then
  3541. begin
  3542. { write method id and name }
  3543. asmlist[al_rtti].concat(Tai_const.Create_8bit(tkmethod));
  3544. write_rtti_name;
  3545. {$ifdef cpurequiresproperalignment}
  3546. asmlist[al_rtti].concat(Tai_align.Create(sizeof(TConstPtrUInt)));
  3547. {$endif cpurequiresproperalignment}
  3548. { write kind of method (can only be function or procedure)}
  3549. if rettype.def = voidtype.def then
  3550. methodkind := mkProcedure
  3551. else
  3552. methodkind := mkFunction;
  3553. asmlist[al_rtti].concat(Tai_const.Create_8bit(methodkind));
  3554. { get # of parameters }
  3555. asmlist[al_rtti].concat(Tai_const.Create_8bit(maxparacount));
  3556. { write parameter info. The parameters must be written in reverse order
  3557. if this method uses right to left parameter pushing! }
  3558. if proccalloption in pushleftright_pocalls then
  3559. begin
  3560. for i:=0 to paras.count-1 do
  3561. write_para(tparavarsym(paras[i]));
  3562. end
  3563. else
  3564. begin
  3565. for i:=paras.count-1 downto 0 do
  3566. write_para(tparavarsym(paras[i]));
  3567. end;
  3568. { write name of result type }
  3569. tstoreddef(rettype.def).write_rtti_name;
  3570. end
  3571. else
  3572. begin
  3573. asmlist[al_rtti].concat(Tai_const.Create_8bit(tkprocvar));
  3574. write_rtti_name;
  3575. end;
  3576. end;
  3577. function tprocvardef.is_publishable : boolean;
  3578. begin
  3579. is_publishable:=(po_methodpointer in procoptions);
  3580. end;
  3581. function tprocvardef.gettypename : string;
  3582. var
  3583. s: string;
  3584. showhidden : boolean;
  3585. begin
  3586. {$ifdef EXTDEBUG}
  3587. showhidden:=true;
  3588. {$else EXTDEBUG}
  3589. showhidden:=false;
  3590. {$endif EXTDEBUG}
  3591. s:='<';
  3592. if po_classmethod in procoptions then
  3593. s := s+'class method type of'
  3594. else
  3595. if po_addressonly in procoptions then
  3596. s := s+'address of'
  3597. else
  3598. s := s+'procedure variable type of';
  3599. if po_local in procoptions then
  3600. s := s+' local';
  3601. if assigned(rettype.def) and
  3602. (rettype.def<>voidtype.def) then
  3603. s:=s+' function'+typename_paras(showhidden)+':'+rettype.def.gettypename
  3604. else
  3605. s:=s+' procedure'+typename_paras(showhidden);
  3606. if po_methodpointer in procoptions then
  3607. s := s+' of object';
  3608. gettypename := s+';'+ProcCallOptionStr[proccalloption]+'>';
  3609. end;
  3610. {***************************************************************************
  3611. TOBJECTDEF
  3612. ***************************************************************************}
  3613. type
  3614. tproptablelistitem = class(TLinkedListItem)
  3615. index : longint;
  3616. def : tobjectdef;
  3617. end;
  3618. tpropnamelistitem = class(TLinkedListItem)
  3619. index : longint;
  3620. name : stringid;
  3621. owner : tsymtable;
  3622. end;
  3623. var
  3624. proptablelist : tlinkedlist;
  3625. propnamelist : tlinkedlist;
  3626. function searchproptablelist(p : tobjectdef) : tproptablelistitem;
  3627. var
  3628. hp : tproptablelistitem;
  3629. begin
  3630. hp:=tproptablelistitem(proptablelist.first);
  3631. while assigned(hp) do
  3632. if hp.def=p then
  3633. begin
  3634. result:=hp;
  3635. exit;
  3636. end
  3637. else
  3638. hp:=tproptablelistitem(hp.next);
  3639. result:=nil;
  3640. end;
  3641. function searchpropnamelist(const n:string) : tpropnamelistitem;
  3642. var
  3643. hp : tpropnamelistitem;
  3644. begin
  3645. hp:=tpropnamelistitem(propnamelist.first);
  3646. while assigned(hp) do
  3647. if hp.name=n then
  3648. begin
  3649. result:=hp;
  3650. exit;
  3651. end
  3652. else
  3653. hp:=tpropnamelistitem(hp.next);
  3654. result:=nil;
  3655. end;
  3656. constructor tobjectdef.create(ot : tobjectdeftype;const n : string;c : tobjectdef);
  3657. begin
  3658. inherited create;
  3659. objecttype:=ot;
  3660. deftype:=objectdef;
  3661. objectoptions:=[];
  3662. childof:=nil;
  3663. symtable:=tobjectsymtable.create(n,aktpackrecords);
  3664. { create space for vmt !! }
  3665. vmt_offset:=0;
  3666. symtable.defowner:=self;
  3667. lastvtableindex:=0;
  3668. set_parent(c);
  3669. objname:=stringdup(upper(n));
  3670. objrealname:=stringdup(n);
  3671. if objecttype in [odt_interfacecorba,odt_interfacecom] then
  3672. prepareguid;
  3673. { setup implemented interfaces }
  3674. if objecttype in [odt_class,odt_interfacecorba] then
  3675. implementedinterfaces:=timplementedinterfaces.create
  3676. else
  3677. implementedinterfaces:=nil;
  3678. writing_class_record_stab:=false;
  3679. end;
  3680. constructor tobjectdef.ppuload(ppufile:tcompilerppufile);
  3681. var
  3682. i,implintfcount: longint;
  3683. d : tderef;
  3684. begin
  3685. inherited ppuloaddef(ppufile);
  3686. deftype:=objectdef;
  3687. objecttype:=tobjectdeftype(ppufile.getbyte);
  3688. objrealname:=stringdup(ppufile.getstring);
  3689. objname:=stringdup(upper(objrealname^));
  3690. symtable:=tobjectsymtable.create(objrealname^,0);
  3691. tobjectsymtable(symtable).datasize:=ppufile.getaint;
  3692. tobjectsymtable(symtable).fieldalignment:=ppufile.getbyte;
  3693. tobjectsymtable(symtable).recordalignment:=ppufile.getbyte;
  3694. vmt_offset:=ppufile.getlongint;
  3695. ppufile.getderef(childofderef);
  3696. ppufile.getsmallset(objectoptions);
  3697. { load guid }
  3698. iidstr:=nil;
  3699. if objecttype in [odt_interfacecom,odt_interfacecorba] then
  3700. begin
  3701. new(iidguid);
  3702. ppufile.getguid(iidguid^);
  3703. iidstr:=stringdup(ppufile.getstring);
  3704. lastvtableindex:=ppufile.getlongint;
  3705. end;
  3706. { load implemented interfaces }
  3707. if objecttype in [odt_class,odt_interfacecorba] then
  3708. begin
  3709. implementedinterfaces:=timplementedinterfaces.create;
  3710. implintfcount:=ppufile.getlongint;
  3711. for i:=1 to implintfcount do
  3712. begin
  3713. ppufile.getderef(d);
  3714. implementedinterfaces.addintf_deref(d,ppufile.getlongint);
  3715. end;
  3716. end
  3717. else
  3718. implementedinterfaces:=nil;
  3719. tobjectsymtable(symtable).ppuload(ppufile);
  3720. symtable.defowner:=self;
  3721. { handles the predefined class tobject }
  3722. { the last TOBJECT which is loaded gets }
  3723. { it ! }
  3724. if (childof=nil) and
  3725. (objecttype=odt_class) and
  3726. (objname^='TOBJECT') then
  3727. class_tobject:=self;
  3728. if (childof=nil) and
  3729. (objecttype=odt_interfacecom) and
  3730. (objname^='IUNKNOWN') then
  3731. interface_iunknown:=self;
  3732. writing_class_record_stab:=false;
  3733. end;
  3734. destructor tobjectdef.destroy;
  3735. begin
  3736. if assigned(symtable) then
  3737. symtable.free;
  3738. stringdispose(objname);
  3739. stringdispose(objrealname);
  3740. if assigned(iidstr) then
  3741. stringdispose(iidstr);
  3742. if assigned(implementedinterfaces) then
  3743. implementedinterfaces.free;
  3744. if assigned(iidguid) then
  3745. dispose(iidguid);
  3746. inherited destroy;
  3747. end;
  3748. function tobjectdef.getcopy : tstoreddef;
  3749. var
  3750. i,
  3751. implintfcount : longint;
  3752. begin
  3753. result:=tobjectdef.create(objecttype,objname^,childof);
  3754. tobjectdef(result).symtable:=symtable.getcopy;
  3755. if assigned(objname) then
  3756. tobjectdef(result).objname:=stringdup(objname^);
  3757. if assigned(objrealname) then
  3758. tobjectdef(result).objrealname:=stringdup(objrealname^);
  3759. tobjectdef(result).objectoptions:=objectoptions;
  3760. tobjectdef(result).vmt_offset:=vmt_offset;
  3761. if assigned(iidguid) then
  3762. begin
  3763. new(tobjectdef(result).iidguid);
  3764. move(iidguid^,tobjectdef(result).iidguid^,sizeof(iidguid^));
  3765. end;
  3766. if assigned(iidstr) then
  3767. tobjectdef(result).iidstr:=stringdup(iidstr^);
  3768. tobjectdef(result).lastvtableindex:=lastvtableindex;
  3769. if assigned(implementedinterfaces) then
  3770. begin
  3771. implintfcount:=implementedinterfaces.count;
  3772. for i:=1 to implintfcount do
  3773. begin
  3774. tobjectdef(result).implementedinterfaces.addintf_ioffset(implementedinterfaces.interfaces(i),
  3775. implementedinterfaces.ioffsets(i));
  3776. end;
  3777. end;
  3778. end;
  3779. procedure tobjectdef.ppuwrite(ppufile:tcompilerppufile);
  3780. var
  3781. implintfcount : longint;
  3782. i : longint;
  3783. begin
  3784. inherited ppuwritedef(ppufile);
  3785. ppufile.putbyte(byte(objecttype));
  3786. ppufile.putstring(objrealname^);
  3787. ppufile.putaint(tobjectsymtable(symtable).datasize);
  3788. ppufile.putbyte(tobjectsymtable(symtable).fieldalignment);
  3789. ppufile.putbyte(tobjectsymtable(symtable).recordalignment);
  3790. ppufile.putlongint(vmt_offset);
  3791. ppufile.putderef(childofderef);
  3792. ppufile.putsmallset(objectoptions);
  3793. if objecttype in [odt_interfacecom,odt_interfacecorba] then
  3794. begin
  3795. ppufile.putguid(iidguid^);
  3796. ppufile.putstring(iidstr^);
  3797. ppufile.putlongint(lastvtableindex);
  3798. end;
  3799. if objecttype in [odt_class,odt_interfacecorba] then
  3800. begin
  3801. implintfcount:=implementedinterfaces.count;
  3802. ppufile.putlongint(implintfcount);
  3803. for i:=1 to implintfcount do
  3804. begin
  3805. ppufile.putderef(implementedinterfaces.interfacesderef(i));
  3806. ppufile.putlongint(implementedinterfaces.ioffsets(i));
  3807. end;
  3808. end;
  3809. ppufile.writeentry(ibobjectdef);
  3810. tobjectsymtable(symtable).ppuwrite(ppufile);
  3811. end;
  3812. function tobjectdef.gettypename:string;
  3813. begin
  3814. gettypename:=typename;
  3815. end;
  3816. procedure tobjectdef.buildderef;
  3817. var
  3818. oldrecsyms : tsymtable;
  3819. begin
  3820. inherited buildderef;
  3821. childofderef.build(childof);
  3822. oldrecsyms:=aktrecordsymtable;
  3823. aktrecordsymtable:=symtable;
  3824. tstoredsymtable(symtable).buildderef;
  3825. aktrecordsymtable:=oldrecsyms;
  3826. if objecttype in [odt_class,odt_interfacecorba] then
  3827. implementedinterfaces.buildderef;
  3828. end;
  3829. procedure tobjectdef.deref;
  3830. var
  3831. oldrecsyms : tsymtable;
  3832. begin
  3833. inherited deref;
  3834. childof:=tobjectdef(childofderef.resolve);
  3835. oldrecsyms:=aktrecordsymtable;
  3836. aktrecordsymtable:=symtable;
  3837. tstoredsymtable(symtable).deref;
  3838. aktrecordsymtable:=oldrecsyms;
  3839. if objecttype in [odt_class,odt_interfacecorba] then
  3840. implementedinterfaces.deref;
  3841. end;
  3842. function tobjectdef.getparentdef:tdef;
  3843. begin
  3844. {$warning TODO Remove getparentdef hack}
  3845. { With 2 forward declared classes with the child class before the
  3846. parent class the child class is written earlier to the ppu. Leaving it
  3847. possible to have a reference to the parent class for property overriding,
  3848. but the parent class still has the childof not resolved yet (PFV) }
  3849. if childof=nil then
  3850. childof:=tobjectdef(childofderef.resolve);
  3851. result:=childof;
  3852. end;
  3853. procedure tobjectdef.prepareguid;
  3854. begin
  3855. { set up guid }
  3856. if not assigned(iidguid) then
  3857. begin
  3858. new(iidguid);
  3859. fillchar(iidguid^,sizeof(iidguid^),0); { default null guid }
  3860. end;
  3861. { setup iidstring }
  3862. if not assigned(iidstr) then
  3863. iidstr:=stringdup(''); { default is empty string }
  3864. end;
  3865. procedure tobjectdef.set_parent( c : tobjectdef);
  3866. begin
  3867. { nothing to do if the parent was not forward !}
  3868. if assigned(childof) then
  3869. exit;
  3870. childof:=c;
  3871. { some options are inherited !! }
  3872. if assigned(c) then
  3873. begin
  3874. { only important for classes }
  3875. lastvtableindex:=c.lastvtableindex;
  3876. objectoptions:=objectoptions+(c.objectoptions*
  3877. inherited_objectoptions);
  3878. if not (objecttype in [odt_interfacecom,odt_interfacecorba]) then
  3879. begin
  3880. { add the data of the anchestor class }
  3881. inc(tobjectsymtable(symtable).datasize,tobjectsymtable(c.symtable).datasize);
  3882. if (oo_has_vmt in objectoptions) and
  3883. (oo_has_vmt in c.objectoptions) then
  3884. dec(tobjectsymtable(symtable).datasize,sizeof(aint));
  3885. { if parent has a vmt field then
  3886. the offset is the same for the child PM }
  3887. if (oo_has_vmt in c.objectoptions) or is_class(self) then
  3888. begin
  3889. vmt_offset:=c.vmt_offset;
  3890. include(objectoptions,oo_has_vmt);
  3891. end;
  3892. end;
  3893. end;
  3894. end;
  3895. procedure tobjectdef.insertvmt;
  3896. begin
  3897. if objecttype in [odt_interfacecom,odt_interfacecorba] then
  3898. exit;
  3899. if (oo_has_vmt in objectoptions) then
  3900. internalerror(12345)
  3901. else
  3902. begin
  3903. tobjectsymtable(symtable).datasize:=align(tobjectsymtable(symtable).datasize,
  3904. tobjectsymtable(symtable).fieldalignment);
  3905. {$ifdef cpurequiresproperalignment}
  3906. tobjectsymtable(symtable).datasize:=align(tobjectsymtable(symtable).datasize,sizeof(aint));
  3907. {$endif cpurequiresproperalignment}
  3908. vmt_offset:=tobjectsymtable(symtable).datasize;
  3909. inc(tobjectsymtable(symtable).datasize,sizeof(aint));
  3910. include(objectoptions,oo_has_vmt);
  3911. end;
  3912. end;
  3913. procedure tobjectdef.check_forwards;
  3914. begin
  3915. if not(objecttype in [odt_interfacecom,odt_interfacecorba]) then
  3916. tstoredsymtable(symtable).check_forwards;
  3917. if (oo_is_forward in objectoptions) then
  3918. begin
  3919. { ok, in future, the forward can be resolved }
  3920. Message1(sym_e_class_forward_not_resolved,objrealname^);
  3921. exclude(objectoptions,oo_is_forward);
  3922. end;
  3923. end;
  3924. { true, if self inherits from d (or if they are equal) }
  3925. function tobjectdef.is_related(d : tdef) : boolean;
  3926. var
  3927. hp : tobjectdef;
  3928. begin
  3929. hp:=self;
  3930. while assigned(hp) do
  3931. begin
  3932. if hp=d then
  3933. begin
  3934. is_related:=true;
  3935. exit;
  3936. end;
  3937. hp:=hp.childof;
  3938. end;
  3939. is_related:=false;
  3940. end;
  3941. procedure _searchdestructor(sym:Tnamedindexitem;sd:pointer);
  3942. begin
  3943. { if we found already a destructor, then we exit }
  3944. if (ppointer(sd)^=nil) and
  3945. (Tsym(sym).typ=procsym) then
  3946. ppointer(sd)^:=Tprocsym(sym).search_procdef_bytype(potype_destructor);
  3947. end;
  3948. function tobjectdef.searchdestructor : tprocdef;
  3949. var
  3950. o : tobjectdef;
  3951. sd : tprocdef;
  3952. begin
  3953. searchdestructor:=nil;
  3954. o:=self;
  3955. sd:=nil;
  3956. while assigned(o) do
  3957. begin
  3958. o.symtable.foreach_static(@_searchdestructor,@sd);
  3959. if assigned(sd) then
  3960. begin
  3961. searchdestructor:=sd;
  3962. exit;
  3963. end;
  3964. o:=o.childof;
  3965. end;
  3966. end;
  3967. function tobjectdef.size : aint;
  3968. begin
  3969. if objecttype in [odt_class,odt_interfacecom,odt_interfacecorba] then
  3970. result:=sizeof(aint)
  3971. else
  3972. result:=tobjectsymtable(symtable).datasize;
  3973. end;
  3974. function tobjectdef.alignment:longint;
  3975. begin
  3976. if objecttype in [odt_class,odt_interfacecom,odt_interfacecorba] then
  3977. alignment:=sizeof(aint)
  3978. else
  3979. alignment:=tobjectsymtable(symtable).recordalignment;
  3980. end;
  3981. function tobjectdef.vmtmethodoffset(index:longint):longint;
  3982. begin
  3983. { for offset of methods for classes, see rtl/inc/objpash.inc }
  3984. case objecttype of
  3985. odt_class:
  3986. { the +2*sizeof(Aint) is size and -size }
  3987. vmtmethodoffset:=(index+10)*sizeof(aint)+2*sizeof(AInt);
  3988. odt_interfacecom,odt_interfacecorba:
  3989. vmtmethodoffset:=index*sizeof(aint);
  3990. else
  3991. {$ifdef WITHDMT}
  3992. vmtmethodoffset:=(index+4)*sizeof(aint);
  3993. {$else WITHDMT}
  3994. vmtmethodoffset:=(index+3)*sizeof(aint);
  3995. {$endif WITHDMT}
  3996. end;
  3997. end;
  3998. function tobjectdef.vmt_mangledname : string;
  3999. begin
  4000. if not(oo_has_vmt in objectoptions) then
  4001. Message1(parser_n_object_has_no_vmt,objrealname^);
  4002. vmt_mangledname:=make_mangledname('VMT',owner,objname^);
  4003. end;
  4004. function tobjectdef.rtti_name : string;
  4005. begin
  4006. rtti_name:=make_mangledname('RTTI',owner,objname^);
  4007. end;
  4008. function tobjectdef.needs_inittable : boolean;
  4009. begin
  4010. case objecttype of
  4011. odt_class :
  4012. needs_inittable:=false;
  4013. odt_interfacecom:
  4014. needs_inittable:=true;
  4015. odt_interfacecorba:
  4016. needs_inittable:=is_related(interface_iunknown);
  4017. odt_object:
  4018. needs_inittable:=tobjectsymtable(symtable).needs_init_final;
  4019. else
  4020. internalerror(200108267);
  4021. end;
  4022. end;
  4023. function tobjectdef.members_need_inittable : boolean;
  4024. begin
  4025. members_need_inittable:=tobjectsymtable(symtable).needs_init_final;
  4026. end;
  4027. procedure tobjectdef.collect_published_properties(sym:tnamedindexitem;arg:pointer);
  4028. var
  4029. hp : tpropnamelistitem;
  4030. begin
  4031. if (tsym(sym).typ=propertysym) and
  4032. (sp_published in tsym(sym).symoptions) then
  4033. begin
  4034. hp:=searchpropnamelist(tsym(sym).name);
  4035. if not(assigned(hp)) then
  4036. begin
  4037. hp:=tpropnamelistitem.create;
  4038. hp.name:=tsym(sym).name;
  4039. hp.index:=propnamelist.count;
  4040. hp.owner:=tsym(sym).owner;
  4041. propnamelist.concat(hp);
  4042. end;
  4043. end;
  4044. end;
  4045. procedure tobjectdef.count_published_properties(sym:tnamedindexitem;arg:pointer);
  4046. begin
  4047. if (tsym(sym).typ=propertysym) and
  4048. (sp_published in tsym(sym).symoptions) then
  4049. inc(plongint(arg)^);
  4050. end;
  4051. procedure tobjectdef.write_property_info(sym : tnamedindexitem;arg:pointer);
  4052. var
  4053. proctypesinfo : byte;
  4054. propnameitem : tpropnamelistitem;
  4055. procedure writeproc(proc : tsymlist; shiftvalue : byte);
  4056. var
  4057. typvalue : byte;
  4058. hp : psymlistitem;
  4059. address : longint;
  4060. def : tdef;
  4061. begin
  4062. if not(assigned(proc) and assigned(proc.firstsym)) then
  4063. begin
  4064. asmlist[al_rtti].concat(Tai_const.create(ait_const_ptr,1));
  4065. typvalue:=3;
  4066. end
  4067. else if proc.firstsym^.sym.typ=fieldvarsym then
  4068. begin
  4069. address:=0;
  4070. hp:=proc.firstsym;
  4071. def:=nil;
  4072. while assigned(hp) do
  4073. begin
  4074. case hp^.sltype of
  4075. sl_load :
  4076. begin
  4077. def:=tfieldvarsym(hp^.sym).vartype.def;
  4078. inc(address,tfieldvarsym(hp^.sym).fieldoffset);
  4079. end;
  4080. sl_subscript :
  4081. begin
  4082. if not(assigned(def) and (def.deftype=recorddef)) then
  4083. internalerror(200402171);
  4084. inc(address,tfieldvarsym(hp^.sym).fieldoffset);
  4085. def:=tfieldvarsym(hp^.sym).vartype.def;
  4086. end;
  4087. sl_vec :
  4088. begin
  4089. if not(assigned(def) and (def.deftype=arraydef)) then
  4090. internalerror(200402172);
  4091. def:=tarraydef(def).elementtype.def;
  4092. inc(address,def.size*hp^.value);
  4093. end;
  4094. end;
  4095. hp:=hp^.next;
  4096. end;
  4097. asmlist[al_rtti].concat(Tai_const.create(ait_const_ptr,address));
  4098. typvalue:=0;
  4099. end
  4100. else
  4101. begin
  4102. { When there was an error then procdef is not assigned }
  4103. if not assigned(proc.procdef) then
  4104. exit;
  4105. if not(po_virtualmethod in tprocdef(proc.procdef).procoptions) then
  4106. begin
  4107. asmlist[al_rtti].concat(Tai_const.createname(tprocdef(proc.procdef).mangledname,AT_FUNCTION,0));
  4108. typvalue:=1;
  4109. end
  4110. else
  4111. begin
  4112. { virtual method, write vmt offset }
  4113. asmlist[al_rtti].concat(Tai_const.create(ait_const_ptr,
  4114. tprocdef(proc.procdef)._class.vmtmethodoffset(tprocdef(proc.procdef).extnumber)));
  4115. typvalue:=2;
  4116. end;
  4117. end;
  4118. proctypesinfo:=proctypesinfo or (typvalue shl shiftvalue);
  4119. end;
  4120. begin
  4121. if (tsym(sym).typ=propertysym) and
  4122. (sp_published in tsym(sym).symoptions) then
  4123. begin
  4124. if ppo_indexed in tpropertysym(sym).propoptions then
  4125. proctypesinfo:=$40
  4126. else
  4127. proctypesinfo:=0;
  4128. asmlist[al_rtti].concat(Tai_const.Create_sym(tstoreddef(tpropertysym(sym).proptype.def).get_rtti_label(fullrtti)));
  4129. writeproc(tpropertysym(sym).readaccess,0);
  4130. writeproc(tpropertysym(sym).writeaccess,2);
  4131. { isn't it stored ? }
  4132. if not(ppo_stored in tpropertysym(sym).propoptions) then
  4133. begin
  4134. asmlist[al_rtti].concat(Tai_const.create_sym(nil));
  4135. proctypesinfo:=proctypesinfo or (3 shl 4);
  4136. end
  4137. else
  4138. writeproc(tpropertysym(sym).storedaccess,4);
  4139. asmlist[al_rtti].concat(Tai_const.Create_32bit(tpropertysym(sym).index));
  4140. asmlist[al_rtti].concat(Tai_const.Create_32bit(tpropertysym(sym).default));
  4141. propnameitem:=searchpropnamelist(tpropertysym(sym).name);
  4142. if not assigned(propnameitem) then
  4143. internalerror(200512201);
  4144. asmlist[al_rtti].concat(Tai_const.Create_16bit(propnameitem.index));
  4145. asmlist[al_rtti].concat(Tai_const.Create_8bit(proctypesinfo));
  4146. asmlist[al_rtti].concat(Tai_const.Create_8bit(length(tpropertysym(sym).realname)));
  4147. asmlist[al_rtti].concat(Tai_string.Create(tpropertysym(sym).realname));
  4148. {$ifdef cpurequiresproperalignment}
  4149. asmlist[al_rtti].concat(Tai_align.Create(sizeof(TConstPtrUInt)));
  4150. {$endif cpurequiresproperalignment}
  4151. end;
  4152. end;
  4153. procedure tobjectdef.generate_published_child_rtti(sym : tnamedindexitem;arg:pointer);
  4154. begin
  4155. if needs_prop_entry(tsym(sym)) then
  4156. begin
  4157. case tsym(sym).typ of
  4158. propertysym:
  4159. tstoreddef(tpropertysym(sym).proptype.def).get_rtti_label(fullrtti);
  4160. fieldvarsym:
  4161. tstoreddef(tfieldvarsym(sym).vartype.def).get_rtti_label(fullrtti);
  4162. else
  4163. internalerror(1509991);
  4164. end;
  4165. end;
  4166. end;
  4167. procedure tobjectdef.write_child_rtti_data(rt:trttitype);
  4168. begin
  4169. FRTTIType:=rt;
  4170. case rt of
  4171. initrtti :
  4172. symtable.foreach(@generate_field_rtti,nil);
  4173. fullrtti :
  4174. symtable.foreach(@generate_published_child_rtti,nil);
  4175. else
  4176. internalerror(200108301);
  4177. end;
  4178. end;
  4179. procedure tobjectdef.count_published_fields(sym:tnamedindexitem;arg:pointer);
  4180. var
  4181. hp : tproptablelistitem;
  4182. begin
  4183. if (tsym(sym).typ=fieldvarsym) and
  4184. (sp_published in tsym(sym).symoptions) then
  4185. begin
  4186. if tfieldvarsym(sym).vartype.def.deftype<>objectdef then
  4187. internalerror(0206001);
  4188. hp:=searchproptablelist(tobjectdef(tfieldvarsym(sym).vartype.def));
  4189. if not(assigned(hp)) then
  4190. begin
  4191. hp:=tproptablelistitem.create;
  4192. hp.def:=tobjectdef(tfieldvarsym(sym).vartype.def);
  4193. hp.index:=proptablelist.count+1;
  4194. proptablelist.concat(hp);
  4195. end;
  4196. inc(plongint(arg)^);
  4197. end;
  4198. end;
  4199. procedure tobjectdef.writefields(sym:tnamedindexitem;arg:pointer);
  4200. var
  4201. hp : tproptablelistitem;
  4202. begin
  4203. if needs_prop_entry(tsym(sym)) and
  4204. (tsym(sym).typ=fieldvarsym) then
  4205. begin
  4206. {$ifdef cpurequiresproperalignment}
  4207. asmlist[al_rtti].concat(Tai_align.Create(sizeof(AInt)));
  4208. {$endif cpurequiresproperalignment}
  4209. asmlist[al_rtti].concat(Tai_const.Create_aint(tfieldvarsym(sym).fieldoffset));
  4210. hp:=searchproptablelist(tobjectdef(tfieldvarsym(sym).vartype.def));
  4211. if not(assigned(hp)) then
  4212. internalerror(0206002);
  4213. asmlist[al_rtti].concat(Tai_const.Create_16bit(hp.index));
  4214. asmlist[al_rtti].concat(Tai_const.Create_8bit(length(tfieldvarsym(sym).realname)));
  4215. asmlist[al_rtti].concat(Tai_string.Create(tfieldvarsym(sym).realname));
  4216. end;
  4217. end;
  4218. function tobjectdef.generate_field_table : tasmlabel;
  4219. var
  4220. fieldtable,
  4221. classtable : tasmlabel;
  4222. hp : tproptablelistitem;
  4223. fieldcount : longint;
  4224. begin
  4225. proptablelist:=TLinkedList.Create;
  4226. objectlibrary.getdatalabel(fieldtable);
  4227. objectlibrary.getdatalabel(classtable);
  4228. maybe_new_object_file(asmlist[al_rtti]);
  4229. new_section(asmlist[al_rtti],sec_rodata,classtable.name,const_align(sizeof(aint)));
  4230. { fields }
  4231. fieldcount:=0;
  4232. symtable.foreach(@count_published_fields,@fieldcount);
  4233. asmlist[al_rtti].concat(Tai_label.Create(fieldtable));
  4234. asmlist[al_rtti].concat(Tai_const.Create_16bit(fieldcount));
  4235. {$ifdef cpurequiresproperalignment}
  4236. asmlist[al_rtti].concat(Tai_align.Create(sizeof(TConstPtrUInt)));
  4237. {$endif cpurequiresproperalignment}
  4238. asmlist[al_rtti].concat(Tai_const.Create_sym(classtable));
  4239. symtable.foreach(@writefields,nil);
  4240. { generate the class table }
  4241. asmlist[al_rtti].concat(tai_align.create(const_align(sizeof(aint))));
  4242. asmlist[al_rtti].concat(Tai_label.Create(classtable));
  4243. asmlist[al_rtti].concat(Tai_const.Create_16bit(proptablelist.count));
  4244. {$ifdef cpurequiresproperalignment}
  4245. asmlist[al_rtti].concat(Tai_align.Create(sizeof(TConstPtrUInt)));
  4246. {$endif cpurequiresproperalignment}
  4247. hp:=tproptablelistitem(proptablelist.first);
  4248. while assigned(hp) do
  4249. begin
  4250. asmlist[al_rtti].concat(Tai_const.Createname(tobjectdef(hp.def).vmt_mangledname,AT_DATA,0));
  4251. hp:=tproptablelistitem(hp.next);
  4252. end;
  4253. generate_field_table:=fieldtable;
  4254. proptablelist.free;
  4255. proptablelist:=nil;
  4256. end;
  4257. procedure tobjectdef.write_rtti_data(rt:trttitype);
  4258. procedure collect_unique_published_props(pd:tobjectdef);
  4259. begin
  4260. if assigned(pd.childof) then
  4261. collect_unique_published_props(pd.childof);
  4262. pd.symtable.foreach(@collect_published_properties,nil);
  4263. end;
  4264. var
  4265. i : longint;
  4266. propcount : longint;
  4267. begin
  4268. case objecttype of
  4269. odt_class:
  4270. asmlist[al_rtti].concat(Tai_const.Create_8bit(tkclass));
  4271. odt_object:
  4272. asmlist[al_rtti].concat(Tai_const.Create_8bit(tkobject));
  4273. odt_interfacecom:
  4274. asmlist[al_rtti].concat(Tai_const.Create_8bit(tkinterface));
  4275. odt_interfacecorba:
  4276. asmlist[al_rtti].concat(Tai_const.Create_8bit(tkinterfaceCorba));
  4277. else
  4278. exit;
  4279. end;
  4280. { generate the name }
  4281. asmlist[al_rtti].concat(Tai_const.Create_8bit(length(objrealname^)));
  4282. asmlist[al_rtti].concat(Tai_string.Create(objrealname^));
  4283. {$ifdef cpurequiresproperalignment}
  4284. asmlist[al_rtti].concat(Tai_align.Create(sizeof(TConstPtrUInt)));
  4285. {$endif cpurequiresproperalignment}
  4286. case rt of
  4287. initrtti :
  4288. begin
  4289. asmlist[al_rtti].concat(Tai_const.Create_32bit(size));
  4290. if objecttype in [odt_class,odt_object] then
  4291. begin
  4292. count:=0;
  4293. FRTTIType:=rt;
  4294. symtable.foreach(@count_field_rtti,nil);
  4295. asmlist[al_rtti].concat(Tai_const.Create_32bit(count));
  4296. symtable.foreach(@write_field_rtti,nil);
  4297. end;
  4298. end;
  4299. fullrtti :
  4300. begin
  4301. { Collect unique property names with nameindex }
  4302. propnamelist:=TLinkedList.Create;
  4303. collect_unique_published_props(self);
  4304. if not(objecttype in [odt_interfacecom,odt_interfacecorba]) then
  4305. begin
  4306. if (oo_has_vmt in objectoptions) then
  4307. asmlist[al_rtti].concat(Tai_const.Createname(vmt_mangledname,AT_DATA,0))
  4308. else
  4309. asmlist[al_rtti].concat(Tai_const.create_sym(nil));
  4310. end;
  4311. { write parent typeinfo }
  4312. if assigned(childof) and ((oo_can_have_published in childof.objectoptions) or
  4313. (objecttype in [odt_interfacecom,odt_interfacecorba])) then
  4314. asmlist[al_rtti].concat(Tai_const.Create_sym(childof.get_rtti_label(fullrtti)))
  4315. else
  4316. asmlist[al_rtti].concat(Tai_const.create_sym(nil));
  4317. if objecttype in [odt_object,odt_class] then
  4318. begin
  4319. { total number of unique properties }
  4320. asmlist[al_rtti].concat(Tai_const.Create_16bit(propnamelist.count));
  4321. end
  4322. else
  4323. { interface: write flags, iid and iidstr }
  4324. begin
  4325. asmlist[al_rtti].concat(Tai_const.Create_32bit(
  4326. { ugly, but working }
  4327. longint([
  4328. TCompilerIntfFlag(ord(ifHasGuid)*ord(assigned(iidguid))),
  4329. TCompilerIntfFlag(ord(ifHasStrGUID)*ord(assigned(iidstr)))
  4330. ])
  4331. {
  4332. ifDispInterface,
  4333. ifDispatch, }
  4334. ));
  4335. {$ifdef cpurequiresproperalignment}
  4336. asmlist[al_rtti].concat(Tai_align.Create(sizeof(TConstPtrUInt)));
  4337. {$endif cpurequiresproperalignment}
  4338. asmlist[al_rtti].concat(Tai_const.Create_32bit(longint(iidguid^.D1)));
  4339. asmlist[al_rtti].concat(Tai_const.Create_16bit(iidguid^.D2));
  4340. asmlist[al_rtti].concat(Tai_const.Create_16bit(iidguid^.D3));
  4341. for i:=Low(iidguid^.D4) to High(iidguid^.D4) do
  4342. asmlist[al_rtti].concat(Tai_const.Create_8bit(iidguid^.D4[i]));
  4343. end;
  4344. { write unit name }
  4345. asmlist[al_rtti].concat(Tai_const.Create_8bit(length(current_module.realmodulename^)));
  4346. asmlist[al_rtti].concat(Tai_string.Create(current_module.realmodulename^));
  4347. {$ifdef cpurequiresproperalignment}
  4348. asmlist[al_rtti].concat(Tai_align.Create(sizeof(TConstPtrUInt)));
  4349. {$endif cpurequiresproperalignment}
  4350. { write iidstr }
  4351. if objecttype in [odt_interfacecom,odt_interfacecorba] then
  4352. begin
  4353. if assigned(iidstr) then
  4354. begin
  4355. asmlist[al_rtti].concat(Tai_const.Create_8bit(length(iidstr^)));
  4356. asmlist[al_rtti].concat(Tai_string.Create(iidstr^));
  4357. end
  4358. else
  4359. asmlist[al_rtti].concat(Tai_const.Create_8bit(0));
  4360. {$ifdef cpurequiresproperalignment}
  4361. asmlist[al_rtti].concat(Tai_align.Create(sizeof(TConstPtrUInt)));
  4362. {$endif cpurequiresproperalignment}
  4363. end;
  4364. { write published properties for this object }
  4365. if objecttype in [odt_object,odt_class] then
  4366. begin
  4367. propcount:=0;
  4368. symtable.foreach(@count_published_properties,@propcount);
  4369. asmlist[al_rtti].concat(Tai_const.Create_16bit(propcount));
  4370. {$ifdef cpurequiresproperalignment}
  4371. asmlist[al_rtti].concat(Tai_align.Create(sizeof(TConstPtrUInt)));
  4372. {$endif cpurequiresproperalignment}
  4373. end;
  4374. symtable.foreach(@write_property_info,nil);
  4375. propnamelist.free;
  4376. propnamelist:=nil;
  4377. end;
  4378. end;
  4379. end;
  4380. function tobjectdef.is_publishable : boolean;
  4381. begin
  4382. is_publishable:=objecttype in [odt_class,odt_interfacecom,odt_interfacecorba];
  4383. end;
  4384. {****************************************************************************
  4385. TIMPLEMENTEDINTERFACES
  4386. ****************************************************************************}
  4387. type
  4388. tnamemap = class(TNamedIndexItem)
  4389. newname: pstring;
  4390. constructor create(const aname, anewname: string);
  4391. destructor destroy; override;
  4392. end;
  4393. constructor tnamemap.create(const aname, anewname: string);
  4394. begin
  4395. inherited createname(aname);
  4396. newname:=stringdup(anewname);
  4397. end;
  4398. destructor tnamemap.destroy;
  4399. begin
  4400. stringdispose(newname);
  4401. inherited destroy;
  4402. end;
  4403. type
  4404. tprocdefstore = class(TNamedIndexItem)
  4405. procdef: tprocdef;
  4406. constructor create(aprocdef: tprocdef);
  4407. end;
  4408. constructor tprocdefstore.create(aprocdef: tprocdef);
  4409. begin
  4410. inherited create;
  4411. procdef:=aprocdef;
  4412. end;
  4413. constructor timplintfentry.create(aintf: tobjectdef);
  4414. begin
  4415. inherited create;
  4416. intf:=aintf;
  4417. ioffset:=-1;
  4418. namemappings:=nil;
  4419. procdefs:=nil;
  4420. end;
  4421. constructor timplintfentry.create_deref(const d:tderef);
  4422. begin
  4423. inherited create;
  4424. intf:=nil;
  4425. intfderef:=d;
  4426. ioffset:=-1;
  4427. namemappings:=nil;
  4428. procdefs:=nil;
  4429. end;
  4430. destructor timplintfentry.destroy;
  4431. begin
  4432. if assigned(namemappings) then
  4433. namemappings.free;
  4434. if assigned(procdefs) then
  4435. procdefs.free;
  4436. inherited destroy;
  4437. end;
  4438. constructor timplementedinterfaces.create;
  4439. begin
  4440. finterfaces:=tindexarray.create(1);
  4441. end;
  4442. destructor timplementedinterfaces.destroy;
  4443. begin
  4444. finterfaces.destroy;
  4445. end;
  4446. function timplementedinterfaces.count: longint;
  4447. begin
  4448. count:=finterfaces.count;
  4449. end;
  4450. procedure timplementedinterfaces.checkindex(intfindex: longint);
  4451. begin
  4452. if (intfindex<1) or (intfindex>count) then
  4453. InternalError(200006123);
  4454. end;
  4455. function timplementedinterfaces.interfaces(intfindex: longint): tobjectdef;
  4456. begin
  4457. checkindex(intfindex);
  4458. interfaces:=timplintfentry(finterfaces.search(intfindex)).intf;
  4459. end;
  4460. function timplementedinterfaces.interfacesderef(intfindex: longint): tderef;
  4461. begin
  4462. checkindex(intfindex);
  4463. interfacesderef:=timplintfentry(finterfaces.search(intfindex)).intfderef;
  4464. end;
  4465. function timplementedinterfaces.ioffsets(intfindex: longint): longint;
  4466. begin
  4467. checkindex(intfindex);
  4468. ioffsets:=timplintfentry(finterfaces.search(intfindex)).ioffset;
  4469. end;
  4470. procedure timplementedinterfaces.setioffsets(intfindex,iofs:longint);
  4471. begin
  4472. checkindex(intfindex);
  4473. timplintfentry(finterfaces.search(intfindex)).ioffset:=iofs;
  4474. end;
  4475. function timplementedinterfaces.implindex(intfindex:longint):longint;
  4476. begin
  4477. checkindex(intfindex);
  4478. result:=timplintfentry(finterfaces.search(intfindex)).implindex;
  4479. end;
  4480. procedure timplementedinterfaces.setimplindex(intfindex,implidx:longint);
  4481. begin
  4482. checkindex(intfindex);
  4483. timplintfentry(finterfaces.search(intfindex)).implindex:=implidx;
  4484. end;
  4485. function timplementedinterfaces.searchintf(def: tdef): longint;
  4486. var
  4487. i: longint;
  4488. begin
  4489. i:=1;
  4490. while (i<=count) and (tdef(interfaces(i))<>def) do inc(i);
  4491. if i<=count then
  4492. searchintf:=i
  4493. else
  4494. searchintf:=-1;
  4495. end;
  4496. procedure timplementedinterfaces.buildderef;
  4497. var
  4498. i: longint;
  4499. begin
  4500. for i:=1 to count do
  4501. with timplintfentry(finterfaces.search(i)) do
  4502. intfderef.build(intf);
  4503. end;
  4504. procedure timplementedinterfaces.deref;
  4505. var
  4506. i: longint;
  4507. begin
  4508. for i:=1 to count do
  4509. with timplintfentry(finterfaces.search(i)) do
  4510. intf:=tobjectdef(intfderef.resolve);
  4511. end;
  4512. procedure timplementedinterfaces.addintf_deref(const d:tderef;iofs:longint);
  4513. var
  4514. hintf : timplintfentry;
  4515. begin
  4516. hintf:=timplintfentry.create_deref(d);
  4517. hintf.ioffset:=iofs;
  4518. finterfaces.insert(hintf);
  4519. end;
  4520. procedure timplementedinterfaces.addintf_ioffset(d:tdef;iofs:longint);
  4521. var
  4522. hintf : timplintfentry;
  4523. begin
  4524. hintf:=timplintfentry.create(tobjectdef(d));
  4525. hintf.ioffset:=iofs;
  4526. finterfaces.insert(hintf);
  4527. end;
  4528. procedure timplementedinterfaces.addintf(def: tdef);
  4529. begin
  4530. if not assigned(def) or (searchintf(def)<>-1) or (def.deftype<>objectdef) or
  4531. not (tobjectdef(def).objecttype in [odt_interfacecom,odt_interfacecorba]) then
  4532. internalerror(200006124);
  4533. finterfaces.insert(timplintfentry.create(tobjectdef(def)));
  4534. end;
  4535. procedure timplementedinterfaces.clearmappings;
  4536. var
  4537. i: longint;
  4538. begin
  4539. for i:=1 to count do
  4540. with timplintfentry(finterfaces.search(i)) do
  4541. begin
  4542. if assigned(namemappings) then
  4543. namemappings.free;
  4544. namemappings:=nil;
  4545. end;
  4546. end;
  4547. procedure timplementedinterfaces.addmappings(intfindex: longint; const origname, newname: string);
  4548. begin
  4549. checkindex(intfindex);
  4550. with timplintfentry(finterfaces.search(intfindex)) do
  4551. begin
  4552. if not assigned(namemappings) then
  4553. namemappings:=tdictionary.create;
  4554. namemappings.insert(tnamemap.create(origname,newname));
  4555. end;
  4556. end;
  4557. function timplementedinterfaces.getmappings(intfindex: longint; const origname: string; var nextexist: pointer): string;
  4558. begin
  4559. checkindex(intfindex);
  4560. if not assigned(nextexist) then
  4561. with timplintfentry(finterfaces.search(intfindex)) do
  4562. begin
  4563. if assigned(namemappings) then
  4564. nextexist:=namemappings.search(origname)
  4565. else
  4566. nextexist:=nil;
  4567. end;
  4568. if assigned(nextexist) then
  4569. begin
  4570. getmappings:=tnamemap(nextexist).newname^;
  4571. nextexist:=tnamemap(nextexist).listnext;
  4572. end
  4573. else
  4574. getmappings:='';
  4575. end;
  4576. procedure timplementedinterfaces.addimplproc(intfindex: longint; procdef: tprocdef);
  4577. var
  4578. found : boolean;
  4579. i : longint;
  4580. begin
  4581. checkindex(intfindex);
  4582. with timplintfentry(finterfaces.search(intfindex)) do
  4583. begin
  4584. if not assigned(procdefs) then
  4585. procdefs:=tindexarray.create(4);
  4586. { No duplicate entries of the same procdef }
  4587. found:=false;
  4588. for i:=1 to procdefs.count do
  4589. if tprocdefstore(procdefs.search(i)).procdef=procdef then
  4590. begin
  4591. found:=true;
  4592. break;
  4593. end;
  4594. if not found then
  4595. procdefs.insert(tprocdefstore.create(procdef));
  4596. end;
  4597. end;
  4598. function timplementedinterfaces.implproccount(intfindex: longint): longint;
  4599. begin
  4600. checkindex(intfindex);
  4601. with timplintfentry(finterfaces.search(intfindex)) do
  4602. if assigned(procdefs) then
  4603. implproccount:=procdefs.count
  4604. else
  4605. implproccount:=0;
  4606. end;
  4607. function timplementedinterfaces.implprocs(intfindex: longint; procindex: longint): tprocdef;
  4608. begin
  4609. checkindex(intfindex);
  4610. with timplintfentry(finterfaces.search(intfindex)) do
  4611. if assigned(procdefs) then
  4612. implprocs:=tprocdefstore(procdefs.search(procindex)).procdef
  4613. else
  4614. internalerror(200006131);
  4615. end;
  4616. function timplementedinterfaces.isimplmergepossible(intfindex, remainindex: longint; var weight: longint): boolean;
  4617. var
  4618. possible: boolean;
  4619. i: longint;
  4620. iiep1: TIndexArray;
  4621. iiep2: TIndexArray;
  4622. begin
  4623. checkindex(intfindex);
  4624. checkindex(remainindex);
  4625. iiep1:=timplintfentry(finterfaces.search(intfindex)).procdefs;
  4626. iiep2:=timplintfentry(finterfaces.search(remainindex)).procdefs;
  4627. if not assigned(iiep1) then { empty interface is mergeable :-) }
  4628. begin
  4629. possible:=true;
  4630. weight:=0;
  4631. end
  4632. else
  4633. begin
  4634. possible:=assigned(iiep2) and (iiep1.count<=iiep2.count);
  4635. i:=1;
  4636. while (possible) and (i<=iiep1.count) do
  4637. begin
  4638. possible:=
  4639. (tprocdefstore(iiep1.search(i)).procdef=tprocdefstore(iiep2.search(i)).procdef);
  4640. inc(i);
  4641. end;
  4642. if possible then
  4643. weight:=iiep1.count;
  4644. end;
  4645. isimplmergepossible:=possible;
  4646. end;
  4647. {****************************************************************************
  4648. TFORWARDDEF
  4649. ****************************************************************************}
  4650. constructor tforwarddef.create(const s:string;const pos : tfileposinfo);
  4651. var
  4652. oldregisterdef : boolean;
  4653. begin
  4654. { never register the forwarddefs, they are disposed at the
  4655. end of the type declaration block }
  4656. oldregisterdef:=registerdef;
  4657. registerdef:=false;
  4658. inherited create;
  4659. registerdef:=oldregisterdef;
  4660. deftype:=forwarddef;
  4661. tosymname:=stringdup(s);
  4662. forwardpos:=pos;
  4663. end;
  4664. function tforwarddef.gettypename:string;
  4665. begin
  4666. gettypename:='unresolved forward to '+tosymname^;
  4667. end;
  4668. destructor tforwarddef.destroy;
  4669. begin
  4670. if assigned(tosymname) then
  4671. stringdispose(tosymname);
  4672. inherited destroy;
  4673. end;
  4674. {****************************************************************************
  4675. TUNDEFINEDDEF
  4676. ****************************************************************************}
  4677. constructor tundefineddef.create;
  4678. begin
  4679. inherited create;
  4680. deftype:=undefineddef;
  4681. end;
  4682. constructor tundefineddef.ppuload(ppufile:tcompilerppufile);
  4683. begin
  4684. inherited ppuloaddef(ppufile);
  4685. deftype:=undefineddef;
  4686. end;
  4687. function tundefineddef.gettypename:string;
  4688. begin
  4689. gettypename:='<undefined type>';
  4690. end;
  4691. procedure tundefineddef.ppuwrite(ppufile:tcompilerppufile);
  4692. begin
  4693. inherited ppuwritedef(ppufile);
  4694. ppufile.writeentry(ibundefineddef);
  4695. end;
  4696. {****************************************************************************
  4697. TERRORDEF
  4698. ****************************************************************************}
  4699. constructor terrordef.create;
  4700. begin
  4701. inherited create;
  4702. deftype:=errordef;
  4703. end;
  4704. procedure terrordef.ppuwrite(ppufile:tcompilerppufile);
  4705. begin
  4706. { Can't write errordefs to ppu }
  4707. internalerror(200411063);
  4708. end;
  4709. function terrordef.gettypename:string;
  4710. begin
  4711. gettypename:='<erroneous type>';
  4712. end;
  4713. function terrordef.getmangledparaname:string;
  4714. begin
  4715. getmangledparaname:='error';
  4716. end;
  4717. {****************************************************************************
  4718. Definition Helpers
  4719. ****************************************************************************}
  4720. function is_interfacecom(def: tdef): boolean;
  4721. begin
  4722. is_interfacecom:=
  4723. assigned(def) and
  4724. (def.deftype=objectdef) and
  4725. (tobjectdef(def).objecttype=odt_interfacecom);
  4726. end;
  4727. function is_interfacecorba(def: tdef): boolean;
  4728. begin
  4729. is_interfacecorba:=
  4730. assigned(def) and
  4731. (def.deftype=objectdef) and
  4732. (tobjectdef(def).objecttype=odt_interfacecorba);
  4733. end;
  4734. function is_interface(def: tdef): boolean;
  4735. begin
  4736. is_interface:=
  4737. assigned(def) and
  4738. (def.deftype=objectdef) and
  4739. (tobjectdef(def).objecttype in [odt_interfacecom,odt_interfacecorba]);
  4740. end;
  4741. function is_class(def: tdef): boolean;
  4742. begin
  4743. is_class:=
  4744. assigned(def) and
  4745. (def.deftype=objectdef) and
  4746. (tobjectdef(def).objecttype=odt_class);
  4747. end;
  4748. function is_object(def: tdef): boolean;
  4749. begin
  4750. is_object:=
  4751. assigned(def) and
  4752. (def.deftype=objectdef) and
  4753. (tobjectdef(def).objecttype=odt_object);
  4754. end;
  4755. function is_cppclass(def: tdef): boolean;
  4756. begin
  4757. is_cppclass:=
  4758. assigned(def) and
  4759. (def.deftype=objectdef) and
  4760. (tobjectdef(def).objecttype=odt_cppclass);
  4761. end;
  4762. function is_class_or_interface(def: tdef): boolean;
  4763. begin
  4764. is_class_or_interface:=
  4765. assigned(def) and
  4766. (def.deftype=objectdef) and
  4767. (tobjectdef(def).objecttype in [odt_class,odt_interfacecom,odt_interfacecorba]);
  4768. end;
  4769. {$ifdef x86}
  4770. function use_sse(def : tdef) : boolean;
  4771. begin
  4772. use_sse:=(is_single(def) and (aktfputype in sse_singlescalar)) or
  4773. (is_double(def) and (aktfputype in sse_doublescalar));
  4774. end;
  4775. {$endif x86}
  4776. end.