Introduce Type::isAnyPointerType() and convert all clients (suggested by Chris).

I don't love the name, however it simplifies the code and is a worthwhile change. If/when we come up with a better name, we can do a search/replace.

llvm-svn: 75650
This commit is contained in:
Steve Naroff
2009-07-14 18:25:06 +00:00
parent 49c81799b0
commit 6b712a7ba1
7 changed files with 18 additions and 30 deletions

View File

@@ -375,6 +375,7 @@ public:
bool isFunctionNoProtoType() const { return getAsFunctionNoProtoType() != 0; }
bool isFunctionProtoType() const { return getAsFunctionProtoType() != 0; }
bool isPointerType() const;
bool isAnyPointerType() const; // Any C pointer or ObjC object pointer
bool isBlockPointerType() const;
bool isVoidPointerType() const;
bool isReferenceType() const;
@@ -2120,6 +2121,9 @@ inline bool Type::isFunctionType() const {
inline bool Type::isPointerType() const {
return isa<PointerType>(CanonicalType.getUnqualifiedType());
}
inline bool Type::isAnyPointerType() const {
return isPointerType() || isObjCObjectPointerType();
}
inline bool Type::isBlockPointerType() const {
return isa<BlockPointerType>(CanonicalType.getUnqualifiedType());
}

View File

@@ -200,8 +200,7 @@ public:
}
static inline bool IsLocType(QualType T) {
return T->isPointerType() || T->isObjCObjectPointerType()
|| T->isBlockPointerType();
return T->isAnyPointerType() || T->isBlockPointerType();
}
};

View File

@@ -1088,7 +1088,7 @@ QualType ASTContext::getObjCGCQualType(QualType T,
if (T->isPointerType()) {
QualType Pointee = T->getAsPointerType()->getPointeeType();
if (Pointee->isPointerType() || Pointee->isObjCObjectPointerType()) {
if (Pointee->isAnyPointerType()) {
QualType ResultType = getObjCGCQualType(Pointee, GCAttr);
return getPointerType(ResultType);
}

View File

@@ -30,8 +30,7 @@ static bool AreTypesCompatible(QualType Derived, QualType Ancestor,
// Right now don't compare the compatibility of pointers. That involves
// looking at subtyping relationships. FIXME: Future patch.
if ((Derived->isPointerType() || Derived->isObjCObjectPointerType()) &&
(Ancestor->isPointerType() || Ancestor->isObjCObjectPointerType()))
if (Derived->isAnyPointerType() && Ancestor->isAnyPointerType())
return true;
return C.typesAreCompatible(Derived, Ancestor);

View File

@@ -986,7 +986,7 @@ Value *ScalarExprEmitter::EmitOverflowCheckedBinOp(const BinOpInfo &Ops) {
}
Value *ScalarExprEmitter::EmitAdd(const BinOpInfo &Ops) {
if (!Ops.Ty->isPointerType() && !Ops.Ty->isObjCObjectPointerType()) {
if (!Ops.Ty->isAnyPointerType()) {
if (CGF.getContext().getLangOptions().OverflowChecking &&
Ops.Ty->isSignedIntegerType())
return EmitOverflowCheckedBinOp(Ops);

View File

@@ -3094,14 +3094,12 @@ QualType Sema::CheckConditionalOperands(Expr *&Cond, Expr *&LHS, Expr *&RHS,
}
// C99 6.5.15p6 - "if one operand is a null pointer constant, the result has
// the type of the other operand."
if ((LHSTy->isPointerType() || LHSTy->isBlockPointerType() ||
LHSTy->isObjCObjectPointerType()) &&
if ((LHSTy->isAnyPointerType() || LHSTy->isBlockPointerType()) &&
RHS->isNullPointerConstant(Context)) {
ImpCastExprToType(RHS, LHSTy); // promote the null to a pointer.
return LHSTy;
}
if ((RHSTy->isPointerType() || RHSTy->isBlockPointerType() ||
RHSTy->isObjCObjectPointerType()) &&
if ((RHSTy->isAnyPointerType() || RHSTy->isBlockPointerType()) &&
LHS->isNullPointerConstant(Context)) {
ImpCastExprToType(LHS, RHSTy); // promote the null to a pointer.
return RHSTy;
@@ -3823,12 +3821,10 @@ inline QualType Sema::CheckAdditionOperands( // C99 6.5.6
// Put any potential pointer into PExp
Expr* PExp = lex, *IExp = rex;
if (IExp->getType()->isPointerType() ||
IExp->getType()->isObjCObjectPointerType())
if (IExp->getType()->isAnyPointerType())
std::swap(PExp, IExp);
if (PExp->getType()->isPointerType() ||
PExp->getType()->isObjCObjectPointerType()) {
if (PExp->getType()->isAnyPointerType()) {
if (IExp->getType()->isIntegerType()) {
QualType PointeeTy = PExp->getType()->getPointeeType();
@@ -3912,8 +3908,7 @@ QualType Sema::CheckSubtractionOperands(Expr *&lex, Expr *&rex,
}
// Either ptr - int or ptr - ptr.
if (lex->getType()->isPointerType() ||
lex->getType()->isObjCObjectPointerType()) {
if (lex->getType()->isAnyPointerType()) {
QualType lpointee = lex->getType()->getPointeeType();
// The LHS must be an completely-defined object type.
@@ -4293,8 +4288,7 @@ QualType Sema::CheckCompareOperands(Expr *&lex, Expr *&rex, SourceLocation Loc,
return ResultTy;
}
}
if ((lType->isPointerType() || lType->isObjCObjectPointerType()) &&
rType->isIntegerType()) {
if (lType->isAnyPointerType() && rType->isIntegerType()) {
if (isRelational)
Diag(Loc, diag::ext_typecheck_ordered_comparison_of_pointer_integer)
<< lType << rType << lex->getSourceRange() << rex->getSourceRange();
@@ -4304,8 +4298,7 @@ QualType Sema::CheckCompareOperands(Expr *&lex, Expr *&rex, SourceLocation Loc,
ImpCastExprToType(rex, lType); // promote the integer to pointer
return ResultTy;
}
if (lType->isIntegerType() &&
(rType->isPointerType() || rType->isObjCObjectPointerType())) {
if (lType->isIntegerType() && rType->isAnyPointerType()) {
if (isRelational)
Diag(Loc, diag::ext_typecheck_ordered_comparison_of_pointer_integer)
<< lType << rType << lex->getSourceRange() << rex->getSourceRange();
@@ -4578,15 +4571,9 @@ QualType Sema::CheckIncrementDecrementOperand(Expr *Op, SourceLocation OpLoc,
Diag(OpLoc, diag::warn_increment_bool) << Op->getSourceRange();
} else if (ResType->isRealType()) {
// OK!
} else if (ResType->getAsPointerType() ||ResType->isObjCObjectPointerType()) {
QualType PointeeTy;
} else if (ResType->isAnyPointerType()) {
QualType PointeeTy = ResType->getPointeeType();
if (const PointerType *PTy = ResType->getAsPointerType())
PointeeTy = PTy->getPointeeType();
else if (const ObjCObjectPointerType *OPT =
ResType->getAsObjCObjectPointerType())
PointeeTy = OPT->getPointeeType();
// C99 6.5.2.4p2, 6.5.6p2
if (PointeeTy->isVoidType()) {
if (getLangOptions().CPlusPlus) {

View File

@@ -1482,8 +1482,7 @@ QualType Sema::CXXCheckConditionalOperands(Expr *&Cond, Expr *&LHS, Expr *&RHS,
QualType Sema::FindCompositePointerType(Expr *&E1, Expr *&E2) {
assert(getLangOptions().CPlusPlus && "This function assumes C++");
QualType T1 = E1->getType(), T2 = E2->getType();
if(!T1->isPointerType() && !T2->isPointerType() &&
!T1->isObjCObjectPointerType() && !T2->isObjCObjectPointerType())
if(!T1->isAnyPointerType() && !T2->isAnyPointerType())
return QualType();
// C++0x 5.9p2