annotate win64-msvc/include/capnp/schema.capnp @ 58:eab3b14ddc95

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