symdef.pas 171 KB

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