[lldb][NFC] Move TypeSystem RTTI to static variable to remove swift reference

This commit is contained in:
Raphael Isemann 2019-11-27 10:27:25 +01:00
parent e20a1e486e
commit 92d5ea5d16
6 changed files with 17 additions and 53 deletions

View File

@ -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 = "");

View File

@ -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 @@ public:
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 {

View File

@ -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);

View File

@ -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<ClangASTContext>(m_type_system);
}
ConstString CompilerDecl::GetName() const {

View File

@ -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 <vector>
@ -24,7 +25,7 @@ CompilerDeclContext::FindDeclByName(ConstString name,
}
bool CompilerDeclContext::IsClang() const {
return IsValid() && m_type_system->getKind() == TypeSystem::eKindClang;
return IsValid() && llvm::isa<ClangASTContext>(m_type_system);
}
ConstString CompilerDeclContext::GetName() const {

View File

@ -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,