[cfe-commits] r130655 - in /cfe/trunk: include/clang/AST/Type.h lib/Sema/SemaExprCXX.cpp

Douglas Gregor dgregor at apple.com
Sun May 1 08:42:07 PDT 2011


On May 1, 2011, at 2:29 AM, Chandler Carruth wrote:

> Author: chandlerc
> Date: Sun May  1 04:29:58 2011
> New Revision: 130655
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=130655&view=rev
> Log:
> Move several more type traits' implementations into the AST. A few were
> already present in the AST, and I added the ones that weren't.
> 
> Modified:
>    cfe/trunk/include/clang/AST/Type.h
>    cfe/trunk/lib/Sema/SemaExprCXX.cpp
> 
> Modified: cfe/trunk/include/clang/AST/Type.h
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Type.h?rev=130655&r1=130654&r2=130655&view=diff
> ==============================================================================
> --- cfe/trunk/include/clang/AST/Type.h (original)
> +++ cfe/trunk/include/clang/AST/Type.h Sun May  1 04:29:58 2011
> @@ -1240,6 +1240,8 @@
>   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 @@
>     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() ||

isRecordType() subsumes isUnionType(); we don't need the latter.

> +  //    -- enumerations, which comprise a set of named constant values. [...];
> +         isEnumeralType() ||
> +  //    -- pointers to non-static class members, [...].
> +         isMemberPointerType();
> +}

VectorType/ExtVectorType, ComplexType, and ObjCObjectPointerType should all be considered compound types (as an extension), IMO.

A switch on the type class of the canonical type would be a lot more efficient here.

Thanks!

	- Doug




More information about the cfe-commits mailing list