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
|
||||
{
|
||||
return !entry->TemplateTypeParameters().IsEmpty();
|
||||
return !entry->TemplateParameters().IsEmpty();
|
||||
}
|
||||
};
|
||||
|
||||
@@ -565,23 +565,41 @@ printf(" -> failed to add type to cache\n");
|
||||
// parameters
|
||||
classTypeEntry = DwarfUtils::GetDIEByPredicate(
|
||||
dynamic_cast<DIEClassBaseType*>(typeEntry),
|
||||
HasTemplateTypeParametersPredicate());
|
||||
HasTemplateParametersPredicate());
|
||||
|
||||
if (classTypeEntry != NULL) {
|
||||
for (DebugInfoEntryList::ConstIterator it
|
||||
= classTypeEntry->TemplateTypeParameters()
|
||||
= classTypeEntry->TemplateParameters()
|
||||
.GetIterator();
|
||||
DebugInfoEntry* _typeEntry = it.Next();) {
|
||||
DIETemplateTypeParameter* templateTypeEntry =
|
||||
dynamic_cast<DIETemplateTypeParameter*>(_typeEntry);
|
||||
DIETemplateTypeParameter* templateTypeEntry
|
||||
= dynamic_cast<DIETemplateTypeParameter*>(_typeEntry);
|
||||
DwarfType* templateType;
|
||||
if (CreateType(templateTypeEntry->GetType(), templateType)
|
||||
!= B_OK) {
|
||||
continue;
|
||||
if (templateTypeEntry != NULL) {
|
||||
if (CreateType(templateTypeEntry->GetType(), templateType)
|
||||
!= B_OK) {
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
DIETemplateValueParameter* templateValueEntry
|
||||
= dynamic_cast<DIETemplateValueParameter*>(_typeEntry);
|
||||
if (CreateType(templateValueEntry->GetType(), templateType)
|
||||
!= B_OK) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
BReference<DwarfType> templateTypeReference(templateType,
|
||||
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();
|
||||
fTypeCache->RemoveType(type);
|
||||
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
|
||||
|
||||
|
||||
@@ -568,8 +607,10 @@ 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();
|
||||
for (int32 i = 0; DwarfTemplateParameter* parameter
|
||||
= fTemplateParameters.ItemAt(i); i++) {
|
||||
parameter->ReleaseReference();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -609,32 +650,16 @@ DwarfCompoundType::DataMemberAt(int32 index) const
|
||||
|
||||
|
||||
int32
|
||||
DwarfCompoundType::CountTemplateTypeParameters() const
|
||||
DwarfCompoundType::CountTemplateParameters() const
|
||||
{
|
||||
return fTemplateTypeParameters.CountItems();
|
||||
return fTemplateParameters.CountItems();
|
||||
}
|
||||
|
||||
|
||||
Type*
|
||||
DwarfCompoundType::TemplateTypeParameterAt(int32 index) const
|
||||
TemplateParameter*
|
||||
DwarfCompoundType::TemplateParameterAt(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;
|
||||
return fTemplateParameters.ItemAt(index);
|
||||
}
|
||||
|
||||
|
||||
@@ -770,12 +795,12 @@ DwarfCompoundType::AddDataMember(DwarfDataMember* member)
|
||||
|
||||
|
||||
bool
|
||||
DwarfCompoundType::AddTemplateTypeParameter(DwarfType* type)
|
||||
DwarfCompoundType::AddTemplateParameter(DwarfTemplateParameter* parameter)
|
||||
{
|
||||
if (!fTemplateTypeParameters.AddItem(type))
|
||||
if (!fTemplateParameters.AddItem(parameter))
|
||||
return false;
|
||||
|
||||
type->AcquireReference();
|
||||
parameter->AcquireReference();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
|
||||
class Architecture;
|
||||
class CompilationUnit;
|
||||
class DebugInfoEntry;
|
||||
class DIEAddressingType;
|
||||
class DIEArrayType;
|
||||
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 {
|
||||
public:
|
||||
DwarfPrimitiveType(
|
||||
@@ -271,11 +291,8 @@ 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 int32 CountTemplateParameters() const;
|
||||
virtual TemplateParameter* TemplateParameterAt(int32 index) const;
|
||||
|
||||
virtual status_t ResolveBaseTypeLocation(BaseType* _baseType,
|
||||
const ValueLocation& parentLocation,
|
||||
@@ -291,12 +308,13 @@ public:
|
||||
|
||||
bool AddInheritance(DwarfInheritance* inheritance);
|
||||
bool AddDataMember(DwarfDataMember* member);
|
||||
bool AddTemplateTypeParameter(DwarfType* type);
|
||||
bool AddTemplateParameter(
|
||||
DwarfTemplateParameter* parameter);
|
||||
|
||||
private:
|
||||
typedef BObjectList<DwarfDataMember> DataMemberList;
|
||||
typedef BObjectList<DwarfInheritance> InheritanceList;
|
||||
typedef BObjectList<DwarfType> TemplateTypeList;
|
||||
typedef BObjectList<DwarfTemplateParameter> TemplateParameterList;
|
||||
|
||||
private:
|
||||
status_t _ResolveDataMemberLocation(
|
||||
@@ -310,7 +328,7 @@ private:
|
||||
DIECompoundType* fEntry;
|
||||
InheritanceList fInheritances;
|
||||
DataMemberList fDataMembers;
|
||||
TemplateTypeList fTemplateTypeParameters;
|
||||
TemplateParameterList fTemplateParameters;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -478,10 +478,8 @@ DIEClassBaseType::AddChild(DebugInfoEntry* child)
|
||||
fMemberFunctions.Add(child);
|
||||
return B_OK;
|
||||
case DW_TAG_template_type_parameter:
|
||||
fTemplateTypeParameters.Add(child);
|
||||
return B_OK;
|
||||
case DW_TAG_template_value_parameter:
|
||||
fTemplateValueParameters.Add(child);
|
||||
fTemplateParameters.Add(child);
|
||||
return B_OK;
|
||||
// TODO: Variants!
|
||||
default:
|
||||
|
||||
@@ -353,10 +353,8 @@ public:
|
||||
|
||||
const DebugInfoEntryList& BaseTypes() const
|
||||
{ return fBaseTypes; }
|
||||
const DebugInfoEntryList& TemplateTypeParameters() const
|
||||
{ return fTemplateTypeParameters; }
|
||||
const DebugInfoEntryList& TemplateValueParameters() const
|
||||
{ return fTemplateValueParameters; }
|
||||
const DebugInfoEntryList& TemplateParameters() const
|
||||
{ return fTemplateParameters; }
|
||||
|
||||
virtual status_t AddChild(DebugInfoEntry* child);
|
||||
|
||||
@@ -366,8 +364,7 @@ protected:
|
||||
DebugInfoEntryList fAccessDeclarations;
|
||||
DebugInfoEntryList fMemberFunctions;
|
||||
DebugInfoEntryList fInnerTypes;
|
||||
DebugInfoEntryList fTemplateTypeParameters;
|
||||
DebugInfoEntryList fTemplateValueParameters;
|
||||
DebugInfoEntryList fTemplateParameters;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -72,6 +72,14 @@ FunctionParameter::~FunctionParameter()
|
||||
}
|
||||
|
||||
|
||||
// #pragma mark - TemplateParameter
|
||||
|
||||
|
||||
TemplateParameter::~TemplateParameter()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
// #pragma mark - Type
|
||||
|
||||
|
||||
|
||||
@@ -43,6 +43,12 @@ enum address_type_kind {
|
||||
};
|
||||
|
||||
|
||||
enum template_type_kind {
|
||||
TEMPLATE_TYPE_TYPE,
|
||||
TEMPLATE_TYPE_VALUE
|
||||
};
|
||||
|
||||
|
||||
enum {
|
||||
TYPE_MODIFIER_CONST = 0x01,
|
||||
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 {
|
||||
public:
|
||||
virtual ~Type();
|
||||
@@ -158,12 +174,9 @@ 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 CountTemplateParameters() 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,
|
||||
const ValueLocation& parentLocation,
|
||||
|
||||
Reference in New Issue
Block a user