symdef.pas 129 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392
  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. procedure reset;override;
  153. function GetSymtable(t:tGetSymtable):TSymtable;override;
  154. function is_packed:boolean;
  155. end;
  156. trecorddef = class(tabstractrecorddef)
  157. public
  158. isunion : boolean;
  159. constructor create(p : TSymtable);
  160. constructor ppuload(ppufile:tcompilerppufile);
  161. destructor destroy;override;
  162. function getcopy : tstoreddef;override;
  163. procedure ppuwrite(ppufile:tcompilerppufile);override;
  164. procedure buildderef;override;
  165. procedure deref;override;
  166. function size:aint;override;
  167. function alignment : shortint;override;
  168. function padalignment: shortint;
  169. function GetTypeName:string;override;
  170. { debug }
  171. function needs_inittable : boolean;override;
  172. end;
  173. tprocdef = class;
  174. tobjectdef = class;
  175. { TImplementedInterface }
  176. TImplementedInterface = class
  177. IntfDef : tobjectdef;
  178. IntfDefDeref : tderef;
  179. IType : tinterfaceentrytype;
  180. IOffset : longint;
  181. VtblImplIntf : TImplementedInterface;
  182. NameMappings : TFPHashList;
  183. ProcDefs : TFPObjectList;
  184. // FieldOffset can be merged with IOffset. But then, fpc is not allowed to genrate a vmtentry.
  185. // Right now, fpc generate an entry for all implemented interfaces (but it should just for etStandard ones)
  186. // - Ivo Steinmann
  187. FieldOffset : longint;
  188. constructor create(aintf: tobjectdef);
  189. constructor create_deref(d:tderef);
  190. destructor destroy; override;
  191. function getcopy:TImplementedInterface;
  192. procedure buildderef;
  193. procedure deref;
  194. procedure AddMapping(const origname, newname: string);
  195. function GetMapping(const origname: string):string;
  196. procedure AddImplProc(pd:tprocdef);
  197. function IsImplMergePossible(MergingIntf:TImplementedInterface;out weight: longint): boolean;
  198. end;
  199. { tobjectdef }
  200. tobjectdef = class(tabstractrecorddef)
  201. public
  202. dwarf_struct_lab : tasmsymbol;
  203. childof : tobjectdef;
  204. childofderef : tderef;
  205. objname,
  206. objrealname : pshortstring;
  207. objectoptions : tobjectoptions;
  208. { to be able to have a variable vmt position }
  209. { and no vmt field for objects without virtuals }
  210. vmtentries : TFPObjectList;
  211. vmt_offset : longint;
  212. writing_class_record_dbginfo : boolean;
  213. objecttype : tobjecttyp;
  214. iidguid : pguid;
  215. iidstr : pshortstring;
  216. { store implemented interfaces defs and name mappings }
  217. ImplementedInterfaces : TFPObjectList;
  218. constructor create(ot : tobjecttyp;const n : string;c : tobjectdef);
  219. constructor ppuload(ppufile:tcompilerppufile);
  220. destructor destroy;override;
  221. function getcopy : tstoreddef;override;
  222. procedure ppuwrite(ppufile:tcompilerppufile);override;
  223. function GetTypeName:string;override;
  224. procedure buildderef;override;
  225. procedure deref;override;
  226. function getparentdef:tdef;override;
  227. function size : aint;override;
  228. function alignment:shortint;override;
  229. function vmtmethodoffset(index:longint):longint;
  230. function members_need_inittable : boolean;
  231. function find_implemented_interface(aintfdef:tobjectdef):TImplementedInterface;
  232. { this should be called when this class implements an interface }
  233. procedure prepareguid;
  234. function is_publishable : boolean;override;
  235. function needs_inittable : boolean;override;
  236. function vmt_mangledname : string;
  237. procedure check_forwards;
  238. function is_related(d : tdef) : boolean;override;
  239. procedure insertvmt;
  240. procedure set_parent(c : tobjectdef);
  241. function FindDestructor : tprocdef;
  242. end;
  243. tclassrefdef = class(tabstractpointerdef)
  244. constructor create(def:tdef);
  245. constructor ppuload(ppufile:tcompilerppufile);
  246. procedure ppuwrite(ppufile:tcompilerppufile);override;
  247. function GetTypeName:string;override;
  248. function is_publishable : boolean;override;
  249. end;
  250. tarraydef = class(tstoreddef)
  251. lowrange,
  252. highrange : aint;
  253. rangedef : tdef;
  254. rangedefderef : tderef;
  255. arrayoptions : tarraydefoptions;
  256. protected
  257. _elementdef : tdef;
  258. _elementdefderef : tderef;
  259. procedure setelementdef(def:tdef);
  260. public
  261. function elesize : aint;
  262. function elepackedbitsize : aint;
  263. function elecount : aword;
  264. constructor create_from_pointer(def:tdef);
  265. constructor create(l,h : aint;def:tdef);
  266. constructor ppuload(ppufile:tcompilerppufile);
  267. function getcopy : tstoreddef;override;
  268. procedure ppuwrite(ppufile:tcompilerppufile);override;
  269. function GetTypeName:string;override;
  270. function getmangledparaname : string;override;
  271. procedure buildderef;override;
  272. procedure deref;override;
  273. function size : aint;override;
  274. function alignment : shortint;override;
  275. { returns the label of the range check string }
  276. function needs_inittable : boolean;override;
  277. property elementdef : tdef read _elementdef write setelementdef;
  278. end;
  279. torddef = class(tstoreddef)
  280. low,high : TConstExprInt;
  281. ordtype : tordtype;
  282. constructor create(t : tordtype;v,b : TConstExprInt);
  283. constructor ppuload(ppufile:tcompilerppufile);
  284. function getcopy : tstoreddef;override;
  285. procedure ppuwrite(ppufile:tcompilerppufile);override;
  286. function is_publishable : boolean;override;
  287. function GetTypeName:string;override;
  288. function alignment:shortint;override;
  289. procedure setsize;
  290. function packedbitsize: aint; override;
  291. function getvardef : longint;override;
  292. end;
  293. tfloatdef = class(tstoreddef)
  294. floattype : tfloattype;
  295. constructor create(t : tfloattype);
  296. constructor ppuload(ppufile:tcompilerppufile);
  297. function getcopy : tstoreddef;override;
  298. procedure ppuwrite(ppufile:tcompilerppufile);override;
  299. function GetTypeName:string;override;
  300. function is_publishable : boolean;override;
  301. function alignment:shortint;override;
  302. procedure setsize;
  303. function getvardef:longint;override;
  304. end;
  305. tabstractprocdef = class(tstoreddef)
  306. { saves a definition to the return type }
  307. returndef : tdef;
  308. returndefderef : tderef;
  309. parast : TSymtable;
  310. paras : tparalist;
  311. proctypeoption : tproctypeoption;
  312. proccalloption : tproccalloption;
  313. procoptions : tprocoptions;
  314. requiredargarea : aint;
  315. { number of user visibile parameters }
  316. maxparacount,
  317. minparacount : byte;
  318. {$ifdef i386}
  319. fpu_used : longint; { how many stack fpu must be empty }
  320. {$endif i386}
  321. {$ifdef m68k}
  322. exp_funcretloc : tregister; { explicit funcretloc for AmigaOS }
  323. {$endif}
  324. funcretloc : array[tcallercallee] of TLocation;
  325. has_paraloc_info : boolean; { paraloc info is available }
  326. constructor create(dt:tdeftyp;level:byte);
  327. constructor ppuload(dt:tdeftyp;ppufile:tcompilerppufile);
  328. destructor destroy;override;
  329. procedure ppuwrite(ppufile:tcompilerppufile);override;
  330. procedure buildderef;override;
  331. procedure deref;override;
  332. procedure calcparas;
  333. function typename_paras(showhidden:boolean): string;
  334. procedure test_if_fpu_result;
  335. function is_methodpointer:boolean;virtual;
  336. function is_addressonly:boolean;virtual;
  337. private
  338. procedure count_para(p:TObject;arg:pointer);
  339. procedure insert_para(p:TObject;arg:pointer);
  340. end;
  341. tprocvardef = class(tabstractprocdef)
  342. constructor create(level:byte);
  343. constructor ppuload(ppufile:tcompilerppufile);
  344. function getcopy : tstoreddef;override;
  345. procedure ppuwrite(ppufile:tcompilerppufile);override;
  346. function GetSymtable(t:tGetSymtable):TSymtable;override;
  347. function size : aint;override;
  348. function GetTypeName:string;override;
  349. function is_publishable : boolean;override;
  350. function is_methodpointer:boolean;override;
  351. function is_addressonly:boolean;override;
  352. function getmangledparaname:string;override;
  353. end;
  354. tmessageinf = record
  355. case integer of
  356. 0 : (str : pshortstring);
  357. 1 : (i : longint);
  358. end;
  359. tinlininginfo = record
  360. { node tree }
  361. code : tnode;
  362. flags : tprocinfoflags;
  363. end;
  364. pinlininginfo = ^tinlininginfo;
  365. {$ifdef oldregvars}
  366. { register variables }
  367. pregvarinfo = ^tregvarinfo;
  368. tregvarinfo = record
  369. regvars : array[1..maxvarregs] of tsym;
  370. regvars_para : array[1..maxvarregs] of boolean;
  371. regvars_refs : array[1..maxvarregs] of longint;
  372. fpuregvars : array[1..maxfpuvarregs] of tsym;
  373. fpuregvars_para : array[1..maxfpuvarregs] of boolean;
  374. fpuregvars_refs : array[1..maxfpuvarregs] of longint;
  375. end;
  376. {$endif oldregvars}
  377. tprocdef = class(tabstractprocdef)
  378. private
  379. _mangledname : pshortstring;
  380. public
  381. messageinf : tmessageinf;
  382. dispid : longint;
  383. extnumber : word;
  384. {$ifndef EXTDEBUG}
  385. { where is this function defined and what were the symbol
  386. flags, needed here because there
  387. is only one symbol for all overloaded functions
  388. EXTDEBUG has fileinfo in tdef (PFV) }
  389. fileinfo : tfileposinfo;
  390. {$endif}
  391. symoptions : tsymoptions;
  392. { symbol owning this definition }
  393. procsym : tsym;
  394. procsymderef : tderef;
  395. { alias names }
  396. aliasnames : TCmdStrList;
  397. { symtables }
  398. localst : TSymtable;
  399. funcretsym : tsym;
  400. funcretsymderef : tderef;
  401. _class : tobjectdef;
  402. _classderef : tderef;
  403. {$if defined(powerpc) or defined(m68k)}
  404. { library symbol for AmigaOS/MorphOS }
  405. libsym : tsym;
  406. libsymderef : tderef;
  407. {$endif powerpc or m68k}
  408. { name of the result variable to insert in the localsymtable }
  409. resultname : pshortstring;
  410. { true, if the procedure is only declared
  411. (forward procedure) }
  412. forwarddef,
  413. { true if the procedure is declared in the interface }
  414. interfacedef : boolean;
  415. { true if the procedure has a forward declaration }
  416. hasforward : boolean;
  417. { import info }
  418. import_dll,
  419. import_name : pshortstring;
  420. import_nr : word;
  421. { info for inlining the subroutine, if this pointer is nil,
  422. the procedure can't be inlined }
  423. inlininginfo : pinlininginfo;
  424. {$ifdef oldregvars}
  425. regvarinfo: pregvarinfo;
  426. {$endif oldregvars}
  427. { position in aasmoutput list }
  428. procstarttai,
  429. procendtai : tai;
  430. constructor create(level:byte);
  431. constructor ppuload(ppufile:tcompilerppufile);
  432. destructor destroy;override;
  433. procedure ppuwrite(ppufile:tcompilerppufile);override;
  434. procedure buildderef;override;
  435. procedure buildderefimpl;override;
  436. procedure deref;override;
  437. procedure derefimpl;override;
  438. procedure reset;override;
  439. function GetSymtable(t:tGetSymtable):TSymtable;override;
  440. function GetTypeName : string;override;
  441. function mangledname : string;
  442. procedure setmangledname(const s : string);
  443. function fullprocname(showhidden:boolean):string;
  444. function cplusplusmangledname : string;
  445. function is_methodpointer:boolean;override;
  446. function is_addressonly:boolean;override;
  447. function is_visible_for_object(currobjdef,contextobjdef:tobjectdef):boolean;
  448. end;
  449. { single linked list of overloaded procs }
  450. pprocdeflist = ^tprocdeflist;
  451. tprocdeflist = record
  452. def : tprocdef;
  453. defderef : tderef;
  454. next : pprocdeflist;
  455. end;
  456. tstringdef = class(tstoreddef)
  457. stringtype : tstringtype;
  458. len : aint;
  459. constructor createshort(l : byte);
  460. constructor loadshort(ppufile:tcompilerppufile);
  461. constructor createlong(l : aint);
  462. constructor loadlong(ppufile:tcompilerppufile);
  463. constructor createansi(l : aint);
  464. constructor loadansi(ppufile:tcompilerppufile);
  465. constructor createwide(l : aint);
  466. constructor loadwide(ppufile:tcompilerppufile);
  467. function getcopy : tstoreddef;override;
  468. function stringtypname:string;
  469. procedure ppuwrite(ppufile:tcompilerppufile);override;
  470. function GetTypeName:string;override;
  471. function getmangledparaname:string;override;
  472. function is_publishable : boolean;override;
  473. function alignment : shortint;override;
  474. function needs_inittable : boolean;override;
  475. function getvardef:longint;override;
  476. end;
  477. tenumdef = class(tstoreddef)
  478. minval,
  479. maxval : aint;
  480. has_jumps : boolean;
  481. firstenum : tsym; {tenumsym}
  482. basedef : tenumdef;
  483. basedefderef : tderef;
  484. constructor create;
  485. constructor create_subrange(_basedef:tenumdef;_min,_max:aint);
  486. constructor ppuload(ppufile:tcompilerppufile);
  487. function getcopy : tstoreddef;override;
  488. procedure ppuwrite(ppufile:tcompilerppufile);override;
  489. procedure buildderef;override;
  490. procedure deref;override;
  491. procedure derefimpl;override;
  492. function GetTypeName:string;override;
  493. function is_publishable : boolean;override;
  494. procedure calcsavesize;
  495. function packedbitsize: aint; override;
  496. procedure setmax(_max:aint);
  497. procedure setmin(_min:aint);
  498. function min:aint;
  499. function max:aint;
  500. end;
  501. tsetdef = class(tstoreddef)
  502. elementdef : tdef;
  503. elementdefderef : tderef;
  504. settype : tsettype;
  505. setbase,
  506. setmax : aword;
  507. constructor create(def:tdef;low, high : aint);
  508. constructor ppuload(ppufile:tcompilerppufile);
  509. function getcopy : tstoreddef;override;
  510. procedure ppuwrite(ppufile:tcompilerppufile);override;
  511. procedure buildderef;override;
  512. procedure deref;override;
  513. function GetTypeName:string;override;
  514. function is_publishable : boolean;override;
  515. end;
  516. Tdefmatch=(dm_exact,dm_equal,dm_convertl1);
  517. var
  518. aktobjectdef : tobjectdef; { used for private functions check !! }
  519. { default types }
  520. generrordef, { error in definition }
  521. voidpointertype, { pointer for Void-pointeddef }
  522. charpointertype, { pointer for Char-pointeddef }
  523. widecharpointertype, { pointer for WideChar-pointeddef }
  524. voidfarpointertype,
  525. cundefinedtype,
  526. cformaltype, { unique formal definition }
  527. ctypedformaltype, { unique typed formal definition }
  528. voidtype, { Void (procedure) }
  529. cchartype, { Char }
  530. cwidechartype, { WideChar }
  531. booltype, { boolean type }
  532. bool16type,
  533. bool32type,
  534. bool64type, { implement me }
  535. u8inttype, { 8-Bit unsigned integer }
  536. s8inttype, { 8-Bit signed integer }
  537. u16inttype, { 16-Bit unsigned integer }
  538. s16inttype, { 16-Bit signed integer }
  539. u32inttype, { 32-Bit unsigned integer }
  540. s32inttype, { 32-Bit signed integer }
  541. u64inttype, { 64-bit unsigned integer }
  542. s64inttype, { 64-bit signed integer }
  543. s32floattype, { pointer for realconstn }
  544. s64floattype, { pointer for realconstn }
  545. s80floattype, { pointer to type of temp. floats }
  546. s64currencytype, { pointer to a currency type }
  547. cshortstringtype, { pointer to type of short string const }
  548. clongstringtype, { pointer to type of long string const }
  549. cansistringtype, { pointer to type of ansi string const }
  550. cwidestringtype, { pointer to type of wide string const }
  551. openshortstringtype, { pointer to type of an open shortstring,
  552. needed for readln() }
  553. openchararraytype, { pointer to type of an open array of char,
  554. needed for readln() }
  555. cfiletype, { get the same definition for all file }
  556. { used for stabs }
  557. methodpointertype, { typecasting of methodpointers to extract self }
  558. hresultdef,
  559. { we use only one variant def for every variant class }
  560. cvarianttype,
  561. colevarianttype,
  562. { default integer type s32inttype on 32 bit systems, s64bittype on 64 bit systems }
  563. sinttype,
  564. uinttype,
  565. { unsigned and signed ord type with the same size as a pointer }
  566. ptruinttype,
  567. ptrsinttype,
  568. { several types to simulate more or less C++ objects for GDB }
  569. vmttype,
  570. vmtarraytype,
  571. pvmttype : tdef; { type of classrefs, used for stabs }
  572. { pointer to the anchestor of all classes }
  573. class_tobject : tobjectdef;
  574. { pointer to the ancestor of all COM interfaces }
  575. interface_iunknown : tobjectdef;
  576. { pointer to the TGUID type
  577. of all interfaces }
  578. rec_tguid : trecorddef;
  579. const
  580. {$ifdef i386}
  581. pbestrealtype : ^tdef = @s80floattype;
  582. {$endif}
  583. {$ifdef x86_64}
  584. pbestrealtype : ^tdef = @s80floattype;
  585. {$endif}
  586. {$ifdef m68k}
  587. pbestrealtype : ^tdef = @s64floattype;
  588. {$endif}
  589. {$ifdef alpha}
  590. pbestrealtype : ^tdef = @s64floattype;
  591. {$endif}
  592. {$ifdef powerpc}
  593. pbestrealtype : ^tdef = @s64floattype;
  594. {$endif}
  595. {$ifdef POWERPC64}
  596. pbestrealtype : ^tdef = @s64floattype;
  597. {$endif}
  598. {$ifdef ia64}
  599. pbestrealtype : ^tdef = @s64floattype;
  600. {$endif}
  601. {$ifdef SPARC}
  602. pbestrealtype : ^tdef = @s64floattype;
  603. {$endif SPARC}
  604. {$ifdef vis}
  605. pbestrealtype : ^tdef = @s64floattype;
  606. {$endif vis}
  607. {$ifdef ARM}
  608. pbestrealtype : ^tdef = @s64floattype;
  609. {$endif ARM}
  610. {$ifdef MIPS}
  611. pbestrealtype : ^tdef = @s64floattype;
  612. {$endif MIPS}
  613. function make_mangledname(const typeprefix:string;st:TSymtable;const suffix:string):string;
  614. { should be in the types unit, but the types unit uses the node stuff :( }
  615. function is_interfacecom(def: tdef): boolean;
  616. function is_interfacecorba(def: tdef): boolean;
  617. function is_interface(def: tdef): boolean;
  618. function is_dispinterface(def: tdef): boolean;
  619. function is_object(def: tdef): boolean;
  620. function is_class(def: tdef): boolean;
  621. function is_cppclass(def: tdef): boolean;
  622. function is_class_or_interface(def: tdef): boolean;
  623. function is_class_or_interface_or_dispinterface(def: tdef): boolean;
  624. {$ifdef x86}
  625. function use_sse(def : tdef) : boolean;
  626. {$endif x86}
  627. implementation
  628. uses
  629. SysUtils,
  630. cutils,
  631. { global }
  632. verbose,
  633. { target }
  634. systems,aasmcpu,paramgr,
  635. { symtable }
  636. symsym,symtable,symutil,defutil,
  637. { module }
  638. fmodule,
  639. { other }
  640. gendef,
  641. fpccrc
  642. ;
  643. {****************************************************************************
  644. Constants
  645. ****************************************************************************}
  646. const
  647. varempty = 0;
  648. varnull = 1;
  649. varsmallint = 2;
  650. varinteger = 3;
  651. varsingle = 4;
  652. vardouble = 5;
  653. varcurrency = 6;
  654. vardate = 7;
  655. varolestr = 8;
  656. vardispatch = 9;
  657. varerror = 10;
  658. varboolean = 11;
  659. varvariant = 12;
  660. varunknown = 13;
  661. vardecimal = 14;
  662. varshortint = 16;
  663. varbyte = 17;
  664. varword = 18;
  665. varlongword = 19;
  666. varint64 = 20;
  667. varqword = 21;
  668. varUndefined = -1;
  669. varstrarg = $48;
  670. varstring = $100;
  671. varany = $101;
  672. vardefmask = $fff;
  673. vararray = $2000;
  674. varbyref = $4000;
  675. {****************************************************************************
  676. Helpers
  677. ****************************************************************************}
  678. function make_mangledname(const typeprefix:string;st:TSymtable;const suffix:string):string;
  679. var
  680. s,hs,
  681. prefix : string;
  682. oldlen,
  683. newlen,
  684. i : longint;
  685. crc : dword;
  686. hp : tparavarsym;
  687. begin
  688. prefix:='';
  689. if not assigned(st) then
  690. internalerror(200204212);
  691. { sub procedures }
  692. while (st.symtabletype=localsymtable) do
  693. begin
  694. if st.defowner.typ<>procdef then
  695. internalerror(200204173);
  696. { Add the full mangledname of procedure to prevent
  697. conflicts with 2 overloads having both a nested procedure
  698. with the same name, see tb0314 (PFV) }
  699. s:=tprocdef(st.defowner).procsym.name;
  700. oldlen:=length(s);
  701. for i:=0 to tprocdef(st.defowner).paras.count-1 do
  702. begin
  703. hp:=tparavarsym(tprocdef(st.defowner).paras[i]);
  704. if not(vo_is_hidden_para in hp.varoptions) then
  705. s:=s+'$'+hp.vardef.mangledparaname;
  706. end;
  707. if not is_void(tprocdef(st.defowner).returndef) then
  708. s:=s+'$$'+tprocdef(st.defowner).returndef.mangledparaname;
  709. newlen:=length(s);
  710. { Replace with CRC if the parameter line is very long }
  711. if (newlen-oldlen>12) and
  712. ((newlen+length(prefix)>128) or (newlen-oldlen>32)) then
  713. begin
  714. crc:=$ffffffff;
  715. for i:=0 to tprocdef(st.defowner).paras.count-1 do
  716. begin
  717. hp:=tparavarsym(tprocdef(st.defowner).paras[i]);
  718. if not(vo_is_hidden_para in hp.varoptions) then
  719. begin
  720. hs:=hp.vardef.mangledparaname;
  721. crc:=UpdateCrc32(crc,hs[1],length(hs));
  722. end;
  723. end;
  724. hs:=hp.vardef.mangledparaname;
  725. crc:=UpdateCrc32(crc,hs[1],length(hs));
  726. s:=Copy(s,1,oldlen)+'$crc'+hexstr(crc,8);
  727. end;
  728. if prefix<>'' then
  729. prefix:=s+'_'+prefix
  730. else
  731. prefix:=s;
  732. st:=st.defowner.owner;
  733. end;
  734. { object/classes symtable }
  735. if (st.symtabletype=ObjectSymtable) then
  736. begin
  737. if st.defowner.typ<>objectdef then
  738. internalerror(200204174);
  739. prefix:=tobjectdef(st.defowner).objname^+'_$_'+prefix;
  740. st:=st.defowner.owner;
  741. end;
  742. { symtable must now be static or global }
  743. if not(st.symtabletype in [staticsymtable,globalsymtable]) then
  744. internalerror(200204175);
  745. result:='';
  746. if typeprefix<>'' then
  747. result:=result+typeprefix+'_';
  748. { Add P$ for program, which can have the same name as
  749. a unit }
  750. if (TSymtable(main_module.localsymtable)=st) and
  751. (not main_module.is_unit) then
  752. result:=result+'P$'+st.name^
  753. else
  754. result:=result+st.name^;
  755. if prefix<>'' then
  756. result:=result+'_'+prefix;
  757. if suffix<>'' then
  758. result:=result+'_'+suffix;
  759. { the Darwin assembler assumes that all symbols starting with 'L' are local }
  760. if (target_info.system in systems_darwin) and
  761. (result[1] = 'L') then
  762. result := '_' + result;
  763. end;
  764. {****************************************************************************
  765. TDEF (base class for definitions)
  766. ****************************************************************************}
  767. constructor tstoreddef.create(dt:tdeftyp);
  768. var
  769. insertstack : psymtablestackitem;
  770. begin
  771. inherited create(dt);
  772. savesize := 0;
  773. {$ifdef EXTDEBUG}
  774. fileinfo := current_filepos;
  775. {$endif}
  776. generictokenbuf:=nil;
  777. genericdef:=nil;
  778. { Don't register forwarddefs, they are disposed at the
  779. end of an type block }
  780. if (dt=forwarddef) then
  781. exit;
  782. { Register in current_module }
  783. if assigned(current_module) then
  784. begin
  785. current_module.deflist.Add(self);
  786. DefId:=current_module.deflist.Count-1;
  787. end;
  788. { Register in symtable stack }
  789. if assigned(symtablestack) then
  790. begin
  791. insertstack:=symtablestack.stack;
  792. while assigned(insertstack) and
  793. (insertstack^.symtable.symtabletype=withsymtable) do
  794. insertstack:=insertstack^.next;
  795. if not assigned(insertstack) then
  796. internalerror(200602044);
  797. insertstack^.symtable.insertdef(self);
  798. end;
  799. end;
  800. destructor tstoreddef.destroy;
  801. begin
  802. { Direct calls are not allowed, use symtable.deletedef() }
  803. if assigned(owner) then
  804. internalerror(200612311);
  805. if assigned(generictokenbuf) then
  806. begin
  807. generictokenbuf.free;
  808. generictokenbuf:=nil;
  809. end;
  810. inherited destroy;
  811. end;
  812. constructor tstoreddef.ppuload(dt:tdeftyp;ppufile:tcompilerppufile);
  813. var
  814. sizeleft,i : longint;
  815. buf : array[0..255] of byte;
  816. begin
  817. inherited create(dt);
  818. DefId:=ppufile.getlongint;
  819. current_module.deflist[DefId]:=self;
  820. {$ifdef EXTDEBUG}
  821. fillchar(fileinfo,sizeof(fileinfo),0);
  822. {$endif}
  823. { load }
  824. ppufile.getderef(typesymderef);
  825. ppufile.getsmallset(defoptions);
  826. if df_generic in defoptions then
  827. begin
  828. sizeleft:=ppufile.getlongint;
  829. initgeneric;
  830. while sizeleft>0 do
  831. begin
  832. if sizeleft>sizeof(buf) then
  833. i:=sizeof(buf)
  834. else
  835. i:=sizeleft;
  836. ppufile.getdata(buf,i);
  837. generictokenbuf.write(buf,i);
  838. dec(sizeleft,i);
  839. end;
  840. end;
  841. if df_specialization in defoptions then
  842. ppufile.getderef(genericdefderef);
  843. end;
  844. function Tstoreddef.rtti_mangledname(rt:trttitype):string;
  845. var
  846. prefix : string[4];
  847. begin
  848. if rt=fullrtti then
  849. begin
  850. prefix:='RTTI';
  851. include(defstates,ds_rtti_table_used);
  852. end
  853. else
  854. begin
  855. prefix:='INIT';
  856. include(defstates,ds_init_table_used);
  857. end;
  858. if assigned(typesym) and
  859. (owner.symtabletype in [staticsymtable,globalsymtable]) then
  860. result:=make_mangledname(prefix,owner,typesym.name)
  861. else
  862. result:=make_mangledname(prefix,findunitsymtable(owner),'DEF'+tostr(DefId))
  863. end;
  864. procedure Tstoreddef.reset;
  865. begin
  866. end;
  867. function tstoreddef.getcopy : tstoreddef;
  868. begin
  869. Message(sym_e_cant_create_unique_type);
  870. getcopy:=terrordef.create;
  871. end;
  872. procedure tstoreddef.ppuwrite(ppufile:tcompilerppufile);
  873. var
  874. sizeleft,i : longint;
  875. buf : array[0..255] of byte;
  876. oldintfcrc : boolean;
  877. begin
  878. ppufile.putlongint(DefId);
  879. ppufile.putderef(typesymderef);
  880. ppufile.putsmallset(defoptions);
  881. if df_generic in defoptions then
  882. begin
  883. oldintfcrc:=ppufile.do_interface_crc;
  884. ppufile.do_interface_crc:=false;
  885. if assigned(generictokenbuf) then
  886. begin
  887. sizeleft:=generictokenbuf.size;
  888. generictokenbuf.seek(0);
  889. end
  890. else
  891. sizeleft:=0;
  892. ppufile.putlongint(sizeleft);
  893. while sizeleft>0 do
  894. begin
  895. if sizeleft>sizeof(buf) then
  896. i:=sizeof(buf)
  897. else
  898. i:=sizeleft;
  899. generictokenbuf.read(buf,i);
  900. ppufile.putdata(buf,i);
  901. dec(sizeleft,i);
  902. end;
  903. ppufile.do_interface_crc:=oldintfcrc;
  904. end;
  905. if df_specialization in defoptions then
  906. ppufile.putderef(genericdefderef);
  907. end;
  908. procedure tstoreddef.buildderef;
  909. begin
  910. typesymderef.build(typesym);
  911. genericdefderef.build(genericdef);
  912. end;
  913. procedure tstoreddef.buildderefimpl;
  914. begin
  915. end;
  916. procedure tstoreddef.deref;
  917. begin
  918. typesym:=ttypesym(typesymderef.resolve);
  919. if df_specialization in defoptions then
  920. genericdef:=tstoreddef(genericdefderef.resolve);
  921. end;
  922. procedure tstoreddef.derefimpl;
  923. begin
  924. end;
  925. function tstoreddef.size : aint;
  926. begin
  927. size:=savesize;
  928. end;
  929. function tstoreddef.getvardef:longint;
  930. begin
  931. result:=varUndefined;
  932. end;
  933. function tstoreddef.alignment : shortint;
  934. begin
  935. { natural alignment by default }
  936. alignment:=size_2_align(savesize);
  937. end;
  938. { returns true, if the definition can be published }
  939. function tstoreddef.is_publishable : boolean;
  940. begin
  941. is_publishable:=false;
  942. end;
  943. { needs an init table }
  944. function tstoreddef.needs_inittable : boolean;
  945. begin
  946. needs_inittable:=false;
  947. end;
  948. function tstoreddef.is_intregable : boolean;
  949. var
  950. recsize,temp: longint;
  951. begin
  952. is_intregable:=false;
  953. case typ of
  954. orddef,
  955. pointerdef,
  956. enumdef,
  957. classrefdef:
  958. is_intregable:=true;
  959. procvardef :
  960. is_intregable:=not(po_methodpointer in tprocvardef(self).procoptions);
  961. objectdef:
  962. is_intregable:=(is_class(self) or is_interface(self)) and not needs_inittable;
  963. setdef:
  964. is_intregable:=(tsetdef(self).settype=smallset);
  965. recorddef:
  966. begin
  967. recsize:=size;
  968. is_intregable:=
  969. ispowerof2(recsize,temp) and
  970. (recsize <= sizeof(aint));
  971. end;
  972. end;
  973. end;
  974. function tstoreddef.is_fpuregable : boolean;
  975. begin
  976. {$ifdef x86}
  977. result:=use_sse(self);
  978. {$else x86}
  979. result:=(typ=floatdef) and not(cs_fp_emulation in current_settings.moduleswitches);
  980. {$endif x86}
  981. end;
  982. procedure tstoreddef.initgeneric;
  983. begin
  984. if assigned(generictokenbuf) then
  985. internalerror(200512131);
  986. generictokenbuf:=tdynamicarray.create(256);
  987. end;
  988. {****************************************************************************
  989. Tstringdef
  990. ****************************************************************************}
  991. constructor tstringdef.createshort(l : byte);
  992. begin
  993. inherited create(stringdef);
  994. stringtype:=st_shortstring;
  995. len:=l;
  996. savesize:=len+1;
  997. end;
  998. constructor tstringdef.loadshort(ppufile:tcompilerppufile);
  999. begin
  1000. inherited ppuload(stringdef,ppufile);
  1001. stringtype:=st_shortstring;
  1002. len:=ppufile.getbyte;
  1003. savesize:=len+1;
  1004. end;
  1005. constructor tstringdef.createlong(l : aint);
  1006. begin
  1007. inherited create(stringdef);
  1008. stringtype:=st_longstring;
  1009. len:=l;
  1010. savesize:=sizeof(aint);
  1011. end;
  1012. constructor tstringdef.loadlong(ppufile:tcompilerppufile);
  1013. begin
  1014. inherited ppuload(stringdef,ppufile);
  1015. stringtype:=st_longstring;
  1016. len:=ppufile.getaint;
  1017. savesize:=sizeof(aint);
  1018. end;
  1019. constructor tstringdef.createansi(l:aint);
  1020. begin
  1021. inherited create(stringdef);
  1022. stringtype:=st_ansistring;
  1023. len:=l;
  1024. savesize:=sizeof(aint);
  1025. end;
  1026. constructor tstringdef.loadansi(ppufile:tcompilerppufile);
  1027. begin
  1028. inherited ppuload(stringdef,ppufile);
  1029. stringtype:=st_ansistring;
  1030. len:=ppufile.getaint;
  1031. savesize:=sizeof(aint);
  1032. end;
  1033. constructor tstringdef.createwide(l : aint);
  1034. begin
  1035. inherited create(stringdef);
  1036. stringtype:=st_widestring;
  1037. len:=l;
  1038. savesize:=sizeof(aint);
  1039. end;
  1040. constructor tstringdef.loadwide(ppufile:tcompilerppufile);
  1041. begin
  1042. inherited ppuload(stringdef,ppufile);
  1043. stringtype:=st_widestring;
  1044. len:=ppufile.getaint;
  1045. savesize:=sizeof(aint);
  1046. end;
  1047. function tstringdef.getcopy : tstoreddef;
  1048. begin
  1049. result:=tstringdef.create(typ);
  1050. result.typ:=stringdef;
  1051. tstringdef(result).stringtype:=stringtype;
  1052. tstringdef(result).len:=len;
  1053. tstringdef(result).savesize:=savesize;
  1054. end;
  1055. function tstringdef.stringtypname:string;
  1056. const
  1057. typname:array[tstringtype] of string[8]=(
  1058. 'shortstr','longstr','ansistr','widestr'
  1059. );
  1060. begin
  1061. stringtypname:=typname[stringtype];
  1062. end;
  1063. procedure tstringdef.ppuwrite(ppufile:tcompilerppufile);
  1064. begin
  1065. inherited ppuwrite(ppufile);
  1066. if stringtype=st_shortstring then
  1067. begin
  1068. {$ifdef extdebug}
  1069. if len > 255 then internalerror(12122002);
  1070. {$endif}
  1071. ppufile.putbyte(byte(len))
  1072. end
  1073. else
  1074. ppufile.putaint(len);
  1075. case stringtype of
  1076. st_shortstring : ppufile.writeentry(ibshortstringdef);
  1077. st_longstring : ppufile.writeentry(iblongstringdef);
  1078. st_ansistring : ppufile.writeentry(ibansistringdef);
  1079. st_widestring : ppufile.writeentry(ibwidestringdef);
  1080. end;
  1081. end;
  1082. function tstringdef.needs_inittable : boolean;
  1083. begin
  1084. needs_inittable:=stringtype in [st_ansistring,st_widestring];
  1085. end;
  1086. function tstringdef.GetTypeName : string;
  1087. const
  1088. names : array[tstringtype] of string[11] = (
  1089. 'ShortString','LongString','AnsiString','WideString');
  1090. begin
  1091. GetTypeName:=names[stringtype];
  1092. end;
  1093. function tstringdef.getvardef : longint;
  1094. const
  1095. vardef : array[tstringtype] of longint = (
  1096. varUndefined,varUndefined,varString,varOleStr);
  1097. begin
  1098. result:=vardef[stringtype];
  1099. end;
  1100. function tstringdef.alignment : shortint;
  1101. begin
  1102. case stringtype of
  1103. st_widestring,
  1104. st_ansistring:
  1105. alignment:=size_2_align(savesize);
  1106. st_longstring,
  1107. st_shortstring:
  1108. if (tf_requires_proper_alignment in target_info.flags) then
  1109. { char to string accesses byte 0 and 1 with one word access }
  1110. alignment:=size_2_align(2)
  1111. else
  1112. alignment:=size_2_align(1);
  1113. else
  1114. internalerror(200412301);
  1115. end;
  1116. end;
  1117. function tstringdef.getmangledparaname : string;
  1118. begin
  1119. getmangledparaname:='STRING';
  1120. end;
  1121. function tstringdef.is_publishable : boolean;
  1122. begin
  1123. is_publishable:=true;
  1124. end;
  1125. {****************************************************************************
  1126. TENUMDEF
  1127. ****************************************************************************}
  1128. constructor tenumdef.create;
  1129. begin
  1130. inherited create(enumdef);
  1131. minval:=0;
  1132. maxval:=0;
  1133. calcsavesize;
  1134. has_jumps:=false;
  1135. basedef:=nil;
  1136. firstenum:=nil;
  1137. end;
  1138. constructor tenumdef.create_subrange(_basedef:tenumdef;_min,_max:aint);
  1139. begin
  1140. inherited create(enumdef);
  1141. minval:=_min;
  1142. maxval:=_max;
  1143. basedef:=_basedef;
  1144. calcsavesize;
  1145. has_jumps:=false;
  1146. firstenum:=basedef.firstenum;
  1147. while assigned(firstenum) and (tenumsym(firstenum).value<>minval) do
  1148. firstenum:=tenumsym(firstenum).nextenum;
  1149. end;
  1150. constructor tenumdef.ppuload(ppufile:tcompilerppufile);
  1151. begin
  1152. inherited ppuload(enumdef,ppufile);
  1153. ppufile.getderef(basedefderef);
  1154. minval:=ppufile.getaint;
  1155. maxval:=ppufile.getaint;
  1156. savesize:=ppufile.getaint;
  1157. has_jumps:=false;
  1158. firstenum:=Nil;
  1159. end;
  1160. function tenumdef.getcopy : tstoreddef;
  1161. begin
  1162. if assigned(basedef) then
  1163. result:=tenumdef.create_subrange(basedef,minval,maxval)
  1164. else
  1165. begin
  1166. result:=tenumdef.create;
  1167. tenumdef(result).minval:=minval;
  1168. tenumdef(result).maxval:=maxval;
  1169. end;
  1170. tenumdef(result).has_jumps:=has_jumps;
  1171. tenumdef(result).firstenum:=firstenum;
  1172. tenumdef(result).basedefderef:=basedefderef;
  1173. end;
  1174. procedure tenumdef.calcsavesize;
  1175. begin
  1176. if (current_settings.packenum=8) or (min<low(longint)) or (int64(max)>high(cardinal)) then
  1177. savesize:=8
  1178. else
  1179. if (current_settings.packenum=4) or (min<low(smallint)) or (max>high(word)) then
  1180. savesize:=4
  1181. else
  1182. if (current_settings.packenum=2) or (min<low(shortint)) or (max>high(byte)) then
  1183. savesize:=2
  1184. else
  1185. savesize:=1;
  1186. end;
  1187. function tenumdef.packedbitsize: aint;
  1188. var
  1189. sizeval: tconstexprint;
  1190. power: longint;
  1191. begin
  1192. result := 0;
  1193. if (minval >= 0) and
  1194. (maxval <= 1) then
  1195. result := 1
  1196. else
  1197. begin
  1198. if (minval>=0) then
  1199. sizeval:=maxval
  1200. else
  1201. { don't count 0 twice }
  1202. sizeval:=(cutils.max(-minval,maxval)*2)-1;
  1203. { 256 must become 512 etc. }
  1204. nextpowerof2(sizeval+1,power);
  1205. result := power;
  1206. end;
  1207. end;
  1208. procedure tenumdef.setmax(_max:aint);
  1209. begin
  1210. maxval:=_max;
  1211. calcsavesize;
  1212. end;
  1213. procedure tenumdef.setmin(_min:aint);
  1214. begin
  1215. minval:=_min;
  1216. calcsavesize;
  1217. end;
  1218. function tenumdef.min:aint;
  1219. begin
  1220. min:=minval;
  1221. end;
  1222. function tenumdef.max:aint;
  1223. begin
  1224. max:=maxval;
  1225. end;
  1226. procedure tenumdef.buildderef;
  1227. begin
  1228. inherited buildderef;
  1229. basedefderef.build(basedef);
  1230. end;
  1231. procedure tenumdef.deref;
  1232. begin
  1233. inherited deref;
  1234. basedef:=tenumdef(basedefderef.resolve);
  1235. { restart ordering }
  1236. firstenum:=nil;
  1237. end;
  1238. procedure tenumdef.derefimpl;
  1239. begin
  1240. if assigned(basedef) and
  1241. (firstenum=nil) then
  1242. begin
  1243. firstenum:=basedef.firstenum;
  1244. while assigned(firstenum) and (tenumsym(firstenum).value<>minval) do
  1245. firstenum:=tenumsym(firstenum).nextenum;
  1246. end;
  1247. end;
  1248. procedure tenumdef.ppuwrite(ppufile:tcompilerppufile);
  1249. begin
  1250. inherited ppuwrite(ppufile);
  1251. ppufile.putderef(basedefderef);
  1252. ppufile.putaint(min);
  1253. ppufile.putaint(max);
  1254. ppufile.putaint(savesize);
  1255. ppufile.writeentry(ibenumdef);
  1256. end;
  1257. function tenumdef.is_publishable : boolean;
  1258. begin
  1259. is_publishable:=true;
  1260. end;
  1261. function tenumdef.GetTypeName : string;
  1262. begin
  1263. GetTypeName:='<enumeration type>';
  1264. end;
  1265. {****************************************************************************
  1266. TORDDEF
  1267. ****************************************************************************}
  1268. constructor torddef.create(t : tordtype;v,b : TConstExprInt);
  1269. begin
  1270. inherited create(orddef);
  1271. low:=v;
  1272. high:=b;
  1273. ordtype:=t;
  1274. setsize;
  1275. end;
  1276. constructor torddef.ppuload(ppufile:tcompilerppufile);
  1277. begin
  1278. inherited ppuload(orddef,ppufile);
  1279. ordtype:=tordtype(ppufile.getbyte);
  1280. low:=ppufile.getexprint;
  1281. high:=ppufile.getexprint;
  1282. setsize;
  1283. end;
  1284. function torddef.getcopy : tstoreddef;
  1285. begin
  1286. result:=torddef.create(ordtype,low,high);
  1287. result.typ:=orddef;
  1288. torddef(result).low:=low;
  1289. torddef(result).high:=high;
  1290. torddef(result).ordtype:=ordtype;
  1291. torddef(result).savesize:=savesize;
  1292. end;
  1293. function torddef.alignment:shortint;
  1294. begin
  1295. if (target_info.system = system_i386_darwin) and
  1296. (ordtype in [s64bit,u64bit]) then
  1297. result := 4
  1298. else
  1299. result := inherited alignment;
  1300. end;
  1301. procedure torddef.setsize;
  1302. const
  1303. sizetbl : array[tordtype] of longint = (
  1304. 0,
  1305. 1,2,4,8,
  1306. 1,2,4,8,
  1307. 1,2,4,8,
  1308. 1,2,8
  1309. );
  1310. begin
  1311. savesize:=sizetbl[ordtype];
  1312. end;
  1313. function torddef.packedbitsize: aint;
  1314. var
  1315. sizeval: tconstexprint;
  1316. power: longint;
  1317. begin
  1318. result := 0;
  1319. if ordtype = uvoid then
  1320. exit;
  1321. if (ordtype = u64bit) or
  1322. ((ordtype = s64bit) and
  1323. ((low <= (system.low(int64) div 2)) or
  1324. (high > (system.high(int64) div 2)))) then
  1325. result := 64
  1326. else if (low >= 0) and
  1327. (high <= 1) then
  1328. result := 1
  1329. else
  1330. begin
  1331. if (low>=0) then
  1332. sizeval:=high
  1333. else
  1334. { don't count 0 twice }
  1335. sizeval:=(cutils.max(-low,high)*2)-1;
  1336. { 256 must become 512 etc. }
  1337. nextpowerof2(sizeval+1,power);
  1338. result := power;
  1339. end;
  1340. end;
  1341. function torddef.getvardef : longint;
  1342. const
  1343. basetype2vardef : array[tordtype] of longint = (
  1344. varUndefined,
  1345. varbyte,varqword,varlongword,varqword,
  1346. varshortint,varsmallint,varinteger,varint64,
  1347. varboolean,varboolean,varUndefined,varUndefined,
  1348. varUndefined,varUndefined,varCurrency);
  1349. begin
  1350. result:=basetype2vardef[ordtype];
  1351. end;
  1352. procedure torddef.ppuwrite(ppufile:tcompilerppufile);
  1353. begin
  1354. inherited ppuwrite(ppufile);
  1355. ppufile.putbyte(byte(ordtype));
  1356. ppufile.putexprint(low);
  1357. ppufile.putexprint(high);
  1358. ppufile.writeentry(iborddef);
  1359. end;
  1360. function torddef.is_publishable : boolean;
  1361. begin
  1362. is_publishable:=(ordtype<>uvoid);
  1363. end;
  1364. function torddef.GetTypeName : string;
  1365. const
  1366. names : array[tordtype] of string[20] = (
  1367. 'untyped',
  1368. 'Byte','Word','DWord','QWord',
  1369. 'ShortInt','SmallInt','LongInt','Int64',
  1370. 'Boolean','WordBool','LongBool','QWordBool',
  1371. 'Char','WideChar','Currency');
  1372. begin
  1373. GetTypeName:=names[ordtype];
  1374. end;
  1375. {****************************************************************************
  1376. TFLOATDEF
  1377. ****************************************************************************}
  1378. constructor tfloatdef.create(t : tfloattype);
  1379. begin
  1380. inherited create(floatdef);
  1381. floattype:=t;
  1382. setsize;
  1383. end;
  1384. constructor tfloatdef.ppuload(ppufile:tcompilerppufile);
  1385. begin
  1386. inherited ppuload(floatdef,ppufile);
  1387. floattype:=tfloattype(ppufile.getbyte);
  1388. setsize;
  1389. end;
  1390. function tfloatdef.getcopy : tstoreddef;
  1391. begin
  1392. result:=tfloatdef.create(floattype);
  1393. result.typ:=floatdef;
  1394. tfloatdef(result).savesize:=savesize;
  1395. end;
  1396. function tfloatdef.alignment:shortint;
  1397. begin
  1398. if (target_info.system = system_i386_darwin) then
  1399. case floattype of
  1400. s80real : result:=16;
  1401. s64real,
  1402. s64currency,
  1403. s64comp : result:=4;
  1404. else
  1405. result := inherited alignment;
  1406. end
  1407. else
  1408. result := inherited alignment;
  1409. end;
  1410. procedure tfloatdef.setsize;
  1411. begin
  1412. case floattype of
  1413. s32real : savesize:=4;
  1414. s80real : savesize:=10;
  1415. s64real,
  1416. s64currency,
  1417. s64comp : savesize:=8;
  1418. else
  1419. savesize:=0;
  1420. end;
  1421. end;
  1422. function tfloatdef.getvardef : longint;
  1423. const
  1424. floattype2vardef : array[tfloattype] of longint = (
  1425. varSingle,varDouble,varUndefined,
  1426. varUndefined,varCurrency,varUndefined);
  1427. begin
  1428. if (upper(typename)='TDATETIME') and
  1429. assigned(owner) and
  1430. assigned(owner.name) and
  1431. (owner.name^='SYSTEM') then
  1432. result:=varDate
  1433. else
  1434. result:=floattype2vardef[floattype];
  1435. end;
  1436. procedure tfloatdef.ppuwrite(ppufile:tcompilerppufile);
  1437. begin
  1438. inherited ppuwrite(ppufile);
  1439. ppufile.putbyte(byte(floattype));
  1440. ppufile.writeentry(ibfloatdef);
  1441. end;
  1442. function tfloatdef.is_publishable : boolean;
  1443. begin
  1444. is_publishable:=true;
  1445. end;
  1446. function tfloatdef.GetTypeName : string;
  1447. const
  1448. names : array[tfloattype] of string[20] = (
  1449. 'Single','Double','Extended','Comp','Currency','Float128');
  1450. begin
  1451. GetTypeName:=names[floattype];
  1452. end;
  1453. {****************************************************************************
  1454. TFILEDEF
  1455. ****************************************************************************}
  1456. constructor tfiledef.createtext;
  1457. begin
  1458. inherited create(filedef);
  1459. filetyp:=ft_text;
  1460. typedfiledef:=nil;
  1461. setsize;
  1462. end;
  1463. constructor tfiledef.createuntyped;
  1464. begin
  1465. inherited create(filedef);
  1466. filetyp:=ft_untyped;
  1467. typedfiledef:=nil;
  1468. setsize;
  1469. end;
  1470. constructor tfiledef.createtyped(def:tdef);
  1471. begin
  1472. inherited create(filedef);
  1473. filetyp:=ft_typed;
  1474. typedfiledef:=def;
  1475. setsize;
  1476. end;
  1477. constructor tfiledef.ppuload(ppufile:tcompilerppufile);
  1478. begin
  1479. inherited ppuload(filedef,ppufile);
  1480. filetyp:=tfiletyp(ppufile.getbyte);
  1481. if filetyp=ft_typed then
  1482. ppufile.getderef(typedfiledefderef)
  1483. else
  1484. typedfiledef:=nil;
  1485. setsize;
  1486. end;
  1487. function tfiledef.getcopy : tstoreddef;
  1488. begin
  1489. case filetyp of
  1490. ft_typed:
  1491. result:=tfiledef.createtyped(typedfiledef);
  1492. ft_untyped:
  1493. result:=tfiledef.createuntyped;
  1494. ft_text:
  1495. result:=tfiledef.createtext;
  1496. else
  1497. internalerror(2004121201);
  1498. end;
  1499. end;
  1500. procedure tfiledef.buildderef;
  1501. begin
  1502. inherited buildderef;
  1503. if filetyp=ft_typed then
  1504. typedfiledefderef.build(typedfiledef);
  1505. end;
  1506. procedure tfiledef.deref;
  1507. begin
  1508. inherited deref;
  1509. if filetyp=ft_typed then
  1510. typedfiledef:=tdef(typedfiledefderef.resolve);
  1511. end;
  1512. procedure tfiledef.setsize;
  1513. begin
  1514. {$ifdef cpu64bit}
  1515. case filetyp of
  1516. ft_text :
  1517. if target_info.system in [system_x86_64_win64,system_ia64_win64] then
  1518. savesize:=632{+8}
  1519. else
  1520. savesize:=628{+8};
  1521. ft_typed,
  1522. ft_untyped :
  1523. if target_info.system in [system_x86_64_win64,system_ia64_win64] then
  1524. savesize:=372
  1525. else
  1526. savesize:=368;
  1527. end;
  1528. {$else cpu64bit}
  1529. case filetyp of
  1530. ft_text :
  1531. savesize:=592{+4};
  1532. ft_typed,
  1533. ft_untyped :
  1534. savesize:=332;
  1535. end;
  1536. {$endif cpu64bit}
  1537. end;
  1538. procedure tfiledef.ppuwrite(ppufile:tcompilerppufile);
  1539. begin
  1540. inherited ppuwrite(ppufile);
  1541. ppufile.putbyte(byte(filetyp));
  1542. if filetyp=ft_typed then
  1543. ppufile.putderef(typedfiledefderef);
  1544. ppufile.writeentry(ibfiledef);
  1545. end;
  1546. function tfiledef.GetTypeName : string;
  1547. begin
  1548. case filetyp of
  1549. ft_untyped:
  1550. GetTypeName:='File';
  1551. ft_typed:
  1552. GetTypeName:='File Of '+typedfiledef.typename;
  1553. ft_text:
  1554. GetTypeName:='Text'
  1555. end;
  1556. end;
  1557. function tfiledef.getmangledparaname : string;
  1558. begin
  1559. case filetyp of
  1560. ft_untyped:
  1561. getmangledparaname:='FILE';
  1562. ft_typed:
  1563. getmangledparaname:='FILE$OF$'+typedfiledef.mangledparaname;
  1564. ft_text:
  1565. getmangledparaname:='TEXT'
  1566. end;
  1567. end;
  1568. {****************************************************************************
  1569. TVARIANTDEF
  1570. ****************************************************************************}
  1571. constructor tvariantdef.create(v : tvarianttype);
  1572. begin
  1573. inherited create(variantdef);
  1574. varianttype:=v;
  1575. setsize;
  1576. end;
  1577. constructor tvariantdef.ppuload(ppufile:tcompilerppufile);
  1578. begin
  1579. inherited ppuload(variantdef,ppufile);
  1580. varianttype:=tvarianttype(ppufile.getbyte);
  1581. setsize;
  1582. end;
  1583. function tvariantdef.getcopy : tstoreddef;
  1584. begin
  1585. result:=tvariantdef.create(varianttype);
  1586. end;
  1587. procedure tvariantdef.ppuwrite(ppufile:tcompilerppufile);
  1588. begin
  1589. inherited ppuwrite(ppufile);
  1590. ppufile.putbyte(byte(varianttype));
  1591. ppufile.writeentry(ibvariantdef);
  1592. end;
  1593. function tvariantdef.getvardef : longint;
  1594. begin
  1595. Result:=varVariant;
  1596. end;
  1597. procedure tvariantdef.setsize;
  1598. begin
  1599. {$ifdef cpu64bit}
  1600. savesize:=24;
  1601. {$else cpu64bit}
  1602. savesize:=16;
  1603. {$endif cpu64bit}
  1604. end;
  1605. function tvariantdef.GetTypeName : string;
  1606. begin
  1607. case varianttype of
  1608. vt_normalvariant:
  1609. GetTypeName:='Variant';
  1610. vt_olevariant:
  1611. GetTypeName:='OleVariant';
  1612. end;
  1613. end;
  1614. function tvariantdef.needs_inittable : boolean;
  1615. begin
  1616. needs_inittable:=true;
  1617. end;
  1618. function tvariantdef.is_publishable : boolean;
  1619. begin
  1620. is_publishable:=true;
  1621. end;
  1622. {****************************************************************************
  1623. TABSTRACtpointerdef
  1624. ****************************************************************************}
  1625. constructor tabstractpointerdef.create(dt:tdeftyp;def:tdef);
  1626. begin
  1627. inherited create(dt);
  1628. pointeddef:=def;
  1629. savesize:=sizeof(aint);
  1630. end;
  1631. constructor tabstractpointerdef.ppuload(dt:tdeftyp;ppufile:tcompilerppufile);
  1632. begin
  1633. inherited ppuload(dt,ppufile);
  1634. ppufile.getderef(pointeddefderef);
  1635. savesize:=sizeof(aint);
  1636. end;
  1637. procedure tabstractpointerdef.buildderef;
  1638. begin
  1639. inherited buildderef;
  1640. pointeddefderef.build(pointeddef);
  1641. end;
  1642. procedure tabstractpointerdef.deref;
  1643. begin
  1644. inherited deref;
  1645. pointeddef:=tdef(pointeddefderef.resolve);
  1646. end;
  1647. procedure tabstractpointerdef.ppuwrite(ppufile:tcompilerppufile);
  1648. begin
  1649. inherited ppuwrite(ppufile);
  1650. ppufile.putderef(pointeddefderef);
  1651. end;
  1652. {****************************************************************************
  1653. tpointerdef
  1654. ****************************************************************************}
  1655. constructor tpointerdef.create(def:tdef);
  1656. begin
  1657. inherited create(pointerdef,def);
  1658. is_far:=false;
  1659. end;
  1660. constructor tpointerdef.createfar(def:tdef);
  1661. begin
  1662. inherited create(pointerdef,def);
  1663. is_far:=true;
  1664. end;
  1665. constructor tpointerdef.ppuload(ppufile:tcompilerppufile);
  1666. begin
  1667. inherited ppuload(pointerdef,ppufile);
  1668. is_far:=(ppufile.getbyte<>0);
  1669. end;
  1670. function tpointerdef.getcopy : tstoreddef;
  1671. begin
  1672. result:=tpointerdef.create(pointeddef);
  1673. tpointerdef(result).is_far:=is_far;
  1674. tpointerdef(result).savesize:=savesize;
  1675. end;
  1676. procedure tpointerdef.ppuwrite(ppufile:tcompilerppufile);
  1677. begin
  1678. inherited ppuwrite(ppufile);
  1679. ppufile.putbyte(byte(is_far));
  1680. ppufile.writeentry(ibpointerdef);
  1681. end;
  1682. function tpointerdef.GetTypeName : string;
  1683. begin
  1684. if is_far then
  1685. GetTypeName:='^'+pointeddef.typename+';far'
  1686. else
  1687. GetTypeName:='^'+pointeddef.typename;
  1688. end;
  1689. {****************************************************************************
  1690. TCLASSREFDEF
  1691. ****************************************************************************}
  1692. constructor tclassrefdef.create(def:tdef);
  1693. begin
  1694. inherited create(classrefdef,def);
  1695. end;
  1696. constructor tclassrefdef.ppuload(ppufile:tcompilerppufile);
  1697. begin
  1698. inherited ppuload(classrefdef,ppufile);
  1699. end;
  1700. procedure tclassrefdef.ppuwrite(ppufile:tcompilerppufile);
  1701. begin
  1702. inherited ppuwrite(ppufile);
  1703. ppufile.writeentry(ibclassrefdef);
  1704. end;
  1705. function tclassrefdef.GetTypeName : string;
  1706. begin
  1707. GetTypeName:='Class Of '+pointeddef.typename;
  1708. end;
  1709. function tclassrefdef.is_publishable : boolean;
  1710. begin
  1711. result:=true;
  1712. end;
  1713. {***************************************************************************
  1714. TSETDEF
  1715. ***************************************************************************}
  1716. constructor tsetdef.create(def:tdef;low, high : aint);
  1717. var
  1718. setallocbits: aint;
  1719. packedsavesize: aint;
  1720. begin
  1721. inherited create(setdef);
  1722. elementdef:=def;
  1723. setmax:=high;
  1724. if (current_settings.setalloc=0) then
  1725. begin
  1726. setbase:=0;
  1727. if (high<32) then
  1728. begin
  1729. settype:=smallset;
  1730. savesize:=Sizeof(longint)
  1731. end
  1732. else if (high<256) then
  1733. begin
  1734. settype:=normset;
  1735. savesize:=32
  1736. end
  1737. else
  1738. savesize:=(high+7) div 8
  1739. end
  1740. else
  1741. begin
  1742. setallocbits:=current_settings.setalloc*8;
  1743. setbase:=low and not(setallocbits-1);
  1744. packedsavesize:=current_settings.setalloc*((((high+setallocbits)-setbase)) DIV setallocbits);
  1745. savesize:=packedsavesize;
  1746. if (packedsavesize<=4) then
  1747. begin
  1748. settype:=smallset;
  1749. if savesize=3 then
  1750. savesize:=4;
  1751. end
  1752. else if (packedsavesize<=32) then
  1753. settype:=normset;
  1754. end;
  1755. end;
  1756. constructor tsetdef.ppuload(ppufile:tcompilerppufile);
  1757. begin
  1758. inherited ppuload(setdef,ppufile);
  1759. ppufile.getderef(elementdefderef);
  1760. settype:=tsettype(ppufile.getbyte);
  1761. savesize:=ppufile.getaint;
  1762. setbase:=ppufile.getaint;
  1763. setmax:=ppufile.getaint;
  1764. end;
  1765. function tsetdef.getcopy : tstoreddef;
  1766. begin
  1767. result:=tsetdef.create(elementdef,setbase,setmax);
  1768. { the copy might have been created with a different setalloc setting }
  1769. tsetdef(result).settype:=settype;
  1770. tsetdef(result).savesize:=savesize;
  1771. end;
  1772. procedure tsetdef.ppuwrite(ppufile:tcompilerppufile);
  1773. begin
  1774. inherited ppuwrite(ppufile);
  1775. ppufile.putderef(elementdefderef);
  1776. ppufile.putbyte(byte(settype));
  1777. ppufile.putaint(savesize);
  1778. ppufile.putaint(setbase);
  1779. ppufile.putaint(setmax);
  1780. ppufile.writeentry(ibsetdef);
  1781. end;
  1782. procedure tsetdef.buildderef;
  1783. begin
  1784. inherited buildderef;
  1785. elementdefderef.build(elementdef);
  1786. end;
  1787. procedure tsetdef.deref;
  1788. begin
  1789. inherited deref;
  1790. elementdef:=tdef(elementdefderef.resolve);
  1791. end;
  1792. function tsetdef.is_publishable : boolean;
  1793. begin
  1794. is_publishable:=savesize in [1,2,4];
  1795. end;
  1796. function tsetdef.GetTypeName : string;
  1797. begin
  1798. if assigned(elementdef) then
  1799. GetTypeName:='Set Of '+elementdef.typename
  1800. else
  1801. GetTypeName:='Empty Set';
  1802. end;
  1803. {***************************************************************************
  1804. TFORMALDEF
  1805. ***************************************************************************}
  1806. constructor tformaldef.create(Atyped:boolean);
  1807. begin
  1808. inherited create(formaldef);
  1809. typed:=Atyped;
  1810. savesize:=0;
  1811. end;
  1812. constructor tformaldef.ppuload(ppufile:tcompilerppufile);
  1813. begin
  1814. inherited ppuload(formaldef,ppufile);
  1815. typed:=boolean(ppufile.getbyte);
  1816. savesize:=0;
  1817. end;
  1818. procedure tformaldef.ppuwrite(ppufile:tcompilerppufile);
  1819. begin
  1820. inherited ppuwrite(ppufile);
  1821. ppufile.putbyte(byte(typed));
  1822. ppufile.writeentry(ibformaldef);
  1823. end;
  1824. function tformaldef.GetTypeName : string;
  1825. begin
  1826. if typed then
  1827. GetTypeName:='<Typed formal type>'
  1828. else
  1829. GetTypeName:='<Formal type>';
  1830. end;
  1831. {***************************************************************************
  1832. TARRAYDEF
  1833. ***************************************************************************}
  1834. constructor tarraydef.create(l,h : aint;def:tdef);
  1835. begin
  1836. inherited create(arraydef);
  1837. lowrange:=l;
  1838. highrange:=h;
  1839. rangedef:=def;
  1840. _elementdef:=nil;
  1841. arrayoptions:=[];
  1842. end;
  1843. constructor tarraydef.create_from_pointer(def:tdef);
  1844. begin
  1845. { use -1 so that the elecount will not overflow }
  1846. self.create(0,high(aint)-1,s32inttype);
  1847. arrayoptions:=[ado_IsConvertedPointer];
  1848. setelementdef(def);
  1849. end;
  1850. constructor tarraydef.ppuload(ppufile:tcompilerppufile);
  1851. begin
  1852. inherited ppuload(arraydef,ppufile);
  1853. { the addresses are calculated later }
  1854. ppufile.getderef(_elementdefderef);
  1855. ppufile.getderef(rangedefderef);
  1856. lowrange:=ppufile.getaint;
  1857. highrange:=ppufile.getaint;
  1858. ppufile.getsmallset(arrayoptions);
  1859. end;
  1860. function tarraydef.getcopy : tstoreddef;
  1861. begin
  1862. result:=tarraydef.create(lowrange,highrange,rangedef);
  1863. tarraydef(result).arrayoptions:=arrayoptions;
  1864. tarraydef(result)._elementdef:=_elementdef;
  1865. end;
  1866. procedure tarraydef.buildderef;
  1867. begin
  1868. inherited buildderef;
  1869. _elementdefderef.build(_elementdef);
  1870. rangedefderef.build(rangedef);
  1871. end;
  1872. procedure tarraydef.deref;
  1873. begin
  1874. inherited deref;
  1875. _elementdef:=tdef(_elementdefderef.resolve);
  1876. rangedef:=tdef(rangedefderef.resolve);
  1877. end;
  1878. procedure tarraydef.ppuwrite(ppufile:tcompilerppufile);
  1879. begin
  1880. inherited ppuwrite(ppufile);
  1881. ppufile.putderef(_elementdefderef);
  1882. ppufile.putderef(rangedefderef);
  1883. ppufile.putaint(lowrange);
  1884. ppufile.putaint(highrange);
  1885. ppufile.putsmallset(arrayoptions);
  1886. ppufile.writeentry(ibarraydef);
  1887. end;
  1888. function tarraydef.elesize : aint;
  1889. begin
  1890. if (ado_IsBitPacked in arrayoptions) then
  1891. internalerror(2006080101);
  1892. if assigned(_elementdef) then
  1893. result:=_elementdef.size
  1894. else
  1895. result:=0;
  1896. end;
  1897. function tarraydef.elepackedbitsize : aint;
  1898. begin
  1899. if not(ado_IsBitPacked in arrayoptions) then
  1900. internalerror(2006080102);
  1901. if assigned(_elementdef) then
  1902. result:=_elementdef.packedbitsize
  1903. else
  1904. result:=0;
  1905. end;
  1906. function tarraydef.elecount : aword;
  1907. var
  1908. qhigh,qlow : qword;
  1909. begin
  1910. if ado_IsDynamicArray in arrayoptions then
  1911. begin
  1912. result:=0;
  1913. exit;
  1914. end;
  1915. if (highrange>0) and (lowrange<0) then
  1916. begin
  1917. qhigh:=highrange;
  1918. qlow:=qword(-lowrange);
  1919. { prevent overflow, return 0 to indicate overflow }
  1920. if qhigh+qlow>qword(high(aint)-1) then
  1921. result:=0
  1922. else
  1923. result:=qhigh+qlow+1;
  1924. end
  1925. else
  1926. result:=int64(highrange)-lowrange+1;
  1927. end;
  1928. function tarraydef.size : aint;
  1929. var
  1930. cachedelecount : aword;
  1931. cachedelesize : aint;
  1932. begin
  1933. if ado_IsDynamicArray in arrayoptions then
  1934. begin
  1935. size:=sizeof(aint);
  1936. exit;
  1937. end;
  1938. { Tarraydef.size may never be called for an open array! }
  1939. if highrange<lowrange then
  1940. internalerror(99080501);
  1941. if not (ado_IsBitPacked in arrayoptions) then
  1942. cachedelesize:=elesize
  1943. else
  1944. cachedelesize := elepackedbitsize;
  1945. cachedelecount:=elecount;
  1946. if (cachedelesize = 0) then
  1947. begin
  1948. size := 0;
  1949. exit;
  1950. end;
  1951. if (cachedelecount = 0) then
  1952. begin
  1953. size := -1;
  1954. exit;
  1955. end;
  1956. { prevent overflow, return -1 to indicate overflow }
  1957. { also make sure we don't need 64/128 bit arithmetic to calculate offsets }
  1958. if (cachedelecount > high(aint)) or
  1959. ((high(aint) div cachedelesize) < cachedelecount) or
  1960. { also lowrange*elesize must be < high(aint) to prevent overflow when
  1961. accessing the array, see ncgmem (PFV) }
  1962. ((high(aint) div cachedelesize) < abs(lowrange)) then
  1963. begin
  1964. result:=-1;
  1965. exit;
  1966. end;
  1967. if (ado_IsBitPacked in arrayoptions) then
  1968. size:=(cachedelesize * cachedelecount + 7) div 8
  1969. else
  1970. result:=cachedelesize*cachedelecount;
  1971. end;
  1972. procedure tarraydef.setelementdef(def:tdef);
  1973. begin
  1974. _elementdef:=def;
  1975. if not(
  1976. (ado_IsDynamicArray in arrayoptions) or
  1977. (ado_IsConvertedPointer in arrayoptions) or
  1978. (highrange<lowrange)
  1979. ) and
  1980. (size=-1) then
  1981. Message(sym_e_segment_too_large);
  1982. end;
  1983. function tarraydef.alignment : shortint;
  1984. begin
  1985. { alignment of dyn. arrays doesn't depend on the element size }
  1986. if (ado_IsDynamicArray in arrayoptions) then
  1987. alignment:=size_2_align(sizeof(aint))
  1988. { alignment is the size of the elements }
  1989. else if (elementdef.typ in [arraydef,recorddef]) or
  1990. ((elementdef.typ=objectdef) and
  1991. is_object(elementdef)) then
  1992. alignment:=elementdef.alignment
  1993. else if not (ado_IsBitPacked in arrayoptions) then
  1994. alignment:=size_2_align(elesize)
  1995. else
  1996. alignment:=packedbitsloadsize(elepackedbitsize);
  1997. end;
  1998. function tarraydef.needs_inittable : boolean;
  1999. begin
  2000. needs_inittable:=(ado_IsDynamicArray in arrayoptions) or elementdef.needs_inittable;
  2001. end;
  2002. function tarraydef.GetTypeName : string;
  2003. begin
  2004. if (ado_IsConstString in arrayoptions) then
  2005. result:='Constant String'
  2006. else if (ado_isarrayofconst in arrayoptions) or
  2007. (ado_isConstructor in arrayoptions) then
  2008. begin
  2009. if (ado_isvariant in arrayoptions) or ((highrange=-1) and (lowrange=0)) then
  2010. GetTypeName:='Array Of Const'
  2011. else
  2012. GetTypeName:='Array Of Const/Constant Open Array of '+elementdef.typename;
  2013. end
  2014. else if (ado_IsDynamicArray in arrayoptions) then
  2015. GetTypeName:='Dynamic Array Of '+elementdef.typename
  2016. else if ((highrange=-1) and (lowrange=0)) then
  2017. GetTypeName:='Open Array Of '+elementdef.typename
  2018. else
  2019. begin
  2020. result := '';
  2021. if (ado_IsBitPacked in arrayoptions) then
  2022. result:='Packed ';
  2023. if rangedef.typ=enumdef then
  2024. result:=result+'Array['+rangedef.typename+'] Of '+elementdef.typename
  2025. else
  2026. result:=result+'Array['+tostr(lowrange)+'..'+
  2027. tostr(highrange)+'] Of '+elementdef.typename
  2028. end;
  2029. end;
  2030. function tarraydef.getmangledparaname : string;
  2031. begin
  2032. if ado_isarrayofconst in arrayoptions then
  2033. getmangledparaname:='array_of_const'
  2034. else
  2035. if ((highrange=-1) and (lowrange=0)) then
  2036. getmangledparaname:='array_of_'+elementdef.mangledparaname
  2037. else
  2038. internalerror(200204176);
  2039. end;
  2040. {***************************************************************************
  2041. tabstractrecorddef
  2042. ***************************************************************************}
  2043. function tabstractrecorddef.GetSymtable(t:tGetSymtable):TSymtable;
  2044. begin
  2045. if t=gs_record then
  2046. GetSymtable:=symtable
  2047. else
  2048. GetSymtable:=nil;
  2049. end;
  2050. procedure tabstractrecorddef.reset;
  2051. begin
  2052. inherited reset;
  2053. tstoredsymtable(symtable).reset_all_defs;
  2054. end;
  2055. function tabstractrecorddef.is_packed:boolean;
  2056. begin
  2057. result:=tabstractrecordsymtable(symtable).is_packed;
  2058. end;
  2059. {***************************************************************************
  2060. trecorddef
  2061. ***************************************************************************}
  2062. constructor trecorddef.create(p : TSymtable);
  2063. begin
  2064. inherited create(recorddef);
  2065. symtable:=p;
  2066. symtable.defowner:=self;
  2067. isunion:=false;
  2068. end;
  2069. constructor trecorddef.ppuload(ppufile:tcompilerppufile);
  2070. begin
  2071. inherited ppuload(recorddef,ppufile);
  2072. symtable:=trecordsymtable.create(0);
  2073. trecordsymtable(symtable).fieldalignment:=shortint(ppufile.getbyte);
  2074. trecordsymtable(symtable).recordalignment:=shortint(ppufile.getbyte);
  2075. trecordsymtable(symtable).padalignment:=shortint(ppufile.getbyte);
  2076. trecordsymtable(symtable).usefieldalignment:=shortint(ppufile.getbyte);
  2077. { requires usefieldalignment to be set }
  2078. trecordsymtable(symtable).datasize:=ppufile.getaint;
  2079. trecordsymtable(symtable).ppuload(ppufile);
  2080. symtable.defowner:=self;
  2081. isunion:=false;
  2082. end;
  2083. destructor trecorddef.destroy;
  2084. begin
  2085. if assigned(symtable) then
  2086. begin
  2087. symtable.free;
  2088. symtable:=nil;
  2089. end;
  2090. inherited destroy;
  2091. end;
  2092. function trecorddef.getcopy : tstoreddef;
  2093. begin
  2094. result:=trecorddef.create(symtable.getcopy);
  2095. trecorddef(result).isunion:=isunion;
  2096. end;
  2097. function trecorddef.needs_inittable : boolean;
  2098. begin
  2099. needs_inittable:=trecordsymtable(symtable).needs_init_final
  2100. end;
  2101. procedure trecorddef.buildderef;
  2102. begin
  2103. inherited buildderef;
  2104. tstoredsymtable(symtable).buildderef;
  2105. end;
  2106. procedure trecorddef.deref;
  2107. begin
  2108. inherited deref;
  2109. { now dereference the definitions }
  2110. tstoredsymtable(symtable).deref;
  2111. { assign TGUID? load only from system unit }
  2112. if not(assigned(rec_tguid)) and
  2113. (upper(typename)='TGUID') and
  2114. assigned(owner) and
  2115. assigned(owner.name) and
  2116. (owner.name^='SYSTEM') then
  2117. rec_tguid:=self;
  2118. end;
  2119. procedure trecorddef.ppuwrite(ppufile:tcompilerppufile);
  2120. begin
  2121. inherited ppuwrite(ppufile);
  2122. ppufile.putbyte(byte(trecordsymtable(symtable).fieldalignment));
  2123. ppufile.putbyte(byte(trecordsymtable(symtable).recordalignment));
  2124. ppufile.putbyte(byte(trecordsymtable(symtable).padalignment));
  2125. ppufile.putbyte(byte(trecordsymtable(symtable).usefieldalignment));
  2126. ppufile.putaint(trecordsymtable(symtable).datasize);
  2127. ppufile.writeentry(ibrecorddef);
  2128. trecordsymtable(symtable).ppuwrite(ppufile);
  2129. end;
  2130. function trecorddef.size:aint;
  2131. begin
  2132. result:=trecordsymtable(symtable).datasize;
  2133. end;
  2134. function trecorddef.alignment:shortint;
  2135. begin
  2136. alignment:=trecordsymtable(symtable).recordalignment;
  2137. end;
  2138. function trecorddef.padalignment:shortint;
  2139. begin
  2140. padalignment := trecordsymtable(symtable).padalignment;
  2141. end;
  2142. function trecorddef.GetTypeName : string;
  2143. begin
  2144. GetTypeName:='<record type>'
  2145. end;
  2146. {***************************************************************************
  2147. TABSTRACTPROCDEF
  2148. ***************************************************************************}
  2149. constructor tabstractprocdef.create(dt:tdeftyp;level:byte);
  2150. begin
  2151. inherited create(dt);
  2152. parast:=tparasymtable.create(self,level);
  2153. paras:=nil;
  2154. minparacount:=0;
  2155. maxparacount:=0;
  2156. proctypeoption:=potype_none;
  2157. proccalloption:=pocall_none;
  2158. procoptions:=[];
  2159. returndef:=voidtype;
  2160. {$ifdef i386}
  2161. fpu_used:=0;
  2162. {$endif i386}
  2163. savesize:=sizeof(aint);
  2164. requiredargarea:=0;
  2165. has_paraloc_info:=false;
  2166. location_reset(funcretloc[callerside],LOC_INVALID,OS_NO);
  2167. location_reset(funcretloc[calleeside],LOC_INVALID,OS_NO);
  2168. end;
  2169. destructor tabstractprocdef.destroy;
  2170. begin
  2171. if assigned(paras) then
  2172. begin
  2173. {$ifdef MEMDEBUG}
  2174. memprocpara.start;
  2175. {$endif MEMDEBUG}
  2176. paras.free;
  2177. paras:=nil;
  2178. {$ifdef MEMDEBUG}
  2179. memprocpara.stop;
  2180. {$endif MEMDEBUG}
  2181. end;
  2182. if assigned(parast) then
  2183. begin
  2184. {$ifdef MEMDEBUG}
  2185. memprocparast.start;
  2186. {$endif MEMDEBUG}
  2187. parast.free;
  2188. parast:=nil;
  2189. {$ifdef MEMDEBUG}
  2190. memprocparast.stop;
  2191. {$endif MEMDEBUG}
  2192. end;
  2193. inherited destroy;
  2194. end;
  2195. procedure tabstractprocdef.count_para(p:TObject;arg:pointer);
  2196. begin
  2197. if (tsym(p).typ<>paravarsym) then
  2198. exit;
  2199. inc(plongint(arg)^);
  2200. if not(vo_is_hidden_para in tparavarsym(p).varoptions) then
  2201. begin
  2202. if not assigned(tparavarsym(p).defaultconstsym) then
  2203. inc(minparacount);
  2204. inc(maxparacount);
  2205. end;
  2206. end;
  2207. procedure tabstractprocdef.insert_para(p:TObject;arg:pointer);
  2208. begin
  2209. if (tsym(p).typ<>paravarsym) then
  2210. exit;
  2211. paras.add(p);
  2212. end;
  2213. procedure tabstractprocdef.calcparas;
  2214. var
  2215. paracount : longint;
  2216. begin
  2217. { This can already be assigned when
  2218. we need to reresolve this unit (PFV) }
  2219. if assigned(paras) then
  2220. paras.free;
  2221. paras:=tparalist.create(false);
  2222. paracount:=0;
  2223. minparacount:=0;
  2224. maxparacount:=0;
  2225. parast.SymList.ForEachCall(@count_para,@paracount);
  2226. paras.capacity:=paracount;
  2227. { Insert parameters in table }
  2228. parast.SymList.ForEachCall(@insert_para,nil);
  2229. { Order parameters }
  2230. paras.sortparas;
  2231. end;
  2232. { all functions returning in FPU are
  2233. assume to use 2 FPU registers
  2234. until the function implementation
  2235. is processed PM }
  2236. procedure tabstractprocdef.test_if_fpu_result;
  2237. begin
  2238. {$ifdef i386}
  2239. if assigned(returndef) and
  2240. (returndef.typ=floatdef) then
  2241. fpu_used:=maxfpuregs;
  2242. {$endif i386}
  2243. end;
  2244. procedure tabstractprocdef.buildderef;
  2245. begin
  2246. { released procdef? }
  2247. if not assigned(parast) then
  2248. exit;
  2249. inherited buildderef;
  2250. returndefderef.build(returndef);
  2251. { parast }
  2252. tparasymtable(parast).buildderef;
  2253. end;
  2254. procedure tabstractprocdef.deref;
  2255. begin
  2256. inherited deref;
  2257. returndef:=tdef(returndefderef.resolve);
  2258. { parast }
  2259. tparasymtable(parast).deref;
  2260. { recalculated parameters }
  2261. calcparas;
  2262. end;
  2263. constructor tabstractprocdef.ppuload(dt:tdeftyp;ppufile:tcompilerppufile);
  2264. var
  2265. b : byte;
  2266. begin
  2267. inherited ppuload(dt,ppufile);
  2268. parast:=nil;
  2269. Paras:=nil;
  2270. minparacount:=0;
  2271. maxparacount:=0;
  2272. ppufile.getderef(returndefderef);
  2273. {$ifdef i386}
  2274. fpu_used:=ppufile.getbyte;
  2275. {$else}
  2276. ppufile.getbyte;
  2277. {$endif i386}
  2278. proctypeoption:=tproctypeoption(ppufile.getbyte);
  2279. proccalloption:=tproccalloption(ppufile.getbyte);
  2280. ppufile.getnormalset(procoptions);
  2281. location_reset(funcretloc[callerside],LOC_INVALID,OS_NO);
  2282. location_reset(funcretloc[calleeside],LOC_INVALID,OS_NO);
  2283. if po_explicitparaloc in procoptions then
  2284. begin
  2285. b:=ppufile.getbyte;
  2286. if b<>sizeof(funcretloc[callerside]) then
  2287. internalerror(200411154);
  2288. ppufile.getdata(funcretloc[callerside],sizeof(funcretloc[callerside]));
  2289. end;
  2290. savesize:=sizeof(aint);
  2291. has_paraloc_info:=(po_explicitparaloc in procoptions);
  2292. end;
  2293. procedure tabstractprocdef.ppuwrite(ppufile:tcompilerppufile);
  2294. var
  2295. oldintfcrc : boolean;
  2296. begin
  2297. { released procdef? }
  2298. if not assigned(parast) then
  2299. exit;
  2300. inherited ppuwrite(ppufile);
  2301. ppufile.putderef(returndefderef);
  2302. oldintfcrc:=ppufile.do_interface_crc;
  2303. ppufile.do_interface_crc:=false;
  2304. {$ifdef i386}
  2305. if simplify_ppu then
  2306. fpu_used:=0;
  2307. ppufile.putbyte(fpu_used);
  2308. {$else}
  2309. ppufile.putbyte(0);
  2310. {$endif}
  2311. ppufile.putbyte(ord(proctypeoption));
  2312. ppufile.putbyte(ord(proccalloption));
  2313. ppufile.putnormalset(procoptions);
  2314. ppufile.do_interface_crc:=oldintfcrc;
  2315. if (po_explicitparaloc in procoptions) then
  2316. begin
  2317. { Make a 'valid' funcretloc for procedures }
  2318. ppufile.putbyte(sizeof(funcretloc[callerside]));
  2319. ppufile.putdata(funcretloc[callerside],sizeof(funcretloc[callerside]));
  2320. end;
  2321. end;
  2322. function tabstractprocdef.typename_paras(showhidden:boolean) : string;
  2323. var
  2324. hs,s : string;
  2325. hp : TParavarsym;
  2326. hpc : tconstsym;
  2327. first : boolean;
  2328. i : integer;
  2329. begin
  2330. s:='';
  2331. first:=true;
  2332. for i:=0 to paras.count-1 do
  2333. begin
  2334. hp:=tparavarsym(paras[i]);
  2335. if not(vo_is_hidden_para in hp.varoptions) or
  2336. (showhidden) then
  2337. begin
  2338. if first then
  2339. begin
  2340. s:=s+'(';
  2341. first:=false;
  2342. end
  2343. else
  2344. s:=s+',';
  2345. if vo_is_hidden_para in hp.varoptions then
  2346. s:=s+'<';
  2347. case hp.varspez of
  2348. vs_var :
  2349. s:=s+'var';
  2350. vs_const :
  2351. s:=s+'const';
  2352. vs_out :
  2353. s:=s+'out';
  2354. end;
  2355. if assigned(hp.vardef.typesym) then
  2356. begin
  2357. if s<>'(' then
  2358. s:=s+' ';
  2359. hs:=hp.vardef.typesym.realname;
  2360. if hs[1]<>'$' then
  2361. s:=s+hp.vardef.typesym.realname
  2362. else
  2363. s:=s+hp.vardef.GetTypeName;
  2364. end
  2365. else
  2366. s:=s+hp.vardef.GetTypeName;
  2367. { default value }
  2368. if assigned(hp.defaultconstsym) then
  2369. begin
  2370. hpc:=tconstsym(hp.defaultconstsym);
  2371. hs:='';
  2372. case hpc.consttyp of
  2373. conststring,
  2374. constresourcestring :
  2375. hs:=strpas(pchar(hpc.value.valueptr));
  2376. constreal :
  2377. str(pbestreal(hpc.value.valueptr)^,hs);
  2378. constpointer :
  2379. hs:=tostr(hpc.value.valueordptr);
  2380. constord :
  2381. begin
  2382. if is_boolean(hpc.constdef) then
  2383. begin
  2384. if hpc.value.valueord<>0 then
  2385. hs:='TRUE'
  2386. else
  2387. hs:='FALSE';
  2388. end
  2389. else
  2390. hs:=tostr(hpc.value.valueord);
  2391. end;
  2392. constnil :
  2393. hs:='nil';
  2394. constset :
  2395. hs:='<set>';
  2396. end;
  2397. if hs<>'' then
  2398. s:=s+'="'+hs+'"';
  2399. end;
  2400. if vo_is_hidden_para in hp.varoptions then
  2401. s:=s+'>';
  2402. end;
  2403. end;
  2404. if not first then
  2405. s:=s+')';
  2406. if (po_varargs in procoptions) then
  2407. s:=s+';VarArgs';
  2408. typename_paras:=s;
  2409. end;
  2410. function tabstractprocdef.is_methodpointer:boolean;
  2411. begin
  2412. result:=false;
  2413. end;
  2414. function tabstractprocdef.is_addressonly:boolean;
  2415. begin
  2416. result:=true;
  2417. end;
  2418. {***************************************************************************
  2419. TPROCDEF
  2420. ***************************************************************************}
  2421. constructor tprocdef.create(level:byte);
  2422. begin
  2423. inherited create(procdef,level);
  2424. localst:=tlocalsymtable.create(self,parast.symtablelevel);
  2425. _mangledname:=nil;
  2426. fileinfo:=current_filepos;
  2427. extnumber:=$ffff;
  2428. aliasnames:=TCmdStrList.create;
  2429. funcretsym:=nil;
  2430. forwarddef:=true;
  2431. interfacedef:=false;
  2432. hasforward:=false;
  2433. _class := nil;
  2434. import_dll:=nil;
  2435. import_name:=nil;
  2436. import_nr:=0;
  2437. inlininginfo:=nil;
  2438. end;
  2439. constructor tprocdef.ppuload(ppufile:tcompilerppufile);
  2440. var
  2441. level : byte;
  2442. begin
  2443. inherited ppuload(procdef,ppufile);
  2444. if po_has_mangledname in procoptions then
  2445. _mangledname:=stringdup(ppufile.getstring)
  2446. else
  2447. _mangledname:=nil;
  2448. extnumber:=ppufile.getword;
  2449. level:=ppufile.getbyte;
  2450. ppufile.getderef(_classderef);
  2451. ppufile.getderef(procsymderef);
  2452. ppufile.getposinfo(fileinfo);
  2453. ppufile.getsmallset(symoptions);
  2454. {$ifdef powerpc}
  2455. { library symbol for AmigaOS/MorphOS }
  2456. ppufile.getderef(libsymderef);
  2457. {$endif powerpc}
  2458. { import stuff }
  2459. if po_has_importdll in procoptions then
  2460. import_dll:=stringdup(ppufile.getstring)
  2461. else
  2462. import_dll:=nil;
  2463. if po_has_importname in procoptions then
  2464. import_name:=stringdup(ppufile.getstring)
  2465. else
  2466. import_name:=nil;
  2467. import_nr:=ppufile.getword;
  2468. if (po_msgint in procoptions) then
  2469. messageinf.i:=ppufile.getlongint;
  2470. if (po_msgstr in procoptions) then
  2471. messageinf.str:=stringdup(ppufile.getstring);
  2472. if (po_dispid in procoptions) then
  2473. dispid:=ppufile.getlongint;
  2474. { inline stuff }
  2475. if (po_has_inlininginfo in procoptions) then
  2476. begin
  2477. ppufile.getderef(funcretsymderef);
  2478. new(inlininginfo);
  2479. ppufile.getsmallset(inlininginfo^.flags);
  2480. end
  2481. else
  2482. begin
  2483. inlininginfo:=nil;
  2484. funcretsym:=nil;
  2485. end;
  2486. { load para symtable }
  2487. parast:=tparasymtable.create(self,level);
  2488. tparasymtable(parast).ppuload(ppufile);
  2489. { load local symtable }
  2490. if (po_has_inlininginfo in procoptions) then
  2491. begin
  2492. localst:=tlocalsymtable.create(self,level);
  2493. tlocalsymtable(localst).ppuload(ppufile);
  2494. end
  2495. else
  2496. localst:=nil;
  2497. { inline stuff }
  2498. if (po_has_inlininginfo in procoptions) then
  2499. inlininginfo^.code:=ppuloadnodetree(ppufile);
  2500. { default values for no persistent data }
  2501. if (cs_link_deffile in current_settings.globalswitches) and
  2502. (tf_need_export in target_info.flags) and
  2503. (po_exports in procoptions) then
  2504. deffile.AddExport(mangledname);
  2505. aliasnames:=TCmdStrList.create;
  2506. forwarddef:=false;
  2507. interfacedef:=false;
  2508. hasforward:=false;
  2509. { Disable po_has_inlining until the derefimpl is done }
  2510. exclude(procoptions,po_has_inlininginfo);
  2511. end;
  2512. destructor tprocdef.destroy;
  2513. begin
  2514. aliasnames.free;
  2515. aliasnames:=nil;
  2516. if assigned(localst) and
  2517. (localst.symtabletype<>staticsymtable) then
  2518. begin
  2519. {$ifdef MEMDEBUG}
  2520. memproclocalst.start;
  2521. {$endif MEMDEBUG}
  2522. localst.free;
  2523. localst:=nil;
  2524. {$ifdef MEMDEBUG}
  2525. memproclocalst.start;
  2526. {$endif MEMDEBUG}
  2527. end;
  2528. if assigned(inlininginfo) then
  2529. begin
  2530. {$ifdef MEMDEBUG}
  2531. memprocnodetree.start;
  2532. {$endif MEMDEBUG}
  2533. tnode(inlininginfo^.code).free;
  2534. {$ifdef MEMDEBUG}
  2535. memprocnodetree.start;
  2536. {$endif MEMDEBUG}
  2537. dispose(inlininginfo);
  2538. inlininginfo:=nil;
  2539. end;
  2540. stringdispose(resultname);
  2541. stringdispose(import_dll);
  2542. stringdispose(import_name);
  2543. if (po_msgstr in procoptions) then
  2544. stringdispose(messageinf.str);
  2545. if assigned(_mangledname) then
  2546. begin
  2547. {$ifdef MEMDEBUG}
  2548. memmanglednames.start;
  2549. {$endif MEMDEBUG}
  2550. stringdispose(_mangledname);
  2551. {$ifdef MEMDEBUG}
  2552. memmanglednames.stop;
  2553. {$endif MEMDEBUG}
  2554. end;
  2555. inherited destroy;
  2556. end;
  2557. procedure tprocdef.ppuwrite(ppufile:tcompilerppufile);
  2558. var
  2559. oldintfcrc : boolean;
  2560. begin
  2561. { released procdef? }
  2562. if not assigned(parast) then
  2563. exit;
  2564. inherited ppuwrite(ppufile);
  2565. if po_has_mangledname in procoptions then
  2566. ppufile.putstring(_mangledname^);
  2567. ppufile.putword(extnumber);
  2568. ppufile.putbyte(parast.symtablelevel);
  2569. ppufile.putderef(_classderef);
  2570. ppufile.putderef(procsymderef);
  2571. ppufile.putposinfo(fileinfo);
  2572. ppufile.putsmallset(symoptions);
  2573. {$ifdef powerpc}
  2574. { library symbol for AmigaOS/MorphOS }
  2575. ppufile.putderef(libsymderef);
  2576. {$endif powerpc}
  2577. { import }
  2578. if po_has_importdll in procoptions then
  2579. ppufile.putstring(import_dll^);
  2580. if po_has_importname in procoptions then
  2581. ppufile.putstring(import_name^);
  2582. ppufile.putword(import_nr);
  2583. if (po_msgint in procoptions) then
  2584. ppufile.putlongint(messageinf.i);
  2585. if (po_msgstr in procoptions) then
  2586. ppufile.putstring(messageinf.str^);
  2587. if (po_dispid in procoptions) then
  2588. ppufile.putlongint(dispid);
  2589. { inline stuff }
  2590. oldintfcrc:=ppufile.do_crc;
  2591. ppufile.do_crc:=false;
  2592. if (po_has_inlininginfo in procoptions) then
  2593. begin
  2594. ppufile.putderef(funcretsymderef);
  2595. ppufile.putsmallset(inlininginfo^.flags);
  2596. end;
  2597. ppufile.do_crc:=oldintfcrc;
  2598. { write this entry }
  2599. ppufile.writeentry(ibprocdef);
  2600. { Save the para symtable, this is taken from the interface }
  2601. tparasymtable(parast).ppuwrite(ppufile);
  2602. { save localsymtable for inline procedures or when local
  2603. browser info is requested, this has no influence on the crc }
  2604. if (po_has_inlininginfo in procoptions) then
  2605. begin
  2606. oldintfcrc:=ppufile.do_crc;
  2607. ppufile.do_crc:=false;
  2608. tlocalsymtable(localst).ppuwrite(ppufile);
  2609. ppufile.do_crc:=oldintfcrc;
  2610. end;
  2611. { node tree for inlining }
  2612. oldintfcrc:=ppufile.do_crc;
  2613. ppufile.do_crc:=false;
  2614. if (po_has_inlininginfo in procoptions) then
  2615. ppuwritenodetree(ppufile,inlininginfo^.code);
  2616. ppufile.do_crc:=oldintfcrc;
  2617. end;
  2618. procedure tprocdef.reset;
  2619. begin
  2620. inherited reset;
  2621. procstarttai:=nil;
  2622. procendtai:=nil;
  2623. end;
  2624. function tprocdef.fullprocname(showhidden:boolean):string;
  2625. var
  2626. s : string;
  2627. t : ttoken;
  2628. begin
  2629. {$ifdef EXTDEBUG}
  2630. showhidden:=true;
  2631. {$endif EXTDEBUG}
  2632. s:='';
  2633. if owner.symtabletype=localsymtable then
  2634. s:=s+'local ';
  2635. if assigned(_class) then
  2636. begin
  2637. if po_classmethod in procoptions then
  2638. s:=s+'class ';
  2639. s:=s+_class.objrealname^+'.';
  2640. end;
  2641. if proctypeoption=potype_operator then
  2642. begin
  2643. for t:=NOTOKEN to last_overloaded do
  2644. if procsym.realname='$'+overloaded_names[t] then
  2645. begin
  2646. s:='operator '+arraytokeninfo[t].str+typename_paras(showhidden);
  2647. break;
  2648. end;
  2649. end
  2650. else
  2651. s:=s+procsym.realname+typename_paras(showhidden);
  2652. case proctypeoption of
  2653. potype_constructor:
  2654. s:='constructor '+s;
  2655. potype_destructor:
  2656. s:='destructor '+s;
  2657. else
  2658. if assigned(returndef) and
  2659. not(is_void(returndef)) then
  2660. s:=s+':'+returndef.GetTypeName;
  2661. end;
  2662. { forced calling convention? }
  2663. if (po_hascallingconvention in procoptions) then
  2664. s:=s+';'+ProcCallOptionStr[proccalloption];
  2665. fullprocname:=s;
  2666. end;
  2667. function tprocdef.is_methodpointer:boolean;
  2668. begin
  2669. result:=assigned(_class);
  2670. end;
  2671. function tprocdef.is_addressonly:boolean;
  2672. begin
  2673. result:=assigned(owner) and
  2674. (owner.symtabletype<>ObjectSymtable);
  2675. end;
  2676. function tprocdef.is_visible_for_object(currobjdef,contextobjdef:tobjectdef):boolean;
  2677. var
  2678. contextst : TSymtable;
  2679. begin
  2680. result:=false;
  2681. { Support passing a context in which module we are to find protected members }
  2682. if assigned(contextobjdef) then
  2683. contextst:=contextobjdef.owner
  2684. else
  2685. contextst:=nil;
  2686. { private symbols are allowed when we are in the same
  2687. module as they are defined }
  2688. if (sp_private in symoptions) and
  2689. (owner.defowner.owner.symtabletype in [globalsymtable,staticsymtable]) and
  2690. not(owner.defowner.owner.iscurrentunit or (owner.defowner.owner=contextst)) then
  2691. exit;
  2692. if (sp_strictprivate in symoptions) then
  2693. begin
  2694. result:=currobjdef=tobjectdef(owner.defowner);
  2695. exit;
  2696. end;
  2697. if (sp_strictprotected in symoptions) then
  2698. begin
  2699. result:=assigned(currobjdef) and
  2700. currobjdef.is_related(tobjectdef(owner.defowner));
  2701. exit;
  2702. end;
  2703. { protected symbols are visible in the module that defines them and
  2704. also visible to related objects. The related object must be defined
  2705. in the current module }
  2706. if (sp_protected in symoptions) and
  2707. (
  2708. (
  2709. (owner.defowner.owner.symtabletype in [globalsymtable,staticsymtable]) and
  2710. not((owner.defowner.owner.iscurrentunit) or (owner.defowner.owner=contextst))
  2711. ) and
  2712. not(
  2713. assigned(currobjdef) and
  2714. (currobjdef.owner.symtabletype in [globalsymtable,staticsymtable]) and
  2715. (currobjdef.owner.iscurrentunit) and
  2716. currobjdef.is_related(tobjectdef(owner.defowner))
  2717. )
  2718. ) then
  2719. exit;
  2720. result:=true;
  2721. end;
  2722. function tprocdef.GetSymtable(t:tGetSymtable):TSymtable;
  2723. begin
  2724. case t of
  2725. gs_local :
  2726. GetSymtable:=localst;
  2727. gs_para :
  2728. GetSymtable:=parast;
  2729. else
  2730. GetSymtable:=nil;
  2731. end;
  2732. end;
  2733. procedure tprocdef.buildderef;
  2734. begin
  2735. inherited buildderef;
  2736. _classderef.build(_class);
  2737. { procsym that originaly defined this definition, should be in the
  2738. same symtable }
  2739. procsymderef.build(procsym);
  2740. {$ifdef powerpc}
  2741. { library symbol for AmigaOS/MorphOS }
  2742. libsymderef.build(libsym);
  2743. {$endif powerpc}
  2744. end;
  2745. procedure tprocdef.buildderefimpl;
  2746. begin
  2747. inherited buildderefimpl;
  2748. { Localst is not available for main/unit init }
  2749. if assigned(localst) then
  2750. begin
  2751. tlocalsymtable(localst).buildderef;
  2752. tlocalsymtable(localst).buildderefimpl;
  2753. end;
  2754. { inline tree }
  2755. if (po_has_inlininginfo in procoptions) then
  2756. begin
  2757. funcretsymderef.build(funcretsym);
  2758. inlininginfo^.code.buildderefimpl;
  2759. end;
  2760. end;
  2761. procedure tprocdef.deref;
  2762. begin
  2763. inherited deref;
  2764. _class:=tobjectdef(_classderef.resolve);
  2765. { procsym that originaly defined this definition, should be in the
  2766. same symtable }
  2767. procsym:=tprocsym(procsymderef.resolve);
  2768. {$ifdef powerpc}
  2769. { library symbol for AmigaOS/MorphOS }
  2770. libsym:=tsym(libsymderef.resolve);
  2771. {$endif powerpc}
  2772. end;
  2773. procedure tprocdef.derefimpl;
  2774. begin
  2775. { Enable has_inlininginfo when the inlininginfo
  2776. structure is available. The has_inlininginfo was disabled
  2777. after the load, since the data was invalid }
  2778. if assigned(inlininginfo) then
  2779. include(procoptions,po_has_inlininginfo);
  2780. { Locals }
  2781. if assigned(localst) then
  2782. begin
  2783. tlocalsymtable(localst).deref;
  2784. tlocalsymtable(localst).derefimpl;
  2785. end;
  2786. { Inline }
  2787. if (po_has_inlininginfo in procoptions) then
  2788. begin
  2789. inlininginfo^.code.derefimpl;
  2790. { funcretsym, this is always located in the localst }
  2791. funcretsym:=tsym(funcretsymderef.resolve);
  2792. end
  2793. else
  2794. begin
  2795. { safety }
  2796. funcretsym:=nil;
  2797. end;
  2798. end;
  2799. function tprocdef.GetTypeName : string;
  2800. begin
  2801. GetTypeName := FullProcName(false);
  2802. end;
  2803. function tprocdef.mangledname : string;
  2804. var
  2805. hp : TParavarsym;
  2806. hs : string;
  2807. crc : dword;
  2808. newlen,
  2809. oldlen,
  2810. i : integer;
  2811. begin
  2812. if assigned(_mangledname) then
  2813. begin
  2814. {$ifdef compress}
  2815. mangledname:=minilzw_decode(_mangledname^);
  2816. {$else}
  2817. mangledname:=_mangledname^;
  2818. {$endif}
  2819. exit;
  2820. end;
  2821. { we need to use the symtable where the procsym is inserted,
  2822. because that is visible to the world }
  2823. mangledname:=make_mangledname('',procsym.owner,procsym.name);
  2824. oldlen:=length(mangledname);
  2825. { add parameter types }
  2826. for i:=0 to paras.count-1 do
  2827. begin
  2828. hp:=tparavarsym(paras[i]);
  2829. if not(vo_is_hidden_para in hp.varoptions) then
  2830. mangledname:=mangledname+'$'+hp.vardef.mangledparaname;
  2831. end;
  2832. { add resultdef, add $$ as separator to make it unique from a
  2833. parameter separator }
  2834. if not is_void(returndef) then
  2835. mangledname:=mangledname+'$$'+returndef.mangledparaname;
  2836. newlen:=length(mangledname);
  2837. { Replace with CRC if the parameter line is very long }
  2838. if (newlen-oldlen>12) and
  2839. ((newlen>128) or (newlen-oldlen>64)) then
  2840. begin
  2841. crc:=$ffffffff;
  2842. for i:=0 to paras.count-1 do
  2843. begin
  2844. hp:=tparavarsym(paras[i]);
  2845. if not(vo_is_hidden_para in hp.varoptions) then
  2846. begin
  2847. hs:=hp.vardef.mangledparaname;
  2848. crc:=UpdateCrc32(crc,hs[1],length(hs));
  2849. end;
  2850. end;
  2851. hs:=hp.vardef.mangledparaname;
  2852. crc:=UpdateCrc32(crc,hs[1],length(hs));
  2853. mangledname:=Copy(mangledname,1,oldlen)+'$crc'+hexstr(crc,8);
  2854. end;
  2855. {$ifdef compress}
  2856. _mangledname:=stringdup(minilzw_encode(mangledname));
  2857. {$else}
  2858. _mangledname:=stringdup(mangledname);
  2859. {$endif}
  2860. end;
  2861. function tprocdef.cplusplusmangledname : string;
  2862. function getcppparaname(p : tdef) : string;
  2863. const
  2864. ordtype2str : array[tordtype] of string[2] = (
  2865. '',
  2866. 'Uc','Us','Ui','Us',
  2867. 'Sc','s','i','x',
  2868. 'b','b','b','b',
  2869. 'c','w','x');
  2870. var
  2871. s : string;
  2872. begin
  2873. case p.typ of
  2874. orddef:
  2875. s:=ordtype2str[torddef(p).ordtype];
  2876. pointerdef:
  2877. s:='P'+getcppparaname(tpointerdef(p).pointeddef);
  2878. else
  2879. internalerror(2103001);
  2880. end;
  2881. getcppparaname:=s;
  2882. end;
  2883. var
  2884. s,s2 : string;
  2885. hp : TParavarsym;
  2886. i : integer;
  2887. begin
  2888. { outdated gcc 2.x name mangling scheme }
  2889. {$ifdef NAMEMANGLING_GCC2}
  2890. s := procsym.realname;
  2891. if procsym.owner.symtabletype=ObjectSymtable then
  2892. begin
  2893. s2:=upper(tobjectdef(procsym.owner.defowner).objrealname^);
  2894. case proctypeoption of
  2895. potype_destructor:
  2896. s:='_$_'+tostr(length(s2))+s2;
  2897. potype_constructor:
  2898. s:='___'+tostr(length(s2))+s2;
  2899. else
  2900. s:='_'+s+'__'+tostr(length(s2))+s2;
  2901. end;
  2902. end
  2903. else s:=s+'__';
  2904. s:=s+'F';
  2905. { concat modifiers }
  2906. { !!!!! }
  2907. { now we handle the parameters }
  2908. if maxparacount>0 then
  2909. begin
  2910. for i:=0 to paras.count-1 do
  2911. begin
  2912. hp:=tparavarsym(paras[i]);
  2913. s2:=getcppparaname(hp.vardef);
  2914. if hp.varspez in [vs_var,vs_out] then
  2915. s2:='R'+s2;
  2916. s:=s+s2;
  2917. end;
  2918. end
  2919. else
  2920. s:=s+'v';
  2921. cplusplusmangledname:=s;
  2922. {$endif NAMEMANGLING_GCC2}
  2923. { gcc 3.x name mangling scheme }
  2924. if procsym.owner.symtabletype=ObjectSymtable then
  2925. begin
  2926. s:='_ZN';
  2927. s2:=tobjectdef(procsym.owner.defowner).objrealname^;
  2928. s:=s+tostr(length(s2))+s2;
  2929. case proctypeoption of
  2930. potype_constructor:
  2931. s:=s+'C1';
  2932. potype_destructor:
  2933. s:=s+'D1';
  2934. else
  2935. s:=s+tostr(length(procsym.realname))+procsym.realname;
  2936. end;
  2937. s:=s+'E';
  2938. end
  2939. else
  2940. s:=procsym.realname;
  2941. { now we handle the parameters }
  2942. if maxparacount>0 then
  2943. begin
  2944. for i:=0 to paras.count-1 do
  2945. begin
  2946. hp:=tparavarsym(paras[i]);
  2947. s2:=getcppparaname(hp.vardef);
  2948. if hp.varspez in [vs_var,vs_out] then
  2949. s2:='R'+s2;
  2950. s:=s+s2;
  2951. end;
  2952. end
  2953. else
  2954. s:=s+'v';
  2955. cplusplusmangledname:=s;
  2956. end;
  2957. procedure tprocdef.setmangledname(const s : string);
  2958. begin
  2959. { This is not allowed anymore, the forward declaration
  2960. already needs to create the correct mangledname, no changes
  2961. afterwards are allowed (PFV) }
  2962. { Exception: interface definitions in mode macpas, since in that }
  2963. { case no reference to the old name can exist yet (JM) }
  2964. if assigned(_mangledname) then
  2965. if ((m_mac in current_settings.modeswitches) and
  2966. (interfacedef)) then
  2967. stringdispose(_mangledname)
  2968. else
  2969. internalerror(200411171);
  2970. {$ifdef compress}
  2971. _mangledname:=stringdup(minilzw_encode(s));
  2972. {$else}
  2973. _mangledname:=stringdup(s);
  2974. {$endif}
  2975. include(procoptions,po_has_mangledname);
  2976. end;
  2977. {***************************************************************************
  2978. TPROCVARDEF
  2979. ***************************************************************************}
  2980. constructor tprocvardef.create(level:byte);
  2981. begin
  2982. inherited create(procvardef,level);
  2983. end;
  2984. constructor tprocvardef.ppuload(ppufile:tcompilerppufile);
  2985. begin
  2986. inherited ppuload(procvardef,ppufile);
  2987. { load para symtable }
  2988. parast:=tparasymtable.create(self,unknown_level);
  2989. tparasymtable(parast).ppuload(ppufile);
  2990. end;
  2991. function tprocvardef.getcopy : tstoreddef;
  2992. var
  2993. i : tcallercallee;
  2994. j : longint;
  2995. begin
  2996. result:=tprocvardef.create(parast.symtablelevel);
  2997. tprocvardef(result).returndef:=returndef;
  2998. tprocvardef(result).returndefderef:=returndefderef;
  2999. tprocvardef(result).parast:=parast.getcopy;
  3000. tprocvardef(result).savesize:=savesize;
  3001. { create paralist copy }
  3002. tprocvardef(result).paras:=tparalist.create(false);
  3003. tprocvardef(result).paras.count:=paras.count;
  3004. for j:=0 to paras.count-1 do
  3005. tprocvardef(result).paras[j]:=paras[j];
  3006. tprocvardef(result).proctypeoption:=proctypeoption;
  3007. tprocvardef(result).proccalloption:=proccalloption;
  3008. tprocvardef(result).procoptions:=procoptions;
  3009. tprocvardef(result).requiredargarea:=requiredargarea;
  3010. tprocvardef(result).maxparacount:=maxparacount;
  3011. tprocvardef(result).minparacount:=minparacount;
  3012. for i:=low(tcallercallee) to high(tcallercallee) do
  3013. location_copy(tprocvardef(result).funcretloc[i],funcretloc[i]);
  3014. tprocvardef(result).has_paraloc_info:=has_paraloc_info;
  3015. {$ifdef i386}
  3016. tprocvardef(result).fpu_used:=fpu_used;
  3017. {$endif i386}
  3018. {$ifdef m68k}
  3019. tprocvardef(result).exp_funcretloc:=exp_funcretloc;
  3020. {$endif}
  3021. end;
  3022. procedure tprocvardef.ppuwrite(ppufile:tcompilerppufile);
  3023. begin
  3024. { here we cannot get a real good value so just give something }
  3025. { plausible (PM) }
  3026. { a more secure way would be
  3027. to allways store in a temp }
  3028. {$ifdef i386}
  3029. if is_fpu(returndef) then
  3030. fpu_used:={2}maxfpuregs
  3031. else
  3032. fpu_used:=0;
  3033. {$endif i386}
  3034. inherited ppuwrite(ppufile);
  3035. { Write this entry }
  3036. ppufile.writeentry(ibprocvardef);
  3037. { Save the para symtable, this is taken from the interface }
  3038. tparasymtable(parast).ppuwrite(ppufile);
  3039. end;
  3040. function tprocvardef.GetSymtable(t:tGetSymtable):TSymtable;
  3041. begin
  3042. case t of
  3043. gs_para :
  3044. GetSymtable:=parast;
  3045. else
  3046. GetSymtable:=nil;
  3047. end;
  3048. end;
  3049. function tprocvardef.size : aint;
  3050. begin
  3051. if (po_methodpointer in procoptions) and
  3052. not(po_addressonly in procoptions) then
  3053. size:=2*sizeof(aint)
  3054. else
  3055. size:=sizeof(aint);
  3056. end;
  3057. function tprocvardef.is_methodpointer:boolean;
  3058. begin
  3059. result:=(po_methodpointer in procoptions);
  3060. end;
  3061. function tprocvardef.is_addressonly:boolean;
  3062. begin
  3063. result:=not(po_methodpointer in procoptions) or
  3064. (po_addressonly in procoptions);
  3065. end;
  3066. function tprocvardef.getmangledparaname:string;
  3067. begin
  3068. result:='procvar';
  3069. end;
  3070. function tprocvardef.is_publishable : boolean;
  3071. begin
  3072. is_publishable:=(po_methodpointer in procoptions);
  3073. end;
  3074. function tprocvardef.GetTypeName : string;
  3075. var
  3076. s: string;
  3077. showhidden : boolean;
  3078. begin
  3079. {$ifdef EXTDEBUG}
  3080. showhidden:=true;
  3081. {$else EXTDEBUG}
  3082. showhidden:=false;
  3083. {$endif EXTDEBUG}
  3084. s:='<';
  3085. if po_classmethod in procoptions then
  3086. s := s+'class method type of'
  3087. else
  3088. if po_addressonly in procoptions then
  3089. s := s+'address of'
  3090. else
  3091. s := s+'procedure variable type of';
  3092. if po_local in procoptions then
  3093. s := s+' local';
  3094. if assigned(returndef) and
  3095. (returndef<>voidtype) then
  3096. s:=s+' function'+typename_paras(showhidden)+':'+returndef.GetTypeName
  3097. else
  3098. s:=s+' procedure'+typename_paras(showhidden);
  3099. if po_methodpointer in procoptions then
  3100. s := s+' of object';
  3101. GetTypeName := s+';'+ProcCallOptionStr[proccalloption]+'>';
  3102. end;
  3103. {***************************************************************************
  3104. TOBJECTDEF
  3105. ***************************************************************************}
  3106. constructor tobjectdef.create(ot : tobjecttyp;const n : string;c : tobjectdef);
  3107. begin
  3108. inherited create(objectdef);
  3109. objecttype:=ot;
  3110. objectoptions:=[];
  3111. childof:=nil;
  3112. symtable:=tObjectSymtable.create(self,n,current_settings.packrecords);
  3113. { create space for vmt !! }
  3114. vmtentries:=nil;
  3115. vmt_offset:=0;
  3116. set_parent(c);
  3117. objname:=stringdup(upper(n));
  3118. objrealname:=stringdup(n);
  3119. if objecttype in [odt_interfacecorba,odt_interfacecom,odt_dispinterface] then
  3120. prepareguid;
  3121. { setup implemented interfaces }
  3122. if objecttype in [odt_class,odt_interfacecorba] then
  3123. ImplementedInterfaces:=TFPObjectList.Create(true)
  3124. else
  3125. ImplementedInterfaces:=nil;
  3126. writing_class_record_dbginfo:=false;
  3127. end;
  3128. constructor tobjectdef.ppuload(ppufile:tcompilerppufile);
  3129. var
  3130. i,
  3131. implintfcount : longint;
  3132. d : tderef;
  3133. ImplIntf : TImplementedInterface;
  3134. begin
  3135. inherited ppuload(objectdef,ppufile);
  3136. objecttype:=tobjecttyp(ppufile.getbyte);
  3137. objrealname:=stringdup(ppufile.getstring);
  3138. objname:=stringdup(upper(objrealname^));
  3139. symtable:=tObjectSymtable.create(self,objrealname^,0);
  3140. tObjectSymtable(symtable).datasize:=ppufile.getaint;
  3141. tObjectSymtable(symtable).fieldalignment:=ppufile.getbyte;
  3142. tObjectSymtable(symtable).recordalignment:=ppufile.getbyte;
  3143. vmt_offset:=ppufile.getlongint;
  3144. vmtentries:=nil;
  3145. ppufile.getderef(childofderef);
  3146. ppufile.getsmallset(objectoptions);
  3147. { load guid }
  3148. iidstr:=nil;
  3149. if objecttype in [odt_interfacecom,odt_interfacecorba,odt_dispinterface] then
  3150. begin
  3151. new(iidguid);
  3152. ppufile.getguid(iidguid^);
  3153. iidstr:=stringdup(ppufile.getstring);
  3154. end;
  3155. { load implemented interfaces }
  3156. if objecttype in [odt_class,odt_interfacecorba] then
  3157. begin
  3158. ImplementedInterfaces:=TFPObjectList.Create(true);
  3159. implintfcount:=ppufile.getlongint;
  3160. for i:=0 to implintfcount-1 do
  3161. begin
  3162. ppufile.getderef(d);
  3163. ImplIntf:=TImplementedInterface.Create_deref(d);
  3164. ImplIntf.IOffset:=ppufile.getlongint;
  3165. ImplementedInterfaces.Add(ImplIntf);
  3166. end;
  3167. end
  3168. else
  3169. ImplementedInterfaces:=nil;
  3170. tObjectSymtable(symtable).ppuload(ppufile);
  3171. { handles the predefined class tobject }
  3172. { the last TOBJECT which is loaded gets }
  3173. { it ! }
  3174. if (childof=nil) and
  3175. (objecttype=odt_class) and
  3176. (objname^='TOBJECT') then
  3177. class_tobject:=self;
  3178. if (childof=nil) and
  3179. (objecttype=odt_interfacecom) and
  3180. (objname^='IUNKNOWN') then
  3181. interface_iunknown:=self;
  3182. writing_class_record_dbginfo:=false;
  3183. end;
  3184. destructor tobjectdef.destroy;
  3185. begin
  3186. if assigned(symtable) then
  3187. begin
  3188. symtable.free;
  3189. symtable:=nil;
  3190. end;
  3191. stringdispose(objname);
  3192. stringdispose(objrealname);
  3193. stringdispose(iidstr);
  3194. if assigned(ImplementedInterfaces) then
  3195. begin
  3196. ImplementedInterfaces.free;
  3197. ImplementedInterfaces:=nil;
  3198. end;
  3199. if assigned(iidguid) then
  3200. begin
  3201. dispose(iidguid);
  3202. iidguid:=nil;
  3203. end;
  3204. if assigned(vmtentries) then
  3205. begin
  3206. vmtentries.free;
  3207. vmtentries:=nil;
  3208. end;
  3209. inherited destroy;
  3210. end;
  3211. function tobjectdef.getcopy : tstoreddef;
  3212. var
  3213. i : longint;
  3214. begin
  3215. result:=tobjectdef.create(objecttype,objname^,childof);
  3216. tobjectdef(result).symtable:=symtable.getcopy;
  3217. if assigned(objname) then
  3218. tobjectdef(result).objname:=stringdup(objname^);
  3219. if assigned(objrealname) then
  3220. tobjectdef(result).objrealname:=stringdup(objrealname^);
  3221. tobjectdef(result).objectoptions:=objectoptions;
  3222. tobjectdef(result).vmt_offset:=vmt_offset;
  3223. if assigned(iidguid) then
  3224. begin
  3225. new(tobjectdef(result).iidguid);
  3226. move(iidguid^,tobjectdef(result).iidguid^,sizeof(iidguid^));
  3227. end;
  3228. if assigned(iidstr) then
  3229. tobjectdef(result).iidstr:=stringdup(iidstr^);
  3230. if assigned(ImplementedInterfaces) then
  3231. begin
  3232. for i:=0 to ImplementedInterfaces.count-1 do
  3233. tobjectdef(result).ImplementedInterfaces.Add(TImplementedInterface(ImplementedInterfaces[i]).Getcopy);
  3234. end;
  3235. if assigned(vmtentries) then
  3236. begin
  3237. tobjectdef(result).vmtentries:=TFPobjectList.Create(false);
  3238. tobjectdef(result).vmtentries.Assign(vmtentries);
  3239. end;
  3240. end;
  3241. procedure tobjectdef.ppuwrite(ppufile:tcompilerppufile);
  3242. var
  3243. i : longint;
  3244. ImplIntf : TImplementedInterface;
  3245. begin
  3246. inherited ppuwrite(ppufile);
  3247. ppufile.putbyte(byte(objecttype));
  3248. ppufile.putstring(objrealname^);
  3249. ppufile.putaint(tObjectSymtable(symtable).datasize);
  3250. ppufile.putbyte(tObjectSymtable(symtable).fieldalignment);
  3251. ppufile.putbyte(tObjectSymtable(symtable).recordalignment);
  3252. ppufile.putlongint(vmt_offset);
  3253. ppufile.putderef(childofderef);
  3254. ppufile.putsmallset(objectoptions);
  3255. if objecttype in [odt_interfacecom,odt_interfacecorba,odt_dispinterface] then
  3256. begin
  3257. ppufile.putguid(iidguid^);
  3258. ppufile.putstring(iidstr^);
  3259. end;
  3260. if objecttype in [odt_class,odt_interfacecorba] then
  3261. begin
  3262. ppufile.putlongint(ImplementedInterfaces.Count);
  3263. for i:=0 to ImplementedInterfaces.Count-1 do
  3264. begin
  3265. ImplIntf:=TImplementedInterface(ImplementedInterfaces[i]);
  3266. ppufile.putderef(ImplIntf.intfdefderef);
  3267. ppufile.putlongint(ImplIntf.Ioffset);
  3268. end;
  3269. end;
  3270. ppufile.writeentry(ibobjectdef);
  3271. tObjectSymtable(symtable).ppuwrite(ppufile);
  3272. end;
  3273. function tobjectdef.GetTypeName:string;
  3274. begin
  3275. if (self <> aktobjectdef) then
  3276. GetTypeName:=typename
  3277. else
  3278. { in this case we will go in endless recursion, because then }
  3279. { there is no tsym associated yet with the def. It can occur }
  3280. { (tests/webtbf/tw4757.pp), so for now give a generic name }
  3281. { instead of the actual type name }
  3282. GetTypeName:='<Currently Parsed Class>';
  3283. end;
  3284. procedure tobjectdef.buildderef;
  3285. var
  3286. i : longint;
  3287. begin
  3288. inherited buildderef;
  3289. childofderef.build(childof);
  3290. tstoredsymtable(symtable).buildderef;
  3291. if objecttype in [odt_class,odt_interfacecorba] then
  3292. begin
  3293. for i:=0 to ImplementedInterfaces.count-1 do
  3294. TImplementedInterface(ImplementedInterfaces[i]).buildderef;
  3295. end;
  3296. end;
  3297. procedure tobjectdef.deref;
  3298. var
  3299. i : longint;
  3300. begin
  3301. inherited deref;
  3302. childof:=tobjectdef(childofderef.resolve);
  3303. tstoredsymtable(symtable).deref;
  3304. if objecttype in [odt_class,odt_interfacecorba] then
  3305. begin
  3306. for i:=0 to ImplementedInterfaces.count-1 do
  3307. TImplementedInterface(ImplementedInterfaces[i]).deref;
  3308. end;
  3309. end;
  3310. function tobjectdef.getparentdef:tdef;
  3311. begin
  3312. {$warning TODO Remove getparentdef hack}
  3313. { With 2 forward declared classes with the child class before the
  3314. parent class the child class is written earlier to the ppu. Leaving it
  3315. possible to have a reference to the parent class for property overriding,
  3316. but the parent class still has the childof not resolved yet (PFV) }
  3317. if childof=nil then
  3318. childof:=tobjectdef(childofderef.resolve);
  3319. result:=childof;
  3320. end;
  3321. procedure tobjectdef.prepareguid;
  3322. begin
  3323. { set up guid }
  3324. if not assigned(iidguid) then
  3325. begin
  3326. new(iidguid);
  3327. fillchar(iidguid^,sizeof(iidguid^),0); { default null guid }
  3328. end;
  3329. { setup iidstring }
  3330. if not assigned(iidstr) then
  3331. iidstr:=stringdup(''); { default is empty string }
  3332. end;
  3333. procedure tobjectdef.set_parent( c : tobjectdef);
  3334. begin
  3335. { nothing to do if the parent was not forward !}
  3336. if assigned(childof) then
  3337. exit;
  3338. childof:=c;
  3339. { some options are inherited !! }
  3340. if assigned(c) then
  3341. begin
  3342. { only important for classes }
  3343. objectoptions:=objectoptions+(c.objectoptions*inherited_objectoptions);
  3344. if not (objecttype in [odt_interfacecom,odt_interfacecorba,odt_dispinterface]) then
  3345. begin
  3346. { add the data of the anchestor class }
  3347. tObjectSymtable(symtable).datasize:=
  3348. tObjectSymtable(symtable).datasize+
  3349. tObjectSymtable(c.symtable).datasize;
  3350. if (oo_has_vmt in objectoptions) and
  3351. (oo_has_vmt in c.objectoptions) then
  3352. tObjectSymtable(symtable).datasize:=
  3353. tObjectSymtable(symtable).datasize-sizeof(aint);
  3354. { if parent has a vmt field then
  3355. the offset is the same for the child PM }
  3356. if (oo_has_vmt in c.objectoptions) or is_class(self) then
  3357. begin
  3358. vmt_offset:=c.vmt_offset;
  3359. include(objectoptions,oo_has_vmt);
  3360. end;
  3361. end;
  3362. end;
  3363. end;
  3364. procedure tobjectdef.insertvmt;
  3365. begin
  3366. if objecttype in [odt_interfacecom,odt_interfacecorba,odt_dispinterface] then
  3367. exit;
  3368. if (oo_has_vmt in objectoptions) then
  3369. internalerror(12345)
  3370. else
  3371. begin
  3372. tObjectSymtable(symtable).datasize:=align(tObjectSymtable(symtable).datasize,
  3373. tObjectSymtable(symtable).fieldalignment);
  3374. if (tf_requires_proper_alignment in target_info.flags) then
  3375. tObjectSymtable(symtable).datasize:=align(tObjectSymtable(symtable).datasize,sizeof(aint));
  3376. vmt_offset:=tObjectSymtable(symtable).datasize;
  3377. tObjectSymtable(symtable).datasize:=
  3378. tObjectSymtable(symtable).datasize+sizeof(aint);
  3379. include(objectoptions,oo_has_vmt);
  3380. end;
  3381. end;
  3382. procedure tobjectdef.check_forwards;
  3383. begin
  3384. if not(objecttype in [odt_interfacecom,odt_interfacecorba,odt_dispinterface]) then
  3385. tstoredsymtable(symtable).check_forwards;
  3386. if (oo_is_forward in objectoptions) then
  3387. begin
  3388. { ok, in future, the forward can be resolved }
  3389. Message1(sym_e_class_forward_not_resolved,objrealname^);
  3390. exclude(objectoptions,oo_is_forward);
  3391. end;
  3392. end;
  3393. { true, if self inherits from d (or if they are equal) }
  3394. function tobjectdef.is_related(d : tdef) : boolean;
  3395. var
  3396. hp : tobjectdef;
  3397. begin
  3398. hp:=self;
  3399. while assigned(hp) do
  3400. begin
  3401. if hp=d then
  3402. begin
  3403. is_related:=true;
  3404. exit;
  3405. end;
  3406. hp:=hp.childof;
  3407. end;
  3408. is_related:=false;
  3409. end;
  3410. function tobjectdef.FindDestructor : tprocdef;
  3411. var
  3412. objdef : tobjectdef;
  3413. i : longint;
  3414. sym : tsym;
  3415. pd : tprocdef;
  3416. begin
  3417. result:=nil;
  3418. objdef:=self;
  3419. while assigned(objdef) do
  3420. begin
  3421. for i:=0 to objdef.symtable.SymList.Count-1 do
  3422. begin
  3423. sym:=TSym(objdef.symtable.SymList[i]);
  3424. if sym.typ=procsym then
  3425. begin
  3426. pd:=Tprocsym(sym).Find_procdef_bytype(potype_destructor);
  3427. if assigned(pd) then
  3428. begin
  3429. result:=pd;
  3430. exit;
  3431. end;
  3432. end;
  3433. end;
  3434. objdef:=objdef.childof;
  3435. end;
  3436. end;
  3437. function tobjectdef.size : aint;
  3438. begin
  3439. if objecttype in [odt_class,odt_interfacecom,odt_interfacecorba,odt_dispinterface] then
  3440. result:=sizeof(aint)
  3441. else
  3442. result:=tObjectSymtable(symtable).datasize;
  3443. end;
  3444. function tobjectdef.alignment:shortint;
  3445. begin
  3446. if objecttype in [odt_class,odt_interfacecom,odt_interfacecorba,odt_dispinterface] then
  3447. alignment:=sizeof(aint)
  3448. else
  3449. alignment:=tObjectSymtable(symtable).recordalignment;
  3450. end;
  3451. function tobjectdef.vmtmethodoffset(index:longint):longint;
  3452. begin
  3453. { for offset of methods for classes, see rtl/inc/objpash.inc }
  3454. case objecttype of
  3455. odt_class:
  3456. { the +2*sizeof(Aint) is size and -size }
  3457. vmtmethodoffset:=(index+10)*sizeof(aint)+2*sizeof(AInt);
  3458. odt_interfacecom,odt_interfacecorba:
  3459. vmtmethodoffset:=index*sizeof(aint);
  3460. else
  3461. {$ifdef WITHDMT}
  3462. vmtmethodoffset:=(index+4)*sizeof(aint);
  3463. {$else WITHDMT}
  3464. vmtmethodoffset:=(index+3)*sizeof(aint);
  3465. {$endif WITHDMT}
  3466. end;
  3467. end;
  3468. function tobjectdef.vmt_mangledname : string;
  3469. begin
  3470. if not(oo_has_vmt in objectoptions) then
  3471. Message1(parser_n_object_has_no_vmt,objrealname^);
  3472. vmt_mangledname:=make_mangledname('VMT',owner,objname^);
  3473. end;
  3474. function tobjectdef.needs_inittable : boolean;
  3475. begin
  3476. case objecttype of
  3477. odt_dispinterface,
  3478. odt_class :
  3479. needs_inittable:=false;
  3480. odt_interfacecom:
  3481. needs_inittable:=true;
  3482. odt_interfacecorba:
  3483. needs_inittable:=is_related(interface_iunknown);
  3484. odt_object:
  3485. needs_inittable:=tObjectSymtable(symtable).needs_init_final;
  3486. odt_cppclass:
  3487. needs_inittable:=false;
  3488. else
  3489. internalerror(200108267);
  3490. end;
  3491. end;
  3492. function tobjectdef.members_need_inittable : boolean;
  3493. begin
  3494. members_need_inittable:=tObjectSymtable(symtable).needs_init_final;
  3495. end;
  3496. function tobjectdef.find_implemented_interface(aintfdef:tobjectdef):TImplementedInterface;
  3497. var
  3498. ImplIntf : TImplementedInterface;
  3499. i : longint;
  3500. begin
  3501. result:=nil;
  3502. if not assigned(ImplementedInterfaces) then
  3503. exit;
  3504. for i:=0 to ImplementedInterfaces.Count-1 do
  3505. begin
  3506. ImplIntf:=TImplementedInterface(ImplementedInterfaces[i]);
  3507. if ImplIntf.intfdef=aintfdef then
  3508. begin
  3509. result:=ImplIntf;
  3510. exit;
  3511. end;
  3512. end;
  3513. end;
  3514. function tobjectdef.is_publishable : boolean;
  3515. begin
  3516. is_publishable:=objecttype in [odt_class,odt_interfacecom,odt_interfacecorba,odt_dispinterface];
  3517. end;
  3518. {****************************************************************************
  3519. TImplementedInterface
  3520. ****************************************************************************}
  3521. constructor TImplementedInterface.create(aintf: tobjectdef);
  3522. begin
  3523. inherited create;
  3524. intfdef:=aintf;
  3525. IOffset:=-1;
  3526. IType:=etStandard;
  3527. FieldOffset:=-1;
  3528. NameMappings:=nil;
  3529. procdefs:=nil;
  3530. end;
  3531. constructor TImplementedInterface.create_deref(d:tderef);
  3532. begin
  3533. inherited create;
  3534. intfdef:=nil;
  3535. intfdefderef:=d;
  3536. IOffset:=-1;
  3537. IType:=etStandard;
  3538. FieldOffset:=-1;
  3539. NameMappings:=nil;
  3540. procdefs:=nil;
  3541. end;
  3542. destructor TImplementedInterface.destroy;
  3543. var
  3544. i : longint;
  3545. mappedname : pshortstring;
  3546. begin
  3547. if assigned(NameMappings) then
  3548. begin
  3549. for i:=0 to NameMappings.Count-1 do
  3550. begin
  3551. mappedname:=pshortstring(NameMappings[i]);
  3552. stringdispose(mappedname);
  3553. end;
  3554. NameMappings.free;
  3555. NameMappings:=nil;
  3556. end;
  3557. if assigned(procdefs) then
  3558. begin
  3559. procdefs.free;
  3560. procdefs:=nil;
  3561. end;
  3562. inherited destroy;
  3563. end;
  3564. procedure TImplementedInterface.buildderef;
  3565. begin
  3566. intfdefderef.build(intfdef);
  3567. end;
  3568. procedure TImplementedInterface.deref;
  3569. begin
  3570. intfdef:=tobjectdef(intfdefderef.resolve);
  3571. end;
  3572. procedure TImplementedInterface.AddMapping(const origname,newname: string);
  3573. begin
  3574. if not assigned(NameMappings) then
  3575. NameMappings:=TFPHashList.Create;
  3576. NameMappings.Add(origname,stringdup(newname));
  3577. end;
  3578. function TImplementedInterface.GetMapping(const origname: string):string;
  3579. var
  3580. mappedname : pshortstring;
  3581. begin
  3582. result:='';
  3583. if not assigned(NameMappings) then
  3584. exit;
  3585. mappedname:=PShortstring(NameMappings.Find(origname));
  3586. if assigned(mappedname) then
  3587. result:=mappedname^;
  3588. end;
  3589. procedure TImplementedInterface.AddImplProc(pd:tprocdef);
  3590. var
  3591. i : longint;
  3592. found : boolean;
  3593. begin
  3594. if not assigned(procdefs) then
  3595. procdefs:=TFPObjectList.Create(false);
  3596. { No duplicate entries of the same procdef }
  3597. found:=false;
  3598. for i:=0 to procdefs.count-1 do
  3599. if tprocdef(procdefs[i])=pd then
  3600. begin
  3601. found:=true;
  3602. break;
  3603. end;
  3604. if not found then
  3605. procdefs.Add(pd);
  3606. end;
  3607. function TImplementedInterface.IsImplMergePossible(MergingIntf:TImplementedInterface;out weight: longint): boolean;
  3608. var
  3609. i : longint;
  3610. begin
  3611. result:=false;
  3612. weight:=0;
  3613. { empty interface is mergeable }
  3614. if ProcDefs.Count=0 then
  3615. begin
  3616. result:=true;
  3617. exit;
  3618. end;
  3619. { The interface to merge must at least the number of
  3620. procedures of this interface }
  3621. if MergingIntf.ProcDefs.Count<ProcDefs.Count then
  3622. exit;
  3623. for i:=0 to ProcDefs.Count-1 do
  3624. begin
  3625. if MergingIntf.ProcDefs[i]<>ProcDefs[i] then
  3626. exit;
  3627. end;
  3628. weight:=ProcDefs.Count;
  3629. result:=true;
  3630. end;
  3631. function TImplementedInterface.getcopy:TImplementedInterface;
  3632. begin
  3633. Result:=TImplementedInterface.Create(nil);
  3634. Move(pointer(self)^,pointer(result)^,InstanceSize);
  3635. end;
  3636. {****************************************************************************
  3637. TFORWARDDEF
  3638. ****************************************************************************}
  3639. constructor tforwarddef.create(const s:string;const pos : tfileposinfo);
  3640. begin
  3641. inherited create(forwarddef);
  3642. tosymname:=stringdup(s);
  3643. forwardpos:=pos;
  3644. end;
  3645. function tforwarddef.GetTypeName:string;
  3646. begin
  3647. GetTypeName:='unresolved forward to '+tosymname^;
  3648. end;
  3649. destructor tforwarddef.destroy;
  3650. begin
  3651. stringdispose(tosymname);
  3652. inherited destroy;
  3653. end;
  3654. {****************************************************************************
  3655. TUNDEFINEDDEF
  3656. ****************************************************************************}
  3657. constructor tundefineddef.create;
  3658. begin
  3659. inherited create(undefineddef);
  3660. end;
  3661. constructor tundefineddef.ppuload(ppufile:tcompilerppufile);
  3662. begin
  3663. inherited ppuload(undefineddef,ppufile);
  3664. end;
  3665. function tundefineddef.GetTypeName:string;
  3666. begin
  3667. GetTypeName:='<undefined type>';
  3668. end;
  3669. procedure tundefineddef.ppuwrite(ppufile:tcompilerppufile);
  3670. begin
  3671. inherited ppuwrite(ppufile);
  3672. ppufile.writeentry(ibundefineddef);
  3673. end;
  3674. {****************************************************************************
  3675. TERRORDEF
  3676. ****************************************************************************}
  3677. constructor terrordef.create;
  3678. begin
  3679. inherited create(errordef);
  3680. end;
  3681. procedure terrordef.ppuwrite(ppufile:tcompilerppufile);
  3682. begin
  3683. { Can't write errordefs to ppu }
  3684. internalerror(200411063);
  3685. end;
  3686. function terrordef.GetTypeName:string;
  3687. begin
  3688. GetTypeName:='<erroneous type>';
  3689. end;
  3690. function terrordef.getmangledparaname:string;
  3691. begin
  3692. getmangledparaname:='error';
  3693. end;
  3694. {****************************************************************************
  3695. Definition Helpers
  3696. ****************************************************************************}
  3697. function is_interfacecom(def: tdef): boolean;
  3698. begin
  3699. is_interfacecom:=
  3700. assigned(def) and
  3701. (def.typ=objectdef) and
  3702. (tobjectdef(def).objecttype=odt_interfacecom);
  3703. end;
  3704. function is_interfacecorba(def: tdef): boolean;
  3705. begin
  3706. is_interfacecorba:=
  3707. assigned(def) and
  3708. (def.typ=objectdef) and
  3709. (tobjectdef(def).objecttype=odt_interfacecorba);
  3710. end;
  3711. function is_interface(def: tdef): boolean;
  3712. begin
  3713. is_interface:=
  3714. assigned(def) and
  3715. (def.typ=objectdef) and
  3716. (tobjectdef(def).objecttype in [odt_interfacecom,odt_interfacecorba]);
  3717. end;
  3718. function is_dispinterface(def: tdef): boolean;
  3719. begin
  3720. result:=
  3721. assigned(def) and
  3722. (def.typ=objectdef) and
  3723. (tobjectdef(def).objecttype=odt_dispinterface);
  3724. end;
  3725. function is_class(def: tdef): boolean;
  3726. begin
  3727. is_class:=
  3728. assigned(def) and
  3729. (def.typ=objectdef) and
  3730. (tobjectdef(def).objecttype=odt_class);
  3731. end;
  3732. function is_object(def: tdef): boolean;
  3733. begin
  3734. is_object:=
  3735. assigned(def) and
  3736. (def.typ=objectdef) and
  3737. (tobjectdef(def).objecttype=odt_object);
  3738. end;
  3739. function is_cppclass(def: tdef): boolean;
  3740. begin
  3741. is_cppclass:=
  3742. assigned(def) and
  3743. (def.typ=objectdef) and
  3744. (tobjectdef(def).objecttype=odt_cppclass);
  3745. end;
  3746. function is_class_or_interface(def: tdef): boolean;
  3747. begin
  3748. is_class_or_interface:=
  3749. assigned(def) and
  3750. (def.typ=objectdef) and
  3751. (tobjectdef(def).objecttype in [odt_class,odt_interfacecom,odt_interfacecorba]);
  3752. end;
  3753. function is_class_or_interface_or_dispinterface(def: tdef): boolean;
  3754. begin
  3755. result:=
  3756. assigned(def) and
  3757. (def.typ=objectdef) and
  3758. (tobjectdef(def).objecttype in [odt_class,odt_interfacecom,odt_interfacecorba,odt_dispinterface]);
  3759. end;
  3760. {$ifdef x86}
  3761. function use_sse(def : tdef) : boolean;
  3762. begin
  3763. use_sse:=(is_single(def) and (current_settings.fputype in sse_singlescalar)) or
  3764. (is_double(def) and (current_settings.fputype in sse_doublescalar));
  3765. end;
  3766. {$endif x86}
  3767. end.