symdef.pas 188 KB

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