[Lldb-commits] [lldb] r141765 - in /lldb/trunk: include/lldb/Expression/ClangExpressionDeclMap.h source/Expression/ClangExpressionDeclMap.cpp
Sean Callanan
scallanan at apple.com
Tue Oct 11 18:39:28 PDT 2011
Author: spyffe
Date: Tue Oct 11 20:39:28 2011
New Revision: 141765
URL: http://llvm.org/viewvc/llvm-project?rev=141765&view=rev
Log:
Cleanups in preparation for making FindExternalVisibleDecls
look in individual modules rather than globally.
Also some whitespace fixes.
Modified:
lldb/trunk/include/lldb/Expression/ClangExpressionDeclMap.h
lldb/trunk/source/Expression/ClangExpressionDeclMap.cpp
Modified: lldb/trunk/include/lldb/Expression/ClangExpressionDeclMap.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Expression/ClangExpressionDeclMap.h?rev=141765&r1=141764&r2=141765&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Expression/ClangExpressionDeclMap.h (original)
+++ lldb/trunk/include/lldb/Expression/ClangExpressionDeclMap.h Tue Oct 11 20:39:28 2011
@@ -855,7 +855,7 @@
void
FindExternalVisibleDecls (NameSearchContext &context,
lldb::ModuleSP module,
- ClangNamespaceDecl &decl,
+ ClangNamespaceDecl &namespace_decl,
const ConstString &name);
//------------------------------------------------------------------
Modified: lldb/trunk/source/Expression/ClangExpressionDeclMap.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/ClangExpressionDeclMap.cpp?rev=141765&r1=141764&r2=141765&view=diff
==============================================================================
--- lldb/trunk/source/Expression/ClangExpressionDeclMap.cpp (original)
+++ lldb/trunk/source/Expression/ClangExpressionDeclMap.cpp Tue Oct 11 20:39:28 2011
@@ -2119,73 +2119,14 @@
void
ClangExpressionDeclMap::FindExternalVisibleDecls (NameSearchContext &context,
lldb::ModuleSP module,
- ClangNamespaceDecl &decl,
+ ClangNamespaceDecl &namespace_decl,
const ConstString &name)
{
assert (m_struct_vars.get());
assert (m_parser_vars.get());
lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
-
- do
- {
- if (isa<TranslationUnitDecl>(context.m_decl_context))
- break;
-
- if (!isa<NamespaceDecl>(context.m_decl_context))
- return;
-
- 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))
- {
- ExternalASTSource *external_source = original_ctx->getExternalSource();
- if (!external_source)
- break;
-
- if (!original_tag_decl)
- break;
-
- external_source->CompleteType (original_tag_decl);
- }
-
- DeclContext *original_decl_context = dyn_cast<DeclContext>(original_decl);
-
- if (!original_decl_context)
- break;
-
- 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);
-
SymbolContextList sc_list;
const char *name_unique_cstr = name.GetCString();
@@ -2197,161 +2138,7 @@
// doesn't start with our phony prefix of '$'
Target *target = m_parser_vars->m_exe_ctx->GetTargetPtr();
StackFrame *frame = m_parser_vars->m_exe_ctx->GetFramePtr();
- if (name_unique_cstr[0] != '$')
- {
- ValueObjectSP valobj;
- VariableSP var;
- Error err;
- bool found = false;
-
- if (frame)
- {
- valobj = frame->GetValueForVariableExpressionPath(name_unique_cstr,
- eNoDynamicValues,
- StackFrame::eExpressionPathOptionCheckPtrVsMember,
- var,
- err);
-
- // If we found a variable in scope, no need to pull up function names
- if (err.Success() && var != NULL)
- {
- AddOneVariable(context, var);
- found = true;
- }
- }
- else if (target)
- {
- var = FindGlobalVariable (*target,
- name_unique_cstr,
- NULL);
-
- if (var)
- {
- AddOneVariable(context, var);
- found = true;
- }
- }
-
- if (!found)
- {
- const bool include_symbols = true;
- const bool append = false;
- m_parser_vars->m_sym_ctx.FindFunctionsByName (name,
- eFunctionNameTypeBase,
- include_symbols,
- append,
- sc_list);
-
- if (sc_list.GetSize())
- {
- bool found_specific = false;
- Symbol *generic_symbol = NULL;
- Symbol *non_extern_symbol = NULL;
-
- for (uint32_t index = 0, num_indices = sc_list.GetSize();
- index < num_indices;
- ++index)
- {
- SymbolContext sym_ctx;
- sc_list.GetContextAtIndex(index, sym_ctx);
-
- if (sym_ctx.function)
- {
- // TODO only do this if it's a C function; C++ functions may be
- // overloaded
- if (!found_specific)
- AddOneFunction(context, sym_ctx.function, NULL);
- found_specific = true;
- found = true;
- }
- else if (sym_ctx.symbol)
- {
- if (sym_ctx.symbol->IsExternal())
- generic_symbol = sym_ctx.symbol;
- else
- non_extern_symbol = sym_ctx.symbol;
- }
- }
-
- if (!found_specific)
- {
- if (generic_symbol)
- {
- AddOneFunction (context, NULL, generic_symbol);
- found = true;
- }
- else if (non_extern_symbol)
- {
- AddOneFunction (context, NULL, non_extern_symbol);
- found = true;
- }
- }
- }
-
- if (!found)
- {
- // We couldn't find a variable or function for this. Now we'll hunt for a generic
- // data symbol, and -- if it is found -- treat it as a variable.
-
- Symbol *data_symbol = FindGlobalDataSymbol(*target, name);
-
- if (data_symbol)
- {
- AddOneGenericVariable(context, *data_symbol);
- found = true;
- }
- }
- }
-
- ModuleList &images = m_parser_vars->m_sym_ctx.target_sp->GetImages();
-
- ClangASTImporter::NamespaceMapSP namespace_decls(new ClangASTImporter::NamespaceMap);
-
- for (uint32_t i = 0, e = images.GetSize();
- i != e;
- ++i)
- {
- ModuleSP image = images.GetModuleAtIndex(i);
-
- if (!image)
- continue;
-
- ClangNamespaceDecl namespace_decl;
-
- SymbolVendor *symbol_vendor = image->GetSymbolVendor();
-
- if (!symbol_vendor)
- continue;
-
- SymbolContext null_sc;
-
- namespace_decl = symbol_vendor->FindNamespace(null_sc, name);
-
- if (namespace_decl)
- {
- (*namespace_decls)[image] = namespace_decl;
-
- if (log)
- {
- std::string s;
- llvm::raw_string_ostream os(s);
- namespace_decl.GetNamespaceDecl()->print(os);
- os.flush();
-
- log->Printf("Found namespace %s in file %s", s.c_str(), image->GetFileSpec().GetFilename().GetCString());
- }
- }
- }
-
- if (!namespace_decls->empty())
- {
- NamespaceDecl *clang_namespace_decl = AddNamespace(context, namespace_decls);
-
- if (clang_namespace_decl)
- clang_namespace_decl->setHasExternalVisibleStorage();
- }
- }
- else
+ if (name_unique_cstr[0] == '$' && !namespace_decl)
{
static ConstString g_lldb_class_name ("$__lldb_class");
@@ -2386,7 +2173,7 @@
this_type->Dump(&strm, true);
log->PutCString (strm.GetData());
}
-
+
TypeFromUser this_user_type(this_type->GetClangFullType(),
this_type->GetClangAST());
@@ -2405,7 +2192,7 @@
TypeFromUser class_user_type(pointer_target_qual_type.getAsOpaquePtr(),
this_type->GetClangAST());
-
+
if (log)
{
StreamString type_stream;
@@ -2428,34 +2215,34 @@
return;
VariableList *vars = frame->GetVariableList(false);
-
+
if (!vars)
return;
-
+
lldb::VariableSP self_var = vars->FindVariable(ConstString("self"));
-
+
if (!self_var ||
!self_var->IsInScope(frame) ||
!self_var->LocationIsValidForFrame (frame))
return;
-
+
Type *self_type = self_var->GetType();
if (!self_type)
return;
-
+
TypeFromUser self_user_type(self_type->GetClangFullType(),
self_type->GetClangAST());
m_struct_vars->m_object_pointer_type = self_user_type;
-
+
void *pointer_target_type = NULL;
-
+
if (!ClangASTContext::IsPointerType(self_user_type.GetOpaqueQualType(),
&pointer_target_type)
|| pointer_target_type == NULL)
return;
-
+
TypeFromUser class_user_type(pointer_target_type,
self_type->GetClangAST());
@@ -2475,7 +2262,7 @@
// any other $__lldb names should be weeded out now
if (!::strncmp(name_unique_cstr, "$__lldb", sizeof("$__lldb") - 1))
return;
-
+
do
{
if (!target)
@@ -2492,7 +2279,7 @@
break;
TypeDecl *ptype_type_decl = m_parser_vars->m_persistent_vars->GetPersistentType(name);
-
+
if (!ptype_type_decl)
break;
@@ -2513,7 +2300,7 @@
} while (0);
ClangExpressionVariableSP pvar_sp(m_parser_vars->m_persistent_vars->GetVariable(name));
-
+
if (pvar_sp)
{
AddOneVariable(context, pvar_sp);
@@ -2530,6 +2317,160 @@
AddOneRegister(context, reg_info);
}
}
+ else
+ {
+ ValueObjectSP valobj;
+ VariableSP var;
+ Error err;
+ bool found = false;
+
+ if (frame && !namespace_decl)
+ {
+ valobj = frame->GetValueForVariableExpressionPath(name_unique_cstr,
+ eNoDynamicValues,
+ StackFrame::eExpressionPathOptionCheckPtrVsMember,
+ var,
+ err);
+
+ // If we found a variable in scope, no need to pull up function names
+ if (err.Success() && var != NULL)
+ {
+ AddOneVariable(context, var);
+ found = true;
+ }
+ }
+ else if (target)
+ {
+ var = FindGlobalVariable (*target,
+ name_unique_cstr,
+ NULL);
+
+ if (var)
+ {
+ AddOneVariable(context, var);
+ found = true;
+ }
+ }
+
+ if (!found)
+ {
+ const bool include_symbols = true;
+ const bool append = false;
+ m_parser_vars->m_sym_ctx.FindFunctionsByName (name,
+ eFunctionNameTypeBase,
+ include_symbols,
+ append,
+ sc_list);
+
+ if (sc_list.GetSize())
+ {
+ bool found_specific = false;
+ Symbol *generic_symbol = NULL;
+ Symbol *non_extern_symbol = NULL;
+
+ for (uint32_t index = 0, num_indices = sc_list.GetSize();
+ index < num_indices;
+ ++index)
+ {
+ SymbolContext sym_ctx;
+ sc_list.GetContextAtIndex(index, sym_ctx);
+
+ if (sym_ctx.function)
+ {
+ // TODO only do this if it's a C function; C++ functions may be
+ // overloaded
+ if (!found_specific)
+ AddOneFunction(context, sym_ctx.function, NULL);
+ found_specific = true;
+ found = true;
+ }
+ else if (sym_ctx.symbol)
+ {
+ if (sym_ctx.symbol->IsExternal())
+ generic_symbol = sym_ctx.symbol;
+ else
+ non_extern_symbol = sym_ctx.symbol;
+ }
+ }
+
+ if (!found_specific)
+ {
+ if (generic_symbol)
+ {
+ AddOneFunction (context, NULL, generic_symbol);
+ found = true;
+ }
+ else if (non_extern_symbol)
+ {
+ AddOneFunction (context, NULL, non_extern_symbol);
+ found = true;
+ }
+ }
+ }
+
+ if (!found)
+ {
+ // We couldn't find a variable or function for this. Now we'll hunt for a generic
+ // data symbol, and -- if it is found -- treat it as a variable.
+
+ Symbol *data_symbol = FindGlobalDataSymbol(*target, name);
+
+ if (data_symbol)
+ {
+ AddOneGenericVariable(context, *data_symbol);
+ found = true;
+ }
+ }
+ }
+
+ ModuleList &images = m_parser_vars->m_sym_ctx.target_sp->GetImages();
+
+ ClangASTImporter::NamespaceMapSP namespace_decls(new ClangASTImporter::NamespaceMap);
+
+ for (uint32_t i = 0, e = images.GetSize();
+ i != e;
+ ++i)
+ {
+ ModuleSP image = images.GetModuleAtIndex(i);
+
+ if (!image)
+ continue;
+
+ ClangNamespaceDecl namespace_decl;
+
+ SymbolVendor *symbol_vendor = image->GetSymbolVendor();
+
+ if (!symbol_vendor)
+ continue;
+
+ SymbolContext null_sc;
+
+ namespace_decl = symbol_vendor->FindNamespace(null_sc, name);
+
+ if (namespace_decl)
+ {
+ (*namespace_decls)[image] = namespace_decl;
+
+ if (log)
+ {
+ std::string s;
+ llvm::raw_string_ostream os(s);
+ namespace_decl.GetNamespaceDecl()->print(os);
+ os.flush();
+
+ log->Printf("Found namespace %s in file %s", s.c_str(), image->GetFileSpec().GetFilename().GetCString());
+ }
+ }
+ }
+
+ if (!namespace_decls->empty())
+ {
+ NamespaceDecl *clang_namespace_decl = AddNamespace(context, namespace_decls);
+
+ if (clang_namespace_decl)
+ clang_namespace_decl->setHasExternalVisibleStorage();
+ }
+ }
lldb::TypeSP type_sp (m_parser_vars->m_sym_ctx.FindTypeByName (name));
More information about the lldb-commits
mailing list