Rework handling of template parameters.
- Keep a unified list in DIEClassBaseType so that the order of template parameters is preserved in cases when type and value parameters are mixed. Thanks Ingo for the hint. - Introduce new base Type TemplateParameter, which represents either a template type or template value parameter, a list of which is attached to CompoundType. - Add DwarfTemplateParameter implementing subclass of TemplateParameter and adjust DwarfTypeFactory accordingly for the above changes.
This commit is contained in:
@@ -102,13 +102,13 @@ struct HasBaseTypesPredicate {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// #pragma mark - HasTemplateTypeParametersPredicate
|
// #pragma mark - HasTemplateParametersPredicate
|
||||||
|
|
||||||
|
|
||||||
struct HasTemplateTypeParametersPredicate {
|
struct HasTemplateParametersPredicate {
|
||||||
inline bool operator()(DIEClassBaseType* entry) const
|
inline bool operator()(DIEClassBaseType* entry) const
|
||||||
{
|
{
|
||||||
return !entry->TemplateTypeParameters().IsEmpty();
|
return !entry->TemplateParameters().IsEmpty();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -565,23 +565,41 @@ printf(" -> failed to add type to cache\n");
|
|||||||
// parameters
|
// parameters
|
||||||
classTypeEntry = DwarfUtils::GetDIEByPredicate(
|
classTypeEntry = DwarfUtils::GetDIEByPredicate(
|
||||||
dynamic_cast<DIEClassBaseType*>(typeEntry),
|
dynamic_cast<DIEClassBaseType*>(typeEntry),
|
||||||
HasTemplateTypeParametersPredicate());
|
HasTemplateParametersPredicate());
|
||||||
|
|
||||||
if (classTypeEntry != NULL) {
|
if (classTypeEntry != NULL) {
|
||||||
for (DebugInfoEntryList::ConstIterator it
|
for (DebugInfoEntryList::ConstIterator it
|
||||||
= classTypeEntry->TemplateTypeParameters()
|
= classTypeEntry->TemplateParameters()
|
||||||
.GetIterator();
|
.GetIterator();
|
||||||
DebugInfoEntry* _typeEntry = it.Next();) {
|
DebugInfoEntry* _typeEntry = it.Next();) {
|
||||||
DIETemplateTypeParameter* templateTypeEntry =
|
DIETemplateTypeParameter* templateTypeEntry
|
||||||
dynamic_cast<DIETemplateTypeParameter*>(_typeEntry);
|
= dynamic_cast<DIETemplateTypeParameter*>(_typeEntry);
|
||||||
DwarfType* templateType;
|
DwarfType* templateType;
|
||||||
if (CreateType(templateTypeEntry->GetType(), templateType)
|
if (templateTypeEntry != NULL) {
|
||||||
!= B_OK) {
|
if (CreateType(templateTypeEntry->GetType(), templateType)
|
||||||
continue;
|
!= B_OK) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
DIETemplateValueParameter* templateValueEntry
|
||||||
|
= dynamic_cast<DIETemplateValueParameter*>(_typeEntry);
|
||||||
|
if (CreateType(templateValueEntry->GetType(), templateType)
|
||||||
|
!= B_OK) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
BReference<DwarfType> templateTypeReference(templateType,
|
BReference<DwarfType> templateTypeReference(templateType,
|
||||||
true);
|
true);
|
||||||
if (!type->AddTemplateTypeParameter(templateType)) {
|
DwarfTemplateParameter* parameter
|
||||||
|
= new(std::nothrow) DwarfTemplateParameter(_typeEntry,
|
||||||
|
templateType);
|
||||||
|
if (parameter == NULL) {
|
||||||
|
cacheLocker.Lock();
|
||||||
|
fTypeCache->RemoveType(type);
|
||||||
|
return B_NO_MEMORY;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!type->AddTemplateParameter(parameter)) {
|
||||||
cacheLocker.Lock();
|
cacheLocker.Lock();
|
||||||
fTypeCache->RemoveType(type);
|
fTypeCache->RemoveType(type);
|
||||||
return B_NO_MEMORY;
|
return B_NO_MEMORY;
|
||||||
|
|||||||
@@ -518,6 +518,45 @@ DwarfFunctionParameter::GetType() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// #pragma mark - DwarfTemplateParameter
|
||||||
|
|
||||||
|
|
||||||
|
DwarfTemplateParameter::DwarfTemplateParameter(DebugInfoEntry* entry,
|
||||||
|
DwarfType* type)
|
||||||
|
:
|
||||||
|
fEntry(entry),
|
||||||
|
fType(type)
|
||||||
|
{
|
||||||
|
fType->AcquireReference();
|
||||||
|
DIETemplateTypeParameter* typeParameter
|
||||||
|
= dynamic_cast<DIETemplateTypeParameter *>(entry);
|
||||||
|
if (typeParameter != NULL)
|
||||||
|
fTemplateKind = TEMPLATE_TYPE_TYPE;
|
||||||
|
else {
|
||||||
|
DIETemplateValueParameter* valueParameter
|
||||||
|
= dynamic_cast<DIETemplateValueParameter *>(entry);
|
||||||
|
fTemplateKind = TEMPLATE_TYPE_VALUE;
|
||||||
|
const ConstantAttributeValue* constValue = valueParameter
|
||||||
|
->ConstValue();
|
||||||
|
switch (constValue->attributeClass) {
|
||||||
|
case ATTRIBUTE_CLASS_CONSTANT:
|
||||||
|
fValue.SetTo(constValue->constant);
|
||||||
|
break;
|
||||||
|
case ATTRIBUTE_CLASS_STRING:
|
||||||
|
fValue.SetTo(constValue->string);
|
||||||
|
break;
|
||||||
|
// TODO: ATTRIBUTE_CLASS_BLOCK_DATA
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
DwarfTemplateParameter::~DwarfTemplateParameter()
|
||||||
|
{
|
||||||
|
fType->ReleaseReference();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// #pragma mark - DwarfPrimitiveType
|
// #pragma mark - DwarfPrimitiveType
|
||||||
|
|
||||||
|
|
||||||
@@ -568,8 +607,10 @@ DwarfCompoundType::~DwarfCompoundType()
|
|||||||
for (int32 i = 0; DwarfDataMember* member = fDataMembers.ItemAt(i); i++)
|
for (int32 i = 0; DwarfDataMember* member = fDataMembers.ItemAt(i); i++)
|
||||||
member->ReleaseReference();
|
member->ReleaseReference();
|
||||||
|
|
||||||
for (int32 i = 0; DwarfType* type = fTemplateTypeParameters.ItemAt(i); i++)
|
for (int32 i = 0; DwarfTemplateParameter* parameter
|
||||||
type->ReleaseReference();
|
= fTemplateParameters.ItemAt(i); i++) {
|
||||||
|
parameter->ReleaseReference();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -609,32 +650,16 @@ DwarfCompoundType::DataMemberAt(int32 index) const
|
|||||||
|
|
||||||
|
|
||||||
int32
|
int32
|
||||||
DwarfCompoundType::CountTemplateTypeParameters() const
|
DwarfCompoundType::CountTemplateParameters() const
|
||||||
{
|
{
|
||||||
return fTemplateTypeParameters.CountItems();
|
return fTemplateParameters.CountItems();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Type*
|
TemplateParameter*
|
||||||
DwarfCompoundType::TemplateTypeParameterAt(int32 index) const
|
DwarfCompoundType::TemplateParameterAt(int32 index) const
|
||||||
{
|
{
|
||||||
return fTemplateTypeParameters.ItemAt(index);
|
return fTemplateParameters.ItemAt(index);
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int32
|
|
||||||
DwarfCompoundType::CountTemplateValueParameters() const
|
|
||||||
{
|
|
||||||
// TODO: implement
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
Type*
|
|
||||||
DwarfCompoundType::TemplateValueParameterAt(int32 index) const
|
|
||||||
{
|
|
||||||
// TODO: implement
|
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -770,12 +795,12 @@ DwarfCompoundType::AddDataMember(DwarfDataMember* member)
|
|||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
DwarfCompoundType::AddTemplateTypeParameter(DwarfType* type)
|
DwarfCompoundType::AddTemplateParameter(DwarfTemplateParameter* parameter)
|
||||||
{
|
{
|
||||||
if (!fTemplateTypeParameters.AddItem(type))
|
if (!fTemplateParameters.AddItem(parameter))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
type->AcquireReference();
|
parameter->AcquireReference();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
|
|
||||||
class Architecture;
|
class Architecture;
|
||||||
class CompilationUnit;
|
class CompilationUnit;
|
||||||
|
class DebugInfoEntry;
|
||||||
class DIEAddressingType;
|
class DIEAddressingType;
|
||||||
class DIEArrayType;
|
class DIEArrayType;
|
||||||
class DIEBaseType;
|
class DIEBaseType;
|
||||||
@@ -237,6 +238,25 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
class DwarfTemplateParameter : public TemplateParameter {
|
||||||
|
public:
|
||||||
|
DwarfTemplateParameter(
|
||||||
|
DebugInfoEntry* entry,
|
||||||
|
DwarfType* type);
|
||||||
|
~DwarfTemplateParameter();
|
||||||
|
|
||||||
|
virtual template_type_kind Kind() const { return fTemplateKind; }
|
||||||
|
virtual Type* GetType() const { return fType; }
|
||||||
|
virtual BVariant Value() const { return fValue; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
DebugInfoEntry* fEntry;
|
||||||
|
template_type_kind fTemplateKind;
|
||||||
|
Type* fType;
|
||||||
|
BVariant fValue;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
class DwarfPrimitiveType : public PrimitiveType, public DwarfType {
|
class DwarfPrimitiveType : public PrimitiveType, public DwarfType {
|
||||||
public:
|
public:
|
||||||
DwarfPrimitiveType(
|
DwarfPrimitiveType(
|
||||||
@@ -271,11 +291,8 @@ public:
|
|||||||
virtual int32 CountDataMembers() const;
|
virtual int32 CountDataMembers() const;
|
||||||
virtual DataMember* DataMemberAt(int32 index) const;
|
virtual DataMember* DataMemberAt(int32 index) const;
|
||||||
|
|
||||||
virtual int32 CountTemplateTypeParameters() const;
|
virtual int32 CountTemplateParameters() const;
|
||||||
virtual Type* TemplateTypeParameterAt(int32 index) const;
|
virtual TemplateParameter* TemplateParameterAt(int32 index) const;
|
||||||
|
|
||||||
virtual int32 CountTemplateValueParameters() const;
|
|
||||||
virtual Type* TemplateValueParameterAt(int32 index) const;
|
|
||||||
|
|
||||||
virtual status_t ResolveBaseTypeLocation(BaseType* _baseType,
|
virtual status_t ResolveBaseTypeLocation(BaseType* _baseType,
|
||||||
const ValueLocation& parentLocation,
|
const ValueLocation& parentLocation,
|
||||||
@@ -291,12 +308,13 @@ public:
|
|||||||
|
|
||||||
bool AddInheritance(DwarfInheritance* inheritance);
|
bool AddInheritance(DwarfInheritance* inheritance);
|
||||||
bool AddDataMember(DwarfDataMember* member);
|
bool AddDataMember(DwarfDataMember* member);
|
||||||
bool AddTemplateTypeParameter(DwarfType* type);
|
bool AddTemplateParameter(
|
||||||
|
DwarfTemplateParameter* parameter);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
typedef BObjectList<DwarfDataMember> DataMemberList;
|
typedef BObjectList<DwarfDataMember> DataMemberList;
|
||||||
typedef BObjectList<DwarfInheritance> InheritanceList;
|
typedef BObjectList<DwarfInheritance> InheritanceList;
|
||||||
typedef BObjectList<DwarfType> TemplateTypeList;
|
typedef BObjectList<DwarfTemplateParameter> TemplateParameterList;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
status_t _ResolveDataMemberLocation(
|
status_t _ResolveDataMemberLocation(
|
||||||
@@ -310,7 +328,7 @@ private:
|
|||||||
DIECompoundType* fEntry;
|
DIECompoundType* fEntry;
|
||||||
InheritanceList fInheritances;
|
InheritanceList fInheritances;
|
||||||
DataMemberList fDataMembers;
|
DataMemberList fDataMembers;
|
||||||
TemplateTypeList fTemplateTypeParameters;
|
TemplateParameterList fTemplateParameters;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -478,10 +478,8 @@ DIEClassBaseType::AddChild(DebugInfoEntry* child)
|
|||||||
fMemberFunctions.Add(child);
|
fMemberFunctions.Add(child);
|
||||||
return B_OK;
|
return B_OK;
|
||||||
case DW_TAG_template_type_parameter:
|
case DW_TAG_template_type_parameter:
|
||||||
fTemplateTypeParameters.Add(child);
|
|
||||||
return B_OK;
|
|
||||||
case DW_TAG_template_value_parameter:
|
case DW_TAG_template_value_parameter:
|
||||||
fTemplateValueParameters.Add(child);
|
fTemplateParameters.Add(child);
|
||||||
return B_OK;
|
return B_OK;
|
||||||
// TODO: Variants!
|
// TODO: Variants!
|
||||||
default:
|
default:
|
||||||
|
|||||||
@@ -353,10 +353,8 @@ public:
|
|||||||
|
|
||||||
const DebugInfoEntryList& BaseTypes() const
|
const DebugInfoEntryList& BaseTypes() const
|
||||||
{ return fBaseTypes; }
|
{ return fBaseTypes; }
|
||||||
const DebugInfoEntryList& TemplateTypeParameters() const
|
const DebugInfoEntryList& TemplateParameters() const
|
||||||
{ return fTemplateTypeParameters; }
|
{ return fTemplateParameters; }
|
||||||
const DebugInfoEntryList& TemplateValueParameters() const
|
|
||||||
{ return fTemplateValueParameters; }
|
|
||||||
|
|
||||||
virtual status_t AddChild(DebugInfoEntry* child);
|
virtual status_t AddChild(DebugInfoEntry* child);
|
||||||
|
|
||||||
@@ -366,8 +364,7 @@ protected:
|
|||||||
DebugInfoEntryList fAccessDeclarations;
|
DebugInfoEntryList fAccessDeclarations;
|
||||||
DebugInfoEntryList fMemberFunctions;
|
DebugInfoEntryList fMemberFunctions;
|
||||||
DebugInfoEntryList fInnerTypes;
|
DebugInfoEntryList fInnerTypes;
|
||||||
DebugInfoEntryList fTemplateTypeParameters;
|
DebugInfoEntryList fTemplateParameters;
|
||||||
DebugInfoEntryList fTemplateValueParameters;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -72,6 +72,14 @@ FunctionParameter::~FunctionParameter()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// #pragma mark - TemplateParameter
|
||||||
|
|
||||||
|
|
||||||
|
TemplateParameter::~TemplateParameter()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// #pragma mark - Type
|
// #pragma mark - Type
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -43,6 +43,12 @@ enum address_type_kind {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
enum template_type_kind {
|
||||||
|
TEMPLATE_TYPE_TYPE,
|
||||||
|
TEMPLATE_TYPE_VALUE
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
TYPE_MODIFIER_CONST = 0x01,
|
TYPE_MODIFIER_CONST = 0x01,
|
||||||
TYPE_MODIFIER_VOLATILE = 0x02,
|
TYPE_MODIFIER_VOLATILE = 0x02,
|
||||||
@@ -105,6 +111,16 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
class TemplateParameter : public BReferenceable {
|
||||||
|
public:
|
||||||
|
virtual ~TemplateParameter();
|
||||||
|
|
||||||
|
virtual template_type_kind Kind() const = 0;
|
||||||
|
virtual Type* GetType() const = 0;
|
||||||
|
virtual BVariant Value() const = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
class Type : public BReferenceable {
|
class Type : public BReferenceable {
|
||||||
public:
|
public:
|
||||||
virtual ~Type();
|
virtual ~Type();
|
||||||
@@ -158,12 +174,9 @@ public:
|
|||||||
virtual int32 CountDataMembers() const = 0;
|
virtual int32 CountDataMembers() const = 0;
|
||||||
virtual DataMember* DataMemberAt(int32 index) const = 0;
|
virtual DataMember* DataMemberAt(int32 index) const = 0;
|
||||||
|
|
||||||
virtual int32 CountTemplateTypeParameters() const = 0;
|
virtual int32 CountTemplateParameters() const = 0;
|
||||||
virtual Type* TemplateTypeParameterAt(int32 index) const = 0;
|
virtual TemplateParameter* TemplateParameterAt(int32 index) const = 0;
|
||||||
|
|
||||||
virtual int32 CountTemplateValueParameters() const = 0;
|
|
||||||
virtual Type* TemplateValueParameterAt(int32 index) const
|
|
||||||
= 0;
|
|
||||||
|
|
||||||
virtual status_t ResolveBaseTypeLocation(BaseType* baseType,
|
virtual status_t ResolveBaseTypeLocation(BaseType* baseType,
|
||||||
const ValueLocation& parentLocation,
|
const ValueLocation& parentLocation,
|
||||||
|
|||||||
Reference in New Issue
Block a user