symdef.pas 128 KB

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