symdef.pas 165 KB

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