symdef.pas 146 KB

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