symdef.pas 194 KB

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