symdef.pas 127 KB

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