symdef.pas 129 KB

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