summaryrefslogtreecommitdiffstats
path: root/lldb/source
diff options
context:
space:
mode:
authorSean Callanan <scallanan@apple.com>2011-10-28 23:38:38 +0000
committerSean Callanan <scallanan@apple.com>2011-10-28 23:38:38 +0000
commiteddeb3b96fbba466d8a630757fad063b54ee1f76 (patch)
tree386770e8ddf9cf7f50aaccf97e1a39d8ae6dac01 /lldb/source
parent8763780961ae37b46690e0ee66447847275a0040 (diff)
downloadbcm5719-llvm-eddeb3b96fbba466d8a630757fad063b54ee1f76.tar.gz
bcm5719-llvm-eddeb3b96fbba466d8a630757fad063b54ee1f76.zip
As part of a general refactoring of ClangASTSource to
allow it to complete types on behalf of any AST context (including the "scratch" AST context associated with the target), I scrapped its role as intermediary between the Clang parser and ClangExpressionDeclMap, and instead made ClangExpressionDeclMap inherit from ClangASTSource. After this, I will migrate the functions that complete types and perform namespace lookups from ClangExpressionDeclMap to ClangASTSource. Ultimately ClangExpressionDeclMap's only responsiblity will be to look up variables and ensure that they are materialized and dematerialized correctly. llvm-svn: 143253
Diffstat (limited to 'lldb/source')
-rw-r--r--lldb/source/Expression/ClangASTSource.cpp54
-rw-r--r--lldb/source/Expression/ClangExpressionDeclMap.cpp40
-rw-r--r--lldb/source/Expression/ClangExpressionParser.cpp3
3 files changed, 48 insertions, 49 deletions
diff --git a/lldb/source/Expression/ClangASTSource.cpp b/lldb/source/Expression/ClangASTSource.cpp
index f68e07c6b49..858bdf0737e 100644
--- a/lldb/source/Expression/ClangASTSource.cpp
+++ b/lldb/source/Expression/ClangASTSource.cpp
@@ -25,9 +25,11 @@ ClangASTSource::~ClangASTSource()
void
ClangASTSource::StartTranslationUnit(ASTConsumer *Consumer)
{
- // Tell Sema to ask us when looking into the translation unit's decl.
- m_ast_context.getTranslationUnitDecl()->setHasExternalVisibleStorage();
- m_ast_context.getTranslationUnitDecl()->setHasExternalLexicalStorage();
+ if (!m_ast_context)
+ return;
+
+ m_ast_context->getTranslationUnitDecl()->setHasExternalVisibleStorage();
+ m_ast_context->getTranslationUnitDecl()->setHasExternalLexicalStorage();
}
// The core lookup interface.
@@ -38,7 +40,10 @@ ClangASTSource::FindExternalVisibleDeclsByName
DeclarationName clang_decl_name
)
{
- if (m_decl_map.GetImportInProgress())
+ if (!m_ast_context)
+ return SetNoExternalVisibleDeclsForName(decl_ctx, clang_decl_name);
+
+ if (GetImportInProgress())
return SetNoExternalVisibleDeclsForName(decl_ctx, clang_decl_name);
std::string decl_name (clang_decl_name.getAsString());
@@ -77,13 +82,13 @@ ClangASTSource::FindExternalVisibleDeclsByName
}
- if (!m_decl_map.GetLookupsEnabled())
+ if (!GetLookupsEnabled())
{
// Wait until we see a '$' at the start of a name before we start doing
// any lookups so we can avoid lookup up all of the builtin types.
if (!decl_name.empty() && decl_name[0] == '$')
{
- m_decl_map.SetLookupsEnabled ();
+ SetLookupsEnabled (true);
}
else
{
@@ -105,7 +110,7 @@ ClangASTSource::FindExternalVisibleDeclsByName
// printf("[%5u] FindExternalVisibleDeclsByName() \"%s\"\n", g_depth, uniqued_const_decl_name);
llvm::SmallVector<NamedDecl*, 4> name_decls;
NameSearchContext name_search_context(*this, name_decls, clang_decl_name, decl_ctx);
- m_decl_map.FindExternalVisibleDecls(name_search_context, const_decl_name);
+ FindExternalVisibleDecls(name_search_context);
DeclContext::lookup_result result (SetExternalVisibleDeclsForName (decl_ctx, clang_decl_name, name_decls));
// --g_depth;
m_active_lookups.erase (uniqued_const_decl_name);
@@ -113,25 +118,20 @@ ClangASTSource::FindExternalVisibleDeclsByName
}
void
-ClangASTSource::CompleteType (TagDecl *tag_decl)
+ClangASTSource::FindExternalVisibleDecls (NameSearchContext &context)
{
- m_decl_map.CompleteTagDecl (tag_decl);
}
void
-ClangASTSource::CompleteType (ObjCInterfaceDecl *objc_decl)
+ClangASTSource::CompleteType (TagDecl *tag_decl)
{
- m_decl_map.CompleteObjCInterfaceDecl (objc_decl);
}
-void
-ClangASTSource::MaterializeVisibleDecls(const DeclContext *DC)
+void
+ClangASTSource::CompleteType (ObjCInterfaceDecl *objc_decl)
{
- return;
}
-// This is used to support iterating through an entire lexical context,
-// which isn't something the debugger should ever need to do.
clang::ExternalLoadResult
ClangASTSource::FindExternalLexicalDecls
(
@@ -140,13 +140,7 @@ ClangASTSource::FindExternalLexicalDecls
llvm::SmallVectorImpl<Decl*> &Decls
)
{
- return m_decl_map.FindExternalLexicalDecls (DC, isKindWeWant, Decls);
-}
-
-clang::ASTContext *
-NameSearchContext::GetASTContext()
-{
- return &m_ast_source.m_ast_context;
+ return ELR_Success;
}
clang::NamedDecl *
@@ -156,7 +150,7 @@ NameSearchContext::AddVarDecl(void *type)
assert (type && "Type for variable must be non-NULL!");
- clang::NamedDecl *Decl = VarDecl::Create(m_ast_source.m_ast_context,
+ clang::NamedDecl *Decl = VarDecl::Create(*m_ast_source.m_ast_context,
const_cast<DeclContext*>(m_decl_context),
SourceLocation(),
SourceLocation(),
@@ -173,7 +167,7 @@ NameSearchContext::AddVarDecl(void *type)
clang::NamedDecl *
NameSearchContext::AddFunDecl (void *type)
{
- clang::FunctionDecl *func_decl = FunctionDecl::Create (m_ast_source.m_ast_context,
+ clang::FunctionDecl *func_decl = FunctionDecl::Create (*m_ast_source.m_ast_context,
const_cast<DeclContext*>(m_decl_context),
SourceLocation(),
SourceLocation(),
@@ -203,7 +197,7 @@ NameSearchContext::AddFunDecl (void *type)
{
QualType arg_qual_type (func_proto_type->getArgType(ArgIndex));
- parm_var_decls.push_back(ParmVarDecl::Create (m_ast_source.m_ast_context,
+ parm_var_decls.push_back(ParmVarDecl::Create (*m_ast_source.m_ast_context,
const_cast<DeclContext*>(m_decl_context),
SourceLocation(),
SourceLocation(),
@@ -230,10 +224,10 @@ NameSearchContext::AddGenericFunDecl()
proto_info.Variadic = true;
- QualType generic_function_type(m_ast_source.m_ast_context.getFunctionType (m_ast_source.m_ast_context.UnknownAnyTy, // result
- NULL, // argument types
- 0, // number of arguments
- proto_info));
+ QualType generic_function_type(m_ast_source.m_ast_context->getFunctionType (m_ast_source.m_ast_context->UnknownAnyTy, // result
+ NULL, // argument types
+ 0, // number of arguments
+ proto_info));
return AddFunDecl(generic_function_type.getAsOpaquePtr());
}
diff --git a/lldb/source/Expression/ClangExpressionDeclMap.cpp b/lldb/source/Expression/ClangExpressionDeclMap.cpp
index 6a15b9fc3fb..6c85831bff0 100644
--- a/lldb/source/Expression/ClangExpressionDeclMap.cpp
+++ b/lldb/source/Expression/ClangExpressionDeclMap.cpp
@@ -2228,8 +2228,12 @@ ClangExpressionDeclMap::CompleteNamespaceMap (ClangASTImporter::NamespaceMapSP &
// Interface for ClangASTSource
void
-ClangExpressionDeclMap::FindExternalVisibleDecls (NameSearchContext &context, const ConstString &name)
+ClangExpressionDeclMap::FindExternalVisibleDecls (NameSearchContext &context)
{
+ assert (m_ast_context);
+
+ const ConstString name(context.m_decl_name.getAsString().c_str());
+
lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
if (m_parser_vars->m_ignore_lookups)
@@ -2256,7 +2260,7 @@ ClangExpressionDeclMap::FindExternalVisibleDecls (NameSearchContext &context, co
if (const NamespaceDecl *namespace_context = dyn_cast<NamespaceDecl>(context.m_decl_context))
{
- ClangASTImporter::NamespaceMapSP namespace_map = m_parser_vars->GetASTImporter(context.GetASTContext())->GetNamespaceMap(namespace_context);
+ ClangASTImporter::NamespaceMapSP namespace_map = m_parser_vars->GetASTImporter(m_ast_context)->GetNamespaceMap(namespace_context);
if (log && log->GetVerbose())
log->Printf(" FEVD[%u] Inspecting namespace map %p (%d entries)",
@@ -2327,6 +2331,7 @@ ClangExpressionDeclMap::FindExternalVisibleDecls (NameSearchContext &context,
{
assert (m_struct_vars.get());
assert (m_parser_vars.get());
+ assert (m_ast_context);
lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
@@ -2482,7 +2487,7 @@ ClangExpressionDeclMap::FindExternalVisibleDecls (NameSearchContext &context,
if (!ptype_type_decl)
break;
- Decl *parser_ptype_decl = ClangASTContext::CopyDecl(context.GetASTContext(), scratch_ast_context, ptype_type_decl);
+ Decl *parser_ptype_decl = ClangASTContext::CopyDecl(m_ast_context, scratch_ast_context, ptype_type_decl);
if (!parser_ptype_decl)
break;
@@ -2834,7 +2839,7 @@ ClangExpressionDeclMap::FindExternalLexicalDecls (const DeclContext *decl_contex
}
void
-ClangExpressionDeclMap::CompleteTagDecl (TagDecl *tag_decl)
+ClangExpressionDeclMap::CompleteType (TagDecl *tag_decl)
{
assert (m_parser_vars.get());
@@ -2859,7 +2864,7 @@ ClangExpressionDeclMap::CompleteTagDecl (TagDecl *tag_decl)
}
void
-ClangExpressionDeclMap::CompleteObjCInterfaceDecl (clang::ObjCInterfaceDecl *interface_decl)
+ClangExpressionDeclMap::CompleteType (clang::ObjCInterfaceDecl *interface_decl)
{
assert (m_parser_vars.get());
@@ -2877,7 +2882,6 @@ ClangExpressionDeclMap::CompleteObjCInterfaceDecl (clang::ObjCInterfaceDecl *int
if (log)
{
- log->Printf(" [CompleteObjCInterfaceDecl] Completing an ObjCInterfaceDecl named %s", interface_decl->getName().str().c_str());
log->Printf(" [COID] After:");
ASTDumper dumper((Decl*)interface_decl);
dumper.ToLog(log, " [COID] ");
@@ -3011,7 +3015,7 @@ ClangExpressionDeclMap::AddOneVariable (NameSearchContext &context, VariableSP v
Value *var_location = GetVariableValue (*m_parser_vars->m_exe_ctx,
var,
- context.GetASTContext(),
+ m_ast_context,
&ut,
&pt);
@@ -3061,10 +3065,10 @@ ClangExpressionDeclMap::AddOneVariable(NameSearchContext &context,
TypeFromUser user_type (pvar_sp->GetTypeFromUser());
- TypeFromParser parser_type (GuardedCopyType(context.GetASTContext(),
+ TypeFromParser parser_type (GuardedCopyType(m_ast_context,
user_type.GetASTContext(),
user_type.GetOpaqueQualType()),
- context.GetASTContext());
+ m_ast_context);
NamedDecl *var_decl = context.AddVarDecl(ClangASTContext::CreateLValueReferenceType(parser_type.GetASTContext(), parser_type.GetOpaqueQualType()));
@@ -3100,8 +3104,8 @@ ClangExpressionDeclMap::AddOneGenericVariable(NameSearchContext &context,
TypeFromUser user_type (ClangASTContext::CreateLValueReferenceType(scratch_ast_context, ClangASTContext::GetVoidPtrType(scratch_ast_context, true)),
scratch_ast_context);
- TypeFromParser parser_type (ClangASTContext::CreateLValueReferenceType(scratch_ast_context, ClangASTContext::GetVoidPtrType(context.GetASTContext(), true)),
- context.GetASTContext());
+ TypeFromParser parser_type (ClangASTContext::CreateLValueReferenceType(scratch_ast_context, ClangASTContext::GetVoidPtrType(m_ast_context, true)),
+ m_ast_context);
NamedDecl *var_decl = context.AddVarDecl(parser_type.GetOpaqueQualType());
@@ -3199,7 +3203,7 @@ ClangExpressionDeclMap::AddOneRegister (NameSearchContext &context,
{
lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
- void *ast_type = ClangASTContext::GetBuiltinTypeForEncodingAndBitSize(context.GetASTContext(),
+ void *ast_type = ClangASTContext::GetBuiltinTypeForEncodingAndBitSize(m_ast_context,
reg_info->encoding,
reg_info->byte_size * 8);
@@ -3211,7 +3215,7 @@ ClangExpressionDeclMap::AddOneRegister (NameSearchContext &context,
}
TypeFromParser parser_type (ast_type,
- context.GetASTContext());
+ m_ast_context);
NamedDecl *var_decl = context.AddVarDecl(parser_type.GetOpaqueQualType());
@@ -3247,12 +3251,12 @@ ClangExpressionDeclMap::AddNamespace (NameSearchContext &context, ClangASTImport
const ClangNamespaceDecl &namespace_decl = namespace_decls->begin()->second;
- Decl *copied_decl = m_parser_vars->GetASTImporter(context.GetASTContext())->CopyDecl(namespace_decl.GetASTContext(),
- namespace_decl.GetNamespaceDecl());
+ Decl *copied_decl = m_parser_vars->GetASTImporter(m_ast_context)->CopyDecl(namespace_decl.GetASTContext(),
+ namespace_decl.GetNamespaceDecl());
NamespaceDecl *copied_namespace_decl = dyn_cast<NamespaceDecl>(copied_decl);
- m_parser_vars->GetASTImporter(context.GetASTContext())->RegisterNamespaceMap(copied_namespace_decl, namespace_decls);
+ m_parser_vars->GetASTImporter(m_ast_context)->RegisterNamespaceMap(copied_namespace_decl, namespace_decls);
return dyn_cast<NamespaceDecl>(copied_decl);
}
@@ -3298,7 +3302,7 @@ ClangExpressionDeclMap::AddOneFunction (NameSearchContext &context,
fun_address = &fun->GetAddressRange().GetBaseAddress();
fun_ast_context = fun_type->GetClangASTContext().getASTContext();
- void *copied_type = GuardedCopyType(context.GetASTContext(), fun_ast_context, fun_opaque_type);
+ void *copied_type = GuardedCopyType(m_ast_context, fun_ast_context, fun_opaque_type);
if (copied_type)
{
fun_decl = context.AddFunDecl(copied_type);
@@ -3365,7 +3369,7 @@ ClangExpressionDeclMap::AddOneType(NameSearchContext &context,
unsigned int current_id,
bool add_method)
{
- ASTContext *parser_ast_context = context.GetASTContext();
+ ASTContext *parser_ast_context = m_ast_context;
ASTContext *user_ast_context = ut.GetASTContext();
void *copied_type = GuardedCopyType(parser_ast_context, user_ast_context, ut.GetOpaqueQualType());
diff --git a/lldb/source/Expression/ClangExpressionParser.cpp b/lldb/source/Expression/ClangExpressionParser.cpp
index e49142687d4..50518e78e73 100644
--- a/lldb/source/Expression/ClangExpressionParser.cpp
+++ b/lldb/source/Expression/ClangExpressionParser.cpp
@@ -320,7 +320,8 @@ ClangExpressionParser::ClangExpressionParser (ExecutionContextScope *exe_scope,
if (decl_map)
{
- OwningPtr<clang::ExternalASTSource> ast_source(new ClangASTSource(*ast_context, *decl_map));
+ llvm::OwningPtr<clang::ExternalASTSource> ast_source(decl_map->CreateProxy());
+ decl_map->InstallASTContext(ast_context.get());
ast_context->setExternalSource(ast_source);
}
OpenPOWER on IntegriCloud