Pass capn_ptr by value, better handling of tags
This commit is contained in:
parent
3a235fe8c6
commit
b8da11676a
10 changed files with 1236 additions and 438 deletions
29
compiler/capnpc-c.c
Normal file
29
compiler/capnpc-c.c
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
#include "schema.h"
|
||||
|
||||
|
||||
int main() {
|
||||
struct capn capn;
|
||||
struct CodeGeneratorRequest_ptr root;
|
||||
struct CodeGeneratorRequest req;
|
||||
int i;
|
||||
|
||||
if (capn_init_fp(&capn, stdin)) {
|
||||
fprintf(stderr, "failed to read schema on input\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
root.p = capn_root(&capn);
|
||||
read_CodeGeneratorRequest(&root, &req);
|
||||
|
||||
for (i = 0; i < req.nodes.size; i++) {
|
||||
struct Node_ptr p;
|
||||
struct Node n;
|
||||
p.p = capn_getp(&req.nodes, i);
|
||||
read_Node(&p, &n);
|
||||
|
||||
fprintf(stderr, "node %s id:%#llx scope:%#llx type:%d\n",
|
||||
n.displayName.str, n.id, n.scopeId, n.body_tag);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
222
compiler/schema.c
Normal file
222
compiler/schema.c
Normal file
|
|
@ -0,0 +1,222 @@
|
|||
#include "schema.h"
|
||||
|
||||
void read_Node(const struct Node_ptr *p, struct Node *s) {
|
||||
s->id = capn_read64(&p->p, 0);
|
||||
s->displayName = capn_get_text(&p->p, 0);
|
||||
s->scopeId = capn_read64(&p->p, 8);
|
||||
s->nestedNodes = capn_getp(&p->p, 1);
|
||||
s->annotations = capn_getp(&p->p, 2);
|
||||
s->body_tag = capn_read16(&p->p, 16);
|
||||
switch (s->body_tag) {
|
||||
case Node_fileNode:
|
||||
s->body.fileNode.p = capn_getp(&p->p, 3);
|
||||
break;
|
||||
case Node_structNode:
|
||||
s->body.structNode.p = capn_getp(&p->p, 3);
|
||||
break;
|
||||
case Node_enumNode:
|
||||
s->body.enumNode.p = capn_getp(&p->p, 3);
|
||||
break;
|
||||
case Node_interfaceNode:
|
||||
s->body.interfaceNode.p = capn_getp(&p->p, 3);
|
||||
break;
|
||||
case Node_constNode:
|
||||
s->body.constNode.p = capn_getp(&p->p, 3);
|
||||
break;
|
||||
case Node_annotationNode:
|
||||
s->body.annotationNode.p = capn_getp(&p->p, 3);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void read_Node_NestedNode(const struct Node_NestedNode_ptr *p, struct Node_NestedNode *s) {
|
||||
s->name = capn_get_text(&p->p, 0);
|
||||
s->id = capn_read64(&p->p, 0);
|
||||
}
|
||||
|
||||
void read_Type(const struct Type_ptr *p, struct Type *s) {
|
||||
s->body_tag = capn_read16(&p->p, 0);
|
||||
switch (s->body_tag) {
|
||||
case Type_listType:
|
||||
s->body.listType.p = capn_getp(&p->p, 0);
|
||||
break;
|
||||
case Type_enumType:
|
||||
s->body.enumType = capn_read64(&p->p, 0);
|
||||
break;
|
||||
case Type_structType:
|
||||
s->body.structType = capn_read64(&p->p, 0);
|
||||
break;
|
||||
case Type_interfaceType:
|
||||
s->body.interfaceType = capn_read64(&p->p, 0);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void read_Value(const struct Value_ptr *p, struct Value *s) {
|
||||
s->body_tag = capn_read16(&p->p, 0);
|
||||
switch (s->body_tag) {
|
||||
case Value_boolValue:
|
||||
s->body.boolValue = (capn_read8(&p->p, 8) & 1) != 0;
|
||||
break;
|
||||
case Value_int8Value:
|
||||
s->body.int8Value = (int8_t) capn_read8(&p->p, 8);
|
||||
break;
|
||||
case Value_int16Value:
|
||||
s->body.int16Value = (int16_t) capn_read16(&p->p, 8);
|
||||
break;
|
||||
case Value_int32Value:
|
||||
s->body.int32Value = (int32_t) capn_read32(&p->p, 8);
|
||||
break;
|
||||
case Value_int64Value:
|
||||
s->body.int64Value = (int64_t) capn_read64(&p->p, 8);
|
||||
break;
|
||||
case Value_uint8Value:
|
||||
s->body.uint8Value = capn_read8(&p->p, 8);
|
||||
break;
|
||||
case Value_uint16Value:
|
||||
s->body.uint16Value = capn_read16(&p->p, 8);
|
||||
break;
|
||||
case Value_uint32Value:
|
||||
s->body.uint32Value = capn_read32(&p->p, 8);
|
||||
break;
|
||||
case Value_uint64Value:
|
||||
s->body.uint64Value = capn_read64(&p->p, 8);
|
||||
break;
|
||||
case Value_float32Value:
|
||||
s->body.float32Value = capn_read_float(&p->p, 8, 0.0f);
|
||||
break;
|
||||
case Value_float64Value:
|
||||
s->body.float64Value = capn_read_double(&p->p, 8, 0.0);
|
||||
break;
|
||||
case Value_textValue:
|
||||
s->body.textValue = capn_get_text(&p->p, 0);
|
||||
break;
|
||||
case Value_dataValue:
|
||||
s->body.dataValue = capn_get_data(&p->p, 0);
|
||||
break;
|
||||
case Value_listValue:
|
||||
s->body.listValue = capn_getp(&p->p, 0);
|
||||
break;
|
||||
case Value_enumValue:
|
||||
s->body.enumValue = capn_read16(&p->p, 8);
|
||||
break;
|
||||
case Value_structValue:
|
||||
s->body.structValue = capn_getp(&p->p, 0);
|
||||
break;
|
||||
case Value_objectValue:
|
||||
s->body.objectValue = capn_getp(&p->p, 0);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void read_Annotation(const struct Annotation_ptr *p, struct Annotation *s) {
|
||||
s->id = capn_read64(&p->p, 0);
|
||||
s->value.p = capn_getp(&p->p, 0);
|
||||
}
|
||||
|
||||
void read_FileNode(const struct FileNode_ptr *p, struct FileNode *s) {
|
||||
s->imports = capn_getp(&p->p, 0);
|
||||
}
|
||||
|
||||
void read_FileNode_Import(const struct FileNode_Import_ptr *p, struct FileNode_Import *s) {
|
||||
s->id = capn_read64(&p->p, 0);
|
||||
s->name = capn_get_text(&p->p, 0);
|
||||
}
|
||||
|
||||
void read_StructNode(const struct StructNode_ptr *p, struct StructNode *s) {
|
||||
s->dataSectionWordSize = capn_read16(&p->p, 0);
|
||||
s->pointerSectionSize = capn_read16(&p->p, 2);
|
||||
s->preferredListEncoding = (enum ElementSize) capn_read16(&p->p, 4);
|
||||
s->members = capn_getp(&p->p, 0);
|
||||
}
|
||||
|
||||
void read_StructNode_Member(const struct StructNode_Member_ptr *p, struct StructNode_Member *s) {
|
||||
s->name = capn_get_text(&p->p, 0);
|
||||
s->ordinal = capn_read16(&p->p, 0);
|
||||
s->codeOrder = capn_read16(&p->p, 2);
|
||||
s->annotations = capn_getp(&p->p, 1);
|
||||
s->body_tag = (enum StructNode_Member_body) capn_read16(&p->p, 4);
|
||||
switch (s->body_tag) {
|
||||
case StructNode_Member_fieldMember:
|
||||
s->body.fieldMember.p = capn_getp(&p->p, 2);
|
||||
break;
|
||||
case StructNode_Member_unionMember:
|
||||
s->body.unionMember.p = capn_getp(&p->p, 2);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void read_StructNode_Field(const struct StructNode_Field_ptr *p, struct StructNode_Field *s) {
|
||||
s->offset = capn_read32(&p->p, 0);
|
||||
s->type.p = capn_getp(&p->p, 0);
|
||||
s->defaultValue.p = capn_getp(&p->p, 1);
|
||||
}
|
||||
|
||||
void read_StructNode_Union(const struct StructNode_Union_ptr *p, struct StructNode_Union *s) {
|
||||
s->discriminantOffset = capn_read32(&p->p, 0);
|
||||
s->members = capn_getp(&p->p, 0);
|
||||
}
|
||||
|
||||
void read_EnumNode(const struct EnumNode_ptr *p, struct EnumNode *s) {
|
||||
s->enumerants = capn_getp(&p->p, 0);
|
||||
}
|
||||
|
||||
void read_EnumNode_Enumerant(const struct EnumNode_Enumerant_ptr *p, struct EnumNode_Enumerant *s) {
|
||||
s->name = capn_get_text(&p->p, 0);
|
||||
s->codeOrder = capn_read16(&p->p, 0);
|
||||
s->annotations = capn_getp(&p->p, 1);
|
||||
}
|
||||
|
||||
void read_InterfaceNode(const struct InterfaceNode_ptr *p, struct InterfaceNode *s) {
|
||||
s->methods = capn_getp(&p->p, 0);
|
||||
}
|
||||
|
||||
void read_InterfaceNode_Method(const struct InterfaceNode_Method_ptr *p, struct InterfaceNode_Method *s) {
|
||||
s->name = capn_get_text(&p->p, 0);
|
||||
s->codeOrder = capn_read16(&p->p, 0);
|
||||
s->params = capn_getp(&p->p, 1);
|
||||
s->requiredParamCount = capn_read16(&p->p, 2);
|
||||
s->returnType.p = capn_getp(&p->p, 2);
|
||||
s->annotations = capn_getp(&p->p, 3);
|
||||
}
|
||||
|
||||
void read_InterfaceNode_Method_Param(const struct InterfaceNode_Method_Param_ptr *p, struct InterfaceNode_Method_Param *s) {
|
||||
s->name = capn_get_text(&p->p, 0);
|
||||
s->type.p = capn_getp(&p->p, 1);
|
||||
s->defaultValue.p = capn_getp(&p->p, 2);
|
||||
s->annotations = capn_getp(&p->p, 3);
|
||||
}
|
||||
|
||||
void read_ConstNode(const struct ConstNode_ptr *p, struct ConstNode *s) {
|
||||
s->type.p = capn_getp(&p->p, 0);
|
||||
s->value.p = capn_getp(&p->p, 1);
|
||||
}
|
||||
|
||||
void read_AnnotationNode(const struct AnnotationNode_ptr *p, struct AnnotationNode *s) {
|
||||
s->type.p = capn_getp(&p->p, 0);
|
||||
s->targetsFile = (capn_read8(&p->p, 0) & 1) != 0;
|
||||
s->targetsConst = (capn_read8(&p->p, 0) & 3) != 0;
|
||||
s->targetsEnum = (capn_read8(&p->p, 0) & 4) != 0;
|
||||
s->targetsEnumerant = (capn_read8(&p->p, 0) & 8) != 0;
|
||||
s->targetsStruct = (capn_read8(&p->p, 0) & 16) != 0;
|
||||
s->targetsField = (capn_read8(&p->p, 0) & 32) != 0;
|
||||
s->targetsUnion = (capn_read8(&p->p, 0) & 64) != 0;
|
||||
s->targetsInterface = (capn_read8(&p->p, 0) & 128) != 0;
|
||||
s->targetsMethod = (capn_read8(&p->p, 1) & 1) != 0;
|
||||
s->targetsParam = (capn_read8(&p->p, 1) & 2) != 0;
|
||||
s->targetsAnnotation = (capn_read8(&p->p, 1) & 4) != 0;
|
||||
}
|
||||
|
||||
void read_CodeGeneratorRequest(const struct CodeGeneratorRequest_ptr *p, struct CodeGeneratorRequest *s) {
|
||||
s->nodes = capn_getp(&p->p, 0);
|
||||
s->requestedFiles = capn_getp(&p->p, 1);
|
||||
}
|
||||
|
||||
316
compiler/schema.capnp
Normal file
316
compiler/schema.capnp
Normal file
|
|
@ -0,0 +1,316 @@
|
|||
# Copyright (c) 2013, Kenton Varda <temporal@gmail.com>
|
||||
# All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions are met:
|
||||
#
|
||||
# 1. Redistributions of source code must retain the above copyright notice, this
|
||||
# list of conditions and the following disclaimer.
|
||||
# 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
# this list of conditions and the following disclaimer in the documentation
|
||||
# and/or other materials provided with the distribution.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
||||
# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
@0xb471df2f45ca32c7;
|
||||
|
||||
# WARNING: This protocol is still subject to backwards-incompatible change.
|
||||
|
||||
using Id = UInt64;
|
||||
# The globally-unique ID of a file, type, or annotation.
|
||||
|
||||
struct Node {
|
||||
id @0 :Id;
|
||||
|
||||
displayName @1 :Text;
|
||||
# Name to present to humans to identify this Node. You should not attempt to parse this. Its
|
||||
# format could change. It is not guaranteed to be unique.
|
||||
#
|
||||
# (On Zooko's triangle, this is the node's nickname.)
|
||||
|
||||
scopeId @2 :Id = 0;
|
||||
# ID of the lexical parent node. Typically, the scope node will have a NestedNode pointing back
|
||||
# at this node, but robust code should avoid relying on this. `scopeId` is zero if the node has
|
||||
# no parent, which is normally only the case with files, but should be allowed for any kind of
|
||||
# node (in order to make runtime type generation easier).
|
||||
|
||||
nestedNodes @3 :List(NestedNode);
|
||||
# List of nodes nested within this node, along with the names under which they were declared.
|
||||
|
||||
struct NestedNode {
|
||||
name @0 :Text;
|
||||
# Unqualified symbol name. Unlike Node.name, this *can* be used programmatically.
|
||||
#
|
||||
# (On Zooko's triangle, this is the node's petname according to its parent scope.)
|
||||
|
||||
id @1 :Id;
|
||||
# ID of the nested node. Typically, the target node's scopeId points back to this node, but
|
||||
# robust code should avoid relying on this.
|
||||
}
|
||||
|
||||
annotations @4 :List(Annotation);
|
||||
# Annotations applied to this node.
|
||||
|
||||
body @5 union {
|
||||
# Info specific to each kind of node.
|
||||
|
||||
fileNode @6 :FileNode;
|
||||
structNode @7 :StructNode;
|
||||
enumNode @8 :EnumNode;
|
||||
interfaceNode @9 :InterfaceNode;
|
||||
constNode @10 :ConstNode;
|
||||
annotationNode @11 :AnnotationNode;
|
||||
}
|
||||
}
|
||||
|
||||
struct Type {
|
||||
# Represents a type expression.
|
||||
|
||||
body @0 union {
|
||||
voidType @1 :Void;
|
||||
boolType @2 :Void;
|
||||
int8Type @3 :Void;
|
||||
int16Type @4 :Void;
|
||||
int32Type @5 :Void;
|
||||
int64Type @6 :Void;
|
||||
uint8Type @7 :Void;
|
||||
uint16Type @8 :Void;
|
||||
uint32Type @9 :Void;
|
||||
uint64Type @10 :Void;
|
||||
float32Type @11 :Void;
|
||||
float64Type @12 :Void;
|
||||
textType @13 :Void;
|
||||
dataType @14 :Void;
|
||||
|
||||
listType @15 :Type; # Value = the element type.
|
||||
|
||||
enumType @16 :Id;
|
||||
structType @17 :Id;
|
||||
interfaceType @18 :Id;
|
||||
|
||||
objectType @19 :Void;
|
||||
}
|
||||
}
|
||||
|
||||
struct Value {
|
||||
# Represents a value, e.g. a field default value, constant value, or annotation value.
|
||||
|
||||
body @0 union {
|
||||
# Note ordinals 1 and 10 are intentionally swapped to improve union layout.
|
||||
voidValue @10 :Void;
|
||||
boolValue @2 :Bool;
|
||||
int8Value @3 :Int8;
|
||||
int16Value @4 :Int16;
|
||||
int32Value @5 :Int32;
|
||||
int64Value @6 :Int64;
|
||||
uint8Value @7 :UInt8;
|
||||
uint16Value @8 :UInt16;
|
||||
uint32Value @9 :UInt32;
|
||||
uint64Value @1 :UInt64;
|
||||
float32Value @11 :Float32;
|
||||
float64Value @12 :Float64;
|
||||
textValue @13 :Text;
|
||||
dataValue @14 :Data;
|
||||
|
||||
listValue @15 :Object;
|
||||
|
||||
enumValue @16 :UInt16;
|
||||
structValue @17 :Object;
|
||||
|
||||
interfaceValue @18 :Void;
|
||||
# The only interface value that can be represented statically is "null", whose methods always
|
||||
# throw exceptions.
|
||||
|
||||
objectValue @19 :Object;
|
||||
}
|
||||
}
|
||||
|
||||
struct Annotation {
|
||||
# Describes an annotation applied to a declaration. Note AnnotationNode describes the
|
||||
# annotation's declaration, while this describes a use of the annotation.
|
||||
|
||||
id @0 :Id;
|
||||
# ID of the annotation node.
|
||||
|
||||
value @1 :Value;
|
||||
}
|
||||
|
||||
struct FileNode {
|
||||
imports @0 :List(Import);
|
||||
struct Import {
|
||||
id @0 :Id;
|
||||
# ID of the imported file.
|
||||
|
||||
name @1 :Text;
|
||||
# Name which *this* file used to refer to the foreign file. This may be a relative name.
|
||||
# This information is provided because it might be useful for code generation, e.g. to generate
|
||||
# #include directives in C++.
|
||||
#
|
||||
# (On Zooko's triangle, this is the import's petname according to the importing file.)
|
||||
}
|
||||
}
|
||||
|
||||
enum ElementSize {
|
||||
# Possible element sizes for encoded lists. These correspond exactly to the possible values of
|
||||
# the 3-bit element size component of a list pointer.
|
||||
|
||||
empty @0; # aka "void", but that's a keyword.
|
||||
bit @1;
|
||||
byte @2;
|
||||
twoBytes @3;
|
||||
fourBytes @4;
|
||||
eightBytes @5;
|
||||
pointer @6;
|
||||
inlineComposite @7;
|
||||
}
|
||||
|
||||
struct StructNode {
|
||||
dataSectionWordSize @0 :UInt16;
|
||||
pointerSectionSize @1 :UInt16;
|
||||
|
||||
preferredListEncoding @2 :ElementSize;
|
||||
# The preferred element size to use when encoding a list of this struct. If this is anything
|
||||
# other than `inlineComposite` then the struct is one word or less in size and is a candidate for
|
||||
# list packing optimization.
|
||||
|
||||
members @3 :List(Member);
|
||||
# Top-level fields and unions of the struct, ordered by ordinal number, except that members of
|
||||
# unions are not included in this list (because they are nested inside the union declaration).
|
||||
# Note that this ordering is stable as the protocol evolves -- new members can only be added to
|
||||
# the end. So, when encoding a struct as tag/value pairs with numeric tags, it actually may make
|
||||
# sense to use the field's position in this list rather than the original ordinal number to
|
||||
# identify fields.
|
||||
|
||||
struct Member {
|
||||
name @0 :Text;
|
||||
|
||||
ordinal @1 :UInt16;
|
||||
|
||||
codeOrder @2 :UInt16;
|
||||
# Indicates where this member appeared in the code, relative to other members.
|
||||
# Code ordering may have semantic relevance -- programmers tend to place related fields
|
||||
# together. So, using code ordering makes sense in human-readable formats where ordering is
|
||||
# otherwise irrelevant, like JSON. The values of codeOrder are tightly-packed, so for unions
|
||||
# and non-union fields the maximum value of codeOrder is count(fields) + count(unions).
|
||||
# Fields that are members of a union are only ordered relative to the other members of that
|
||||
# union, so the maximum value there is count(union.fields).
|
||||
|
||||
annotations @3 :List(Annotation);
|
||||
|
||||
body @4 union {
|
||||
# More member types could be added over time. Consumers should skip those that they
|
||||
# don't understand.
|
||||
|
||||
fieldMember @5 :Field;
|
||||
unionMember @6 :Union;
|
||||
}
|
||||
}
|
||||
|
||||
struct Field {
|
||||
offset @0 :UInt32;
|
||||
# Offset, in units of the field's size, from the beginning of the section in which the field
|
||||
# resides. E.g. for a UInt32 field, multiply this by 4 to get the byte offset from the
|
||||
# beginning of the data section.
|
||||
|
||||
type @1 :Type;
|
||||
defaultValue @2 :Value;
|
||||
}
|
||||
|
||||
struct Union {
|
||||
discriminantOffset @0 :UInt32;
|
||||
# Offset of the union's 16-bit discriminant within the struct's data section, in 16-bit units.
|
||||
|
||||
members @1 :List(Member);
|
||||
# Fields of this union, ordered by ordinal. Currently all members are fields, but
|
||||
# consumers should skip member types that they don't understand. The first member in this list
|
||||
# gets discriminant value zero, the next gets one, and so on.
|
||||
#
|
||||
# TODO(soon): Discriminant zero should be reserved to mean "unset", unless the first field in
|
||||
# the union actually predates the union (it was retroactively unionized), in which case it
|
||||
# gets discriminant zero.
|
||||
}
|
||||
}
|
||||
|
||||
struct EnumNode {
|
||||
enumerants @0 :List(Enumerant);
|
||||
# Enumerants, in order by ordinal.
|
||||
|
||||
struct Enumerant {
|
||||
name @0 :Text;
|
||||
|
||||
codeOrder @1 :UInt16;
|
||||
# Specifies order in which the enumerants were declared in the code.
|
||||
# Like Struct.Field.codeOrder.
|
||||
|
||||
annotations @2 :List(Annotation);
|
||||
}
|
||||
}
|
||||
|
||||
struct InterfaceNode {
|
||||
methods @0 :List(Method);
|
||||
# Methods, in order by ordinal.
|
||||
|
||||
struct Method {
|
||||
name @0 :Text;
|
||||
|
||||
codeOrder @1 :UInt16;
|
||||
# Specifies order in which the methods were declared in the code.
|
||||
# Like Struct.Field.codeOrder.
|
||||
|
||||
params @2 :List(Param);
|
||||
struct Param {
|
||||
name @0 :Text;
|
||||
type @1 :Type;
|
||||
defaultValue @2 :Value;
|
||||
annotations @3 :List(Annotation);
|
||||
}
|
||||
|
||||
requiredParamCount @3 :UInt16;
|
||||
# One plus the index of the last parameter that has no default value. In languages where
|
||||
# method calls look like function calls, this is the minimum number of parameters that must
|
||||
# always be specified, while subsequent parameters are optional.
|
||||
|
||||
returnType @4 :Type;
|
||||
|
||||
annotations @5 :List(Annotation);
|
||||
}
|
||||
}
|
||||
|
||||
struct ConstNode {
|
||||
type @0 :Type;
|
||||
value @1 :Value;
|
||||
}
|
||||
|
||||
struct AnnotationNode {
|
||||
type @0 :Type;
|
||||
|
||||
targetsFile @1 :Bool;
|
||||
targetsConst @2 :Bool;
|
||||
targetsEnum @3 :Bool;
|
||||
targetsEnumerant @4 :Bool;
|
||||
targetsStruct @5 :Bool;
|
||||
targetsField @6 :Bool;
|
||||
targetsUnion @7 :Bool;
|
||||
targetsInterface @8 :Bool;
|
||||
targetsMethod @9 :Bool;
|
||||
targetsParam @10 :Bool;
|
||||
targetsAnnotation @11 :Bool;
|
||||
}
|
||||
|
||||
struct CodeGeneratorRequest {
|
||||
nodes @0 :List(Node);
|
||||
# All nodes parsed by the compiler, including for the files on the command line and their
|
||||
# imports.
|
||||
|
||||
requestedFiles @1 :List(Id);
|
||||
# IDs of files which were listed on the command line.
|
||||
}
|
||||
266
compiler/schema.h
Normal file
266
compiler/schema.h
Normal file
|
|
@ -0,0 +1,266 @@
|
|||
/* vim: set sw=8 ts=8 sts=8 noet: */
|
||||
#include <capn.h>
|
||||
|
||||
struct Node_ptr {struct capn_ptr p;};
|
||||
struct Node_NestedNode_ptr {struct capn_ptr p;};
|
||||
struct Type_ptr {struct capn_ptr p;};
|
||||
struct Value_ptr {struct capn_ptr p;};
|
||||
struct Annotation_ptr {struct capn_ptr p;};
|
||||
struct FileNode_ptr {struct capn_ptr p;};
|
||||
struct FileNode_Import_ptr {struct capn_ptr p;};
|
||||
struct StructNode_ptr {struct capn_ptr p;};
|
||||
struct StructNode_Member_ptr {struct capn_ptr p;};
|
||||
struct StructNode_Field_ptr {struct capn_ptr p;};
|
||||
struct StructNode_Union_ptr {struct capn_ptr p;};
|
||||
struct EnumNode_ptr {struct capn_ptr p;};
|
||||
struct EnumNode_Enumerant_ptr {struct capn_ptr p;};
|
||||
struct InterfaceNode_ptr {struct capn_ptr p;};
|
||||
struct InterfaceNode_Method_ptr {struct capn_ptr p;};
|
||||
struct InterfaceNode_Method_Param_ptr {struct capn_ptr p;};
|
||||
struct ConstNode_ptr {struct capn_ptr p;};
|
||||
struct AnnotationNode_ptr {struct capn_ptr p;};
|
||||
struct CodeGeneratorRequest_ptr {struct capn_ptr p;};
|
||||
|
||||
enum Node_body {
|
||||
Node_fileNode = 0,
|
||||
Node_structNode = 1,
|
||||
Node_enumNode = 2,
|
||||
Node_interfaceNode = 3,
|
||||
Node_constNode = 4,
|
||||
Node_annotationNode = 5,
|
||||
};
|
||||
|
||||
struct Node {
|
||||
uint64_t id;
|
||||
struct capn_text displayName;
|
||||
uint64_t scopeId;
|
||||
struct capn_ptr nestedNodes; /* List(Node_NestedNode) */
|
||||
struct capn_ptr annotations; /* List(Annotation) */
|
||||
enum Node_body body_tag;
|
||||
union {
|
||||
struct FileNode_ptr fileNode;
|
||||
struct StructNode_ptr structNode;
|
||||
struct EnumNode_ptr enumNode;
|
||||
struct InterfaceNode_ptr interfaceNode;
|
||||
struct ConstNode_ptr constNode;
|
||||
struct AnnotationNode_ptr annotationNode;
|
||||
} body;
|
||||
};
|
||||
|
||||
struct Node_NestedNode {
|
||||
struct capn_text name;
|
||||
uint64_t id;
|
||||
};
|
||||
|
||||
enum Type_body {
|
||||
Type_voidType = 0,
|
||||
Type_boolType = 1,
|
||||
Type_int8Type = 2,
|
||||
Type_int16Type = 3,
|
||||
Type_int32Type = 4,
|
||||
Type_int64Type = 5,
|
||||
Type_uint8Type = 6,
|
||||
Type_uint16Type = 7,
|
||||
Type_uint32Type = 8,
|
||||
Type_uint64Type = 9,
|
||||
Type_float32Type = 10,
|
||||
Type_float64Type = 11,
|
||||
Type_textType = 12,
|
||||
Type_dataType = 13,
|
||||
Type_listType = 14,
|
||||
Type_enumType = 15,
|
||||
Type_structType = 16,
|
||||
Type_interfaceType = 17,
|
||||
Type_objectType = 18,
|
||||
};
|
||||
|
||||
struct Type {
|
||||
enum Type_body body_tag;
|
||||
union {
|
||||
struct Type_ptr listType;
|
||||
uint64_t enumType;
|
||||
uint64_t structType;
|
||||
uint64_t interfaceType;
|
||||
} body;
|
||||
};
|
||||
|
||||
enum Value_body {
|
||||
Value_voidValue = 9,
|
||||
Value_boolValue = 1,
|
||||
Value_int8Value = 2,
|
||||
Value_int16Value = 3,
|
||||
Value_int32Value = 4,
|
||||
Value_int64Value = 5,
|
||||
Value_uint8Value = 6,
|
||||
Value_uint16Value = 7,
|
||||
Value_uint32Value = 8,
|
||||
Value_uint64Value = 0,
|
||||
Value_float32Value = 10,
|
||||
Value_float64Value = 11,
|
||||
Value_textValue = 12,
|
||||
Value_dataValue = 13,
|
||||
Value_listValue = 14,
|
||||
Value_enumValue = 15,
|
||||
Value_structValue = 16,
|
||||
Value_interfaceValue = 17,
|
||||
Value_objectValue = 18,
|
||||
};
|
||||
|
||||
struct Value {
|
||||
enum Value_body body_tag;
|
||||
union {
|
||||
unsigned int boolValue : 1;
|
||||
int8_t int8Value;
|
||||
int16_t int16Value;
|
||||
int32_t int32Value;
|
||||
int64_t int64Value;
|
||||
uint8_t uint8Value;
|
||||
uint16_t uint16Value;
|
||||
uint32_t uint32Value;
|
||||
uint64_t uint64Value;
|
||||
float float32Value;
|
||||
double float64Value;
|
||||
struct capn_text textValue;
|
||||
struct capn_data dataValue;
|
||||
struct capn_ptr listValue;
|
||||
uint16_t enumValue;
|
||||
struct capn_ptr structValue;
|
||||
struct capn_ptr objectValue;
|
||||
} body;
|
||||
};
|
||||
|
||||
struct Annotation {
|
||||
uint64_t id;
|
||||
struct Value_ptr value;
|
||||
};
|
||||
|
||||
struct FileNode {
|
||||
struct capn_ptr imports; /* List(FileNode_Import) */
|
||||
};
|
||||
|
||||
struct FileNode_Import {
|
||||
uint64_t id;
|
||||
struct capn_text name;
|
||||
};
|
||||
|
||||
enum ElementSize {
|
||||
ElementSize_empty = 0,
|
||||
ElementSize_bit = 1,
|
||||
ElementSize_byte = 2,
|
||||
ElementSize_twoBytes = 3,
|
||||
ElementSize_fourBytes = 4,
|
||||
ElementSize_eightBytes = 5,
|
||||
ElementSize_pointer = 6,
|
||||
ElementSize_inlineComposite = 7,
|
||||
};
|
||||
|
||||
struct StructNode {
|
||||
uint16_t dataSectionWordSize;
|
||||
uint16_t pointerSectionSize;
|
||||
enum ElementSize preferredListEncoding;
|
||||
struct capn_ptr members; /* List(StructNode_Member) */
|
||||
};
|
||||
|
||||
enum StructNode_Member_body {
|
||||
StructNode_Member_fieldMember = 0,
|
||||
StructNode_Member_unionMember = 1,
|
||||
};
|
||||
|
||||
struct StructNode_Member {
|
||||
struct capn_text name;
|
||||
uint16_t ordinal;
|
||||
uint16_t codeOrder;
|
||||
struct capn_ptr annotations; /* List(Annotation) */
|
||||
enum StructNode_Member_body body_tag;
|
||||
union {
|
||||
struct StructNode_Field_ptr fieldMember;
|
||||
struct StructNode_Field_ptr unionMember;
|
||||
} body;
|
||||
};
|
||||
|
||||
struct StructNode_Field {
|
||||
uint32_t offset;
|
||||
struct Type_ptr type;
|
||||
struct Value_ptr defaultValue;
|
||||
};
|
||||
|
||||
struct StructNode_Union {
|
||||
uint32_t discriminantOffset;
|
||||
struct capn_ptr members; /* List(StructNode_Member) */
|
||||
};
|
||||
|
||||
struct EnumNode {
|
||||
struct capn_ptr enumerants; /* List(EnumNode_Enumerant) */
|
||||
};
|
||||
|
||||
struct EnumNode_Enumerant {
|
||||
struct capn_text name;
|
||||
uint16_t codeOrder;
|
||||
struct capn_ptr annotations; /* List(Annotation) */
|
||||
};
|
||||
|
||||
struct InterfaceNode {
|
||||
struct capn_ptr methods; /* List(InterfaceNode_Method) */
|
||||
};
|
||||
|
||||
struct InterfaceNode_Method {
|
||||
struct capn_text name;
|
||||
uint16_t codeOrder;
|
||||
struct capn_ptr params; /* List(InterfaceNode_Method_Param) */
|
||||
uint16_t requiredParamCount;
|
||||
struct Type_ptr returnType;
|
||||
struct capn_ptr annotations; /* List(Annotation) */
|
||||
};
|
||||
|
||||
struct InterfaceNode_Method_Param {
|
||||
struct capn_text name;
|
||||
struct Type_ptr type;
|
||||
struct Value_ptr defaultValue;
|
||||
struct capn_ptr annotations; /* List(Annotation) */
|
||||
};
|
||||
|
||||
struct ConstNode {
|
||||
struct Type_ptr type;
|
||||
struct Value_ptr value;
|
||||
};
|
||||
|
||||
struct AnnotationNode {
|
||||
struct Type_ptr type;
|
||||
unsigned int targetsFile : 1;
|
||||
unsigned int targetsConst : 1;
|
||||
unsigned int targetsEnum : 1;
|
||||
unsigned int targetsEnumerant : 1;
|
||||
unsigned int targetsStruct : 1;
|
||||
unsigned int targetsField : 1;
|
||||
unsigned int targetsUnion : 1;
|
||||
unsigned int targetsInterface : 1;
|
||||
unsigned int targetsMethod : 1;
|
||||
unsigned int targetsParam : 1;
|
||||
unsigned int targetsAnnotation : 1;
|
||||
};
|
||||
|
||||
struct CodeGeneratorRequest {
|
||||
struct capn_ptr nodes; /* List(Node) */
|
||||
struct capn_ptr requestedFiles; /* List(uint64_t) */
|
||||
};
|
||||
|
||||
void read_Node(const struct Node_ptr*, struct Node*);
|
||||
void read_Node_NestedNode(const struct Node_NestedNode_ptr*, struct Node_NestedNode*);
|
||||
void read_Type(const struct Type_ptr*, struct Type*);
|
||||
void read_Value(const struct Value_ptr*, struct Value*);
|
||||
void read_Annotation(const struct Annotation_ptr*, struct Annotation*);
|
||||
void read_FileNode(const struct FileNode_ptr*, struct FileNode*);
|
||||
void read_FileNode_Import(const struct FileNode_Import_ptr*, struct FileNode_Import*);
|
||||
void read_StructNode(const struct StructNode_ptr*, struct StructNode*);
|
||||
void read_StructNode_Member(const struct StructNode_Member_ptr*, struct StructNode_Member*);
|
||||
void read_StructNode_Field(const struct StructNode_Field_ptr*, struct StructNode_Field*);
|
||||
void read_StructNode_Union(const struct StructNode_Union_ptr*, struct StructNode_Union*);
|
||||
void read_EnumNode(const struct EnumNode_ptr*, struct EnumNode*);
|
||||
void read_EnumNode_Enumerant(const struct EnumNode_Enumerant_ptr*, struct EnumNode_Enumerant*);
|
||||
void read_InterfaceNode(const struct InterfaceNode_ptr*, struct InterfaceNode*);
|
||||
void read_InterfaceNode_Method(const struct InterfaceNode_Method_ptr*, struct InterfaceNode_Method*);
|
||||
void read_InterfaceNode_Method_Param(const struct InterfaceNode_Method_Param_ptr*, struct InterfaceNode_Method_Param*);
|
||||
void read_ConstNode(const struct ConstNode_ptr*, struct ConstNode*);
|
||||
void read_AnnotationNode(const struct AnnotationNode_ptr*, struct AnnotationNode*);
|
||||
void read_CodeGeneratorRequest(const struct CodeGeneratorRequest_ptr*, struct CodeGeneratorRequest*);
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue