symdef.pas 127 KB

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