symdef.pas 166 KB

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