]> granicus.if.org Git - clang/commitdiff
Restructure the API in Type based on a conversation with Richard Smith.
authorChandler Carruth <chandlerc@gmail.com>
Mon, 20 Jun 2011 01:23:19 +0000 (01:23 +0000)
committerChandler Carruth <chandlerc@gmail.com>
Mon, 20 Jun 2011 01:23:19 +0000 (01:23 +0000)
This makes 'isPointerLikeType' a little less confusing, and pulls the
decay check into a separate interface that is much more clear and
concrete. Also, just implement these as logical wrappers around other
predicates. Having a switch based implementation isn't likely to be
necessary. We can try to optimize them later if they show up on
a profile.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@133405 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/AST/Type.h
lib/AST/Type.cpp
lib/Sema/SemaExpr.cpp

index 08d62029667f8f8491bb572653453e820739c3a7..5f5b53a2224feaa2a935f3ac5c83cd3ce2c13c5f 100644 (file)
@@ -1456,7 +1456,9 @@ public:
 
   /// \brief Determine wither this type is a C++ elaborated-type-specifier.
   bool isElaboratedTypeSpecifier() const;
-  
+
+  bool canDecayToPointerType() const;
+
   /// hasPointerRepresentation - Whether this type is represented
   /// natively as a pointer; this includes pointers, references, block
   /// pointers, and Objective-C interface, qualified id, and qualified
@@ -4515,6 +4517,19 @@ inline bool Type::isPointerType() const {
 inline bool Type::isAnyPointerType() const {
   return isPointerType() || isObjCObjectPointerType();
 }
+
+/// \brief Tests whether the type behaves like a pointer type.
+///
+/// This includes all of the pointer types including block pointers,
+/// member pointers, and ObjC Object pointers.
+///
+/// Note that this is distinct from hasPointerRepresentation.
+///
+/// \returns True for types which behave like pointer types.
+inline bool Type::isPointerLikeType() const {
+  return isAnyPointerType() || isBlockPointerType() || isMemberPointerType();
+}
+
 inline bool Type::isBlockPointerType() const {
   return isa<BlockPointerType>(CanonicalType);
 }
@@ -4649,6 +4664,11 @@ inline bool Type::isOverloadableType() const {
   return isDependentType() || isRecordType() || isEnumeralType();
 }
 
+/// \brief Determines whether this type can decay to a pointer type.
+inline bool Type::canDecayToPointerType() const {
+  return isFunctionType() || isArrayType();
+}
+
 inline bool Type::hasPointerRepresentation() const {
   return (isPointerType() || isReferenceType() || isBlockPointerType() ||
           isObjCObjectPointerType() || isNullPtrType());
index b30f8966b6f7130118c99025646f3e3663bcae11..583cb5d57c09a10d122205a29ae55f50abaf89e0 100644 (file)
@@ -288,32 +288,6 @@ bool Type::isDerivedType() const {
     return false;
   }
 }
-
-/// \brief Tests whether the type behaves like a pointer type.
-///
-/// This includes all of the obviously pointer types including block pointers,
-/// member pointers, and ObjC Object pointers. It also includes function and
-/// array types which behave as pointers due to decay.
-///
-/// \returns True for types which act like pointer types.
-bool Type::isPointerLikeType() const {
-  switch (CanonicalType->getTypeClass()) {
-  case Pointer:
-  case BlockPointer:
-  case MemberPointer:
-  case ConstantArray:
-  case IncompleteArray:
-  case VariableArray:
-  case DependentSizedArray:
-  case FunctionProto:
-  case FunctionNoProto:
-  case ObjCObjectPointer:
-    return true;
-  default:
-    return false;
-  }
-}
-
 bool Type::isClassType() const {
   if (const RecordType *RT = getAs<RecordType>())
     return RT->getDecl()->isClass();
index 15751d078bd9b66200c26391ab5c91541a4cf0e0..42ec82ac4a211679aa0df14eaf90af8296f17bdf 100644 (file)
@@ -8963,7 +8963,10 @@ ExprResult Sema::CreateBuiltinBinOp(SourceLocation OpLoc,
       QualType LeftType = lhs.get()->getType();
       QualType RightType = rhs.get()->getType();
       if (LeftNull != RightNull &&
-          !LeftType->isPointerLikeType() && !RightType->isPointerLikeType()) {
+          !LeftType->isPointerLikeType() &&
+          !LeftType->canDecayToPointerType() &&
+          !RightType->isPointerLikeType() &&
+          !RightType->canDecayToPointerType()) {
         Diag(OpLoc, diag::warn_null_in_arithmetic_operation)
           << (LeftNull ? lhs.get()->getSourceRange()
                        : rhs.get()->getSourceRange());