[cfe-commits] r40646 - in /cfe/trunk: AST/Expr.cpp AST/Type.cpp Sema/SemaExpr.cpp include/clang/AST/Type.h

Chris Lattner sabre at nondot.org
Tue Jul 31 12:29:30 PDT 2007


Author: lattner
Date: Tue Jul 31 14:29:30 2007
New Revision: 40646

URL: http://llvm.org/viewvc/llvm-project?rev=40646&view=rev
Log:
split the rest of the type predicates into pure predicates:
there is now an isXXXType and a getAsXXXType

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

Modified: cfe/trunk/AST/Expr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/AST/Expr.cpp?rev=40646&r1=40645&r2=40646&view=diff

==============================================================================
--- cfe/trunk/AST/Expr.cpp (original)
+++ cfe/trunk/AST/Expr.cpp Tue Jul 31 14:29:30 2007
@@ -580,7 +580,7 @@
 OCUVectorComponent::ComponentType OCUVectorComponent::getComponentType() const {
   // derive the component type, no need to waste space.
   const char *compStr = Accessor.getName();
-  const OCUVectorType *VT = getType()->isOCUVectorType();
+  const OCUVectorType *VT = getType()->getAsOCUVectorType();
   if (VT->isPointAccessor(*compStr)) return Point;
   if (VT->isColorAccessor(*compStr)) return Color;
   if (VT->isTextureAccessor(*compStr)) return Texture;

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

==============================================================================
--- cfe/trunk/AST/Type.cpp (original)
+++ cfe/trunk/AST/Type.cpp Tue Jul 31 14:29:30 2007
@@ -56,11 +56,33 @@
   }
 }
 
-const FunctionType *Type::isFunctionType() const {
+// FIXME: move inline
+bool Type::isFunctionType() const { return isa<FunctionType>(CanonicalType); }
+bool Type::isPointerType() const { return isa<PointerType>(CanonicalType); }
+bool Type::isReferenceType() const { return isa<ReferenceType>(CanonicalType); }
+bool Type::isArrayType() const { return isa<ArrayType>(CanonicalType); }
+bool Type::isRecordType() const { return isa<RecordType>(CanonicalType); }
+bool Type::isStructureType() const {
+  if (const RecordType *RT = dyn_cast<RecordType>(this))
+    if (RT->getDecl()->getKind() == Decl::Struct)
+      return true;
+  return false;
+}
+bool Type::isUnionType() const {
+  if (const RecordType *RT = dyn_cast<RecordType>(this))
+    if (RT->getDecl()->getKind() == Decl::Union)
+      return true;
+  return false;
+}
+bool Type::isVectorType() const { return isa<VectorType>(CanonicalType); }
+bool Type::isOCUVectorType() const { return isa<OCUVectorType>(CanonicalType); }
+    
+
+const FunctionType *Type::getAsFunctionType() 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))
@@ -68,10 +90,6 @@
   return 0;
 }
 
-// FIXME: move inline
-bool Type::isPointerType() const { return isa<PointerType>(CanonicalType); }
-bool Type::isReferenceType() const { return isa<ReferenceType>(CanonicalType); }
-
 const PointerType *Type::getAsPointerType() const {
   // If this is directly a pointer type, return it.
   if (const PointerType *PTy = dyn_cast<PointerType>(this))
@@ -96,7 +114,7 @@
   return 0;
 }
 
-const ArrayType *Type::isArrayType() const {
+const ArrayType *Type::getAsArrayType() const {
   // If this is directly a reference type, return it.
   if (const ArrayType *ATy = dyn_cast<ArrayType>(this))
     return ATy;
@@ -108,7 +126,7 @@
   return 0;
 }
 
-const RecordType *Type::isRecordType() const {
+const RecordType *Type::getAsRecordType() const {
   // If this is directly a reference type, return it.
   if (const RecordType *RTy = dyn_cast<RecordType>(this))
     return RTy;
@@ -120,32 +138,32 @@
   return 0;
 }
 
-const TagType *Type::isStructureType() const {
+const RecordType *Type::getAsStructureType() 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 (const RecordType *RT = dyn_cast<RecordType>(this)) {
+    if (RT->getDecl()->getKind() == Decl::Struct)
+      return RT;
   }
   // 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 cast<TagType>(cast<TypedefType>(this)->LookThroughTypedefs());
+  if (const RecordType *RT = dyn_cast<RecordType>(CanonicalType)) {
+    if (RT->getDecl()->getKind() == Decl::Struct)
+      return cast<RecordType>(cast<TypedefType>(this)->LookThroughTypedefs());
   }
   return 0;
 }
 
-const TagType *Type::isUnionType() const { 
+const RecordType *Type::getAsUnionType() 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 (const RecordType *RT = dyn_cast<RecordType>(this)) {
+    if (RT->getDecl()->getKind() == Decl::Union)
+      return RT;
   }
   // 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 cast<TagType>(cast<TypedefType>(this)->LookThroughTypedefs());
+  if (const RecordType *RT = dyn_cast<RecordType>(CanonicalType)) {
+    if (RT->getDecl()->getKind() == Decl::Union)
+      return cast<RecordType>(cast<TypedefType>(this)->LookThroughTypedefs());
   }
   return 0;
 }
@@ -154,7 +172,7 @@
   return isa<ComplexType>(CanonicalType);
 }
 
-const VectorType *Type::isVectorType() const {
+const VectorType *Type::getAsVectorType() const {
   // Are we directly a vector type?
   if (const VectorType *VTy = dyn_cast<VectorType>(this))
     return VTy;
@@ -167,7 +185,7 @@
   return 0;
 }
 
-const OCUVectorType *Type::isOCUVectorType() const {
+const OCUVectorType *Type::getAsOCUVectorType() const {
   // Are we directly an OpenCU vector type?
   if (const OCUVectorType *VTy = dyn_cast<OCUVectorType>(this))
     return VTy;

Modified: cfe/trunk/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Sema/SemaExpr.cpp?rev=40646&r1=40645&r2=40646&view=diff

==============================================================================
--- cfe/trunk/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/Sema/SemaExpr.cpp Tue Jul 31 14:29:30 2007
@@ -314,8 +314,8 @@
     IndexExpr = LHSExp;
     // FIXME: need to deal with const...
     ResultType = PTy->getPointeeType();
-  } else if (const VectorType *VTy = LHSTy->isVectorType()) { // vectors: V[123]
-    BaseExpr = LHSExp;
+  } else if (const VectorType *VTy = LHSTy->getAsVectorType()) {
+    BaseExpr = LHSExp;    // vectors: V[123]
     IndexExpr = RHSExp;
     // FIXME: need to deal with const...
     ResultType = VTy->getElementType();
@@ -342,7 +342,7 @@
 QualType Sema::
 CheckOCUVectorComponent(QualType baseType, SourceLocation OpLoc,
                         IdentifierInfo &CompName, SourceLocation CompLoc) {
-  const OCUVectorType *vecType = baseType->isOCUVectorType();
+  const OCUVectorType *vecType = baseType->getAsOCUVectorType();
   
   // The vector accessor can't exceed the number of elements.
   const char *compStr = CompName.getName();
@@ -416,7 +416,7 @@
                   SourceRange(MemberLoc));
   }
   // The base type is either a record or an OCUVectorType.
-  if (const RecordType *RTy = BaseType->isRecordType()) {
+  if (const RecordType *RTy = BaseType->getAsRecordType()) {
     RecordDecl *RDecl = RTy->getDecl();
     if (RTy->isIncompleteType())
       return Diag(OpLoc, diag::err_typecheck_incomplete_tag, RDecl->getName(),
@@ -499,7 +499,7 @@
       QualType rhsType = argExpr->getType();
 
       // If necessary, apply function/array conversion. C99 6.7.5.3p[7,8]. 
-      if (const ArrayType *ary = lhsType->isArrayType())
+      if (const ArrayType *ary = lhsType->getAsArrayType())
         lhsType = Context.getPointerType(ary->getElementType());
       else if (lhsType->isFunctionType())
         lhsType = Context.getPointerType(lhsType);
@@ -706,7 +706,7 @@
   }
   if (t->isFunctionType())
     promoteExprToType(e, Context.getPointerType(t));
-  else if (const ArrayType *ary = t->isArrayType())
+  else if (const ArrayType *ary = t->getAsArrayType())
     promoteExprToType(e, Context.getPointerType(ary->getElementType()));
 }
 

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

==============================================================================
--- cfe/trunk/include/clang/AST/Type.h (original)
+++ cfe/trunk/include/clang/AST/Type.h Tue Jul 31 14:29:30 2007
@@ -232,27 +232,35 @@
   bool isFloatingType() const;     // C99 6.2.5p11 (real floating + complex)
   bool isRealType() const;         // C99 6.2.5p17 (real floating + integer)
   bool isArithmeticType() const;   // C99 6.2.5p18 (integer + floating)
+  bool isVoidType() const;         // C99 6.2.5p19
+  bool isDerivedType() const;      // C99 6.2.5p20
+  bool isScalarType() const;       // C99 6.2.5p21 (arithmetic + pointers)
+  bool isAggregateType() const;    // C99 6.2.5p21 (arrays, structures)
   
-  /// Vector types
-  const VectorType *isVectorType() const; // GCC vector type.
-  const OCUVectorType *isOCUVectorType() const; // OCU vector type.
-  
-  /// Derived types (C99 6.2.5p20).
-  bool isDerivedType() const;
-  const FunctionType *isFunctionType() const;   
-
+  // Type Predicates: Check to see if this type is structurally the specified
+  // type, ignoring typedefs.
+  bool isFunctionType() const;
   bool isPointerType() const;
   bool isReferenceType() const;
+  bool isArrayType() const;
+  bool isRecordType() const;
+  bool isStructureType() const;   
+  bool isUnionType() const;
+  bool isVectorType() const; // GCC vector type.
+  bool isOCUVectorType() const; // OCU vector type.
+  
+  // Type Checking Functions: Check to see if this type is structurally the
+  // specified type, ignoring typedefs, and return a pointer to the best type
+  // we can.
+  const FunctionType *getAsFunctionType() const;   
   const PointerType *getAsPointerType() const;
   const ReferenceType *getAsReferenceType() const;
-  const ArrayType *isArrayType() const;
-  const RecordType *isRecordType() 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)
-  bool isAggregateType() const;    // C99 6.2.5p21 (arrays, structures)
+  const ArrayType *getAsArrayType() const;
+  const RecordType *getAsRecordType() const;
+  const RecordType *getAsStructureType() const;   
+  const RecordType *getAsUnionType() const;
+  const VectorType *getAsVectorType() const; // GCC vector type.
+  const OCUVectorType *getAsOCUVectorType() const; // OCU vector type.
   
   /// More type predicates useful for type checking/promotion
   bool isPromotableIntegerType() const; // C99 6.3.1.1p2
@@ -717,9 +725,6 @@
   RecordType(); // DO NOT IMPLEMENT
 public:
     
-  const RecordDecl *getDecl() {
-    return reinterpret_cast<RecordDecl*>(TagType::getDecl());
-  }
   RecordDecl *getDecl() const {
     return reinterpret_cast<RecordDecl*>(TagType::getDecl());
   }





More information about the cfe-commits mailing list