<rdar://problem/12490588>

From SBType, we can now get a lldb::BasicType enumeration out of an existing type.

llvm-svn: 165857
This commit is contained in:
Greg Clayton 2012-10-13 00:20:27 +00:00
parent 01db0c6823
commit eaafa732df
6 changed files with 123 additions and 27 deletions

View File

@ -105,6 +105,12 @@ public:
lldb::SBType
GetUnqualifiedType();
// Get the "lldb::BasicType" enumeration for a type. If a type is not a basic
// type eBasicTypeInvalid will be returned
lldb::BasicType
GetBasicType();
// The call below confusing and should really be renamed to "CreateBasicType"
lldb::SBType
GetBasicType(lldb::BasicType type);

View File

@ -274,6 +274,9 @@ public:
lldb::clang_type_t
GetTypeForDecl (clang::ObjCInterfaceDecl *objc_decl);
static lldb::BasicType
GetLLDBBasicTypeEnumeration (lldb::clang_type_t clang_type);
//------------------------------------------------------------------
// CVR modifiers
//------------------------------------------------------------------

View File

@ -537,7 +537,10 @@ namespace lldb {
eBasicTypeVoid = 1,
eBasicTypeChar,
eBasicTypeSignedChar,
eBasicTypeUnsignedChar,
eBasicTypeWChar,
eBasicTypeSignedWChar,
eBasicTypeUnsignedWChar,
eBasicTypeChar16,
eBasicTypeChar32,
eBasicTypeShort,
@ -551,6 +554,7 @@ namespace lldb {
eBasicTypeInt128,
eBasicTypeUnsignedInt128,
eBasicTypeBool,
eBasicTypeHalf,
eBasicTypeFloat,
eBasicTypeDouble,
eBasicTypeLongDouble,
@ -559,7 +563,9 @@ namespace lldb {
eBasicTypeLongDoubleComplex,
eBasicTypeObjCID,
eBasicTypeObjCClass,
eBasicTypeObjCSel
eBasicTypeObjCSel,
eBasicTypeNullPtr,
eBasicTypeOther
} BasicType;
typedef enum TypeClass

View File

@ -177,6 +177,9 @@ public:
lldb::SBType
GetUnqualifiedType();
lldb::BasicType
GetBasicType();
lldb::SBType
GetBasicType (lldb::BasicType type);

View File

@ -229,24 +229,51 @@ SBType::GetUnqualifiedType()
return SBType(ClangASTType(m_opaque_sp->GetASTContext(),qt.getUnqualifiedType().getAsOpaquePtr()));
}
lldb::BasicType
SBType::GetBasicType()
{
if (IsValid())
return ClangASTContext::GetLLDBBasicTypeEnumeration (m_opaque_sp->GetOpaqueQualType());
return eBasicTypeInvalid;
}
SBType
SBType::GetBasicType(lldb::BasicType type)
{
if (!IsValid())
return SBType();
clang::CanQualType base_type_qual;
clang::QualType base_type_qual;
switch (type)
{
case eBasicTypeVoid:
base_type_qual = m_opaque_sp->GetASTContext()->VoidTy;
break;
case eBasicTypeChar:
base_type_qual = m_opaque_sp->GetASTContext()->CharTy;
break;
case eBasicTypeSignedChar:
base_type_qual = m_opaque_sp->GetASTContext()->SignedCharTy;
break;
case eBasicTypeUnsignedChar:
base_type_qual = m_opaque_sp->GetASTContext()->UnsignedCharTy;
break;
case eBasicTypeWChar:
base_type_qual = m_opaque_sp->GetASTContext()->getWCharType();
break;
case eBasicTypeSignedWChar:
base_type_qual = m_opaque_sp->GetASTContext()->getSignedWCharType();
break;
case eBasicTypeUnsignedWChar:
base_type_qual = m_opaque_sp->GetASTContext()->getUnsignedWCharType();
break;
case eBasicTypeChar16:
base_type_qual = m_opaque_sp->GetASTContext()->Char16Ty;
break;
case eBasicTypeChar32:
base_type_qual = m_opaque_sp->GetASTContext()->Char32Ty;
break;
case eBasicTypeShort:
base_type_qual = m_opaque_sp->GetASTContext()->ShortTy;
break;
@ -265,30 +292,6 @@ SBType::GetBasicType(lldb::BasicType type)
case eBasicTypeUnsignedLong:
base_type_qual = m_opaque_sp->GetASTContext()->UnsignedLongTy;
break;
case eBasicTypeBool:
base_type_qual = m_opaque_sp->GetASTContext()->BoolTy;
break;
case eBasicTypeFloat:
base_type_qual = m_opaque_sp->GetASTContext()->FloatTy;
break;
case eBasicTypeDouble:
base_type_qual = m_opaque_sp->GetASTContext()->DoubleTy;
break;
case eBasicTypeObjCID:
base_type_qual = m_opaque_sp->GetASTContext()->ObjCBuiltinIdTy;
break;
case eBasicTypeVoid:
base_type_qual = m_opaque_sp->GetASTContext()->VoidTy;
break;
case eBasicTypeWChar:
base_type_qual = m_opaque_sp->GetASTContext()->WCharTy;
break;
case eBasicTypeChar16:
base_type_qual = m_opaque_sp->GetASTContext()->Char16Ty;
break;
case eBasicTypeChar32:
base_type_qual = m_opaque_sp->GetASTContext()->Char32Ty;
break;
case eBasicTypeLongLong:
base_type_qual = m_opaque_sp->GetASTContext()->LongLongTy;
break;
@ -301,6 +304,18 @@ SBType::GetBasicType(lldb::BasicType type)
case eBasicTypeUnsignedInt128:
base_type_qual = m_opaque_sp->GetASTContext()->UnsignedInt128Ty;
break;
case eBasicTypeBool:
base_type_qual = m_opaque_sp->GetASTContext()->BoolTy;
break;
case eBasicTypeHalf:
base_type_qual = m_opaque_sp->GetASTContext()->HalfTy;
break;
case eBasicTypeFloat:
base_type_qual = m_opaque_sp->GetASTContext()->FloatTy;
break;
case eBasicTypeDouble:
base_type_qual = m_opaque_sp->GetASTContext()->DoubleTy;
break;
case eBasicTypeLongDouble:
base_type_qual = m_opaque_sp->GetASTContext()->LongDoubleTy;
break;
@ -313,12 +328,18 @@ SBType::GetBasicType(lldb::BasicType type)
case eBasicTypeLongDoubleComplex:
base_type_qual = m_opaque_sp->GetASTContext()->LongDoubleComplexTy;
break;
case eBasicTypeObjCID:
base_type_qual = m_opaque_sp->GetASTContext()->ObjCBuiltinIdTy;
break;
case eBasicTypeObjCClass:
base_type_qual = m_opaque_sp->GetASTContext()->ObjCBuiltinClassTy;
break;
case eBasicTypeObjCSel:
base_type_qual = m_opaque_sp->GetASTContext()->ObjCBuiltinSelTy;
break;
case eBasicTypeNullPtr:
base_type_qual = m_opaque_sp->GetASTContext()->NullPtrTy;
break;
default:
return SBType();
}

View File

@ -3644,6 +3644,63 @@ ClangASTContext::GetFieldAtIndex (clang::ASTContext *ast,
return NULL;
}
lldb::BasicType
ClangASTContext::GetLLDBBasicTypeEnumeration (clang_type_t clang_type)
{
if (clang_type)
{
QualType qual_type(QualType::getFromOpaquePtr(clang_type));
const clang::Type::TypeClass type_class = qual_type->getTypeClass();
switch (type_class)
{
case clang::Type::Builtin:
switch (cast<clang::BuiltinType>(qual_type)->getKind())
case clang::BuiltinType::Void: return eBasicTypeVoid;
case clang::BuiltinType::Bool: return eBasicTypeBool;
case clang::BuiltinType::Char_S: return eBasicTypeSignedChar;
case clang::BuiltinType::Char_U: return eBasicTypeUnsignedChar;
case clang::BuiltinType::Char16: return eBasicTypeChar16;
case clang::BuiltinType::Char32: return eBasicTypeChar32;
case clang::BuiltinType::UChar: return eBasicTypeUnsignedChar;
case clang::BuiltinType::SChar: return eBasicTypeSignedChar;
case clang::BuiltinType::WChar_S: return eBasicTypeSignedWChar;
case clang::BuiltinType::WChar_U: return eBasicTypeUnsignedWChar;
case clang::BuiltinType::Short: return eBasicTypeShort;
case clang::BuiltinType::UShort: return eBasicTypeUnsignedShort;
case clang::BuiltinType::Int: return eBasicTypeInt;
case clang::BuiltinType::UInt: return eBasicTypeUnsignedInt;
case clang::BuiltinType::Long: return eBasicTypeLong;
case clang::BuiltinType::ULong: return eBasicTypeUnsignedLong;
case clang::BuiltinType::LongLong: return eBasicTypeLongLong;
case clang::BuiltinType::ULongLong: return eBasicTypeUnsignedLongLong;
case clang::BuiltinType::Int128: return eBasicTypeInt128;
case clang::BuiltinType::UInt128: return eBasicTypeUnsignedInt128;
case clang::BuiltinType::Half: return eBasicTypeHalf;
case clang::BuiltinType::Float: return eBasicTypeFloat;
case clang::BuiltinType::Double: return eBasicTypeDouble;
case clang::BuiltinType::LongDouble:return eBasicTypeLongDouble;
case clang::BuiltinType::NullPtr: return eBasicTypeNullPtr;
case clang::BuiltinType::ObjCId: return eBasicTypeObjCID;
case clang::BuiltinType::ObjCClass: return eBasicTypeObjCClass;
case clang::BuiltinType::ObjCSel: return eBasicTypeObjCSel;
case clang::BuiltinType::Dependent:
case clang::BuiltinType::Overload:
case clang::BuiltinType::BoundMember:
case clang::BuiltinType::PseudoObject:
case clang::BuiltinType::UnknownAny:
case clang::BuiltinType::BuiltinFn:
case clang::BuiltinType::ARCUnbridgedCast:
return eBasicTypeOther;
}
}
return eBasicTypeInvalid;
}
// If a pointer to a pointee type (the clang_type arg) says that it has no
// children, then we either need to trust it, or override it and return a