symdef.pas 167 KB

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