From ce6b908edbf2f14dd8299ead51de1cc67c014e26 Mon Sep 17 00:00:00 2001 From: Rene Gollent Date: Sun, 2 Dec 2012 22:09:24 -0500 Subject: [PATCH] Extend CompoundType to handle template parameters. - Adjust CompoundType to add accessors for template type and value parameters. - Add DwarfCompoundType/DwarfTypeFactory handling for template template type parameters. --- .../debugger/debug_info/DwarfTypeFactory.cpp | 41 ++++++++++++++++- src/apps/debugger/debug_info/DwarfTypes.cpp | 44 +++++++++++++++++++ src/apps/debugger/debug_info/DwarfTypes.h | 9 ++++ src/apps/debugger/model/Type.h | 7 +++ 4 files changed, 100 insertions(+), 1 deletion(-) diff --git a/src/apps/debugger/debug_info/DwarfTypeFactory.cpp b/src/apps/debugger/debug_info/DwarfTypeFactory.cpp index 7bd2292985..594d7ed142 100644 --- a/src/apps/debugger/debug_info/DwarfTypeFactory.cpp +++ b/src/apps/debugger/debug_info/DwarfTypeFactory.cpp @@ -102,6 +102,17 @@ struct HasBaseTypesPredicate { }; +// #pragma mark - HasTemplateTypeParametersPredicate + + +struct HasTemplateTypeParametersPredicate { + inline bool operator()(DIEClassBaseType* entry) const + { + return !entry->TemplateTypeParameters().IsEmpty(); + } +}; + + // #pragma mark - HasParametersPredicate @@ -516,7 +527,7 @@ printf(" -> failed to add type to cache\n"); } // If the type is a class/struct/interface type, we also need to add its - // base types. + // base types, and possibly template parameters. if (DIEClassBaseType* classTypeEntry = dynamic_cast(typeEntry)) { // find the abstract origin or specification that defines the base types @@ -549,6 +560,34 @@ printf(" -> failed to add type to cache\n"); } } } + + // find the abstract origin or specification that defines the template + // parameters + classTypeEntry = DwarfUtils::GetDIEByPredicate( + dynamic_cast(typeEntry), + HasTemplateTypeParametersPredicate()); + + if (classTypeEntry != NULL) { + for (DebugInfoEntryList::ConstIterator it + = classTypeEntry->TemplateTypeParameters() + .GetIterator(); + DebugInfoEntry* _typeEntry = it.Next();) { + DIETemplateTypeParameter* templateTypeEntry = + dynamic_cast(_typeEntry); + DwarfType* templateType; + if (CreateType(templateTypeEntry->GetType(), templateType) + != B_OK) { + continue; + } + BReference templateTypeReference(templateType, + true); + if (!type->AddTemplateTypeParameter(templateType)) { + cacheLocker.Lock(); + fTypeCache->RemoveType(type); + return B_NO_MEMORY; + } + } + } } _type = typeReference.Detach(); diff --git a/src/apps/debugger/debug_info/DwarfTypes.cpp b/src/apps/debugger/debug_info/DwarfTypes.cpp index 608ec1dbcf..96b1a57002 100644 --- a/src/apps/debugger/debug_info/DwarfTypes.cpp +++ b/src/apps/debugger/debug_info/DwarfTypes.cpp @@ -567,6 +567,9 @@ DwarfCompoundType::~DwarfCompoundType() } for (int32 i = 0; DwarfDataMember* member = fDataMembers.ItemAt(i); i++) member->ReleaseReference(); + + for (int32 i = 0; DwarfType* type = fTemplateTypeParameters.ItemAt(i); i++) + type->ReleaseReference(); } @@ -605,6 +608,36 @@ DwarfCompoundType::DataMemberAt(int32 index) const } +int32 +DwarfCompoundType::CountTemplateTypeParameters() const +{ + return fTemplateTypeParameters.CountItems(); +} + + +Type* +DwarfCompoundType::TemplateTypeParameterAt(int32 index) const +{ + return fTemplateTypeParameters.ItemAt(index); +} + + +int32 +DwarfCompoundType::CountTemplateValueParameters() const +{ + // TODO: implement + return 0; +} + + +Type* +DwarfCompoundType::TemplateValueParameterAt(int32 index) const +{ + // TODO: implement + return NULL; +} + + status_t DwarfCompoundType::ResolveBaseTypeLocation(BaseType* _baseType, const ValueLocation& parentLocation, ValueLocation*& _location) @@ -736,6 +769,17 @@ DwarfCompoundType::AddDataMember(DwarfDataMember* member) } +bool +DwarfCompoundType::AddTemplateTypeParameter(DwarfType* type) +{ + if (!fTemplateTypeParameters.AddItem(type)) + return false; + + type->AcquireReference(); + return true; +} + + status_t DwarfCompoundType::_ResolveDataMemberLocation(DwarfType* memberType, const MemberLocation* memberLocation, diff --git a/src/apps/debugger/debug_info/DwarfTypes.h b/src/apps/debugger/debug_info/DwarfTypes.h index 976f4e1baa..b718e38957 100644 --- a/src/apps/debugger/debug_info/DwarfTypes.h +++ b/src/apps/debugger/debug_info/DwarfTypes.h @@ -271,6 +271,12 @@ public: virtual int32 CountDataMembers() const; virtual DataMember* DataMemberAt(int32 index) const; + virtual int32 CountTemplateTypeParameters() const; + virtual Type* TemplateTypeParameterAt(int32 index) const; + + virtual int32 CountTemplateValueParameters() const; + virtual Type* TemplateValueParameterAt(int32 index) const; + virtual status_t ResolveBaseTypeLocation(BaseType* _baseType, const ValueLocation& parentLocation, ValueLocation*& _location); @@ -285,10 +291,12 @@ public: bool AddInheritance(DwarfInheritance* inheritance); bool AddDataMember(DwarfDataMember* member); + bool AddTemplateTypeParameter(DwarfType* type); private: typedef BObjectList DataMemberList; typedef BObjectList InheritanceList; + typedef BObjectList TemplateTypeList; private: status_t _ResolveDataMemberLocation( @@ -302,6 +310,7 @@ private: DIECompoundType* fEntry; InheritanceList fInheritances; DataMemberList fDataMembers; + TemplateTypeList fTemplateTypeParameters; }; diff --git a/src/apps/debugger/model/Type.h b/src/apps/debugger/model/Type.h index 44b0b2a5c1..c7abc78232 100644 --- a/src/apps/debugger/model/Type.h +++ b/src/apps/debugger/model/Type.h @@ -158,6 +158,13 @@ public: virtual int32 CountDataMembers() const = 0; virtual DataMember* DataMemberAt(int32 index) const = 0; + virtual int32 CountTemplateTypeParameters() const = 0; + virtual Type* TemplateTypeParameterAt(int32 index) const = 0; + + virtual int32 CountTemplateValueParameters() const = 0; + virtual Type* TemplateValueParameterAt(int32 index) const + = 0; + virtual status_t ResolveBaseTypeLocation(BaseType* baseType, const ValueLocation& parentLocation, ValueLocation*& _location) = 0;