[Lldb-commits] [lldb] a00acba - [lldb] Fix missing initialization in UtilityFunction ctor (NFC)

Jonas Devlieghere via lldb-commits lldb-commits at lists.llvm.org
Thu Oct 22 21:12:34 PDT 2020


Author: Jonas Devlieghere
Date: 2020-10-22T21:12:27-07:00
New Revision: a00acbab45b0c407da05bf5c8152018e1857a1f0

URL: https://github.com/llvm/llvm-project/commit/a00acbab45b0c407da05bf5c8152018e1857a1f0
DIFF: https://github.com/llvm/llvm-project/commit/a00acbab45b0c407da05bf5c8152018e1857a1f0.diff

LOG: [lldb] Fix missing initialization in UtilityFunction ctor (NFC)

The UtilityFunction ctor was dropping the text argument. Probably for
that reason ClangUtilityFunction was setting the parent's member
directly instead of deferring to the parent ctor. Also change the
signatures to take strings which are std::moved in place.

Added: 
    

Modified: 
    lldb/include/lldb/Expression/UtilityFunction.h
    lldb/source/Expression/UtilityFunction.cpp
    lldb/source/Plugins/ExpressionParser/Clang/ClangUtilityFunction.cpp
    lldb/source/Plugins/ExpressionParser/Clang/ClangUtilityFunction.h

Removed: 
    


################################################################################
diff  --git a/lldb/include/lldb/Expression/UtilityFunction.h b/lldb/include/lldb/Expression/UtilityFunction.h
index 5ebbc0ede1e3..99fb32153aa2 100644
--- a/lldb/include/lldb/Expression/UtilityFunction.h
+++ b/lldb/include/lldb/Expression/UtilityFunction.h
@@ -42,8 +42,8 @@ class UtilityFunction : public Expression {
   ///
   /// \param[in] name
   ///     The name of the function, as used in the text.
-  UtilityFunction(ExecutionContextScope &exe_scope, const char *text,
-                  const char *name);
+  UtilityFunction(ExecutionContextScope &exe_scope, std::string text,
+                  std::string name);
 
   ~UtilityFunction() override;
 
@@ -110,9 +110,10 @@ class UtilityFunction : public Expression {
 protected:
   std::shared_ptr<IRExecutionUnit> m_execution_unit_sp;
   lldb::ModuleWP m_jit_module_wp;
-  std::string m_function_text; ///< The text of the function.  Must be a
-                               ///well-formed translation unit.
-  std::string m_function_name; ///< The name of the function.
+  /// The text of the function.  Must be a well-formed translation unit.
+  std::string m_function_text;
+  /// The name of the function.
+  std::string m_function_name;
   std::unique_ptr<FunctionCaller> m_caller_up;
 };
 

diff  --git a/lldb/source/Expression/UtilityFunction.cpp b/lldb/source/Expression/UtilityFunction.cpp
index 3de2ee2acbbf..128db0ccbc3e 100644
--- a/lldb/source/Expression/UtilityFunction.cpp
+++ b/lldb/source/Expression/UtilityFunction.cpp
@@ -41,9 +41,9 @@ char UtilityFunction::ID;
 /// \param[in] name
 ///     The name of the function, as used in the text.
 UtilityFunction::UtilityFunction(ExecutionContextScope &exe_scope,
-                                 const char *text, const char *name)
+                                 std::string text, std::string name)
     : Expression(exe_scope), m_execution_unit_sp(), m_jit_module_wp(),
-      m_function_text(), m_function_name(name) {}
+      m_function_text(std::move(text)), m_function_name(std::move(name)) {}
 
 UtilityFunction::~UtilityFunction() {
   lldb::ProcessSP process_sp(m_jit_process_wp.lock());

diff  --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangUtilityFunction.cpp b/lldb/source/Plugins/ExpressionParser/Clang/ClangUtilityFunction.cpp
index 25ec982220a0..5fdb7b4f4d9c 100644
--- a/lldb/source/Plugins/ExpressionParser/Clang/ClangUtilityFunction.cpp
+++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangUtilityFunction.cpp
@@ -42,11 +42,9 @@ char ClangUtilityFunction::ID;
 /// \param[in] name
 ///     The name of the function, as used in the text.
 ClangUtilityFunction::ClangUtilityFunction(ExecutionContextScope &exe_scope,
-                                           const char *text, const char *name)
-    : UtilityFunction(exe_scope, text, name) {
+                                           std::string text, std::string name)
+    : UtilityFunction(exe_scope, std::move(text), std::move(name)) {
   m_function_text.assign(ClangExpressionSourceCode::g_expression_prefix);
-  if (text && text[0])
-    m_function_text.append(text);
 }
 
 ClangUtilityFunction::~ClangUtilityFunction() {}

diff  --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangUtilityFunction.h b/lldb/source/Plugins/ExpressionParser/Clang/ClangUtilityFunction.h
index 1f2dd5fdbecc..7914e1406cd0 100644
--- a/lldb/source/Plugins/ExpressionParser/Clang/ClangUtilityFunction.h
+++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangUtilityFunction.h
@@ -41,6 +41,34 @@ class ClangUtilityFunction : public UtilityFunction {
   }
   static bool classof(const Expression *obj) { return obj->isA(&ID); }
 
+  /// Constructor
+  ///
+  /// \param[in] text
+  ///     The text of the function.  Must be a full translation unit.
+  ///
+  /// \param[in] name
+  ///     The name of the function, as used in the text.
+  ClangUtilityFunction(ExecutionContextScope &exe_scope, std::string text,
+                       std::string name);
+
+  ~ClangUtilityFunction() override;
+
+  ExpressionTypeSystemHelper *GetTypeSystemHelper() override {
+    return &m_type_system_helper;
+  }
+
+  ClangExpressionDeclMap *DeclMap() { return m_type_system_helper.DeclMap(); }
+
+  void ResetDeclMap() { m_type_system_helper.ResetDeclMap(); }
+
+  void ResetDeclMap(ExecutionContext &exe_ctx, bool keep_result_in_memory) {
+    m_type_system_helper.ResetDeclMap(exe_ctx, keep_result_in_memory);
+  }
+
+  bool Install(DiagnosticManager &diagnostic_manager,
+               ExecutionContext &exe_ctx) override;
+
+private:
   class ClangUtilityFunctionHelper : public ClangExpressionHelper {
   public:
     ClangUtilityFunctionHelper() {}
@@ -58,7 +86,7 @@ class ClangUtilityFunction : public UtilityFunction {
     void ResetDeclMap(ExecutionContext &exe_ctx, bool keep_result_in_memory);
 
     /// Return the object that the parser should allow to access ASTs. May be
-    /// NULL if the ASTs do not need to be transformed.
+    /// nullptr if the ASTs do not need to be transformed.
     ///
     /// \param[in] passthrough
     ///     The ASTConsumer that the returned transformer should send
@@ -71,37 +99,9 @@ class ClangUtilityFunction : public UtilityFunction {
   private:
     std::unique_ptr<ClangExpressionDeclMap> m_expr_decl_map_up;
   };
-  /// Constructor
-  ///
-  /// \param[in] text
-  ///     The text of the function.  Must be a full translation unit.
-  ///
-  /// \param[in] name
-  ///     The name of the function, as used in the text.
-  ClangUtilityFunction(ExecutionContextScope &exe_scope, const char *text,
-                       const char *name);
-
-  ~ClangUtilityFunction() override;
-
-  ExpressionTypeSystemHelper *GetTypeSystemHelper() override {
-    return &m_type_system_helper;
-  }
 
-  ClangExpressionDeclMap *DeclMap() { return m_type_system_helper.DeclMap(); }
-
-  void ResetDeclMap() { m_type_system_helper.ResetDeclMap(); }
-
-  void ResetDeclMap(ExecutionContext &exe_ctx, bool keep_result_in_memory) {
-    m_type_system_helper.ResetDeclMap(exe_ctx, keep_result_in_memory);
-  }
-
-  bool Install(DiagnosticManager &diagnostic_manager,
-               ExecutionContext &exe_ctx) override;
-
-private:
-  ClangUtilityFunctionHelper m_type_system_helper; ///< The map to use when
-                                                   ///parsing and materializing
-                                                   ///the expression.
+  /// The map to use when parsing and materializing the expression.
+  ClangUtilityFunctionHelper m_type_system_helper;
 };
 
 } // namespace lldb_private


        


More information about the lldb-commits mailing list