Add member template 'Type::getAs<T>', 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<Type> 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<PointerType>.
b) Removed 'Type::getAsBlockPointerTypE()'; now clients use getAs<BlockPointerType>.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@76098 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/SemaChecking.cpp b/lib/Sema/SemaChecking.cpp
index 4eed018..6256872 100644
--- a/lib/Sema/SemaChecking.cpp
+++ b/lib/Sema/SemaChecking.cpp
@@ -205,7 +205,7 @@
       bool HasVAListArg = Format->getFirstArg() == 0;
       if (!HasVAListArg) {
         const FunctionType *FT = 
-          Ty->getAsBlockPointerType()->getPointeeType()->getAsFunctionType();
+          Ty->getAs<BlockPointerType>()->getPointeeType()->getAsFunctionType();
         if (const FunctionProtoType *Proto = dyn_cast<FunctionProtoType>(FT))
           HasVAListArg = !Proto->isVariadic();
       }
@@ -241,7 +241,7 @@
     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<PointerType>()->getPointeeType();
   if (!ValType->isIntegerType() && !ValType->isPointerType() && 
       !ValType->isBlockPointerType())
     return Diag(DRE->getLocStart(),
@@ -344,7 +344,7 @@
                                            TUScope, false, DRE->getLocStart()));
   const FunctionProtoType *BuiltinFT =
     NewBuiltinDecl->getType()->getAsFunctionProtoType();
-  ValType = BuiltinFT->getArgType(0)->getAsPointerType()->getPointeeType();
+  ValType = BuiltinFT->getArgType(0)->getAs<PointerType>()->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 @@
       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<PointerType>()) {
         isConstant = T.isConstant(Context) && 
                      PT->getPointeeType().isConstant(Context);
       }
diff --git a/lib/Sema/SemaDeclAttr.cpp b/lib/Sema/SemaDeclAttr.cpp
index 09cb96b..5d05b4c 100644
--- a/lib/Sema/SemaDeclAttr.cpp
+++ b/lib/Sema/SemaDeclAttr.cpp
@@ -36,9 +36,9 @@
     return 0;
   
   if (Ty->isFunctionPointerType())
-    Ty = Ty->getAsPointerType()->getPointeeType();
+    Ty = Ty->getAs<PointerType>()->getPointeeType();
   else if (blocksToo && Ty->isBlockPointerType())
-    Ty = Ty->getAsBlockPointerType()->getPointeeType();
+    Ty = Ty->getAs<BlockPointerType>()->getPointeeType();
 
   return Ty->getAsFunctionType();
 }
@@ -133,7 +133,7 @@
 }
 
 static inline bool isCFStringType(QualType T, ASTContext &Ctx) {
-  const PointerType *PT = T->getAsPointerType();
+  const PointerType *PT = T->getAs<PointerType>();
   if (!PT)
     return false;
 
@@ -632,7 +632,7 @@
   if (TypedefDecl *TD = dyn_cast<TypedefDecl>(D)) {
     QualType T = TD->getUnderlyingType();
     if (!T->isPointerType() ||
-        !T->getAsPointerType()->getPointeeType()->isRecordType()) {
+        !T->getAs<PointerType>()->getPointeeType()->isRecordType()) {
       S.Diag(TD->getLocation(), diag::err_nsobject_attribute);
       return;
     }
@@ -751,7 +751,7 @@
     QualType Ty = V->getType();
     if (Ty->isBlockPointerType() || Ty->isFunctionPointerType()) {
       const FunctionType *FT = Ty->isFunctionPointerType() ? getFunctionType(d) 
-        : Ty->getAsBlockPointerType()->getPointeeType()->getAsFunctionType();
+        : Ty->getAs<BlockPointerType>()->getPointeeType()->getAsFunctionType();
       if (!cast<FunctionProtoType>(FT)->isVariadic()) {
         int m = Ty->isFunctionPointerType() ? 0 : 1;
         S.Diag(Attr.getLoc(), diag::warn_attribute_sentinel_not_variadic) << m;
@@ -1147,7 +1147,7 @@
   if (not_nsstring_type &&
       !isCFStringType(Ty, S.Context) &&
       (!Ty->isPointerType() ||
-       !Ty->getAsPointerType()->getPointeeType()->isCharType())) {
+       !Ty->getAs<PointerType>()->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 @@
   if (!isNSStringType(Ty, S.Context) &&
       !isCFStringType(Ty, S.Context) &&
       (!Ty->isPointerType() ||
-       !Ty->getAsPointerType()->getPointeeType()->isCharType())) {
+       !Ty->getAs<PointerType>()->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 @@
       return;
     }    
   } else if (!Ty->isPointerType() ||
-             !Ty->getAsPointerType()->getPointeeType()->isCharType()) {
+             !Ty->getAs<PointerType>()->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 @@
     return;
   }
   
-  if (!(S.Context.isObjCNSObjectType(RetTy) || RetTy->getAsPointerType()
+  if (!(S.Context.isObjCNSObjectType(RetTy) || RetTy->getAs<PointerType>()
         || 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 c62858a..21daa8f 100644
--- a/lib/Sema/SemaDeclCXX.cpp
+++ b/lib/Sema/SemaDeclCXX.cpp
@@ -1009,9 +1009,9 @@
     return RequireNonAbstractType(Loc, AT->getElementType(), DiagID, SelID,
                                   CurrentRD);
   
-  if (const PointerType *PT = T->getAsPointerType()) {
+  if (const PointerType *PT = T->getAs<PointerType>()) {
     // Find the innermost pointer type.
-    while (const PointerType *T = PT->getPointeeType()->getAsPointerType())
+    while (const PointerType *T = PT->getPointeeType()->getAs<PointerType>())
       PT = T;
     
     if (const ArrayType *AT = Context.getAsArrayType(PT->getPointeeType()))
@@ -3079,7 +3079,7 @@
   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<PointerType>()) {
     BaseType = Ptr->getPointeeType();
     Mode = 1;
     DK = diag::err_catch_incomplete_ptr;
diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp
index 1304558..a229791 100644
--- a/lib/Sema/SemaExpr.cpp
+++ b/lib/Sema/SemaExpr.cpp
@@ -133,8 +133,8 @@
     QualType Ty = V->getType();
     if (Ty->isBlockPointerType() || Ty->isFunctionPointerType()) {
       const FunctionType *FT = Ty->isFunctionPointerType() 
-      ? Ty->getAsPointerType()->getPointeeType()->getAsFunctionType()
-      : Ty->getAsBlockPointerType()->getPointeeType()->getAsFunctionType();
+      ? Ty->getAs<PointerType>()->getPointeeType()->getAsFunctionType()
+      : Ty->getAs<BlockPointerType>()->getPointeeType()->getAsFunctionType();
       if (const FunctionProtoType *Proto = dyn_cast<FunctionProtoType>(FT)) {
         unsigned NumArgsInProto = Proto->getNumArgs();
         unsigned k;
@@ -756,7 +756,7 @@
     // 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<PointerType>()) {
       BaseObjectIsPointer = true;
       ObjectType = ObjectPtr->getPointeeType();
     }
@@ -1835,11 +1835,11 @@
     BaseExpr = LHSExp;
     IndexExpr = RHSExp;
     ResultType = Context.DependentTy;
-  } else if (const PointerType *PTy = LHSTy->getAsPointerType()) {
+  } else if (const PointerType *PTy = LHSTy->getAs<PointerType>()) {
     BaseExpr = LHSExp;
     IndexExpr = RHSExp;
     ResultType = PTy->getPointeeType();
-  } else if (const PointerType *PTy = RHSTy->getAsPointerType()) {
+  } else if (const PointerType *PTy = RHSTy->getAs<PointerType>()) {
      // Handle the uncommon case of "123[Ptr]".
     BaseExpr = RHSExp;
     IndexExpr = LHSExp;
@@ -1874,7 +1874,7 @@
 
     BaseExpr = LHSExp;
     IndexExpr = RHSExp;
-    ResultType = LHSTy->getAsPointerType()->getPointeeType();
+    ResultType = LHSTy->getAs<PointerType>()->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 @@
 
     BaseExpr = RHSExp;
     IndexExpr = LHSExp;
-    ResultType = RHSTy->getAsPointerType()->getPointeeType();
+    ResultType = RHSTy->getAs<PointerType>()->getPointeeType();
   } else {
     return ExprError(Diag(LLoc, diag::err_typecheck_subscript_value)
        << LHSExp->getSourceRange() << RHSExp->getSourceRange());
@@ -2098,7 +2098,7 @@
                                                          OpLoc, 
                                                      DeclarationName(&Member),
                                                          MemberLoc));
-    else if (const PointerType *PT = BaseType->getAsPointerType())
+    else if (const PointerType *PT = BaseType->getAs<PointerType>())
       BaseType = PT->getPointeeType();
     else if (BaseType->isObjCObjectPointerType())
       ;
@@ -2119,7 +2119,7 @@
       // 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<PointerType>();
 
       if (!PT || (getLangOptions().ObjC1 && 
                   !PT->getPointeeType()->isRecordType()))
@@ -2500,7 +2500,7 @@
   if (BaseType == Context.OverloadTy || 
       BaseType->isFunctionType() ||
       (BaseType->isPointerType() && 
-       BaseType->getAsPointerType()->isFunctionType())) {
+       BaseType->getAs<PointerType>()->isFunctionType())) {
     SourceLocation Loc = PP.getLocForEndOfToken(BaseExpr->getLocEnd());
     Diag(Loc, diag::note_member_reference_needs_call)
       << CodeModificationHint::CreateInsertion(Loc, "()");
@@ -2794,13 +2794,13 @@
   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<PointerType>();
     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<BlockPointerType>()->getPointeeType()->
                 getAsFunctionType();
   }
   if (FuncT == 0)
@@ -3131,8 +3131,8 @@
       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<BlockPointerType>()->getPointeeType();
+    QualType rhptee = RHSTy->getAs<BlockPointerType>()->getPointeeType();
 
     if (!Context.typesAreCompatible(lhptee.getUnqualifiedType(),
                                     rhptee.getUnqualifiedType())) {
@@ -3206,8 +3206,8 @@
   // 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<PointerType>()->getPointeeType();
+    QualType rhptee = RHSTy->getAs<PointerType>()->getPointeeType();
 
     // ignore qualifiers on void (C99 6.5.15p3, clause 6)
     if (lhptee->isVoidType() && rhptee->isIncompleteOrObjectType()) {
@@ -3313,8 +3313,8 @@
   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<PointerType>()->getPointeeType();
+  rhptee = rhsType->getAs<PointerType>()->getPointeeType();
 
   return CheckPointeeTypesForAssignment(lhptee, rhptee);
 }
@@ -3396,8 +3396,8 @@
   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<BlockPointerType>()->getPointeeType();
+  rhptee = rhsType->getAs<BlockPointerType>()->getPointeeType();
 
   // make sure we operate on the canonical type
   lhptee = Context.getCanonicalType(lhptee);
@@ -3496,12 +3496,12 @@
 
     if (isa<ObjCObjectPointerType>(rhsType)) {
       QualType rhptee = rhsType->getAsObjCObjectPointerType()->getPointeeType();
-      QualType lhptee = lhsType->getAsPointerType()->getPointeeType();
+      QualType lhptee = lhsType->getAs<PointerType>()->getPointeeType();
       return CheckPointeeTypesForAssignment(lhptee, rhptee);
     }
 
-    if (rhsType->getAsBlockPointerType()) {
-      if (lhsType->getAsPointerType()->getPointeeType()->isVoidType())
+    if (rhsType->getAs<BlockPointerType>()) {
+      if (lhsType->getAs<PointerType>()->getPointeeType()->isVoidType())
         return Compatible;
 
       // Treat block pointers as objects.
@@ -3522,7 +3522,7 @@
     if (rhsType->isBlockPointerType())
       return CheckBlockPointerTypesForAssignment(lhsType, rhsType);
 
-    if (const PointerType *RHSPT = rhsType->getAsPointerType()) {
+    if (const PointerType *RHSPT = rhsType->getAs<PointerType>()) {
       if (RHSPT->getPointeeType()->isVoidType())
         return Compatible;
     }
@@ -3535,7 +3535,7 @@
 
     if (isa<PointerType>(rhsType)) {
       QualType lhptee = lhsType->getAsObjCObjectPointerType()->getPointeeType();
-      QualType rhptee = rhsType->getAsPointerType()->getPointeeType();
+      QualType rhptee = rhsType->getAs<PointerType>()->getPointeeType();
       return CheckPointeeTypesForAssignment(lhptee, rhptee);
     }
     if (rhsType->isObjCObjectPointerType()) {
@@ -3545,7 +3545,7 @@
       QualType rhptee = rhsType->getAsObjCObjectPointerType()->getPointeeType();
       return CheckPointeeTypesForAssignment(lhptee, rhptee);
     }
-    if (const PointerType *RHSPT = rhsType->getAsPointerType()) {
+    if (const PointerType *RHSPT = rhsType->getAs<PointerType>()) {
       if (RHSPT->getPointeeType()->isVoidType())
         return Compatible;
     }
@@ -3566,7 +3566,7 @@
       return CheckPointerTypesForAssignment(lhsType, rhsType);
 
     if (isa<BlockPointerType>(lhsType) &&
-        rhsType->getAsPointerType()->getPointeeType()->isVoidType())
+        rhsType->getAs<PointerType>()->getPointeeType()->isVoidType())
       return Compatible;
     return Incompatible;
   }
@@ -3580,11 +3580,11 @@
 
     if (isa<PointerType>(lhsType)) {
       QualType rhptee = lhsType->getAsObjCObjectPointerType()->getPointeeType();
-      QualType lhptee = rhsType->getAsPointerType()->getPointeeType();
+      QualType lhptee = rhsType->getAs<PointerType>()->getPointeeType();
       return CheckPointeeTypesForAssignment(lhptee, rhptee);
     }
     if (isa<BlockPointerType>(lhsType) &&
-        rhsType->getAsPointerType()->getPointeeType()->isVoidType())
+        rhsType->getAs<PointerType>()->getPointeeType()->isVoidType())
       return Compatible;
     return Incompatible;
   }
@@ -3636,7 +3636,7 @@
       // 1) void pointer
       // 2) null pointer constant
       if (FromType->isPointerType())
-        if (FromType->getAsPointerType()->getPointeeType()->isVoidType()) {
+        if (FromType->getAs<PointerType>()->getPointeeType()->isVoidType()) {
           ImpCastExprToType(rExpr, it->getType());
           InitField = *it;
           break;
@@ -3973,7 +3973,7 @@
     }
 
     // Handle pointer-pointer subtractions.
-    if (const PointerType *RHSPTy = rex->getType()->getAsPointerType()) {
+    if (const PointerType *RHSPTy = rex->getType()->getAs<PointerType>()) {
       QualType rpointee = RHSPTy->getPointeeType();
 
       // RHS must be a completely-type object type.
@@ -4168,9 +4168,9 @@
   // 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<PointerType>()->getPointeeType());
     QualType RCanPointeeTy =
-      Context.getCanonicalType(rType->getAsPointerType()->getPointeeType());
+      Context.getCanonicalType(rType->getAs<PointerType>()->getPointeeType());
 
     if (isRelational) {
       if (lType->isFunctionPointerType() || rType->isFunctionPointerType()) {
@@ -4240,8 +4240,8 @@
   }
   // Handle block pointer types.
   if (!isRelational && lType->isBlockPointerType() && rType->isBlockPointerType()) {
-    QualType lpointee = lType->getAsBlockPointerType()->getPointeeType();
-    QualType rpointee = rType->getAsBlockPointerType()->getPointeeType();
+    QualType lpointee = lType->getAs<BlockPointerType>()->getPointeeType();
+    QualType rpointee = rType->getAs<BlockPointerType>()->getPointeeType();
 
     if (!LHSIsNull && !RHSIsNull &&
         !Context.typesAreCompatible(lpointee, rpointee)) {
@@ -4256,9 +4256,9 @@
       && ((lType->isBlockPointerType() && rType->isPointerType())
           || (lType->isPointerType() && rType->isBlockPointerType()))) {
     if (!LHSIsNull && !RHSIsNull) {
-      if (!((rType->isPointerType() && rType->getAsPointerType()
+      if (!((rType->isPointerType() && rType->getAs<PointerType>()
              ->getPointeeType()->isVoidType())
-            || (lType->isPointerType() && lType->getAsPointerType()
+            || (lType->isPointerType() && lType->getAs<PointerType>()
                 ->getPointeeType()->isVoidType())))
         Diag(Loc, diag::err_typecheck_comparison_of_distinct_blocks)
           << lType << rType << lex->getSourceRange() << rex->getSourceRange();
@@ -4269,8 +4269,8 @@
 
   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<PointerType>();
+      const PointerType *RPT = rType->getAs<PointerType>();
       bool LPtrToVoid = LPT ?
         Context.getCanonicalType(LPT->getPointeeType())->isVoidType() : false;
       bool RPtrToVoid = RPT ?
@@ -4798,7 +4798,7 @@
   // 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<PointerType>())
     return PT->getPointeeType();
 
   if (const ObjCObjectPointerType *OPT = Ty->getAsObjCObjectPointerType())
diff --git a/lib/Sema/SemaExprCXX.cpp b/lib/Sema/SemaExprCXX.cpp
index 144dc50..b3de60a 100644
--- a/lib/Sema/SemaExprCXX.cpp
+++ b/lib/Sema/SemaExprCXX.cpp
@@ -136,7 +136,7 @@
   //   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<PointerType>()) {
     Ty = Ptr->getPointeeType();
     isPointer = 1;
   }
@@ -708,7 +708,7 @@
       return ExprError(Diag(StartLoc, diag::err_delete_operand)
         << Type << Ex->getSourceRange());
 
-    QualType Pointee = Type->getAsPointerType()->getPointeeType();
+    QualType Pointee = Type->getAs<PointerType>()->getPointeeType();
     if (Pointee->isFunctionType() || Pointee->isVoidType())
       return ExprError(Diag(StartLoc, diag::err_delete_operand)
         << Type << Ex->getSourceRange());
@@ -812,7 +812,7 @@
   // string literal can be converted to an rvalue of type "pointer
   // to wchar_t" (C++ 4.2p2).
   if (StringLiteral *StrLit = dyn_cast<StringLiteral>(From))
-    if (const PointerType *ToPtrType = ToType->getAsPointerType())
+    if (const PointerType *ToPtrType = ToType->getAs<PointerType>())
       if (const BuiltinType *ToPointeeType 
           = ToPtrType->getPointeeType()->getAsBuiltinType()) {
         // This conversion is considered only when there is an
@@ -1066,7 +1066,7 @@
   //   such a class]
   QualType LType = lex->getType();
   if (isIndirect) {
-    if (const PointerType *Ptr = LType->getAsPointerType())
+    if (const PointerType *Ptr = LType->getAs<PointerType>())
       LType = Ptr->getPointeeType().getNonReferenceType();
     else {
       Diag(Loc, diag::err_bad_memptr_lhs)
@@ -1515,8 +1515,8 @@
   llvm::SmallVector<unsigned, 4> QualifierUnion;
   QualType Composite1 = T1, Composite2 = T2;
   const PointerType *Ptr1, *Ptr2;
-  while ((Ptr1 = Composite1->getAsPointerType()) &&
-         (Ptr2 = Composite2->getAsPointerType())) {
+  while ((Ptr1 = Composite1->getAs<PointerType>()) &&
+         (Ptr2 = Composite2->getAs<PointerType>())) {
     Composite1 = Ptr1->getPointeeType();
     Composite2 = Ptr2->getPointeeType();
     QualifierUnion.push_back(
diff --git a/lib/Sema/SemaExprObjC.cpp b/lib/Sema/SemaExprObjC.cpp
index 1131a9f..c209568 100644
--- a/lib/Sema/SemaExprObjC.cpp
+++ b/lib/Sema/SemaExprObjC.cpp
@@ -859,7 +859,7 @@
   if (!lhs->isPointerType())
     return false;
   
-  QualType ltype = lhs->getAsPointerType()->getPointeeType();
+  QualType ltype = lhs->getAs<PointerType>()->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 c88321e..a37be68 100644
--- a/lib/Sema/SemaLookup.cpp
+++ b/lib/Sema/SemaLookup.cpp
@@ -1435,7 +1435,7 @@
   // 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<PointerType>())
       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 daf6800..4b58b3d 100644
--- a/lib/Sema/SemaNamedCast.cpp
+++ b/lib/Sema/SemaNamedCast.cpp
@@ -529,10 +529,10 @@
   // 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<PointerType>()) {
     QualType SrcPointee = SrcPointer->getPointeeType();
     if (SrcPointee->isVoidType()) {
-      if (const PointerType *DestPointer = DestType->getAsPointerType()) {
+      if (const PointerType *DestPointer = DestType->getAs<PointerType>()) {
         QualType DestPointee = DestPointer->getPointeeType();
         if (DestPointee->isIncompleteOrObjectType()) {
           // This is definitely the intended conversion, but it might fail due
@@ -627,12 +627,12 @@
   // In addition, DR54 clarifies that the base must be accessible in the
   // current context.
 
-  const PointerType *SrcPointer = SrcType->getAsPointerType();
+  const PointerType *SrcPointer = SrcType->getAs<PointerType>();
   if (!SrcPointer) {
     return TSC_NotApplicable;
   }
 
-  const PointerType *DestPointer = DestType->getAsPointerType();
+  const PointerType *DestPointer = DestType->getAs<PointerType>();
   if (!DestPointer) {
     return TSC_NotApplicable;
   }
@@ -828,7 +828,7 @@
   //   or "pointer to cv void".
 
   QualType DestPointee;
-  const PointerType *DestPointer = DestType->getAsPointerType();
+  const PointerType *DestPointer = DestType->getAs<PointerType>();
   const ReferenceType *DestReference = DestType->getAsReferenceType();
   if (DestPointer) {
     DestPointee = DestPointer->getPointeeType();
@@ -863,7 +863,7 @@
   QualType SrcType = Self.Context.getCanonicalType(OrigSrcType);
   QualType SrcPointee;
   if (DestPointer) {
-    if (const PointerType *SrcPointer = SrcType->getAsPointerType()) {
+    if (const PointerType *SrcPointer = SrcType->getAs<PointerType>()) {
       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 d0d61c6..dc24a03 100644
--- a/lib/Sema/SemaOverload.cpp
+++ b/lib/Sema/SemaOverload.cpp
@@ -173,7 +173,7 @@
     FromType = Context.getArrayDecayedType(FromType);
 
   if (Second == ICK_Pointer_Conversion)
-    if (const PointerType* ToPtrType = ToType->getAsPointerType())
+    if (const PointerType* ToPtrType = ToType->getAs<PointerType>())
       return ToPtrType->getPointeeType()->isVoidType();
 
   return false;
@@ -915,7 +915,7 @@
 
   // Blocks: Block pointers can be converted to void*.
   if (FromType->isBlockPointerType() && ToType->isPointerType() &&
-      ToType->getAsPointerType()->getPointeeType()->isVoidType()) {
+      ToType->getAs<PointerType>()->getPointeeType()->isVoidType()) {
     ConvertedType = ToType;
     return true;
   }
@@ -933,7 +933,7 @@
     return true;
   }
 
-  const PointerType* ToTypePtr = ToType->getAsPointerType();
+  const PointerType* ToTypePtr = ToType->getAs<PointerType>();
   if (!ToTypePtr)
     return false;
 
@@ -944,7 +944,7 @@
   }
 
   // Beyond this point, both types need to be pointers.
-  const PointerType *FromTypePtr = FromType->getAsPointerType();
+  const PointerType *FromTypePtr = FromType->getAs<PointerType>();
   if (!FromTypePtr)
     return false;
 
@@ -1042,17 +1042,17 @@
   } 
   // 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<PointerType>())
     ToPointeeType = ToCPtr->getPointeeType();
-  else if (const BlockPointerType *ToBlockPtr = ToType->getAsBlockPointerType())
+  else if (const BlockPointerType *ToBlockPtr = ToType->getAs<BlockPointerType>())
     ToPointeeType = ToBlockPtr->getPointeeType();
   else
     return false;
 
   QualType FromPointeeType;
-  if (const PointerType *FromCPtr = FromType->getAsPointerType())
+  if (const PointerType *FromCPtr = FromType->getAs<PointerType>())
     FromPointeeType = FromCPtr->getPointeeType();
-  else if (const BlockPointerType *FromBlockPtr = FromType->getAsBlockPointerType())
+  else if (const BlockPointerType *FromBlockPtr = FromType->getAs<BlockPointerType>())
     FromPointeeType = FromBlockPtr->getPointeeType();
   else
     return false;
@@ -1142,8 +1142,8 @@
 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<PointerType>())
+    if (const PointerType *ToPtrType = ToType->getAs<PointerType>()) {
       QualType FromPointeeType = FromPtrType->getPointeeType(),
                ToPointeeType   = ToPtrType->getPointeeType();
 
@@ -1404,7 +1404,7 @@
         User.ConversionFunction = Constructor;
         User.After.setAsIdentityConversion();
         User.After.FromTypePtr 
-          = ThisType->getAsPointerType()->getPointeeType().getAsOpaquePtr();
+          = ThisType->getAs<PointerType>()->getPointeeType().getAsOpaquePtr();
         User.After.ToTypePtr = ToType.getAsOpaquePtr();
         return true;
       } else if (CXXConversionDecl *Conversion
@@ -1579,9 +1579,9 @@
       FromType2 = Context.getArrayDecayedType(FromType2);
 
     QualType FromPointee1 
-      = FromType1->getAsPointerType()->getPointeeType().getUnqualifiedType();
+      = FromType1->getAs<PointerType>()->getPointeeType().getUnqualifiedType();
     QualType FromPointee2
-      = FromType2->getAsPointerType()->getPointeeType().getUnqualifiedType();
+      = FromType2->getAs<PointerType>()->getPointeeType().getUnqualifiedType();
 
     if (IsDerivedFrom(FromPointee2, FromPointee1))
       return ImplicitConversionSequence::Better;
@@ -1771,13 +1771,13 @@
       FromType1->isPointerType() && FromType2->isPointerType() &&
       ToType1->isPointerType() && ToType2->isPointerType()) {
     QualType FromPointee1 
-      = FromType1->getAsPointerType()->getPointeeType().getUnqualifiedType();
+      = FromType1->getAs<PointerType>()->getPointeeType().getUnqualifiedType();
     QualType ToPointee1 
-      = ToType1->getAsPointerType()->getPointeeType().getUnqualifiedType();
+      = ToType1->getAs<PointerType>()->getPointeeType().getUnqualifiedType();
     QualType FromPointee2
-      = FromType2->getAsPointerType()->getPointeeType().getUnqualifiedType();
+      = FromType2->getAs<PointerType>()->getPointeeType().getUnqualifiedType();
     QualType ToPointee2
-      = ToType2->getAsPointerType()->getPointeeType().getUnqualifiedType();
+      = ToType2->getAs<PointerType>()->getPointeeType().getUnqualifiedType();
 
     const ObjCInterfaceType* FromIface1 = FromPointee1->getAsObjCInterfaceType();
     const ObjCInterfaceType* FromIface2 = FromPointee2->getAsObjCInterfaceType();
@@ -1943,7 +1943,7 @@
 
   // 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<PointerType>())
     FromType = PT->getPointeeType();
 
   assert(FromType->isRecordType());
@@ -1991,9 +1991,9 @@
 Sema::PerformObjectArgumentInitialization(Expr *&From, CXXMethodDecl *Method) {
   QualType FromRecordType, DestType;
   QualType ImplicitParamRecordType  = 
-    Method->getThisType(Context)->getAsPointerType()->getPointeeType();
+    Method->getThisType(Context)->getAs<PointerType>()->getPointeeType();
   
-  if (const PointerType *PT = From->getType()->getAsPointerType()) {
+  if (const PointerType *PT = From->getType()->getAs<PointerType>()) {
     FromRecordType = PT->getPointeeType();
     DestType = Method->getThisType(Context);
   } else {
@@ -2634,7 +2634,7 @@
   if (!PointerTypes.insert(Ty))
     return false;
 
-  if (const PointerType *PointerTy = Ty->getAsPointerType()) {
+  if (const PointerType *PointerTy = Ty->getAs<PointerType>()) {
     QualType PointeeTy = PointerTy->getPointeeType();
     // FIXME: Optimize this so that we don't keep trying to add the same types.
 
@@ -2710,7 +2710,7 @@
   // We don't care about qualifiers on the type.
   Ty = Ty.getUnqualifiedType();
 
-  if (const PointerType *PointerTy = Ty->getAsPointerType()) {
+  if (const PointerType *PointerTy = Ty->getAs<PointerType>()) {
     QualType PointeeTy = PointerTy->getPointeeType();
 
     // Insert our type, and its more-qualified variants, into the set
@@ -2898,7 +2898,7 @@
     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<PointerType>()->getPointeeType()->isObjectType())
         continue;
 
       QualType ParamTypes[2] = { 
@@ -2936,7 +2936,7 @@
     for (BuiltinCandidateTypeSet::iterator Ptr = CandidateTypes.pointer_begin();
          Ptr != CandidateTypes.pointer_end(); ++Ptr) {
       QualType ParamTy = *Ptr;
-      QualType PointeeTy = ParamTy->getAsPointerType()->getPointeeType();
+      QualType PointeeTy = ParamTy->getAs<PointerType>()->getPointeeType();
       AddBuiltinCandidate(Context.getLValueReferenceType(PointeeTy), 
                           &ParamTy, Args, 1, CandidateSet);
     }
@@ -3336,7 +3336,7 @@
     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<PointerType>()->getPointeeType();
       QualType ResultTy = Context.getLValueReferenceType(PointeeType);
 
       // T& operator[](T*, ptrdiff_t)
@@ -3624,7 +3624,7 @@
           FnType = FnTypeRef->getPointeeType();
           isRValueReference = true;
         }
-        if (const PointerType *FnTypePtr = FnType->getAsPointerType()) {
+        if (const PointerType *FnTypePtr = FnType->getAs<PointerType>()) {
           FnType = FnTypePtr->getPointeeType();
           isPointer = true;
         }
@@ -3673,7 +3673,7 @@
                                          bool Complain) {
   QualType FunctionType = ToType;
   bool IsMember = false;
-  if (const PointerType *ToTypePtr = ToType->getAsPointerType())
+  if (const PointerType *ToTypePtr = ToType->getAs<PointerType>())
     FunctionType = ToTypePtr->getPointeeType();
   else if (const ReferenceType *ToTypeRef = ToType->getAsReferenceType())
     FunctionType = ToTypeRef->getPointeeType();
@@ -4414,7 +4414,7 @@
     // 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<PointerType>())
       ConvType = ConvPtrType->getPointeeType();
 
     if (const FunctionProtoType *Proto = ConvType->getAsFunctionProtoType())
diff --git a/lib/Sema/SemaStmt.cpp b/lib/Sema/SemaStmt.cpp
index bd2b0ae..0a7ed46 100644
--- a/lib/Sema/SemaStmt.cpp
+++ b/lib/Sema/SemaStmt.cpp
@@ -1204,7 +1204,7 @@
     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<PointerType>();
       if (!PT || !PT->getPointeeType()->isVoidType())
         return StmtError(Diag(AtLoc, diag::error_objc_throw_expects_object)
                         << ThrowExpr->getType() << ThrowExpr->getSourceRange());
@@ -1221,7 +1221,7 @@
   // Make sure the expression type is an ObjC pointer or "void *".
   Expr *SyncExpr = static_cast<Expr*>(SynchExpr.get());
   if (!SyncExpr->getType()->isObjCObjectPointerType()) {
-    const PointerType *PT = SyncExpr->getType()->getAsPointerType();
+    const PointerType *PT = SyncExpr->getType()->getAs<PointerType>();
     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 568d68c..85d3867 100644
--- a/lib/Sema/SemaTemplate.cpp
+++ b/lib/Sema/SemaTemplate.cpp
@@ -225,8 +225,8 @@
   if (T->isIntegralType() || T->isEnumeralType() ||
       //   -- pointer to object or pointer to function, 
       (T->isPointerType() && 
-       (T->getAsPointerType()->getPointeeType()->isObjectType() ||
-        T->getAsPointerType()->getPointeeType()->isFunctionType())) ||
+       (T->getAs<PointerType>()->getPointeeType()->isObjectType() ||
+        T->getAs<PointerType>()->getPointeeType()->isFunctionType())) ||
       //   -- reference to object or reference to function, 
       T->isReferenceType() ||
       //   -- pointer to member.
@@ -1648,7 +1648,7 @@
       //    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<PointerType>()->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 @@
     //      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<PointerType>()->getPointeeType()->isObjectType() &&
            "Only object pointers allowed here");
 
     if (ArgType->isNullPtrType()) {
diff --git a/lib/Sema/SemaTemplateDeduction.cpp b/lib/Sema/SemaTemplateDeduction.cpp
index f6f9d10..b304751 100644
--- a/lib/Sema/SemaTemplateDeduction.cpp
+++ b/lib/Sema/SemaTemplateDeduction.cpp
@@ -397,7 +397,7 @@
       
     //     T *
     case Type::Pointer: {
-      const PointerType *PointerArg = Arg->getAsPointerType();
+      const PointerType *PointerArg = Arg->getAs<PointerType>();
       if (!PointerArg)
         return Sema::TDK_NonDeducedMismatch;
       
@@ -1320,7 +1320,7 @@
     if (isSimpleTemplateIdType(ParamType) ||
         (isa<PointerType>(ParamType) && 
          isSimpleTemplateIdType(
-                              ParamType->getAsPointerType()->getPointeeType())))
+                              ParamType->getAs<PointerType>()->getPointeeType())))
       TDF |= TDF_DerivedClass;
     
     if (TemplateDeductionResult Result
diff --git a/lib/Sema/SemaType.cpp b/lib/Sema/SemaType.cpp
index 8195aba..ee4cd20 100644
--- a/lib/Sema/SemaType.cpp
+++ b/lib/Sema/SemaType.cpp
@@ -300,7 +300,7 @@
     if (TypeQuals & QualType::Restrict) {
       if (Result->isPointerType() || Result->isReferenceType()) {
         QualType EltTy = Result->isPointerType() ? 
-          Result->getAsPointerType()->getPointeeType() :
+          Result->getAs<PointerType>()->getPointeeType() :
           Result->getAsReferenceType()->getPointeeType();
       
         // If we have a pointer or reference, the pointee must have an object
@@ -1185,7 +1185,7 @@
   //   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<PointerType>()) {
     T = IT->getPointeeType();
     kind = 1;
   } else if (const ReferenceType* IT = T->getAsReferenceType()) {
@@ -1205,7 +1205,7 @@
 /// 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<PointerType>())
     T = PT->getPointeeType();
   else if (const MemberPointerType *PT = T->getAsMemberPointerType())
     T = PT->getPointeeType();
@@ -1287,7 +1287,7 @@
     bool SubIsPointer = false;
     if (const ReferenceType *RefTy = CanonicalSubT->getAsReferenceType())
       CanonicalSubT = RefTy->getPointeeType();
-    if (const PointerType *PtrTy = CanonicalSubT->getAsPointerType()) {
+    if (const PointerType *PtrTy = CanonicalSubT->getAs<PointerType>()) {
       CanonicalSubT = PtrTy->getPointeeType();
       SubIsPointer = true;
     }
@@ -1308,7 +1308,7 @@
       if (const ReferenceType *RefTy = CanonicalSuperT->getAsReferenceType())
         CanonicalSuperT = RefTy->getPointeeType();
       if (SubIsPointer) {
-        if (const PointerType *PtrTy = CanonicalSuperT->getAsPointerType())
+        if (const PointerType *PtrTy = CanonicalSuperT->getAs<PointerType>())
           CanonicalSuperT = PtrTy->getPointeeType();
         else {
           continue;
@@ -1384,8 +1384,8 @@
 /// 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<PointerType>(),
+                    *T2PtrType = T2->getAs<PointerType>();
   if (T1PtrType && T2PtrType) {
     T1 = T1PtrType->getPointeeType();
     T2 = T2PtrType->getPointeeType();