symdef.pas 191 KB

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