Mercurial > hg > sv-dependency-builds
comparison win64-msvc/include/capnp/generated-header-support.h @ 148:b4bfdf10c4b3
Update Win64 capnp builds to v0.6
author | Chris Cannam <cannam@all-day-breakfast.com> |
---|---|
date | Mon, 22 May 2017 18:56:49 +0100 |
parents | 42a73082be24 |
children |
comparison
equal
deleted
inserted
replaced
147:45360b968bf4 | 148:b4bfdf10c4b3 |
---|---|
17 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | 17 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
18 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | 18 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
19 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | 19 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
20 // THE SOFTWARE. | 20 // THE SOFTWARE. |
21 | 21 |
22 // This file is included form all generated headers. | 22 // This file is included from all generated headers. |
23 | 23 |
24 #ifndef CAPNP_GENERATED_HEADER_SUPPORT_H_ | 24 #ifndef CAPNP_GENERATED_HEADER_SUPPORT_H_ |
25 #define CAPNP_GENERATED_HEADER_SUPPORT_H_ | 25 #define CAPNP_GENERATED_HEADER_SUPPORT_H_ |
26 | 26 |
27 #if defined(__GNUC__) && !defined(CAPNP_HEADER_WARNINGS) | 27 #if defined(__GNUC__) && !defined(CAPNP_HEADER_WARNINGS) |
28 #pragma GCC system_header | 28 #pragma GCC system_header |
29 #endif | 29 #endif |
30 | 30 |
31 #include "raw-schema.h" | |
31 #include "layout.h" | 32 #include "layout.h" |
32 #include "list.h" | 33 #include "list.h" |
33 #include "orphan.h" | 34 #include "orphan.h" |
34 #include "pointer-helpers.h" | 35 #include "pointer-helpers.h" |
35 #include "any.h" | 36 #include "any.h" |
49 | 50 |
50 namespace _ { // private | 51 namespace _ { // private |
51 | 52 |
52 #if !CAPNP_LITE | 53 #if !CAPNP_LITE |
53 | 54 |
54 struct RawSchema; | |
55 | |
56 struct RawBrandedSchema { | |
57 // Represents a combination of a schema and bindings for its generic parameters. | |
58 // | |
59 // Note that while we generate one `RawSchema` per type, we generate a `RawBrandedSchema` for | |
60 // every _instance_ of a generic type -- or, at least, every instance that is actually used. For | |
61 // generated-code types, we use template magic to initialize these. | |
62 | |
63 const RawSchema* generic; | |
64 // Generic type which we're branding. | |
65 | |
66 struct Binding { | |
67 uint8_t which; // Numeric value of one of schema::Type::Which. | |
68 | |
69 bool isImplicitParameter; | |
70 // For AnyPointer, true if it's an implicit method parameter. | |
71 | |
72 uint16_t listDepth; // Number of times to wrap the base type in List(). | |
73 | |
74 uint16_t paramIndex; | |
75 // For AnyPointer. If it's a type parameter (scopeId is non-zero) or it's an implicit parameter | |
76 // (isImplicitParameter is true), then this is the parameter index. Otherwise this is a numeric | |
77 // value of one of schema::Type::AnyPointer::Unconstrained::Which. | |
78 | |
79 union { | |
80 const RawBrandedSchema* schema; // for struct, enum, interface | |
81 uint64_t scopeId; // for AnyPointer, if it's a type parameter | |
82 }; | |
83 | |
84 Binding() = default; | |
85 inline constexpr Binding(uint8_t which, uint16_t listDepth, const RawBrandedSchema* schema) | |
86 : which(which), isImplicitParameter(false), listDepth(listDepth), paramIndex(0), | |
87 schema(schema) {} | |
88 inline constexpr Binding(uint8_t which, uint16_t listDepth, | |
89 uint64_t scopeId, uint16_t paramIndex) | |
90 : which(which), isImplicitParameter(false), listDepth(listDepth), paramIndex(paramIndex), | |
91 scopeId(scopeId) {} | |
92 inline constexpr Binding(uint8_t which, uint16_t listDepth, uint16_t implicitParamIndex) | |
93 : which(which), isImplicitParameter(true), listDepth(listDepth), | |
94 paramIndex(implicitParamIndex), scopeId(0) {} | |
95 }; | |
96 | |
97 struct Scope { | |
98 uint64_t typeId; | |
99 // Type ID whose parameters are being bound. | |
100 | |
101 const Binding* bindings; | |
102 uint bindingCount; | |
103 // Bindings for those parameters. | |
104 | |
105 bool isUnbound; | |
106 // This scope is unbound, in the sense of SchemaLoader::getUnbound(). | |
107 }; | |
108 | |
109 const Scope* scopes; | |
110 // Array of enclosing scopes for which generic variables have been bound, sorted by type ID. | |
111 | |
112 struct Dependency { | |
113 uint location; | |
114 const RawBrandedSchema* schema; | |
115 }; | |
116 | |
117 const Dependency* dependencies; | |
118 // Map of branded schemas for dependencies of this type, given our brand. Only dependencies that | |
119 // are branded are included in this map; if a dependency is missing, use its `defaultBrand`. | |
120 | |
121 uint32_t scopeCount; | |
122 uint32_t dependencyCount; | |
123 | |
124 enum class DepKind { | |
125 // Component of a Dependency::location. Specifies what sort of dependency this is. | |
126 | |
127 INVALID, | |
128 // Mostly defined to ensure that zero is not a valid location. | |
129 | |
130 FIELD, | |
131 // Binding needed for a field's type. The index is the field index (NOT ordinal!). | |
132 | |
133 METHOD_PARAMS, | |
134 // Bindings needed for a method's params type. The index is the method number. | |
135 | |
136 METHOD_RESULTS, | |
137 // Bindings needed for a method's results type. The index is the method ordinal. | |
138 | |
139 SUPERCLASS, | |
140 // Bindings needed for a superclass type. The index is the superclass's index in the | |
141 // "extends" list. | |
142 | |
143 CONST_TYPE | |
144 // Bindings needed for the type of a constant. The index is zero. | |
145 }; | |
146 | |
147 static inline uint makeDepLocation(DepKind kind, uint index) { | |
148 // Make a number representing the location of a particular dependency within its parent | |
149 // schema. | |
150 | |
151 return (static_cast<uint>(kind) << 24) | index; | |
152 } | |
153 | |
154 class Initializer { | |
155 public: | |
156 virtual void init(const RawBrandedSchema* generic) const = 0; | |
157 }; | |
158 | |
159 const Initializer* lazyInitializer; | |
160 // Lazy initializer, invoked by ensureInitialized(). | |
161 | |
162 inline void ensureInitialized() const { | |
163 // Lazy initialization support. Invoke to ensure that initialization has taken place. This | |
164 // is required in particular when traversing the dependency list. RawSchemas for compiled-in | |
165 // types are always initialized; only dynamically-loaded schemas may be lazy. | |
166 | |
167 const Initializer* i = __atomic_load_n(&lazyInitializer, __ATOMIC_ACQUIRE); | |
168 if (i != nullptr) i->init(this); | |
169 } | |
170 | |
171 inline bool isUnbound() const; | |
172 // Checks if this schema is the result of calling SchemaLoader::getUnbound(), in which case | |
173 // binding lookups need to be handled specially. | |
174 }; | |
175 | |
176 struct RawSchema { | |
177 // The generated code defines a constant RawSchema for every compiled declaration. | |
178 // | |
179 // This is an internal structure which could change in the future. | |
180 | |
181 uint64_t id; | |
182 | |
183 const word* encodedNode; | |
184 // Encoded SchemaNode, readable via readMessageUnchecked<schema::Node>(encodedNode). | |
185 | |
186 uint32_t encodedSize; | |
187 // Size of encodedNode, in words. | |
188 | |
189 const RawSchema* const* dependencies; | |
190 // Pointers to other types on which this one depends, sorted by ID. The schemas in this table | |
191 // may be uninitialized -- you must call ensureInitialized() on the one you wish to use before | |
192 // using it. | |
193 // | |
194 // TODO(someday): Make this a hashtable. | |
195 | |
196 const uint16_t* membersByName; | |
197 // Indexes of members sorted by name. Used to implement name lookup. | |
198 // TODO(someday): Make this a hashtable. | |
199 | |
200 uint32_t dependencyCount; | |
201 uint32_t memberCount; | |
202 // Sizes of above tables. | |
203 | |
204 const uint16_t* membersByDiscriminant; | |
205 // List of all member indexes ordered by discriminant value. Those which don't have a | |
206 // discriminant value are listed at the end, in order by ordinal. | |
207 | |
208 const RawSchema* canCastTo; | |
209 // Points to the RawSchema of a compiled-in type to which it is safe to cast any DynamicValue | |
210 // with this schema. This is null for all compiled-in types; it is only set by SchemaLoader on | |
211 // dynamically-loaded types. | |
212 | |
213 class Initializer { | |
214 public: | |
215 virtual void init(const RawSchema* schema) const = 0; | |
216 }; | |
217 | |
218 const Initializer* lazyInitializer; | |
219 // Lazy initializer, invoked by ensureInitialized(). | |
220 | |
221 inline void ensureInitialized() const { | |
222 // Lazy initialization support. Invoke to ensure that initialization has taken place. This | |
223 // is required in particular when traversing the dependency list. RawSchemas for compiled-in | |
224 // types are always initialized; only dynamically-loaded schemas may be lazy. | |
225 | |
226 const Initializer* i = __atomic_load_n(&lazyInitializer, __ATOMIC_ACQUIRE); | |
227 if (i != nullptr) i->init(this); | |
228 } | |
229 | |
230 RawBrandedSchema defaultBrand; | |
231 // Specifies the brand to use for this schema if no generic parameters have been bound to | |
232 // anything. Generally, in the default brand, all generic parameters are treated as if they were | |
233 // bound to `AnyPointer`. | |
234 }; | |
235 | |
236 inline bool RawBrandedSchema::isUnbound() const { | |
237 // The unbound schema is the only one that has no scopes but is not the default schema. | |
238 return scopeCount == 0 && this != &generic->defaultBrand; | |
239 } | |
240 | |
241 template <typename T, typename CapnpPrivate = typename T::_capnpPrivate, bool = false> | 55 template <typename T, typename CapnpPrivate = typename T::_capnpPrivate, bool = false> |
242 inline const RawSchema& rawSchema() { | 56 inline const RawSchema& rawSchema() { |
243 return *CapnpPrivate::schema; | 57 return *CapnpPrivate::schema; |
244 } | 58 } |
245 template <typename T, uint64_t id = schemas::EnumInfo<T>::typeId> | 59 template <typename T, uint64_t id = schemas::EnumInfo<T>::typeId> |
247 return *schemas::EnumInfo<T>::schema; | 61 return *schemas::EnumInfo<T>::schema; |
248 } | 62 } |
249 | 63 |
250 template <typename T, typename CapnpPrivate = typename T::_capnpPrivate> | 64 template <typename T, typename CapnpPrivate = typename T::_capnpPrivate> |
251 inline const RawBrandedSchema& rawBrandedSchema() { | 65 inline const RawBrandedSchema& rawBrandedSchema() { |
252 return *CapnpPrivate::brand; | 66 return *CapnpPrivate::brand(); |
253 } | 67 } |
254 template <typename T, uint64_t id = schemas::EnumInfo<T>::typeId> | 68 template <typename T, uint64_t id = schemas::EnumInfo<T>::typeId> |
255 inline const RawBrandedSchema& rawBrandedSchema() { | 69 inline const RawBrandedSchema& rawBrandedSchema() { |
256 return schemas::EnumInfo<T>::schema->defaultBrand; | 70 return schemas::EnumInfo<T>::schema->defaultBrand; |
257 } | 71 } |
262 // specific brand instance. TypeTag is the _capnpPrivate struct for the type in question. | 76 // specific brand instance. TypeTag is the _capnpPrivate struct for the type in question. |
263 | 77 |
264 template <typename TypeTag> | 78 template <typename TypeTag> |
265 struct ChooseBrand<TypeTag> { | 79 struct ChooseBrand<TypeTag> { |
266 // All params were AnyPointer. No specific brand needed. | 80 // All params were AnyPointer. No specific brand needed. |
267 static constexpr _::RawBrandedSchema const* brand = &TypeTag::schema->defaultBrand; | 81 static constexpr _::RawBrandedSchema const* brand() { return &TypeTag::schema->defaultBrand; } |
268 }; | 82 }; |
269 | 83 |
270 template <typename TypeTag, typename... Rest> | 84 template <typename TypeTag, typename... Rest> |
271 struct ChooseBrand<TypeTag, AnyPointer, Rest...>: public ChooseBrand<TypeTag, Rest...> {}; | 85 struct ChooseBrand<TypeTag, AnyPointer, Rest...>: public ChooseBrand<TypeTag, Rest...> {}; |
272 // The first parameter is AnyPointer, so recurse to check the rest. | 86 // The first parameter is AnyPointer, so recurse to check the rest. |
273 | 87 |
274 template <typename TypeTag, typename First, typename... Rest> | 88 template <typename TypeTag, typename First, typename... Rest> |
275 struct ChooseBrand<TypeTag, First, Rest...> { | 89 struct ChooseBrand<TypeTag, First, Rest...> { |
276 // At least one parameter is not AnyPointer, so use the specificBrand constant. | 90 // At least one parameter is not AnyPointer, so use the specificBrand constant. |
277 static constexpr _::RawBrandedSchema const* brand = &TypeTag::specificBrand; | 91 static constexpr _::RawBrandedSchema const* brand() { return &TypeTag::specificBrand; } |
278 }; | 92 }; |
279 | 93 |
280 template <typename T, Kind k = kind<T>()> | 94 template <typename T, Kind k = kind<T>()> |
281 struct BrandBindingFor_; | 95 struct BrandBindingFor_; |
282 | 96 |
330 }; | 144 }; |
331 | 145 |
332 template <typename T> | 146 template <typename T> |
333 struct BrandBindingFor_<T, Kind::STRUCT> { | 147 struct BrandBindingFor_<T, Kind::STRUCT> { |
334 static constexpr RawBrandedSchema::Binding get(uint16_t listDepth) { | 148 static constexpr RawBrandedSchema::Binding get(uint16_t listDepth) { |
335 return { 16, listDepth, T::_capnpPrivate::brand }; | 149 return { 16, listDepth, T::_capnpPrivate::brand() }; |
336 } | 150 } |
337 }; | 151 }; |
338 | 152 |
339 template <typename T> | 153 template <typename T> |
340 struct BrandBindingFor_<T, Kind::INTERFACE> { | 154 struct BrandBindingFor_<T, Kind::INTERFACE> { |
341 static constexpr RawBrandedSchema::Binding get(uint16_t listDepth) { | 155 static constexpr RawBrandedSchema::Binding get(uint16_t listDepth) { |
342 return { 17, listDepth, T::_capnpPrivate::brand }; | 156 return { 17, listDepth, T::_capnpPrivate::brand() }; |
343 } | 157 } |
344 }; | 158 }; |
345 | 159 |
346 template <> | 160 template <> |
347 struct BrandBindingFor_<AnyPointer, Kind::OTHER> { | 161 struct BrandBindingFor_<AnyPointer, Kind::OTHER> { |
495 template <typename T> | 309 template <typename T> |
496 inline constexpr uint sizeInWords() { | 310 inline constexpr uint sizeInWords() { |
497 // Return the size, in words, of a Struct type, if allocated free-standing (not in a list). | 311 // Return the size, in words, of a Struct type, if allocated free-standing (not in a list). |
498 // May be useful for pre-computing space needed in order to precisely allocate messages. | 312 // May be useful for pre-computing space needed in order to precisely allocate messages. |
499 | 313 |
500 return (WordCount32(_::structSize<T>().data) + | 314 return unbound((upgradeBound<uint>(_::structSize<T>().data) + |
501 _::structSize<T>().pointers * WORDS_PER_POINTER) / WORDS; | 315 _::structSize<T>().pointers * WORDS_PER_POINTER) / WORDS); |
502 } | 316 } |
503 | 317 |
504 } // namespace capnp | 318 } // namespace capnp |
505 | 319 |
506 #if _MSC_VER | 320 #if _MSC_VER |
510 #define CAPNP_NON_INT_CONSTEXPR_DECL_INIT(value) | 324 #define CAPNP_NON_INT_CONSTEXPR_DECL_INIT(value) |
511 #define CAPNP_NON_INT_CONSTEXPR_DEF_INIT(value) = value | 325 #define CAPNP_NON_INT_CONSTEXPR_DEF_INIT(value) = value |
512 #else | 326 #else |
513 #define CAPNP_NON_INT_CONSTEXPR_DECL_INIT(value) = value | 327 #define CAPNP_NON_INT_CONSTEXPR_DECL_INIT(value) = value |
514 #define CAPNP_NON_INT_CONSTEXPR_DEF_INIT(value) | 328 #define CAPNP_NON_INT_CONSTEXPR_DEF_INIT(value) |
329 #endif | |
330 | |
331 #if _MSC_VER | |
332 // TODO(msvc): A little hack to allow MSVC to use C++14 return type deduction in cases where the | |
333 // explicit type exposes bugs in the compiler. | |
334 #define CAPNP_AUTO_IF_MSVC(...) auto | |
335 #else | |
336 #define CAPNP_AUTO_IF_MSVC(...) __VA_ARGS__ | |
515 #endif | 337 #endif |
516 | 338 |
517 #if CAPNP_LITE | 339 #if CAPNP_LITE |
518 | 340 |
519 #define CAPNP_DECLARE_SCHEMA(id) \ | 341 #define CAPNP_DECLARE_SCHEMA(id) \ |