symdef.pas 168 KB

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