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