Title: [104333] trunk/Source/_javascript_Core
Revision
104333
Author
[email protected]
Date
2012-01-06 13:57:22 -0800 (Fri, 06 Jan 2012)

Log Message

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. 

Modified Paths

Diff

Modified: trunk/Source/_javascript_Core/ChangeLog (104332 => 104333)


--- trunk/Source/_javascript_Core/ChangeLog	2012-01-06 21:55:12 UTC (rev 104332)
+++ trunk/Source/_javascript_Core/ChangeLog	2012-01-06 21:57:22 UTC (rev 104333)
@@ -1,3 +1,18 @@
+2012-01-06  Sam Weinig  <[email protected]>
+
+        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  <[email protected]>
 
         GetByteArrayLength is incorrect

Modified: trunk/Source/_javascript_Core/wtf/TypeTraits.cpp (104332 => 104333)


--- trunk/Source/_javascript_Core/wtf/TypeTraits.cpp	2012-01-06 21:55:12 UTC (rev 104332)
+++ trunk/Source/_javascript_Core/wtf/TypeTraits.cpp	2012-01-06 21:57:22 UTC (rev 104333)
@@ -139,4 +139,20 @@
 COMPILE_ASSERT((IsSameType<int, RemoveReference<int>::Type>::value), WTF_Test_RemoveReference_int);
 COMPILE_ASSERT((IsSameType<int, RemoveReference<int&>::Type>::value), WTF_Test_RemoveReference_int_reference);
 
+
+typedef int IntArray[];
+typedef int IntArraySized[4];
+
+COMPILE_ASSERT((IsArray<IntArray>::value), WTF_Test_IsArray_int_array);
+COMPILE_ASSERT((IsArray<IntArraySized>::value), WTF_Test_IsArray_int_sized_array);
+
+COMPILE_ASSERT((IsSameType<int, RemoveExtent<IntArray>::Type>::value), WTF_Test_RemoveExtent_int_array);
+COMPILE_ASSERT((IsSameType<int, RemoveExtent<IntArraySized>::Type>::value), WTF_Test_RemoveReference_int_sized_array);
+
+COMPILE_ASSERT((IsSameType<int*, DecayArray<IntArray>::Type>::value), WTF_Test_DecayArray_int_array);
+COMPILE_ASSERT((IsSameType<int*, DecayArray<IntArraySized>::Type>::value), WTF_Test_DecayArray_int_sized_array);
+
+COMPILE_ASSERT((IsSameType<int*, DecayArray<IntArray&>::Type>::value), WTF_Test_DecayArray_int_array_reference);
+COMPILE_ASSERT((IsSameType<int*, DecayArray<IntArraySized&>::Type>::value), WTF_Test_DecayArray_int_sized_array_reference);
+
 } // namespace WTF

Modified: trunk/Source/_javascript_Core/wtf/TypeTraits.h (104332 => 104333)


--- trunk/Source/_javascript_Core/wtf/TypeTraits.h	2012-01-06 21:55:12 UTC (rev 104332)
+++ trunk/Source/_javascript_Core/wtf/TypeTraits.h	2012-01-06 21:57:22 UTC (rev 104333)
@@ -35,10 +35,14 @@
 
     // The following are provided in this file:
     //
+    //   Conditional<Predicate, If, Then>::Type
+    //
     //   IsInteger<T>::value
     //   IsPod<T>::value, see the definition for a note about its limitations
     //   IsConvertibleToInteger<T>::value
     //
+    //   IsArray<T>::value
+    //
     //   IsSameType<T, U>::value
     //
     //   RemovePointer<T>::Type
@@ -46,9 +50,15 @@
     //   RemoveConst<T>::Type
     //   RemoveVolatile<T>::Type
     //   RemoveConstVolatile<T>::Type
+    //   RemoveExtent<T>::Type
     //
+    //   DecayArray<T>::Type
+    //
     //   COMPILE_ASSERT's in TypeTraits.cpp illustrate their usage and what they do.
 
+    template <bool Predicate, class If, class Then> struct Conditional  { typedef If Type; };
+    template <class If, class Then> struct Conditional<false, If, Then> { typedef Then Type; };
+
     template<typename T> struct IsInteger           { static const bool value = false; };
     template<> struct IsInteger<bool>               { static const bool value = true; };
     template<> struct IsInteger<char>               { static const bool value = true; };
@@ -104,6 +114,20 @@
         static const bool value = IsInteger<T>::value || IsConvertibleToDouble<!IsInteger<T>::value, T>::value;
     };
 
+
+    template <class T> struct IsArray {
+        static const bool value = false;
+    };
+
+    template <class T> struct IsArray<T[]> {
+        static const bool value = true;
+    };
+
+    template <class T, size_t N> struct IsArray<T[N]> {
+        static const bool value = true;
+    };
+
+
     template <typename T, typename U> struct IsSameType {
         static const bool value = false;
     };
@@ -182,6 +206,28 @@
         typedef T Type;
     };
 
+    template <typename T> struct RemoveExtent {
+        typedef T Type;
+    };
+
+    template <typename T> struct RemoveExtent<T[]> {
+        typedef T Type;
+    };
+
+    template <typename T, size_t N> struct RemoveExtent<T[N]> {
+        typedef T Type;
+    };
+
+    template <class T> struct DecayArray {
+        typedef typename RemoveReference<T>::Type U;
+    public:
+        typedef typename Conditional<
+            IsArray<U>::value,
+            typename RemoveExtent<U>::Type*,
+            typename RemoveConstVolatile<U>::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.
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to