symdef.pas 126 KB

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