From 3ad8278737d042c6b5b61c0143ee68db66be91fe Mon Sep 17 00:00:00 2001 From: Raphael Isemann Date: Wed, 11 Sep 2019 14:33:11 +0000 Subject: [PATCH] [lldb][NFC] Make include directories in Clang expression parser a std::string We never compare these directories (where ConstString would be good) and essentially just convert this back to a normal string in the end. So we might as well just use std::string. Also makes it easier to unittest this code (which was the main motivation for this change). llvm-svn: 371623 --- .../Clang/ClangExpressionParser.cpp | 13 ++++++------- .../ExpressionParser/Clang/ClangExpressionParser.h | 4 ++-- .../ExpressionParser/Clang/ClangUserExpression.cpp | 2 +- .../ExpressionParser/Clang/ClangUserExpression.h | 2 +- 4 files changed, 10 insertions(+), 11 deletions(-) diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp index 01e768a2ccf3..9487237f8d13 100644 --- a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp +++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp @@ -213,16 +213,15 @@ private: std::shared_ptr m_passthrough; }; -static void -SetupModuleHeaderPaths(CompilerInstance *compiler, - std::vector include_directories, - lldb::TargetSP target_sp) { +static void SetupModuleHeaderPaths(CompilerInstance *compiler, + std::vector include_directories, + lldb::TargetSP target_sp) { Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS)); HeaderSearchOptions &search_opts = compiler->getHeaderSearchOpts(); - for (ConstString dir : include_directories) { - search_opts.AddPath(dir.AsCString(), frontend::System, false, true); + for (const std::string &dir : include_directories) { + search_opts.AddPath(dir, frontend::System, false, true); LLDB_LOG(log, "Added user include dir: {0}", dir); } @@ -261,7 +260,7 @@ SetupModuleHeaderPaths(CompilerInstance *compiler, ClangExpressionParser::ClangExpressionParser( ExecutionContextScope *exe_scope, Expression &expr, - bool generate_debug_info, std::vector include_directories) + bool generate_debug_info, std::vector include_directories) : ExpressionParser(exe_scope, expr, generate_debug_info), m_compiler(), m_pp_callbacks(nullptr), m_include_directories(std::move(include_directories)) { diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.h b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.h index a42c2190ffb8..80a92691eaac 100644 --- a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.h +++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.h @@ -55,7 +55,7 @@ public: /// expression. ClangExpressionParser(ExecutionContextScope *exe_scope, Expression &expr, bool generate_debug_info, - std::vector include_directories = {}); + std::vector include_directories = {}); /// Destructor ~ClangExpressionParser() override; @@ -177,7 +177,7 @@ private: ///encounters module imports std::unique_ptr m_ast_context; - std::vector m_include_directories; + std::vector m_include_directories; }; } diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp b/lldb/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp index 54d852b2d839..57bf654528ad 100644 --- a/lldb/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp +++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp @@ -469,7 +469,7 @@ ClangUserExpression::GetModulesToImport(ExecutionContext &exe_ctx) { } for (const SourceModule &m : sc.comp_unit->GetImportedModules()) - m_include_directories.push_back(m.search_path); + m_include_directories.emplace_back(m.search_path.GetCString()); // Check if we imported 'std' or any of its submodules. // We currently don't support importing any other modules in the expression diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangUserExpression.h b/lldb/source/Plugins/ExpressionParser/Clang/ClangUserExpression.h index 5899e3a52c0f..9af5ce6cf24b 100644 --- a/lldb/source/Plugins/ExpressionParser/Clang/ClangUserExpression.h +++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangUserExpression.h @@ -209,7 +209,7 @@ private: /// The language type of the current expression. lldb::LanguageType m_expr_lang = lldb::eLanguageTypeUnknown; /// The include directories that should be used when parsing the expression. - std::vector m_include_directories; + std::vector m_include_directories; /// The absolute character position in the transformed source code where the /// user code (as typed by the user) starts. If the variable is empty, then we