split the rest of the type predicates into pure predicates:

there is now an isXXXType and a getAsXXXType

llvm-svn: 40646
This commit is contained in:
Chris Lattner 2007-07-31 19:29:30 +00:00
parent ba32aed8a9
commit 4197796f65
4 changed files with 75 additions and 52 deletions

View File

@ -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;

View File

@ -56,11 +56,33 @@ bool Type::isDerivedType() const {
}
}
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 @@ const FunctionType *Type::isFunctionType() const {
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 @@ 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<ArrayType>(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<RecordType>(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<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 @@ bool Type::isComplexType() const {
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 @@ 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<OCUVectorType>(this))
return VTy;

View File

@ -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()));
}

View File

@ -232,28 +232,36 @@ 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)
/// 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;
bool isPointerType() const;
bool isReferenceType() 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 isDerivedType() const; // C99 6.2.5p20
bool isScalarType() const; // C99 6.2.5p21 (arithmetic + pointers)
bool isAggregateType() const; // C99 6.2.5p21 (arrays, structures)
// 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 *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<RecordDecl*>(TagType::getDecl());
}
RecordDecl *getDecl() const {
return reinterpret_cast<RecordDecl*>(TagType::getDecl());
}