symdef.pas 129 KB

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