symdef.pas 129 KB

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