symdef.pas 170 KB

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