symdef.pas 127 KB

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