1/*
2 * Copyright (C) 2006-2018 Apple Inc. All rights reserved.
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
13 *
14 * You should have received a copy of the GNU Library General Public License
15 * along with this library; see the file COPYING.LIB. If not, write to
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18 *
19 */
20
21#pragma once
22
23#include <stddef.h>
24
25namespace WTF {
26
27class AtomString;
28class AtomStringImpl;
29class BinarySemaphore;
30class CString;
31class CrashOnOverflow;
32class FunctionDispatcher;
33class Hasher;
34class MonotonicTime;
35class OrdinalNumber;
36class PrintStream;
37class SHA1;
38class Seconds;
39class String;
40class StringBuilder;
41class StringImpl;
42class StringView;
43class TextPosition;
44class TextStream;
45class UniquedStringImpl;
46class URL;
47class WallTime;
48
49struct FastMalloc;
50
51template<typename> class CompletionHandler;
52template<typename T> struct DumbPtrTraits;
53template<typename T> struct DumbValueTraits;
54template<typename> class Function;
55template<typename> class LazyNeverDestroyed;
56template<typename> class NeverDestroyed;
57template<typename> class OptionSet;
58template<typename> class Optional;
59template<typename T, typename = DumbPtrTraits<T>> class Ref;
60template<typename T, typename = DumbPtrTraits<T>> class RefPtr;
61template<typename> class StringBuffer;
62template<typename, typename = void> class StringTypeAdapter;
63template<typename T> class WeakPtr;
64
65template<typename> struct DefaultHash { using Hash = void; };
66template<typename> struct HashTraits;
67
68template<typename> struct EnumTraits;
69template<typename E, E...> struct EnumValues;
70
71template<typename...> class Variant;
72template<typename, size_t = 0, typename = CrashOnOverflow, size_t = 16> class Vector;
73template<typename Value, typename = typename DefaultHash<Value>::Hash, typename = HashTraits<Value>> class HashCountedSet;
74template<typename KeyArg, typename MappedArg, typename = typename DefaultHash<KeyArg>::Hash, typename = HashTraits<KeyArg>, typename = HashTraits<MappedArg>> class HashMap;
75template<typename ValueArg, typename = typename DefaultHash<ValueArg>::Hash, typename = HashTraits<ValueArg>> class HashSet;
76
77template<size_t, typename> struct variant_alternative;
78template<ptrdiff_t, typename...> struct __indexed_type;
79template<ptrdiff_t _Index, typename... _Types> constexpr typename __indexed_type<_Index, _Types...>::__type const& get(Variant<_Types...> const&);
80
81}
82
83namespace std {
84namespace experimental {
85inline namespace fundamentals_v3 {
86template<class, class> class expected;
87template<class> class unexpected;
88}}} // namespace std::experimental::fundamentals_v3
89
90using WTF::AtomString;
91using WTF::AtomStringImpl;
92using WTF::BinarySemaphore;
93using WTF::CString;
94using WTF::CompletionHandler;
95using WTF::DumbPtrTraits;
96using WTF::DumbValueTraits;
97using WTF::Function;
98using WTF::FunctionDispatcher;
99using WTF::HashCountedSet;
100using WTF::HashMap;
101using WTF::HashSet;
102using WTF::Hasher;
103using WTF::LazyNeverDestroyed;
104using WTF::NeverDestroyed;
105using WTF::OptionSet;
106using WTF::Optional;
107using WTF::OrdinalNumber;
108using WTF::PrintStream;
109using WTF::Ref;
110using WTF::RefPtr;
111using WTF::SHA1;
112using WTF::String;
113using WTF::StringBuffer;
114using WTF::StringBuilder;
115using WTF::StringImpl;
116using WTF::StringView;
117using WTF::TextPosition;
118using WTF::TextStream;
119using WTF::URL;
120using WTF::Variant;
121using WTF::Vector;
122
123template<class T, class E> using Expected = std::experimental::expected<T, E>;
124template<class E> using Unexpected = std::experimental::unexpected<E>;
125
126// Sometimes an inline method simply forwards to another one and does nothing else. If it were
127// just a forward declaration of that method then you would only need a forward declaration of
128// its return types and parameter types too, but because it's inline and it actually needs to
129// return / pass these types (even though it's just passing through whatever it called) you
130// now find yourself having to actually have a full declaration of these types. That might be
131// an include you'd rather avoid.
132//
133// No more. Enter template magic to lazily instantiate that method!
134//
135// This macro makes the method work as if you'd declared the return / parameter types as normal,
136// but forces lazy instantiation of the method at the call site, at which point the caller (not
137// the declaration) had better have a full declaration of the return / parameter types.
138//
139// Simply pass the forward-declared types to the macro, with an alias for each, and then define
140// your function as you otherwise would have but using the aliased name. Why the alias? So you
141// can be lazy on templated types! Sample usage:
142//
143// struct Foo; // No need to define Foo!
144// template<typename T>
145// struct A {
146// Foo declared(Bar); // Forward declarations of Foo and Bar are sufficient here.
147// // The below code would normally require a definition of Foo and Bar.
148// WTF_LAZY_INSTANTIATE(Foo=Foo, Bar=Bar) Foo forwarder(Bar b) { return declared(b); }
149// };
150#define WTF_LAZY_JOIN_UNLAZE(A, B) A##B
151#define WTF_LAZY_JOIN(A, B) WTF_LAZY_JOIN_UNLAZE(A, B)
152#define WTF_LAZY_ARGUMENT_NUMBER(_1, _2, _3, _4, _5, _6, _7, _8, N, ...) N
153#define WTF_LAZY_AUGMENT(...) unused, __VA_ARGS__
154#define WTF_LAZY_EXPAND(x) x
155#define WTF_LAZY_NUM_ARGS_(...) WTF_LAZY_EXPAND(WTF_LAZY_ARGUMENT_NUMBER(__VA_ARGS__, 7, 6, 5, 4, 3, 2, 1, 0))
156#define WTF_LAZY_NUM_ARGS(...) WTF_LAZY_NUM_ARGS_(WTF_LAZY_AUGMENT(__VA_ARGS__))
157#define WTF_LAZY_FOR_EACH_TERM(F, ...) \
158 WTF_LAZY_JOIN(WTF_LAZY_FOR_EACH_TERM_, WTF_LAZY_NUM_ARGS(__VA_ARGS__))(F, (__VA_ARGS__))
159#define WTF_LAZY_FIRST(_1, ...) _1
160#define WTF_LAZY_REST(_1, ...) (__VA_ARGS__)
161#define WTF_LAZY_REST_(_1, ...) __VA_ARGS__
162#define WTF_LAZY_CALL(F, ARG) F(ARG)
163#define WTF_LAZY_FOR_EACH_TERM_0(...)
164#define WTF_LAZY_FOR_EACH_TERM_1(F, ARGS) WTF_LAZY_CALL(F, WTF_LAZY_FIRST ARGS) WTF_LAZY_FOR_EACH_TERM_0(F, WTF_LAZY_REST ARGS)
165#define WTF_LAZY_FOR_EACH_TERM_2(F, ARGS) WTF_LAZY_CALL(F, WTF_LAZY_FIRST ARGS) WTF_LAZY_FOR_EACH_TERM_1(F, WTF_LAZY_REST ARGS)
166#define WTF_LAZY_FOR_EACH_TERM_3(F, ARGS) WTF_LAZY_CALL(F, WTF_LAZY_FIRST ARGS) WTF_LAZY_FOR_EACH_TERM_2(F, WTF_LAZY_REST ARGS)
167#define WTF_LAZY_FOR_EACH_TERM_4(F, ARGS) WTF_LAZY_CALL(F, WTF_LAZY_FIRST ARGS) WTF_LAZY_FOR_EACH_TERM_3(F, WTF_LAZY_REST ARGS)
168#define WTF_LAZY_FOR_EACH_TERM_5(F, ARGS) WTF_LAZY_CALL(F, WTF_LAZY_FIRST ARGS) WTF_LAZY_FOR_EACH_TERM_4(F, WTF_LAZY_REST ARGS)
169#define WTF_LAZY_FOR_EACH_TERM_6(F, ARGS) WTF_LAZY_CALL(F, WTF_LAZY_FIRST ARGS) WTF_LAZY_FOR_EACH_TERM_5(F, WTF_LAZY_REST ARGS)
170#define WTF_LAZY_FOR_EACH_TERM_7(F, ARGS) WTF_LAZY_CALL(F, WTF_LAZY_FIRST ARGS) WTF_LAZY_FOR_EACH_TERM_6(F, WTF_LAZY_REST ARGS)
171#define WTF_LAZY_DECLARE_ALIAS_AND_TYPE(ALIAS_AND_TYPE) typename ALIAS_AND_TYPE,
172#define WTF_LAZY_INSTANTIATE(...) \
173 template< \
174 WTF_LAZY_FOR_EACH_TERM(WTF_LAZY_DECLARE_ALIAS_AND_TYPE, __VA_ARGS__) \
175 typename = void>
176
177#define WTF_LAZY_HAS_REST_0(...)
178#define WTF_LAZY_HAS_REST_1(...)
179#define WTF_LAZY_HAS_REST_2 WTF_LAZY_EXPAND
180#define WTF_LAZY_HAS_REST_3 WTF_LAZY_EXPAND
181#define WTF_LAZY_HAS_REST_4 WTF_LAZY_EXPAND
182#define WTF_LAZY_HAS_REST_5 WTF_LAZY_EXPAND
183#define WTF_LAZY_HAS_REST_6 WTF_LAZY_EXPAND
184#define WTF_LAZY_HAS_REST_7 WTF_LAZY_EXPAND
185#define WTF_LAZY_HAS_REST_8 WTF_LAZY_EXPAND
186#define WTF_LAZY_HAS_REST(...) \
187 WTF_LAZY_JOIN(WTF_LAZY_HAS_REST_, WTF_LAZY_NUM_ARGS(__VA_ARGS__))
188