symdef.pas 167 KB

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