diff --git a/lldb/include/lldb/Symbol/ClangASTContext.h b/lldb/include/lldb/Symbol/ClangASTContext.h index f4428c68218257..20421bca305edf 100644 --- a/lldb/include/lldb/Symbol/ClangASTContext.h +++ b/lldb/include/lldb/Symbol/ClangASTContext.h @@ -41,15 +41,17 @@ namespace lldb_private { class Declaration; class ClangASTContext : public TypeSystem { + // LLVM RTTI support + static char ID; + public: typedef void (*CompleteTagDeclCallback)(void *baton, clang::TagDecl *); typedef void (*CompleteObjCInterfaceDeclCallback)(void *baton, clang::ObjCInterfaceDecl *); // llvm casting support - static bool classof(const TypeSystem *ts) { - return ts->getKind() == TypeSystem::eKindClang; - } + bool isA(const void *ClassID) const override { return ClassID == &ID; } + static bool classof(const TypeSystem *ts) { return ts->isA(&ID); } // Constructors and Destructors explicit ClangASTContext(llvm::StringRef triple = ""); diff --git a/lldb/include/lldb/Symbol/TypeSystem.h b/lldb/include/lldb/Symbol/TypeSystem.h index 6283d67baba520..ea860647fdb1c4 100644 --- a/lldb/include/lldb/Symbol/TypeSystem.h +++ b/lldb/include/lldb/Symbol/TypeSystem.h @@ -52,47 +52,11 @@ struct LanguageSet { /// Interface for representing the Type Systems in different languages. class TypeSystem : public PluginInterface { public: - // Intrusive type system that allows us to use llvm casting. - // - // To add a new type system: - // - // 1 - Add a new enumeration for llvm casting below for your TypeSystem - // subclass, here we will use eKindFoo - // - // 2 - Your TypeSystem subclass will inherit from TypeSystem and needs - // to implement a static classof() function that returns your - // enumeration: - // - // class Foo : public lldb_private::TypeSystem - // { - // static bool classof(const TypeSystem *ts) - // { - // return ts->getKind() == TypeSystem::eKindFoo; - // } - // }; - // - // 3 - Contruct your TypeSystem subclass with the enumeration from below - // - // Foo() : - // TypeSystem(TypeSystem::eKindFoo), - // ... - // { - // } - // - // Then you can use the llvm casting on any "TypeSystem *" to get an instance - // of your subclass. - enum LLVMCastKind { - eKindClang, - eKindSwift, - kNumKinds - }; - // Constructors and Destructors - TypeSystem(LLVMCastKind kind); - ~TypeSystem() override; - LLVMCastKind getKind() const { return m_kind; } + // LLVM RTTI support + virtual bool isA(const void *ClassID) const = 0; static lldb::TypeSystemSP CreateInstance(lldb::LanguageType language, Module *module); @@ -493,8 +457,7 @@ class TypeSystem : public PluginInterface { virtual bool IsMeaninglessWithoutDynamicResolution(void *type); protected: - const LLVMCastKind m_kind; // Support for llvm casting - SymbolFile *m_sym_file; + SymbolFile *m_sym_file = nullptr; }; class TypeSystemMap { diff --git a/lldb/source/Symbol/ClangASTContext.cpp b/lldb/source/Symbol/ClangASTContext.cpp index 244ac8ce5ff87b..e413029f030059 100644 --- a/lldb/source/Symbol/ClangASTContext.cpp +++ b/lldb/source/Symbol/ClangASTContext.cpp @@ -337,6 +337,8 @@ static ClangASTMap &GetASTMap() { return *g_map_ptr; } +char ClangASTContext::ID; + bool ClangASTContext::IsOperator(llvm::StringRef name, clang::OverloadedOperatorKind &op_kind) { // All operators have to start with "operator". @@ -522,8 +524,7 @@ static void ParseLangArgs(LangOptions &Opts, InputKind IK, const char *triple) { Opts.NoInlineDefine = !Opt; } -ClangASTContext::ClangASTContext(llvm::StringRef target_triple) - : TypeSystem(TypeSystem::eKindClang) { +ClangASTContext::ClangASTContext(llvm::StringRef target_triple) { if (!target_triple.empty()) SetTargetTriple(target_triple); // The caller didn't pass an ASTContext so create a new one for this @@ -531,16 +532,14 @@ ClangASTContext::ClangASTContext(llvm::StringRef target_triple) CreateASTContext(); } -ClangASTContext::ClangASTContext(ArchSpec arch) - : TypeSystem(TypeSystem::eKindClang) { +ClangASTContext::ClangASTContext(ArchSpec arch) { SetTargetTriple(arch.GetTriple().str()); // The caller didn't pass an ASTContext so create a new one for this // ClangASTContext. CreateASTContext(); } -ClangASTContext::ClangASTContext(ASTContext &existing_ctxt) - : TypeSystem(TypeSystem::eKindClang) { +ClangASTContext::ClangASTContext(ASTContext &existing_ctxt) { SetTargetTriple(existing_ctxt.getTargetInfo().getTriple().str()); m_ast_up.reset(&existing_ctxt); diff --git a/lldb/source/Symbol/CompilerDecl.cpp b/lldb/source/Symbol/CompilerDecl.cpp index 2c64113a2bbeba..3d17d802dd0448 100644 --- a/lldb/source/Symbol/CompilerDecl.cpp +++ b/lldb/source/Symbol/CompilerDecl.cpp @@ -7,13 +7,14 @@ //===----------------------------------------------------------------------===// #include "lldb/Symbol/CompilerDecl.h" +#include "lldb/Symbol/ClangASTContext.h" #include "lldb/Symbol/CompilerDeclContext.h" #include "lldb/Symbol/TypeSystem.h" using namespace lldb_private; bool CompilerDecl::IsClang() const { - return IsValid() && m_type_system->getKind() == TypeSystem::eKindClang; + return IsValid() && llvm::isa(m_type_system); } ConstString CompilerDecl::GetName() const { diff --git a/lldb/source/Symbol/CompilerDeclContext.cpp b/lldb/source/Symbol/CompilerDeclContext.cpp index a6f046c4eb22ea..7d45f47ad133c1 100644 --- a/lldb/source/Symbol/CompilerDeclContext.cpp +++ b/lldb/source/Symbol/CompilerDeclContext.cpp @@ -7,6 +7,7 @@ //===----------------------------------------------------------------------===// #include "lldb/Symbol/CompilerDeclContext.h" +#include "lldb/Symbol/ClangASTContext.h" #include "lldb/Symbol/CompilerDecl.h" #include "lldb/Symbol/TypeSystem.h" #include @@ -24,7 +25,7 @@ CompilerDeclContext::FindDeclByName(ConstString name, } bool CompilerDeclContext::IsClang() const { - return IsValid() && m_type_system->getKind() == TypeSystem::eKindClang; + return IsValid() && llvm::isa(m_type_system); } ConstString CompilerDeclContext::GetName() const { diff --git a/lldb/source/Symbol/TypeSystem.cpp b/lldb/source/Symbol/TypeSystem.cpp index c63f24aea33543..4e746bd18e1f3b 100644 --- a/lldb/source/Symbol/TypeSystem.cpp +++ b/lldb/source/Symbol/TypeSystem.cpp @@ -43,8 +43,6 @@ size_t LanguageSet::Size() const { return bitvector.count(); } bool LanguageSet::Empty() const { return bitvector.none(); } bool LanguageSet::operator[](unsigned i) const { return bitvector[i]; } -TypeSystem::TypeSystem(LLVMCastKind kind) : m_kind(kind), m_sym_file(nullptr) {} - TypeSystem::~TypeSystem() {} static lldb::TypeSystemSP CreateInstanceHelper(lldb::LanguageType language,