From 52f3a2faf92c4d8efd0e626d52d5f64b7c5d468f Mon Sep 17 00:00:00 2001 From: Raphael Isemann Date: Tue, 12 Nov 2019 10:04:32 +0100 Subject: [PATCH] [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 --- lldb/include/lldb/Expression/Expression.h | 24 +++++----------------- lldb/include/lldb/Expression/FunctionCaller.h | 11 +++++----- lldb/include/lldb/Expression/LLVMUserExpression.h | 12 ++++++----- lldb/include/lldb/Expression/UserExpression.h | 14 ++++++------- lldb/include/lldb/Expression/UtilityFunction.h | 13 ++++++------ lldb/source/Expression/Expression.cpp | 10 ++++----- lldb/source/Expression/FunctionCaller.cpp | 6 ++++-- lldb/source/Expression/LLVMUserExpression.cpp | 12 +++++------ lldb/source/Expression/UserExpression.cpp | 7 ++++--- lldb/source/Expression/UtilityFunction.cpp | 11 +++++----- .../ExpressionParser/Clang/ClangFunctionCaller.cpp | 2 ++ .../ExpressionParser/Clang/ClangFunctionCaller.h | 13 +++++++----- .../ExpressionParser/Clang/ClangUserExpression.cpp | 4 +++- .../ExpressionParser/Clang/ClangUserExpression.h | 9 +++++--- .../Clang/ClangUtilityFunction.cpp | 4 +++- .../ExpressionParser/Clang/ClangUtilityFunction.h | 9 +++++--- 16 files changed, 83 insertions(+), 78 deletions(-) diff --git a/lldb/include/lldb/Expression/Expression.h b/lldb/include/lldb/Expression/Expression.h index fca5fb9..e0ea7e9 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 @@ public: 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 ea9d020..6f60750 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 5f4c43c..2679c01 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 @@ 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( diff --git a/lldb/include/lldb/Expression/UserExpression.h b/lldb/include/lldb/Expression/UserExpression.h index b1d52f8..02d2991 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 @@ 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; diff --git a/lldb/include/lldb/Expression/UtilityFunction.h b/lldb/include/lldb/Expression/UtilityFunction.h index 26da081..8a11e2f 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 @@ 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; diff --git a/lldb/source/Expression/Expression.cpp b/lldb/source/Expression/Expression.cpp index 8e1ef69..71369d0b 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 203cfff..dc80c81 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 : ""), + : Expression(exe_scope), m_execution_unit_sp(), m_parser(), + m_jit_module_wp(), m_name(name ? name : ""), 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 ee72e7c..1fc878b 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 e2d1d2f..9e3c8ad 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 aac8b33..2dbc0e9 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 3eeb50c..7f7c0a9 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 24f6f2e..45bd1f4 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 60592ca..9faac05 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 d94f9cc..b8506a6 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 564c62c..1edf443 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 70ebb2f..9efaa02 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: -- 2.7.4