symdef.pas 169 KB

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