symdef.pas 192 KB

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