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 | |
25 | namespace WTF { |
26 | |
27 | class AtomString; |
28 | class AtomStringImpl; |
29 | class BinarySemaphore; |
30 | class CString; |
31 | class CrashOnOverflow; |
32 | class FunctionDispatcher; |
33 | class Hasher; |
34 | class MonotonicTime; |
35 | class OrdinalNumber; |
36 | class PrintStream; |
37 | class SHA1; |
38 | class Seconds; |
39 | class String; |
40 | class StringBuilder; |
41 | class StringImpl; |
42 | class StringView; |
43 | class TextPosition; |
44 | class TextStream; |
45 | class UniquedStringImpl; |
46 | class URL; |
47 | class WallTime; |
48 | |
49 | struct FastMalloc; |
50 | |
51 | template<typename> class CompletionHandler; |
52 | template<typename T> struct DumbPtrTraits; |
53 | template<typename T> struct DumbValueTraits; |
54 | template<typename> class Function; |
55 | template<typename> class LazyNeverDestroyed; |
56 | template<typename> class NeverDestroyed; |
57 | template<typename> class OptionSet; |
58 | template<typename> class Optional; |
59 | template<typename T, typename = DumbPtrTraits<T>> class Ref; |
60 | template<typename T, typename = DumbPtrTraits<T>> class RefPtr; |
61 | template<typename> class StringBuffer; |
62 | template<typename, typename = void> class StringTypeAdapter; |
63 | template<typename T> class WeakPtr; |
64 | |
65 | template<typename> struct DefaultHash { using Hash = void; }; |
66 | template<typename> struct HashTraits; |
67 | |
68 | template<typename> struct EnumTraits; |
69 | template<typename E, E...> struct EnumValues; |
70 | |
71 | template<typename...> class Variant; |
72 | template<typename, size_t = 0, typename = CrashOnOverflow, size_t = 16> class Vector; |
73 | template<typename Value, typename = typename DefaultHash<Value>::Hash, typename = HashTraits<Value>> class HashCountedSet; |
74 | template<typename KeyArg, typename MappedArg, typename = typename DefaultHash<KeyArg>::Hash, typename = HashTraits<KeyArg>, typename = HashTraits<MappedArg>> class HashMap; |
75 | template<typename ValueArg, typename = typename DefaultHash<ValueArg>::Hash, typename = HashTraits<ValueArg>> class HashSet; |
76 | |
77 | template<size_t, typename> struct variant_alternative; |
78 | template<ptrdiff_t, typename...> struct __indexed_type; |
79 | template<ptrdiff_t _Index, typename... _Types> constexpr typename __indexed_type<_Index, _Types...>::__type const& get(Variant<_Types...> const&); |
80 | |
81 | } |
82 | |
83 | namespace std { |
84 | namespace experimental { |
85 | inline namespace fundamentals_v3 { |
86 | template<class, class> class expected; |
87 | template<class> class unexpected; |
88 | }}} // namespace std::experimental::fundamentals_v3 |
89 | |
90 | using WTF::AtomString; |
91 | using WTF::AtomStringImpl; |
92 | using WTF::BinarySemaphore; |
93 | using WTF::CString; |
94 | using WTF::CompletionHandler; |
95 | using WTF::DumbPtrTraits; |
96 | using WTF::DumbValueTraits; |
97 | using WTF::Function; |
98 | using WTF::FunctionDispatcher; |
99 | using WTF::HashCountedSet; |
100 | using WTF::HashMap; |
101 | using WTF::HashSet; |
102 | using WTF::Hasher; |
103 | using WTF::LazyNeverDestroyed; |
104 | using WTF::NeverDestroyed; |
105 | using WTF::OptionSet; |
106 | using WTF::Optional; |
107 | using WTF::OrdinalNumber; |
108 | using WTF::PrintStream; |
109 | using WTF::Ref; |
110 | using WTF::RefPtr; |
111 | using WTF::SHA1; |
112 | using WTF::String; |
113 | using WTF::StringBuffer; |
114 | using WTF::StringBuilder; |
115 | using WTF::StringImpl; |
116 | using WTF::StringView; |
117 | using WTF::TextPosition; |
118 | using WTF::TextStream; |
119 | using WTF::URL; |
120 | using WTF::Variant; |
121 | using WTF::Vector; |
122 | |
123 | template<class T, class E> using Expected = std::experimental::expected<T, E>; |
124 | template<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 | |