From: Chris Lattner Date: Tue, 31 Jul 2007 19:29:30 +0000 (+0000) Subject: split the rest of the type predicates into pure predicates: X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c8629630ce3e7f0da231bf10a4b39240caaac68a;p=clang split the rest of the type predicates into pure predicates: there is now an isXXXType and a getAsXXXType git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@40646 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/AST/Expr.cpp b/AST/Expr.cpp index 36ab0332cd..5fcd31a590 100644 --- a/AST/Expr.cpp +++ b/AST/Expr.cpp @@ -580,7 +580,7 @@ bool Expr::isNullPointerConstant(ASTContext &Ctx) const { 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; diff --git a/AST/Type.cpp b/AST/Type.cpp index 1c61c681ce..dc3ee8ebcb 100644 --- a/AST/Type.cpp +++ b/AST/Type.cpp @@ -56,11 +56,33 @@ bool Type::isDerivedType() const { } } -const FunctionType *Type::isFunctionType() const { +// FIXME: move inline +bool Type::isFunctionType() const { return isa(CanonicalType); } +bool Type::isPointerType() const { return isa(CanonicalType); } +bool Type::isReferenceType() const { return isa(CanonicalType); } +bool Type::isArrayType() const { return isa(CanonicalType); } +bool Type::isRecordType() const { return isa(CanonicalType); } +bool Type::isStructureType() const { + if (const RecordType *RT = dyn_cast(this)) + if (RT->getDecl()->getKind() == Decl::Struct) + return true; + return false; +} +bool Type::isUnionType() const { + if (const RecordType *RT = dyn_cast(this)) + if (RT->getDecl()->getKind() == Decl::Union) + return true; + return false; +} +bool Type::isVectorType() const { return isa(CanonicalType); } +bool Type::isOCUVectorType() const { return isa(CanonicalType); } + + +const FunctionType *Type::getAsFunctionType() 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)) @@ -68,10 +90,6 @@ const FunctionType *Type::isFunctionType() const { return 0; } -// FIXME: move inline -bool Type::isPointerType() const { return isa(CanonicalType); } -bool Type::isReferenceType() const { return isa(CanonicalType); } - const PointerType *Type::getAsPointerType() const { // If this is directly a pointer type, return it. if (const PointerType *PTy = dyn_cast(this)) @@ -96,7 +114,7 @@ const ReferenceType *Type::getAsReferenceType() const { 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(this)) return ATy; @@ -108,7 +126,7 @@ const ArrayType *Type::isArrayType() const { 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(this)) return RTy; @@ -120,32 +138,32 @@ const RecordType *Type::isRecordType() const { 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(this)) { - if (TT->getDecl()->getKind() == Decl::Struct) - return TT; + if (const RecordType *RT = dyn_cast(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(CanonicalType)) { - if (TT->getDecl()->getKind() == Decl::Struct) - return cast(cast(this)->LookThroughTypedefs()); + if (const RecordType *RT = dyn_cast(CanonicalType)) { + if (RT->getDecl()->getKind() == Decl::Struct) + return cast(cast(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(this)) { - if (TT->getDecl()->getKind() == Decl::Union) - return TT; + if (const RecordType *RT = dyn_cast(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(CanonicalType)) { - if (TT->getDecl()->getKind() == Decl::Union) - return cast(cast(this)->LookThroughTypedefs()); + if (const RecordType *RT = dyn_cast(CanonicalType)) { + if (RT->getDecl()->getKind() == Decl::Union) + return cast(cast(this)->LookThroughTypedefs()); } return 0; } @@ -154,7 +172,7 @@ bool Type::isComplexType() const { return isa(CanonicalType); } -const VectorType *Type::isVectorType() const { +const VectorType *Type::getAsVectorType() const { // Are we directly a vector type? if (const VectorType *VTy = dyn_cast(this)) return VTy; @@ -167,7 +185,7 @@ const VectorType *Type::isVectorType() const { 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(this)) return VTy; diff --git a/Sema/SemaExpr.cpp b/Sema/SemaExpr.cpp index 0db9879e41..940b5bea5f 100644 --- a/Sema/SemaExpr.cpp +++ b/Sema/SemaExpr.cpp @@ -314,8 +314,8 @@ ParseArraySubscriptExpr(ExprTy *Base, SourceLocation LLoc, 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 @@ ParseArraySubscriptExpr(ExprTy *Base, SourceLocation LLoc, 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 @@ ParseMemberReferenceExpr(ExprTy *Base, SourceLocation OpLoc, 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 @@ ParseCallExpr(ExprTy *fn, SourceLocation LParenLoc, 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 @@ void Sema::DefaultFunctionArrayConversion(Expr *&e) { } 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())); } diff --git a/include/clang/AST/Type.h b/include/clang/AST/Type.h index c1096555e5..ceba2fa0b0 100644 --- a/include/clang/AST/Type.h +++ b/include/clang/AST/Type.h @@ -232,27 +232,35 @@ public: 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 @@ class RecordType : public TagType { RecordType(); // DO NOT IMPLEMENT public: - const RecordDecl *getDecl() { - return reinterpret_cast(TagType::getDecl()); - } RecordDecl *getDecl() const { return reinterpret_cast(TagType::getDecl()); }