symdef.pas 127 KB

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