зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1232686 - Use decltype to infer Variant::match return type; r=fitzgen
This commit is contained in:
Родитель
aed4228f29
Коммит
2177cca5cd
|
@ -137,8 +137,6 @@ parseMessage(ZeroCopyInputStream& stream, uint32_t sizeOfMessage, MessageType& m
|
|||
template<typename CharT, typename InternedStringSet>
|
||||
struct GetOrInternStringMatcher
|
||||
{
|
||||
using ReturnType = const CharT*;
|
||||
|
||||
InternedStringSet& internedStrings;
|
||||
|
||||
explicit GetOrInternStringMatcher(InternedStringSet& strings) : internedStrings(strings) { }
|
||||
|
@ -860,8 +858,6 @@ class TwoByteString : public Variant<JSAtom*, const char16_t*, JS::ubi::EdgeName
|
|||
|
||||
struct AsTwoByteStringMatcher
|
||||
{
|
||||
using ReturnType = TwoByteString;
|
||||
|
||||
TwoByteString match(JSAtom* atom) {
|
||||
return TwoByteString(atom);
|
||||
}
|
||||
|
@ -873,16 +869,12 @@ class TwoByteString : public Variant<JSAtom*, const char16_t*, JS::ubi::EdgeName
|
|||
|
||||
struct IsNonNullMatcher
|
||||
{
|
||||
using ReturnType = bool;
|
||||
|
||||
template<typename T>
|
||||
bool match(const T& t) { return t != nullptr; }
|
||||
};
|
||||
|
||||
struct LengthMatcher
|
||||
{
|
||||
using ReturnType = size_t;
|
||||
|
||||
size_t match(JSAtom* atom) {
|
||||
MOZ_ASSERT(atom);
|
||||
JS::ubi::AtomOrTwoByteChars s(atom);
|
||||
|
@ -902,8 +894,6 @@ class TwoByteString : public Variant<JSAtom*, const char16_t*, JS::ubi::EdgeName
|
|||
|
||||
struct CopyToBufferMatcher
|
||||
{
|
||||
using ReturnType = size_t;
|
||||
|
||||
RangedPtr<char16_t> destination;
|
||||
size_t maxLength;
|
||||
|
||||
|
@ -985,8 +975,6 @@ struct TwoByteString::HashPolicy {
|
|||
using Lookup = TwoByteString;
|
||||
|
||||
struct HashingMatcher {
|
||||
using ReturnType = js::HashNumber;
|
||||
|
||||
js::HashNumber match(const JSAtom* atom) {
|
||||
return js::DefaultHasher<const JSAtom*>::hash(atom);
|
||||
}
|
||||
|
@ -1009,7 +997,6 @@ struct TwoByteString::HashPolicy {
|
|||
}
|
||||
|
||||
struct EqualityMatcher {
|
||||
using ReturnType = bool;
|
||||
const TwoByteString& rhs;
|
||||
explicit EqualityMatcher(const TwoByteString& rhs) : rhs(rhs) { }
|
||||
|
||||
|
|
|
@ -1938,8 +1938,6 @@ ScriptSource::chars(JSContext* cx, UncompressedSourceCache::AutoHoldEntry& holde
|
|||
{
|
||||
struct CharsMatcher
|
||||
{
|
||||
using ReturnType = const char16_t*;
|
||||
|
||||
JSContext* cx;
|
||||
ScriptSource& ss;
|
||||
UncompressedSourceCache::AutoHoldEntry& holder;
|
||||
|
@ -1951,11 +1949,11 @@ ScriptSource::chars(JSContext* cx, UncompressedSourceCache::AutoHoldEntry& holde
|
|||
, holder(holder)
|
||||
{ }
|
||||
|
||||
ReturnType match(Uncompressed& u) {
|
||||
const char16_t* match(Uncompressed& u) {
|
||||
return u.chars;
|
||||
}
|
||||
|
||||
ReturnType match(Compressed& c) {
|
||||
const char16_t* match(Compressed& c) {
|
||||
if (const char16_t* decompressed = cx->runtime()->uncompressedSourceCache.lookup(&ss, holder))
|
||||
return decompressed;
|
||||
|
||||
|
@ -1984,18 +1982,16 @@ ScriptSource::chars(JSContext* cx, UncompressedSourceCache::AutoHoldEntry& holde
|
|||
return decompressed;
|
||||
}
|
||||
|
||||
ReturnType match(Parent& p) {
|
||||
const char16_t* match(Parent& p) {
|
||||
return p.parent->chars(cx, holder);
|
||||
}
|
||||
|
||||
ReturnType match(Missing&) {
|
||||
const char16_t* match(Missing&) {
|
||||
MOZ_CRASH("ScriptSource::chars() on ScriptSource with SourceType = Missing");
|
||||
return nullptr;
|
||||
}
|
||||
};
|
||||
|
||||
CharsMatcher cm(cx, *this, holder);
|
||||
return data.match(cm);
|
||||
return data.match(CharsMatcher(cx, *this, holder));
|
||||
}
|
||||
|
||||
JSFlatString*
|
||||
|
@ -2192,30 +2188,28 @@ ScriptSource::~ScriptSource()
|
|||
{
|
||||
struct DestroyMatcher
|
||||
{
|
||||
using ReturnType = void;
|
||||
|
||||
ScriptSource& ss;
|
||||
|
||||
explicit DestroyMatcher(ScriptSource& ss)
|
||||
: ss(ss)
|
||||
{ }
|
||||
|
||||
ReturnType match(Uncompressed& u) {
|
||||
void match(Uncompressed& u) {
|
||||
if (u.ownsChars)
|
||||
js_free(const_cast<char16_t*>(u.chars));
|
||||
}
|
||||
|
||||
ReturnType match(Compressed& c) {
|
||||
void match(Compressed& c) {
|
||||
if (ss.inCompressedSourceSet)
|
||||
TlsPerThreadData.get()->runtimeFromMainThread()->compressedSourceSet.remove(&ss);
|
||||
js_free(c.raw);
|
||||
}
|
||||
|
||||
ReturnType match(Parent& p) {
|
||||
void match(Parent& p) {
|
||||
p.parent->decref();
|
||||
}
|
||||
|
||||
ReturnType match(Missing&) {
|
||||
void match(Missing&) {
|
||||
// Nothing to do here.
|
||||
}
|
||||
};
|
||||
|
@ -2223,8 +2217,7 @@ ScriptSource::~ScriptSource()
|
|||
MOZ_ASSERT(refs == 0);
|
||||
MOZ_ASSERT_IF(inCompressedSourceSet, data.is<Compressed>());
|
||||
|
||||
DestroyMatcher dm(*this);
|
||||
data.match(dm);
|
||||
data.match(DestroyMatcher(*this));
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -2247,21 +2240,19 @@ ScriptSource::performXDR(XDRState<mode>* xdr)
|
|||
{
|
||||
struct CompressedLengthMatcher
|
||||
{
|
||||
using ReturnType = size_t;
|
||||
|
||||
ReturnType match(Uncompressed&) {
|
||||
size_t match(Uncompressed&) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
ReturnType match(Compressed& c) {
|
||||
size_t match(Compressed& c) {
|
||||
return c.nbytes;
|
||||
}
|
||||
|
||||
ReturnType match(Parent& p) {
|
||||
size_t match(Parent& p) {
|
||||
return p.parent->data.match(*this);
|
||||
}
|
||||
|
||||
ReturnType match(Missing&) {
|
||||
size_t match(Missing&) {
|
||||
MOZ_CRASH("Missing source data in ScriptSource::performXDR");
|
||||
return 0;
|
||||
}
|
||||
|
@ -2269,21 +2260,19 @@ ScriptSource::performXDR(XDRState<mode>* xdr)
|
|||
|
||||
struct RawDataMatcher
|
||||
{
|
||||
using ReturnType = void*;
|
||||
|
||||
ReturnType match(Uncompressed& u) {
|
||||
void* match(Uncompressed& u) {
|
||||
return (void*) u.chars;
|
||||
}
|
||||
|
||||
ReturnType match(Compressed& c) {
|
||||
void* match(Compressed& c) {
|
||||
return c.raw;
|
||||
}
|
||||
|
||||
ReturnType match(Parent& p) {
|
||||
void* match(Parent& p) {
|
||||
return p.parent->data.match(*this);
|
||||
}
|
||||
|
||||
ReturnType match(Missing&) {
|
||||
void* match(Missing&) {
|
||||
MOZ_CRASH("Missing source data in ScriptSource::performXDR");
|
||||
return nullptr;
|
||||
}
|
||||
|
@ -2303,10 +2292,8 @@ ScriptSource::performXDR(XDRState<mode>* xdr)
|
|||
return false;
|
||||
|
||||
uint32_t compressedLength;
|
||||
if (mode == XDR_ENCODE) {
|
||||
CompressedLengthMatcher m;
|
||||
compressedLength = data.match(m);
|
||||
}
|
||||
if (mode == XDR_ENCODE)
|
||||
compressedLength = data.match(CompressedLengthMatcher());
|
||||
if (!xdr->codeUint32(&compressedLength))
|
||||
return false;
|
||||
|
||||
|
@ -2334,8 +2321,7 @@ ScriptSource::performXDR(XDRState<mode>* xdr)
|
|||
else
|
||||
setSource((const char16_t*) p, length_);
|
||||
} else {
|
||||
RawDataMatcher rdm;
|
||||
void* p = data.match(rdm);
|
||||
void* p = data.match(RawDataMatcher());
|
||||
if (!xdr->codeBytes(p, byteLen))
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -1560,8 +1560,6 @@ ConcreteStackFrame<SavedFrame>::constructSavedFrameStack(JSContext* cx,
|
|||
// `JS::ubi::AtomOrTwoByteChars` string to a `JSAtom*`.
|
||||
struct MOZ_STACK_CLASS AtomizingMatcher
|
||||
{
|
||||
using ReturnType = JSAtom*;
|
||||
|
||||
JSContext* cx;
|
||||
size_t length;
|
||||
|
||||
|
|
|
@ -55,8 +55,6 @@ using JS::ubi::TracerConcreteWithCompartment;
|
|||
|
||||
struct CopyToBufferMatcher
|
||||
{
|
||||
using ReturnType = size_t;
|
||||
|
||||
RangedPtr<char16_t> destination;
|
||||
size_t maxLength;
|
||||
|
||||
|
@ -108,8 +106,6 @@ JS::ubi::AtomOrTwoByteChars::copyToBuffer(RangedPtr<char16_t> destination, size_
|
|||
|
||||
struct LengthMatcher
|
||||
{
|
||||
using ReturnType = size_t;
|
||||
|
||||
size_t
|
||||
match(JSAtom* atom)
|
||||
{
|
||||
|
|
|
@ -169,10 +169,11 @@ struct VariantImplementation<N, T> {
|
|||
return aLhs.template as<T>() == aRhs.template as<T>();
|
||||
}
|
||||
|
||||
template<typename Matcher, typename ConcreteVariant,
|
||||
typename ReturnType = typename RemoveReference<Matcher>::Type::ReturnType>
|
||||
static ReturnType
|
||||
match(Matcher&& aMatcher, ConcreteVariant& aV) {
|
||||
template<typename Matcher, typename ConcreteVariant>
|
||||
static auto
|
||||
match(Matcher&& aMatcher, ConcreteVariant& aV)
|
||||
-> decltype(aMatcher.match(aV.template as<T>()))
|
||||
{
|
||||
return aMatcher.match(aV.template as<T>());
|
||||
}
|
||||
};
|
||||
|
@ -226,10 +227,10 @@ struct VariantImplementation<N, T, Ts...>
|
|||
}
|
||||
}
|
||||
|
||||
template<typename Matcher, typename ConcreteVariant,
|
||||
typename ReturnType = typename RemoveReference<Matcher>::Type::ReturnType>
|
||||
static ReturnType
|
||||
template<typename Matcher, typename ConcreteVariant>
|
||||
static auto
|
||||
match(Matcher&& aMatcher, ConcreteVariant& aV)
|
||||
-> decltype(aMatcher.match(aV.template as<T>()))
|
||||
{
|
||||
if (aV.template is<T>()) {
|
||||
return aMatcher.match(aV.template as<T>());
|
||||
|
@ -243,7 +244,7 @@ struct VariantImplementation<N, T, Ts...>
|
|||
// initialize return object of type <...> with an rvalue of type
|
||||
// <...>" then that means that the Matcher::match(T&) overloads
|
||||
// are returning different types. They must all return the same
|
||||
// Matcher::ReturnType type.
|
||||
// type.
|
||||
return Next::match(aMatcher, aV);
|
||||
}
|
||||
}
|
||||
|
@ -370,11 +371,11 @@ struct AsVariantTemporary
|
|||
* // Good!
|
||||
* struct FooMatcher
|
||||
* {
|
||||
* using ReturnType = char*;
|
||||
* ReturnType match(A& a) { ... }
|
||||
* ReturnType match(B& b) { ... }
|
||||
* ReturnType match(C& c) { ... }
|
||||
* ReturnType match(D& d) { ... } // Compile-time error to forget D!
|
||||
* // The return type of all matchers must be idential.
|
||||
* char* match(A& a) { ... }
|
||||
* char* match(B& b) { ... }
|
||||
* char* match(C& c) { ... }
|
||||
* char* match(D& d) { ... } // Compile-time error to forget D!
|
||||
* }
|
||||
* char* foo(Variant<A, B, C, D>& v) {
|
||||
* return v.match(FooMatcher());
|
||||
|
@ -558,15 +559,15 @@ public:
|
|||
|
||||
/** Match on an immutable const reference. */
|
||||
template<typename Matcher>
|
||||
typename RemoveReference<Matcher>::Type::ReturnType
|
||||
match(Matcher&& aMatcher) const {
|
||||
auto
|
||||
match(Matcher&& aMatcher) const -> decltype(Impl::match(aMatcher, *this)) {
|
||||
return Impl::match(aMatcher, *this);
|
||||
}
|
||||
|
||||
/** Match on a mutable non-const reference. */
|
||||
template<typename Matcher>
|
||||
typename RemoveReference<Matcher>::Type::ReturnType
|
||||
match(Matcher&& aMatcher) {
|
||||
auto
|
||||
match(Matcher&& aMatcher) -> decltype(Impl::match(aMatcher, *this)) {
|
||||
return Impl::match(aMatcher, *this);
|
||||
}
|
||||
};
|
||||
|
|
|
@ -129,8 +129,6 @@ struct Describer
|
|||
static const char* medium;
|
||||
static const char* big;
|
||||
|
||||
using ReturnType = const char*;
|
||||
|
||||
const char* match(const uint8_t&) { return little; }
|
||||
const char* match(const uint32_t&) { return medium; }
|
||||
const char* match(const uint64_t&) { return big; }
|
||||
|
|
Загрузка…
Ссылка в новой задаче