symdef.pas 128 KB

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