symdef.pas 176 KB

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