symdef.pas 166 KB

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