symdef.pas 171 KB

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