symdef.pas 169 KB

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