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