symdef.pas 127 KB

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