This change brings in the latest LLVM/Clang, and
completes the support in the LLDB expression parser
for incomplete types. Clang now imports types
lazily, and we complete those types as necessary.
Changes include:
- ClangASTSource now supports three APIs which it
passes to ClangExpressionDeclMap. CompleteType
completes a TagDecl or an ObjCInterfaceDecl when
needed; FindExternalVisibleDecls finds named
entities that are visible in the expression's
scope; and FindExternalLexicalDecls performs a
(potentially restricted) search for entities
inside a lexical scope like a namespace. These
changes mean that entities in namespaces should
work normally.
- The SymbolFileDWARF code for searching a context
for a specific name is now more general, and can
search arbitrary contexts.
- We are continuing to adapt our calls into LLVM
from interfaces that take start and end iterators
when accepting multiple items to interfaces that
use ArrayRef.
- I have cleaned up some code, especially our use
of namespaces.
This change is neutral for our testsuite and greatly
improves correctness for large programs (like Clang)
with complicated type systems. It should also lay
the groundwork for improving the expression parser's
performance as we are lazier and lazier about
providing type information.
git-svn-id: https://llvm.org/svn/llvm-project/llvdb/trunk@136555 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/source/Expression/ClangExpressionDeclMap.cpp b/source/Expression/ClangExpressionDeclMap.cpp
index 97e73bd..4f21fc0 100644
--- a/source/Expression/ClangExpressionDeclMap.cpp
+++ b/source/Expression/ClangExpressionDeclMap.cpp
@@ -134,7 +134,7 @@
{
assert (m_parser_vars.get());
ExecutionContext *exe_ctx = m_parser_vars->m_exe_ctx;
- clang::ASTContext *context(exe_ctx->target->GetScratchClangASTContext()->getASTContext());
+ ASTContext *context(exe_ctx->target->GetScratchClangASTContext()->getASTContext());
TypeFromUser user_type(ClangASTContext::CopyType(context,
type.GetASTContext(),
@@ -203,7 +203,7 @@
lldb::ClangExpressionVariableSP
ClangExpressionDeclMap::BuildCastVariable (const ConstString &name,
- clang::VarDecl *decl,
+ VarDecl *decl,
lldb_private::TypeFromParser type)
{
assert (m_parser_vars.get());
@@ -211,7 +211,7 @@
lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
ExecutionContext *exe_ctx = m_parser_vars->m_exe_ctx;
- clang::ASTContext *context(exe_ctx->target->GetScratchClangASTContext()->getASTContext());
+ ASTContext *context(exe_ctx->target->GetScratchClangASTContext()->getASTContext());
ClangExpressionVariableSP var_sp (m_found_entities.GetVariable(decl));
@@ -273,7 +273,7 @@
bool
ClangExpressionDeclMap::AddPersistentVariable
(
- const clang::NamedDecl *decl,
+ const NamedDecl *decl,
const ConstString &name,
TypeFromParser parser_type,
bool is_result,
@@ -285,7 +285,7 @@
lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
ExecutionContext *exe_ctx = m_parser_vars->m_exe_ctx;
- clang::ASTContext *context(exe_ctx->target->GetScratchClangASTContext()->getASTContext());
+ ASTContext *context(exe_ctx->target->GetScratchClangASTContext()->getASTContext());
TypeFromUser user_type(ClangASTContext::CopyType(context,
parser_type.GetASTContext(),
@@ -333,7 +333,7 @@
bool
ClangExpressionDeclMap::AddValueToStruct
(
- const clang::NamedDecl *decl,
+ const NamedDecl *decl,
const ConstString &name,
llvm::Value *value,
size_t size,
@@ -439,7 +439,7 @@
bool
ClangExpressionDeclMap::GetStructElement
(
- const clang::NamedDecl *&decl,
+ const NamedDecl *&decl,
llvm::Value *&value,
off_t &offset,
ConstString &name,
@@ -472,7 +472,7 @@
bool
ClangExpressionDeclMap::GetFunctionInfo
(
- const clang::NamedDecl *decl,
+ const NamedDecl *decl,
llvm::Value**& value,
uint64_t &ptr
)
@@ -915,7 +915,7 @@
if (log)
log->PutCString("Not bothering to allocate a struct because no arguments are needed");
- m_material_vars->m_allocated_area = 0;
+ m_material_vars->m_allocated_area = NULL;
return true;
}
@@ -1674,61 +1674,57 @@
if (isa<TranslationUnitDecl>(context.m_decl_context))
break;
- if (log)
- log->Printf("'%s' is in something other than a translation unit", name.GetCString());
-
- const Decl *context_decl = dyn_cast<Decl>(context.m_decl_context);
-
- if (!context_decl)
+ if (!isa<NamespaceDecl>(context.m_decl_context))
return;
- if (const NamespaceDecl *namespace_decl = dyn_cast<NamespaceDecl>(context_decl))
+ const Decl *context_decl = dyn_cast<Decl>(context.m_decl_context);
+
+ if (log)
+ log->Printf("Searching for '%s' in a '%s'", name.GetCString(), context_decl->getDeclKindName());
+
+ Decl *original_decl = NULL;
+ ASTContext *original_ctx = NULL;
+
+ if (!m_parser_vars->GetASTImporter(context.GetASTContext())->ResolveDeclOrigin(context_decl, &original_decl, &original_ctx))
+ break;
+
+ if (TagDecl *original_tag_decl = dyn_cast<TagDecl>(original_decl))
{
- Decl *original_decl = NULL;
- ASTContext *original_ctx = NULL;
+ ExternalASTSource *external_source = original_ctx->getExternalSource();
- if (log)
- log->Printf("Resolving the containing context's origin...");
-
- if (!m_parser_vars->GetASTImporter(context.GetASTContext())->ResolveDeclOrigin(namespace_decl, &original_decl, &original_ctx))
+ if (!external_source)
break;
-
- if (log)
- log->Printf("Casting it to a DeclContext...");
-
- DeclContext *original_decl_context = dyn_cast<DeclContext>(original_decl);
-
- if (!original_decl_context)
- break;
-
- if (log)
- {
- std::string s;
- llvm::raw_string_ostream os(s);
- original_decl->print(os);
- os.flush();
-
- log->Printf("Containing context:");
- log->Printf("%s", s.c_str());
- }
-
- if (!original_ctx->getExternalSource())
- break;
-
- DeclContextLookupConstResult original_lookup_result = original_ctx->getExternalSource()->FindExternalVisibleDeclsByName(original_decl_context, context.m_decl_name);
- NamedDecl *const *iter = NULL;
+ if (!original_tag_decl)
+ break;
- for (iter = original_lookup_result.first;
- iter != original_lookup_result.second;
- ++iter)
- {
- clang::NamedDecl *copied_result = dyn_cast<NamedDecl>(m_parser_vars->GetASTImporter(context.GetASTContext())->CopyDecl(original_ctx, *iter));
+ external_source->CompleteType (original_tag_decl);
+ }
+
+ DeclContext *original_decl_context = dyn_cast<DeclContext>(original_decl);
+
+ if (!original_decl_context)
+ break;
- if (copied_result)
- context.AddNamedDecl(copied_result);
+ for (TagDecl::decl_iterator iter = original_decl_context->decls_begin();
+ iter != original_decl_context->decls_end();
+ ++iter)
+ {
+ NamedDecl *named_decl = dyn_cast<NamedDecl>(*iter);
+
+ if (named_decl && named_decl->getName().equals(name.GetCString()))
+ {
+ Decl *copied_decl = m_parser_vars->GetASTImporter(context.GetASTContext())->CopyDecl(original_ctx, named_decl);
+ NamedDecl *copied_named_decl = dyn_cast<NamedDecl>(copied_decl);
+
+ if (!copied_named_decl)
+ continue;
+
+ context.AddNamedDecl (copied_named_decl);
}
}
+
+ return;
}
while (0);
@@ -1824,7 +1820,7 @@
log->Printf("%s", s.c_str());
}
- clang::NamespaceDecl *clang_namespace_decl = AddNamespace(context, namespace_decl);
+ NamespaceDecl *clang_namespace_decl = AddNamespace(context, namespace_decl);
if (clang_namespace_decl)
clang_namespace_decl->setHasExternalLexicalStorage();
}
@@ -1976,44 +1972,103 @@
}
}
-const clang::DeclContext *
-ClangExpressionDeclMap::CompleteDeclContext (clang::ASTContext *ast_context,
- const clang::DeclContext *decl_context)
+clang::ExternalLoadResult
+ClangExpressionDeclMap::FindExternalLexicalDecls (const DeclContext *decl_context,
+ bool (*predicate)(Decl::Kind),
+ llvm::SmallVectorImpl<Decl*> &decls)
{
- lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
-
- if (log)
- {
- const NamedDecl *named_decl = dyn_cast<NamedDecl>(decl_context);
-
- if (named_decl)
- log->Printf("Completing a '%s' DeclContext named '%s'", decl_context->getDeclKindName(), named_decl->getDeclName().getAsString().c_str());
- else
- log->Printf("Completing a '%s' DeclContext", decl_context->getDeclKindName());
- }
-
assert (m_parser_vars.get());
- if (!m_parser_vars->GetASTImporter (ast_context)->CompleteDeclContext(decl_context))
- return NULL;
+ lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
+
+ const Decl *context_decl = dyn_cast<Decl>(decl_context);
+
+ if (!context_decl)
+ return ELR_Failure;
+
+ ASTContext *ast_context = &context_decl->getASTContext();
+
+ if (log)
+ log->Printf("Finding lexical decls in a '%s' with %s predicate", context_decl->getDeclKindName(), (predicate ? "non-null" : "null"));
+
+ Decl *original_decl = NULL;
+ ASTContext *original_ctx = NULL;
+
+ ClangASTImporter *ast_importer = m_parser_vars->GetASTImporter(ast_context);
+
+ if (!ast_importer)
+ return ELR_Failure;
+
+ if (!ast_importer->ResolveDeclOrigin(context_decl, &original_decl, &original_ctx))
+ return ELR_Failure;
if (log)
{
- const Decl *decl = dyn_cast<Decl>(decl_context);
+ std::string decl_print_string;
+ llvm::raw_string_ostream decl_print_stream(decl_print_string);
+ original_decl->print(decl_print_stream);
+ decl_print_stream.flush();
+ log->Printf("Original decl:\n%s", decl_print_string.c_str());
+ }
+
+ if (TagDecl *original_tag_decl = dyn_cast<TagDecl>(original_decl))
+ {
+ ExternalASTSource *external_source = original_ctx->getExternalSource();
- if (decl)
+ if (!external_source)
+ return ELR_Failure;
+
+ if (!original_tag_decl)
+ return ELR_Failure;
+
+ external_source->CompleteType (original_tag_decl);
+ }
+
+ DeclContext *original_decl_context = dyn_cast<DeclContext>(original_decl);
+
+ if (!original_decl_context)
+ return ELR_Failure;
+
+ for (TagDecl::decl_iterator iter = original_decl_context->decls_begin();
+ iter != original_decl_context->decls_end();
+ ++iter)
+ {
+ Decl *decl = *iter;
+
+ if (!predicate || predicate(decl->getKind()))
{
- std::string s;
- llvm::raw_string_ostream os(s);
- decl->print(os);
- os.flush();
+ if (log)
+ {
+ std::string decl_print_string;
+ llvm::raw_string_ostream decl_print_stream(decl_print_string);
+ decl->print(decl_print_stream);
+ decl_print_stream.flush();
+ log->Printf(" Adding lexical decl %s", decl_print_string.c_str());
+ }
+
+ Decl *copied_decl = ast_importer->CopyDecl(original_ctx, decl);
- log->Printf("After:");
- log->Printf("%s", s.c_str());
+ decls.push_back(copied_decl);
}
}
- return decl_context;
+ return ELR_AlreadyLoaded;
+}
+
+void
+ClangExpressionDeclMap::CompleteTagDecl (TagDecl *tag_decl)
+{
+ assert (m_parser_vars.get());
+
+ m_parser_vars->GetASTImporter(&tag_decl->getASTContext())->CompleteTagDecl (tag_decl);
+}
+
+void
+ClangExpressionDeclMap::CompleteObjCInterfaceDecl (clang::ObjCInterfaceDecl *interface_decl)
+{
+ assert (m_parser_vars.get());
+
+ m_parser_vars->GetASTImporter(&interface_decl->getASTContext())->CompleteObjCInterfaceDecl (interface_decl);
}
Value *
@@ -2021,7 +2076,7 @@
(
ExecutionContext &exe_ctx,
VariableSP var,
- clang::ASTContext *parser_ast_context,
+ ASTContext *parser_ast_context,
TypeFromUser *user_type,
TypeFromParser *parser_type
)
@@ -2046,7 +2101,7 @@
return NULL;
}
- clang::ASTContext *ast = var_type->GetClangASTContext().getASTContext();
+ ASTContext *ast = var_type->GetClangASTContext().getASTContext();
if (!ast)
{
@@ -2170,12 +2225,12 @@
log->Printf("Found variable %s, returned %s", decl_name.c_str(), var_decl_print_string.c_str());
- if (log->GetVerbose())
- {
- StreamString var_decl_dump_string;
- ASTDumper::DumpDecl(var_decl_dump_string, var_decl);
- log->Printf("%s\n", var_decl_dump_string.GetData());
- }
+ //if (log->GetVerbose())
+ //{
+ // StreamString var_decl_dump_string;
+ // ASTDumper::DumpDecl(var_decl_dump_string, var_decl);
+ // log->Printf("%s\n", var_decl_dump_string.GetData());
+ //}
}
}
@@ -2219,7 +2274,7 @@
lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
- clang::ASTContext *scratch_ast_context = m_parser_vars->m_exe_ctx->target->GetScratchClangASTContext()->getASTContext();
+ ASTContext *scratch_ast_context = m_parser_vars->m_exe_ctx->target->GetScratchClangASTContext()->getASTContext();
TypeFromUser user_type (ClangASTContext::CreateLValueReferenceType(scratch_ast_context, ClangASTContext::GetVoidPtrType(scratch_ast_context, true)),
scratch_ast_context);
@@ -2265,12 +2320,12 @@
log->Printf("Found variable %s, returned %s", decl_name.c_str(), var_decl_print_string.c_str());
- if (log->GetVerbose())
- {
- StreamString var_decl_dump_string;
- ASTDumper::DumpDecl(var_decl_dump_string, var_decl);
- log->Printf("%s\n", var_decl_dump_string.GetData());
- }
+ //if (log->GetVerbose())
+ //{
+ // StreamString var_decl_dump_string;
+ // ASTDumper::DumpDecl(var_decl_dump_string, var_decl);
+ // log->Printf("%s\n", var_decl_dump_string.GetData());
+ //}
}
}
@@ -2279,7 +2334,7 @@
{
lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
- clang::ASTContext *scratch_ast_context = m_parser_vars->m_exe_ctx->target->GetScratchClangASTContext()->getASTContext();
+ ASTContext *scratch_ast_context = m_parser_vars->m_exe_ctx->target->GetScratchClangASTContext()->getASTContext();
for (size_t index = 0, num_entities = m_found_entities.GetSize();
index < num_entities;
@@ -2374,17 +2429,17 @@
}
}
-clang::NamespaceDecl *
+NamespaceDecl *
ClangExpressionDeclMap::AddNamespace (NameSearchContext &context, const ClangNamespaceDecl &namespace_decl)
{
lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
assert (m_parser_vars.get());
- clang::Decl *copied_decl = m_parser_vars->GetASTImporter(context.GetASTContext())->CopyDecl(namespace_decl.GetASTContext(),
+ Decl *copied_decl = m_parser_vars->GetASTImporter(context.GetASTContext())->CopyDecl(namespace_decl.GetASTContext(),
namespace_decl.GetNamespaceDecl());
- return dyn_cast<clang::NamespaceDecl>(copied_decl);
+ return dyn_cast<NamespaceDecl>(copied_decl);
}
void
@@ -2402,7 +2457,7 @@
// only valid for Functions, not for Symbols
void *fun_opaque_type = NULL;
- clang::ASTContext *fun_ast_context = NULL;
+ ASTContext *fun_ast_context = NULL;
if (fun)
{
@@ -2478,8 +2533,8 @@
TypeFromUser &ut,
bool add_method)
{
- clang::ASTContext *parser_ast_context = context.GetASTContext();
- clang::ASTContext *user_ast_context = ut.GetASTContext();
+ ASTContext *parser_ast_context = context.GetASTContext();
+ ASTContext *user_ast_context = ut.GetASTContext();
void *copied_type = GuardedCopyType(parser_ast_context, user_ast_context, ut.GetOpaqueQualType());