symdef.pas 163 KB

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