[Lldb-commits] [lldb] r371623 - [lldb][NFC] Make include directories in Clang expression parser a std::string

Raphael Isemann via lldb-commits lldb-commits at lists.llvm.org
Wed Sep 11 07:33:12 PDT 2019


Author: teemperor
Date: Wed Sep 11 07:33:11 2019
New Revision: 371623

URL: http://llvm.org/viewvc/llvm-project?rev=371623&view=rev
Log:
[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).

Modified:
    lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
    lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.h
    lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp
    lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangUserExpression.h

Modified: lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp?rev=371623&r1=371622&r2=371623&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp (original)
+++ lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp Wed Sep 11 07:33:11 2019
@@ -213,16 +213,15 @@ private:
   std::shared_ptr<clang::TextDiagnosticBuffer> m_passthrough;
 };
 
-static void
-SetupModuleHeaderPaths(CompilerInstance *compiler,
-                       std::vector<ConstString> include_directories,
-                       lldb::TargetSP target_sp) {
+static void SetupModuleHeaderPaths(CompilerInstance *compiler,
+                                   std::vector<std::string> 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
 
 ClangExpressionParser::ClangExpressionParser(
     ExecutionContextScope *exe_scope, Expression &expr,
-    bool generate_debug_info, std::vector<ConstString> include_directories)
+    bool generate_debug_info, std::vector<std::string> include_directories)
     : ExpressionParser(exe_scope, expr, generate_debug_info), m_compiler(),
       m_pp_callbacks(nullptr),
       m_include_directories(std::move(include_directories)) {

Modified: lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.h?rev=371623&r1=371622&r2=371623&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.h (original)
+++ lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.h Wed Sep 11 07:33:11 2019
@@ -55,7 +55,7 @@ public:
   ///     expression.
   ClangExpressionParser(ExecutionContextScope *exe_scope, Expression &expr,
                         bool generate_debug_info,
-                        std::vector<ConstString> include_directories = {});
+                        std::vector<std::string> include_directories = {});
 
   /// Destructor
   ~ClangExpressionParser() override;
@@ -177,7 +177,7 @@ private:
                                              ///encounters module imports
   std::unique_ptr<ClangASTContext> m_ast_context;
 
-  std::vector<ConstString> m_include_directories;
+  std::vector<std::string> m_include_directories;
 };
 }
 

Modified: lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp?rev=371623&r1=371622&r2=371623&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp (original)
+++ lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp Wed Sep 11 07:33:11 2019
@@ -469,7 +469,7 @@ ClangUserExpression::GetModulesToImport(
   }
 
   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

Modified: lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangUserExpression.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangUserExpression.h?rev=371623&r1=371622&r2=371623&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangUserExpression.h (original)
+++ lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangUserExpression.h Wed Sep 11 07:33:11 2019
@@ -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<ConstString> m_include_directories;
+  std::vector<std::string> 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




More information about the lldb-commits mailing list