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