From f0c5aeb69011197d1ef1bbed7ba363d52e95c5d8 Mon Sep 17 00:00:00 2001 From: Sean Callanan Date: Mon, 20 Apr 2015 16:31:29 +0000 Subject: This patch implements several improvements to the module-loading support for the expression parser. - It adds support for auto-loading modules referred to by a compile unit. These references are currently in the form of empty translation units. This functionality is gated by the setting target.auto-import-clang-modules (boolean) = false - It improves and corrects support for loading macros from modules, currently by textually pasting all #defines into the user's expression. The improvements center around including only those modules that are relevant to the current context - hand-loaded modules and the modules that are imported from the current compile unit. - It adds an "opt-in" mechanism for all of this functionality. Modules have to be explicitly imported (via @import) or auto-loaded (by enabling the above setting) to enable any of this functionality. It also adds support to the compile unit and symbol file code to deal with empty translation units that indicate module imports, and plumbs this through to the CompileUnit interface. Finally, it makes the following changes to the test suite: - It adds a testcase that verifies that modules are automatically loaded when the appropriate setting is enabled (lang/objc/modules-auto-import); and - It modifies lanb/objc/modules-incomplete to test the case where a module #undefs something that is #defined in another module. llvm-svn: 235313 --- lldb/source/Expression/ClangExpressionParser.cpp | 37 +++++++++++++++--------- 1 file changed, 24 insertions(+), 13 deletions(-) (limited to 'lldb/source/Expression/ClangExpressionParser.cpp') diff --git a/lldb/source/Expression/ClangExpressionParser.cpp b/lldb/source/Expression/ClangExpressionParser.cpp index c7d84e61813..57e620bf2d9 100644 --- a/lldb/source/Expression/ClangExpressionParser.cpp +++ b/lldb/source/Expression/ClangExpressionParser.cpp @@ -24,6 +24,7 @@ #include "lldb/Expression/ClangExpression.h" #include "lldb/Expression/ClangExpressionDeclMap.h" #include "lldb/Expression/ClangModulesDeclVendor.h" +#include "lldb/Expression/ClangPersistentVariables.h" #include "lldb/Expression/IRExecutionUnit.h" #include "lldb/Expression/IRDynamicChecks.h" #include "lldb/Expression/IRInterpreter.h" @@ -96,12 +97,15 @@ std::string GetBuiltinIncludePath(const char *Argv0) { class ClangExpressionParser::LLDBPreprocessorCallbacks : public PPCallbacks { - ClangModulesDeclVendor &m_decl_vendor; - StreamString m_error_stream; - bool m_has_errors = false; + ClangModulesDeclVendor &m_decl_vendor; + ClangPersistentVariables &m_persistent_vars; + StreamString m_error_stream; + bool m_has_errors = false; public: - LLDBPreprocessorCallbacks(ClangModulesDeclVendor &decl_vendor) : - m_decl_vendor(decl_vendor) + LLDBPreprocessorCallbacks(ClangModulesDeclVendor &decl_vendor, + ClangPersistentVariables &persistent_vars) : + m_decl_vendor(decl_vendor), + m_persistent_vars(persistent_vars) { } @@ -109,19 +113,26 @@ public: ModuleIdPath path, const clang::Module * /*null*/) { - std::vector string_path; + std::vector string_path; for (const std::pair &component : path) { - string_path.push_back(component.first->getName()); + string_path.push_back(ConstString(component.first->getName())); } StreamString error_stream; - if (!m_decl_vendor.AddModule(string_path, m_error_stream)) + ClangModulesDeclVendor::ModuleVector exported_modules; + + if (!m_decl_vendor.AddModule(string_path, &exported_modules, m_error_stream)) { m_has_errors = true; } + + for (ClangModulesDeclVendor::ModuleID module : exported_modules) + { + m_persistent_vars.AddHandLoadedClangModule(module); + } } bool hasErrors() @@ -298,7 +309,7 @@ ClangExpressionParser::ClangExpressionParser (ExecutionContextScope *exe_scope, if (ClangModulesDeclVendor *decl_vendor = target_sp->GetClangModulesDeclVendor()) { - std::unique_ptr pp_callbacks(new LLDBPreprocessorCallbacks(*decl_vendor)); + std::unique_ptr pp_callbacks(new LLDBPreprocessorCallbacks(*decl_vendor, target_sp->GetPersistentVariables())); m_pp_callbacks = static_cast(pp_callbacks.get()); m_compiler->getPreprocessor().addPPCallbacks(std::move(pp_callbacks)); } @@ -309,10 +320,10 @@ ClangExpressionParser::ClangExpressionParser (ExecutionContextScope *exe_scope, m_builtin_context.reset(new Builtin::Context()); std::unique_ptr ast_context(new ASTContext(m_compiler->getLangOpts(), - m_compiler->getSourceManager(), - m_compiler->getPreprocessor().getIdentifierTable(), - *m_selector_table.get(), - *m_builtin_context.get())); + m_compiler->getSourceManager(), + m_compiler->getPreprocessor().getIdentifierTable(), + *m_selector_table.get(), + *m_builtin_context.get())); ast_context->InitBuiltinTypes(m_compiler->getTarget()); -- cgit v1.2.3