mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-14 05:45:37 +00:00
Bug 851237 - Replace StaticAssert uses with MOZ_STATIC_ASSERT. r=dholbert
--HG-- extra : rebase_source : d8b9715e05b959b11ee0f645141fd077b8599ab1
This commit is contained in:
parent
f2bef86c4d
commit
9443788310
@ -8,6 +8,7 @@
|
||||
#ifndef js_HashTable_h__
|
||||
#define js_HashTable_h__
|
||||
|
||||
#include "mozilla/Assertions.h"
|
||||
#include "mozilla/Attributes.h"
|
||||
#include "mozilla/DebugOnly.h"
|
||||
#include "mozilla/TypeTraits.h"
|
||||
@ -67,7 +68,15 @@ class HashMap
|
||||
|
||||
// HashMap construction is fallible (due to OOM); thus the user must call
|
||||
// init after constructing a HashMap and check the return value.
|
||||
HashMap(AllocPolicy a = AllocPolicy()) : impl(a) {}
|
||||
HashMap(AllocPolicy a = AllocPolicy())
|
||||
: impl(a)
|
||||
{
|
||||
MOZ_STATIC_ASSERT(tl::IsRelocatableHeapType<Key>::result,
|
||||
"Key type must be relocatable");
|
||||
MOZ_STATIC_ASSERT(tl::IsRelocatableHeapType<Value>::result,
|
||||
"Value type must be relocatable");
|
||||
}
|
||||
|
||||
bool init(uint32_t len = 16) { return impl.init(len); }
|
||||
bool initialized() const { return impl.initialized(); }
|
||||
|
||||
@ -254,9 +263,6 @@ class HashMap
|
||||
HashMap &operator=(const HashMap &hm) MOZ_DELETE;
|
||||
|
||||
friend class Impl::Enum;
|
||||
|
||||
typedef typename tl::StaticAssert<tl::IsRelocatableHeapType<Key>::result>::result keyAssert;
|
||||
typedef typename tl::StaticAssert<tl::IsRelocatableHeapType<Value>::result>::result valAssert;
|
||||
};
|
||||
|
||||
/*****************************************************************************/
|
||||
@ -297,7 +303,11 @@ class HashSet
|
||||
|
||||
// HashSet construction is fallible (due to OOM); thus the user must call
|
||||
// init after constructing a HashSet and check the return value.
|
||||
HashSet(AllocPolicy a = AllocPolicy()) : impl(a) {}
|
||||
HashSet(AllocPolicy a = AllocPolicy()) : impl(a)
|
||||
{
|
||||
MOZ_STATIC_ASSERT(tl::IsRelocatableHeapType<T>::result,
|
||||
"Set element type must be relocatable");
|
||||
}
|
||||
bool init(uint32_t len = 16) { return impl.init(len); }
|
||||
bool initialized() const { return impl.initialized(); }
|
||||
|
||||
@ -448,8 +458,6 @@ class HashSet
|
||||
HashSet &operator=(const HashSet &hs) MOZ_DELETE;
|
||||
|
||||
friend class Impl::Enum;
|
||||
|
||||
typedef typename tl::StaticAssert<tl::IsRelocatableHeapType<T>::result>::result _;
|
||||
};
|
||||
|
||||
/*****************************************************************************/
|
||||
|
@ -191,13 +191,15 @@ class Handle : public js::HandleBase<T>
|
||||
|
||||
/* Create a handle for a NULL pointer. */
|
||||
Handle(js::NullPtr) {
|
||||
typedef typename js::tl::StaticAssert<mozilla::IsPointer<T>::value>::result _;
|
||||
MOZ_STATIC_ASSERT(mozilla::IsPointer<T>::value,
|
||||
"js::NullPtr overload not valid for non-pointer types");
|
||||
ptr = reinterpret_cast<const T *>(&js::NullPtr::constNullValue);
|
||||
}
|
||||
|
||||
/* Create a handle for a NULL pointer. */
|
||||
Handle(JS::NullPtr) {
|
||||
typedef typename js::tl::StaticAssert<mozilla::IsPointer<T>::value>::result _;
|
||||
MOZ_STATIC_ASSERT(mozilla::IsPointer<T>::value,
|
||||
"JS::NullPtr overload not valid for non-pointer types");
|
||||
ptr = reinterpret_cast<const T *>(&JS::NullPtr::constNullValue);
|
||||
}
|
||||
|
||||
|
@ -64,17 +64,17 @@ template <class T> struct BitSize {
|
||||
static const size_t result = sizeof(T) * JS_BITS_PER_BYTE;
|
||||
};
|
||||
|
||||
/* Allow Assertions by only including the 'result' typedef if 'true'. */
|
||||
template <bool> struct StaticAssert {};
|
||||
template <> struct StaticAssert<true> { typedef int result; };
|
||||
|
||||
/*
|
||||
* Produce an N-bit mask, where N <= BitSize<size_t>::result. Handle the
|
||||
* language-undefined edge case when N = BitSize<size_t>::result.
|
||||
*/
|
||||
template <size_t N> struct NBitMask {
|
||||
typedef typename StaticAssert<N < BitSize<size_t>::result>::result _;
|
||||
static const size_t result = (size_t(1) << N) - 1;
|
||||
// Assert the precondition. On success this evaluates to 0. Otherwise it
|
||||
// triggers divide-by-zero at compile time: a guaranteed compile error in
|
||||
// C++11, and usually one in C++98. Add this value to |result| to assure
|
||||
// its computation.
|
||||
static const size_t checkPrecondition = 0 / (N < BitSize<size_t>::result);
|
||||
static const size_t result = (size_t(1) << N) - 1 + checkPrecondition;
|
||||
};
|
||||
template <> struct NBitMask<BitSize<size_t>::result> {
|
||||
static const size_t result = size_t(-1);
|
||||
|
@ -8,6 +8,7 @@
|
||||
#ifndef LifoAlloc_h__
|
||||
#define LifoAlloc_h__
|
||||
|
||||
#include "mozilla/Assertions.h"
|
||||
#include "mozilla/Attributes.h"
|
||||
#include "mozilla/DebugOnly.h"
|
||||
#include "mozilla/GuardObjects.h"
|
||||
@ -33,9 +34,9 @@ JS_ALWAYS_INLINE
|
||||
char *
|
||||
AlignPtr(void *orig)
|
||||
{
|
||||
typedef tl::StaticAssert<
|
||||
tl::FloorLog2<LIFO_ALLOC_ALIGN>::result == tl::CeilingLog2<LIFO_ALLOC_ALIGN>::result
|
||||
>::result _;
|
||||
MOZ_STATIC_ASSERT(tl::FloorLog2<LIFO_ALLOC_ALIGN>::result ==
|
||||
tl::CeilingLog2<LIFO_ALLOC_ALIGN>::result,
|
||||
"LIFO_ALLOC_ALIGN must be a power of two");
|
||||
|
||||
char *result = (char *) ((uintptr_t(orig) + (LIFO_ALLOC_ALIGN - 1)) & (~LIFO_ALLOC_ALIGN + 1));
|
||||
JS_ASSERT(uintptr_t(result) % LIFO_ALLOC_ALIGN == 0);
|
||||
|
Loading…
Reference in New Issue
Block a user