diff options
-rw-r--r-- | lldb/include/lldb/Expression/ClangASTSource.h | 7 | ||||
-rw-r--r-- | lldb/include/lldb/Expression/ClangExpressionDeclMap.h | 43 | ||||
-rw-r--r-- | lldb/source/Expression/ClangASTSource.cpp | 153 | ||||
-rw-r--r-- | lldb/source/Expression/ClangExpressionDeclMap.cpp | 159 |
4 files changed, 146 insertions, 216 deletions
diff --git a/lldb/include/lldb/Expression/ClangASTSource.h b/lldb/include/lldb/Expression/ClangASTSource.h index 7c883377d0d..847fab35b19 100644 --- a/lldb/include/lldb/Expression/ClangASTSource.h +++ b/lldb/include/lldb/Expression/ClangASTSource.h @@ -120,7 +120,7 @@ public: /// @param[in] Decls /// A vector that is filled in with matching Decls. //------------------------------------------------------------------ - virtual clang::ExternalLoadResult + clang::ExternalLoadResult FindExternalLexicalDecls (const clang::DeclContext *DC, bool (*isKindWeWant)(clang::Decl::Kind), llvm::SmallVectorImpl<clang::Decl*> &Decls); @@ -157,7 +157,6 @@ public: // APIs for NamespaceMapCompleter // - //------------------------------------------------------------------ /// Look up the modules containing a given namespace and put the /// appropriate entries in the namespace map. @@ -180,6 +179,10 @@ public: // Helper APIs // + clang::NamespaceDecl * + AddNamespace (NameSearchContext &context, + ClangASTImporter::NamespaceMapSP &namespace_decls); + //------------------------------------------------------------------ /// The worker function for FindExternalVisibleDeclsByName. /// diff --git a/lldb/include/lldb/Expression/ClangExpressionDeclMap.h b/lldb/include/lldb/Expression/ClangExpressionDeclMap.h index 22ff0d6acd8..7ce9851c1e4 100644 --- a/lldb/include/lldb/Expression/ClangExpressionDeclMap.h +++ b/lldb/include/lldb/Expression/ClangExpressionDeclMap.h @@ -117,10 +117,6 @@ public: //------------------------------------------------------------------ const ConstString & GetPersistentResultName (); - - clang::NamespaceDecl * - AddNamespace (NameSearchContext &context, - ClangASTImporter::NamespaceMapSP &namespace_decls); //------------------------------------------------------------------ /// [Used by IRForTarget] Get a constant variable given a name, @@ -625,45 +621,6 @@ public: //------------------------------------------------------------------ void FindExternalVisibleDecls (NameSearchContext &context); - - //------------------------------------------------------------------ - /// [Used by ClangASTSource] Find all Decls in a context that match - /// a given criterion. - /// - /// @param[in] decl_context - /// The DeclContext to search. - /// - /// @param[in] predicate - /// Returns True if a DeclKind is desired; False if not. - /// - /// @param[in] decls - /// A list to add all found Decls that have a desired DeclKind - /// into. - //------------------------------------------------------------------ - clang::ExternalLoadResult - FindExternalLexicalDecls (const clang::DeclContext *decl_context, - bool (*predicate)(clang::Decl::Kind), - llvm::SmallVectorImpl<clang::Decl*> &decls); - - //------------------------------------------------------------------ - /// [Used by ClangASTSource] Complete the definition of a TagDecl. - /// - /// @param[in] tag_decl - /// The TagDecl to be completed. - //------------------------------------------------------------------ - void - CompleteType (clang::TagDecl *tag_decl); - - //------------------------------------------------------------------ - /// [Used by ClangASTSource] Complete the definition of an - /// ObjCInterfaceDecl. - /// - /// @param[in] tag_decl - /// The ObjCInterfaceDecl to be completed. - //------------------------------------------------------------------ - void - CompleteType (clang::ObjCInterfaceDecl *interface_decl); - private: ClangExpressionVariableList m_found_entities; ///< All entities that were looked up for the parser. ClangExpressionVariableList m_struct_members; ///< All entities that need to be placed in the struct. diff --git a/lldb/source/Expression/ClangASTSource.cpp b/lldb/source/Expression/ClangASTSource.cpp index 7ed5a5abcb6..1f9bf6b2936 100644 --- a/lldb/source/Expression/ClangASTSource.cpp +++ b/lldb/source/Expression/ClangASTSource.cpp @@ -12,9 +12,9 @@ #include "lldb/Core/Log.h" #include "lldb/Core/Module.h" #include "lldb/Core/ModuleList.h" +#include "lldb/Expression/ASTDumper.h" #include "lldb/Expression/ClangASTSource.h" #include "lldb/Expression/ClangExpression.h" -#include "lldb/Expression/ClangExpressionDeclMap.h" #include "lldb/Symbol/ClangNamespaceDecl.h" #include "lldb/Symbol/SymbolVendor.h" #include "lldb/Target/Target.h" @@ -128,23 +128,133 @@ ClangASTSource::FindExternalVisibleDecls (NameSearchContext &context) void ClangASTSource::CompleteType (TagDecl *tag_decl) -{ +{ + lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS)); + + if (log) + { + log->Printf(" [CompleteTagDecl] Completing a TagDecl named %s", tag_decl->getName().str().c_str()); + log->Printf(" [CTD] Before:"); + ASTDumper dumper((Decl*)tag_decl); + dumper.ToLog(log, " [CTD] "); + } + + m_ast_importer->CompleteTagDecl (tag_decl); + + if (log) + { + log->Printf(" [CTD] After:"); + ASTDumper dumper((Decl*)tag_decl); + dumper.ToLog(log, " [CTD] "); + } } void -ClangASTSource::CompleteType (ObjCInterfaceDecl *objc_decl) -{ +ClangASTSource::CompleteType (clang::ObjCInterfaceDecl *interface_decl) +{ + lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS)); + + if (log) + { + log->Printf(" [CompleteObjCInterfaceDecl] Completing an ObjCInterfaceDecl named %s", interface_decl->getName().str().c_str()); + log->Printf(" [COID] Before:"); + ASTDumper dumper((Decl*)interface_decl); + dumper.ToLog(log, " [COID] "); + } + + m_ast_importer->CompleteObjCInterfaceDecl (interface_decl); + + if (log) + { + log->Printf(" [COID] After:"); + ASTDumper dumper((Decl*)interface_decl); + dumper.ToLog(log, " [COID] "); + } } clang::ExternalLoadResult -ClangASTSource::FindExternalLexicalDecls -( - const DeclContext *DC, - bool (*isKindWeWant)(Decl::Kind), - llvm::SmallVectorImpl<Decl*> &Decls -) -{ - return ELR_Success; +ClangASTSource::FindExternalLexicalDecls (const DeclContext *decl_context, + bool (*predicate)(Decl::Kind), + llvm::SmallVectorImpl<Decl*> &decls) +{ + lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS)); + + const Decl *context_decl = dyn_cast<Decl>(decl_context); + + if (!context_decl) + return ELR_Failure; + + static unsigned int invocation_id = 0; + unsigned int current_id = invocation_id++; + + if (log) + { + if (const NamedDecl *context_named_decl = dyn_cast<NamedDecl>(context_decl)) + log->Printf("FindExternalLexicalDecls[%u] in '%s' (a %s) with %s predicate", + current_id, + context_named_decl->getNameAsString().c_str(), + context_decl->getDeclKindName(), + (predicate ? "non-null" : "null")); + else if(context_decl) + log->Printf("FindExternalLexicalDecls[%u] in a %s with %s predicate", + current_id, + context_decl->getDeclKindName(), + (predicate ? "non-null" : "null")); + else + log->Printf("FindExternalLexicalDecls[%u] in a NULL context with %s predicate", + current_id, + (predicate ? "non-null" : "null")); + } + + Decl *original_decl = NULL; + ASTContext *original_ctx = NULL; + + if (!m_ast_importer->ResolveDeclOrigin(context_decl, &original_decl, &original_ctx)) + return ELR_Failure; + + if (log) + { + log->Printf(" FELD[%u] Original decl:", current_id); + ASTDumper(original_decl).ToLog(log, " "); + } + + if (TagDecl *original_tag_decl = dyn_cast<TagDecl>(original_decl)) + { + ExternalASTSource *external_source = original_ctx->getExternalSource(); + + if (external_source) + 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())) + { + if (log) + { + ASTDumper ast_dumper(decl); + if (const NamedDecl *context_named_decl = dyn_cast<NamedDecl>(context_decl)) + log->Printf(" FELD[%d] Adding [to %s] lexical decl %s", current_id, context_named_decl->getNameAsString().c_str(), ast_dumper.GetCString()); + else + log->Printf(" FELD[%d] Adding lexical decl %s", current_id, ast_dumper.GetCString()); + } + + Decl *copied_decl = m_ast_importer->CopyDecl(original_ctx, decl); + + decls.push_back(copied_decl); + } + } + + return ELR_AlreadyLoaded; } void @@ -242,6 +352,25 @@ ClangASTSource::CompleteNamespaceMap (ClangASTImporter::NamespaceMapSP &namespac } } +NamespaceDecl * +ClangASTSource::AddNamespace (NameSearchContext &context, ClangASTImporter::NamespaceMapSP &namespace_decls) +{ + if (namespace_decls.empty()) + return NULL; + + lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS)); + + const ClangNamespaceDecl &namespace_decl = namespace_decls->begin()->second; + + Decl *copied_decl = m_ast_importer->CopyDecl(namespace_decl.GetASTContext(), namespace_decl.GetNamespaceDecl()); + + NamespaceDecl *copied_namespace_decl = dyn_cast<NamespaceDecl>(copied_decl); + + m_ast_importer->RegisterNamespaceMap(copied_namespace_decl, namespace_decls); + + return dyn_cast<NamespaceDecl>(copied_decl); +} + clang::NamedDecl * NameSearchContext::AddVarDecl(void *type) { diff --git a/lldb/source/Expression/ClangExpressionDeclMap.cpp b/lldb/source/Expression/ClangExpressionDeclMap.cpp index dc8acbe0700..5c332be5d90 100644 --- a/lldb/source/Expression/ClangExpressionDeclMap.cpp +++ b/lldb/source/Expression/ClangExpressionDeclMap.cpp @@ -2648,143 +2648,6 @@ ClangExpressionDeclMap::FindExternalVisibleDecls (NameSearchContext &context, } while(0); } -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; - - static unsigned int invocation_id = 0; - unsigned int current_id = invocation_id++; - - if (log) - { - if (const NamedDecl *context_named_decl = dyn_cast<NamedDecl>(context_decl)) - log->Printf("FindExternalLexicalDecls[%u] in '%s' (a %s) with %s predicate", - current_id, - context_named_decl->getNameAsString().c_str(), - context_decl->getDeclKindName(), - (predicate ? "non-null" : "null")); - else if(context_decl) - log->Printf("FindExternalLexicalDecls[%u] in a %s with %s predicate", - current_id, - context_decl->getDeclKindName(), - (predicate ? "non-null" : "null")); - else - log->Printf("FindExternalLexicalDecls[%u] in a NULL context with %s predicate", - current_id, - (predicate ? "non-null" : "null")); - } - - Decl *original_decl = NULL; - ASTContext *original_ctx = NULL; - - if (!m_ast_importer->ResolveDeclOrigin(context_decl, &original_decl, &original_ctx)) - return ELR_Failure; - - if (log) - { - log->Printf(" FELD[%u] Original decl:", current_id); - ASTDumper(original_decl).ToLog(log, " "); - } - - if (TagDecl *original_tag_decl = dyn_cast<TagDecl>(original_decl)) - { - ExternalASTSource *external_source = original_ctx->getExternalSource(); - - if (external_source) - 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())) - { - if (log) - { - ASTDumper ast_dumper(decl); - if (const NamedDecl *context_named_decl = dyn_cast<NamedDecl>(context_decl)) - log->Printf(" FELD[%d] Adding [to %s] lexical decl %s", current_id, context_named_decl->getNameAsString().c_str(), ast_dumper.GetCString()); - else - log->Printf(" FELD[%d] Adding lexical decl %s", current_id, ast_dumper.GetCString()); - } - - Decl *copied_decl = m_ast_importer->CopyDecl(original_ctx, decl); - - decls.push_back(copied_decl); - } - } - - return ELR_AlreadyLoaded; -} - -void -ClangExpressionDeclMap::CompleteType (TagDecl *tag_decl) -{ - assert (m_parser_vars.get()); - - lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS)); - - if (log) - { - log->Printf(" [CompleteTagDecl] Completing a TagDecl named %s", tag_decl->getName().str().c_str()); - log->Printf(" [CTD] Before:"); - ASTDumper dumper((Decl*)tag_decl); - dumper.ToLog(log, " [CTD] "); - } - - m_ast_importer->CompleteTagDecl (tag_decl); - - if (log) - { - log->Printf(" [CTD] After:"); - ASTDumper dumper((Decl*)tag_decl); - dumper.ToLog(log, " [CTD] "); - } -} - -void -ClangExpressionDeclMap::CompleteType (clang::ObjCInterfaceDecl *interface_decl) -{ - assert (m_parser_vars.get()); - - lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS)); - - if (log) - { - log->Printf(" [CompleteObjCInterfaceDecl] Completing an ObjCInterfaceDecl named %s", interface_decl->getName().str().c_str()); - log->Printf(" [COID] Before:"); - ASTDumper dumper((Decl*)interface_decl); - dumper.ToLog(log, " [COID] "); - } - - m_ast_importer->CompleteObjCInterfaceDecl (interface_decl); - - if (log) - { - log->Printf(" [COID] After:"); - ASTDumper dumper((Decl*)interface_decl); - dumper.ToLog(log, " [COID] "); - } -} - Value * ClangExpressionDeclMap::GetVariableValue ( @@ -3031,7 +2894,6 @@ ClangExpressionDeclMap::AddOneGenericVariable(NameSearchContext &context, entity->m_parser_vars->m_llvm_value = NULL; entity->m_parser_vars->m_lldb_value = symbol_location.release(); entity->m_parser_vars->m_lldb_sym = &symbol; - //entity->m_flags |= ClangExpressionVariable::EVUnknownType; if (log) { @@ -3136,27 +2998,6 @@ ClangExpressionDeclMap::AddOneRegister (NameSearchContext &context, } } -NamespaceDecl * -ClangExpressionDeclMap::AddNamespace (NameSearchContext &context, ClangASTImporter::NamespaceMapSP &namespace_decls) -{ - if (namespace_decls.empty()) - return NULL; - - lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS)); - - assert (m_parser_vars.get()); - - const ClangNamespaceDecl &namespace_decl = namespace_decls->begin()->second; - - Decl *copied_decl = m_ast_importer->CopyDecl(namespace_decl.GetASTContext(), namespace_decl.GetNamespaceDecl()); - - NamespaceDecl *copied_namespace_decl = dyn_cast<NamespaceDecl>(copied_decl); - - m_ast_importer->RegisterNamespaceMap(copied_namespace_decl, namespace_decls); - - return dyn_cast<NamespaceDecl>(copied_decl); -} - void ClangExpressionDeclMap::AddOneFunction (NameSearchContext &context, Function* fun, |