annotate osx/include/capnp/schema.capnp @ 135:38d1c0e7850b

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