diff --git a/lldb/include/lldb/Expression/ExpressionTypeSystemHelper.h b/lldb/include/lldb/Expression/ExpressionTypeSystemHelper.h --- a/lldb/include/lldb/Expression/ExpressionTypeSystemHelper.h +++ b/lldb/include/lldb/Expression/ExpressionTypeSystemHelper.h @@ -11,35 +11,25 @@ #define LLDB_EXPRESSION_EXPRESSIONTYPESYSTEMHELPER_H #include "llvm/Support/Casting.h" +#include "llvm/Support/ExtensibleRTTI.h" namespace lldb_private { /// \class ExpressionTypeSystemHelper ExpressionTypeSystemHelper.h /// "lldb/Expression/ExpressionTypeSystemHelper.h" /// A helper object that the Expression can pass to its ExpressionParser -/// to provide generic information that -/// any type of expression will need to supply. It's only job is to support -/// dyn_cast so that the expression parser can cast it back to the requisite -/// specific type. +/// to provide generic information that any type of expression will need to +/// supply. It's only job is to support dyn_cast so that the expression parser +/// can cast it back to the requisite specific type. /// -class ExpressionTypeSystemHelper { +class ExpressionTypeSystemHelper + : public llvm::RTTIExtends { public: - enum LLVMCastKind { - eKindClangHelper, - eKindSwiftHelper, - eKindGoHelper, - kNumKinds - }; + /// LLVM RTTI support + static char ID; - LLVMCastKind getKind() const { return m_kind; } - - ExpressionTypeSystemHelper(LLVMCastKind kind) : m_kind(kind) {} - - ~ExpressionTypeSystemHelper() = default; - -protected: - LLVMCastKind m_kind; + virtual ~ExpressionTypeSystemHelper() = default; }; } // namespace lldb_private diff --git a/lldb/include/lldb/Expression/ExpressionVariable.h b/lldb/include/lldb/Expression/ExpressionVariable.h --- a/lldb/include/lldb/Expression/ExpressionVariable.h +++ b/lldb/include/lldb/Expression/ExpressionVariable.h @@ -18,19 +18,20 @@ #include "lldb/Core/ValueObject.h" #include "lldb/Utility/ConstString.h" #include "lldb/lldb-public.h" +#include "llvm/Support/ExtensibleRTTI.h" namespace lldb_private { class ExpressionVariable - : public std::enable_shared_from_this { + : public std::enable_shared_from_this, + public llvm::RTTIExtends { public: - // See TypeSystem.h for how to add subclasses to this. - enum LLVMCastKind { eKindClang, eKindSwift, eKindGo, kNumKinds }; + /// LLVM RTTI support + static char ID; - LLVMCastKind getKind() const { return m_kind; } + ExpressionVariable(); - ExpressionVariable(LLVMCastKind kind); - virtual ~ExpressionVariable(); + virtual ~ExpressionVariable() = default; std::optional GetByteSize() { return m_frozen_sp->GetByteSize(); } @@ -109,7 +110,6 @@ // these should be private lldb::ValueObjectSP m_frozen_sp; lldb::ValueObjectSP m_live_sp; - LLVMCastKind m_kind; }; /// \class ExpressionVariableList ExpressionVariable.h @@ -200,14 +200,13 @@ std::vector m_variables; }; -class PersistentExpressionState : public ExpressionVariableList { +class PersistentExpressionState + : public ExpressionVariableList, + public llvm::RTTIExtends { public: - // See TypeSystem.h for how to add subclasses to this. - enum LLVMCastKind { eKindClang, eKindSwift, eKindGo, kNumKinds }; + /// LLVM RTTI support + static char ID; - LLVMCastKind getKind() const { return m_kind; } - - PersistentExpressionState(LLVMCastKind kind); virtual ~PersistentExpressionState(); virtual lldb::ExpressionVariableSP @@ -237,8 +236,6 @@ GetPersistentVariablePrefix(bool is_error = false) const = 0; private: - LLVMCastKind m_kind; - typedef std::set ExecutionUnitSet; ExecutionUnitSet m_execution_units; ///< The execution units that contain valuable symbols. diff --git a/lldb/include/lldb/Expression/REPL.h b/lldb/include/lldb/Expression/REPL.h --- a/lldb/include/lldb/Expression/REPL.h +++ b/lldb/include/lldb/Expression/REPL.h @@ -15,17 +15,17 @@ #include "lldb/Interpreter/OptionGroupFormat.h" #include "lldb/Interpreter/OptionGroupValueObjectDisplay.h" #include "lldb/Target/Target.h" +#include "llvm/Support/ExtensibleRTTI.h" namespace lldb_private { -class REPL : public IOHandlerDelegate { +class REPL : public IOHandlerDelegate, + public llvm::RTTIExtends { public: - // See TypeSystem.h for how to add subclasses to this. - enum LLVMCastKind { eKindClang, eKindSwift, eKindGo, kNumKinds }; + /// LLVM RTTI support + static char ID; - LLVMCastKind getKind() const { return m_kind; } - - REPL(LLVMCastKind kind, Target &target); + REPL(Target &target); ~REPL() override; @@ -168,7 +168,6 @@ Target &m_target; lldb::IOHandlerSP m_io_handler_sp; - LLVMCastKind m_kind; private: std::string GetSourcePath(); diff --git a/lldb/source/Expression/CMakeLists.txt b/lldb/source/Expression/CMakeLists.txt --- a/lldb/source/Expression/CMakeLists.txt +++ b/lldb/source/Expression/CMakeLists.txt @@ -3,6 +3,7 @@ DWARFExpression.cpp DWARFExpressionList.cpp Expression.cpp + ExpressionTypeSystemHelper.cpp ExpressionVariable.cpp FunctionCaller.cpp IRExecutionUnit.cpp diff --git a/lldb/source/Expression/ExpressionTypeSystemHelper.cpp b/lldb/source/Expression/ExpressionTypeSystemHelper.cpp new file mode 100644 --- /dev/null +++ b/lldb/source/Expression/ExpressionTypeSystemHelper.cpp @@ -0,0 +1,13 @@ +//===-- ExpressionTypeSystemHelper.cpp ------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "lldb/Expression/ExpressionTypeSystemHelper.h" + +using namespace lldb_private; + +char ExpressionTypeSystemHelper::ID; diff --git a/lldb/source/Expression/ExpressionVariable.cpp b/lldb/source/Expression/ExpressionVariable.cpp --- a/lldb/source/Expression/ExpressionVariable.cpp +++ b/lldb/source/Expression/ExpressionVariable.cpp @@ -15,9 +15,9 @@ using namespace lldb_private; -ExpressionVariable::ExpressionVariable(LLVMCastKind kind) - : m_flags(0), m_kind(kind) {} -ExpressionVariable::~ExpressionVariable() = default; +char ExpressionVariable::ID; + +ExpressionVariable::ExpressionVariable() : m_flags(0) {} uint8_t *ExpressionVariable::GetValueBytes() { std::optional byte_size = m_frozen_sp->GetByteSize(); @@ -32,8 +32,8 @@ return nullptr; } -PersistentExpressionState::PersistentExpressionState(LLVMCastKind kind) - : m_kind(kind) {} +char PersistentExpressionState::ID; + PersistentExpressionState::~PersistentExpressionState() = default; lldb::addr_t PersistentExpressionState::LookupSymbol(ConstString name) { diff --git a/lldb/source/Expression/REPL.cpp b/lldb/source/Expression/REPL.cpp --- a/lldb/source/Expression/REPL.cpp +++ b/lldb/source/Expression/REPL.cpp @@ -22,7 +22,9 @@ using namespace lldb_private; -REPL::REPL(LLVMCastKind kind, Target &target) : m_target(target), m_kind(kind) { +char REPL::ID; + +REPL::REPL(Target &target) : m_target(target) { // Make sure all option values have sane defaults Debugger &debugger = m_target.GetDebugger(); debugger.SetShowProgress(false); diff --git a/lldb/source/Plugins/ExpressionParser/Clang/CMakeLists.txt b/lldb/source/Plugins/ExpressionParser/Clang/CMakeLists.txt --- a/lldb/source/Plugins/ExpressionParser/Clang/CMakeLists.txt +++ b/lldb/source/Plugins/ExpressionParser/Clang/CMakeLists.txt @@ -7,6 +7,7 @@ ClangASTSource.cpp ClangDeclVendor.cpp ClangExpressionDeclMap.cpp + ClangExpressionHelper.cpp ClangExpressionParser.cpp ClangExpressionSourceCode.cpp ClangExpressionUtil.cpp diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionHelper.h b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionHelper.h --- a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionHelper.h +++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionHelper.h @@ -27,18 +27,12 @@ class RecordingMemoryManager; // ClangExpressionHelper -class ClangExpressionHelper : public ExpressionTypeSystemHelper { +class ClangExpressionHelper + : public llvm::RTTIExtends { public: - static bool classof(const ExpressionTypeSystemHelper *ts) { - return ts->getKind() == eKindClangHelper; - } - - ClangExpressionHelper() - : ExpressionTypeSystemHelper( - ExpressionTypeSystemHelper::LLVMCastKind::eKindClangHelper) {} - - /// Destructor - virtual ~ClangExpressionHelper() = default; + // LLVM RTTI support + static char ID; /// Return the object that the parser should use when resolving external /// values. May be NULL if everything should be self-contained. @@ -54,8 +48,6 @@ ASTTransformer(clang::ASTConsumer *passthrough) = 0; virtual void CommitPersistentDecls() {} - -protected: }; } // namespace lldb_private diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionHelper.cpp b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionHelper.cpp new file mode 100644 --- /dev/null +++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionHelper.cpp @@ -0,0 +1,13 @@ +//===-- ClangExpressionHelper.cpp -----------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "ClangExpressionHelper.h" + +using namespace lldb_private; + +char ClangExpressionHelper::ID; diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionVariable.h b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionVariable.h --- a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionVariable.h +++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionVariable.h @@ -57,8 +57,12 @@ /// /// This class supports all of these use cases using simple type polymorphism, /// and provides necessary support methods. Its interface is RTTI-neutral. -class ClangExpressionVariable : public ExpressionVariable { +class ClangExpressionVariable + : public llvm::RTTIExtends { public: + // LLVM RTTI support + static char ID; + ClangExpressionVariable(ExecutionContextScope *exe_scope, lldb::ByteOrder byte_order, uint32_t addr_byte_size); @@ -197,11 +201,6 @@ TypeFromUser GetTypeFromUser(); - // llvm casting support - static bool classof(const ExpressionVariable *ev) { - return ev->getKind() == ExpressionVariable::eKindClang; - } - /// Members ClangExpressionVariable(const ClangExpressionVariable &) = delete; const ClangExpressionVariable & diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionVariable.cpp b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionVariable.cpp --- a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionVariable.cpp +++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionVariable.cpp @@ -20,11 +20,12 @@ using namespace lldb_private; using namespace clang; +char ClangExpressionVariable::ID; + ClangExpressionVariable::ClangExpressionVariable( ExecutionContextScope *exe_scope, lldb::ByteOrder byte_order, uint32_t addr_byte_size) - : ExpressionVariable(LLVMCastKind::eKindClang), m_parser_vars(), - m_jit_vars() { + : m_parser_vars(), m_jit_vars() { m_flags = EVNone; m_frozen_sp = ValueObjectConstResult::Create(exe_scope, byte_order, addr_byte_size); @@ -33,16 +34,14 @@ ClangExpressionVariable::ClangExpressionVariable( ExecutionContextScope *exe_scope, Value &value, ConstString name, uint16_t flags) - : ExpressionVariable(LLVMCastKind::eKindClang), m_parser_vars(), - m_jit_vars() { + : m_parser_vars(), m_jit_vars() { m_flags = flags; m_frozen_sp = ValueObjectConstResult::Create(exe_scope, value, name); } ClangExpressionVariable::ClangExpressionVariable( const lldb::ValueObjectSP &valobj_sp) - : ExpressionVariable(LLVMCastKind::eKindClang), m_parser_vars(), - m_jit_vars() { + : m_parser_vars(), m_jit_vars() { m_flags = EVNone; m_frozen_sp = valobj_sp; } @@ -51,8 +50,7 @@ ExecutionContextScope *exe_scope, ConstString name, const TypeFromUser &user_type, lldb::ByteOrder byte_order, uint32_t addr_byte_size) - : ExpressionVariable(LLVMCastKind::eKindClang), m_parser_vars(), - m_jit_vars() { + : m_parser_vars(), m_jit_vars() { m_flags = EVNone; m_frozen_sp = ValueObjectConstResult::Create(exe_scope, byte_order, addr_byte_size); diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangFunctionCaller.h b/lldb/source/Plugins/ExpressionParser/Clang/ClangFunctionCaller.h --- a/lldb/source/Plugins/ExpressionParser/Clang/ClangFunctionCaller.h +++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangFunctionCaller.h @@ -57,11 +57,14 @@ class ClangFunctionCaller : public FunctionCaller { friend class ASTStructExtractor; - class ClangFunctionCallerHelper : public ClangExpressionHelper { + class ClangFunctionCallerHelper + : public llvm::RTTIExtends { public: - ClangFunctionCallerHelper(ClangFunctionCaller &owner) : m_owner(owner) {} + // LLVM RTTI support + static char ID; - ~ClangFunctionCallerHelper() override = default; + ClangFunctionCallerHelper(ClangFunctionCaller &owner) : m_owner(owner) {} /// Return the object that the parser should use when resolving external /// values. May be NULL if everything should be self-contained. diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangFunctionCaller.cpp b/lldb/source/Plugins/ExpressionParser/Clang/ClangFunctionCaller.cpp --- a/lldb/source/Plugins/ExpressionParser/Clang/ClangFunctionCaller.cpp +++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangFunctionCaller.cpp @@ -207,6 +207,8 @@ return num_errors; } +char ClangFunctionCaller::ClangFunctionCallerHelper::ID; + clang::ASTConsumer * ClangFunctionCaller::ClangFunctionCallerHelper::ASTTransformer( clang::ASTConsumer *passthrough) { diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangPersistentVariables.h b/lldb/source/Plugins/ExpressionParser/Clang/ClangPersistentVariables.h --- a/lldb/source/Plugins/ExpressionParser/Clang/ClangPersistentVariables.h +++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangPersistentVariables.h @@ -31,17 +31,17 @@ /// A list of variables that can be accessed and updated by any expression. See /// ClangPersistentVariable for more discussion. Also provides an increasing, /// 0-based counter for naming result variables. -class ClangPersistentVariables : public PersistentExpressionState { +class ClangPersistentVariables + : public llvm::RTTIExtends { public: + // LLVM RTTI support + static char ID; + ClangPersistentVariables(std::shared_ptr target_sp); ~ClangPersistentVariables() override = default; - // llvm casting support - static bool classof(const PersistentExpressionState *pv) { - return pv->getKind() == PersistentExpressionState::eKindClang; - } - std::shared_ptr GetClangASTImporter(); std::shared_ptr GetClangModulesDeclVendor(); diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangPersistentVariables.cpp b/lldb/source/Plugins/ExpressionParser/Clang/ClangPersistentVariables.cpp --- a/lldb/source/Plugins/ExpressionParser/Clang/ClangPersistentVariables.cpp +++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangPersistentVariables.cpp @@ -26,10 +26,11 @@ using namespace lldb; using namespace lldb_private; +char ClangPersistentVariables::ID; + ClangPersistentVariables::ClangPersistentVariables( std::shared_ptr target_sp) - : lldb_private::PersistentExpressionState(LLVMCastKind::eKindClang), - m_target_sp(target_sp) {} + : m_target_sp(target_sp) {} ExpressionVariableSP ClangPersistentVariables::CreatePersistentVariable( const lldb::ValueObjectSP &valobj_sp) { diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangUserExpression.h b/lldb/source/Plugins/ExpressionParser/Clang/ClangUserExpression.h --- a/lldb/source/Plugins/ExpressionParser/Clang/ClangUserExpression.h +++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangUserExpression.h @@ -51,13 +51,16 @@ enum { kDefaultTimeout = 500000u }; - class ClangUserExpressionHelper : public ClangExpressionHelper { + class ClangUserExpressionHelper + : public llvm::RTTIExtends { public: + // LLVM RTTI support + static char ID; + ClangUserExpressionHelper(Target &target, bool top_level) : m_target(target), m_top_level(top_level) {} - ~ClangUserExpressionHelper() override = default; - /// Return the object that the parser should use when resolving external /// values. May be NULL if everything should be self-contained. ClangExpressionDeclMap *DeclMap() override { diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp b/lldb/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp --- a/lldb/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp +++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp @@ -981,6 +981,8 @@ return m_result_delegate.GetVariable(); } +char ClangUserExpression::ClangUserExpressionHelper::ID; + void ClangUserExpression::ClangUserExpressionHelper::ResetDeclMap( ExecutionContext &exe_ctx, Materializer::PersistentVariableDelegate &delegate, diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangUtilityFunction.h b/lldb/source/Plugins/ExpressionParser/Clang/ClangUtilityFunction.h --- a/lldb/source/Plugins/ExpressionParser/Clang/ClangUtilityFunction.h +++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangUtilityFunction.h @@ -72,11 +72,12 @@ ExecutionContext &exe_ctx) override; private: - class ClangUtilityFunctionHelper : public ClangExpressionHelper { + class ClangUtilityFunctionHelper + : public llvm::RTTIExtends { public: - ClangUtilityFunctionHelper() = default; - - ~ClangUtilityFunctionHelper() override = default; + // LLVM RTTI support + static char ID; /// Return the object that the parser should use when resolving external /// values. May be NULL if everything should be self-contained. diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangUtilityFunction.cpp b/lldb/source/Plugins/ExpressionParser/Clang/ClangUtilityFunction.cpp --- a/lldb/source/Plugins/ExpressionParser/Clang/ClangUtilityFunction.cpp +++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangUtilityFunction.cpp @@ -176,6 +176,8 @@ } } +char ClangUtilityFunction::ClangUtilityFunctionHelper::ID; + void ClangUtilityFunction::ClangUtilityFunctionHelper::ResetDeclMap( ExecutionContext &exe_ctx, bool keep_result_in_memory) { std::shared_ptr ast_importer; diff --git a/lldb/source/Plugins/REPL/Clang/ClangREPL.h b/lldb/source/Plugins/REPL/Clang/ClangREPL.h --- a/lldb/source/Plugins/REPL/Clang/ClangREPL.h +++ b/lldb/source/Plugins/REPL/Clang/ClangREPL.h @@ -14,8 +14,11 @@ namespace lldb_private { /// Implements a Clang-based REPL for C languages on top of LLDB's REPL /// framework. -class ClangREPL : public REPL { +class ClangREPL : public llvm::RTTIExtends { public: + // LLVM RTTI support + static char ID; + ClangREPL(lldb::LanguageType language, Target &target); ~ClangREPL() override; diff --git a/lldb/source/Plugins/REPL/Clang/ClangREPL.cpp b/lldb/source/Plugins/REPL/Clang/ClangREPL.cpp --- a/lldb/source/Plugins/REPL/Clang/ClangREPL.cpp +++ b/lldb/source/Plugins/REPL/Clang/ClangREPL.cpp @@ -15,8 +15,10 @@ LLDB_PLUGIN_DEFINE(ClangREPL) +char ClangREPL::ID; + ClangREPL::ClangREPL(lldb::LanguageType language, Target &target) - : REPL(eKindClang, target), m_language(language), + : llvm::RTTIExtends(target), m_language(language), m_implicit_expr_result_regex("\\$[0-9]+") {} ClangREPL::~ClangREPL() = default;