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
diff --git a/AST/Type.cpp b/AST/Type.cpp
index 560e4c1..90cd7d0 100644
--- a/AST/Type.cpp
+++ b/AST/Type.cpp
@@ -56,8 +56,16 @@
}
}
-bool Type::isFunctionType() const {
- return isa<FunctionType>(CanonicalType);
+const FunctionType *Type::isFunctionType() const {
+ // If this is directly a function type, return it.
+ if (const FunctionType *FTy = dyn_cast<FunctionType>(this))
+ return FTy;
+
+ // If this is a typedef for a function type, strip the typedef off without
+ // losing all typedef information.
+ if (isa<FunctionType>(CanonicalType))
+ return cast<FunctionType>(cast<TypedefType>(this)->LookThroughTypedefs());
+ return 0;
}
const PointerType *Type::isPointerType() const {
@@ -108,20 +116,34 @@
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<TagType>(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<TagType>(CanonicalType)) {
if (TT->getDecl()->getKind() == Decl::Struct)
- return true;
+ return cast<TagType>(cast<TypedefType>(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<TagType>(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<TagType>(CanonicalType)) {
if (TT->getDecl()->getKind() == Decl::Union)
- return true;
+ return cast<TagType>(cast<TypedefType>(this)->LookThroughTypedefs());
}
- return false;
+ return 0;
}
bool Type::isComplexType() const {
@@ -141,6 +163,19 @@
return 0;
}
+const OCUVectorType *Type::isOCUVectorType() const {
+ // Are we directly an OpenCU vector type?
+ if (const OCUVectorType *VTy = dyn_cast<OCUVectorType>(this))
+ return VTy;
+
+ // If this is a typedef for an OpenCU vector type, strip the typedef off
+ // without losing all typedef information.
+ if (isa<OCUVectorType>(CanonicalType))
+ return cast<OCUVectorType>(cast<TypedefType>(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).