Mercurial > hg > sv-dependency-builds
comparison win32-mingw/include/capnp/schema.capnp @ 50:37d53a7e8262
Headers for KJ/Capnp Win32
author | Chris Cannam |
---|---|
date | Wed, 26 Oct 2016 13:18:45 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
49:3ab5a40c4e3b | 50:37d53a7e8262 |
---|---|
1 # Copyright (c) 2013-2014 Sandstorm Development Group, Inc. and contributors | |
2 # Licensed under the MIT License: | |
3 # | |
4 # Permission is hereby granted, free of charge, to any person obtaining a copy | |
5 # of this software and associated documentation files (the "Software"), to deal | |
6 # in the Software without restriction, including without limitation the rights | |
7 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
8 # copies of the Software, and to permit persons to whom the Software is | |
9 # furnished to do so, subject to the following conditions: | |
10 # | |
11 # The above copyright notice and this permission notice shall be included in | |
12 # all copies or substantial portions of the Software. | |
13 # | |
14 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
15 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
16 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
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, | |
19 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | |
20 # THE SOFTWARE. | |
21 | |
22 using Cxx = import "/capnp/c++.capnp"; | |
23 | |
24 @0xa93fc509624c72d9; | |
25 $Cxx.namespace("capnp::schema"); | |
26 | |
27 using Id = UInt64; | |
28 # The globally-unique ID of a file, type, or annotation. | |
29 | |
30 struct Node { | |
31 id @0 :Id; | |
32 | |
33 displayName @1 :Text; | |
34 # Name to present to humans to identify this Node. You should not attempt to parse this. Its | |
35 # format could change. It is not guaranteed to be unique. | |
36 # | |
37 # (On Zooko's triangle, this is the node's nickname.) | |
38 | |
39 displayNamePrefixLength @2 :UInt32; | |
40 # If you want a shorter version of `displayName` (just naming this node, without its surrounding | |
41 # scope), chop off this many characters from the beginning of `displayName`. | |
42 | |
43 scopeId @3 :Id; | |
44 # ID of the lexical parent node. Typically, the scope node will have a NestedNode pointing back | |
45 # at this node, but robust code should avoid relying on this (and, in fact, group nodes are not | |
46 # listed in the outer struct's nestedNodes, since they are listed in the fields). `scopeId` is | |
47 # zero if the node has no parent, which is normally only the case with files, but should be | |
48 # allowed for any kind of node (in order to make runtime type generation easier). | |
49 | |
50 parameters @32 :List(Parameter); | |
51 # If this node is parameterized (generic), the list of parameters. Empty for non-generic types. | |
52 | |
53 isGeneric @33 :Bool; | |
54 # True if this node is generic, meaning that it or one of its parent scopes has a non-empty | |
55 # `parameters`. | |
56 | |
57 struct Parameter { | |
58 # Information about one of the node's parameters. | |
59 | |
60 name @0 :Text; | |
61 } | |
62 | |
63 nestedNodes @4 :List(NestedNode); | |
64 # List of nodes nested within this node, along with the names under which they were declared. | |
65 | |
66 struct NestedNode { | |
67 name @0 :Text; | |
68 # Unqualified symbol name. Unlike Node.displayName, this *can* be used programmatically. | |
69 # | |
70 # (On Zooko's triangle, this is the node's petname according to its parent scope.) | |
71 | |
72 id @1 :Id; | |
73 # ID of the nested node. Typically, the target node's scopeId points back to this node, but | |
74 # robust code should avoid relying on this. | |
75 } | |
76 | |
77 annotations @5 :List(Annotation); | |
78 # Annotations applied to this node. | |
79 | |
80 union { | |
81 # Info specific to each kind of node. | |
82 | |
83 file @6 :Void; | |
84 | |
85 struct :group { | |
86 dataWordCount @7 :UInt16; | |
87 # Size of the data section, in words. | |
88 | |
89 pointerCount @8 :UInt16; | |
90 # Size of the pointer section, in pointers (which are one word each). | |
91 | |
92 preferredListEncoding @9 :ElementSize; | |
93 # The preferred element size to use when encoding a list of this struct. If this is anything | |
94 # other than `inlineComposite` then the struct is one word or less in size and is a candidate | |
95 # for list packing optimization. | |
96 | |
97 isGroup @10 :Bool; | |
98 # If true, then this "struct" node is actually not an independent node, but merely represents | |
99 # some named union or group within a particular parent struct. This node's scopeId refers | |
100 # to the parent struct, which may itself be a union/group in yet another struct. | |
101 # | |
102 # All group nodes share the same dataWordCount and pointerCount as the top-level | |
103 # struct, and their fields live in the same ordinal and offset spaces as all other fields in | |
104 # the struct. | |
105 # | |
106 # Note that a named union is considered a special kind of group -- in fact, a named union | |
107 # is exactly equivalent to a group that contains nothing but an unnamed union. | |
108 | |
109 discriminantCount @11 :UInt16; | |
110 # Number of fields in this struct which are members of an anonymous union, and thus may | |
111 # overlap. If this is non-zero, then a 16-bit discriminant is present indicating which | |
112 # of the overlapping fields is active. This can never be 1 -- if it is non-zero, it must be | |
113 # two or more. | |
114 # | |
115 # Note that the fields of an unnamed union are considered fields of the scope containing the | |
116 # union -- an unnamed union is not its own group. So, a top-level struct may contain a | |
117 # non-zero discriminant count. Named unions, on the other hand, are equivalent to groups | |
118 # containing unnamed unions. So, a named union has its own independent schema node, with | |
119 # `isGroup` = true. | |
120 | |
121 discriminantOffset @12 :UInt32; | |
122 # If `discriminantCount` is non-zero, this is the offset of the union discriminant, in | |
123 # multiples of 16 bits. | |
124 | |
125 fields @13 :List(Field); | |
126 # Fields defined within this scope (either the struct's top-level fields, or the fields of | |
127 # a particular group; see `isGroup`). | |
128 # | |
129 # The fields are sorted by ordinal number, but note that because groups share the same | |
130 # ordinal space, the field's index in this list is not necessarily exactly its ordinal. | |
131 # On the other hand, the field's position in this list does remain the same even as the | |
132 # protocol evolves, since it is not possible to insert or remove an earlier ordinal. | |
133 # Therefore, for most use cases, if you want to identify a field by number, it may make the | |
134 # most sense to use the field's index in this list rather than its ordinal. | |
135 } | |
136 | |
137 enum :group { | |
138 enumerants@14 :List(Enumerant); | |
139 # Enumerants ordered by numeric value (ordinal). | |
140 } | |
141 | |
142 interface :group { | |
143 methods @15 :List(Method); | |
144 # Methods ordered by ordinal. | |
145 | |
146 superclasses @31 :List(Superclass); | |
147 # Superclasses of this interface. | |
148 } | |
149 | |
150 const :group { | |
151 type @16 :Type; | |
152 value @17 :Value; | |
153 } | |
154 | |
155 annotation :group { | |
156 type @18 :Type; | |
157 | |
158 targetsFile @19 :Bool; | |
159 targetsConst @20 :Bool; | |
160 targetsEnum @21 :Bool; | |
161 targetsEnumerant @22 :Bool; | |
162 targetsStruct @23 :Bool; | |
163 targetsField @24 :Bool; | |
164 targetsUnion @25 :Bool; | |
165 targetsGroup @26 :Bool; | |
166 targetsInterface @27 :Bool; | |
167 targetsMethod @28 :Bool; | |
168 targetsParam @29 :Bool; | |
169 targetsAnnotation @30 :Bool; | |
170 } | |
171 } | |
172 } | |
173 | |
174 struct Field { | |
175 # Schema for a field of a struct. | |
176 | |
177 name @0 :Text; | |
178 | |
179 codeOrder @1 :UInt16; | |
180 # Indicates where this member appeared in the code, relative to other members. | |
181 # Code ordering may have semantic relevance -- programmers tend to place related fields | |
182 # together. So, using code ordering makes sense in human-readable formats where ordering is | |
183 # otherwise irrelevant, like JSON. The values of codeOrder are tightly-packed, so the maximum | |
184 # value is count(members) - 1. Fields that are members of a union are only ordered relative to | |
185 # the other members of that union, so the maximum value there is count(union.members). | |
186 | |
187 annotations @2 :List(Annotation); | |
188 | |
189 const noDiscriminant :UInt16 = 0xffff; | |
190 | |
191 discriminantValue @3 :UInt16 = Field.noDiscriminant; | |
192 # If the field is in a union, this is the value which the union's discriminant should take when | |
193 # the field is active. If the field is not in a union, this is 0xffff. | |
194 | |
195 union { | |
196 slot :group { | |
197 # A regular, non-group, non-fixed-list field. | |
198 | |
199 offset @4 :UInt32; | |
200 # Offset, in units of the field's size, from the beginning of the section in which the field | |
201 # resides. E.g. for a UInt32 field, multiply this by 4 to get the byte offset from the | |
202 # beginning of the data section. | |
203 | |
204 type @5 :Type; | |
205 defaultValue @6 :Value; | |
206 | |
207 hadExplicitDefault @10 :Bool; | |
208 # Whether the default value was specified explicitly. Non-explicit default values are always | |
209 # zero or empty values. Usually, whether the default value was explicit shouldn't matter. | |
210 # The main use case for this flag is for structs representing method parameters: | |
211 # explicitly-defaulted parameters may be allowed to be omitted when calling the method. | |
212 } | |
213 | |
214 group :group { | |
215 # A group. | |
216 | |
217 typeId @7 :Id; | |
218 # The ID of the group's node. | |
219 } | |
220 } | |
221 | |
222 ordinal :union { | |
223 implicit @8 :Void; | |
224 explicit @9 :UInt16; | |
225 # The original ordinal number given to the field. You probably should NOT use this; if you need | |
226 # a numeric identifier for a field, use its position within the field array for its scope. | |
227 # The ordinal is given here mainly just so that the original schema text can be reproduced given | |
228 # the compiled version -- i.e. so that `capnp compile -ocapnp` can do its job. | |
229 } | |
230 } | |
231 | |
232 struct Enumerant { | |
233 # Schema for member of an enum. | |
234 | |
235 name @0 :Text; | |
236 | |
237 codeOrder @1 :UInt16; | |
238 # Specifies order in which the enumerants were declared in the code. | |
239 # Like Struct.Field.codeOrder. | |
240 | |
241 annotations @2 :List(Annotation); | |
242 } | |
243 | |
244 struct Superclass { | |
245 id @0 :Id; | |
246 brand @1 :Brand; | |
247 } | |
248 | |
249 struct Method { | |
250 # Schema for method of an interface. | |
251 | |
252 name @0 :Text; | |
253 | |
254 codeOrder @1 :UInt16; | |
255 # Specifies order in which the methods were declared in the code. | |
256 # Like Struct.Field.codeOrder. | |
257 | |
258 implicitParameters @7 :List(Node.Parameter); | |
259 # The parameters listed in [] (typically, type / generic parameters), whose bindings are intended | |
260 # to be inferred rather than specified explicitly, although not all languages support this. | |
261 | |
262 paramStructType @2 :Id; | |
263 # ID of the parameter struct type. If a named parameter list was specified in the method | |
264 # declaration (rather than a single struct parameter type) then a corresponding struct type is | |
265 # auto-generated. Such an auto-generated type will not be listed in the interface's | |
266 # `nestedNodes` and its `scopeId` will be zero -- it is completely detached from the namespace. | |
267 # (Awkwardly, it does of course inherit generic parameters from the method's scope, which makes | |
268 # this a situation where you can't just climb the scope chain to find where a particular | |
269 # generic parameter was introduced. Making the `scopeId` zero was a mistake.) | |
270 | |
271 paramBrand @5 :Brand; | |
272 # Brand of param struct type. | |
273 | |
274 resultStructType @3 :Id; | |
275 # ID of the return struct type; similar to `paramStructType`. | |
276 | |
277 resultBrand @6 :Brand; | |
278 # Brand of result struct type. | |
279 | |
280 annotations @4 :List(Annotation); | |
281 } | |
282 | |
283 struct Type { | |
284 # Represents a type expression. | |
285 | |
286 union { | |
287 # The ordinals intentionally match those of Value. | |
288 | |
289 void @0 :Void; | |
290 bool @1 :Void; | |
291 int8 @2 :Void; | |
292 int16 @3 :Void; | |
293 int32 @4 :Void; | |
294 int64 @5 :Void; | |
295 uint8 @6 :Void; | |
296 uint16 @7 :Void; | |
297 uint32 @8 :Void; | |
298 uint64 @9 :Void; | |
299 float32 @10 :Void; | |
300 float64 @11 :Void; | |
301 text @12 :Void; | |
302 data @13 :Void; | |
303 | |
304 list :group { | |
305 elementType @14 :Type; | |
306 } | |
307 | |
308 enum :group { | |
309 typeId @15 :Id; | |
310 brand @21 :Brand; | |
311 } | |
312 struct :group { | |
313 typeId @16 :Id; | |
314 brand @22 :Brand; | |
315 } | |
316 interface :group { | |
317 typeId @17 :Id; | |
318 brand @23 :Brand; | |
319 } | |
320 | |
321 anyPointer :union { | |
322 unconstrained :union { | |
323 # A regular AnyPointer. | |
324 # | |
325 # The name "unconstained" means as opposed to constraining it to match a type parameter. | |
326 # In retrospect this name is probably a poor choice given that it may still be constrained | |
327 # to be a struct, list, or capability. | |
328 | |
329 anyKind @18 :Void; # truly AnyPointer | |
330 struct @25 :Void; # AnyStruct | |
331 list @26 :Void; # AnyList | |
332 capability @27 :Void; # Capability | |
333 } | |
334 | |
335 parameter :group { | |
336 # This is actually a reference to a type parameter defined within this scope. | |
337 | |
338 scopeId @19 :Id; | |
339 # ID of the generic type whose parameter we're referencing. This should be a parent of the | |
340 # current scope. | |
341 | |
342 parameterIndex @20 :UInt16; | |
343 # Index of the parameter within the generic type's parameter list. | |
344 } | |
345 | |
346 implicitMethodParameter :group { | |
347 # This is actually a reference to an implicit (generic) parameter of a method. The only | |
348 # legal context for this type to appear is inside Method.paramBrand or Method.resultBrand. | |
349 | |
350 parameterIndex @24 :UInt16; | |
351 } | |
352 } | |
353 } | |
354 } | |
355 | |
356 struct Brand { | |
357 # Specifies bindings for parameters of generics. Since these bindings turn a generic into a | |
358 # non-generic, we call it the "brand". | |
359 | |
360 scopes @0 :List(Scope); | |
361 # For each of the target type and each of its parent scopes, a parameterization may be included | |
362 # in this list. If no parameterization is included for a particular relevant scope, then either | |
363 # that scope has no parameters or all parameters should be considered to be `AnyPointer`. | |
364 | |
365 struct Scope { | |
366 scopeId @0 :Id; | |
367 # ID of the scope to which these params apply. | |
368 | |
369 union { | |
370 bind @1 :List(Binding); | |
371 # List of parameter bindings. | |
372 | |
373 inherit @2 :Void; | |
374 # The place where this Brand appears is actually within this scope or a sub-scope, | |
375 # and the bindings for this scope should be inherited from the reference point. | |
376 } | |
377 } | |
378 | |
379 struct Binding { | |
380 union { | |
381 unbound @0 :Void; | |
382 type @1 :Type; | |
383 | |
384 # TODO(someday): Allow non-type parameters? Unsure if useful. | |
385 } | |
386 } | |
387 } | |
388 | |
389 struct Value { | |
390 # Represents a value, e.g. a field default value, constant value, or annotation value. | |
391 | |
392 union { | |
393 # The ordinals intentionally match those of Type. | |
394 | |
395 void @0 :Void; | |
396 bool @1 :Bool; | |
397 int8 @2 :Int8; | |
398 int16 @3 :Int16; | |
399 int32 @4 :Int32; | |
400 int64 @5 :Int64; | |
401 uint8 @6 :UInt8; | |
402 uint16 @7 :UInt16; | |
403 uint32 @8 :UInt32; | |
404 uint64 @9 :UInt64; | |
405 float32 @10 :Float32; | |
406 float64 @11 :Float64; | |
407 text @12 :Text; | |
408 data @13 :Data; | |
409 | |
410 list @14 :AnyPointer; | |
411 | |
412 enum @15 :UInt16; | |
413 struct @16 :AnyPointer; | |
414 | |
415 interface @17 :Void; | |
416 # The only interface value that can be represented statically is "null", whose methods always | |
417 # throw exceptions. | |
418 | |
419 anyPointer @18 :AnyPointer; | |
420 } | |
421 } | |
422 | |
423 struct Annotation { | |
424 # Describes an annotation applied to a declaration. Note AnnotationNode describes the | |
425 # annotation's declaration, while this describes a use of the annotation. | |
426 | |
427 id @0 :Id; | |
428 # ID of the annotation node. | |
429 | |
430 brand @2 :Brand; | |
431 # Brand of the annotation. | |
432 # | |
433 # Note that the annotation itself is not allowed to be parameterized, but its scope might be. | |
434 | |
435 value @1 :Value; | |
436 } | |
437 | |
438 enum ElementSize { | |
439 # Possible element sizes for encoded lists. These correspond exactly to the possible values of | |
440 # the 3-bit element size component of a list pointer. | |
441 | |
442 empty @0; # aka "void", but that's a keyword. | |
443 bit @1; | |
444 byte @2; | |
445 twoBytes @3; | |
446 fourBytes @4; | |
447 eightBytes @5; | |
448 pointer @6; | |
449 inlineComposite @7; | |
450 } | |
451 | |
452 struct CodeGeneratorRequest { | |
453 nodes @0 :List(Node); | |
454 # All nodes parsed by the compiler, including for the files on the command line and their | |
455 # imports. | |
456 | |
457 requestedFiles @1 :List(RequestedFile); | |
458 # Files which were listed on the command line. | |
459 | |
460 struct RequestedFile { | |
461 id @0 :Id; | |
462 # ID of the file. | |
463 | |
464 filename @1 :Text; | |
465 # Name of the file as it appeared on the command-line (minus the src-prefix). You may use | |
466 # this to decide where to write the output. | |
467 | |
468 imports @2 :List(Import); | |
469 # List of all imported paths seen in this file. | |
470 | |
471 struct Import { | |
472 id @0 :Id; | |
473 # ID of the imported file. | |
474 | |
475 name @1 :Text; | |
476 # Name which *this* file used to refer to the foreign file. This may be a relative name. | |
477 # This information is provided because it might be useful for code generation, e.g. to | |
478 # generate #include directives in C++. We don't put this in Node.file because this | |
479 # information is only meaningful at compile time anyway. | |
480 # | |
481 # (On Zooko's triangle, this is the import's petname according to the importing file.) | |
482 } | |
483 } | |
484 } |