symdef.pas 130 KB

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