symdef.pas 127 KB

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