symdef.pas 128 KB

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