symdef.pas 167 KB

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