summaryrefslogtreecommitdiffstats
path: root/lldb/source/Expression/ClangExpressionDeclMap.cpp
diff options
context:
space:
mode:
authorSean Callanan <scallanan@apple.com>2011-07-30 02:42:06 +0000
committerSean Callanan <scallanan@apple.com>2011-07-30 02:42:06 +0000
commitcc427fadec4aac05751e30ce42df87d3a4a63037 (patch)
treef766c31ddc18961aaeaa876b2c0525062efb9e7a /lldb/source/Expression/ClangExpressionDeclMap.cpp
parentfc1aa292ad7b8f332356486d461af818706fe1ad (diff)
downloadbcm5719-llvm-cc427fadec4aac05751e30ce42df87d3a4a63037.tar.gz
bcm5719-llvm-cc427fadec4aac05751e30ce42df87d3a4a63037.zip
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. llvm-svn: 136555
Diffstat (limited to 'lldb/source/Expression/ClangExpressionDeclMap.cpp')
-rw-r--r--lldb/source/Expression/ClangExpressionDeclMap.cpp245
1 files changed, 150 insertions, 95 deletions
diff --git a/lldb/source/Expression/ClangExpressionDeclMap.cpp b/lldb/source/Expression/ClangExpressionDeclMap.cpp
index 97e73bd541e..4f21fc054e8 100644
--- a/lldb/source/Expression/ClangExpressionDeclMap.cpp
+++ b/lldb/source/Expression/ClangExpressionDeclMap.cpp
@@ -134,7 +134,7 @@ ClangExpressionDeclMap::BuildIntegerVariable (const ConstString &name,
{
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 @@ ClangExpressionDeclMap::BuildIntegerVariable (const ConstString &name,
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 @@ ClangExpressionDeclMap::BuildCastVariable (const ConstString &name,
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 @@ ClangExpressionDeclMap::BuildCastVariable (const ConstString &name,
bool
ClangExpressionDeclMap::AddPersistentVariable
(
- const clang::NamedDecl *decl,
+ const NamedDecl *decl,
const ConstString &name,
TypeFromParser parser_type,
bool is_result,
@@ -285,7 +285,7 @@ ClangExpressionDeclMap::AddPersistentVariable
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 @@ ClangExpressionDeclMap::AddPersistentVariable
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::GetStructInfo
bool
ClangExpressionDeclMap::GetStructElement
(
- const clang::NamedDecl *&decl,
+ const NamedDecl *&decl,
llvm::Value *&value,
off_t &offset,
ConstString &name,
@@ -472,7 +472,7 @@ ClangExpressionDeclMap::GetStructElement
bool
ClangExpressionDeclMap::GetFunctionInfo
(
- const clang::NamedDecl *decl,
+ const NamedDecl *decl,
llvm::Value**& value,
uint64_t &ptr
)
@@ -915,7 +915,7 @@ ClangExpressionDeclMap::DoMaterialize
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 @@ ClangExpressionDeclMap::GetDecls (NameSearchContext &context, const ConstString
if (isa<TranslationUnitDecl>(context.m_decl_context))
break;
- if (log)
- log->Printf("'%s' is in something other than a translation unit", name.GetCString());
+ if (!isa<NamespaceDecl>(context.m_decl_context))
+ return;
const Decl *context_decl = dyn_cast<Decl>(context.m_decl_context);
-
- if (!context_decl)
- return;
- if (const NamespaceDecl *namespace_decl = dyn_cast<NamespaceDecl>(context_decl))
+ 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;
-
- if (log)
- log->Printf("Resolving the containing context's origin...");
+ ExternalASTSource *external_source = original_ctx->getExternalSource();
- 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)
+
+ if (!original_tag_decl)
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;
+ external_source->CompleteType (original_tag_decl);
+ }
+
+ DeclContext *original_decl_context = dyn_cast<DeclContext>(original_decl);
+
+ if (!original_decl_context)
+ break;
- DeclContextLookupConstResult original_lookup_result = original_ctx->getExternalSource()->FindExternalVisibleDeclsByName(original_decl_context, context.m_decl_name);
-
- NamedDecl *const *iter = NULL;
+ for (TagDecl::decl_iterator iter = original_decl_context->decls_begin();
+ iter != original_decl_context->decls_end();
+ ++iter)
+ {
+ NamedDecl *named_decl = dyn_cast<NamedDecl>(*iter);
- for (iter = original_lookup_result.first;
- iter != original_lookup_result.second;
- ++iter)
+ if (named_decl && named_decl->getName().equals(name.GetCString()))
{
- clang::NamedDecl *copied_result = dyn_cast<NamedDecl>(m_parser_vars->GetASTImporter(context.GetASTContext())->CopyDecl(original_ctx, *iter));
+ 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;
- if (copied_result)
- context.AddNamedDecl(copied_result);
+ context.AddNamedDecl (copied_named_decl);
}
}
+
+ return;
}
while (0);
@@ -1824,7 +1820,7 @@ ClangExpressionDeclMap::GetDecls (NameSearchContext &context, const ConstString
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 @@ ClangExpressionDeclMap::GetDecls (NameSearchContext &context, const ConstString
}
}
-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)
{
+ assert (m_parser_vars.get());
+
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 NamedDecl *named_decl = dyn_cast<NamedDecl>(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 (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());
+ if (!external_source)
+ return ELR_Failure;
+
+ if (!original_tag_decl)
+ return ELR_Failure;
+
+ external_source->CompleteType (original_tag_decl);
}
- assert (m_parser_vars.get());
+ DeclContext *original_decl_context = dyn_cast<DeclContext>(original_decl);
- if (!m_parser_vars->GetASTImporter (ast_context)->CompleteDeclContext(decl_context))
- return NULL;
+ if (!original_decl_context)
+ return ELR_Failure;
- if (log)
+ for (TagDecl::decl_iterator iter = original_decl_context->decls_begin();
+ iter != original_decl_context->decls_end();
+ ++iter)
{
- const Decl *decl = dyn_cast<Decl>(decl_context);
+ Decl *decl = *iter;
- if (decl)
+ 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 @@ ClangExpressionDeclMap::GetVariableValue
(
ExecutionContext &exe_ctx,
VariableSP var,
- clang::ASTContext *parser_ast_context,
+ ASTContext *parser_ast_context,
TypeFromUser *user_type,
TypeFromParser *parser_type
)
@@ -2046,7 +2101,7 @@ ClangExpressionDeclMap::GetVariableValue
return NULL;
}
- clang::ASTContext *ast = var_type->GetClangASTContext().getASTContext();
+ ASTContext *ast = var_type->GetClangASTContext().getASTContext();
if (!ast)
{
@@ -2170,12 +2225,12 @@ ClangExpressionDeclMap::AddOneVariable (NameSearchContext &context, VariableSP v
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 @@ ClangExpressionDeclMap::AddOneGenericVariable(NameSearchContext &context,
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 @@ ClangExpressionDeclMap::AddOneGenericVariable(NameSearchContext &context,
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 @@ ClangExpressionDeclMap::ResolveUnknownTypes()
{
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 @@ ClangExpressionDeclMap::AddOneRegister (NameSearchContext &context,
}
}
-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 @@ ClangExpressionDeclMap::AddOneFunction (NameSearchContext &context,
// 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 @@ ClangExpressionDeclMap::AddOneType(NameSearchContext &context,
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());
OpenPOWER on IntegriCloud