Commit 52f3a2fa authored by Raphael Isemann's avatar Raphael Isemann
Browse files

[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
parent 6cc853b4
Loading
Loading
Loading
Loading
+5 −19
Original line number Diff line number Diff line
@@ -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 @@ public:

  virtual ExpressionTypeSystemHelper *GetTypeSystemHelper() { return nullptr; }

  /// LLVM-style RTTI support.
  ExpressionKind getKind() const { return m_kind; }
  // LLVM RTTI support
  virtual bool isA(const void *ClassID) const = 0;

private:
  /// LLVM-style RTTI support.
  const ExpressionKind m_kind;
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
+6 −5
Original line number Diff line number Diff line
@@ -54,11 +54,12 @@ 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
  ///
+7 −5
Original line number Diff line number Diff line
@@ -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 @@ public:
  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(
+7 −7
Original line number Diff line number Diff line
@@ -33,11 +33,12 @@ 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 };

@@ -61,8 +62,7 @@ public:
  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;
+7 −6
Original line number Diff line number Diff line
@@ -28,11 +28,12 @@ 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
  ///
@@ -42,7 +43,7 @@ public:
  /// \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;

Loading