symdef.pas 142 KB

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