[Lldb-commits] [lldb] r149658 - in /lldb/trunk: include/lldb/API/SBType.h include/lldb/Symbol/ClangASTContext.h include/lldb/lldb-enumerations.h scripts/Python/interface/SBType.i source/API/SBType.cpp source/Interpreter/ScriptInterpreterPython.cpp source/Symbol/ClangASTContext.cpp
Greg Clayton
gclayton at apple.com
Thu Feb 2 17:30:31 PST 2012
Author: gclayton
Date: Thu Feb 2 19:30:30 2012
New Revision: 149658
URL: http://llvm.org/viewvc/llvm-project?rev=149658&view=rev
Log:
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.
Modified:
lldb/trunk/include/lldb/API/SBType.h
lldb/trunk/include/lldb/Symbol/ClangASTContext.h
lldb/trunk/include/lldb/lldb-enumerations.h
lldb/trunk/scripts/Python/interface/SBType.i
lldb/trunk/source/API/SBType.cpp
lldb/trunk/source/Interpreter/ScriptInterpreterPython.cpp
lldb/trunk/source/Symbol/ClangASTContext.cpp
Modified: lldb/trunk/include/lldb/API/SBType.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBType.h?rev=149658&r1=149657&r2=149658&view=diff
==============================================================================
--- lldb/trunk/include/lldb/API/SBType.h (original)
+++ lldb/trunk/include/lldb/API/SBType.h Thu Feb 2 19:30:30 2012
@@ -124,6 +124,15 @@
lldb::SBTypeMember
GetVirtualBaseClassAtIndex (uint32_t idx);
+ uint32_t
+ GetNumberOfTemplateArguments ();
+
+ lldb::SBType
+ GetTemplateArgumentType (uint32_t idx);
+
+ lldb::TemplateArgumentKind
+ GetTemplateArgumentKind (uint32_t idx);
+
const char*
GetName();
Modified: lldb/trunk/include/lldb/Symbol/ClangASTContext.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Symbol/ClangASTContext.h?rev=149658&r1=149657&r2=149658&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Symbol/ClangASTContext.h (original)
+++ lldb/trunk/include/lldb/Symbol/ClangASTContext.h Thu Feb 2 19:30:30 2012
@@ -593,6 +593,30 @@
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
//------------------------------------------------------------------
Modified: lldb/trunk/include/lldb/lldb-enumerations.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/lldb-enumerations.h?rev=149658&r1=149657&r2=149658&view=diff
==============================================================================
--- lldb/trunk/include/lldb/lldb-enumerations.h (original)
+++ lldb/trunk/include/lldb/lldb-enumerations.h Thu Feb 2 19:30:30 2012
@@ -577,6 +577,19 @@
eTypeClassAny = (0xffffffffu)
}TypeClass;
+ typedef enum TemplateArgumentKind
+ {
+ eTemplateArgumentKindNull = 0,
+ eTemplateArgumentKindType,
+ eTemplateArgumentKindDeclaration,
+ eTemplateArgumentKindIntegral,
+ eTemplateArgumentKindTemplate,
+ eTemplateArgumentKindTemplateExpansion,
+ eTemplateArgumentKindExpression,
+ eTemplateArgumentKindPack
+
+ } TemplateArgumentKind;
+
} // namespace lldb
Modified: lldb/trunk/scripts/Python/interface/SBType.i
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/Python/interface/SBType.i?rev=149658&r1=149657&r2=149658&view=diff
==============================================================================
--- lldb/trunk/scripts/Python/interface/SBType.i (original)
+++ lldb/trunk/scripts/Python/interface/SBType.i Thu Feb 2 19:30:30 2012
@@ -191,6 +191,15 @@
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)
Modified: lldb/trunk/source/API/SBType.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBType.cpp?rev=149658&r1=149657&r2=149658&view=diff
==============================================================================
--- lldb/trunk/source/API/SBType.cpp (original)
+++ lldb/trunk/source/API/SBType.cpp Thu Feb 2 19:30:30 2012
@@ -437,6 +437,50 @@
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 @@
{
return *m_opaque_ap.get();
}
-
Modified: lldb/trunk/source/Interpreter/ScriptInterpreterPython.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/ScriptInterpreterPython.cpp?rev=149658&r1=149657&r2=149658&view=diff
==============================================================================
--- lldb/trunk/source/Interpreter/ScriptInterpreterPython.cpp (original)
+++ lldb/trunk/source/Interpreter/ScriptInterpreterPython.cpp Thu Feb 2 19:30:30 2012
@@ -326,7 +326,7 @@
// 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());
Modified: lldb/trunk/source/Symbol/ClangASTContext.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/ClangASTContext.cpp?rev=149658&r1=149657&r2=149658&view=diff
==============================================================================
--- lldb/trunk/source/Symbol/ClangASTContext.cpp (original)
+++ lldb/trunk/source/Symbol/ClangASTContext.cpp Thu Feb 2 19:30:30 2012
@@ -2499,6 +2499,111 @@
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
More information about the lldb-commits
mailing list