[Lldb-commits] [lldb] 52f3a2f - [lldb][NFC] Move LLVM RTTI implementation from enum to static ID variable

Raphael Isemann via lldb-commits lldb-commits at lists.llvm.org
Tue Nov 12 01:05:34 PST 2019


Author: Raphael Isemann
Date: 2019-11-12T10:04:32+01:00
New Revision: 52f3a2faf92c4d8efd0e626d52d5f64b7c5d468f

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

LOG: [lldb][NFC] Move LLVM RTTI implementation from enum to static ID variable

Summary:
swift-lldb currently has to patch the ExpressionKind enum to add support for Swift expressions. If we implement LLVM's RTTI
with a static ID variable instead of a centralised enum we can drop that patch.

Reviewers: labath, davide

Reviewed By: labath

Subscribers: JDevlieghere, lldb-commits

Tags: #upstreaming_lldb_s_downstream_patches, #lldb

Differential Revision: https://reviews.llvm.org/D70070

Added: 
    

Modified: 
    lldb/include/lldb/Expression/Expression.h
    lldb/include/lldb/Expression/FunctionCaller.h
    lldb/include/lldb/Expression/LLVMUserExpression.h
    lldb/include/lldb/Expression/UserExpression.h
    lldb/include/lldb/Expression/UtilityFunction.h
    lldb/source/Expression/Expression.cpp
    lldb/source/Expression/FunctionCaller.cpp
    lldb/source/Expression/LLVMUserExpression.cpp
    lldb/source/Expression/UserExpression.cpp
    lldb/source/Expression/UtilityFunction.cpp
    lldb/source/Plugins/ExpressionParser/Clang/ClangFunctionCaller.cpp
    lldb/source/Plugins/ExpressionParser/Clang/ClangFunctionCaller.h
    lldb/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp
    lldb/source/Plugins/ExpressionParser/Clang/ClangUserExpression.h
    lldb/source/Plugins/ExpressionParser/Clang/ClangUtilityFunction.cpp
    lldb/source/Plugins/ExpressionParser/Clang/ClangUtilityFunction.h

Removed: 
    


################################################################################
diff  --git a/lldb/include/lldb/Expression/Expression.h b/lldb/include/lldb/Expression/Expression.h
index fca5fb9119cb..e0ea7e99f4f9 100644
--- a/lldb/include/lldb/Expression/Expression.h
+++ b/lldb/include/lldb/Expression/Expression.h
@@ -32,22 +32,11 @@ class RecordingMemoryManager;
 /// LLVM IR from the expression.
 class Expression {
 public:
-  /// Discriminator for LLVM-style RTTI (dyn_cast<> et al.)
-  enum ExpressionKind {
-    eKindFunctionCaller,
-    eKindClangFunctionCaller,
-    eKindUserExpression,
-    eKindLLVMUserExpression,
-    eKindClangUserExpression,
-    eKindUtilityFunction,
-    eKindClangUtilityFunction,
-  };
-
   enum ResultType { eResultTypeAny, eResultTypeId };
 
-  Expression(Target &target, ExpressionKind kind);
+  Expression(Target &target);
 
-  Expression(ExecutionContextScope &exe_scope, ExpressionKind kind);
+  Expression(ExecutionContextScope &exe_scope);
 
   /// Destructor
   virtual ~Expression() {}
@@ -94,12 +83,9 @@ class Expression {
 
   virtual ExpressionTypeSystemHelper *GetTypeSystemHelper() { return nullptr; }
 
-  /// LLVM-style RTTI support.
-  ExpressionKind getKind() const { return m_kind; }
-  
-private:
-  /// LLVM-style RTTI support.
-  const ExpressionKind m_kind;
+  // LLVM RTTI support
+  virtual bool isA(const void *ClassID) const = 0;
+
 protected:
   lldb::TargetWP m_target_wp; /// Expression's always have to have a target...
   lldb::ProcessWP m_jit_process_wp; /// An expression might have a process, but

diff  --git a/lldb/include/lldb/Expression/FunctionCaller.h b/lldb/include/lldb/Expression/FunctionCaller.h
index ea9d0205bf86..6f60750febd1 100644
--- a/lldb/include/lldb/Expression/FunctionCaller.h
+++ b/lldb/include/lldb/Expression/FunctionCaller.h
@@ -54,12 +54,13 @@ namespace lldb_private {
 /// Any of the methods that take arg_addr_ptr can be passed nullptr, and the
 /// argument space will be managed for you.
 class FunctionCaller : public Expression {
+  // LLVM RTTI support
+  static char ID;
+
 public:
-  /// LLVM-style RTTI support.
-  static bool classof(const Expression *E) {
-    return E->getKind() == eKindFunctionCaller;
-  }
-  
+  bool isA(const void *ClassID) const override { return ClassID == &ID; }
+  static bool classof(const Expression *obj) { return obj->isA(&ID); }
+
   /// Constructor
   ///
   /// \param[in] exe_scope

diff  --git a/lldb/include/lldb/Expression/LLVMUserExpression.h b/lldb/include/lldb/Expression/LLVMUserExpression.h
index 5f4c43cdea2e..2679c01a4e00 100644
--- a/lldb/include/lldb/Expression/LLVMUserExpression.h
+++ b/lldb/include/lldb/Expression/LLVMUserExpression.h
@@ -30,11 +30,14 @@ namespace lldb_private {
 /// implementations of LLVMUserExpression - which will be vended through the
 /// appropriate TypeSystem.
 class LLVMUserExpression : public UserExpression {
+  // LLVM RTTI support
+  static char ID;
+
 public:
-  /// LLVM-style RTTI support.
-  static bool classof(const Expression *E) {
-    return E->getKind() == eKindLLVMUserExpression;
+  bool isA(const void *ClassID) const override {
+    return ClassID == &ID || UserExpression::isA(ClassID);
   }
+  static bool classof(const Expression *obj) { return obj->isA(&ID); }
 
   // The IRPasses struct is filled in by a runtime after an expression is
   // compiled and can be used to to run fixups/analysis passes as required.
@@ -51,8 +54,7 @@ class LLVMUserExpression : public UserExpression {
   LLVMUserExpression(ExecutionContextScope &exe_scope, llvm::StringRef expr,
                      llvm::StringRef prefix, lldb::LanguageType language,
                      ResultType desired_type,
-                     const EvaluateExpressionOptions &options,
-                     ExpressionKind kind);
+                     const EvaluateExpressionOptions &options);
   ~LLVMUserExpression() override;
 
   bool FinalizeJITExecution(

diff  --git a/lldb/include/lldb/Expression/UserExpression.h b/lldb/include/lldb/Expression/UserExpression.h
index b1d52f8ddd55..02d2991fff6b 100644
--- a/lldb/include/lldb/Expression/UserExpression.h
+++ b/lldb/include/lldb/Expression/UserExpression.h
@@ -33,12 +33,13 @@ namespace lldb_private {
 /// implementations of UserExpression - which will be vended through the
 /// appropriate TypeSystem.
 class UserExpression : public Expression {
+  // LLVM RTTI support
+  static char ID;
+
 public:
-  /// LLVM-style RTTI support.
-  static bool classof(const Expression *E) {
-    return E->getKind() == eKindUserExpression;
-  }
-  
+  bool isA(const void *ClassID) const override { return ClassID == &ID; }
+  static bool classof(const Expression *obj) { return obj->isA(&ID); }
+
   enum { kDefaultTimeout = 500000u };
 
   /// Constructor
@@ -61,8 +62,7 @@ class UserExpression : public Expression {
   UserExpression(ExecutionContextScope &exe_scope, llvm::StringRef expr,
                  llvm::StringRef prefix, lldb::LanguageType language,
                  ResultType desired_type,
-                 const EvaluateExpressionOptions &options,
-                 ExpressionKind kind);
+                 const EvaluateExpressionOptions &options);
 
   /// Destructor
   ~UserExpression() override;

diff  --git a/lldb/include/lldb/Expression/UtilityFunction.h b/lldb/include/lldb/Expression/UtilityFunction.h
index 26da081ddced..8a11e2fba05b 100644
--- a/lldb/include/lldb/Expression/UtilityFunction.h
+++ b/lldb/include/lldb/Expression/UtilityFunction.h
@@ -28,12 +28,13 @@ namespace lldb_private {
 /// self-contained function meant to be used from other code.  Utility
 /// functions can perform error-checking for ClangUserExpressions,
 class UtilityFunction : public Expression {
+  // LLVM RTTI support
+  static char ID;
+
 public:
-  /// LLVM-style RTTI support.
-  static bool classof(const Expression *E) {
-    return E->getKind() == eKindUtilityFunction;
-  }
-  
+  bool isA(const void *ClassID) const override { return ClassID == &ID; }
+  static bool classof(const Expression *obj) { return obj->isA(&ID); }
+
   /// Constructor
   ///
   /// \param[in] text
@@ -42,7 +43,7 @@ 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, ExpressionKind kind);
+                  const char *name);
 
   ~UtilityFunction() override;
 

diff  --git a/lldb/source/Expression/Expression.cpp b/lldb/source/Expression/Expression.cpp
index 8e1ef6958cc7..71369d0b9eec 100644
--- a/lldb/source/Expression/Expression.cpp
+++ b/lldb/source/Expression/Expression.cpp
@@ -12,18 +12,16 @@
 
 using namespace lldb_private;
 
-Expression::Expression(Target &target, ExpressionKind kind)
-    : m_kind(kind),
-      m_target_wp(target.shared_from_this()),
+Expression::Expression(Target &target)
+    : m_target_wp(target.shared_from_this()),
       m_jit_start_addr(LLDB_INVALID_ADDRESS),
       m_jit_end_addr(LLDB_INVALID_ADDRESS) {
   // Can't make any kind of expression without a target.
   assert(m_target_wp.lock());
 }
 
-Expression::Expression(ExecutionContextScope &exe_scope, ExpressionKind kind)
-    : m_kind(kind),
-      m_target_wp(exe_scope.CalculateTarget()),
+Expression::Expression(ExecutionContextScope &exe_scope)
+    : m_target_wp(exe_scope.CalculateTarget()),
       m_jit_start_addr(LLDB_INVALID_ADDRESS),
       m_jit_end_addr(LLDB_INVALID_ADDRESS) {
   assert(m_target_wp.lock());

diff  --git a/lldb/source/Expression/FunctionCaller.cpp b/lldb/source/Expression/FunctionCaller.cpp
index 203cfff63d80..dc80c8169d7d 100644
--- a/lldb/source/Expression/FunctionCaller.cpp
+++ b/lldb/source/Expression/FunctionCaller.cpp
@@ -29,14 +29,16 @@
 
 using namespace lldb_private;
 
+char FunctionCaller::ID;
+
 // FunctionCaller constructor
 FunctionCaller::FunctionCaller(ExecutionContextScope &exe_scope,
                                const CompilerType &return_type,
                                const Address &functionAddress,
                                const ValueList &arg_value_list,
                                const char *name)
-    : Expression(exe_scope, eKindFunctionCaller), m_execution_unit_sp(),
-      m_parser(), m_jit_module_wp(), m_name(name ? name : "<unknown>"),
+    : Expression(exe_scope), m_execution_unit_sp(), m_parser(),
+      m_jit_module_wp(), m_name(name ? name : "<unknown>"),
       m_function_ptr(nullptr), m_function_addr(functionAddress),
       m_function_return_type(return_type),
       m_wrapper_function_name("__lldb_caller_function"),

diff  --git a/lldb/source/Expression/LLVMUserExpression.cpp b/lldb/source/Expression/LLVMUserExpression.cpp
index ee72e7ce6322..1fc878bbd616 100644
--- a/lldb/source/Expression/LLVMUserExpression.cpp
+++ b/lldb/source/Expression/LLVMUserExpression.cpp
@@ -35,20 +35,20 @@
 
 using namespace lldb_private;
 
+char LLVMUserExpression::ID;
+
 LLVMUserExpression::LLVMUserExpression(ExecutionContextScope &exe_scope,
                                        llvm::StringRef expr,
                                        llvm::StringRef prefix,
                                        lldb::LanguageType language,
                                        ResultType desired_type,
-                                       const EvaluateExpressionOptions &options,
-                                       ExpressionKind kind)
-    : UserExpression(exe_scope, expr, prefix, language, desired_type, options,
-                     kind),
+                                       const EvaluateExpressionOptions &options)
+    : UserExpression(exe_scope, expr, prefix, language, desired_type, options),
       m_stack_frame_bottom(LLDB_INVALID_ADDRESS),
       m_stack_frame_top(LLDB_INVALID_ADDRESS), m_allow_cxx(false),
       m_allow_objc(false), m_transformed_text(), m_execution_unit_sp(),
-      m_materializer_up(), m_jit_module_wp(),
-      m_can_interpret(false), m_materialized_address(LLDB_INVALID_ADDRESS) {}
+      m_materializer_up(), m_jit_module_wp(), m_can_interpret(false),
+      m_materialized_address(LLDB_INVALID_ADDRESS) {}
 
 LLVMUserExpression::~LLVMUserExpression() {
   if (m_target) {

diff  --git a/lldb/source/Expression/UserExpression.cpp b/lldb/source/Expression/UserExpression.cpp
index e2d1d2f2b3d2..9e3c8ad56af0 100644
--- a/lldb/source/Expression/UserExpression.cpp
+++ b/lldb/source/Expression/UserExpression.cpp
@@ -46,13 +46,14 @@
 
 using namespace lldb_private;
 
+char UserExpression::ID;
+
 UserExpression::UserExpression(ExecutionContextScope &exe_scope,
                                llvm::StringRef expr, llvm::StringRef prefix,
                                lldb::LanguageType language,
                                ResultType desired_type,
-                               const EvaluateExpressionOptions &options,
-                               ExpressionKind kind)
-    : Expression(exe_scope, kind), m_expr_text(expr), m_expr_prefix(prefix),
+                               const EvaluateExpressionOptions &options)
+    : Expression(exe_scope), m_expr_text(expr), m_expr_prefix(prefix),
       m_language(language), m_desired_type(desired_type), m_options(options) {}
 
 UserExpression::~UserExpression() {}

diff  --git a/lldb/source/Expression/UtilityFunction.cpp b/lldb/source/Expression/UtilityFunction.cpp
index aac8b33a6bfa..2dbc0e9d73ed 100644
--- a/lldb/source/Expression/UtilityFunction.cpp
+++ b/lldb/source/Expression/UtilityFunction.cpp
@@ -31,6 +31,8 @@
 using namespace lldb_private;
 using namespace lldb;
 
+char UtilityFunction::ID;
+
 /// Constructor
 ///
 /// \param[in] text
@@ -39,12 +41,9 @@ using namespace lldb;
 /// \param[in] name
 ///     The name of the function, as used in the text.
 UtilityFunction::UtilityFunction(ExecutionContextScope &exe_scope,
-                                 const char *text, const char *name,
-                                 ExpressionKind kind)
-    : Expression(exe_scope, kind),
-      m_execution_unit_sp(), m_jit_module_wp(),
-      m_function_text(),
-      m_function_name(name) {}
+                                 const char *text, const char *name)
+    : Expression(exe_scope), m_execution_unit_sp(), m_jit_module_wp(),
+      m_function_text(), m_function_name(name) {}
 
 UtilityFunction::~UtilityFunction() {
   lldb::ProcessSP process_sp(m_jit_process_wp.lock());

diff  --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangFunctionCaller.cpp b/lldb/source/Plugins/ExpressionParser/Clang/ClangFunctionCaller.cpp
index 3eeb50c53cbf..7f7c0a97f538 100644
--- a/lldb/source/Plugins/ExpressionParser/Clang/ClangFunctionCaller.cpp
+++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangFunctionCaller.cpp
@@ -42,6 +42,8 @@
 
 using namespace lldb_private;
 
+char ClangFunctionCaller::ID;
+
 // ClangFunctionCaller constructor
 ClangFunctionCaller::ClangFunctionCaller(ExecutionContextScope &exe_scope,
                                          const CompilerType &return_type,

diff  --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangFunctionCaller.h b/lldb/source/Plugins/ExpressionParser/Clang/ClangFunctionCaller.h
index 24f6f2eb91b3..45bd1f410a67 100644
--- a/lldb/source/Plugins/ExpressionParser/Clang/ClangFunctionCaller.h
+++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangFunctionCaller.h
@@ -59,11 +59,6 @@ class ClangExpressionParser;
 class ClangFunctionCaller : public FunctionCaller {
   friend class ASTStructExtractor;
 
-  /// LLVM-style RTTI support.
-  static bool classof(const Expression *E) {
-    return E->getKind() == eKindClangFunctionCaller;
-  }
-
   class ClangFunctionCallerHelper : public ClangExpressionHelper {
   public:
     ClangFunctionCallerHelper(ClangFunctionCaller &owner) : m_owner(owner) {}
@@ -91,7 +86,15 @@ class ClangFunctionCaller : public FunctionCaller {
                                                             ///layout.
   };
 
+  // LLVM RTTI support
+  static char ID;
+
 public:
+  bool isA(const void *ClassID) const override {
+    return ClassID == &ID || FunctionCaller::isA(ClassID);
+  }
+  static bool classof(const Expression *obj) { return obj->isA(&ID); }
+
   /// Constructor
   ///
   /// \param[in] exe_scope

diff  --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp b/lldb/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp
index 60592cac517e..9faac05e0888 100644
--- a/lldb/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp
+++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp
@@ -62,13 +62,15 @@
 
 using namespace lldb_private;
 
+char ClangUserExpression::ID;
+
 ClangUserExpression::ClangUserExpression(
     ExecutionContextScope &exe_scope, llvm::StringRef expr,
     llvm::StringRef prefix, lldb::LanguageType language,
     ResultType desired_type, const EvaluateExpressionOptions &options,
     ValueObject *ctx_obj)
     : LLVMUserExpression(exe_scope, expr, prefix, language, desired_type,
-                         options, eKindClangUserExpression),
+                         options),
       m_type_system_helper(*m_target_wp.lock(), options.GetExecutionPolicy() ==
                                                     eExecutionPolicyTopLevel),
       m_result_delegate(exe_scope.CalculateTarget()), m_ctx_obj(ctx_obj) {

diff  --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangUserExpression.h b/lldb/source/Plugins/ExpressionParser/Clang/ClangUserExpression.h
index d94f9cc5e066..b8506a608de7 100644
--- a/lldb/source/Plugins/ExpressionParser/Clang/ClangUserExpression.h
+++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangUserExpression.h
@@ -38,11 +38,14 @@ namespace lldb_private {
 /// the objects needed to parse and interpret or JIT an expression.  It uses
 /// the Clang parser to produce LLVM IR from the expression.
 class ClangUserExpression : public LLVMUserExpression {
+  // LLVM RTTI support
+  static char ID;
+
 public:
-  /// LLVM-style RTTI support.
-  static bool classof(const Expression *E) {
-    return E->getKind() == eKindClangUserExpression;
+  bool isA(const void *ClassID) const override {
+    return ClassID == &ID || LLVMUserExpression::isA(ClassID);
   }
+  static bool classof(const Expression *obj) { return obj->isA(&ID); }
 
   enum { kDefaultTimeout = 500000u };
 

diff  --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangUtilityFunction.cpp b/lldb/source/Plugins/ExpressionParser/Clang/ClangUtilityFunction.cpp
index 564c62c6a2c6..1edf443d6970 100644
--- a/lldb/source/Plugins/ExpressionParser/Clang/ClangUtilityFunction.cpp
+++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangUtilityFunction.cpp
@@ -31,6 +31,8 @@
 
 using namespace lldb_private;
 
+char ClangUtilityFunction::ID;
+
 /// Constructor
 ///
 /// \param[in] text
@@ -40,7 +42,7 @@ using namespace lldb_private;
 ///     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, eKindClangUtilityFunction) {
+    : UtilityFunction(exe_scope, text, name) {
   m_function_text.assign(ClangExpressionSourceCode::g_expression_prefix);
   if (text && text[0])
     m_function_text.append(text);

diff  --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangUtilityFunction.h b/lldb/source/Plugins/ExpressionParser/Clang/ClangUtilityFunction.h
index 70ebb2f3ad8a..9efaa0254c3e 100644
--- a/lldb/source/Plugins/ExpressionParser/Clang/ClangUtilityFunction.h
+++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangUtilityFunction.h
@@ -33,11 +33,14 @@ namespace lldb_private {
 /// simply provide a way to push a function into the target for the debugger
 /// to call later on.
 class ClangUtilityFunction : public UtilityFunction {
+  // LLVM RTTI support
+  static char ID;
+
 public:
-  /// LLVM-style RTTI support.
-  static bool classof(const Expression *E) {
-    return E->getKind() == eKindClangUtilityFunction;
+  bool isA(const void *ClassID) const override {
+    return ClassID == &ID || UtilityFunction::isA(ClassID);
   }
+  static bool classof(const Expression *obj) { return obj->isA(&ID); }
 
   class ClangUtilityFunctionHelper : public ClangExpressionHelper {
   public:


        


More information about the lldb-commits mailing list