[cfe-commits] r40541 - in /cfe/trunk: AST/Type.cpp include/clang/AST/Type.h

Steve Naroff snaroff at apple.com
Thu Jul 26 11:32:01 PDT 2007


Author: snaroff
Date: Thu Jul 26 13:32:01 2007
New Revision: 40541

URL: http://llvm.org/viewvc/llvm-project?rev=40541&view=rev
Log:

Add Type::isOCUVectorType().
Convert isFunctionType(), isStructureType(), and isUnionType() to the new API.


Modified:
    cfe/trunk/AST/Type.cpp
    cfe/trunk/include/clang/AST/Type.h

Modified: cfe/trunk/AST/Type.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/AST/Type.cpp?rev=40541&r1=40540&r2=40541&view=diff

==============================================================================
--- cfe/trunk/AST/Type.cpp (original)
+++ cfe/trunk/AST/Type.cpp Thu Jul 26 13:32:01 2007
@@ -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).

Modified: cfe/trunk/include/clang/AST/Type.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Type.h?rev=40541&r1=40540&r2=40541&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/Type.h (original)
+++ cfe/trunk/include/clang/AST/Type.h Thu Jul 26 13:32:01 2007
@@ -37,6 +37,9 @@
   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 @@
   /// 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 @@
   
   /// 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 @@
     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; 
   }





More information about the cfe-commits mailing list