From: Ted Kremenek Date: Thu, 16 Jul 2009 19:58:26 +0000 (+0000) Subject: Add member template 'Type::getAs', which converts a Type* to a respective T*. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=1a1a6e2bd4c5aefd7fd643cf25915f9623a02e59;p=clang Add member template 'Type::getAs', which converts a Type* to a respective T*. This method is intended to eventually replace the individual Type::getAsXXXType<> methods. The motivation behind this change is twofold: 1) Reduce redundant implementations of Type::getAsXXXType() methods. Most of them are basically copy-and-paste. 2) By centralizing the implementation of the getAs logic we can more smoothly move over to Doug Gregor's proposed canonical type smart pointer scheme. Along with this patch: a) Removed 'Type::getAsPointerType()'; now clients use getAs. b) Removed 'Type::getAsBlockPointerTypE()'; now clients use getAs. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@76098 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/AST/ExprCXX.h b/include/clang/AST/ExprCXX.h index 1767866017..ccfab7418a 100644 --- a/include/clang/AST/ExprCXX.h +++ b/include/clang/AST/ExprCXX.h @@ -711,7 +711,7 @@ public: QualType getAllocatedType() const { assert(getType()->isPointerType()); - return getType()->getAsPointerType()->getPointeeType(); + return getType()->getAs()->getPointeeType(); } FunctionDecl *getOperatorNew() const { return OperatorNew; } diff --git a/include/clang/AST/Type.h b/include/clang/AST/Type.h index 33770f4f1a..3dee933fcf 100644 --- a/include/clang/AST/Type.h +++ b/include/clang/AST/Type.h @@ -431,8 +431,6 @@ public: const FunctionType *getAsFunctionType() const; const FunctionNoProtoType *getAsFunctionNoProtoType() const; const FunctionProtoType *getAsFunctionProtoType() const; - const PointerType *getAsPointerType() const; - const BlockPointerType *getAsBlockPointerType() const; const ReferenceType *getAsReferenceType() const; const LValueReferenceType *getAsLValueReferenceType() const; const RValueReferenceType *getAsRValueReferenceType() const; @@ -457,6 +455,10 @@ public: const ObjCQualifiedInterfaceType *getAsObjCQualifiedInterfaceType() const; const TemplateTypeParmType *getAsTemplateTypeParmType() const; + // Member-template getAs'. This scheme will eventually + // replace the specific getAsXXXX methods above. + template const T *getAs() const; + const TemplateSpecializationType * getAsTemplateSpecializationType() const; @@ -2113,7 +2115,7 @@ inline const TypedefType* Type::getAsTypedefType() const { return dyn_cast(this); } inline const ObjCInterfaceType *Type::getAsPointerToObjCInterfaceType() const { - if (const PointerType *PT = getAsPointerType()) + if (const PointerType *PT = getAs()) return PT->getPointeeType()->getAsObjCInterfaceType(); return 0; } @@ -2142,7 +2144,7 @@ inline bool Type::isRValueReferenceType() const { return isa(CanonicalType.getUnqualifiedType()); } inline bool Type::isFunctionPointerType() const { - if (const PointerType* T = getAsPointerType()) + if (const PointerType* T = getAs()) return T->getPointeeType()->isFunctionType(); else return false; @@ -2247,6 +2249,25 @@ inline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB, Diagnostic::ak_qualtype); return DB; } + +/// Member-template getAs'. +template const T *Type::getAs() const { + // If this is directly a T type, return it. + if (const T *Ty = dyn_cast(this)) + return Ty; + + // If the canonical form of this type isn't the right kind, reject it. + if (!isa(CanonicalType)) { + // Look through type qualifiers + if (isa(CanonicalType.getUnqualifiedType())) + return CanonicalType.getUnqualifiedType()->getAs(); + return 0; + } + + // If this is a typedef for a pointer type, strip the typedef off without + // losing all typedef information. + return cast(getDesugaredType()); +} } // end namespace clang diff --git a/include/clang/Analysis/PathSensitive/MemRegion.h b/include/clang/Analysis/PathSensitive/MemRegion.h index 7f8c5c2903..46d0113422 100644 --- a/include/clang/Analysis/PathSensitive/MemRegion.h +++ b/include/clang/Analysis/PathSensitive/MemRegion.h @@ -357,7 +357,7 @@ public: } QualType getValueType(ASTContext&) const { - const PointerType* PTy = LValueType->getAsPointerType(); + const PointerType* PTy = LValueType->getAs(); assert(PTy); return PTy->getPointeeType(); } diff --git a/lib/AST/ASTContext.cpp b/lib/AST/ASTContext.cpp index b43aadb62e..f30927c4ec 100644 --- a/lib/AST/ASTContext.cpp +++ b/lib/AST/ASTContext.cpp @@ -1092,7 +1092,7 @@ QualType ASTContext::getObjCGCQualType(QualType T, return T; if (T->isPointerType()) { - QualType Pointee = T->getAsPointerType()->getPointeeType(); + QualType Pointee = T->getAs()->getPointeeType(); if (Pointee->isAnyPointerType()) { QualType ResultType = getObjCGCQualType(Pointee, GCAttr); return getPointerType(ResultType); @@ -2779,7 +2779,7 @@ void ASTContext::getObjCEncodingForTypeImpl(QualType T, std::string& S, return; } - if (const PointerType *PT = T->getAsPointerType()) { + if (const PointerType *PT = T->getAs()) { QualType PointeeTy = PT->getPointeeType(); bool isReadOnly = false; // For historical/compatibility reasons, the read-only qualifier of the @@ -2794,8 +2794,8 @@ void ASTContext::getObjCEncodingForTypeImpl(QualType T, std::string& S, } else if (OutermostType) { QualType P = PointeeTy; - while (P->getAsPointerType()) - P = P->getAsPointerType()->getPointeeType(); + while (P->getAs()) + P = P->getAs()->getPointeeType(); if (P.isConstQualified()) { isReadOnly = true; S += 'r'; @@ -3035,7 +3035,7 @@ void ASTContext::setObjCSelType(QualType T) { TypedefDecl *TD = TT->getDecl(); // typedef struct objc_selector *SEL; - const PointerType *ptr = TD->getUnderlyingType()->getAsPointerType(); + const PointerType *ptr = TD->getUnderlyingType()->getAs(); if (!ptr) return; const RecordType *rec = ptr->getPointeeType()->getAsStructureType(); @@ -3159,7 +3159,7 @@ QualType::GCAttrTypes ASTContext::getObjCGCAttrKind(const QualType &Ty) const { if (Ty->isObjCObjectPointerType()) GCAttrs = QualType::Strong; else if (Ty->isPointerType()) - return getObjCGCAttrKind(Ty->getAsPointerType()->getPointeeType()); + return getObjCGCAttrKind(Ty->getAs()->getPointeeType()); } // Non-pointers have none gc'able attribute regardless of the attribute // set on them. @@ -3519,8 +3519,8 @@ QualType ASTContext::mergeTypes(QualType LHS, QualType RHS) { case Type::Pointer: { // Merge two pointer types, while trying to preserve typedef info - QualType LHSPointee = LHS->getAsPointerType()->getPointeeType(); - QualType RHSPointee = RHS->getAsPointerType()->getPointeeType(); + QualType LHSPointee = LHS->getAs()->getPointeeType(); + QualType RHSPointee = RHS->getAs()->getPointeeType(); QualType ResultType = mergeTypes(LHSPointee, RHSPointee); if (ResultType.isNull()) return QualType(); if (getCanonicalType(LHSPointee) == getCanonicalType(ResultType)) @@ -3532,8 +3532,8 @@ QualType ASTContext::mergeTypes(QualType LHS, QualType RHS) { case Type::BlockPointer: { // Merge two block pointer types, while trying to preserve typedef info - QualType LHSPointee = LHS->getAsBlockPointerType()->getPointeeType(); - QualType RHSPointee = RHS->getAsBlockPointerType()->getPointeeType(); + QualType LHSPointee = LHS->getAs()->getPointeeType(); + QualType RHSPointee = RHS->getAs()->getPointeeType(); QualType ResultType = mergeTypes(LHSPointee, RHSPointee); if (ResultType.isNull()) return QualType(); if (getCanonicalType(LHSPointee) == getCanonicalType(ResultType)) diff --git a/lib/AST/DeclPrinter.cpp b/lib/AST/DeclPrinter.cpp index 84ae72977e..55d39e5cc8 100644 --- a/lib/AST/DeclPrinter.cpp +++ b/lib/AST/DeclPrinter.cpp @@ -90,7 +90,7 @@ static QualType GetBaseType(QualType T) { while (!BaseType->isSpecifierType()) { if (isa(BaseType)) break; - else if (const PointerType* PTy = BaseType->getAsPointerType()) + else if (const PointerType* PTy = BaseType->getAs()) BaseType = PTy->getPointeeType(); else if (const ArrayType* ATy = dyn_cast(BaseType)) BaseType = ATy->getElementType(); diff --git a/lib/AST/Expr.cpp b/lib/AST/Expr.cpp index 5d22f38770..74928bcd76 100644 --- a/lib/AST/Expr.cpp +++ b/lib/AST/Expr.cpp @@ -279,9 +279,9 @@ unsigned CallExpr::isBuiltinCall(ASTContext &Context) const { QualType CallExpr::getCallReturnType() const { QualType CalleeType = getCallee()->getType(); - if (const PointerType *FnTypePtr = CalleeType->getAsPointerType()) + if (const PointerType *FnTypePtr = CalleeType->getAs()) CalleeType = FnTypePtr->getPointeeType(); - else if (const BlockPointerType *BPT = CalleeType->getAsBlockPointerType()) + else if (const BlockPointerType *BPT = CalleeType->getAs()) CalleeType = BPT->getPointeeType(); const FunctionType *FnType = CalleeType->getAsFunctionType(); @@ -430,7 +430,7 @@ Expr *InitListExpr::updateInit(unsigned Init, Expr *expr) { /// getFunctionType - Return the underlying function type for this block. /// const FunctionType *BlockExpr::getFunctionType() const { - return getType()->getAsBlockPointerType()-> + return getType()->getAs()-> getPointeeType()->getAsFunctionType(); } @@ -991,7 +991,7 @@ bool Expr::isOBJCGCCandidate(ASTContext &Ctx) const { QualType T = VD->getType(); // dereferencing to an object pointer is always a gc'able candidate if (T->isPointerType() && - T->getAsPointerType()->getPointeeType()->isObjCObjectPointerType()) + T->getAs()->getPointeeType()->isObjCObjectPointerType()) return true; } @@ -1419,7 +1419,7 @@ bool Expr::isNullPointerConstant(ASTContext &Ctx) const if (const ExplicitCastExpr *CE = dyn_cast(this)) { if (!Ctx.getLangOptions().CPlusPlus) { // Check that it is a cast to void*. - if (const PointerType *PT = CE->getType()->getAsPointerType()) { + if (const PointerType *PT = CE->getType()->getAs()) { QualType Pointee = PT->getPointeeType(); if (Pointee.getCVRQualifiers() == 0 && Pointee->isVoidType() && // to void* diff --git a/lib/AST/ExprConstant.cpp b/lib/AST/ExprConstant.cpp index 2c29347c51..9473e4f48c 100644 --- a/lib/AST/ExprConstant.cpp +++ b/lib/AST/ExprConstant.cpp @@ -222,7 +222,7 @@ APValue LValueExprEvaluator::VisitMemberExpr(MemberExpr *E) { if (E->isArrow()) { if (!EvaluatePointer(E->getBase(), result, Info)) return APValue(); - Ty = E->getBase()->getType()->getAsPointerType()->getPointeeType(); + Ty = E->getBase()->getType()->getAs()->getPointeeType(); } else { result = Visit(E->getBase()); if (result.isUninit()) @@ -351,7 +351,7 @@ APValue PointerExprEvaluator::VisitBinaryOperator(const BinaryOperator *E) { if (!EvaluateInteger(IExp, AdditionalOffset, Info)) return APValue(); - QualType PointeeType = PExp->getType()->getAsPointerType()->getPointeeType(); + QualType PointeeType = PExp->getType()->getAs()->getPointeeType(); uint64_t SizeOfPointee; // Explicitly handle GNU void* and function pointer arithmetic extensions. @@ -1029,7 +1029,7 @@ bool IntExprEvaluator::VisitBinaryOperator(const BinaryOperator *E) { if (E->getOpcode() == BinaryOperator::Sub) { const QualType Type = E->getLHS()->getType(); - const QualType ElementType = Type->getAsPointerType()->getPointeeType(); + const QualType ElementType = Type->getAs()->getPointeeType(); uint64_t D = LHSValue.getLValueOffset() - RHSValue.getLValueOffset(); if (!ElementType->isVoidType() && !ElementType->isFunctionType()) diff --git a/lib/AST/Type.cpp b/lib/AST/Type.cpp index 18fa76bf25..13d0cb03e8 100644 --- a/lib/AST/Type.cpp +++ b/lib/AST/Type.cpp @@ -202,7 +202,7 @@ bool Type::isStructureType() const { return false; } bool Type::isVoidPointerType() const { - if (const PointerType *PT = getAsPointerType()) + if (const PointerType *PT = getAs()) return PT->getPointeeType()->isVoidType(); return false; } @@ -296,51 +296,15 @@ const FunctionProtoType *Type::getAsFunctionProtoType() const { } QualType Type::getPointeeType() const { - if (const PointerType *PT = getAsPointerType()) + if (const PointerType *PT = getAs()) return PT->getPointeeType(); if (const ObjCObjectPointerType *OPT = getAsObjCObjectPointerType()) return OPT->getPointeeType(); - if (const BlockPointerType *BPT = getAsBlockPointerType()) + if (const BlockPointerType *BPT = getAs()) return BPT->getPointeeType(); return QualType(); } -const PointerType *Type::getAsPointerType() const { - // If this is directly a pointer type, return it. - if (const PointerType *PTy = dyn_cast(this)) - return PTy; - - // If the canonical form of this type isn't the right kind, reject it. - if (!isa(CanonicalType)) { - // Look through type qualifiers - if (isa(CanonicalType.getUnqualifiedType())) - return CanonicalType.getUnqualifiedType()->getAsPointerType(); - return 0; - } - - // If this is a typedef for a pointer type, strip the typedef off without - // losing all typedef information. - return cast(getDesugaredType()); -} - -const BlockPointerType *Type::getAsBlockPointerType() const { - // If this is directly a block pointer type, return it. - if (const BlockPointerType *PTy = dyn_cast(this)) - return PTy; - - // If the canonical form of this type isn't the right kind, reject it. - if (!isa(CanonicalType)) { - // Look through type qualifiers - if (isa(CanonicalType.getUnqualifiedType())) - return CanonicalType.getUnqualifiedType()->getAsBlockPointerType(); - return 0; - } - - // If this is a typedef for a block pointer type, strip the typedef off - // without losing all typedef information. - return cast(getDesugaredType()); -} - const ReferenceType *Type::getAsReferenceType() const { // If this is directly a reference type, return it. if (const ReferenceType *RTy = dyn_cast(this)) @@ -429,7 +393,7 @@ bool Type::isVariablyModifiedType() const { // Also, C++ references and member pointers can point to a variably modified // type, where VLAs appear as an extension to C++, and should be treated // correctly. - if (const PointerType *PT = getAsPointerType()) + if (const PointerType *PT = getAs()) return PT->getPointeeType()->isVariablyModifiedType(); if (const ReferenceType *RT = getAsReferenceType()) return RT->getPointeeType()->isVariablyModifiedType(); diff --git a/lib/Analysis/BasicStore.cpp b/lib/Analysis/BasicStore.cpp index 7aa63c1c63..99bfac2f50 100644 --- a/lib/Analysis/BasicStore.cpp +++ b/lib/Analysis/BasicStore.cpp @@ -251,7 +251,7 @@ SVal BasicStoreManager::getLValueElement(const GRState *state, static bool isHigherOrderRawPtr(QualType T, ASTContext &C) { bool foundPointer = false; while (1) { - const PointerType *PT = T->getAsPointerType(); + const PointerType *PT = T->getAs(); if (!PT) { if (!foundPointer) return false; diff --git a/lib/Analysis/CFRefCount.cpp b/lib/Analysis/CFRefCount.cpp index 3d2e3ac9a8..1fa3e57af0 100644 --- a/lib/Analysis/CFRefCount.cpp +++ b/lib/Analysis/CFRefCount.cpp @@ -248,7 +248,7 @@ static bool isRefType(QualType RetTy, const char* prefix, return false; // Is the type void*? - const PointerType* PT = RetTy->getAsPointerType(); + const PointerType* PT = RetTy->getAs(); if (!(PT->getPointeeType().getUnqualifiedType() == Ctx->VoidTy)) return false; @@ -1250,7 +1250,7 @@ RetainSummaryManager::updateSummaryFromAnnotations(RetainSummary &Summ, Summ.setRetEffect(RetEffect::MakeOwned(RetEffect::CF, true)); } } - else if (RetTy->getAsPointerType()) { + else if (RetTy->getAs()) { if (FD->getAttr()) { Summ.setRetEffect(RetEffect::MakeOwned(RetEffect::CF, true)); } @@ -1276,7 +1276,7 @@ RetainSummaryManager::updateSummaryFromAnnotations(RetainSummary &Summ, } if (!isTrackedLoc) - isTrackedLoc = MD->getResultType()->getAsPointerType() != NULL; + isTrackedLoc = MD->getResultType()->getAs() != NULL; if (isTrackedLoc && MD->getAttr()) Summ.setRetEffect(RetEffect::MakeOwned(RetEffect::CF, true)); diff --git a/lib/Analysis/CheckNSError.cpp b/lib/Analysis/CheckNSError.cpp index c1382d0377..4e8ba01e3e 100644 --- a/lib/Analysis/CheckNSError.cpp +++ b/lib/Analysis/CheckNSError.cpp @@ -161,7 +161,7 @@ NSErrorCheck::CheckSignature(FunctionDecl& F, QualType& ResultTy, bool NSErrorCheck::CheckNSErrorArgument(QualType ArgTy) { - const PointerType* PPT = ArgTy->getAsPointerType(); + const PointerType* PPT = ArgTy->getAs(); if (!PPT) return false; @@ -182,7 +182,7 @@ bool NSErrorCheck::CheckNSErrorArgument(QualType ArgTy) { bool NSErrorCheck::CheckCFErrorArgument(QualType ArgTy) { - const PointerType* PPT = ArgTy->getAsPointerType(); + const PointerType* PPT = ArgTy->getAs(); if (!PPT) return false; const TypedefType* TT = PPT->getPointeeType()->getAsTypedefType(); diff --git a/lib/Analysis/GRExprEngine.cpp b/lib/Analysis/GRExprEngine.cpp index f83e92acb3..b4bec54877 100644 --- a/lib/Analysis/GRExprEngine.cpp +++ b/lib/Analysis/GRExprEngine.cpp @@ -1274,7 +1274,7 @@ static bool EvalOSAtomicCompareAndSwap(ExplodedNodeSet& Dst, return false; Expr *theValueExpr = CE->getArg(2); - const PointerType *theValueType = theValueExpr->getType()->getAsPointerType(); + const PointerType *theValueType = theValueExpr->getType()->getAs(); // theValueType not a pointer? if (!theValueType) @@ -1382,7 +1382,7 @@ void GRExprEngine::VisitCall(CallExpr* CE, NodeTy* Pred, // Determine the type of function we're calling (if available). const FunctionProtoType *Proto = NULL; QualType FnType = CE->getCallee()->IgnoreParens()->getType(); - if (const PointerType *FnTypePtr = FnType->getAsPointerType()) + if (const PointerType *FnTypePtr = FnType->getAs()) Proto = FnTypePtr->getPointeeType()->getAsFunctionProtoType(); VisitCallRec(CE, Pred, AI, AE, Dst, Proto, /*ParamIdx=*/0); diff --git a/lib/Analysis/RegionStore.cpp b/lib/Analysis/RegionStore.cpp index 0d2467f55e..31623b9983 100644 --- a/lib/Analysis/RegionStore.cpp +++ b/lib/Analysis/RegionStore.cpp @@ -365,7 +365,7 @@ static bool isGenericPtr(ASTContext &Ctx, QualType Ty) { if (Ty->isVoidType()) return true; - if (const PointerType *PT = Ty->getAsPointerType()) { + if (const PointerType *PT = Ty->getAs()) { Ty = PT->getPointeeType(); continue; } @@ -680,7 +680,7 @@ SVal RegionStoreManager::EvalBinOp(const GRState *state, T = Sym->getType(getContext()); } - QualType EleTy = T->getAsPointerType()->getPointeeType(); + QualType EleTy = T->getAs()->getPointeeType(); SVal ZeroIdx = ValMgr.makeZeroArrayIndex(); ER = MRMgr.getElementRegion(EleTy, ZeroIdx, SR, getContext()); break; @@ -689,7 +689,7 @@ SVal RegionStoreManager::EvalBinOp(const GRState *state, // Get the alloca region's current cast type. const AllocaRegion *AR = cast(MR); QualType T = *(state->get(AR)); - QualType EleTy = T->getAsPointerType()->getPointeeType(); + QualType EleTy = T->getAs()->getPointeeType(); SVal ZeroIdx = ValMgr.makeZeroArrayIndex(); ER = MRMgr.getElementRegion(EleTy, ZeroIdx, AR, getContext()); break; @@ -865,7 +865,7 @@ SVal RegionStoreManager::Retrieve(const GRState *state, Loc L, QualType T) { // symbol value. if (const QualType *p = state->get(R)) { QualType T = *p; - RTy = T->getAsPointerType()->getPointeeType(); + RTy = T->getAs()->getPointeeType(); } // All other values are symbolic. @@ -937,7 +937,7 @@ SVal RegionStoreManager::RetrieveElement(const GRState* state, // If the region is already cast to another type, use that type to create the // symbol value. if (const QualType *p = state->get(R)) - Ty = (*p)->getAsPointerType()->getPointeeType(); + Ty = (*p)->getAs()->getPointeeType(); return ValMgr.getRegionValueSymbolValOrUnknown(R, Ty); } @@ -976,7 +976,7 @@ SVal RegionStoreManager::RetrieveField(const GRState* state, // symbol value. if (const QualType *p = state->get(R)) { QualType tmp = *p; - Ty = tmp->getAsPointerType()->getPointeeType(); + Ty = tmp->getAs()->getPointeeType(); } // All other values are symbolic. @@ -1009,7 +1009,7 @@ SVal RegionStoreManager::RetrieveObjCIvar(const GRState* state, // symbol value. if (const QualType *p = state->get(R)) { QualType tmp = *p; - Ty = tmp->getAsPointerType()->getPointeeType(); + Ty = tmp->getAs()->getPointeeType(); } // All other values are symbolic. diff --git a/lib/Analysis/Store.cpp b/lib/Analysis/Store.cpp index b939a0df9c..9147f93eda 100644 --- a/lib/Analysis/Store.cpp +++ b/lib/Analysis/Store.cpp @@ -62,7 +62,7 @@ StoreManager::NewCastRegion(const GRState *state, const MemRegion* R, // Now assume we are casting from pointer to pointer. Other cases should // already be handled. - QualType PointeeTy = CastToTy->getAsPointerType()->getPointeeType(); + QualType PointeeTy = CastToTy->getAs()->getPointeeType(); // Process region cast according to the kind of the region being cast. switch (R->getKind()) { @@ -243,7 +243,7 @@ const GRState *StoreManager::InvalidateRegion(const GRState *state, // If the region is cast to another type, use that type. if (const QualType *CastTy = getCastType(state, R)) { assert(!(*CastTy)->isObjCObjectPointerType()); - QualType NewT = (*CastTy)->getAsPointerType()->getPointeeType(); + QualType NewT = (*CastTy)->getAs()->getPointeeType(); // The only exception is if the original region had a location type as its // value type we always want to treat the region as binding to a location. diff --git a/lib/CodeGen/CGBlocks.cpp b/lib/CodeGen/CGBlocks.cpp index 73200fe2ca..d8d1259587 100644 --- a/lib/CodeGen/CGBlocks.cpp +++ b/lib/CodeGen/CGBlocks.cpp @@ -388,7 +388,7 @@ const llvm::Type *BlockModule::getGenericExtendedBlockLiteralType() { RValue CodeGenFunction::EmitBlockCallExpr(const CallExpr* E) { const BlockPointerType *BPT = - E->getCallee()->getType()->getAsBlockPointerType(); + E->getCallee()->getType()->getAs(); llvm::Value *Callee = EmitScalarExpr(E->getCallee()); diff --git a/lib/CodeGen/CGExpr.cpp b/lib/CodeGen/CGExpr.cpp index 346b6703d3..ab7b70e793 100644 --- a/lib/CodeGen/CGExpr.cpp +++ b/lib/CodeGen/CGExpr.cpp @@ -934,7 +934,7 @@ EmitExtVectorElementExpr(const ExtVectorElementExpr *E) { assert(E->getBase()->getType()->isVectorType()); Base = EmitLValue(E->getBase()); } else { - const PointerType *PT = E->getBase()->getType()->getAsPointerType(); + const PointerType *PT = E->getBase()->getType()->getAs(); llvm::Value *Ptr = EmitScalarExpr(E->getBase()); Base = LValue::MakeAddr(Ptr, PT->getPointeeType().getCVRQualifiers()); } @@ -976,7 +976,7 @@ LValue CodeGenFunction::EmitMemberExpr(const MemberExpr *E) { if (E->isArrow()) { BaseValue = EmitScalarExpr(BaseExpr); const PointerType *PTy = - BaseExpr->getType()->getAsPointerType(); + BaseExpr->getType()->getAs(); if (PTy->getPointeeType()->isUnionType()) isUnion = true; CVRQualifiers = PTy->getPointeeType().getCVRQualifiers(); @@ -1317,7 +1317,7 @@ RValue CodeGenFunction::EmitCall(llvm::Value *Callee, QualType CalleeType, assert(CalleeType->isFunctionPointerType() && "Call must have function pointer type!"); - QualType FnType = CalleeType->getAsPointerType()->getPointeeType(); + QualType FnType = CalleeType->getAs()->getPointeeType(); QualType ResultType = FnType->getAsFunctionType()->getResultType(); CallArgList Args; diff --git a/lib/CodeGen/CGExprScalar.cpp b/lib/CodeGen/CGExprScalar.cpp index e18e08b5c5..0316116631 100644 --- a/lib/CodeGen/CGExprScalar.cpp +++ b/lib/CodeGen/CGExprScalar.cpp @@ -679,7 +679,7 @@ Value *ScalarExprEmitter::VisitPrePostIncDec(const UnaryOperator *E, int AmountVal = isInc ? 1 : -1; if (ValTy->isPointerType() && - ValTy->getAsPointerType()->isVariableArrayType()) { + ValTy->getAs()->isVariableArrayType()) { // The amount of the addition/subtraction needs to account for the VLA size CGF.ErrorUnsupported(E, "VLA pointer inc/dec"); } @@ -1002,13 +1002,13 @@ Value *ScalarExprEmitter::EmitAdd(const BinOpInfo &Ops) { } if (Ops.Ty->isPointerType() && - Ops.Ty->getAsPointerType()->isVariableArrayType()) { + Ops.Ty->getAs()->isVariableArrayType()) { // The amount of the addition needs to account for the VLA size CGF.ErrorUnsupported(Ops.E, "VLA pointer addition"); } Value *Ptr, *Idx; Expr *IdxExp; - const PointerType *PT = Ops.E->getLHS()->getType()->getAsPointerType(); + const PointerType *PT = Ops.E->getLHS()->getType()->getAs(); const ObjCObjectPointerType *OPT = Ops.E->getLHS()->getType()->getAsObjCObjectPointerType(); if (PT || OPT) { @@ -1016,7 +1016,7 @@ Value *ScalarExprEmitter::EmitAdd(const BinOpInfo &Ops) { Idx = Ops.RHS; IdxExp = Ops.E->getRHS(); } else { // int + pointer - PT = Ops.E->getRHS()->getType()->getAsPointerType(); + PT = Ops.E->getRHS()->getType()->getAs(); OPT = Ops.E->getRHS()->getType()->getAsObjCObjectPointerType(); assert((PT || OPT) && "Invalid add expr"); Ptr = Ops.RHS; @@ -1073,7 +1073,7 @@ Value *ScalarExprEmitter::EmitSub(const BinOpInfo &Ops) { } if (Ops.E->getLHS()->getType()->isPointerType() && - Ops.E->getLHS()->getType()->getAsPointerType()->isVariableArrayType()) { + Ops.E->getLHS()->getType()->getAs()->isVariableArrayType()) { // The amount of the addition needs to account for the VLA size for // ptr-int // The amount of the division needs to account for the VLA size for diff --git a/lib/CodeGen/CGObjCMac.cpp b/lib/CodeGen/CGObjCMac.cpp index 661f75a057..bb80be961b 100644 --- a/lib/CodeGen/CGObjCMac.cpp +++ b/lib/CodeGen/CGObjCMac.cpp @@ -3008,7 +3008,7 @@ static QualType::GCAttrTypes GetGCAttrTypeForType(ASTContext &Ctx, if (FQT->isObjCObjectPointerType()) return QualType::Strong; - if (const PointerType *PT = FQT->getAsPointerType()) + if (const PointerType *PT = FQT->getAs()) return GetGCAttrTypeForType(Ctx, PT->getPointeeType()); return QualType::GCNone; diff --git a/lib/CodeGen/CodeGenFunction.cpp b/lib/CodeGen/CodeGenFunction.cpp index a72f2ae710..842bf8be49 100644 --- a/lib/CodeGen/CodeGenFunction.cpp +++ b/lib/CodeGen/CodeGenFunction.cpp @@ -490,7 +490,7 @@ llvm::Value *CodeGenFunction::EmitVLASize(QualType Ty) return SizeEntry; } else if (const ArrayType *AT = dyn_cast(Ty)) { EmitVLASize(AT->getElementType()); - } else if (const PointerType *PT = Ty->getAsPointerType()) + } else if (const PointerType *PT = Ty->getAs()) EmitVLASize(PT->getPointeeType()); else { assert(0 && "unknown VM type!"); diff --git a/lib/Frontend/RewriteBlocks.cpp b/lib/Frontend/RewriteBlocks.cpp index bc855fa879..a7b5e3d686 100644 --- a/lib/Frontend/RewriteBlocks.cpp +++ b/lib/Frontend/RewriteBlocks.cpp @@ -130,7 +130,7 @@ public: OCT == Context->getCanonicalType(Context->getObjCClassType())) return true; - if (const PointerType *PT = OCT->getAsPointerType()) { + if (const PointerType *PT = OCT->getAs()) { if (isa(PT->getPointeeType()) || PT->getPointeeType()->isObjCQualifiedIdType()) return true; @@ -684,13 +684,13 @@ std::string RewriteBlocks::SynthesizeBlockCall(CallExpr *Exp) { if (const DeclRefExpr *DRE = dyn_cast(Exp->getCallee())) { closureName = DRE->getDecl()->getNameAsCString(); - CPT = DRE->getType()->getAsBlockPointerType(); + CPT = DRE->getType()->getAs(); } else if (BlockDeclRefExpr *CDRE = dyn_cast(Exp->getCallee())) { closureName = CDRE->getDecl()->getNameAsCString(); - CPT = CDRE->getType()->getAsBlockPointerType(); + CPT = CDRE->getType()->getAs(); } else if (MemberExpr *MExpr = dyn_cast(Exp->getCallee())) { closureName = MExpr->getMemberDecl()->getNameAsCString(); - CPT = MExpr->getType()->getAsBlockPointerType(); + CPT = MExpr->getType()->getAs(); } else { assert(1 && "RewriteBlockClass: Bad type"); } @@ -813,11 +813,11 @@ void RewriteBlocks::RewriteBlockPointerFunctionArgs(FunctionDecl *FD) { bool RewriteBlocks::PointerTypeTakesAnyBlockArguments(QualType QT) { const FunctionProtoType *FTP; - const PointerType *PT = QT->getAsPointerType(); + const PointerType *PT = QT->getAs(); if (PT) { FTP = PT->getPointeeType()->getAsFunctionProtoType(); } else { - const BlockPointerType *BPT = QT->getAsBlockPointerType(); + const BlockPointerType *BPT = QT->getAs(); assert(BPT && "BlockPointerTypeTakeAnyBlockArguments(): not a block pointer type"); FTP = BPT->getPointeeType()->getAsFunctionProtoType(); } @@ -1068,7 +1068,7 @@ void RewriteBlocks::RewriteFunctionProtoType(QualType funcType, NamedDecl *D) { } void RewriteBlocks::CheckFunctionPointerDecl(QualType funcType, NamedDecl *ND) { - const PointerType *PT = funcType->getAsPointerType(); + const PointerType *PT = funcType->getAs(); if (PT && PointerTypeTakesAnyBlockArguments(funcType)) RewriteFunctionProtoType(PT->getPointeeType(), ND); } diff --git a/lib/Frontend/RewriteObjC.cpp b/lib/Frontend/RewriteObjC.cpp index 1bc7451a17..de45e1a2be 100644 --- a/lib/Frontend/RewriteObjC.cpp +++ b/lib/Frontend/RewriteObjC.cpp @@ -354,7 +354,7 @@ namespace { OCT == Context->getCanonicalType(Context->getObjCClassType())) return true; - if (const PointerType *PT = OCT->getAsPointerType()) { + if (const PointerType *PT = OCT->getAs()) { if (isa(PT->getPointeeType()) || PT->getPointeeType()->isObjCQualifiedIdType()) return true; @@ -394,7 +394,7 @@ void RewriteObjC::RewriteBlocksInFunctionProtoType(QualType funcType, } void RewriteObjC::CheckFunctionPointerDecl(QualType funcType, NamedDecl *ND) { - const PointerType *PT = funcType->getAsPointerType(); + const PointerType *PT = funcType->getAs(); if (PT && PointerTypeTakesAnyBlockArguments(funcType)) RewriteBlocksInFunctionProtoType(PT->getPointeeType(), ND); } @@ -864,9 +864,9 @@ void RewriteObjC::RewriteObjCMethodDecl(ObjCMethodDecl *OMD, // syntax (where a decaration models use). QualType retType = OMD->getResultType(); QualType PointeeTy; - if (const PointerType* PT = retType->getAsPointerType()) + if (const PointerType* PT = retType->getAs()) PointeeTy = PT->getPointeeType(); - else if (const BlockPointerType *BPT = retType->getAsBlockPointerType()) + else if (const BlockPointerType *BPT = retType->getAs()) PointeeTy = BPT->getPointeeType(); if ((FPRetType = PointeeTy->getAsFunctionType())) { ResultStr += FPRetType->getResultType().getAsString(); @@ -939,7 +939,7 @@ void RewriteObjC::RewriteObjCMethodDecl(ObjCMethodDecl *OMD, std::string Name = PDecl->getNameAsString(); if (isTopLevelBlockPointerType(PDecl->getType())) { // Make sure we convert "t (^)(...)" to "t (*)(...)". - const BlockPointerType *BPT = PDecl->getType()->getAsBlockPointerType(); + const BlockPointerType *BPT = PDecl->getType()->getAs(); Context->getPointerType(BPT->getPointeeType()).getAsStringInternal(Name, Context->PrintingPolicy); } else @@ -1138,7 +1138,7 @@ Stmt *RewriteObjC::RewriteObjCIvarRefExpr(ObjCIvarRefExpr *IV, SourceLocation OrigStart) { ObjCIvarDecl *D = IV->getDecl(); if (CurMethodDef) { - if (const PointerType *pType = IV->getBase()->getType()->getAsPointerType()) { + if (const PointerType *pType = IV->getBase()->getType()->getAs()) { ObjCInterfaceType *iFaceDecl = dyn_cast(pType->getPointeeType()); // lookup which class implements the instance variable. @@ -1184,7 +1184,7 @@ Stmt *RewriteObjC::RewriteObjCIvarRefExpr(ObjCIvarRefExpr *IV, // Explicit ivar refs need to have a cast inserted. // FIXME: consider sharing some of this code with the code above. - if (const PointerType *pType = IV->getBase()->getType()->getAsPointerType()) { + if (const PointerType *pType = IV->getBase()->getType()->getAs()) { ObjCInterfaceType *iFaceDecl = dyn_cast(pType->getPointeeType()); // lookup which class implements the instance variable. ObjCInterfaceDecl *clsDeclared = 0; @@ -1608,7 +1608,7 @@ Stmt *RewriteObjC::RewriteObjCTryStmt(ObjCAtTryStmt *S) { buf += "1) { "; ReplaceText(startLoc, lParenLoc-startBuf+1, buf.c_str(), buf.size()); sawIdTypedCatch = true; - } else if (const PointerType *pType = t->getAsPointerType()) { + } else if (const PointerType *pType = t->getAs()) { ObjCInterfaceType *cls; // Should be a pointer to a class. cls = dyn_cast(pType->getPointeeType().getTypePtr()); @@ -1824,7 +1824,7 @@ bool RewriteObjC::needToScanForQualifiers(QualType T) { if (T->isObjCQualifiedIdType()) return true; - if (const PointerType *pType = T->getAsPointerType()) { + if (const PointerType *pType = T->getAs()) { Type *pointeeType = pType->getPointeeType().getTypePtr(); if (isa(pointeeType)) return true; // we have "Class *". @@ -2485,7 +2485,7 @@ Stmt *RewriteObjC::SynthMessageExpr(ObjCMessageExpr *Exp) { : (*PI)->getType(); // Make sure we convert "t (^)(...)" to "t (*)(...)". if (isTopLevelBlockPointerType(t)) { - const BlockPointerType *BPT = t->getAsBlockPointerType(); + const BlockPointerType *BPT = t->getAs(); t = Context->getPointerType(BPT->getPointeeType()); } ArgTypes.push_back(t); @@ -3890,13 +3890,13 @@ Stmt *RewriteObjC::SynthesizeBlockCall(CallExpr *Exp) { if (const DeclRefExpr *DRE = dyn_cast(Exp->getCallee())) { closureName = DRE->getDecl()->getNameAsCString(); - CPT = DRE->getType()->getAsBlockPointerType(); + CPT = DRE->getType()->getAs(); } else if (BlockDeclRefExpr *CDRE = dyn_cast(Exp->getCallee())) { closureName = CDRE->getDecl()->getNameAsCString(); - CPT = CDRE->getType()->getAsBlockPointerType(); + CPT = CDRE->getType()->getAs(); } else if (MemberExpr *MExpr = dyn_cast(Exp->getCallee())) { closureName = MExpr->getMemberDecl()->getNameAsCString(); - CPT = MExpr->getType()->getAsBlockPointerType(); + CPT = MExpr->getType()->getAs(); } else { assert(1 && "RewriteBlockClass: Bad type"); } @@ -3922,7 +3922,7 @@ Stmt *RewriteObjC::SynthesizeBlockCall(CallExpr *Exp) { QualType t = *I; // Make sure we convert "t (^)(...)" to "t (*)(...)". if (isTopLevelBlockPointerType(t)) { - const BlockPointerType *BPT = t->getAsBlockPointerType(); + const BlockPointerType *BPT = t->getAs(); t = Context->getPointerType(BPT->getPointeeType()); } ArgTypes.push_back(t); @@ -4063,11 +4063,11 @@ void RewriteObjC::RewriteBlockPointerFunctionArgs(FunctionDecl *FD) { bool RewriteObjC::PointerTypeTakesAnyBlockArguments(QualType QT) { const FunctionProtoType *FTP; - const PointerType *PT = QT->getAsPointerType(); + const PointerType *PT = QT->getAs(); if (PT) { FTP = PT->getPointeeType()->getAsFunctionProtoType(); } else { - const BlockPointerType *BPT = QT->getAsBlockPointerType(); + const BlockPointerType *BPT = QT->getAs(); assert(BPT && "BlockPointerTypeTakeAnyBlockArguments(): not a block pointer type"); FTP = BPT->getPointeeType()->getAsFunctionProtoType(); } diff --git a/lib/Sema/SemaChecking.cpp b/lib/Sema/SemaChecking.cpp index 4eed018722..6256872b5e 100644 --- a/lib/Sema/SemaChecking.cpp +++ b/lib/Sema/SemaChecking.cpp @@ -205,7 +205,7 @@ Sema::CheckBlockCall(NamedDecl *NDecl, CallExpr *TheCall) { bool HasVAListArg = Format->getFirstArg() == 0; if (!HasVAListArg) { const FunctionType *FT = - Ty->getAsBlockPointerType()->getPointeeType()->getAsFunctionType(); + Ty->getAs()->getPointeeType()->getAsFunctionType(); if (const FunctionProtoType *Proto = dyn_cast(FT)) HasVAListArg = !Proto->isVariadic(); } @@ -241,7 +241,7 @@ bool Sema::SemaBuiltinAtomicOverloaded(CallExpr *TheCall) { return Diag(DRE->getLocStart(), diag::err_atomic_builtin_must_be_pointer) << FirstArg->getType() << FirstArg->getSourceRange(); - QualType ValType = FirstArg->getType()->getAsPointerType()->getPointeeType(); + QualType ValType = FirstArg->getType()->getAs()->getPointeeType(); if (!ValType->isIntegerType() && !ValType->isPointerType() && !ValType->isBlockPointerType()) return Diag(DRE->getLocStart(), @@ -344,7 +344,7 @@ bool Sema::SemaBuiltinAtomicOverloaded(CallExpr *TheCall) { TUScope, false, DRE->getLocStart())); const FunctionProtoType *BuiltinFT = NewBuiltinDecl->getType()->getAsFunctionProtoType(); - ValType = BuiltinFT->getArgType(0)->getAsPointerType()->getPointeeType(); + ValType = BuiltinFT->getArgType(0)->getAs()->getPointeeType(); // If the first type needs to be converted (e.g. void** -> int*), do it now. if (BuiltinFT->getArgType(0) != FirstArg->getType()) { @@ -750,7 +750,7 @@ bool Sema::SemaCheckStringLiteral(const Expr *E, const CallExpr *TheCall, if (const ArrayType *AT = Context.getAsArrayType(T)) { isConstant = AT->getElementType().isConstant(Context); } - else if (const PointerType *PT = T->getAsPointerType()) { + else if (const PointerType *PT = T->getAs()) { isConstant = T.isConstant(Context) && PT->getPointeeType().isConstant(Context); } diff --git a/lib/Sema/SemaDeclAttr.cpp b/lib/Sema/SemaDeclAttr.cpp index 09cb96b900..5d05b4c444 100644 --- a/lib/Sema/SemaDeclAttr.cpp +++ b/lib/Sema/SemaDeclAttr.cpp @@ -36,9 +36,9 @@ static const FunctionType *getFunctionType(Decl *d, bool blocksToo = true) { return 0; if (Ty->isFunctionPointerType()) - Ty = Ty->getAsPointerType()->getPointeeType(); + Ty = Ty->getAs()->getPointeeType(); else if (blocksToo && Ty->isBlockPointerType()) - Ty = Ty->getAsBlockPointerType()->getPointeeType(); + Ty = Ty->getAs()->getPointeeType(); return Ty->getAsFunctionType(); } @@ -133,7 +133,7 @@ static inline bool isNSStringType(QualType T, ASTContext &Ctx) { } static inline bool isCFStringType(QualType T, ASTContext &Ctx) { - const PointerType *PT = T->getAsPointerType(); + const PointerType *PT = T->getAs(); if (!PT) return false; @@ -632,7 +632,7 @@ static void HandleObjCNSObject(Decl *D, const AttributeList &Attr, Sema &S) { if (TypedefDecl *TD = dyn_cast(D)) { QualType T = TD->getUnderlyingType(); if (!T->isPointerType() || - !T->getAsPointerType()->getPointeeType()->isRecordType()) { + !T->getAs()->getPointeeType()->isRecordType()) { S.Diag(TD->getLocation(), diag::err_nsobject_attribute); return; } @@ -751,7 +751,7 @@ static void HandleSentinelAttr(Decl *d, const AttributeList &Attr, Sema &S) { QualType Ty = V->getType(); if (Ty->isBlockPointerType() || Ty->isFunctionPointerType()) { const FunctionType *FT = Ty->isFunctionPointerType() ? getFunctionType(d) - : Ty->getAsBlockPointerType()->getPointeeType()->getAsFunctionType(); + : Ty->getAs()->getPointeeType()->getAsFunctionType(); if (!cast(FT)->isVariadic()) { int m = Ty->isFunctionPointerType() ? 0 : 1; S.Diag(Attr.getLoc(), diag::warn_attribute_sentinel_not_variadic) << m; @@ -1147,7 +1147,7 @@ static void HandleFormatArgAttr(Decl *d, const AttributeList &Attr, Sema &S) { if (not_nsstring_type && !isCFStringType(Ty, S.Context) && (!Ty->isPointerType() || - !Ty->getAsPointerType()->getPointeeType()->isCharType())) { + !Ty->getAs()->getPointeeType()->isCharType())) { // FIXME: Should highlight the actual expression that has the wrong type. S.Diag(Attr.getLoc(), diag::err_format_attribute_not) << (not_nsstring_type ? "a string type" : "an NSString") @@ -1158,7 +1158,7 @@ static void HandleFormatArgAttr(Decl *d, const AttributeList &Attr, Sema &S) { if (!isNSStringType(Ty, S.Context) && !isCFStringType(Ty, S.Context) && (!Ty->isPointerType() || - !Ty->getAsPointerType()->getPointeeType()->isCharType())) { + !Ty->getAs()->getPointeeType()->isCharType())) { // FIXME: Should highlight the actual expression that has the wrong type. S.Diag(Attr.getLoc(), diag::err_format_attribute_result_not) << (not_nsstring_type ? "string type" : "NSString") @@ -1266,7 +1266,7 @@ static void HandleFormatAttr(Decl *d, const AttributeList &Attr, Sema &S) { return; } } else if (!Ty->isPointerType() || - !Ty->getAsPointerType()->getPointeeType()->isCharType()) { + !Ty->getAs()->getPointeeType()->isCharType()) { // FIXME: Should highlight the actual expression that has the wrong type. S.Diag(Attr.getLoc(), diag::err_format_attribute_not) << "a string type" << IdxExpr->getSourceRange(); @@ -1703,7 +1703,7 @@ static void HandleNSReturnsRetainedAttr(Decl *d, const AttributeList &Attr, return; } - if (!(S.Context.isObjCNSObjectType(RetTy) || RetTy->getAsPointerType() + if (!(S.Context.isObjCNSObjectType(RetTy) || RetTy->getAs() || RetTy->getAsObjCObjectPointerType())) { S.Diag(Attr.getLoc(), diag::warn_ns_attribute_wrong_return_type) << Attr.getName(); diff --git a/lib/Sema/SemaDeclCXX.cpp b/lib/Sema/SemaDeclCXX.cpp index c62858ac73..21daa8fc03 100644 --- a/lib/Sema/SemaDeclCXX.cpp +++ b/lib/Sema/SemaDeclCXX.cpp @@ -1009,9 +1009,9 @@ bool Sema::RequireNonAbstractType(SourceLocation Loc, QualType T, return RequireNonAbstractType(Loc, AT->getElementType(), DiagID, SelID, CurrentRD); - if (const PointerType *PT = T->getAsPointerType()) { + if (const PointerType *PT = T->getAs()) { // Find the innermost pointer type. - while (const PointerType *T = PT->getPointeeType()->getAsPointerType()) + while (const PointerType *T = PT->getPointeeType()->getAs()) PT = T; if (const ArrayType *AT = Context.getAsArrayType(PT->getPointeeType())) @@ -3079,7 +3079,7 @@ VarDecl *Sema::BuildExceptionDeclaration(Scope *S, QualType ExDeclType, QualType BaseType = ExDeclType; int Mode = 0; // 0 for direct type, 1 for pointer, 2 for reference unsigned DK = diag::err_catch_incomplete; - if (const PointerType *Ptr = BaseType->getAsPointerType()) { + if (const PointerType *Ptr = BaseType->getAs()) { BaseType = Ptr->getPointeeType(); Mode = 1; DK = diag::err_catch_incomplete_ptr; diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp index 1304558042..a229791ea9 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/lib/Sema/SemaExpr.cpp @@ -133,8 +133,8 @@ void Sema::DiagnoseSentinelCalls(NamedDecl *D, SourceLocation Loc, QualType Ty = V->getType(); if (Ty->isBlockPointerType() || Ty->isFunctionPointerType()) { const FunctionType *FT = Ty->isFunctionPointerType() - ? Ty->getAsPointerType()->getPointeeType()->getAsFunctionType() - : Ty->getAsBlockPointerType()->getPointeeType()->getAsFunctionType(); + ? Ty->getAs()->getPointeeType()->getAsFunctionType() + : Ty->getAs()->getPointeeType()->getAsFunctionType(); if (const FunctionProtoType *Proto = dyn_cast(FT)) { unsigned NumArgsInProto = Proto->getNumArgs(); unsigned k; @@ -756,7 +756,7 @@ Sema::BuildAnonymousStructUnionMemberReference(SourceLocation Loc, // whether its a pointer and whether it adds any qualifiers to the // anonymous struct/union fields we're looking into. QualType ObjectType = BaseObjectExpr->getType(); - if (const PointerType *ObjectPtr = ObjectType->getAsPointerType()) { + if (const PointerType *ObjectPtr = ObjectType->getAs()) { BaseObjectIsPointer = true; ObjectType = ObjectPtr->getPointeeType(); } @@ -1835,11 +1835,11 @@ Sema::ActOnArraySubscriptExpr(Scope *S, ExprArg Base, SourceLocation LLoc, BaseExpr = LHSExp; IndexExpr = RHSExp; ResultType = Context.DependentTy; - } else if (const PointerType *PTy = LHSTy->getAsPointerType()) { + } else if (const PointerType *PTy = LHSTy->getAs()) { BaseExpr = LHSExp; IndexExpr = RHSExp; ResultType = PTy->getPointeeType(); - } else if (const PointerType *PTy = RHSTy->getAsPointerType()) { + } else if (const PointerType *PTy = RHSTy->getAs()) { // Handle the uncommon case of "123[Ptr]". BaseExpr = RHSExp; IndexExpr = LHSExp; @@ -1874,7 +1874,7 @@ Sema::ActOnArraySubscriptExpr(Scope *S, ExprArg Base, SourceLocation LLoc, BaseExpr = LHSExp; IndexExpr = RHSExp; - ResultType = LHSTy->getAsPointerType()->getPointeeType(); + ResultType = LHSTy->getAs()->getPointeeType(); } else if (RHSTy->isArrayType()) { // Same as previous, except for 123[f().a] case Diag(RHSExp->getLocStart(), diag::ext_subscript_non_lvalue) << @@ -1884,7 +1884,7 @@ Sema::ActOnArraySubscriptExpr(Scope *S, ExprArg Base, SourceLocation LLoc, BaseExpr = RHSExp; IndexExpr = LHSExp; - ResultType = RHSTy->getAsPointerType()->getPointeeType(); + ResultType = RHSTy->getAs()->getPointeeType(); } else { return ExprError(Diag(LLoc, diag::err_typecheck_subscript_value) << LHSExp->getSourceRange() << RHSExp->getSourceRange()); @@ -2098,7 +2098,7 @@ Sema::ActOnMemberReferenceExpr(Scope *S, ExprArg Base, SourceLocation OpLoc, OpLoc, DeclarationName(&Member), MemberLoc)); - else if (const PointerType *PT = BaseType->getAsPointerType()) + else if (const PointerType *PT = BaseType->getAs()) BaseType = PT->getPointeeType(); else if (BaseType->isObjCObjectPointerType()) ; @@ -2119,7 +2119,7 @@ Sema::ActOnMemberReferenceExpr(Scope *S, ExprArg Base, SourceLocation OpLoc, // In Obj-C++, however, the above expression is valid, since it could be // accessing the 'f' property if T is an Obj-C interface. The extra check // allows this, while still reporting an error if T is a struct pointer. - const PointerType *PT = BaseType->getAsPointerType(); + const PointerType *PT = BaseType->getAs(); if (!PT || (getLangOptions().ObjC1 && !PT->getPointeeType()->isRecordType())) @@ -2500,7 +2500,7 @@ Sema::ActOnMemberReferenceExpr(Scope *S, ExprArg Base, SourceLocation OpLoc, if (BaseType == Context.OverloadTy || BaseType->isFunctionType() || (BaseType->isPointerType() && - BaseType->getAsPointerType()->isFunctionType())) { + BaseType->getAs()->isFunctionType())) { SourceLocation Loc = PP.getLocForEndOfToken(BaseExpr->getLocEnd()); Diag(Loc, diag::note_member_reference_needs_call) << CodeModificationHint::CreateInsertion(Loc, "()"); @@ -2794,13 +2794,13 @@ Sema::ActOnCallExpr(Scope *S, ExprArg fn, SourceLocation LParenLoc, if (!Fn->getType()->isBlockPointerType()) { // C99 6.5.2.2p1 - "The expression that denotes the called function shall // have type pointer to function". - const PointerType *PT = Fn->getType()->getAsPointerType(); + const PointerType *PT = Fn->getType()->getAs(); if (PT == 0) return ExprError(Diag(LParenLoc, diag::err_typecheck_call_not_function) << Fn->getType() << Fn->getSourceRange()); FuncT = PT->getPointeeType()->getAsFunctionType(); } else { // This is a block call. - FuncT = Fn->getType()->getAsBlockPointerType()->getPointeeType()-> + FuncT = Fn->getType()->getAs()->getPointeeType()-> getAsFunctionType(); } if (FuncT == 0) @@ -3131,8 +3131,8 @@ QualType Sema::CheckConditionalOperands(Expr *&Cond, Expr *&LHS, Expr *&RHS, return LHSTy; } // The block pointer types aren't identical, continue checking. - QualType lhptee = LHSTy->getAsBlockPointerType()->getPointeeType(); - QualType rhptee = RHSTy->getAsBlockPointerType()->getPointeeType(); + QualType lhptee = LHSTy->getAs()->getPointeeType(); + QualType rhptee = RHSTy->getAs()->getPointeeType(); if (!Context.typesAreCompatible(lhptee.getUnqualifiedType(), rhptee.getUnqualifiedType())) { @@ -3206,8 +3206,8 @@ QualType Sema::CheckConditionalOperands(Expr *&Cond, Expr *&LHS, Expr *&RHS, // Check constraints for C object pointers types (C99 6.5.15p3,6). if (LHSTy->isPointerType() && RHSTy->isPointerType()) { // get the "pointed to" types - QualType lhptee = LHSTy->getAsPointerType()->getPointeeType(); - QualType rhptee = RHSTy->getAsPointerType()->getPointeeType(); + QualType lhptee = LHSTy->getAs()->getPointeeType(); + QualType rhptee = RHSTy->getAs()->getPointeeType(); // ignore qualifiers on void (C99 6.5.15p3, clause 6) if (lhptee->isVoidType() && rhptee->isIncompleteOrObjectType()) { @@ -3313,8 +3313,8 @@ Sema::CheckPointerTypesForAssignment(QualType lhsType, QualType rhsType) { QualType lhptee, rhptee; // get the "pointed to" type (ignoring qualifiers at the top level) - lhptee = lhsType->getAsPointerType()->getPointeeType(); - rhptee = rhsType->getAsPointerType()->getPointeeType(); + lhptee = lhsType->getAs()->getPointeeType(); + rhptee = rhsType->getAs()->getPointeeType(); return CheckPointeeTypesForAssignment(lhptee, rhptee); } @@ -3396,8 +3396,8 @@ Sema::CheckBlockPointerTypesForAssignment(QualType lhsType, QualType lhptee, rhptee; // get the "pointed to" type (ignoring qualifiers at the top level) - lhptee = lhsType->getAsBlockPointerType()->getPointeeType(); - rhptee = rhsType->getAsBlockPointerType()->getPointeeType(); + lhptee = lhsType->getAs()->getPointeeType(); + rhptee = rhsType->getAs()->getPointeeType(); // make sure we operate on the canonical type lhptee = Context.getCanonicalType(lhptee); @@ -3496,12 +3496,12 @@ Sema::CheckAssignmentConstraints(QualType lhsType, QualType rhsType) { if (isa(rhsType)) { QualType rhptee = rhsType->getAsObjCObjectPointerType()->getPointeeType(); - QualType lhptee = lhsType->getAsPointerType()->getPointeeType(); + QualType lhptee = lhsType->getAs()->getPointeeType(); return CheckPointeeTypesForAssignment(lhptee, rhptee); } - if (rhsType->getAsBlockPointerType()) { - if (lhsType->getAsPointerType()->getPointeeType()->isVoidType()) + if (rhsType->getAs()) { + if (lhsType->getAs()->getPointeeType()->isVoidType()) return Compatible; // Treat block pointers as objects. @@ -3522,7 +3522,7 @@ Sema::CheckAssignmentConstraints(QualType lhsType, QualType rhsType) { if (rhsType->isBlockPointerType()) return CheckBlockPointerTypesForAssignment(lhsType, rhsType); - if (const PointerType *RHSPT = rhsType->getAsPointerType()) { + if (const PointerType *RHSPT = rhsType->getAs()) { if (RHSPT->getPointeeType()->isVoidType()) return Compatible; } @@ -3535,7 +3535,7 @@ Sema::CheckAssignmentConstraints(QualType lhsType, QualType rhsType) { if (isa(rhsType)) { QualType lhptee = lhsType->getAsObjCObjectPointerType()->getPointeeType(); - QualType rhptee = rhsType->getAsPointerType()->getPointeeType(); + QualType rhptee = rhsType->getAs()->getPointeeType(); return CheckPointeeTypesForAssignment(lhptee, rhptee); } if (rhsType->isObjCObjectPointerType()) { @@ -3545,7 +3545,7 @@ Sema::CheckAssignmentConstraints(QualType lhsType, QualType rhsType) { QualType rhptee = rhsType->getAsObjCObjectPointerType()->getPointeeType(); return CheckPointeeTypesForAssignment(lhptee, rhptee); } - if (const PointerType *RHSPT = rhsType->getAsPointerType()) { + if (const PointerType *RHSPT = rhsType->getAs()) { if (RHSPT->getPointeeType()->isVoidType()) return Compatible; } @@ -3566,7 +3566,7 @@ Sema::CheckAssignmentConstraints(QualType lhsType, QualType rhsType) { return CheckPointerTypesForAssignment(lhsType, rhsType); if (isa(lhsType) && - rhsType->getAsPointerType()->getPointeeType()->isVoidType()) + rhsType->getAs()->getPointeeType()->isVoidType()) return Compatible; return Incompatible; } @@ -3580,11 +3580,11 @@ Sema::CheckAssignmentConstraints(QualType lhsType, QualType rhsType) { if (isa(lhsType)) { QualType rhptee = lhsType->getAsObjCObjectPointerType()->getPointeeType(); - QualType lhptee = rhsType->getAsPointerType()->getPointeeType(); + QualType lhptee = rhsType->getAs()->getPointeeType(); return CheckPointeeTypesForAssignment(lhptee, rhptee); } if (isa(lhsType) && - rhsType->getAsPointerType()->getPointeeType()->isVoidType()) + rhsType->getAs()->getPointeeType()->isVoidType()) return Compatible; return Incompatible; } @@ -3636,7 +3636,7 @@ Sema::CheckTransparentUnionArgumentConstraints(QualType ArgType, Expr *&rExpr) { // 1) void pointer // 2) null pointer constant if (FromType->isPointerType()) - if (FromType->getAsPointerType()->getPointeeType()->isVoidType()) { + if (FromType->getAs()->getPointeeType()->isVoidType()) { ImpCastExprToType(rExpr, it->getType()); InitField = *it; break; @@ -3973,7 +3973,7 @@ QualType Sema::CheckSubtractionOperands(Expr *&lex, Expr *&rex, } // Handle pointer-pointer subtractions. - if (const PointerType *RHSPTy = rex->getType()->getAsPointerType()) { + if (const PointerType *RHSPTy = rex->getType()->getAs()) { QualType rpointee = RHSPTy->getPointeeType(); // RHS must be a completely-type object type. @@ -4168,9 +4168,9 @@ QualType Sema::CheckCompareOperands(Expr *&lex, Expr *&rex, SourceLocation Loc, // errors (when -pedantic-errors is enabled). if (lType->isPointerType() && rType->isPointerType()) { // C99 6.5.8p2 QualType LCanPointeeTy = - Context.getCanonicalType(lType->getAsPointerType()->getPointeeType()); + Context.getCanonicalType(lType->getAs()->getPointeeType()); QualType RCanPointeeTy = - Context.getCanonicalType(rType->getAsPointerType()->getPointeeType()); + Context.getCanonicalType(rType->getAs()->getPointeeType()); if (isRelational) { if (lType->isFunctionPointerType() || rType->isFunctionPointerType()) { @@ -4240,8 +4240,8 @@ QualType Sema::CheckCompareOperands(Expr *&lex, Expr *&rex, SourceLocation Loc, } // Handle block pointer types. if (!isRelational && lType->isBlockPointerType() && rType->isBlockPointerType()) { - QualType lpointee = lType->getAsBlockPointerType()->getPointeeType(); - QualType rpointee = rType->getAsBlockPointerType()->getPointeeType(); + QualType lpointee = lType->getAs()->getPointeeType(); + QualType rpointee = rType->getAs()->getPointeeType(); if (!LHSIsNull && !RHSIsNull && !Context.typesAreCompatible(lpointee, rpointee)) { @@ -4256,9 +4256,9 @@ QualType Sema::CheckCompareOperands(Expr *&lex, Expr *&rex, SourceLocation Loc, && ((lType->isBlockPointerType() && rType->isPointerType()) || (lType->isPointerType() && rType->isBlockPointerType()))) { if (!LHSIsNull && !RHSIsNull) { - if (!((rType->isPointerType() && rType->getAsPointerType() + if (!((rType->isPointerType() && rType->getAs() ->getPointeeType()->isVoidType()) - || (lType->isPointerType() && lType->getAsPointerType() + || (lType->isPointerType() && lType->getAs() ->getPointeeType()->isVoidType()))) Diag(Loc, diag::err_typecheck_comparison_of_distinct_blocks) << lType << rType << lex->getSourceRange() << rex->getSourceRange(); @@ -4269,8 +4269,8 @@ QualType Sema::CheckCompareOperands(Expr *&lex, Expr *&rex, SourceLocation Loc, if ((lType->isObjCObjectPointerType() || rType->isObjCObjectPointerType())) { if (lType->isPointerType() || rType->isPointerType()) { - const PointerType *LPT = lType->getAsPointerType(); - const PointerType *RPT = rType->getAsPointerType(); + const PointerType *LPT = lType->getAs(); + const PointerType *RPT = rType->getAs(); bool LPtrToVoid = LPT ? Context.getCanonicalType(LPT->getPointeeType())->isVoidType() : false; bool RPtrToVoid = RPT ? @@ -4798,7 +4798,7 @@ QualType Sema::CheckIndirectionOperand(Expr *Op, SourceLocation OpLoc) { // incomplete type or void. It would be possible to warn about dereferencing // a void pointer, but it's completely well-defined, and such a warning is // unlikely to catch any mistakes. - if (const PointerType *PT = Ty->getAsPointerType()) + if (const PointerType *PT = Ty->getAs()) return PT->getPointeeType(); if (const ObjCObjectPointerType *OPT = Ty->getAsObjCObjectPointerType()) diff --git a/lib/Sema/SemaExprCXX.cpp b/lib/Sema/SemaExprCXX.cpp index 144dc5095f..b3de60ad8a 100644 --- a/lib/Sema/SemaExprCXX.cpp +++ b/lib/Sema/SemaExprCXX.cpp @@ -136,7 +136,7 @@ bool Sema::CheckCXXThrowOperand(SourceLocation ThrowLoc, Expr *&E) { // to an incomplete type other than (cv) void the program is ill-formed. QualType Ty = E->getType(); int isPointer = 0; - if (const PointerType* Ptr = Ty->getAsPointerType()) { + if (const PointerType* Ptr = Ty->getAs()) { Ty = Ptr->getPointeeType(); isPointer = 1; } @@ -708,7 +708,7 @@ Sema::ActOnCXXDelete(SourceLocation StartLoc, bool UseGlobal, return ExprError(Diag(StartLoc, diag::err_delete_operand) << Type << Ex->getSourceRange()); - QualType Pointee = Type->getAsPointerType()->getPointeeType(); + QualType Pointee = Type->getAs()->getPointeeType(); if (Pointee->isFunctionType() || Pointee->isVoidType()) return ExprError(Diag(StartLoc, diag::err_delete_operand) << Type << Ex->getSourceRange()); @@ -812,7 +812,7 @@ Sema::IsStringLiteralToNonConstPointerConversion(Expr *From, QualType ToType) { // string literal can be converted to an rvalue of type "pointer // to wchar_t" (C++ 4.2p2). if (StringLiteral *StrLit = dyn_cast(From)) - if (const PointerType *ToPtrType = ToType->getAsPointerType()) + if (const PointerType *ToPtrType = ToType->getAs()) if (const BuiltinType *ToPointeeType = ToPtrType->getPointeeType()->getAsBuiltinType()) { // This conversion is considered only when there is an @@ -1066,7 +1066,7 @@ QualType Sema::CheckPointerToMemberOperands( // such a class] QualType LType = lex->getType(); if (isIndirect) { - if (const PointerType *Ptr = LType->getAsPointerType()) + if (const PointerType *Ptr = LType->getAs()) LType = Ptr->getPointeeType().getNonReferenceType(); else { Diag(Loc, diag::err_bad_memptr_lhs) @@ -1515,8 +1515,8 @@ QualType Sema::FindCompositePointerType(Expr *&E1, Expr *&E2) { llvm::SmallVector QualifierUnion; QualType Composite1 = T1, Composite2 = T2; const PointerType *Ptr1, *Ptr2; - while ((Ptr1 = Composite1->getAsPointerType()) && - (Ptr2 = Composite2->getAsPointerType())) { + while ((Ptr1 = Composite1->getAs()) && + (Ptr2 = Composite2->getAs())) { Composite1 = Ptr1->getPointeeType(); Composite2 = Ptr2->getPointeeType(); QualifierUnion.push_back( diff --git a/lib/Sema/SemaExprObjC.cpp b/lib/Sema/SemaExprObjC.cpp index 1131a9f0d8..c20956827b 100644 --- a/lib/Sema/SemaExprObjC.cpp +++ b/lib/Sema/SemaExprObjC.cpp @@ -859,7 +859,7 @@ bool Sema::ObjCQualifiedIdTypesAreCompatible(QualType lhs, QualType rhs, if (!lhs->isPointerType()) return false; - QualType ltype = lhs->getAsPointerType()->getPointeeType(); + QualType ltype = lhs->getAs()->getPointeeType(); if (const ObjCQualifiedInterfaceType *lhsQI = ltype->getAsObjCQualifiedInterfaceType()) { ObjCObjectPointerType::qual_iterator LHSProtoI = lhsQI->qual_begin(); diff --git a/lib/Sema/SemaLookup.cpp b/lib/Sema/SemaLookup.cpp index c88321e1a3..a37be6898f 100644 --- a/lib/Sema/SemaLookup.cpp +++ b/lib/Sema/SemaLookup.cpp @@ -1435,7 +1435,7 @@ addAssociatedClassesAndNamespaces(QualType T, // We handle this by unwrapping pointer and array types immediately, // to avoid unnecessary recursion. while (true) { - if (const PointerType *Ptr = T->getAsPointerType()) + if (const PointerType *Ptr = T->getAs()) T = Ptr->getPointeeType(); else if (const ArrayType *Ptr = Context.getAsArrayType(T)) T = Ptr->getElementType(); diff --git a/lib/Sema/SemaNamedCast.cpp b/lib/Sema/SemaNamedCast.cpp index daf6800ea0..4b58b3d0c7 100644 --- a/lib/Sema/SemaNamedCast.cpp +++ b/lib/Sema/SemaNamedCast.cpp @@ -529,10 +529,10 @@ CheckStaticCast(Sema &Self, Expr *&SrcExpr, QualType DestType, // Reverse pointer conversion to void*. C++ 4.10.p2 specifies conversion to // void*. C++ 5.2.9p10 specifies additional restrictions, which really is // just the usual constness stuff. - if (const PointerType *SrcPointer = SrcType->getAsPointerType()) { + if (const PointerType *SrcPointer = SrcType->getAs()) { QualType SrcPointee = SrcPointer->getPointeeType(); if (SrcPointee->isVoidType()) { - if (const PointerType *DestPointer = DestType->getAsPointerType()) { + if (const PointerType *DestPointer = DestType->getAs()) { QualType DestPointee = DestPointer->getPointeeType(); if (DestPointee->isIncompleteOrObjectType()) { // This is definitely the intended conversion, but it might fail due @@ -627,12 +627,12 @@ TryStaticPointerDowncast(Sema &Self, QualType SrcType, QualType DestType, // In addition, DR54 clarifies that the base must be accessible in the // current context. - const PointerType *SrcPointer = SrcType->getAsPointerType(); + const PointerType *SrcPointer = SrcType->getAs(); if (!SrcPointer) { return TSC_NotApplicable; } - const PointerType *DestPointer = DestType->getAsPointerType(); + const PointerType *DestPointer = DestType->getAs(); if (!DestPointer) { return TSC_NotApplicable; } @@ -828,7 +828,7 @@ CheckDynamicCast(Sema &Self, Expr *&SrcExpr, QualType DestType, // or "pointer to cv void". QualType DestPointee; - const PointerType *DestPointer = DestType->getAsPointerType(); + const PointerType *DestPointer = DestType->getAs(); const ReferenceType *DestReference = DestType->getAsReferenceType(); if (DestPointer) { DestPointee = DestPointer->getPointeeType(); @@ -863,7 +863,7 @@ CheckDynamicCast(Sema &Self, Expr *&SrcExpr, QualType DestType, QualType SrcType = Self.Context.getCanonicalType(OrigSrcType); QualType SrcPointee; if (DestPointer) { - if (const PointerType *SrcPointer = SrcType->getAsPointerType()) { + if (const PointerType *SrcPointer = SrcType->getAs()) { SrcPointee = SrcPointer->getPointeeType(); } else { Self.Diag(OpRange.getBegin(), diag::err_bad_dynamic_cast_not_ptr) diff --git a/lib/Sema/SemaOverload.cpp b/lib/Sema/SemaOverload.cpp index d0d61c6ed1..dc24a0384d 100644 --- a/lib/Sema/SemaOverload.cpp +++ b/lib/Sema/SemaOverload.cpp @@ -173,7 +173,7 @@ isPointerConversionToVoidPointer(ASTContext& Context) const FromType = Context.getArrayDecayedType(FromType); if (Second == ICK_Pointer_Conversion) - if (const PointerType* ToPtrType = ToType->getAsPointerType()) + if (const PointerType* ToPtrType = ToType->getAs()) return ToPtrType->getPointeeType()->isVoidType(); return false; @@ -915,7 +915,7 @@ bool Sema::IsPointerConversion(Expr *From, QualType FromType, QualType ToType, // Blocks: Block pointers can be converted to void*. if (FromType->isBlockPointerType() && ToType->isPointerType() && - ToType->getAsPointerType()->getPointeeType()->isVoidType()) { + ToType->getAs()->getPointeeType()->isVoidType()) { ConvertedType = ToType; return true; } @@ -933,7 +933,7 @@ bool Sema::IsPointerConversion(Expr *From, QualType FromType, QualType ToType, return true; } - const PointerType* ToTypePtr = ToType->getAsPointerType(); + const PointerType* ToTypePtr = ToType->getAs(); if (!ToTypePtr) return false; @@ -944,7 +944,7 @@ bool Sema::IsPointerConversion(Expr *From, QualType FromType, QualType ToType, } // Beyond this point, both types need to be pointers. - const PointerType *FromTypePtr = FromType->getAsPointerType(); + const PointerType *FromTypePtr = FromType->getAs(); if (!FromTypePtr) return false; @@ -1042,17 +1042,17 @@ bool Sema::isObjCPointerConversion(QualType FromType, QualType ToType, } // Beyond this point, both types need to be C pointers or block pointers. QualType ToPointeeType; - if (const PointerType *ToCPtr = ToType->getAsPointerType()) + if (const PointerType *ToCPtr = ToType->getAs()) ToPointeeType = ToCPtr->getPointeeType(); - else if (const BlockPointerType *ToBlockPtr = ToType->getAsBlockPointerType()) + else if (const BlockPointerType *ToBlockPtr = ToType->getAs()) ToPointeeType = ToBlockPtr->getPointeeType(); else return false; QualType FromPointeeType; - if (const PointerType *FromCPtr = FromType->getAsPointerType()) + if (const PointerType *FromCPtr = FromType->getAs()) FromPointeeType = FromCPtr->getPointeeType(); - else if (const BlockPointerType *FromBlockPtr = FromType->getAsBlockPointerType()) + else if (const BlockPointerType *FromBlockPtr = FromType->getAs()) FromPointeeType = FromBlockPtr->getPointeeType(); else return false; @@ -1142,8 +1142,8 @@ bool Sema::isObjCPointerConversion(QualType FromType, QualType ToType, bool Sema::CheckPointerConversion(Expr *From, QualType ToType) { QualType FromType = From->getType(); - if (const PointerType *FromPtrType = FromType->getAsPointerType()) - if (const PointerType *ToPtrType = ToType->getAsPointerType()) { + if (const PointerType *FromPtrType = FromType->getAs()) + if (const PointerType *ToPtrType = ToType->getAs()) { QualType FromPointeeType = FromPtrType->getPointeeType(), ToPointeeType = ToPtrType->getPointeeType(); @@ -1404,7 +1404,7 @@ bool Sema::IsUserDefinedConversion(Expr *From, QualType ToType, User.ConversionFunction = Constructor; User.After.setAsIdentityConversion(); User.After.FromTypePtr - = ThisType->getAsPointerType()->getPointeeType().getAsOpaquePtr(); + = ThisType->getAs()->getPointeeType().getAsOpaquePtr(); User.After.ToTypePtr = ToType.getAsOpaquePtr(); return true; } else if (CXXConversionDecl *Conversion @@ -1579,9 +1579,9 @@ Sema::CompareStandardConversionSequences(const StandardConversionSequence& SCS1, FromType2 = Context.getArrayDecayedType(FromType2); QualType FromPointee1 - = FromType1->getAsPointerType()->getPointeeType().getUnqualifiedType(); + = FromType1->getAs()->getPointeeType().getUnqualifiedType(); QualType FromPointee2 - = FromType2->getAsPointerType()->getPointeeType().getUnqualifiedType(); + = FromType2->getAs()->getPointeeType().getUnqualifiedType(); if (IsDerivedFrom(FromPointee2, FromPointee1)) return ImplicitConversionSequence::Better; @@ -1771,13 +1771,13 @@ Sema::CompareDerivedToBaseConversions(const StandardConversionSequence& SCS1, FromType1->isPointerType() && FromType2->isPointerType() && ToType1->isPointerType() && ToType2->isPointerType()) { QualType FromPointee1 - = FromType1->getAsPointerType()->getPointeeType().getUnqualifiedType(); + = FromType1->getAs()->getPointeeType().getUnqualifiedType(); QualType ToPointee1 - = ToType1->getAsPointerType()->getPointeeType().getUnqualifiedType(); + = ToType1->getAs()->getPointeeType().getUnqualifiedType(); QualType FromPointee2 - = FromType2->getAsPointerType()->getPointeeType().getUnqualifiedType(); + = FromType2->getAs()->getPointeeType().getUnqualifiedType(); QualType ToPointee2 - = ToType2->getAsPointerType()->getPointeeType().getUnqualifiedType(); + = ToType2->getAs()->getPointeeType().getUnqualifiedType(); const ObjCInterfaceType* FromIface1 = FromPointee1->getAsObjCInterfaceType(); const ObjCInterfaceType* FromIface2 = FromPointee2->getAsObjCInterfaceType(); @@ -1943,7 +1943,7 @@ Sema::TryObjectArgumentInitialization(Expr *From, CXXMethodDecl *Method) { // We need to have an object of class type. QualType FromType = From->getType(); - if (const PointerType *PT = FromType->getAsPointerType()) + if (const PointerType *PT = FromType->getAs()) FromType = PT->getPointeeType(); assert(FromType->isRecordType()); @@ -1991,9 +1991,9 @@ bool Sema::PerformObjectArgumentInitialization(Expr *&From, CXXMethodDecl *Method) { QualType FromRecordType, DestType; QualType ImplicitParamRecordType = - Method->getThisType(Context)->getAsPointerType()->getPointeeType(); + Method->getThisType(Context)->getAs()->getPointeeType(); - if (const PointerType *PT = From->getType()->getAsPointerType()) { + if (const PointerType *PT = From->getType()->getAs()) { FromRecordType = PT->getPointeeType(); DestType = Method->getThisType(Context); } else { @@ -2634,7 +2634,7 @@ BuiltinCandidateTypeSet::AddPointerWithMoreQualifiedTypeVariants(QualType Ty) { if (!PointerTypes.insert(Ty)) return false; - if (const PointerType *PointerTy = Ty->getAsPointerType()) { + if (const PointerType *PointerTy = Ty->getAs()) { QualType PointeeTy = PointerTy->getPointeeType(); // FIXME: Optimize this so that we don't keep trying to add the same types. @@ -2710,7 +2710,7 @@ BuiltinCandidateTypeSet::AddTypesConvertedFrom(QualType Ty, // We don't care about qualifiers on the type. Ty = Ty.getUnqualifiedType(); - if (const PointerType *PointerTy = Ty->getAsPointerType()) { + if (const PointerType *PointerTy = Ty->getAs()) { QualType PointeeTy = PointerTy->getPointeeType(); // Insert our type, and its more-qualified variants, into the set @@ -2898,7 +2898,7 @@ Sema::AddBuiltinOperatorCandidates(OverloadedOperatorKind Op, for (BuiltinCandidateTypeSet::iterator Ptr = CandidateTypes.pointer_begin(); Ptr != CandidateTypes.pointer_end(); ++Ptr) { // Skip pointer types that aren't pointers to object types. - if (!(*Ptr)->getAsPointerType()->getPointeeType()->isObjectType()) + if (!(*Ptr)->getAs()->getPointeeType()->isObjectType()) continue; QualType ParamTypes[2] = { @@ -2936,7 +2936,7 @@ Sema::AddBuiltinOperatorCandidates(OverloadedOperatorKind Op, for (BuiltinCandidateTypeSet::iterator Ptr = CandidateTypes.pointer_begin(); Ptr != CandidateTypes.pointer_end(); ++Ptr) { QualType ParamTy = *Ptr; - QualType PointeeTy = ParamTy->getAsPointerType()->getPointeeType(); + QualType PointeeTy = ParamTy->getAs()->getPointeeType(); AddBuiltinCandidate(Context.getLValueReferenceType(PointeeTy), &ParamTy, Args, 1, CandidateSet); } @@ -3336,7 +3336,7 @@ Sema::AddBuiltinOperatorCandidates(OverloadedOperatorKind Op, for (BuiltinCandidateTypeSet::iterator Ptr = CandidateTypes.pointer_begin(); Ptr != CandidateTypes.pointer_end(); ++Ptr) { QualType ParamTypes[2] = { *Ptr, Context.getPointerDiffType() }; - QualType PointeeType = (*Ptr)->getAsPointerType()->getPointeeType(); + QualType PointeeType = (*Ptr)->getAs()->getPointeeType(); QualType ResultTy = Context.getLValueReferenceType(PointeeType); // T& operator[](T*, ptrdiff_t) @@ -3624,7 +3624,7 @@ Sema::PrintOverloadCandidates(OverloadCandidateSet& CandidateSet, FnType = FnTypeRef->getPointeeType(); isRValueReference = true; } - if (const PointerType *FnTypePtr = FnType->getAsPointerType()) { + if (const PointerType *FnTypePtr = FnType->getAs()) { FnType = FnTypePtr->getPointeeType(); isPointer = true; } @@ -3673,7 +3673,7 @@ Sema::ResolveAddressOfOverloadedFunction(Expr *From, QualType ToType, bool Complain) { QualType FunctionType = ToType; bool IsMember = false; - if (const PointerType *ToTypePtr = ToType->getAsPointerType()) + if (const PointerType *ToTypePtr = ToType->getAs()) FunctionType = ToTypePtr->getPointeeType(); else if (const ReferenceType *ToTypeRef = ToType->getAsReferenceType()) FunctionType = ToTypeRef->getPointeeType(); @@ -4414,7 +4414,7 @@ Sema::BuildCallToObjectOfClassType(Scope *S, Expr *Object, // Strip the reference type (if any) and then the pointer type (if // any) to get down to what might be a function type. QualType ConvType = Conv->getConversionType().getNonReferenceType(); - if (const PointerType *ConvPtrType = ConvType->getAsPointerType()) + if (const PointerType *ConvPtrType = ConvType->getAs()) ConvType = ConvPtrType->getPointeeType(); if (const FunctionProtoType *Proto = ConvType->getAsFunctionProtoType()) diff --git a/lib/Sema/SemaStmt.cpp b/lib/Sema/SemaStmt.cpp index bd2b0aef3d..0a7ed462f8 100644 --- a/lib/Sema/SemaStmt.cpp +++ b/lib/Sema/SemaStmt.cpp @@ -1204,7 +1204,7 @@ Sema::ActOnObjCAtThrowStmt(SourceLocation AtLoc, ExprArg expr,Scope *CurScope) { QualType ThrowType = ThrowExpr->getType(); // Make sure the expression type is an ObjC pointer or "void *". if (!ThrowType->isObjCObjectPointerType()) { - const PointerType *PT = ThrowType->getAsPointerType(); + const PointerType *PT = ThrowType->getAs(); if (!PT || !PT->getPointeeType()->isVoidType()) return StmtError(Diag(AtLoc, diag::error_objc_throw_expects_object) << ThrowExpr->getType() << ThrowExpr->getSourceRange()); @@ -1221,7 +1221,7 @@ Sema::ActOnObjCAtSynchronizedStmt(SourceLocation AtLoc, ExprArg SynchExpr, // Make sure the expression type is an ObjC pointer or "void *". Expr *SyncExpr = static_cast(SynchExpr.get()); if (!SyncExpr->getType()->isObjCObjectPointerType()) { - const PointerType *PT = SyncExpr->getType()->getAsPointerType(); + const PointerType *PT = SyncExpr->getType()->getAs(); if (!PT || !PT->getPointeeType()->isVoidType()) return StmtError(Diag(AtLoc, diag::error_objc_synchronized_expects_object) << SyncExpr->getType() << SyncExpr->getSourceRange()); diff --git a/lib/Sema/SemaTemplate.cpp b/lib/Sema/SemaTemplate.cpp index 568d68c9a7..85d38671f1 100644 --- a/lib/Sema/SemaTemplate.cpp +++ b/lib/Sema/SemaTemplate.cpp @@ -225,8 +225,8 @@ Sema::CheckNonTypeTemplateParameterType(QualType T, SourceLocation Loc) { if (T->isIntegralType() || T->isEnumeralType() || // -- pointer to object or pointer to function, (T->isPointerType() && - (T->getAsPointerType()->getPointeeType()->isObjectType() || - T->getAsPointerType()->getPointeeType()->isFunctionType())) || + (T->getAs()->getPointeeType()->isObjectType() || + T->getAs()->getPointeeType()->isFunctionType())) || // -- reference to object or reference to function, T->isReferenceType() || // -- pointer to member. @@ -1648,7 +1648,7 @@ bool Sema::CheckTemplateArgument(NonTypeTemplateParmDecl *Param, // function is selected from the set (13.4). // In C++0x, any std::nullptr_t value can be converted. (ParamType->isPointerType() && - ParamType->getAsPointerType()->getPointeeType()->isFunctionType()) || + ParamType->getAs()->getPointeeType()->isFunctionType()) || // -- For a non-type template-parameter of type reference to // function, no conversions apply. If the template-argument // represents a set of overloaded functions, the matching @@ -1721,7 +1721,7 @@ bool Sema::CheckTemplateArgument(NonTypeTemplateParmDecl *Param, // object, qualification conversions (4.4) and the // array-to-pointer conversion (4.2) are applied. // C++0x also allows a value of std::nullptr_t. - assert(ParamType->getAsPointerType()->getPointeeType()->isObjectType() && + assert(ParamType->getAs()->getPointeeType()->isObjectType() && "Only object pointers allowed here"); if (ArgType->isNullPtrType()) { diff --git a/lib/Sema/SemaTemplateDeduction.cpp b/lib/Sema/SemaTemplateDeduction.cpp index f6f9d105d9..b304751beb 100644 --- a/lib/Sema/SemaTemplateDeduction.cpp +++ b/lib/Sema/SemaTemplateDeduction.cpp @@ -397,7 +397,7 @@ DeduceTemplateArguments(ASTContext &Context, // T * case Type::Pointer: { - const PointerType *PointerArg = Arg->getAsPointerType(); + const PointerType *PointerArg = Arg->getAs(); if (!PointerArg) return Sema::TDK_NonDeducedMismatch; @@ -1320,7 +1320,7 @@ Sema::DeduceTemplateArguments(FunctionTemplateDecl *FunctionTemplate, if (isSimpleTemplateIdType(ParamType) || (isa(ParamType) && isSimpleTemplateIdType( - ParamType->getAsPointerType()->getPointeeType()))) + ParamType->getAs()->getPointeeType()))) TDF |= TDF_DerivedClass; if (TemplateDeductionResult Result diff --git a/lib/Sema/SemaType.cpp b/lib/Sema/SemaType.cpp index 8195aba967..ee4cd204b9 100644 --- a/lib/Sema/SemaType.cpp +++ b/lib/Sema/SemaType.cpp @@ -300,7 +300,7 @@ QualType Sema::ConvertDeclSpecToType(const DeclSpec &DS, if (TypeQuals & QualType::Restrict) { if (Result->isPointerType() || Result->isReferenceType()) { QualType EltTy = Result->isPointerType() ? - Result->getAsPointerType()->getPointeeType() : + Result->getAs()->getPointeeType() : Result->getAsReferenceType()->getPointeeType(); // If we have a pointer or reference, the pointee must have an object @@ -1185,7 +1185,7 @@ bool Sema::CheckSpecifiedExceptionType(QualType T, const SourceRange &Range) { // an incomplete type a pointer or reference to an incomplete type, other // than (cv) void*. int kind; - if (const PointerType* IT = T->getAsPointerType()) { + if (const PointerType* IT = T->getAs()) { T = IT->getPointeeType(); kind = 1; } else if (const ReferenceType* IT = T->getAsReferenceType()) { @@ -1205,7 +1205,7 @@ bool Sema::CheckSpecifiedExceptionType(QualType T, const SourceRange &Range) { /// to member to a function with an exception specification. This means that /// it is invalid to add another level of indirection. bool Sema::CheckDistantExceptionSpec(QualType T) { - if (const PointerType *PT = T->getAsPointerType()) + if (const PointerType *PT = T->getAs()) T = PT->getPointeeType(); else if (const MemberPointerType *PT = T->getAsMemberPointerType()) T = PT->getPointeeType(); @@ -1287,7 +1287,7 @@ bool Sema::CheckExceptionSpecSubset(unsigned DiagID, unsigned NoteID, bool SubIsPointer = false; if (const ReferenceType *RefTy = CanonicalSubT->getAsReferenceType()) CanonicalSubT = RefTy->getPointeeType(); - if (const PointerType *PtrTy = CanonicalSubT->getAsPointerType()) { + if (const PointerType *PtrTy = CanonicalSubT->getAs()) { CanonicalSubT = PtrTy->getPointeeType(); SubIsPointer = true; } @@ -1308,7 +1308,7 @@ bool Sema::CheckExceptionSpecSubset(unsigned DiagID, unsigned NoteID, if (const ReferenceType *RefTy = CanonicalSuperT->getAsReferenceType()) CanonicalSuperT = RefTy->getPointeeType(); if (SubIsPointer) { - if (const PointerType *PtrTy = CanonicalSuperT->getAsPointerType()) + if (const PointerType *PtrTy = CanonicalSuperT->getAs()) CanonicalSuperT = PtrTy->getPointeeType(); else { continue; @@ -1384,8 +1384,8 @@ QualType Sema::ObjCGetTypeForMethodDefinition(DeclPtrTy D) { /// be called in a loop that successively "unwraps" pointer and /// pointer-to-member types to compare them at each level. bool Sema::UnwrapSimilarPointerTypes(QualType& T1, QualType& T2) { - const PointerType *T1PtrType = T1->getAsPointerType(), - *T2PtrType = T2->getAsPointerType(); + const PointerType *T1PtrType = T1->getAs(), + *T2PtrType = T2->getAs(); if (T1PtrType && T2PtrType) { T1 = T1PtrType->getPointeeType(); T2 = T2PtrType->getPointeeType();