From 7064f5c95bbdb17680d0ea658d4090898c2592d3 Mon Sep 17 00:00:00 2001 From: Steve Naroff Date: Thu, 26 Jul 2007 18:32:01 +0000 Subject: [PATCH] Add Type::isOCUVectorType(). Convert isFunctionType(), isStructureType(), and isUnionType() to the new API. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@40541 91177308-0d34-0410-b5e6-96231b3b80d8 --- AST/Type.cpp | 51 +++++++++++++++++++++++++++++++++------- include/clang/AST/Type.h | 17 +++++++++----- 2 files changed, 54 insertions(+), 14 deletions(-) diff --git a/AST/Type.cpp b/AST/Type.cpp index 560e4c1ba6..90cd7d0098 100644 --- a/AST/Type.cpp +++ b/AST/Type.cpp @@ -56,8 +56,16 @@ bool Type::isDerivedType() const { } } -bool Type::isFunctionType() const { - return isa(CanonicalType); +const FunctionType *Type::isFunctionType() const { + // If this is directly a function type, return it. + if (const FunctionType *FTy = dyn_cast(this)) + return FTy; + + // If this is a typedef for a function type, strip the typedef off without + // losing all typedef information. + if (isa(CanonicalType)) + return cast(cast(this)->LookThroughTypedefs()); + return 0; } const PointerType *Type::isPointerType() const { @@ -108,20 +116,34 @@ const RecordType *Type::isRecordType() const { return 0; } -bool Type::isStructureType() const { +const TagType *Type::isStructureType() const { + // If this is directly a structure type, return it. + if (const TagType *TT = dyn_cast(this)) { + if (TT->getDecl()->getKind() == Decl::Struct) + return TT; + } + // If this is a typedef for a structure type, strip the typedef off without + // losing all typedef information. if (const TagType *TT = dyn_cast(CanonicalType)) { if (TT->getDecl()->getKind() == Decl::Struct) - return true; + return cast(cast(this)->LookThroughTypedefs()); } - return false; + return 0; } -bool Type::isUnionType() const { +const TagType *Type::isUnionType() const { + // If this is directly a union type, return it. + if (const TagType *TT = dyn_cast(this)) { + if (TT->getDecl()->getKind() == Decl::Union) + return TT; + } + // If this is a typedef for a union type, strip the typedef off without + // losing all typedef information. if (const TagType *TT = dyn_cast(CanonicalType)) { if (TT->getDecl()->getKind() == Decl::Union) - return true; + return cast(cast(this)->LookThroughTypedefs()); } - return false; + return 0; } bool Type::isComplexType() const { @@ -141,6 +163,19 @@ const VectorType *Type::isVectorType() const { return 0; } +const OCUVectorType *Type::isOCUVectorType() const { + // Are we directly an OpenCU vector type? + if (const OCUVectorType *VTy = dyn_cast(this)) + return VTy; + + // If this is a typedef for an OpenCU vector type, strip the typedef off + // without losing all typedef information. + if (isa(CanonicalType)) + return cast(cast(this)->LookThroughTypedefs()); + + return 0; +} + // C99 6.2.7p1: If both are complete types, then the following additional // requirements apply...FIXME (handle compatibility across source files). diff --git a/include/clang/AST/Type.h b/include/clang/AST/Type.h index c6c31245ff..17d2d0a3c0 100644 --- a/include/clang/AST/Type.h +++ b/include/clang/AST/Type.h @@ -37,6 +37,9 @@ namespace clang { class VectorType; class ArrayType; class RecordType; + class TagType; + class FunctionType; + class OCUVectorType; /// QualType - For efficiency, we don't store CVR-qualified types as nodes on /// their own: instead each reference to a type stores the qualifiers. This @@ -212,9 +215,6 @@ public: /// of memory that can be examined and stored into (H&S). bool isObjectType() const; - /// isFunctionType - types that describe functions. - bool isFunctionType() const; - /// isIncompleteType - Return true if this is an incomplete type. /// A type that can describe objects, but which lacks information needed to /// determine its size (e.g. void, or a fwd declared struct). Clients of this @@ -234,15 +234,17 @@ public: /// Vector types const VectorType *isVectorType() const; // GCC vector type. + const OCUVectorType *isOCUVectorType() const; // OCU vector type. - /// Derived types (C99 6.2.5p20). isFunctionType() is also a derived type. + /// Derived types (C99 6.2.5p20). bool isDerivedType() const; + const FunctionType *isFunctionType() const; const PointerType *isPointerType() const; const ReferenceType *isReferenceType() const; const ArrayType *isArrayType() const; const RecordType *isRecordType() const; - bool isStructureType() const; - bool isUnionType() const; + const TagType *isStructureType() const; + const TagType *isUnionType() const; bool isVoidType() const; // C99 6.2.5p19 bool isScalarType() const; // C99 6.2.5p21 (arithmetic + pointers) @@ -502,6 +504,9 @@ class OCUVectorType : public VectorType { VectorType(OCUVector, vecType, nElements, canonType) {} friend class ASTContext; // ASTContext creates these. public: + static bool classof(const Type *T) { + return T->getTypeClass() == Vector || T->getTypeClass() == OCUVector; + } static bool classof(const VectorType *T) { return T->getTypeClass() == OCUVector; } -- 2.40.0