Implement and use isa/dyncast/cast etc for Type classes.

llvm-svn: 39175
This commit is contained in:
Chris Lattner 2006-11-12 00:56:20 +00:00
parent d5973ebbe2
commit 47814666e1
2 changed files with 15 additions and 2 deletions

View File

@ -77,8 +77,8 @@ TypeRef ASTContext::getPointerType(const TypeRef &T) {
// Unique pointers, to guarantee there is only one pointer of a particular
// structure.
for (unsigned i = 0, e = Types.size(); i != e; ++i)
if (Types[i]->getTypeClass() == Type::Pointer)
if (((PointerType*)Types[i])->getPointee() == T)
if (PointerType *PTy = dyn_cast<PointerType>(Types[i]))
if (PTy->getPointee() == T)
return Types[i];

View File

@ -14,6 +14,7 @@
#ifndef LLVM_CLANG_AST_TYPE_H
#define LLVM_CLANG_AST_TYPE_H
#include "llvm/Support/Casting.h"
#include "llvm/Support/DataTypes.h"
#include <cassert>
#include <iosfwd>
@ -157,6 +158,8 @@ public:
Type *getCanonicalType() const { return CanonicalType; }
virtual void print(std::ostream &OS) const = 0;
static bool classof(const Type *) { return true; }
};
/// BuiltinType - This class is used for builtin types like 'int'. Builtin
@ -167,6 +170,10 @@ public:
BuiltinType(const char *name) : Type(Builtin, 0), Name(name) {}
virtual void print(std::ostream &OS) const;
static bool classof(const Type *T) { return T->getTypeClass() == Builtin; }
static bool classof(const BuiltinType *) { return true; }
};
class PointerType : public Type {
@ -178,12 +185,18 @@ public:
TypeRef getPointee() const { return PointeeType; }
virtual void print(std::ostream &OS) const;
static bool classof(const Type *T) { return T->getTypeClass() == Pointer; }
static bool classof(const PointerType *) { return true; }
};
class TypedefType : public Type {
// Decl * here.
public:
static bool classof(const Type *T) { return T->getTypeClass() == Typedef; }
static bool classof(const TypedefType *) { return true; }
};