Added support to SBType for getting template arguments from a SBType:

uint32_t
SBType::GetNumberOfTemplateArguments ();

lldb::SBType
SBType::GetTemplateArgumentType (uint32_t idx);

lldb::TemplateArgumentKind
SBType::GetTemplateArgumentKind (uint32_t idx);

Some lldb::TemplateArgumentKind values don't have a corresponding SBType
that will be returned from SBType::GetTemplateArgumentType(). This will
help our data formatters do their job by being able to find out the
type of template params and do smart things with those.

llvm-svn: 149658
This commit is contained in:
Greg Clayton 2012-02-03 01:30:30 +00:00
parent 5069aa33b9
commit 402230e633
7 changed files with 205 additions and 2 deletions

View File

@ -124,6 +124,15 @@ public:
lldb::SBTypeMember
GetVirtualBaseClassAtIndex (uint32_t idx);
uint32_t
GetNumberOfTemplateArguments ();
lldb::SBType
GetTemplateArgumentType (uint32_t idx);
lldb::TemplateArgumentKind
GetTemplateArgumentKind (uint32_t idx);
const char*
GetName();

View File

@ -593,6 +593,30 @@ public:
bool omit_empty_base_classes,
std::vector<uint32_t>& child_indexes);
size_t
GetNumTemplateArguments (lldb::clang_type_t clang_type)
{
return GetNumTemplateArguments(getASTContext(), clang_type);
}
lldb::clang_type_t
GetTemplateArgument (lldb::clang_type_t clang_type,
size_t idx,
lldb::TemplateArgumentKind &kind)
{
return GetTemplateArgument(getASTContext(), clang_type, idx, kind);
}
static size_t
GetNumTemplateArguments (clang::ASTContext *ast,
lldb::clang_type_t clang_type);
static lldb::clang_type_t
GetTemplateArgument (clang::ASTContext *ast,
lldb::clang_type_t clang_type,
size_t idx,
lldb::TemplateArgumentKind &kind);
//------------------------------------------------------------------
// clang::TagType
//------------------------------------------------------------------

View File

@ -577,6 +577,19 @@ namespace lldb {
eTypeClassAny = (0xffffffffu)
}TypeClass;
typedef enum TemplateArgumentKind
{
eTemplateArgumentKindNull = 0,
eTemplateArgumentKindType,
eTemplateArgumentKindDeclaration,
eTemplateArgumentKindIntegral,
eTemplateArgumentKindTemplate,
eTemplateArgumentKindTemplateExpansion,
eTemplateArgumentKindExpression,
eTemplateArgumentKindPack
} TemplateArgumentKind;
} // namespace lldb

View File

@ -191,6 +191,15 @@ public:
lldb::TypeClass
GetTypeClass ();
uint32_t
GetNumberOfTemplateArguments ();
lldb::SBType
GetTemplateArgumentType (uint32_t idx);
lldb::TemplateArgumentKind
GetTemplateArgumentKind (uint32_t idx);
%pythoncode %{
__swig_getmethods__["name"] = GetName
if _newclass: x = property(GetName, None)

View File

@ -437,6 +437,50 @@ SBType::GetTypeClass ()
return lldb::eTypeClassInvalid;
}
uint32_t
SBType::GetNumberOfTemplateArguments ()
{
if (IsValid())
{
return ClangASTContext::GetNumTemplateArguments (m_opaque_sp->GetASTContext(),
m_opaque_sp->GetOpaqueQualType());
}
return 0;
}
lldb::SBType
SBType::GetTemplateArgumentType (uint32_t idx)
{
if (IsValid())
{
TemplateArgumentKind kind = eTemplateArgumentKindNull;
return SBType(ClangASTType(m_opaque_sp->GetASTContext(),
ClangASTContext::GetTemplateArgument(m_opaque_sp->GetASTContext(),
m_opaque_sp->GetOpaqueQualType(),
idx,
kind)));
}
return SBType();
}
lldb::TemplateArgumentKind
SBType::GetTemplateArgumentKind (uint32_t idx)
{
TemplateArgumentKind kind = eTemplateArgumentKindNull;
if (IsValid())
{
ClangASTContext::GetTemplateArgument(m_opaque_sp->GetASTContext(),
m_opaque_sp->GetOpaqueQualType(),
idx,
kind);
}
return kind;
}
SBTypeList::SBTypeList() :
m_opaque_ap(new TypeListImpl())
{
@ -622,4 +666,3 @@ SBTypeMember::ref () const
{
return *m_opaque_ap.get();
}

View File

@ -326,7 +326,7 @@ ScriptInterpreterPython::EnterSession ()
// embedded we don't know we should be feeding input to the embedded
// interpreter or to the python sys.stdin. We also don't want to let python
// play with the real stdin from this process, so we need to close it...
run_string.PutCString ("; sys.stdin.close()");
//run_string.PutCString ("; sys.stdin.close()");
run_string.PutCString ("')");
PyRun_SimpleString (run_string.GetData());

View File

@ -2499,6 +2499,111 @@ ClangASTContext::AddMethodToObjCObjectType
return objc_method_decl;
}
size_t
ClangASTContext::GetNumTemplateArguments (clang::ASTContext *ast, 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::Record:
if (GetCompleteQualType (ast, qual_type))
{
const CXXRecordDecl *cxx_record_decl = qual_type->getAsCXXRecordDecl();
if (cxx_record_decl)
{
const ClassTemplateSpecializationDecl *template_decl = dyn_cast<ClassTemplateSpecializationDecl>(cxx_record_decl);
if (template_decl)
return template_decl->getTemplateArgs().size();
}
}
break;
case clang::Type::Typedef:
return ClangASTContext::GetNumTemplateArguments (ast, cast<TypedefType>(qual_type)->getDecl()->getUnderlyingType().getAsOpaquePtr());
default:
break;
}
}
return 0;
}
clang_type_t
ClangASTContext::GetTemplateArgument (clang::ASTContext *ast, clang_type_t clang_type, size_t arg_idx, lldb::TemplateArgumentKind &kind)
{
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::Record:
if (GetCompleteQualType (ast, qual_type))
{
const CXXRecordDecl *cxx_record_decl = qual_type->getAsCXXRecordDecl();
if (cxx_record_decl)
{
const ClassTemplateSpecializationDecl *template_decl = dyn_cast<ClassTemplateSpecializationDecl>(cxx_record_decl);
if (template_decl && arg_idx < template_decl->getTemplateArgs().size())
{
const TemplateArgument &template_arg = template_decl->getTemplateArgs()[arg_idx];
switch (template_arg.getKind())
{
case clang::TemplateArgument::Null:
kind = eTemplateArgumentKindNull;
return NULL;
case clang::TemplateArgument::Type:
kind = eTemplateArgumentKindType;
return template_arg.getAsType().getAsOpaquePtr();
case clang::TemplateArgument::Declaration:
kind = eTemplateArgumentKindDeclaration;
return NULL;
case clang::TemplateArgument::Integral:
kind = eTemplateArgumentKindIntegral;
return template_arg.getIntegralType().getAsOpaquePtr();
case clang::TemplateArgument::Template:
kind = eTemplateArgumentKindTemplate;
return NULL;
case clang::TemplateArgument::TemplateExpansion:
kind = eTemplateArgumentKindTemplateExpansion;
return NULL;
case clang::TemplateArgument::Expression:
kind = eTemplateArgumentKindExpression;
return NULL;
case clang::TemplateArgument::Pack:
kind = eTemplateArgumentKindPack;
return NULL;
default:
assert (!"Unhandled TemplateArgument::ArgKind");
kind = eTemplateArgumentKindNull;
return NULL;
}
}
}
}
break;
case clang::Type::Typedef:
return ClangASTContext::GetTemplateArgument (ast, cast<TypedefType>(qual_type)->getDecl()->getUnderlyingType().getAsOpaquePtr(), arg_idx, kind);
default:
break;
}
}
kind = eTemplateArgumentKindNull;
return NULL;
}
uint32_t
ClangASTContext::GetTypeInfo