]> granicus.if.org Git - clang/commitdiff
Move several more type traits' implementations into the AST. A few were
authorChandler Carruth <chandlerc@gmail.com>
Sun, 1 May 2011 09:29:58 +0000 (09:29 +0000)
committerChandler Carruth <chandlerc@gmail.com>
Sun, 1 May 2011 09:29:58 +0000 (09:29 +0000)
already present in the AST, and I added the ones that weren't.

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

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

index a49992189ee575589bbafae5b0a69676add22807..77d704126c6eaf94e23e337c648e6432858813df 100644 (file)
@@ -1240,6 +1240,8 @@ public:
   bool isDerivedType() const;      // C99 6.2.5p20
   bool isScalarType() const;       // C99 6.2.5p21 (arithmetic + pointers)
   bool isAggregateType() const;
+  bool isFundamentalType() const;
+  bool isCompoundType() const;
 
   // Type Predicates: Check to see if this type is structurally the specified
   // type, ignoring typedefs and qualifiers.
@@ -4226,6 +4228,40 @@ inline QualType QualType::getNonReferenceType() const {
     return *this;
 }
 
+/// \brief Tests whether the type is categorized as a fundamental type.
+///
+/// \returns True for types specified in C++0x [basic.fundamental].
+inline bool Type::isFundamentalType() const {
+  return isVoidType() ||
+         // FIXME: It's really annoying that we don't have an
+         // 'isArithmeticType()' which agrees with the standard definition.
+         (isArithmeticType() && !isEnumeralType());
+}
+
+/// \brief Tests whether the type is categorized as a compound type.
+///
+/// \returns True for types specified in C++0x [basic.compound].
+inline bool Type::isCompoundType() const {
+  // C++0x [basic.compound]p1:
+  //   Compound types can be constructed in the following ways:
+  //    -- arrays of objects of a given type [...];
+  return isArrayType() ||
+  //    -- functions, which have parameters of given types [...];
+         isFunctionType() ||
+  //    -- pointers to void or objects or functions [...];
+         isPointerType() ||
+  //    -- references to objects or functions of a given type. [...]
+         isReferenceType() ||
+  //    -- classes containing a sequence of objects of various types, [...];
+         isRecordType() ||
+  //    -- unions, which ar classes capable of containing objects of different types at different times;
+         isUnionType() ||
+  //    -- enumerations, which comprise a set of named constant values. [...];
+         isEnumeralType() ||
+  //    -- pointers to non-static class members, [...].
+         isMemberPointerType();
+}
+
 inline bool Type::isFunctionType() const {
   return isa<FunctionType>(CanonicalType);
 }
index 2664c7811caafb570ebb17e00741ae80d20b3be6..270ee2988709999bfcd64c676c8a28807a1b349a 100644 (file)
@@ -2484,13 +2484,9 @@ static bool EvaluateUnaryTypeTrait(Sema &Self, UnaryTypeTrait UTT,
   case UTT_IsEnum:
     return T->isEnumeralType();
   case UTT_IsUnion:
-    if (const RecordType *Record = T->getAs<RecordType>())
-      return Record->getDecl()->isUnion();
-    return false;
+    return T->isUnionType();
   case UTT_IsClass:
-    if (const RecordType *Record = T->getAs<RecordType>())
-      return !Record->getDecl()->isUnion();
-    return false;
+    return T->isClassType() || T->isStructureType();
   case UTT_IsFunction:
     return T->isFunctionType();
 
@@ -2499,17 +2495,15 @@ static bool EvaluateUnaryTypeTrait(Sema &Self, UnaryTypeTrait UTT,
   case UTT_IsReference:
     return T->isReferenceType();
   case UTT_IsArithmetic:
-    return T->isArithmeticType() && ! T->isEnumeralType();
+    return T->isArithmeticType() && !T->isEnumeralType();
   case UTT_IsFundamental:
-    return T->isVoidType() || (T->isArithmeticType() && ! T->isEnumeralType());
+    return T->isFundamentalType();
   case UTT_IsObject:
-    // Defined in Section 3.9 p8 of the Working Draft, essentially:
-    // !__is_reference(T) && !__is_function(T) && !__is_void(T).
-    return ! (T->isReferenceType() || T->isFunctionType() || T->isVoidType());
+    return T->isObjectType();
   case UTT_IsScalar:
     return T->isScalarType();
   case UTT_IsCompound:
-    return ! (T->isVoidType() || T->isArithmeticType()) || T->isEnumeralType();
+    return T->isCompoundType();
   case UTT_IsMemberPointer:
     return T->isMemberPointerType();