From b87c01c87b722db6ad869703c2771c66d8faa4a0 Mon Sep 17 00:00:00 2001 From: "weinig@apple.com" Date: Fri, 6 Jan 2012 21:57:22 +0000 Subject: [PATCH] Add a DecayArray type trait as a first step towards merging OwnPtr and OwnArrayPtr https://bugs.webkit.org/show_bug.cgi?id=75737 Reviewed by Anders Carlsson. * wtf/TypeTraits.cpp: * wtf/TypeTraits.h: Added a DecayArray trait, that can convert T[] and T[3] -> T*. DecayArray is composed of some helpers which are also exposed, Conditional<>, which can provide one type or another based on a boolean predicate, IsArray<> which can deduce array types, and RemoveExtent<>, which removes the extent from an array type. git-svn-id: http://svn.webkit.org/repository/webkit/trunk@104333 268f45cc-cd09-0410-ab3c-d52691b4dbfc --- Source/JavaScriptCore/ChangeLog | 15 ++++++++ Source/JavaScriptCore/wtf/TypeTraits.cpp | 16 +++++++++ Source/JavaScriptCore/wtf/TypeTraits.h | 46 ++++++++++++++++++++++++ 3 files changed, 77 insertions(+) diff --git a/Source/JavaScriptCore/ChangeLog b/Source/JavaScriptCore/ChangeLog index bed659f028a..597e14932e3 100644 --- a/Source/JavaScriptCore/ChangeLog +++ b/Source/JavaScriptCore/ChangeLog @@ -1,3 +1,18 @@ +2012-01-06 Sam Weinig + + Add a DecayArray type trait as a first step towards merging OwnPtr and OwnArrayPtr + https://bugs.webkit.org/show_bug.cgi?id=75737 + + Reviewed by Anders Carlsson. + + * wtf/TypeTraits.cpp: + * wtf/TypeTraits.h: + Added a DecayArray trait, that can convert T[] and T[3] -> T*. DecayArray + is composed of some helpers which are also exposed, Conditional<>, which + can provide one type or another based on a boolean predicate, IsArray<> + which can deduce array types, and RemoveExtent<>, which removes the extent + from an array type. + 2012-01-06 Oliver Hunt GetByteArrayLength is incorrect diff --git a/Source/JavaScriptCore/wtf/TypeTraits.cpp b/Source/JavaScriptCore/wtf/TypeTraits.cpp index afeaa5e4cd8..b89a76a94a8 100644 --- a/Source/JavaScriptCore/wtf/TypeTraits.cpp +++ b/Source/JavaScriptCore/wtf/TypeTraits.cpp @@ -139,4 +139,20 @@ COMPILE_ASSERT((!IsSameType::Type>::value), WTF_Test_R COMPILE_ASSERT((IsSameType::Type>::value), WTF_Test_RemoveReference_int); COMPILE_ASSERT((IsSameType::Type>::value), WTF_Test_RemoveReference_int_reference); + +typedef int IntArray[]; +typedef int IntArraySized[4]; + +COMPILE_ASSERT((IsArray::value), WTF_Test_IsArray_int_array); +COMPILE_ASSERT((IsArray::value), WTF_Test_IsArray_int_sized_array); + +COMPILE_ASSERT((IsSameType::Type>::value), WTF_Test_RemoveExtent_int_array); +COMPILE_ASSERT((IsSameType::Type>::value), WTF_Test_RemoveReference_int_sized_array); + +COMPILE_ASSERT((IsSameType::Type>::value), WTF_Test_DecayArray_int_array); +COMPILE_ASSERT((IsSameType::Type>::value), WTF_Test_DecayArray_int_sized_array); + +COMPILE_ASSERT((IsSameType::Type>::value), WTF_Test_DecayArray_int_array_reference); +COMPILE_ASSERT((IsSameType::Type>::value), WTF_Test_DecayArray_int_sized_array_reference); + } // namespace WTF diff --git a/Source/JavaScriptCore/wtf/TypeTraits.h b/Source/JavaScriptCore/wtf/TypeTraits.h index 6c7466acc35..34e8b79a3c5 100644 --- a/Source/JavaScriptCore/wtf/TypeTraits.h +++ b/Source/JavaScriptCore/wtf/TypeTraits.h @@ -35,10 +35,14 @@ namespace WTF { // The following are provided in this file: // + // Conditional::Type + // // IsInteger::value // IsPod::value, see the definition for a note about its limitations // IsConvertibleToInteger::value // + // IsArray::value + // // IsSameType::value // // RemovePointer::Type @@ -46,9 +50,15 @@ namespace WTF { // RemoveConst::Type // RemoveVolatile::Type // RemoveConstVolatile::Type + // RemoveExtent::Type + // + // DecayArray::Type // // COMPILE_ASSERT's in TypeTraits.cpp illustrate their usage and what they do. + template struct Conditional { typedef If Type; }; + template struct Conditional { typedef Then Type; }; + template struct IsInteger { static const bool value = false; }; template<> struct IsInteger { static const bool value = true; }; template<> struct IsInteger { static const bool value = true; }; @@ -104,6 +114,20 @@ namespace WTF { static const bool value = IsInteger::value || IsConvertibleToDouble::value, T>::value; }; + + template struct IsArray { + static const bool value = false; + }; + + template struct IsArray { + static const bool value = true; + }; + + template struct IsArray { + static const bool value = true; + }; + + template struct IsSameType { static const bool value = false; }; @@ -182,6 +206,28 @@ namespace WTF { typedef T Type; }; + template struct RemoveExtent { + typedef T Type; + }; + + template struct RemoveExtent { + typedef T Type; + }; + + template struct RemoveExtent { + typedef T Type; + }; + + template struct DecayArray { + typedef typename RemoveReference::Type U; + public: + typedef typename Conditional< + IsArray::value, + typename RemoveExtent::Type*, + typename RemoveConstVolatile::Type + >::Type Type; + }; + #if (defined(__GLIBCXX__) && (__GLIBCXX__ >= 20070724) && defined(__GXX_EXPERIMENTAL_CXX0X__)) || (defined(_MSC_VER) && (_MSC_VER >= 1600)) // GCC's libstdc++ 20070724 and later supports C++ TR1 type_traits in the std namespace. -- GitLab