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 ord type with the same size as a pointer }
  559. ptrinttype,
  560. { several types to simulate more or less C++ objects for GDB }
  561. vmttype,
  562. vmtarraytype,
  563. pvmttype : tdef; { type of classrefs, used for stabs }
  564. { pointer to the anchestor of all classes }
  565. class_tobject : tobjectdef;
  566. { pointer to the ancestor of all COM interfaces }
  567. interface_iunknown : tobjectdef;
  568. { pointer to the TGUID type
  569. of all interfaces }
  570. rec_tguid : trecorddef;
  571. const
  572. {$ifdef i386}
  573. pbestrealtype : ^tdef = @s80floattype;
  574. {$endif}
  575. {$ifdef x86_64}
  576. pbestrealtype : ^tdef = @s80floattype;
  577. {$endif}
  578. {$ifdef m68k}
  579. pbestrealtype : ^tdef = @s64floattype;
  580. {$endif}
  581. {$ifdef alpha}
  582. pbestrealtype : ^tdef = @s64floattype;
  583. {$endif}
  584. {$ifdef powerpc}
  585. pbestrealtype : ^tdef = @s64floattype;
  586. {$endif}
  587. {$ifdef POWERPC64}
  588. pbestrealtype : ^tdef = @s64floattype;
  589. {$endif}
  590. {$ifdef ia64}
  591. pbestrealtype : ^tdef = @s64floattype;
  592. {$endif}
  593. {$ifdef SPARC}
  594. pbestrealtype : ^tdef = @s64floattype;
  595. {$endif SPARC}
  596. {$ifdef vis}
  597. pbestrealtype : ^tdef = @s64floattype;
  598. {$endif vis}
  599. {$ifdef ARM}
  600. pbestrealtype : ^tdef = @s64floattype;
  601. {$endif ARM}
  602. {$ifdef MIPS}
  603. pbestrealtype : ^tdef = @s64floattype;
  604. {$endif MIPS}
  605. function make_mangledname(const typeprefix:string;st:TSymtable;const suffix:string):string;
  606. { should be in the types unit, but the types unit uses the node stuff :( }
  607. function is_interfacecom(def: tdef): boolean;
  608. function is_interfacecorba(def: tdef): boolean;
  609. function is_interface(def: tdef): boolean;
  610. function is_dispinterface(def: tdef): boolean;
  611. function is_object(def: tdef): boolean;
  612. function is_class(def: tdef): boolean;
  613. function is_cppclass(def: tdef): boolean;
  614. function is_class_or_interface(def: tdef): boolean;
  615. function is_class_or_interface_or_dispinterface(def: tdef): boolean;
  616. {$ifdef x86}
  617. function use_sse(def : tdef) : boolean;
  618. {$endif x86}
  619. implementation
  620. uses
  621. SysUtils,
  622. cutils,
  623. { global }
  624. verbose,
  625. { target }
  626. systems,aasmcpu,paramgr,
  627. { symtable }
  628. symsym,symtable,symutil,defutil,
  629. { module }
  630. fmodule,
  631. { other }
  632. gendef,
  633. fpccrc
  634. ;
  635. {****************************************************************************
  636. Constants
  637. ****************************************************************************}
  638. const
  639. varempty = 0;
  640. varnull = 1;
  641. varsmallint = 2;
  642. varinteger = 3;
  643. varsingle = 4;
  644. vardouble = 5;
  645. varcurrency = 6;
  646. vardate = 7;
  647. varolestr = 8;
  648. vardispatch = 9;
  649. varerror = 10;
  650. varboolean = 11;
  651. varvariant = 12;
  652. varunknown = 13;
  653. vardecimal = 14;
  654. varshortint = 16;
  655. varbyte = 17;
  656. varword = 18;
  657. varlongword = 19;
  658. varint64 = 20;
  659. varqword = 21;
  660. varUndefined = -1;
  661. varstrarg = $48;
  662. varstring = $100;
  663. varany = $101;
  664. vardefmask = $fff;
  665. vararray = $2000;
  666. varbyref = $4000;
  667. {****************************************************************************
  668. Helpers
  669. ****************************************************************************}
  670. function make_mangledname(const typeprefix:string;st:TSymtable;const suffix:string):string;
  671. var
  672. s,hs,
  673. prefix : string;
  674. oldlen,
  675. newlen,
  676. i : longint;
  677. crc : dword;
  678. hp : tparavarsym;
  679. begin
  680. prefix:='';
  681. if not assigned(st) then
  682. internalerror(200204212);
  683. { sub procedures }
  684. while (st.symtabletype=localsymtable) do
  685. begin
  686. if st.defowner.typ<>procdef then
  687. internalerror(200204173);
  688. { Add the full mangledname of procedure to prevent
  689. conflicts with 2 overloads having both a nested procedure
  690. with the same name, see tb0314 (PFV) }
  691. s:=tprocdef(st.defowner).procsym.name;
  692. oldlen:=length(s);
  693. for i:=0 to tprocdef(st.defowner).paras.count-1 do
  694. begin
  695. hp:=tparavarsym(tprocdef(st.defowner).paras[i]);
  696. if not(vo_is_hidden_para in hp.varoptions) then
  697. s:=s+'$'+hp.vardef.mangledparaname;
  698. end;
  699. if not is_void(tprocdef(st.defowner).returndef) then
  700. s:=s+'$$'+tprocdef(st.defowner).returndef.mangledparaname;
  701. newlen:=length(s);
  702. { Replace with CRC if the parameter line is very long }
  703. if (newlen-oldlen>12) and
  704. ((newlen>128) or (newlen-oldlen>64)) then
  705. begin
  706. crc:=$ffffffff;
  707. for i:=0 to tprocdef(st.defowner).paras.count-1 do
  708. begin
  709. hp:=tparavarsym(tprocdef(st.defowner).paras[i]);
  710. if not(vo_is_hidden_para in hp.varoptions) then
  711. begin
  712. hs:=hp.vardef.mangledparaname;
  713. crc:=UpdateCrc32(crc,hs[1],length(hs));
  714. end;
  715. end;
  716. hs:=hp.vardef.mangledparaname;
  717. crc:=UpdateCrc32(crc,hs[1],length(hs));
  718. s:=Copy(s,1,oldlen)+'$crc'+hexstr(crc,8);
  719. end;
  720. if prefix<>'' then
  721. prefix:=s+'_'+prefix
  722. else
  723. prefix:=s;
  724. st:=st.defowner.owner;
  725. end;
  726. { object/classes symtable }
  727. if (st.symtabletype=ObjectSymtable) then
  728. begin
  729. if st.defowner.typ<>objectdef then
  730. internalerror(200204174);
  731. prefix:=tobjectdef(st.defowner).objname^+'_$_'+prefix;
  732. st:=st.defowner.owner;
  733. end;
  734. { symtable must now be static or global }
  735. if not(st.symtabletype in [staticsymtable,globalsymtable]) then
  736. internalerror(200204175);
  737. result:='';
  738. if typeprefix<>'' then
  739. result:=result+typeprefix+'_';
  740. { Add P$ for program, which can have the same name as
  741. a unit }
  742. if (TSymtable(main_module.localsymtable)=st) and
  743. (not main_module.is_unit) then
  744. result:=result+'P$'+st.name^
  745. else
  746. result:=result+st.name^;
  747. if prefix<>'' then
  748. result:=result+'_'+prefix;
  749. if suffix<>'' then
  750. result:=result+'_'+suffix;
  751. { the Darwin assembler assumes that all symbols starting with 'L' are local }
  752. if (target_info.system in [system_powerpc_darwin,system_i386_darwin]) and
  753. (result[1] = 'L') then
  754. result := '_' + result;
  755. end;
  756. {****************************************************************************
  757. TDEF (base class for definitions)
  758. ****************************************************************************}
  759. constructor tstoreddef.create(dt:tdeftyp);
  760. var
  761. insertstack : psymtablestackitem;
  762. begin
  763. inherited create(dt);
  764. savesize := 0;
  765. {$ifdef EXTDEBUG}
  766. fileinfo := current_filepos;
  767. {$endif}
  768. generictokenbuf:=nil;
  769. genericdef:=nil;
  770. { Don't register forwarddefs, they are disposed at the
  771. end of an type block }
  772. if (dt=forwarddef) then
  773. exit;
  774. { Register in current_module }
  775. if assigned(current_module) then
  776. begin
  777. current_module.deflist.Add(self);
  778. DefId:=current_module.deflist.Count-1;
  779. end;
  780. { Register in symtable stack }
  781. if assigned(symtablestack) then
  782. begin
  783. insertstack:=symtablestack.stack;
  784. while assigned(insertstack) and
  785. (insertstack^.symtable.symtabletype=withsymtable) do
  786. insertstack:=insertstack^.next;
  787. if not assigned(insertstack) then
  788. internalerror(200602044);
  789. insertstack^.symtable.insertdef(self);
  790. end;
  791. end;
  792. destructor tstoreddef.destroy;
  793. begin
  794. { Direct calls are not allowed, use symtable.deletedef() }
  795. if assigned(owner) then
  796. internalerror(200612311);
  797. if assigned(generictokenbuf) then
  798. begin
  799. generictokenbuf.free;
  800. generictokenbuf:=nil;
  801. end;
  802. inherited destroy;
  803. end;
  804. constructor tstoreddef.ppuload(dt:tdeftyp;ppufile:tcompilerppufile);
  805. var
  806. sizeleft,i : longint;
  807. buf : array[0..255] of byte;
  808. begin
  809. inherited create(dt);
  810. DefId:=ppufile.getlongint;
  811. current_module.deflist[DefId]:=self;
  812. {$ifdef EXTDEBUG}
  813. fillchar(fileinfo,sizeof(fileinfo),0);
  814. {$endif}
  815. { load }
  816. ppufile.getderef(typesymderef);
  817. ppufile.getsmallset(defoptions);
  818. if df_generic in defoptions then
  819. begin
  820. sizeleft:=ppufile.getlongint;
  821. initgeneric;
  822. while sizeleft>0 do
  823. begin
  824. if sizeleft>sizeof(buf) then
  825. i:=sizeof(buf)
  826. else
  827. i:=sizeleft;
  828. ppufile.getdata(buf,i);
  829. generictokenbuf.write(buf,i);
  830. dec(sizeleft,i);
  831. end;
  832. end;
  833. if df_specialization in defoptions then
  834. ppufile.getderef(genericdefderef);
  835. end;
  836. function Tstoreddef.rtti_mangledname(rt:trttitype):string;
  837. var
  838. prefix : string[4];
  839. begin
  840. if rt=fullrtti then
  841. begin
  842. prefix:='RTTI';
  843. include(defstates,ds_rtti_table_used);
  844. end
  845. else
  846. begin
  847. prefix:='INIT';
  848. include(defstates,ds_init_table_used);
  849. end;
  850. if assigned(typesym) and
  851. (owner.symtabletype in [staticsymtable,globalsymtable]) then
  852. result:=make_mangledname(prefix,owner,typesym.name)
  853. else
  854. result:=make_mangledname(prefix,findunitsymtable(owner),'DEF'+tostr(DefId))
  855. end;
  856. procedure Tstoreddef.reset;
  857. begin
  858. end;
  859. function tstoreddef.getcopy : tstoreddef;
  860. begin
  861. Message(sym_e_cant_create_unique_type);
  862. getcopy:=terrordef.create;
  863. end;
  864. procedure tstoreddef.ppuwrite(ppufile:tcompilerppufile);
  865. var
  866. sizeleft,i : longint;
  867. buf : array[0..255] of byte;
  868. oldintfcrc : boolean;
  869. begin
  870. ppufile.putlongint(DefId);
  871. ppufile.putderef(typesymderef);
  872. ppufile.putsmallset(defoptions);
  873. if df_generic in defoptions then
  874. begin
  875. oldintfcrc:=ppufile.do_interface_crc;
  876. ppufile.do_interface_crc:=false;
  877. if assigned(generictokenbuf) then
  878. begin
  879. sizeleft:=generictokenbuf.size;
  880. generictokenbuf.seek(0);
  881. end
  882. else
  883. sizeleft:=0;
  884. ppufile.putlongint(sizeleft);
  885. while sizeleft>0 do
  886. begin
  887. if sizeleft>sizeof(buf) then
  888. i:=sizeof(buf)
  889. else
  890. i:=sizeleft;
  891. generictokenbuf.read(buf,i);
  892. ppufile.putdata(buf,i);
  893. dec(sizeleft,i);
  894. end;
  895. ppufile.do_interface_crc:=oldintfcrc;
  896. end;
  897. if df_specialization in defoptions then
  898. ppufile.putderef(genericdefderef);
  899. end;
  900. procedure tstoreddef.buildderef;
  901. begin
  902. typesymderef.build(typesym);
  903. genericdefderef.build(genericdef);
  904. end;
  905. procedure tstoreddef.buildderefimpl;
  906. begin
  907. end;
  908. procedure tstoreddef.deref;
  909. begin
  910. typesym:=ttypesym(typesymderef.resolve);
  911. if df_specialization in defoptions then
  912. genericdef:=tstoreddef(genericdefderef.resolve);
  913. end;
  914. procedure tstoreddef.derefimpl;
  915. begin
  916. end;
  917. function tstoreddef.size : aint;
  918. begin
  919. size:=savesize;
  920. end;
  921. function tstoreddef.getvardef:longint;
  922. begin
  923. result:=varUndefined;
  924. end;
  925. function tstoreddef.alignment : shortint;
  926. begin
  927. { natural alignment by default }
  928. alignment:=size_2_align(savesize);
  929. end;
  930. { returns true, if the definition can be published }
  931. function tstoreddef.is_publishable : boolean;
  932. begin
  933. is_publishable:=false;
  934. end;
  935. { needs an init table }
  936. function tstoreddef.needs_inittable : boolean;
  937. begin
  938. needs_inittable:=false;
  939. end;
  940. function tstoreddef.is_intregable : boolean;
  941. var
  942. recsize,temp: longint;
  943. begin
  944. is_intregable:=false;
  945. case typ of
  946. orddef,
  947. pointerdef,
  948. enumdef,
  949. classrefdef:
  950. is_intregable:=true;
  951. procvardef :
  952. is_intregable:=not(po_methodpointer in tprocvardef(self).procoptions);
  953. objectdef:
  954. is_intregable:=(is_class(self) or is_interface(self)) and not needs_inittable;
  955. setdef:
  956. is_intregable:=(tsetdef(self).settype=smallset);
  957. recorddef:
  958. begin
  959. recsize:=size;
  960. is_intregable:=
  961. ispowerof2(recsize,temp) and
  962. (recsize <= sizeof(aint));
  963. end;
  964. end;
  965. end;
  966. function tstoreddef.is_fpuregable : boolean;
  967. begin
  968. {$ifdef x86}
  969. result:=use_sse(self);
  970. {$else x86}
  971. result:=(typ=floatdef) and not(cs_fp_emulation in current_settings.moduleswitches);
  972. {$endif x86}
  973. end;
  974. procedure tstoreddef.initgeneric;
  975. begin
  976. if assigned(generictokenbuf) then
  977. internalerror(200512131);
  978. generictokenbuf:=tdynamicarray.create(256);
  979. end;
  980. {****************************************************************************
  981. Tstringdef
  982. ****************************************************************************}
  983. constructor tstringdef.createshort(l : byte);
  984. begin
  985. inherited create(stringdef);
  986. stringtype:=st_shortstring;
  987. len:=l;
  988. savesize:=len+1;
  989. end;
  990. constructor tstringdef.loadshort(ppufile:tcompilerppufile);
  991. begin
  992. inherited ppuload(stringdef,ppufile);
  993. stringtype:=st_shortstring;
  994. len:=ppufile.getbyte;
  995. savesize:=len+1;
  996. end;
  997. constructor tstringdef.createlong(l : aint);
  998. begin
  999. inherited create(stringdef);
  1000. stringtype:=st_longstring;
  1001. len:=l;
  1002. savesize:=sizeof(aint);
  1003. end;
  1004. constructor tstringdef.loadlong(ppufile:tcompilerppufile);
  1005. begin
  1006. inherited ppuload(stringdef,ppufile);
  1007. stringtype:=st_longstring;
  1008. len:=ppufile.getaint;
  1009. savesize:=sizeof(aint);
  1010. end;
  1011. constructor tstringdef.createansi(l:aint);
  1012. begin
  1013. inherited create(stringdef);
  1014. stringtype:=st_ansistring;
  1015. len:=l;
  1016. savesize:=sizeof(aint);
  1017. end;
  1018. constructor tstringdef.loadansi(ppufile:tcompilerppufile);
  1019. begin
  1020. inherited ppuload(stringdef,ppufile);
  1021. stringtype:=st_ansistring;
  1022. len:=ppufile.getaint;
  1023. savesize:=sizeof(aint);
  1024. end;
  1025. constructor tstringdef.createwide(l : aint);
  1026. begin
  1027. inherited create(stringdef);
  1028. stringtype:=st_widestring;
  1029. len:=l;
  1030. savesize:=sizeof(aint);
  1031. end;
  1032. constructor tstringdef.loadwide(ppufile:tcompilerppufile);
  1033. begin
  1034. inherited ppuload(stringdef,ppufile);
  1035. stringtype:=st_widestring;
  1036. len:=ppufile.getaint;
  1037. savesize:=sizeof(aint);
  1038. end;
  1039. function tstringdef.getcopy : tstoreddef;
  1040. begin
  1041. result:=tstringdef.create(typ);
  1042. result.typ:=stringdef;
  1043. tstringdef(result).stringtype:=stringtype;
  1044. tstringdef(result).len:=len;
  1045. tstringdef(result).savesize:=savesize;
  1046. end;
  1047. function tstringdef.stringtypname:string;
  1048. const
  1049. typname:array[tstringtype] of string[8]=(
  1050. 'shortstr','longstr','ansistr','widestr'
  1051. );
  1052. begin
  1053. stringtypname:=typname[stringtype];
  1054. end;
  1055. procedure tstringdef.ppuwrite(ppufile:tcompilerppufile);
  1056. begin
  1057. inherited ppuwrite(ppufile);
  1058. if stringtype=st_shortstring then
  1059. begin
  1060. {$ifdef extdebug}
  1061. if len > 255 then internalerror(12122002);
  1062. {$endif}
  1063. ppufile.putbyte(byte(len))
  1064. end
  1065. else
  1066. ppufile.putaint(len);
  1067. case stringtype of
  1068. st_shortstring : ppufile.writeentry(ibshortstringdef);
  1069. st_longstring : ppufile.writeentry(iblongstringdef);
  1070. st_ansistring : ppufile.writeentry(ibansistringdef);
  1071. st_widestring : ppufile.writeentry(ibwidestringdef);
  1072. end;
  1073. end;
  1074. function tstringdef.needs_inittable : boolean;
  1075. begin
  1076. needs_inittable:=stringtype in [st_ansistring,st_widestring];
  1077. end;
  1078. function tstringdef.GetTypeName : string;
  1079. const
  1080. names : array[tstringtype] of string[11] = (
  1081. 'ShortString','LongString','AnsiString','WideString');
  1082. begin
  1083. GetTypeName:=names[stringtype];
  1084. end;
  1085. function tstringdef.getvardef : longint;
  1086. const
  1087. vardef : array[tstringtype] of longint = (
  1088. varUndefined,varUndefined,varString,varOleStr);
  1089. begin
  1090. result:=vardef[stringtype];
  1091. end;
  1092. function tstringdef.alignment : shortint;
  1093. begin
  1094. case stringtype of
  1095. st_widestring,
  1096. st_ansistring:
  1097. alignment:=size_2_align(savesize);
  1098. st_longstring,
  1099. st_shortstring:
  1100. {$ifdef cpurequiresproperalignment}
  1101. { char to string accesses byte 0 and 1 with one word access }
  1102. alignment:=size_2_align(2);
  1103. {$else cpurequiresproperalignment}
  1104. alignment:=size_2_align(1);
  1105. {$endif cpurequiresproperalignment}
  1106. else
  1107. internalerror(200412301);
  1108. end;
  1109. end;
  1110. function tstringdef.getmangledparaname : string;
  1111. begin
  1112. getmangledparaname:='STRING';
  1113. end;
  1114. function tstringdef.is_publishable : boolean;
  1115. begin
  1116. is_publishable:=true;
  1117. end;
  1118. {****************************************************************************
  1119. TENUMDEF
  1120. ****************************************************************************}
  1121. constructor tenumdef.create;
  1122. begin
  1123. inherited create(enumdef);
  1124. minval:=0;
  1125. maxval:=0;
  1126. calcsavesize;
  1127. has_jumps:=false;
  1128. basedef:=nil;
  1129. firstenum:=nil;
  1130. end;
  1131. constructor tenumdef.create_subrange(_basedef:tenumdef;_min,_max:aint);
  1132. begin
  1133. inherited create(enumdef);
  1134. minval:=_min;
  1135. maxval:=_max;
  1136. basedef:=_basedef;
  1137. calcsavesize;
  1138. has_jumps:=false;
  1139. firstenum:=basedef.firstenum;
  1140. while assigned(firstenum) and (tenumsym(firstenum).value<>minval) do
  1141. firstenum:=tenumsym(firstenum).nextenum;
  1142. end;
  1143. constructor tenumdef.ppuload(ppufile:tcompilerppufile);
  1144. begin
  1145. inherited ppuload(enumdef,ppufile);
  1146. ppufile.getderef(basedefderef);
  1147. minval:=ppufile.getaint;
  1148. maxval:=ppufile.getaint;
  1149. savesize:=ppufile.getaint;
  1150. has_jumps:=false;
  1151. firstenum:=Nil;
  1152. end;
  1153. function tenumdef.getcopy : tstoreddef;
  1154. begin
  1155. if assigned(basedef) then
  1156. result:=tenumdef.create_subrange(basedef,minval,maxval)
  1157. else
  1158. begin
  1159. result:=tenumdef.create;
  1160. tenumdef(result).minval:=minval;
  1161. tenumdef(result).maxval:=maxval;
  1162. end;
  1163. tenumdef(result).has_jumps:=has_jumps;
  1164. tenumdef(result).firstenum:=firstenum;
  1165. tenumdef(result).basedefderef:=basedefderef;
  1166. end;
  1167. procedure tenumdef.calcsavesize;
  1168. begin
  1169. if (current_settings.packenum=8) or (min<low(longint)) or (int64(max)>high(cardinal)) then
  1170. savesize:=8
  1171. else
  1172. if (current_settings.packenum=4) or (min<low(smallint)) or (max>high(word)) then
  1173. savesize:=4
  1174. else
  1175. if (current_settings.packenum=2) or (min<low(shortint)) or (max>high(byte)) then
  1176. savesize:=2
  1177. else
  1178. savesize:=1;
  1179. end;
  1180. function tenumdef.packedbitsize: aint;
  1181. var
  1182. power: longint;
  1183. begin
  1184. result := 0;
  1185. if (minval < 0) then
  1186. result := inherited packedbitsize
  1187. else
  1188. begin
  1189. if (maxval <= 1) then
  1190. result := 1
  1191. else
  1192. begin
  1193. { 256 must become 512 etc. }
  1194. nextpowerof2(maxval+1,power);
  1195. result := power;
  1196. end;
  1197. end;
  1198. end;
  1199. procedure tenumdef.setmax(_max:aint);
  1200. begin
  1201. maxval:=_max;
  1202. calcsavesize;
  1203. end;
  1204. procedure tenumdef.setmin(_min:aint);
  1205. begin
  1206. minval:=_min;
  1207. calcsavesize;
  1208. end;
  1209. function tenumdef.min:aint;
  1210. begin
  1211. min:=minval;
  1212. end;
  1213. function tenumdef.max:aint;
  1214. begin
  1215. max:=maxval;
  1216. end;
  1217. procedure tenumdef.buildderef;
  1218. begin
  1219. inherited buildderef;
  1220. basedefderef.build(basedef);
  1221. end;
  1222. procedure tenumdef.deref;
  1223. begin
  1224. inherited deref;
  1225. basedef:=tenumdef(basedefderef.resolve);
  1226. { restart ordering }
  1227. firstenum:=nil;
  1228. end;
  1229. procedure tenumdef.derefimpl;
  1230. begin
  1231. if assigned(basedef) and
  1232. (firstenum=nil) then
  1233. begin
  1234. firstenum:=basedef.firstenum;
  1235. while assigned(firstenum) and (tenumsym(firstenum).value<>minval) do
  1236. firstenum:=tenumsym(firstenum).nextenum;
  1237. end;
  1238. end;
  1239. procedure tenumdef.ppuwrite(ppufile:tcompilerppufile);
  1240. begin
  1241. inherited ppuwrite(ppufile);
  1242. ppufile.putderef(basedefderef);
  1243. ppufile.putaint(min);
  1244. ppufile.putaint(max);
  1245. ppufile.putaint(savesize);
  1246. ppufile.writeentry(ibenumdef);
  1247. end;
  1248. function tenumdef.is_publishable : boolean;
  1249. begin
  1250. is_publishable:=true;
  1251. end;
  1252. function tenumdef.GetTypeName : string;
  1253. begin
  1254. GetTypeName:='<enumeration type>';
  1255. end;
  1256. {****************************************************************************
  1257. TORDDEF
  1258. ****************************************************************************}
  1259. constructor torddef.create(t : tordtype;v,b : TConstExprInt);
  1260. begin
  1261. inherited create(orddef);
  1262. low:=v;
  1263. high:=b;
  1264. ordtype:=t;
  1265. setsize;
  1266. end;
  1267. constructor torddef.ppuload(ppufile:tcompilerppufile);
  1268. begin
  1269. inherited ppuload(orddef,ppufile);
  1270. ordtype:=tordtype(ppufile.getbyte);
  1271. if sizeof(TConstExprInt)=8 then
  1272. begin
  1273. low:=ppufile.getint64;
  1274. high:=ppufile.getint64;
  1275. end
  1276. else
  1277. begin
  1278. low:=ppufile.getlongint;
  1279. high:=ppufile.getlongint;
  1280. end;
  1281. setsize;
  1282. end;
  1283. function torddef.getcopy : tstoreddef;
  1284. begin
  1285. result:=torddef.create(ordtype,low,high);
  1286. result.typ:=orddef;
  1287. torddef(result).low:=low;
  1288. torddef(result).high:=high;
  1289. torddef(result).ordtype:=ordtype;
  1290. torddef(result).savesize:=savesize;
  1291. end;
  1292. function torddef.alignment:shortint;
  1293. begin
  1294. if (target_info.system = system_i386_darwin) and
  1295. (ordtype in [s64bit,u64bit]) then
  1296. result := 4
  1297. else
  1298. result := inherited alignment;
  1299. end;
  1300. procedure torddef.setsize;
  1301. const
  1302. sizetbl : array[tordtype] of longint = (
  1303. 0,
  1304. 1,2,4,8,
  1305. 1,2,4,8,
  1306. 1,2,4,8,
  1307. 1,2,8
  1308. );
  1309. begin
  1310. savesize:=sizetbl[ordtype];
  1311. end;
  1312. function torddef.packedbitsize: aint;
  1313. var
  1314. power: longint;
  1315. begin
  1316. result := 0;
  1317. if ordtype = uvoid then
  1318. exit;
  1319. if (low < 0) then
  1320. result := inherited packedbitsize
  1321. else
  1322. begin
  1323. if (high <= 1) then
  1324. result := 1
  1325. else if (ordtype = u64bit) then
  1326. result := 64
  1327. else
  1328. begin
  1329. { 256 must become 512 etc. }
  1330. nextpowerof2(high+1,power);
  1331. result := power;
  1332. end;
  1333. end;
  1334. end;
  1335. function torddef.getvardef : longint;
  1336. const
  1337. basetype2vardef : array[tordtype] of longint = (
  1338. varUndefined,
  1339. varbyte,varqword,varlongword,varqword,
  1340. varshortint,varsmallint,varinteger,varint64,
  1341. varboolean,varUndefined,varUndefined,varUndefined,
  1342. varUndefined,varUndefined,varCurrency);
  1343. begin
  1344. result:=basetype2vardef[ordtype];
  1345. end;
  1346. procedure torddef.ppuwrite(ppufile:tcompilerppufile);
  1347. begin
  1348. inherited ppuwrite(ppufile);
  1349. ppufile.putbyte(byte(ordtype));
  1350. if sizeof(TConstExprInt)=8 then
  1351. begin
  1352. ppufile.putint64(low);
  1353. ppufile.putint64(high);
  1354. end
  1355. else
  1356. begin
  1357. ppufile.putlongint(low);
  1358. ppufile.putlongint(high);
  1359. end;
  1360. ppufile.writeentry(iborddef);
  1361. end;
  1362. function torddef.is_publishable : boolean;
  1363. begin
  1364. is_publishable:=(ordtype<>uvoid);
  1365. end;
  1366. function torddef.GetTypeName : string;
  1367. const
  1368. names : array[tordtype] of string[20] = (
  1369. 'untyped',
  1370. 'Byte','Word','DWord','QWord',
  1371. 'ShortInt','SmallInt','LongInt','Int64',
  1372. 'Boolean','WordBool','LongBool','QWordBool',
  1373. 'Char','WideChar','Currency');
  1374. begin
  1375. GetTypeName:=names[ordtype];
  1376. end;
  1377. {****************************************************************************
  1378. TFLOATDEF
  1379. ****************************************************************************}
  1380. constructor tfloatdef.create(t : tfloattype);
  1381. begin
  1382. inherited create(floatdef);
  1383. floattype:=t;
  1384. setsize;
  1385. end;
  1386. constructor tfloatdef.ppuload(ppufile:tcompilerppufile);
  1387. begin
  1388. inherited ppuload(floatdef,ppufile);
  1389. floattype:=tfloattype(ppufile.getbyte);
  1390. setsize;
  1391. end;
  1392. function tfloatdef.getcopy : tstoreddef;
  1393. begin
  1394. result:=tfloatdef.create(floattype);
  1395. result.typ:=floatdef;
  1396. tfloatdef(result).savesize:=savesize;
  1397. end;
  1398. function tfloatdef.alignment:shortint;
  1399. begin
  1400. if (target_info.system = system_i386_darwin) then
  1401. case floattype of
  1402. s80real : result:=16;
  1403. s64real,
  1404. s64currency,
  1405. s64comp : result:=4;
  1406. else
  1407. result := inherited alignment;
  1408. end
  1409. else
  1410. result := inherited alignment;
  1411. end;
  1412. procedure tfloatdef.setsize;
  1413. begin
  1414. case floattype of
  1415. s32real : savesize:=4;
  1416. s80real : savesize:=10;
  1417. s64real,
  1418. s64currency,
  1419. s64comp : savesize:=8;
  1420. else
  1421. savesize:=0;
  1422. end;
  1423. end;
  1424. function tfloatdef.getvardef : longint;
  1425. const
  1426. floattype2vardef : array[tfloattype] of longint = (
  1427. varSingle,varDouble,varUndefined,
  1428. varUndefined,varCurrency,varUndefined);
  1429. begin
  1430. if (upper(typename)='TDATETIME') and
  1431. assigned(owner) and
  1432. assigned(owner.name) and
  1433. (owner.name^='SYSTEM') then
  1434. result:=varDate
  1435. else
  1436. result:=floattype2vardef[floattype];
  1437. end;
  1438. procedure tfloatdef.ppuwrite(ppufile:tcompilerppufile);
  1439. begin
  1440. inherited ppuwrite(ppufile);
  1441. ppufile.putbyte(byte(floattype));
  1442. ppufile.writeentry(ibfloatdef);
  1443. end;
  1444. function tfloatdef.is_publishable : boolean;
  1445. begin
  1446. is_publishable:=true;
  1447. end;
  1448. function tfloatdef.GetTypeName : string;
  1449. const
  1450. names : array[tfloattype] of string[20] = (
  1451. 'Single','Double','Extended','Comp','Currency','Float128');
  1452. begin
  1453. GetTypeName:=names[floattype];
  1454. end;
  1455. {****************************************************************************
  1456. TFILEDEF
  1457. ****************************************************************************}
  1458. constructor tfiledef.createtext;
  1459. begin
  1460. inherited create(filedef);
  1461. filetyp:=ft_text;
  1462. typedfiledef:=nil;
  1463. setsize;
  1464. end;
  1465. constructor tfiledef.createuntyped;
  1466. begin
  1467. inherited create(filedef);
  1468. filetyp:=ft_untyped;
  1469. typedfiledef:=nil;
  1470. setsize;
  1471. end;
  1472. constructor tfiledef.createtyped(def:tdef);
  1473. begin
  1474. inherited create(filedef);
  1475. filetyp:=ft_typed;
  1476. typedfiledef:=def;
  1477. setsize;
  1478. end;
  1479. constructor tfiledef.ppuload(ppufile:tcompilerppufile);
  1480. begin
  1481. inherited ppuload(filedef,ppufile);
  1482. filetyp:=tfiletyp(ppufile.getbyte);
  1483. if filetyp=ft_typed then
  1484. ppufile.getderef(typedfiledefderef)
  1485. else
  1486. typedfiledef:=nil;
  1487. setsize;
  1488. end;
  1489. function tfiledef.getcopy : tstoreddef;
  1490. begin
  1491. case filetyp of
  1492. ft_typed:
  1493. result:=tfiledef.createtyped(typedfiledef);
  1494. ft_untyped:
  1495. result:=tfiledef.createuntyped;
  1496. ft_text:
  1497. result:=tfiledef.createtext;
  1498. else
  1499. internalerror(2004121201);
  1500. end;
  1501. end;
  1502. procedure tfiledef.buildderef;
  1503. begin
  1504. inherited buildderef;
  1505. if filetyp=ft_typed then
  1506. typedfiledefderef.build(typedfiledef);
  1507. end;
  1508. procedure tfiledef.deref;
  1509. begin
  1510. inherited deref;
  1511. if filetyp=ft_typed then
  1512. typedfiledef:=tdef(typedfiledefderef.resolve);
  1513. end;
  1514. procedure tfiledef.setsize;
  1515. begin
  1516. {$ifdef cpu64bit}
  1517. case filetyp of
  1518. ft_text :
  1519. if target_info.system in [system_x86_64_win64,system_ia64_win64] then
  1520. savesize:=632
  1521. else
  1522. savesize:=628;
  1523. ft_typed,
  1524. ft_untyped :
  1525. if target_info.system in [system_x86_64_win64,system_ia64_win64] then
  1526. savesize:=372
  1527. else
  1528. savesize:=368;
  1529. end;
  1530. {$else cpu64bit}
  1531. case filetyp of
  1532. ft_text :
  1533. savesize:=592;
  1534. ft_typed,
  1535. ft_untyped :
  1536. savesize:=332;
  1537. end;
  1538. {$endif cpu64bit}
  1539. end;
  1540. procedure tfiledef.ppuwrite(ppufile:tcompilerppufile);
  1541. begin
  1542. inherited ppuwrite(ppufile);
  1543. ppufile.putbyte(byte(filetyp));
  1544. if filetyp=ft_typed then
  1545. ppufile.putderef(typedfiledefderef);
  1546. ppufile.writeentry(ibfiledef);
  1547. end;
  1548. function tfiledef.GetTypeName : string;
  1549. begin
  1550. case filetyp of
  1551. ft_untyped:
  1552. GetTypeName:='File';
  1553. ft_typed:
  1554. GetTypeName:='File Of '+typedfiledef.typename;
  1555. ft_text:
  1556. GetTypeName:='Text'
  1557. end;
  1558. end;
  1559. function tfiledef.getmangledparaname : string;
  1560. begin
  1561. case filetyp of
  1562. ft_untyped:
  1563. getmangledparaname:='FILE';
  1564. ft_typed:
  1565. getmangledparaname:='FILE$OF$'+typedfiledef.mangledparaname;
  1566. ft_text:
  1567. getmangledparaname:='TEXT'
  1568. end;
  1569. end;
  1570. {****************************************************************************
  1571. TVARIANTDEF
  1572. ****************************************************************************}
  1573. constructor tvariantdef.create(v : tvarianttype);
  1574. begin
  1575. inherited create(variantdef);
  1576. varianttype:=v;
  1577. setsize;
  1578. end;
  1579. constructor tvariantdef.ppuload(ppufile:tcompilerppufile);
  1580. begin
  1581. inherited ppuload(variantdef,ppufile);
  1582. varianttype:=tvarianttype(ppufile.getbyte);
  1583. setsize;
  1584. end;
  1585. function tvariantdef.getcopy : tstoreddef;
  1586. begin
  1587. result:=tvariantdef.create(varianttype);
  1588. end;
  1589. procedure tvariantdef.ppuwrite(ppufile:tcompilerppufile);
  1590. begin
  1591. inherited ppuwrite(ppufile);
  1592. ppufile.putbyte(byte(varianttype));
  1593. ppufile.writeentry(ibvariantdef);
  1594. end;
  1595. procedure tvariantdef.setsize;
  1596. begin
  1597. {$ifdef cpu64bit}
  1598. savesize:=24;
  1599. {$else cpu64bit}
  1600. savesize:=16;
  1601. {$endif cpu64bit}
  1602. end;
  1603. function tvariantdef.GetTypeName : string;
  1604. begin
  1605. case varianttype of
  1606. vt_normalvariant:
  1607. GetTypeName:='Variant';
  1608. vt_olevariant:
  1609. GetTypeName:='OleVariant';
  1610. end;
  1611. end;
  1612. function tvariantdef.needs_inittable : boolean;
  1613. begin
  1614. needs_inittable:=true;
  1615. end;
  1616. function tvariantdef.is_publishable : boolean;
  1617. begin
  1618. is_publishable:=true;
  1619. end;
  1620. {****************************************************************************
  1621. TABSTRACtpointerdef
  1622. ****************************************************************************}
  1623. constructor tabstractpointerdef.create(dt:tdeftyp;def:tdef);
  1624. begin
  1625. inherited create(dt);
  1626. pointeddef:=def;
  1627. savesize:=sizeof(aint);
  1628. end;
  1629. constructor tabstractpointerdef.ppuload(dt:tdeftyp;ppufile:tcompilerppufile);
  1630. begin
  1631. inherited ppuload(dt,ppufile);
  1632. ppufile.getderef(pointeddefderef);
  1633. savesize:=sizeof(aint);
  1634. end;
  1635. procedure tabstractpointerdef.buildderef;
  1636. begin
  1637. inherited buildderef;
  1638. pointeddefderef.build(pointeddef);
  1639. end;
  1640. procedure tabstractpointerdef.deref;
  1641. begin
  1642. inherited deref;
  1643. pointeddef:=tdef(pointeddefderef.resolve);
  1644. end;
  1645. procedure tabstractpointerdef.ppuwrite(ppufile:tcompilerppufile);
  1646. begin
  1647. inherited ppuwrite(ppufile);
  1648. ppufile.putderef(pointeddefderef);
  1649. end;
  1650. {****************************************************************************
  1651. tpointerdef
  1652. ****************************************************************************}
  1653. constructor tpointerdef.create(def:tdef);
  1654. begin
  1655. inherited create(pointerdef,def);
  1656. is_far:=false;
  1657. end;
  1658. constructor tpointerdef.createfar(def:tdef);
  1659. begin
  1660. inherited create(pointerdef,def);
  1661. is_far:=true;
  1662. end;
  1663. constructor tpointerdef.ppuload(ppufile:tcompilerppufile);
  1664. begin
  1665. inherited ppuload(pointerdef,ppufile);
  1666. is_far:=(ppufile.getbyte<>0);
  1667. end;
  1668. function tpointerdef.getcopy : tstoreddef;
  1669. begin
  1670. result:=tpointerdef.create(pointeddef);
  1671. tpointerdef(result).is_far:=is_far;
  1672. tpointerdef(result).savesize:=savesize;
  1673. end;
  1674. procedure tpointerdef.ppuwrite(ppufile:tcompilerppufile);
  1675. begin
  1676. inherited ppuwrite(ppufile);
  1677. ppufile.putbyte(byte(is_far));
  1678. ppufile.writeentry(ibpointerdef);
  1679. end;
  1680. function tpointerdef.GetTypeName : string;
  1681. begin
  1682. if is_far then
  1683. GetTypeName:='^'+pointeddef.typename+';far'
  1684. else
  1685. GetTypeName:='^'+pointeddef.typename;
  1686. end;
  1687. {****************************************************************************
  1688. TCLASSREFDEF
  1689. ****************************************************************************}
  1690. constructor tclassrefdef.create(def:tdef);
  1691. begin
  1692. inherited create(classrefdef,def);
  1693. end;
  1694. constructor tclassrefdef.ppuload(ppufile:tcompilerppufile);
  1695. begin
  1696. inherited ppuload(classrefdef,ppufile);
  1697. end;
  1698. procedure tclassrefdef.ppuwrite(ppufile:tcompilerppufile);
  1699. begin
  1700. inherited ppuwrite(ppufile);
  1701. ppufile.writeentry(ibclassrefdef);
  1702. end;
  1703. function tclassrefdef.GetTypeName : string;
  1704. begin
  1705. GetTypeName:='Class Of '+pointeddef.typename;
  1706. end;
  1707. function tclassrefdef.is_publishable : boolean;
  1708. begin
  1709. result:=true;
  1710. end;
  1711. {***************************************************************************
  1712. TSETDEF
  1713. ***************************************************************************}
  1714. constructor tsetdef.create(def:tdef;high : aint);
  1715. begin
  1716. inherited create(setdef);
  1717. elementdef:=def;
  1718. // setbase:=low;
  1719. setmax:=high;
  1720. if high<32 then
  1721. begin
  1722. settype:=smallset;
  1723. {
  1724. if current_settings.setalloc=0 then { $PACKSET Fixed?}
  1725. }
  1726. savesize:=Sizeof(longint)
  1727. {
  1728. else {No, use $PACKSET VALUE for rounding}
  1729. savesize:=current_settings.setalloc*(((high+1)+current_settings.setalloc*8-1) DIV (current_settings.setalloc*8));
  1730. }
  1731. end
  1732. else
  1733. if high<256 then
  1734. begin
  1735. settype:=normset;
  1736. if current_settings.setalloc=0 then { $PACKSET Fixed?}
  1737. savesize:=32
  1738. else {No, use $PACKSET VALUE for rounding}
  1739. savesize:=current_settings.setalloc*(((high+1)+current_settings.setalloc*8-1) DIV (current_settings.setalloc*8));
  1740. end
  1741. else
  1742. savesize:=current_settings.setalloc*(((high+1)+current_settings.setalloc*8-1) DIV (current_settings.setalloc*8));
  1743. end;
  1744. constructor tsetdef.ppuload(ppufile:tcompilerppufile);
  1745. begin
  1746. inherited ppuload(setdef,ppufile);
  1747. ppufile.getderef(elementdefderef);
  1748. settype:=tsettype(ppufile.getbyte);
  1749. case settype of
  1750. normset : savesize:=32;
  1751. varset : savesize:=ppufile.getlongint;
  1752. smallset : savesize:=Sizeof(longint);
  1753. end;
  1754. end;
  1755. function tsetdef.getcopy : tstoreddef;
  1756. begin
  1757. case settype of
  1758. smallset:
  1759. result:=tsetdef.create(elementdef,31);
  1760. normset:
  1761. result:=tsetdef.create(elementdef,255);
  1762. else
  1763. internalerror(2004121202);
  1764. end;
  1765. end;
  1766. procedure tsetdef.ppuwrite(ppufile:tcompilerppufile);
  1767. begin
  1768. inherited ppuwrite(ppufile);
  1769. ppufile.putderef(elementdefderef);
  1770. ppufile.putbyte(byte(settype));
  1771. if settype=varset then
  1772. ppufile.putlongint(savesize);
  1773. if settype=normset then
  1774. ppufile.putaint(savesize);
  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.