annotate osx/include/capnp/schema.capnp @ 83:ae30d91d2ffe

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