symdef.pas 127 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324
  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 systems_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 is the size of the elements }
  1970. if (elementdef.typ in [arraydef,recorddef]) or
  1971. ((elementdef.typ=objectdef) and
  1972. is_object(elementdef)) then
  1973. alignment:=elementdef.alignment
  1974. else if not (ado_IsBitPacked in arrayoptions) then
  1975. alignment:=size_2_align(elesize)
  1976. else
  1977. alignment:=packedbitsloadsize(elepackedbitsize);
  1978. end;
  1979. function tarraydef.needs_inittable : boolean;
  1980. begin
  1981. needs_inittable:=(ado_IsDynamicArray in arrayoptions) or elementdef.needs_inittable;
  1982. end;
  1983. function tarraydef.GetTypeName : string;
  1984. begin
  1985. if (ado_IsConstString in arrayoptions) then
  1986. result:='Constant String'
  1987. else if (ado_isarrayofconst in arrayoptions) or
  1988. (ado_isConstructor in arrayoptions) then
  1989. begin
  1990. if (ado_isvariant in arrayoptions) or ((highrange=-1) and (lowrange=0)) then
  1991. GetTypeName:='Array Of Const'
  1992. else
  1993. GetTypeName:='Array Of Const/Constant Open Array of '+elementdef.typename;
  1994. end
  1995. else if (ado_IsDynamicArray in arrayoptions) then
  1996. GetTypeName:='Dynamic Array Of '+elementdef.typename
  1997. else if ((highrange=-1) and (lowrange=0)) then
  1998. GetTypeName:='Open Array Of '+elementdef.typename
  1999. else
  2000. begin
  2001. result := '';
  2002. if (ado_IsBitPacked in arrayoptions) then
  2003. result:='Packed ';
  2004. if rangedef.typ=enumdef then
  2005. result:=result+'Array['+rangedef.typename+'] Of '+elementdef.typename
  2006. else
  2007. result:=result+'Array['+tostr(lowrange)+'..'+
  2008. tostr(highrange)+'] Of '+elementdef.typename
  2009. end;
  2010. end;
  2011. function tarraydef.getmangledparaname : string;
  2012. begin
  2013. if ado_isarrayofconst in arrayoptions then
  2014. getmangledparaname:='array_of_const'
  2015. else
  2016. if ((highrange=-1) and (lowrange=0)) then
  2017. getmangledparaname:='array_of_'+elementdef.mangledparaname
  2018. else
  2019. internalerror(200204176);
  2020. end;
  2021. {***************************************************************************
  2022. tabstractrecorddef
  2023. ***************************************************************************}
  2024. function tabstractrecorddef.GetSymtable(t:tGetSymtable):TSymtable;
  2025. begin
  2026. if t=gs_record then
  2027. GetSymtable:=symtable
  2028. else
  2029. GetSymtable:=nil;
  2030. end;
  2031. procedure tabstractrecorddef.reset;
  2032. begin
  2033. inherited reset;
  2034. tstoredsymtable(symtable).reset_all_defs;
  2035. end;
  2036. function tabstractrecorddef.is_packed:boolean;
  2037. begin
  2038. result:=tabstractrecordsymtable(symtable).is_packed;
  2039. end;
  2040. {***************************************************************************
  2041. trecorddef
  2042. ***************************************************************************}
  2043. constructor trecorddef.create(p : TSymtable);
  2044. begin
  2045. inherited create(recorddef);
  2046. symtable:=p;
  2047. symtable.defowner:=self;
  2048. isunion:=false;
  2049. end;
  2050. constructor trecorddef.ppuload(ppufile:tcompilerppufile);
  2051. begin
  2052. inherited ppuload(recorddef,ppufile);
  2053. symtable:=trecordsymtable.create(0);
  2054. trecordsymtable(symtable).fieldalignment:=shortint(ppufile.getbyte);
  2055. trecordsymtable(symtable).recordalignment:=shortint(ppufile.getbyte);
  2056. trecordsymtable(symtable).padalignment:=shortint(ppufile.getbyte);
  2057. trecordsymtable(symtable).usefieldalignment:=shortint(ppufile.getbyte);
  2058. { requires usefieldalignment to be set }
  2059. trecordsymtable(symtable).datasize:=ppufile.getaint;
  2060. trecordsymtable(symtable).ppuload(ppufile);
  2061. symtable.defowner:=self;
  2062. isunion:=false;
  2063. end;
  2064. destructor trecorddef.destroy;
  2065. begin
  2066. if assigned(symtable) then
  2067. begin
  2068. symtable.free;
  2069. symtable:=nil;
  2070. end;
  2071. inherited destroy;
  2072. end;
  2073. function trecorddef.getcopy : tstoreddef;
  2074. begin
  2075. result:=trecorddef.create(symtable.getcopy);
  2076. trecorddef(result).isunion:=isunion;
  2077. end;
  2078. function trecorddef.needs_inittable : boolean;
  2079. begin
  2080. needs_inittable:=trecordsymtable(symtable).needs_init_final
  2081. end;
  2082. procedure trecorddef.buildderef;
  2083. begin
  2084. inherited buildderef;
  2085. tstoredsymtable(symtable).buildderef;
  2086. end;
  2087. procedure trecorddef.deref;
  2088. begin
  2089. inherited deref;
  2090. { now dereference the definitions }
  2091. tstoredsymtable(symtable).deref;
  2092. { assign TGUID? load only from system unit }
  2093. if not(assigned(rec_tguid)) and
  2094. (upper(typename)='TGUID') and
  2095. assigned(owner) and
  2096. assigned(owner.name) and
  2097. (owner.name^='SYSTEM') then
  2098. rec_tguid:=self;
  2099. end;
  2100. procedure trecorddef.ppuwrite(ppufile:tcompilerppufile);
  2101. begin
  2102. inherited ppuwrite(ppufile);
  2103. ppufile.putbyte(byte(trecordsymtable(symtable).fieldalignment));
  2104. ppufile.putbyte(byte(trecordsymtable(symtable).recordalignment));
  2105. ppufile.putbyte(byte(trecordsymtable(symtable).padalignment));
  2106. ppufile.putbyte(byte(trecordsymtable(symtable).usefieldalignment));
  2107. ppufile.putaint(trecordsymtable(symtable).datasize);
  2108. ppufile.writeentry(ibrecorddef);
  2109. trecordsymtable(symtable).ppuwrite(ppufile);
  2110. end;
  2111. function trecorddef.size:aint;
  2112. begin
  2113. result:=trecordsymtable(symtable).datasize;
  2114. end;
  2115. function trecorddef.alignment:shortint;
  2116. begin
  2117. alignment:=trecordsymtable(symtable).recordalignment;
  2118. end;
  2119. function trecorddef.padalignment:shortint;
  2120. begin
  2121. padalignment := trecordsymtable(symtable).padalignment;
  2122. end;
  2123. function trecorddef.GetTypeName : string;
  2124. begin
  2125. GetTypeName:='<record type>'
  2126. end;
  2127. {***************************************************************************
  2128. TABSTRACTPROCDEF
  2129. ***************************************************************************}
  2130. constructor tabstractprocdef.create(dt:tdeftyp;level:byte);
  2131. begin
  2132. inherited create(dt);
  2133. parast:=tparasymtable.create(self,level);
  2134. paras:=nil;
  2135. minparacount:=0;
  2136. maxparacount:=0;
  2137. proctypeoption:=potype_none;
  2138. proccalloption:=pocall_none;
  2139. procoptions:=[];
  2140. returndef:=voidtype;
  2141. {$ifdef i386}
  2142. fpu_used:=0;
  2143. {$endif i386}
  2144. savesize:=sizeof(aint);
  2145. requiredargarea:=0;
  2146. has_paraloc_info:=false;
  2147. location_reset(funcretloc[callerside],LOC_INVALID,OS_NO);
  2148. location_reset(funcretloc[calleeside],LOC_INVALID,OS_NO);
  2149. end;
  2150. destructor tabstractprocdef.destroy;
  2151. begin
  2152. if assigned(paras) then
  2153. begin
  2154. {$ifdef MEMDEBUG}
  2155. memprocpara.start;
  2156. {$endif MEMDEBUG}
  2157. paras.free;
  2158. paras:=nil;
  2159. {$ifdef MEMDEBUG}
  2160. memprocpara.stop;
  2161. {$endif MEMDEBUG}
  2162. end;
  2163. if assigned(parast) then
  2164. begin
  2165. {$ifdef MEMDEBUG}
  2166. memprocparast.start;
  2167. {$endif MEMDEBUG}
  2168. parast.free;
  2169. parast:=nil;
  2170. {$ifdef MEMDEBUG}
  2171. memprocparast.stop;
  2172. {$endif MEMDEBUG}
  2173. end;
  2174. inherited destroy;
  2175. end;
  2176. procedure tabstractprocdef.count_para(p:TObject;arg:pointer);
  2177. begin
  2178. if (tsym(p).typ<>paravarsym) then
  2179. exit;
  2180. inc(plongint(arg)^);
  2181. if not(vo_is_hidden_para in tparavarsym(p).varoptions) then
  2182. begin
  2183. if not assigned(tparavarsym(p).defaultconstsym) then
  2184. inc(minparacount);
  2185. inc(maxparacount);
  2186. end;
  2187. end;
  2188. procedure tabstractprocdef.insert_para(p:TObject;arg:pointer);
  2189. begin
  2190. if (tsym(p).typ<>paravarsym) then
  2191. exit;
  2192. paras.add(p);
  2193. end;
  2194. procedure tabstractprocdef.calcparas;
  2195. var
  2196. paracount : longint;
  2197. begin
  2198. { This can already be assigned when
  2199. we need to reresolve this unit (PFV) }
  2200. if assigned(paras) then
  2201. paras.free;
  2202. paras:=tparalist.create(false);
  2203. paracount:=0;
  2204. minparacount:=0;
  2205. maxparacount:=0;
  2206. parast.SymList.ForEachCall(@count_para,@paracount);
  2207. paras.capacity:=paracount;
  2208. { Insert parameters in table }
  2209. parast.SymList.ForEachCall(@insert_para,nil);
  2210. { Order parameters }
  2211. paras.sortparas;
  2212. end;
  2213. { all functions returning in FPU are
  2214. assume to use 2 FPU registers
  2215. until the function implementation
  2216. is processed PM }
  2217. procedure tabstractprocdef.test_if_fpu_result;
  2218. begin
  2219. {$ifdef i386}
  2220. if assigned(returndef) and
  2221. (returndef.typ=floatdef) then
  2222. fpu_used:=maxfpuregs;
  2223. {$endif i386}
  2224. end;
  2225. procedure tabstractprocdef.buildderef;
  2226. begin
  2227. { released procdef? }
  2228. if not assigned(parast) then
  2229. exit;
  2230. inherited buildderef;
  2231. returndefderef.build(returndef);
  2232. { parast }
  2233. tparasymtable(parast).buildderef;
  2234. end;
  2235. procedure tabstractprocdef.deref;
  2236. begin
  2237. inherited deref;
  2238. returndef:=tdef(returndefderef.resolve);
  2239. { parast }
  2240. tparasymtable(parast).deref;
  2241. { recalculated parameters }
  2242. calcparas;
  2243. end;
  2244. constructor tabstractprocdef.ppuload(dt:tdeftyp;ppufile:tcompilerppufile);
  2245. var
  2246. b : byte;
  2247. begin
  2248. inherited ppuload(dt,ppufile);
  2249. parast:=nil;
  2250. Paras:=nil;
  2251. minparacount:=0;
  2252. maxparacount:=0;
  2253. ppufile.getderef(returndefderef);
  2254. {$ifdef i386}
  2255. fpu_used:=ppufile.getbyte;
  2256. {$else}
  2257. ppufile.getbyte;
  2258. {$endif i386}
  2259. proctypeoption:=tproctypeoption(ppufile.getbyte);
  2260. proccalloption:=tproccalloption(ppufile.getbyte);
  2261. ppufile.getnormalset(procoptions);
  2262. location_reset(funcretloc[callerside],LOC_INVALID,OS_NO);
  2263. location_reset(funcretloc[calleeside],LOC_INVALID,OS_NO);
  2264. if po_explicitparaloc in procoptions then
  2265. begin
  2266. b:=ppufile.getbyte;
  2267. if b<>sizeof(funcretloc[callerside]) then
  2268. internalerror(200411154);
  2269. ppufile.getdata(funcretloc[callerside],sizeof(funcretloc[callerside]));
  2270. end;
  2271. savesize:=sizeof(aint);
  2272. has_paraloc_info:=(po_explicitparaloc in procoptions);
  2273. end;
  2274. procedure tabstractprocdef.ppuwrite(ppufile:tcompilerppufile);
  2275. var
  2276. oldintfcrc : boolean;
  2277. begin
  2278. { released procdef? }
  2279. if not assigned(parast) then
  2280. exit;
  2281. inherited ppuwrite(ppufile);
  2282. ppufile.putderef(returndefderef);
  2283. oldintfcrc:=ppufile.do_interface_crc;
  2284. ppufile.do_interface_crc:=false;
  2285. {$ifdef i386}
  2286. if simplify_ppu then
  2287. fpu_used:=0;
  2288. ppufile.putbyte(fpu_used);
  2289. {$else}
  2290. ppufile.putbyte(0);
  2291. {$endif}
  2292. ppufile.putbyte(ord(proctypeoption));
  2293. ppufile.putbyte(ord(proccalloption));
  2294. ppufile.putnormalset(procoptions);
  2295. ppufile.do_interface_crc:=oldintfcrc;
  2296. if (po_explicitparaloc in procoptions) then
  2297. begin
  2298. { Make a 'valid' funcretloc for procedures }
  2299. ppufile.putbyte(sizeof(funcretloc[callerside]));
  2300. ppufile.putdata(funcretloc[callerside],sizeof(funcretloc[callerside]));
  2301. end;
  2302. end;
  2303. function tabstractprocdef.typename_paras(showhidden:boolean) : string;
  2304. var
  2305. hs,s : string;
  2306. hp : TParavarsym;
  2307. hpc : tconstsym;
  2308. first : boolean;
  2309. i : integer;
  2310. begin
  2311. s:='';
  2312. first:=true;
  2313. for i:=0 to paras.count-1 do
  2314. begin
  2315. hp:=tparavarsym(paras[i]);
  2316. if not(vo_is_hidden_para in hp.varoptions) or
  2317. (showhidden) then
  2318. begin
  2319. if first then
  2320. begin
  2321. s:=s+'(';
  2322. first:=false;
  2323. end
  2324. else
  2325. s:=s+',';
  2326. if vo_is_hidden_para in hp.varoptions then
  2327. s:=s+'<';
  2328. case hp.varspez of
  2329. vs_var :
  2330. s:=s+'var';
  2331. vs_const :
  2332. s:=s+'const';
  2333. vs_out :
  2334. s:=s+'out';
  2335. end;
  2336. if assigned(hp.vardef.typesym) then
  2337. begin
  2338. if s<>'(' then
  2339. s:=s+' ';
  2340. hs:=hp.vardef.typesym.realname;
  2341. if hs[1]<>'$' then
  2342. s:=s+hp.vardef.typesym.realname
  2343. else
  2344. s:=s+hp.vardef.GetTypeName;
  2345. end
  2346. else
  2347. s:=s+hp.vardef.GetTypeName;
  2348. { default value }
  2349. if assigned(hp.defaultconstsym) then
  2350. begin
  2351. hpc:=tconstsym(hp.defaultconstsym);
  2352. hs:='';
  2353. case hpc.consttyp of
  2354. conststring,
  2355. constresourcestring :
  2356. hs:=strpas(pchar(hpc.value.valueptr));
  2357. constreal :
  2358. str(pbestreal(hpc.value.valueptr)^,hs);
  2359. constpointer :
  2360. hs:=tostr(hpc.value.valueordptr);
  2361. constord :
  2362. begin
  2363. if is_boolean(hpc.constdef) then
  2364. begin
  2365. if hpc.value.valueord<>0 then
  2366. hs:='TRUE'
  2367. else
  2368. hs:='FALSE';
  2369. end
  2370. else
  2371. hs:=tostr(hpc.value.valueord);
  2372. end;
  2373. constnil :
  2374. hs:='nil';
  2375. constset :
  2376. hs:='<set>';
  2377. end;
  2378. if hs<>'' then
  2379. s:=s+'="'+hs+'"';
  2380. end;
  2381. if vo_is_hidden_para in hp.varoptions then
  2382. s:=s+'>';
  2383. end;
  2384. end;
  2385. if not first then
  2386. s:=s+')';
  2387. if (po_varargs in procoptions) then
  2388. s:=s+';VarArgs';
  2389. typename_paras:=s;
  2390. end;
  2391. function tabstractprocdef.is_methodpointer:boolean;
  2392. begin
  2393. result:=false;
  2394. end;
  2395. function tabstractprocdef.is_addressonly:boolean;
  2396. begin
  2397. result:=true;
  2398. end;
  2399. {***************************************************************************
  2400. TPROCDEF
  2401. ***************************************************************************}
  2402. constructor tprocdef.create(level:byte);
  2403. begin
  2404. inherited create(procdef,level);
  2405. localst:=tlocalsymtable.create(self,parast.symtablelevel);
  2406. _mangledname:=nil;
  2407. fileinfo:=current_filepos;
  2408. extnumber:=$ffff;
  2409. aliasnames:=TCmdStrList.create;
  2410. funcretsym:=nil;
  2411. forwarddef:=true;
  2412. interfacedef:=false;
  2413. hasforward:=false;
  2414. _class := nil;
  2415. import_dll:=nil;
  2416. import_name:=nil;
  2417. import_nr:=0;
  2418. inlininginfo:=nil;
  2419. end;
  2420. constructor tprocdef.ppuload(ppufile:tcompilerppufile);
  2421. var
  2422. level : byte;
  2423. begin
  2424. inherited ppuload(procdef,ppufile);
  2425. if po_has_mangledname in procoptions then
  2426. _mangledname:=stringdup(ppufile.getstring)
  2427. else
  2428. _mangledname:=nil;
  2429. extnumber:=ppufile.getword;
  2430. level:=ppufile.getbyte;
  2431. ppufile.getderef(_classderef);
  2432. ppufile.getderef(procsymderef);
  2433. ppufile.getposinfo(fileinfo);
  2434. ppufile.getsmallset(symoptions);
  2435. {$ifdef powerpc}
  2436. { library symbol for AmigaOS/MorphOS }
  2437. ppufile.getderef(libsymderef);
  2438. {$endif powerpc}
  2439. { import stuff }
  2440. if po_has_importdll in procoptions then
  2441. import_dll:=stringdup(ppufile.getstring)
  2442. else
  2443. import_dll:=nil;
  2444. if po_has_importname in procoptions then
  2445. import_name:=stringdup(ppufile.getstring)
  2446. else
  2447. import_name:=nil;
  2448. import_nr:=ppufile.getword;
  2449. if (po_msgint in procoptions) then
  2450. messageinf.i:=ppufile.getlongint;
  2451. if (po_msgstr in procoptions) then
  2452. messageinf.str:=stringdup(ppufile.getstring);
  2453. if (po_dispid in procoptions) then
  2454. dispid:=ppufile.getlongint;
  2455. { inline stuff }
  2456. if (po_has_inlininginfo in procoptions) then
  2457. begin
  2458. ppufile.getderef(funcretsymderef);
  2459. new(inlininginfo);
  2460. ppufile.getsmallset(inlininginfo^.flags);
  2461. end
  2462. else
  2463. begin
  2464. inlininginfo:=nil;
  2465. funcretsym:=nil;
  2466. end;
  2467. { load para symtable }
  2468. parast:=tparasymtable.create(self,level);
  2469. tparasymtable(parast).ppuload(ppufile);
  2470. { load local symtable }
  2471. if (po_has_inlininginfo in procoptions) then
  2472. begin
  2473. localst:=tlocalsymtable.create(self,level);
  2474. tlocalsymtable(localst).ppuload(ppufile);
  2475. end
  2476. else
  2477. localst:=nil;
  2478. { inline stuff }
  2479. if (po_has_inlininginfo in procoptions) then
  2480. inlininginfo^.code:=ppuloadnodetree(ppufile);
  2481. { default values for no persistent data }
  2482. if (cs_link_deffile in current_settings.globalswitches) and
  2483. (tf_need_export in target_info.flags) and
  2484. (po_exports in procoptions) then
  2485. deffile.AddExport(mangledname);
  2486. aliasnames:=TCmdStrList.create;
  2487. forwarddef:=false;
  2488. interfacedef:=false;
  2489. hasforward:=false;
  2490. { Disable po_has_inlining until the derefimpl is done }
  2491. exclude(procoptions,po_has_inlininginfo);
  2492. end;
  2493. destructor tprocdef.destroy;
  2494. begin
  2495. aliasnames.free;
  2496. aliasnames:=nil;
  2497. if assigned(localst) and
  2498. (localst.symtabletype<>staticsymtable) then
  2499. begin
  2500. {$ifdef MEMDEBUG}
  2501. memproclocalst.start;
  2502. {$endif MEMDEBUG}
  2503. localst.free;
  2504. localst:=nil;
  2505. {$ifdef MEMDEBUG}
  2506. memproclocalst.start;
  2507. {$endif MEMDEBUG}
  2508. end;
  2509. if assigned(inlininginfo) then
  2510. begin
  2511. {$ifdef MEMDEBUG}
  2512. memprocnodetree.start;
  2513. {$endif MEMDEBUG}
  2514. tnode(inlininginfo^.code).free;
  2515. {$ifdef MEMDEBUG}
  2516. memprocnodetree.start;
  2517. {$endif MEMDEBUG}
  2518. dispose(inlininginfo);
  2519. inlininginfo:=nil;
  2520. end;
  2521. stringdispose(resultname);
  2522. stringdispose(import_dll);
  2523. stringdispose(import_name);
  2524. if (po_msgstr in procoptions) then
  2525. stringdispose(messageinf.str);
  2526. if assigned(_mangledname) then
  2527. begin
  2528. {$ifdef MEMDEBUG}
  2529. memmanglednames.start;
  2530. {$endif MEMDEBUG}
  2531. stringdispose(_mangledname);
  2532. {$ifdef MEMDEBUG}
  2533. memmanglednames.stop;
  2534. {$endif MEMDEBUG}
  2535. end;
  2536. inherited destroy;
  2537. end;
  2538. procedure tprocdef.ppuwrite(ppufile:tcompilerppufile);
  2539. var
  2540. oldintfcrc : boolean;
  2541. begin
  2542. { released procdef? }
  2543. if not assigned(parast) then
  2544. exit;
  2545. inherited ppuwrite(ppufile);
  2546. if po_has_mangledname in procoptions then
  2547. ppufile.putstring(_mangledname^);
  2548. ppufile.putword(extnumber);
  2549. ppufile.putbyte(parast.symtablelevel);
  2550. ppufile.putderef(_classderef);
  2551. ppufile.putderef(procsymderef);
  2552. ppufile.putposinfo(fileinfo);
  2553. ppufile.putsmallset(symoptions);
  2554. {$ifdef powerpc}
  2555. { library symbol for AmigaOS/MorphOS }
  2556. ppufile.putderef(libsymderef);
  2557. {$endif powerpc}
  2558. { import }
  2559. if po_has_importdll in procoptions then
  2560. ppufile.putstring(import_dll^);
  2561. if po_has_importname in procoptions then
  2562. ppufile.putstring(import_name^);
  2563. ppufile.putword(import_nr);
  2564. if (po_msgint in procoptions) then
  2565. ppufile.putlongint(messageinf.i);
  2566. if (po_msgstr in procoptions) then
  2567. ppufile.putstring(messageinf.str^);
  2568. if (po_dispid in procoptions) then
  2569. ppufile.putlongint(dispid);
  2570. { inline stuff }
  2571. oldintfcrc:=ppufile.do_crc;
  2572. ppufile.do_crc:=false;
  2573. if (po_has_inlininginfo in procoptions) then
  2574. begin
  2575. ppufile.putderef(funcretsymderef);
  2576. ppufile.putsmallset(inlininginfo^.flags);
  2577. end;
  2578. ppufile.do_crc:=oldintfcrc;
  2579. { write this entry }
  2580. ppufile.writeentry(ibprocdef);
  2581. { Save the para symtable, this is taken from the interface }
  2582. tparasymtable(parast).ppuwrite(ppufile);
  2583. { save localsymtable for inline procedures or when local
  2584. browser info is requested, this has no influence on the crc }
  2585. if (po_has_inlininginfo in procoptions) then
  2586. begin
  2587. oldintfcrc:=ppufile.do_crc;
  2588. ppufile.do_crc:=false;
  2589. tlocalsymtable(localst).ppuwrite(ppufile);
  2590. ppufile.do_crc:=oldintfcrc;
  2591. end;
  2592. { node tree for inlining }
  2593. oldintfcrc:=ppufile.do_crc;
  2594. ppufile.do_crc:=false;
  2595. if (po_has_inlininginfo in procoptions) then
  2596. ppuwritenodetree(ppufile,inlininginfo^.code);
  2597. ppufile.do_crc:=oldintfcrc;
  2598. end;
  2599. procedure tprocdef.reset;
  2600. begin
  2601. inherited reset;
  2602. procstarttai:=nil;
  2603. procendtai:=nil;
  2604. end;
  2605. function tprocdef.fullprocname(showhidden:boolean):string;
  2606. var
  2607. s : string;
  2608. t : ttoken;
  2609. begin
  2610. {$ifdef EXTDEBUG}
  2611. showhidden:=true;
  2612. {$endif EXTDEBUG}
  2613. s:='';
  2614. if owner.symtabletype=localsymtable then
  2615. s:=s+'local ';
  2616. if assigned(_class) then
  2617. begin
  2618. if po_classmethod in procoptions then
  2619. s:=s+'class ';
  2620. s:=s+_class.objrealname^+'.';
  2621. end;
  2622. if proctypeoption=potype_operator then
  2623. begin
  2624. for t:=NOTOKEN to last_overloaded do
  2625. if procsym.realname='$'+overloaded_names[t] then
  2626. begin
  2627. s:='operator '+arraytokeninfo[t].str+typename_paras(showhidden);
  2628. break;
  2629. end;
  2630. end
  2631. else
  2632. s:=s+procsym.realname+typename_paras(showhidden);
  2633. case proctypeoption of
  2634. potype_constructor:
  2635. s:='constructor '+s;
  2636. potype_destructor:
  2637. s:='destructor '+s;
  2638. else
  2639. if assigned(returndef) and
  2640. not(is_void(returndef)) then
  2641. s:=s+':'+returndef.GetTypeName;
  2642. end;
  2643. { forced calling convention? }
  2644. if (po_hascallingconvention in procoptions) then
  2645. s:=s+';'+ProcCallOptionStr[proccalloption];
  2646. fullprocname:=s;
  2647. end;
  2648. function tprocdef.is_methodpointer:boolean;
  2649. begin
  2650. result:=assigned(_class);
  2651. end;
  2652. function tprocdef.is_addressonly:boolean;
  2653. begin
  2654. result:=assigned(owner) and
  2655. (owner.symtabletype<>ObjectSymtable);
  2656. end;
  2657. function tprocdef.is_visible_for_object(currobjdef,contextobjdef:tobjectdef):boolean;
  2658. var
  2659. contextst : TSymtable;
  2660. begin
  2661. result:=false;
  2662. { Support passing a context in which module we are to find protected members }
  2663. if assigned(contextobjdef) then
  2664. contextst:=contextobjdef.owner
  2665. else
  2666. contextst:=nil;
  2667. { private symbols are allowed when we are in the same
  2668. module as they are defined }
  2669. if (sp_private in symoptions) and
  2670. (owner.defowner.owner.symtabletype in [globalsymtable,staticsymtable]) and
  2671. not(owner.defowner.owner.iscurrentunit or (owner.defowner.owner=contextst)) then
  2672. exit;
  2673. if (sp_strictprivate in symoptions) then
  2674. begin
  2675. result:=currobjdef=tobjectdef(owner.defowner);
  2676. exit;
  2677. end;
  2678. if (sp_strictprotected in symoptions) then
  2679. begin
  2680. result:=assigned(currobjdef) and
  2681. currobjdef.is_related(tobjectdef(owner.defowner));
  2682. exit;
  2683. end;
  2684. { protected symbols are visible in the module that defines them and
  2685. also visible to related objects. The related object must be defined
  2686. in the current module }
  2687. if (sp_protected in symoptions) and
  2688. (
  2689. (
  2690. (owner.defowner.owner.symtabletype in [globalsymtable,staticsymtable]) and
  2691. not((owner.defowner.owner.iscurrentunit) or (owner.defowner.owner=contextst))
  2692. ) and
  2693. not(
  2694. assigned(currobjdef) and
  2695. (currobjdef.owner.symtabletype in [globalsymtable,staticsymtable]) and
  2696. (currobjdef.owner.iscurrentunit) and
  2697. currobjdef.is_related(tobjectdef(owner.defowner))
  2698. )
  2699. ) then
  2700. exit;
  2701. result:=true;
  2702. end;
  2703. function tprocdef.GetSymtable(t:tGetSymtable):TSymtable;
  2704. begin
  2705. case t of
  2706. gs_local :
  2707. GetSymtable:=localst;
  2708. gs_para :
  2709. GetSymtable:=parast;
  2710. else
  2711. GetSymtable:=nil;
  2712. end;
  2713. end;
  2714. procedure tprocdef.buildderef;
  2715. begin
  2716. inherited buildderef;
  2717. _classderef.build(_class);
  2718. { procsym that originaly defined this definition, should be in the
  2719. same symtable }
  2720. procsymderef.build(procsym);
  2721. {$ifdef powerpc}
  2722. { library symbol for AmigaOS/MorphOS }
  2723. libsymderef.build(libsym);
  2724. {$endif powerpc}
  2725. end;
  2726. procedure tprocdef.buildderefimpl;
  2727. begin
  2728. inherited buildderefimpl;
  2729. { Localst is not available for main/unit init }
  2730. if assigned(localst) then
  2731. begin
  2732. tlocalsymtable(localst).buildderef;
  2733. tlocalsymtable(localst).buildderefimpl;
  2734. end;
  2735. { inline tree }
  2736. if (po_has_inlininginfo in procoptions) then
  2737. begin
  2738. funcretsymderef.build(funcretsym);
  2739. inlininginfo^.code.buildderefimpl;
  2740. end;
  2741. end;
  2742. procedure tprocdef.deref;
  2743. begin
  2744. inherited deref;
  2745. _class:=tobjectdef(_classderef.resolve);
  2746. { procsym that originaly defined this definition, should be in the
  2747. same symtable }
  2748. procsym:=tprocsym(procsymderef.resolve);
  2749. {$ifdef powerpc}
  2750. { library symbol for AmigaOS/MorphOS }
  2751. libsym:=tsym(libsymderef.resolve);
  2752. {$endif powerpc}
  2753. end;
  2754. procedure tprocdef.derefimpl;
  2755. begin
  2756. { Enable has_inlininginfo when the inlininginfo
  2757. structure is available. The has_inlininginfo was disabled
  2758. after the load, since the data was invalid }
  2759. if assigned(inlininginfo) then
  2760. include(procoptions,po_has_inlininginfo);
  2761. { Locals }
  2762. if assigned(localst) then
  2763. begin
  2764. tlocalsymtable(localst).deref;
  2765. tlocalsymtable(localst).derefimpl;
  2766. end;
  2767. { Inline }
  2768. if (po_has_inlininginfo in procoptions) then
  2769. begin
  2770. inlininginfo^.code.derefimpl;
  2771. { funcretsym, this is always located in the localst }
  2772. funcretsym:=tsym(funcretsymderef.resolve);
  2773. end
  2774. else
  2775. begin
  2776. { safety }
  2777. funcretsym:=nil;
  2778. end;
  2779. end;
  2780. function tprocdef.GetTypeName : string;
  2781. begin
  2782. GetTypeName := FullProcName(false);
  2783. end;
  2784. function tprocdef.mangledname : string;
  2785. var
  2786. hp : TParavarsym;
  2787. hs : string;
  2788. crc : dword;
  2789. newlen,
  2790. oldlen,
  2791. i : integer;
  2792. begin
  2793. if assigned(_mangledname) then
  2794. begin
  2795. {$ifdef compress}
  2796. mangledname:=minilzw_decode(_mangledname^);
  2797. {$else}
  2798. mangledname:=_mangledname^;
  2799. {$endif}
  2800. exit;
  2801. end;
  2802. { we need to use the symtable where the procsym is inserted,
  2803. because that is visible to the world }
  2804. mangledname:=make_mangledname('',procsym.owner,procsym.name);
  2805. oldlen:=length(mangledname);
  2806. { add parameter types }
  2807. for i:=0 to paras.count-1 do
  2808. begin
  2809. hp:=tparavarsym(paras[i]);
  2810. if not(vo_is_hidden_para in hp.varoptions) then
  2811. mangledname:=mangledname+'$'+hp.vardef.mangledparaname;
  2812. end;
  2813. { add resultdef, add $$ as separator to make it unique from a
  2814. parameter separator }
  2815. if not is_void(returndef) then
  2816. mangledname:=mangledname+'$$'+returndef.mangledparaname;
  2817. newlen:=length(mangledname);
  2818. { Replace with CRC if the parameter line is very long }
  2819. if (newlen-oldlen>12) and
  2820. ((newlen>128) or (newlen-oldlen>64)) then
  2821. begin
  2822. crc:=$ffffffff;
  2823. for i:=0 to paras.count-1 do
  2824. begin
  2825. hp:=tparavarsym(paras[i]);
  2826. if not(vo_is_hidden_para in hp.varoptions) then
  2827. begin
  2828. hs:=hp.vardef.mangledparaname;
  2829. crc:=UpdateCrc32(crc,hs[1],length(hs));
  2830. end;
  2831. end;
  2832. hs:=hp.vardef.mangledparaname;
  2833. crc:=UpdateCrc32(crc,hs[1],length(hs));
  2834. mangledname:=Copy(mangledname,1,oldlen)+'$crc'+hexstr(crc,8);
  2835. end;
  2836. {$ifdef compress}
  2837. _mangledname:=stringdup(minilzw_encode(mangledname));
  2838. {$else}
  2839. _mangledname:=stringdup(mangledname);
  2840. {$endif}
  2841. end;
  2842. function tprocdef.cplusplusmangledname : string;
  2843. function getcppparaname(p : tdef) : string;
  2844. const
  2845. ordtype2str : array[tordtype] of string[2] = (
  2846. '',
  2847. 'Uc','Us','Ui','Us',
  2848. 'Sc','s','i','x',
  2849. 'b','b','b','b',
  2850. 'c','w','x');
  2851. var
  2852. s : string;
  2853. begin
  2854. case p.typ of
  2855. orddef:
  2856. s:=ordtype2str[torddef(p).ordtype];
  2857. pointerdef:
  2858. s:='P'+getcppparaname(tpointerdef(p).pointeddef);
  2859. else
  2860. internalerror(2103001);
  2861. end;
  2862. getcppparaname:=s;
  2863. end;
  2864. var
  2865. s,s2 : string;
  2866. hp : TParavarsym;
  2867. i : integer;
  2868. begin
  2869. s := procsym.realname;
  2870. if procsym.owner.symtabletype=ObjectSymtable then
  2871. begin
  2872. s2:=upper(tobjectdef(procsym.owner.defowner).typesym.realname);
  2873. case proctypeoption of
  2874. potype_destructor:
  2875. s:='_$_'+tostr(length(s2))+s2;
  2876. potype_constructor:
  2877. s:='___'+tostr(length(s2))+s2;
  2878. else
  2879. s:='_'+s+'__'+tostr(length(s2))+s2;
  2880. end;
  2881. end
  2882. else s:=s+'__';
  2883. s:=s+'F';
  2884. { concat modifiers }
  2885. { !!!!! }
  2886. { now we handle the parameters }
  2887. if maxparacount>0 then
  2888. begin
  2889. for i:=0 to paras.count-1 do
  2890. begin
  2891. hp:=tparavarsym(paras[i]);
  2892. s2:=getcppparaname(hp.vardef);
  2893. if hp.varspez in [vs_var,vs_out] then
  2894. s2:='R'+s2;
  2895. s:=s+s2;
  2896. end;
  2897. end
  2898. else
  2899. s:=s+'v';
  2900. cplusplusmangledname:=s;
  2901. end;
  2902. procedure tprocdef.setmangledname(const s : string);
  2903. begin
  2904. { This is not allowed anymore, the forward declaration
  2905. already needs to create the correct mangledname, no changes
  2906. afterwards are allowed (PFV) }
  2907. { Exception: interface definitions in mode macpas, since in that }
  2908. { case no reference to the old name can exist yet (JM) }
  2909. if assigned(_mangledname) then
  2910. if ((m_mac in current_settings.modeswitches) and
  2911. (interfacedef)) then
  2912. stringdispose(_mangledname)
  2913. else
  2914. internalerror(200411171);
  2915. {$ifdef compress}
  2916. _mangledname:=stringdup(minilzw_encode(s));
  2917. {$else}
  2918. _mangledname:=stringdup(s);
  2919. {$endif}
  2920. include(procoptions,po_has_mangledname);
  2921. end;
  2922. {***************************************************************************
  2923. TPROCVARDEF
  2924. ***************************************************************************}
  2925. constructor tprocvardef.create(level:byte);
  2926. begin
  2927. inherited create(procvardef,level);
  2928. end;
  2929. constructor tprocvardef.ppuload(ppufile:tcompilerppufile);
  2930. begin
  2931. inherited ppuload(procvardef,ppufile);
  2932. { load para symtable }
  2933. parast:=tparasymtable.create(self,unknown_level);
  2934. tparasymtable(parast).ppuload(ppufile);
  2935. end;
  2936. function tprocvardef.getcopy : tstoreddef;
  2937. var
  2938. i : tcallercallee;
  2939. j : longint;
  2940. begin
  2941. result:=tprocvardef.create(parast.symtablelevel);
  2942. tprocvardef(result).returndef:=returndef;
  2943. tprocvardef(result).returndefderef:=returndefderef;
  2944. tprocvardef(result).parast:=parast.getcopy;
  2945. tprocvardef(result).savesize:=savesize;
  2946. { create paralist copy }
  2947. tprocvardef(result).paras:=tparalist.create(false);
  2948. tprocvardef(result).paras.count:=paras.count;
  2949. for j:=0 to paras.count-1 do
  2950. tprocvardef(result).paras[j]:=paras[j];
  2951. tprocvardef(result).proctypeoption:=proctypeoption;
  2952. tprocvardef(result).proccalloption:=proccalloption;
  2953. tprocvardef(result).procoptions:=procoptions;
  2954. tprocvardef(result).requiredargarea:=requiredargarea;
  2955. tprocvardef(result).maxparacount:=maxparacount;
  2956. tprocvardef(result).minparacount:=minparacount;
  2957. for i:=low(tcallercallee) to high(tcallercallee) do
  2958. location_copy(tprocvardef(result).funcretloc[i],funcretloc[i]);
  2959. tprocvardef(result).has_paraloc_info:=has_paraloc_info;
  2960. {$ifdef i386}
  2961. tprocvardef(result).fpu_used:=fpu_used;
  2962. {$endif i386}
  2963. {$ifdef m68k}
  2964. tprocvardef(result).exp_funcretloc:=exp_funcretloc;
  2965. {$endif}
  2966. end;
  2967. procedure tprocvardef.ppuwrite(ppufile:tcompilerppufile);
  2968. begin
  2969. { here we cannot get a real good value so just give something }
  2970. { plausible (PM) }
  2971. { a more secure way would be
  2972. to allways store in a temp }
  2973. {$ifdef i386}
  2974. if is_fpu(returndef) then
  2975. fpu_used:={2}maxfpuregs
  2976. else
  2977. fpu_used:=0;
  2978. {$endif i386}
  2979. inherited ppuwrite(ppufile);
  2980. { Write this entry }
  2981. ppufile.writeentry(ibprocvardef);
  2982. { Save the para symtable, this is taken from the interface }
  2983. tparasymtable(parast).ppuwrite(ppufile);
  2984. end;
  2985. function tprocvardef.GetSymtable(t:tGetSymtable):TSymtable;
  2986. begin
  2987. case t of
  2988. gs_para :
  2989. GetSymtable:=parast;
  2990. else
  2991. GetSymtable:=nil;
  2992. end;
  2993. end;
  2994. function tprocvardef.size : aint;
  2995. begin
  2996. if (po_methodpointer in procoptions) and
  2997. not(po_addressonly in procoptions) then
  2998. size:=2*sizeof(aint)
  2999. else
  3000. size:=sizeof(aint);
  3001. end;
  3002. function tprocvardef.is_methodpointer:boolean;
  3003. begin
  3004. result:=(po_methodpointer in procoptions);
  3005. end;
  3006. function tprocvardef.is_addressonly:boolean;
  3007. begin
  3008. result:=not(po_methodpointer in procoptions) or
  3009. (po_addressonly in procoptions);
  3010. end;
  3011. function tprocvardef.getmangledparaname:string;
  3012. begin
  3013. result:='procvar';
  3014. end;
  3015. function tprocvardef.is_publishable : boolean;
  3016. begin
  3017. is_publishable:=(po_methodpointer in procoptions);
  3018. end;
  3019. function tprocvardef.GetTypeName : string;
  3020. var
  3021. s: string;
  3022. showhidden : boolean;
  3023. begin
  3024. {$ifdef EXTDEBUG}
  3025. showhidden:=true;
  3026. {$else EXTDEBUG}
  3027. showhidden:=false;
  3028. {$endif EXTDEBUG}
  3029. s:='<';
  3030. if po_classmethod in procoptions then
  3031. s := s+'class method type of'
  3032. else
  3033. if po_addressonly in procoptions then
  3034. s := s+'address of'
  3035. else
  3036. s := s+'procedure variable type of';
  3037. if po_local in procoptions then
  3038. s := s+' local';
  3039. if assigned(returndef) and
  3040. (returndef<>voidtype) then
  3041. s:=s+' function'+typename_paras(showhidden)+':'+returndef.GetTypeName
  3042. else
  3043. s:=s+' procedure'+typename_paras(showhidden);
  3044. if po_methodpointer in procoptions then
  3045. s := s+' of object';
  3046. GetTypeName := s+';'+ProcCallOptionStr[proccalloption]+'>';
  3047. end;
  3048. {***************************************************************************
  3049. TOBJECTDEF
  3050. ***************************************************************************}
  3051. constructor tobjectdef.create(ot : tobjecttyp;const n : string;c : tobjectdef);
  3052. begin
  3053. inherited create(objectdef);
  3054. objecttype:=ot;
  3055. objectoptions:=[];
  3056. childof:=nil;
  3057. symtable:=tObjectSymtable.create(self,n,current_settings.packrecords);
  3058. { create space for vmt !! }
  3059. vmtentries:=nil;
  3060. vmt_offset:=0;
  3061. set_parent(c);
  3062. objname:=stringdup(upper(n));
  3063. objrealname:=stringdup(n);
  3064. if objecttype in [odt_interfacecorba,odt_interfacecom,odt_dispinterface] then
  3065. prepareguid;
  3066. { setup implemented interfaces }
  3067. if objecttype in [odt_class,odt_interfacecorba] then
  3068. ImplementedInterfaces:=TFPObjectList.Create(true)
  3069. else
  3070. ImplementedInterfaces:=nil;
  3071. writing_class_record_dbginfo:=false;
  3072. end;
  3073. constructor tobjectdef.ppuload(ppufile:tcompilerppufile);
  3074. var
  3075. i,
  3076. implintfcount : longint;
  3077. d : tderef;
  3078. ImplIntf : TImplementedInterface;
  3079. begin
  3080. inherited ppuload(objectdef,ppufile);
  3081. objecttype:=tobjecttyp(ppufile.getbyte);
  3082. objrealname:=stringdup(ppufile.getstring);
  3083. objname:=stringdup(upper(objrealname^));
  3084. symtable:=tObjectSymtable.create(self,objrealname^,0);
  3085. tObjectSymtable(symtable).datasize:=ppufile.getaint;
  3086. tObjectSymtable(symtable).fieldalignment:=ppufile.getbyte;
  3087. tObjectSymtable(symtable).recordalignment:=ppufile.getbyte;
  3088. vmt_offset:=ppufile.getlongint;
  3089. vmtentries:=nil;
  3090. ppufile.getderef(childofderef);
  3091. ppufile.getsmallset(objectoptions);
  3092. { load guid }
  3093. iidstr:=nil;
  3094. if objecttype in [odt_interfacecom,odt_interfacecorba,odt_dispinterface] then
  3095. begin
  3096. new(iidguid);
  3097. ppufile.getguid(iidguid^);
  3098. iidstr:=stringdup(ppufile.getstring);
  3099. end;
  3100. { load implemented interfaces }
  3101. if objecttype in [odt_class,odt_interfacecorba] then
  3102. begin
  3103. ImplementedInterfaces:=TFPObjectList.Create(true);
  3104. implintfcount:=ppufile.getlongint;
  3105. for i:=0 to implintfcount-1 do
  3106. begin
  3107. ppufile.getderef(d);
  3108. ImplIntf:=TImplementedInterface.Create_deref(d);
  3109. ImplIntf.IOffset:=ppufile.getlongint;
  3110. ImplementedInterfaces.Add(ImplIntf);
  3111. end;
  3112. end
  3113. else
  3114. ImplementedInterfaces:=nil;
  3115. tObjectSymtable(symtable).ppuload(ppufile);
  3116. { handles the predefined class tobject }
  3117. { the last TOBJECT which is loaded gets }
  3118. { it ! }
  3119. if (childof=nil) and
  3120. (objecttype=odt_class) and
  3121. (objname^='TOBJECT') then
  3122. class_tobject:=self;
  3123. if (childof=nil) and
  3124. (objecttype=odt_interfacecom) and
  3125. (objname^='IUNKNOWN') then
  3126. interface_iunknown:=self;
  3127. writing_class_record_dbginfo:=false;
  3128. end;
  3129. destructor tobjectdef.destroy;
  3130. begin
  3131. if assigned(symtable) then
  3132. begin
  3133. symtable.free;
  3134. symtable:=nil;
  3135. end;
  3136. stringdispose(objname);
  3137. stringdispose(objrealname);
  3138. stringdispose(iidstr);
  3139. if assigned(ImplementedInterfaces) then
  3140. begin
  3141. ImplementedInterfaces.free;
  3142. ImplementedInterfaces:=nil;
  3143. end;
  3144. if assigned(iidguid) then
  3145. begin
  3146. dispose(iidguid);
  3147. iidguid:=nil;
  3148. end;
  3149. if assigned(vmtentries) then
  3150. begin
  3151. vmtentries.free;
  3152. vmtentries:=nil;
  3153. end;
  3154. inherited destroy;
  3155. end;
  3156. function tobjectdef.getcopy : tstoreddef;
  3157. var
  3158. i : longint;
  3159. begin
  3160. result:=tobjectdef.create(objecttype,objname^,childof);
  3161. tobjectdef(result).symtable:=symtable.getcopy;
  3162. if assigned(objname) then
  3163. tobjectdef(result).objname:=stringdup(objname^);
  3164. if assigned(objrealname) then
  3165. tobjectdef(result).objrealname:=stringdup(objrealname^);
  3166. tobjectdef(result).objectoptions:=objectoptions;
  3167. tobjectdef(result).vmt_offset:=vmt_offset;
  3168. if assigned(iidguid) then
  3169. begin
  3170. new(tobjectdef(result).iidguid);
  3171. move(iidguid^,tobjectdef(result).iidguid^,sizeof(iidguid^));
  3172. end;
  3173. if assigned(iidstr) then
  3174. tobjectdef(result).iidstr:=stringdup(iidstr^);
  3175. if assigned(ImplementedInterfaces) then
  3176. begin
  3177. for i:=0 to ImplementedInterfaces.count-1 do
  3178. tobjectdef(result).ImplementedInterfaces.Add(TImplementedInterface(ImplementedInterfaces[i]).Getcopy);
  3179. end;
  3180. if assigned(vmtentries) then
  3181. begin
  3182. tobjectdef(result).vmtentries:=TFPobjectList.Create(false);
  3183. tobjectdef(result).vmtentries.Assign(vmtentries);
  3184. end;
  3185. end;
  3186. procedure tobjectdef.ppuwrite(ppufile:tcompilerppufile);
  3187. var
  3188. i : longint;
  3189. ImplIntf : TImplementedInterface;
  3190. begin
  3191. inherited ppuwrite(ppufile);
  3192. ppufile.putbyte(byte(objecttype));
  3193. ppufile.putstring(objrealname^);
  3194. ppufile.putaint(tObjectSymtable(symtable).datasize);
  3195. ppufile.putbyte(tObjectSymtable(symtable).fieldalignment);
  3196. ppufile.putbyte(tObjectSymtable(symtable).recordalignment);
  3197. ppufile.putlongint(vmt_offset);
  3198. ppufile.putderef(childofderef);
  3199. ppufile.putsmallset(objectoptions);
  3200. if objecttype in [odt_interfacecom,odt_interfacecorba,odt_dispinterface] then
  3201. begin
  3202. ppufile.putguid(iidguid^);
  3203. ppufile.putstring(iidstr^);
  3204. end;
  3205. if objecttype in [odt_class,odt_interfacecorba] then
  3206. begin
  3207. ppufile.putlongint(ImplementedInterfaces.Count);
  3208. for i:=0 to ImplementedInterfaces.Count-1 do
  3209. begin
  3210. ImplIntf:=TImplementedInterface(ImplementedInterfaces[i]);
  3211. ppufile.putderef(ImplIntf.intfdefderef);
  3212. ppufile.putlongint(ImplIntf.Ioffset);
  3213. end;
  3214. end;
  3215. ppufile.writeentry(ibobjectdef);
  3216. tObjectSymtable(symtable).ppuwrite(ppufile);
  3217. end;
  3218. function tobjectdef.GetTypeName:string;
  3219. begin
  3220. if (self <> aktobjectdef) then
  3221. GetTypeName:=typename
  3222. else
  3223. { in this case we will go in endless recursion, because then }
  3224. { there is no tsym associated yet with the def. It can occur }
  3225. { (tests/webtbf/tw4757.pp), so for now give a generic name }
  3226. { instead of the actual type name }
  3227. GetTypeName:='<Currently Parsed Class>';
  3228. end;
  3229. procedure tobjectdef.buildderef;
  3230. var
  3231. i : longint;
  3232. begin
  3233. inherited buildderef;
  3234. childofderef.build(childof);
  3235. tstoredsymtable(symtable).buildderef;
  3236. if objecttype in [odt_class,odt_interfacecorba] then
  3237. begin
  3238. for i:=0 to ImplementedInterfaces.count-1 do
  3239. TImplementedInterface(ImplementedInterfaces[i]).buildderef;
  3240. end;
  3241. end;
  3242. procedure tobjectdef.deref;
  3243. var
  3244. i : longint;
  3245. begin
  3246. inherited deref;
  3247. childof:=tobjectdef(childofderef.resolve);
  3248. tstoredsymtable(symtable).deref;
  3249. if objecttype in [odt_class,odt_interfacecorba] then
  3250. begin
  3251. for i:=0 to ImplementedInterfaces.count-1 do
  3252. TImplementedInterface(ImplementedInterfaces[i]).deref;
  3253. end;
  3254. end;
  3255. function tobjectdef.getparentdef:tdef;
  3256. begin
  3257. {$warning TODO Remove getparentdef hack}
  3258. { With 2 forward declared classes with the child class before the
  3259. parent class the child class is written earlier to the ppu. Leaving it
  3260. possible to have a reference to the parent class for property overriding,
  3261. but the parent class still has the childof not resolved yet (PFV) }
  3262. if childof=nil then
  3263. childof:=tobjectdef(childofderef.resolve);
  3264. result:=childof;
  3265. end;
  3266. procedure tobjectdef.prepareguid;
  3267. begin
  3268. { set up guid }
  3269. if not assigned(iidguid) then
  3270. begin
  3271. new(iidguid);
  3272. fillchar(iidguid^,sizeof(iidguid^),0); { default null guid }
  3273. end;
  3274. { setup iidstring }
  3275. if not assigned(iidstr) then
  3276. iidstr:=stringdup(''); { default is empty string }
  3277. end;
  3278. procedure tobjectdef.set_parent( c : tobjectdef);
  3279. begin
  3280. { nothing to do if the parent was not forward !}
  3281. if assigned(childof) then
  3282. exit;
  3283. childof:=c;
  3284. { some options are inherited !! }
  3285. if assigned(c) then
  3286. begin
  3287. { only important for classes }
  3288. objectoptions:=objectoptions+(c.objectoptions*inherited_objectoptions);
  3289. if not (objecttype in [odt_interfacecom,odt_interfacecorba,odt_dispinterface]) then
  3290. begin
  3291. { add the data of the anchestor class }
  3292. inc(tObjectSymtable(symtable).datasize,tObjectSymtable(c.symtable).datasize);
  3293. if (oo_has_vmt in objectoptions) and
  3294. (oo_has_vmt in c.objectoptions) then
  3295. dec(tObjectSymtable(symtable).datasize,sizeof(aint));
  3296. { if parent has a vmt field then
  3297. the offset is the same for the child PM }
  3298. if (oo_has_vmt in c.objectoptions) or is_class(self) then
  3299. begin
  3300. vmt_offset:=c.vmt_offset;
  3301. include(objectoptions,oo_has_vmt);
  3302. end;
  3303. end;
  3304. end;
  3305. end;
  3306. procedure tobjectdef.insertvmt;
  3307. begin
  3308. if objecttype in [odt_interfacecom,odt_interfacecorba,odt_dispinterface] then
  3309. exit;
  3310. if (oo_has_vmt in objectoptions) then
  3311. internalerror(12345)
  3312. else
  3313. begin
  3314. tObjectSymtable(symtable).datasize:=align(tObjectSymtable(symtable).datasize,
  3315. tObjectSymtable(symtable).fieldalignment);
  3316. {$ifdef cpurequiresproperalignment}
  3317. tObjectSymtable(symtable).datasize:=align(tObjectSymtable(symtable).datasize,sizeof(aint));
  3318. {$endif cpurequiresproperalignment}
  3319. vmt_offset:=tObjectSymtable(symtable).datasize;
  3320. inc(tObjectSymtable(symtable).datasize,sizeof(aint));
  3321. include(objectoptions,oo_has_vmt);
  3322. end;
  3323. end;
  3324. procedure tobjectdef.check_forwards;
  3325. begin
  3326. if not(objecttype in [odt_interfacecom,odt_interfacecorba,odt_dispinterface]) then
  3327. tstoredsymtable(symtable).check_forwards;
  3328. if (oo_is_forward in objectoptions) then
  3329. begin
  3330. { ok, in future, the forward can be resolved }
  3331. Message1(sym_e_class_forward_not_resolved,objrealname^);
  3332. exclude(objectoptions,oo_is_forward);
  3333. end;
  3334. end;
  3335. { true, if self inherits from d (or if they are equal) }
  3336. function tobjectdef.is_related(d : tdef) : boolean;
  3337. var
  3338. hp : tobjectdef;
  3339. begin
  3340. hp:=self;
  3341. while assigned(hp) do
  3342. begin
  3343. if hp=d then
  3344. begin
  3345. is_related:=true;
  3346. exit;
  3347. end;
  3348. hp:=hp.childof;
  3349. end;
  3350. is_related:=false;
  3351. end;
  3352. function tobjectdef.FindDestructor : tprocdef;
  3353. var
  3354. objdef : tobjectdef;
  3355. i : longint;
  3356. sym : tsym;
  3357. pd : tprocdef;
  3358. begin
  3359. result:=nil;
  3360. objdef:=self;
  3361. while assigned(objdef) do
  3362. begin
  3363. for i:=0 to objdef.symtable.SymList.Count-1 do
  3364. begin
  3365. sym:=TSym(objdef.symtable.SymList[i]);
  3366. if sym.typ=procsym then
  3367. begin
  3368. pd:=Tprocsym(sym).Find_procdef_bytype(potype_destructor);
  3369. if assigned(pd) then
  3370. begin
  3371. result:=pd;
  3372. exit;
  3373. end;
  3374. end;
  3375. end;
  3376. objdef:=objdef.childof;
  3377. end;
  3378. end;
  3379. function tobjectdef.size : aint;
  3380. begin
  3381. if objecttype in [odt_class,odt_interfacecom,odt_interfacecorba,odt_dispinterface] then
  3382. result:=sizeof(aint)
  3383. else
  3384. result:=tObjectSymtable(symtable).datasize;
  3385. end;
  3386. function tobjectdef.alignment:shortint;
  3387. begin
  3388. if objecttype in [odt_class,odt_interfacecom,odt_interfacecorba,odt_dispinterface] then
  3389. alignment:=sizeof(aint)
  3390. else
  3391. alignment:=tObjectSymtable(symtable).recordalignment;
  3392. end;
  3393. function tobjectdef.vmtmethodoffset(index:longint):longint;
  3394. begin
  3395. { for offset of methods for classes, see rtl/inc/objpash.inc }
  3396. case objecttype of
  3397. odt_class:
  3398. { the +2*sizeof(Aint) is size and -size }
  3399. vmtmethodoffset:=(index+10)*sizeof(aint)+2*sizeof(AInt);
  3400. odt_interfacecom,odt_interfacecorba:
  3401. vmtmethodoffset:=index*sizeof(aint);
  3402. else
  3403. {$ifdef WITHDMT}
  3404. vmtmethodoffset:=(index+4)*sizeof(aint);
  3405. {$else WITHDMT}
  3406. vmtmethodoffset:=(index+3)*sizeof(aint);
  3407. {$endif WITHDMT}
  3408. end;
  3409. end;
  3410. function tobjectdef.vmt_mangledname : string;
  3411. begin
  3412. if not(oo_has_vmt in objectoptions) then
  3413. Message1(parser_n_object_has_no_vmt,objrealname^);
  3414. vmt_mangledname:=make_mangledname('VMT',owner,objname^);
  3415. end;
  3416. function tobjectdef.needs_inittable : boolean;
  3417. begin
  3418. case objecttype of
  3419. odt_dispinterface,
  3420. odt_class :
  3421. needs_inittable:=false;
  3422. odt_interfacecom:
  3423. needs_inittable:=true;
  3424. odt_interfacecorba:
  3425. needs_inittable:=is_related(interface_iunknown);
  3426. odt_object:
  3427. needs_inittable:=tObjectSymtable(symtable).needs_init_final;
  3428. else
  3429. internalerror(200108267);
  3430. end;
  3431. end;
  3432. function tobjectdef.members_need_inittable : boolean;
  3433. begin
  3434. members_need_inittable:=tObjectSymtable(symtable).needs_init_final;
  3435. end;
  3436. function tobjectdef.find_implemented_interface(aintfdef:tobjectdef):TImplementedInterface;
  3437. var
  3438. ImplIntf : TImplementedInterface;
  3439. i : longint;
  3440. begin
  3441. result:=nil;
  3442. if not assigned(ImplementedInterfaces) then
  3443. exit;
  3444. for i:=0 to ImplementedInterfaces.Count-1 do
  3445. begin
  3446. ImplIntf:=TImplementedInterface(ImplementedInterfaces[i]);
  3447. if ImplIntf.intfdef=aintfdef then
  3448. begin
  3449. result:=ImplIntf;
  3450. exit;
  3451. end;
  3452. end;
  3453. end;
  3454. function tobjectdef.is_publishable : boolean;
  3455. begin
  3456. is_publishable:=objecttype in [odt_class,odt_interfacecom,odt_interfacecorba,odt_dispinterface];
  3457. end;
  3458. {****************************************************************************
  3459. TImplementedInterface
  3460. ****************************************************************************}
  3461. constructor TImplementedInterface.create(aintf: tobjectdef);
  3462. begin
  3463. inherited create;
  3464. intfdef:=aintf;
  3465. IOffset:=-1;
  3466. IType:=etStandard;
  3467. FieldOffset:=-1;
  3468. NameMappings:=nil;
  3469. procdefs:=nil;
  3470. end;
  3471. constructor TImplementedInterface.create_deref(d:tderef);
  3472. begin
  3473. inherited create;
  3474. intfdef:=nil;
  3475. intfdefderef:=d;
  3476. IOffset:=-1;
  3477. IType:=etStandard;
  3478. FieldOffset:=-1;
  3479. NameMappings:=nil;
  3480. procdefs:=nil;
  3481. end;
  3482. destructor TImplementedInterface.destroy;
  3483. var
  3484. i : longint;
  3485. mappedname : pshortstring;
  3486. begin
  3487. if assigned(NameMappings) then
  3488. begin
  3489. for i:=0 to NameMappings.Count-1 do
  3490. begin
  3491. mappedname:=pshortstring(NameMappings[i]);
  3492. stringdispose(mappedname);
  3493. end;
  3494. NameMappings.free;
  3495. NameMappings:=nil;
  3496. end;
  3497. if assigned(procdefs) then
  3498. begin
  3499. procdefs.free;
  3500. procdefs:=nil;
  3501. end;
  3502. inherited destroy;
  3503. end;
  3504. procedure TImplementedInterface.buildderef;
  3505. begin
  3506. intfdefderef.build(intfdef);
  3507. end;
  3508. procedure TImplementedInterface.deref;
  3509. begin
  3510. intfdef:=tobjectdef(intfdefderef.resolve);
  3511. end;
  3512. procedure TImplementedInterface.AddMapping(const origname,newname: string);
  3513. begin
  3514. if not assigned(NameMappings) then
  3515. NameMappings:=TFPHashList.Create;
  3516. NameMappings.Add(origname,stringdup(newname));
  3517. end;
  3518. function TImplementedInterface.GetMapping(const origname: string):string;
  3519. var
  3520. mappedname : pshortstring;
  3521. begin
  3522. result:='';
  3523. if not assigned(NameMappings) then
  3524. exit;
  3525. mappedname:=PShortstring(NameMappings.Find(origname));
  3526. if assigned(mappedname) then
  3527. result:=mappedname^;
  3528. end;
  3529. procedure TImplementedInterface.AddImplProc(pd:tprocdef);
  3530. var
  3531. i : longint;
  3532. found : boolean;
  3533. begin
  3534. if not assigned(procdefs) then
  3535. procdefs:=TFPObjectList.Create(false);
  3536. { No duplicate entries of the same procdef }
  3537. found:=false;
  3538. for i:=0 to procdefs.count-1 do
  3539. if tprocdef(procdefs[i])=pd then
  3540. begin
  3541. found:=true;
  3542. break;
  3543. end;
  3544. if not found then
  3545. procdefs.Add(pd);
  3546. end;
  3547. function TImplementedInterface.IsImplMergePossible(MergingIntf:TImplementedInterface;out weight: longint): boolean;
  3548. var
  3549. i : longint;
  3550. begin
  3551. result:=false;
  3552. weight:=0;
  3553. { empty interface is mergeable }
  3554. if ProcDefs.Count=0 then
  3555. begin
  3556. result:=true;
  3557. exit;
  3558. end;
  3559. { The interface to merge must at least the number of
  3560. procedures of this interface }
  3561. if MergingIntf.ProcDefs.Count<ProcDefs.Count then
  3562. exit;
  3563. for i:=0 to ProcDefs.Count-1 do
  3564. begin
  3565. if MergingIntf.ProcDefs[i]<>ProcDefs[i] then
  3566. exit;
  3567. end;
  3568. weight:=ProcDefs.Count;
  3569. result:=true;
  3570. end;
  3571. function TImplementedInterface.getcopy:TImplementedInterface;
  3572. begin
  3573. Result:=TImplementedInterface.Create(nil);
  3574. Move(pointer(self)^,pointer(result)^,InstanceSize);
  3575. end;
  3576. {****************************************************************************
  3577. TFORWARDDEF
  3578. ****************************************************************************}
  3579. constructor tforwarddef.create(const s:string;const pos : tfileposinfo);
  3580. begin
  3581. inherited create(forwarddef);
  3582. tosymname:=stringdup(s);
  3583. forwardpos:=pos;
  3584. end;
  3585. function tforwarddef.GetTypeName:string;
  3586. begin
  3587. GetTypeName:='unresolved forward to '+tosymname^;
  3588. end;
  3589. destructor tforwarddef.destroy;
  3590. begin
  3591. stringdispose(tosymname);
  3592. inherited destroy;
  3593. end;
  3594. {****************************************************************************
  3595. TUNDEFINEDDEF
  3596. ****************************************************************************}
  3597. constructor tundefineddef.create;
  3598. begin
  3599. inherited create(undefineddef);
  3600. end;
  3601. constructor tundefineddef.ppuload(ppufile:tcompilerppufile);
  3602. begin
  3603. inherited ppuload(undefineddef,ppufile);
  3604. end;
  3605. function tundefineddef.GetTypeName:string;
  3606. begin
  3607. GetTypeName:='<undefined type>';
  3608. end;
  3609. procedure tundefineddef.ppuwrite(ppufile:tcompilerppufile);
  3610. begin
  3611. inherited ppuwrite(ppufile);
  3612. ppufile.writeentry(ibundefineddef);
  3613. end;
  3614. {****************************************************************************
  3615. TERRORDEF
  3616. ****************************************************************************}
  3617. constructor terrordef.create;
  3618. begin
  3619. inherited create(errordef);
  3620. end;
  3621. procedure terrordef.ppuwrite(ppufile:tcompilerppufile);
  3622. begin
  3623. { Can't write errordefs to ppu }
  3624. internalerror(200411063);
  3625. end;
  3626. function terrordef.GetTypeName:string;
  3627. begin
  3628. GetTypeName:='<erroneous type>';
  3629. end;
  3630. function terrordef.getmangledparaname:string;
  3631. begin
  3632. getmangledparaname:='error';
  3633. end;
  3634. {****************************************************************************
  3635. Definition Helpers
  3636. ****************************************************************************}
  3637. function is_interfacecom(def: tdef): boolean;
  3638. begin
  3639. is_interfacecom:=
  3640. assigned(def) and
  3641. (def.typ=objectdef) and
  3642. (tobjectdef(def).objecttype=odt_interfacecom);
  3643. end;
  3644. function is_interfacecorba(def: tdef): boolean;
  3645. begin
  3646. is_interfacecorba:=
  3647. assigned(def) and
  3648. (def.typ=objectdef) and
  3649. (tobjectdef(def).objecttype=odt_interfacecorba);
  3650. end;
  3651. function is_interface(def: tdef): boolean;
  3652. begin
  3653. is_interface:=
  3654. assigned(def) and
  3655. (def.typ=objectdef) and
  3656. (tobjectdef(def).objecttype in [odt_interfacecom,odt_interfacecorba]);
  3657. end;
  3658. function is_dispinterface(def: tdef): boolean;
  3659. begin
  3660. result:=
  3661. assigned(def) and
  3662. (def.typ=objectdef) and
  3663. (tobjectdef(def).objecttype=odt_dispinterface);
  3664. end;
  3665. function is_class(def: tdef): boolean;
  3666. begin
  3667. is_class:=
  3668. assigned(def) and
  3669. (def.typ=objectdef) and
  3670. (tobjectdef(def).objecttype=odt_class);
  3671. end;
  3672. function is_object(def: tdef): boolean;
  3673. begin
  3674. is_object:=
  3675. assigned(def) and
  3676. (def.typ=objectdef) and
  3677. (tobjectdef(def).objecttype=odt_object);
  3678. end;
  3679. function is_cppclass(def: tdef): boolean;
  3680. begin
  3681. is_cppclass:=
  3682. assigned(def) and
  3683. (def.typ=objectdef) and
  3684. (tobjectdef(def).objecttype=odt_cppclass);
  3685. end;
  3686. function is_class_or_interface(def: tdef): boolean;
  3687. begin
  3688. is_class_or_interface:=
  3689. assigned(def) and
  3690. (def.typ=objectdef) and
  3691. (tobjectdef(def).objecttype in [odt_class,odt_interfacecom,odt_interfacecorba]);
  3692. end;
  3693. function is_class_or_interface_or_dispinterface(def: tdef): boolean;
  3694. begin
  3695. result:=
  3696. assigned(def) and
  3697. (def.typ=objectdef) and
  3698. (tobjectdef(def).objecttype in [odt_class,odt_interfacecom,odt_interfacecorba,odt_dispinterface]);
  3699. end;
  3700. {$ifdef x86}
  3701. function use_sse(def : tdef) : boolean;
  3702. begin
  3703. use_sse:=(is_single(def) and (current_settings.fputype in sse_singlescalar)) or
  3704. (is_double(def) and (current_settings.fputype in sse_doublescalar));
  3705. end;
  3706. {$endif x86}
  3707. end.