diff --git a/.gitignore b/.gitignore index d1e0061..d70a5d5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ -/*.o -/*.so +*.o +*.so /capn-test +/capnpc-c diff --git a/Makefile b/Makefile index 70dd031..faa127c 100644 --- a/Makefile +++ b/Makefile @@ -3,7 +3,7 @@ LDFLAGS=-g -Wall -Werror -fPIC CFLAGS=-g -Wall -Werror -fPIC -I. -Wno-unused-function -ansi -pedantic -all: capn.so test +all: capn.so capnpc-c test clean: rm -f *.o *.so capnpc-c compiler/*.o @@ -14,11 +14,14 @@ clean: capn.so: capn-malloc.o capn-stream.o capn.o $(CC) -shared $(LDFLAGS) $^ -o $@ +capnpc-c: compiler/capnpc-c.o compiler/schema.o capn.so + $(CC) $(LDFLAGS) $^ -o $@ + test: capn-test ./capn-test %-test.o: %-test.cpp *.h *.c *.inc - $(CXX) `gtest-config --cppflags --cxxflags` -o $@ -c $< + $(CXX) -g -Wall -Werror -I. `gtest-config --cppflags --cxxflags` -o $@ -c $< -capn-test: capn-test.o capn-stream-test.o - $(CXX) `gtest-config --ldflags --libs` -o $@ $^ +capn-test: capn-test.o capn-stream-test.o compiler/schema-test.o compiler/schema.o + $(CXX) -g -Wall -Werror -I. `gtest-config --ldflags --libs` -o $@ $^ diff --git a/capn.c b/capn.c index a63b6c0..f428bca 100644 --- a/capn.c +++ b/capn.c @@ -38,7 +38,7 @@ static int min(int a, int b) { return (a < b) ? a : b; } #define CAPN_LITTLE 0 #endif -static struct capn_tree *insert_rebalance(struct capn_tree *root, struct capn_tree *n) { +struct capn_tree *capn_tree_insert(struct capn_tree *root, struct capn_tree *n) { n->red = 1; n->link[0] = n->link[1] = NULL; @@ -159,7 +159,7 @@ void capn_append_segment(struct capn *c, struct capn_segment *s) { } c->lastseg = s; - c->segtree = insert_rebalance(c->segtree, &s->hdr); + c->segtree = capn_tree_insert(c->segtree, &s->hdr); } static char *new_data(struct capn *c, int sz, struct capn_segment **ps) { @@ -220,7 +220,7 @@ static struct capn_segment *lookup_segment(struct capn* c, struct capn_segment * c->seglist = s; s->hdr.parent = &y->hdr; *x = &s->hdr; - c->segtree = insert_rebalance(c->segtree, &s->hdr); + c->segtree = capn_tree_insert(c->segtree, &s->hdr); } else { c->segnum = id; capn_append_segment(c, s); diff --git a/capn.h b/capn.h index c219c1e..204f200 100644 --- a/capn.h +++ b/capn.h @@ -198,6 +198,7 @@ CAPN_INLINE int capn_write16(capn_ptr p, int off, uint16_t val); CAPN_INLINE int capn_write32(capn_ptr p, int off, uint32_t val); CAPN_INLINE int capn_write64(capn_ptr p, int off, uint64_t val); +struct capn_tree *capn_tree_insert(struct capn_tree *root, struct capn_tree *n); /* capn_init_malloc inits the capn struct with a create function which * allocates segments on the heap using malloc diff --git a/compiler/capnpc-c.c b/compiler/capnpc-c.c index 4a39386..0113e02 100644 --- a/compiler/capnpc-c.c +++ b/compiler/capnpc-c.c @@ -1,28 +1,90 @@ #include "schema.h" +struct scope { + struct capn_tree hdr; + struct scope *enclosing; + capn_text name; + uint64_t id; +}; + +struct scope *find_scope(struct scope *s, uint64_t id) { + while (s && s->id != id) { + s = (struct scope*) s->hdr.link[s->id < id]; + } + return s; +} + +struct capn_tree *insert_scope(struct capn_tree *root, struct scope *s) { + struct capn_tree **x = &root; + while (*x) { + s->hdr.parent = *x; + x = &(*x)->link[((struct scope*)*x)->id < s->id]; + } + *x = &s->hdr; + return capn_tree_insert(root, &s->hdr); +} int main() { struct capn capn; - struct CodeGeneratorRequest_ptr root; + CodeGeneratorRequest_ptr root; struct CodeGeneratorRequest req; - int i; + int i, j; - if (capn_init_fp(&capn, stdin)) { - fprintf(stderr, "failed to read schema on input\n"); + if (capn_init_fp(&capn, stdin, 0)) { + fprintf(stderr, "failed to read schema from stdin\n"); return -1; } - root.p = capn_root(&capn); - read_CodeGeneratorRequest(&root, &req); + root.p = capn_get_root(&capn); + read_CodeGeneratorRequest(&req, root); - 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); + for (i = 0; i < req.nodes.p.size; i++) { + struct Node N; + struct FileNode F; + struct StructNode S; + struct EnumNode E; + struct InterfaceNode I; + struct ConstNode C; + struct AnnotationNode A; + get_Node(&N, req.nodes, i); fprintf(stderr, "node %s id:%#llx scope:%#llx type:%d\n", - n.displayName.str, n.id, n.scopeId, n.body_tag); + N.displayName.str, N.id, N.scopeId, N.body_tag); + + switch (N.body_tag) { + case Node_fileNode: + read_FileNode(&F, N.body.fileNode); + for (j = 0; j < F.imports.p.size; j++) { + struct FileNode_Import fi; + get_FileNode_Import(&fi, F.imports, j); + fprintf(stderr, "\timport %#llx %s\n", fi.id, fi.name.str); + } + break; + case Node_structNode: + read_StructNode(&S, N.body.structNode); + fprintf(stderr, "\tstruct %d %d %d\n", + S.dataSectionWordSize, S.pointerSectionSize, S.preferredListEncoding); + for (j = 0; j < S.members.p.size; j++) { + } + break; + case Node_enumNode: + read_EnumNode(&E, N.body.enumNode); + for (j = 0; j < E.enumerants.p.size; j++) { + struct EnumNode_Enumerant ee; + get_EnumNode_Enumerant(&ee, E.enumerants, j); + fprintf(stderr, "\tenum %d %s %d\n", j, ee.name.str, ee.codeOrder); + } + break; + case Node_interfaceNode: + read_InterfaceNode(&I, N.body.interfaceNode); + break; + case Node_constNode: + read_ConstNode(&C, N.body.constNode); + break; + case Node_annotationNode: + read_AnnotationNode(&A, N.body.annotationNode); + break; + } } return 0; diff --git a/compiler/schema-test.cpp b/compiler/schema-test.cpp new file mode 100644 index 0000000..c4259e8 --- /dev/null +++ b/compiler/schema-test.cpp @@ -0,0 +1,195 @@ +#include "schema.h" +#include + +static const uint8_t simple_schema[] = { + 0x00, 0x00, 0x00, 0x00, 0x5f, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, + 0x05, 0x00, 0x00, 0x00, 0x77, 0x00, 0x00, 0x00, 0x6d, 0x05, 0x00, 0x00, 0x0d, 0x00, 0x00, 0x00, + 0x08, 0x00, 0x00, 0x00, 0x03, 0x00, 0x04, 0x00, 0x73, 0x4d, 0xd2, 0x75, 0x6b, 0xff, 0xe1, 0xbe, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x29, 0x00, 0x00, 0x00, 0xb2, 0x00, 0x00, 0x00, 0x31, 0x00, 0x00, 0x00, 0x17, 0x00, 0x00, 0x00, + 0x3d, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, + 0x09, 0xb7, 0x71, 0x68, 0xc7, 0x34, 0xc8, 0xff, 0x73, 0x4d, 0xd2, 0x75, 0x6b, 0xff, 0xe1, 0xbe, + 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x35, 0x00, 0x00, 0x00, 0xd2, 0x00, 0x00, 0x00, + 0x41, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x41, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, + 0x40, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x63, 0x6f, 0x6d, 0x70, 0x69, 0x6c, 0x65, 0x72, + 0x2f, 0x73, 0x69, 0x6d, 0x70, 0x6c, 0x65, 0x2e, 0x63, 0x61, 0x70, 0x6e, 0x70, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x09, 0xb7, 0x71, 0x68, 0xc7, 0x34, 0xc8, 0xff, + 0x01, 0x00, 0x00, 0x00, 0x22, 0x00, 0x00, 0x00, 0x46, 0x6f, 0x6f, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x63, 0x6f, 0x6d, 0x70, 0x69, 0x6c, 0x65, 0x72, + 0x2f, 0x73, 0x69, 0x6d, 0x70, 0x6c, 0x65, 0x2e, 0x63, 0x61, 0x70, 0x6e, 0x70, 0x3a, 0x46, 0x6f, + 0x6f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x02, 0x00, 0x01, 0x00, 0x07, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x27, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x03, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00, 0x2a, 0x00, 0x00, 0x00, + 0x09, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, + 0x62, 0x6f, 0x64, 0x79, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x67, 0x02, 0x00, 0x00, + 0x4c, 0x00, 0x00, 0x00, 0x01, 0x00, 0x03, 0x00, 0x01, 0x00, 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x29, 0x01, 0x00, 0x00, 0x62, 0x00, 0x00, 0x00, 0x2d, 0x01, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, + 0x2c, 0x01, 0x00, 0x00, 0x01, 0x00, 0x02, 0x00, 0x02, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x49, 0x01, 0x00, 0x00, 0x52, 0x00, 0x00, 0x00, 0x4d, 0x01, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, + 0x4c, 0x01, 0x00, 0x00, 0x01, 0x00, 0x02, 0x00, 0x03, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x69, 0x01, 0x00, 0x00, 0x52, 0x00, 0x00, 0x00, 0x6d, 0x01, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, + 0x6c, 0x01, 0x00, 0x00, 0x01, 0x00, 0x02, 0x00, 0x04, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x89, 0x01, 0x00, 0x00, 0x5a, 0x00, 0x00, 0x00, 0x8d, 0x01, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, + 0x8c, 0x01, 0x00, 0x00, 0x01, 0x00, 0x02, 0x00, 0x05, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xa9, 0x01, 0x00, 0x00, 0x5a, 0x00, 0x00, 0x00, 0xad, 0x01, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, + 0xac, 0x01, 0x00, 0x00, 0x01, 0x00, 0x02, 0x00, 0x06, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xc9, 0x01, 0x00, 0x00, 0x5a, 0x00, 0x00, 0x00, 0xcd, 0x01, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, + 0xcc, 0x01, 0x00, 0x00, 0x01, 0x00, 0x02, 0x00, 0x07, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xe9, 0x01, 0x00, 0x00, 0x5a, 0x00, 0x00, 0x00, 0xed, 0x01, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, + 0xec, 0x01, 0x00, 0x00, 0x01, 0x00, 0x02, 0x00, 0x08, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x09, 0x02, 0x00, 0x00, 0x62, 0x00, 0x00, 0x00, 0x0d, 0x02, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, + 0x0c, 0x02, 0x00, 0x00, 0x01, 0x00, 0x02, 0x00, 0x09, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x29, 0x02, 0x00, 0x00, 0x62, 0x00, 0x00, 0x00, 0x2d, 0x02, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, + 0x2c, 0x02, 0x00, 0x00, 0x01, 0x00, 0x02, 0x00, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x49, 0x02, 0x00, 0x00, 0x52, 0x00, 0x00, 0x00, 0x4d, 0x02, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, + 0x4c, 0x02, 0x00, 0x00, 0x01, 0x00, 0x02, 0x00, 0x0b, 0x00, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x69, 0x02, 0x00, 0x00, 0x6a, 0x00, 0x00, 0x00, 0x6d, 0x02, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, + 0x6c, 0x02, 0x00, 0x00, 0x01, 0x00, 0x02, 0x00, 0x0c, 0x00, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x89, 0x02, 0x00, 0x00, 0x6a, 0x00, 0x00, 0x00, 0x8d, 0x02, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, + 0x8c, 0x02, 0x00, 0x00, 0x01, 0x00, 0x02, 0x00, 0x0d, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xa9, 0x02, 0x00, 0x00, 0x52, 0x00, 0x00, 0x00, 0xad, 0x02, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, + 0xac, 0x02, 0x00, 0x00, 0x01, 0x00, 0x02, 0x00, 0x0e, 0x00, 0x0d, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xc9, 0x02, 0x00, 0x00, 0x52, 0x00, 0x00, 0x00, 0xcd, 0x02, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, + 0xcc, 0x02, 0x00, 0x00, 0x01, 0x00, 0x02, 0x00, 0x0f, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xe9, 0x02, 0x00, 0x00, 0x52, 0x00, 0x00, 0x00, 0xed, 0x02, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, + 0xec, 0x02, 0x00, 0x00, 0x01, 0x00, 0x02, 0x00, 0x10, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x09, 0x03, 0x00, 0x00, 0x52, 0x00, 0x00, 0x00, 0x0d, 0x03, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, + 0x0c, 0x03, 0x00, 0x00, 0x01, 0x00, 0x02, 0x00, 0x11, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x29, 0x03, 0x00, 0x00, 0x62, 0x00, 0x00, 0x00, 0x2d, 0x03, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, + 0x2c, 0x03, 0x00, 0x00, 0x01, 0x00, 0x02, 0x00, 0x12, 0x00, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x49, 0x03, 0x00, 0x00, 0x7a, 0x00, 0x00, 0x00, 0x4d, 0x03, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, + 0x4c, 0x03, 0x00, 0x00, 0x01, 0x00, 0x02, 0x00, 0x13, 0x00, 0x12, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x69, 0x03, 0x00, 0x00, 0x62, 0x00, 0x00, 0x00, 0x6d, 0x03, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, + 0x6c, 0x03, 0x00, 0x00, 0x01, 0x00, 0x02, 0x00, 0x75, 0x69, 0x6e, 0x74, 0x36, 0x34, 0x56, 0x61, + 0x6c, 0x75, 0x65, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x02, 0x00, 0x01, 0x00, + 0x0c, 0x00, 0x00, 0x00, 0x02, 0x00, 0x01, 0x00, 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x62, 0x6f, 0x6f, 0x6c, 0x56, 0x61, 0x6c, 0x75, + 0x65, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, + 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x02, 0x00, 0x01, 0x00, + 0x0c, 0x00, 0x00, 0x00, 0x02, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x69, 0x6e, 0x74, 0x38, 0x56, 0x61, 0x6c, 0x75, + 0x65, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, + 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x02, 0x00, 0x01, 0x00, + 0x0c, 0x00, 0x00, 0x00, 0x02, 0x00, 0x01, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x69, 0x6e, 0x74, 0x31, 0x36, 0x56, 0x61, 0x6c, + 0x75, 0x65, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x02, 0x00, 0x01, 0x00, + 0x0c, 0x00, 0x00, 0x00, 0x02, 0x00, 0x01, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x69, 0x6e, 0x74, 0x33, 0x32, 0x56, 0x61, 0x6c, + 0x75, 0x65, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, + 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x02, 0x00, 0x01, 0x00, + 0x0c, 0x00, 0x00, 0x00, 0x02, 0x00, 0x01, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x69, 0x6e, 0x74, 0x36, 0x34, 0x56, 0x61, 0x6c, + 0x75, 0x65, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x02, 0x00, 0x01, 0x00, + 0x0c, 0x00, 0x00, 0x00, 0x02, 0x00, 0x01, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x75, 0x69, 0x6e, 0x74, 0x38, 0x56, 0x61, 0x6c, + 0x75, 0x65, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, + 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x02, 0x00, 0x01, 0x00, + 0x0c, 0x00, 0x00, 0x00, 0x02, 0x00, 0x01, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x75, 0x69, 0x6e, 0x74, 0x31, 0x36, 0x56, 0x61, + 0x6c, 0x75, 0x65, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x02, 0x00, 0x01, 0x00, + 0x0c, 0x00, 0x00, 0x00, 0x02, 0x00, 0x01, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x75, 0x69, 0x6e, 0x74, 0x33, 0x32, 0x56, 0x61, + 0x6c, 0x75, 0x65, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, + 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x02, 0x00, 0x01, 0x00, + 0x0c, 0x00, 0x00, 0x00, 0x02, 0x00, 0x01, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x76, 0x6f, 0x69, 0x64, 0x56, 0x61, 0x6c, 0x75, + 0x65, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x02, 0x00, 0x01, 0x00, + 0x0c, 0x00, 0x00, 0x00, 0x02, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x66, 0x6c, 0x6f, 0x61, 0x74, 0x33, 0x32, 0x56, + 0x61, 0x6c, 0x75, 0x65, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, + 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x02, 0x00, 0x01, 0x00, + 0x0c, 0x00, 0x00, 0x00, 0x02, 0x00, 0x01, 0x00, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x66, 0x6c, 0x6f, 0x61, 0x74, 0x36, 0x34, 0x56, + 0x61, 0x6c, 0x75, 0x65, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x02, 0x00, 0x01, 0x00, + 0x0c, 0x00, 0x00, 0x00, 0x02, 0x00, 0x01, 0x00, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x74, 0x65, 0x78, 0x74, 0x56, 0x61, 0x6c, 0x75, + 0x65, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x02, 0x00, 0x01, 0x00, + 0x0c, 0x00, 0x00, 0x00, 0x02, 0x00, 0x01, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x64, 0x61, 0x74, 0x61, 0x56, 0x61, 0x6c, 0x75, + 0x65, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x02, 0x00, 0x01, 0x00, + 0x0c, 0x00, 0x00, 0x00, 0x02, 0x00, 0x01, 0x00, 0x0d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x0d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x6c, 0x69, 0x73, 0x74, 0x56, 0x61, 0x6c, 0x75, + 0x65, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x02, 0x00, 0x01, 0x00, + 0x0c, 0x00, 0x00, 0x00, 0x02, 0x00, 0x01, 0x00, 0x12, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x13, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x65, 0x6e, 0x75, 0x6d, 0x56, 0x61, 0x6c, 0x75, + 0x65, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x02, 0x00, 0x01, 0x00, + 0x0c, 0x00, 0x00, 0x00, 0x02, 0x00, 0x01, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x73, 0x74, 0x72, 0x75, 0x63, 0x74, 0x56, 0x61, + 0x6c, 0x75, 0x65, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x02, 0x00, 0x01, 0x00, + 0x0c, 0x00, 0x00, 0x00, 0x02, 0x00, 0x01, 0x00, 0x12, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x13, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x66, 0x61, 0x63, + 0x65, 0x56, 0x61, 0x6c, 0x75, 0x65, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x02, 0x00, 0x01, 0x00, + 0x0c, 0x00, 0x00, 0x00, 0x02, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x6f, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x56, 0x61, + 0x6c, 0x75, 0x65, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x02, 0x00, 0x01, 0x00, + 0x0c, 0x00, 0x00, 0x00, 0x02, 0x00, 0x01, 0x00, 0x12, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x13, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x73, 0x4d, 0xd2, 0x75, 0x6b, 0xff, 0xe1, 0xbe, +}; + +TEST(Schema, ReadSimple) { + struct capn ctx; + ASSERT_EQ(0, capn_init_mem(&ctx, simple_schema, sizeof(simple_schema), 0)); + + CodeGeneratorRequest_ptr root = {capn_get_root(&ctx)}; + EXPECT_EQ(CAPN_STRUCT, root.p.type); + + struct CodeGeneratorRequest req; + read_CodeGeneratorRequest(&req, root); + for (size_t i = 0; i < req.nodes.p.size; i++) { + } +} + diff --git a/compiler/schema.c b/compiler/schema.c index db321fb..3a9c19c 100644 --- a/compiler/schema.c +++ b/compiler/schema.c @@ -1,222 +1,319 @@ #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); +void get_Node(struct Node *s, Node_list l, int i) { + Node_ptr p = {capn_getp(l.p, i)}; + read_Node(s, p); +} + +void get_Node_NestedNode(struct Node_NestedNode *s, Node_NestedNode_list l, int i) { + Node_NestedNode_ptr p = {capn_getp(l.p, i)}; + read_Node_NestedNode(s, p); +} + +void get_Type(struct Type *s, Type_list l, int i) { + Type_ptr p = {capn_getp(l.p, i)}; + read_Type(s, p); +} + +void get_Value(struct Value *s, Value_list l, int i) { + Value_ptr p = {capn_getp(l.p, i)}; + read_Value(s, p); +} + +void get_Annotation(struct Annotation *s, Annotation_list l, int i) { + Annotation_ptr p = {capn_getp(l.p, i)}; + read_Annotation(s, p); +} + +void get_FileNode(struct FileNode *s, FileNode_list l, int i) { + FileNode_ptr p = {capn_getp(l.p, i)}; + read_FileNode(s, p); +} + +void get_FileNode_Import(struct FileNode_Import *s, FileNode_Import_list l, int i) { + FileNode_Import_ptr p = {capn_getp(l.p, i)}; + read_FileNode_Import(s, p); +} + +void get_StructNode(struct StructNode *s, StructNode_list l, int i) { + StructNode_ptr p = {capn_getp(l.p, i)}; + read_StructNode(s, p); +} + +void get_StructNode_Member(struct StructNode_Member *s, StructNode_Member_list l, int i) { + StructNode_Member_ptr p = {capn_getp(l.p, i)}; + read_StructNode_Member(s, p); +} + +void get_StructNode_Field(struct StructNode_Field *s, StructNode_Field_list l, int i) { + StructNode_Field_ptr p = {capn_getp(l.p, i)}; + read_StructNode_Field(s, p); +} + +void get_StructNode_Union(struct StructNode_Union *s, StructNode_Union_list l, int i) { + StructNode_Union_ptr p = {capn_getp(l.p, i)}; + read_StructNode_Union(s, p); +} + +void get_EnumNode(struct EnumNode *s, EnumNode_list l, int i) { + EnumNode_ptr p = {capn_getp(l.p, i)}; + read_EnumNode(s, p); +} + +void get_EnumNode_Enumerant(struct EnumNode_Enumerant *s, EnumNode_Enumerant_list l, int i) { + EnumNode_Enumerant_ptr p = {capn_getp(l.p, i)}; + read_EnumNode_Enumerant(s, p); +} + +void get_InterfaceNode(struct InterfaceNode *s, InterfaceNode_list l, int i) { + InterfaceNode_ptr p = {capn_getp(l.p, i)}; + read_InterfaceNode(s, p); +} + +void get_InterfaceNode_Method(struct InterfaceNode_Method *s, InterfaceNode_Method_list l, int i) { + InterfaceNode_Method_ptr p = {capn_getp(l.p, i)}; + read_InterfaceNode_Method(s, p); +} + +void get_InterfaceNode_Method_Param(struct InterfaceNode_Method_Param *s, InterfaceNode_Method_Param_list l, int i) { + InterfaceNode_Method_Param_ptr p = {capn_getp(l.p, i)}; + read_InterfaceNode_Method_Param(s, p); +} + +void get_ConstNode(struct ConstNode *s, ConstNode_list l, int i) { + ConstNode_ptr p = {capn_getp(l.p, i)}; + read_ConstNode(s, p); +} + +void get_AnnotationNode(struct AnnotationNode *s, AnnotationNode_list l, int i) { + AnnotationNode_ptr p = {capn_getp(l.p, i)}; + read_AnnotationNode(s, p); +} + +void get_CodeGeneratorRequest(struct CodeGeneratorRequest *s, CodeGeneratorRequest_list l, int i) { + CodeGeneratorRequest_ptr p = {capn_getp(l.p, i)}; + read_CodeGeneratorRequest(s, p); +} + + + +void read_Node(struct Node *s, Node_ptr p) { + s->id = capn_read64(p.p, 0); + s->displayName = capn_get_text(p.p, 0); + s->scopeId = capn_read64(p.p, 8); + s->nestedNodes.p = capn_getp(p.p, 1); + s->annotations.p = 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); + s->body.fileNode.p = capn_getp(p.p, 3); break; case Node_structNode: - s->body.structNode.p = capn_getp(&p->p, 3); + s->body.structNode.p = capn_getp(p.p, 3); break; case Node_enumNode: - s->body.enumNode.p = capn_getp(&p->p, 3); + s->body.enumNode.p = capn_getp(p.p, 3); break; case Node_interfaceNode: - s->body.interfaceNode.p = capn_getp(&p->p, 3); + s->body.interfaceNode.p = capn_getp(p.p, 3); break; case Node_constNode: - s->body.constNode.p = capn_getp(&p->p, 3); + s->body.constNode.p = capn_getp(p.p, 3); break; case Node_annotationNode: - s->body.annotationNode.p = capn_getp(&p->p, 3); + 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_Node_NestedNode(struct Node_NestedNode *s, Node_NestedNode_ptr p) { + 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); +void read_Type(struct Type *s, Type_ptr p) { + s->body_tag = capn_read16(p.p, 0); switch (s->body_tag) { case Type_listType: - s->body.listType.p = capn_getp(&p->p, 0); + s->body.listType.p = capn_getp(p.p, 0); break; case Type_enumType: - s->body.enumType = capn_read64(&p->p, 0); + s->body.enumType = capn_read64(p.p, 0); break; case Type_structType: - s->body.structType = capn_read64(&p->p, 0); + s->body.structType = capn_read64(p.p, 0); break; case Type_interfaceType: - s->body.interfaceType = capn_read64(&p->p, 0); + 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); +void read_Value(struct Value *s, Value_ptr p) { + 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; + s->body.boolValue = (capn_read8(p.p, 8) & 1) != 0; break; case Value_int8Value: - s->body.int8Value = (int8_t) capn_read8(&p->p, 8); + s->body.int8Value = (int8_t) capn_read8(p.p, 8); break; case Value_int16Value: - s->body.int16Value = (int16_t) capn_read16(&p->p, 8); + s->body.int16Value = (int16_t) capn_read16(p.p, 8); break; case Value_int32Value: - s->body.int32Value = (int32_t) capn_read32(&p->p, 8); + s->body.int32Value = (int32_t) capn_read32(p.p, 8); break; case Value_int64Value: - s->body.int64Value = (int64_t) capn_read64(&p->p, 8); + s->body.int64Value = (int64_t) capn_read64(p.p, 8); break; case Value_uint8Value: - s->body.uint8Value = capn_read8(&p->p, 8); + s->body.uint8Value = capn_read8(p.p, 8); break; case Value_uint16Value: - s->body.uint16Value = capn_read16(&p->p, 8); + s->body.uint16Value = capn_read16(p.p, 8); break; case Value_uint32Value: - s->body.uint32Value = capn_read32(&p->p, 8); + s->body.uint32Value = capn_read32(p.p, 8); break; case Value_uint64Value: - s->body.uint64Value = capn_read64(&p->p, 8); + s->body.uint64Value = capn_read64(p.p, 8); break; case Value_float32Value: - s->body.float32Value = capn_read_float(&p->p, 8, 0.0f); + 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); + s->body.float64Value = capn_read_double(p.p, 8, 0.0); break; case Value_textValue: - s->body.textValue = capn_get_text(&p->p, 0); + s->body.textValue = capn_get_text(p.p, 0); break; case Value_dataValue: - s->body.dataValue = capn_get_data(&p->p, 0); + s->body.dataValue = capn_get_data(p.p, 0); break; case Value_listValue: - s->body.listValue = capn_getp(&p->p, 0); + s->body.listValue = capn_getp(p.p, 0); break; case Value_enumValue: - s->body.enumValue = capn_read16(&p->p, 8); + s->body.enumValue = capn_read16(p.p, 8); break; case Value_structValue: - s->body.structValue = capn_getp(&p->p, 0); + s->body.structValue = capn_getp(p.p, 0); break; case Value_objectValue: - s->body.objectValue = capn_getp(&p->p, 0); + 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_Annotation(struct Annotation *s, Annotation_ptr p) { + 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(struct FileNode *s, FileNode_ptr p) { + s->imports.p = 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_FileNode_Import(struct FileNode_Import *s, FileNode_Import_ptr p) { + 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(struct StructNode *s, StructNode_ptr p) { + 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.p = 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); +void read_StructNode_Member(struct StructNode_Member *s, StructNode_Member_ptr p) { + s->name = capn_get_text(p.p, 0); + s->ordinal = capn_read16(p.p, 0); + s->codeOrder = capn_read16(p.p, 2); + s->annotations.p = 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); + s->body.fieldMember.p = capn_getp(p.p, 2); break; case StructNode_Member_unionMember: - s->body.unionMember.p = capn_getp(&p->p, 2); + 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_Field(struct StructNode_Field *s, StructNode_Field_ptr p) { + 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_StructNode_Union(struct StructNode_Union *s, StructNode_Union_ptr p) { + s->discriminantOffset = capn_read32(p.p, 0); + s->members.p = 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(struct EnumNode *s, EnumNode_ptr p) { + s->enumerants.p = 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_EnumNode_Enumerant(struct EnumNode_Enumerant *s, EnumNode_Enumerant_ptr p) { + s->name = capn_get_text(p.p, 0); + s->codeOrder = capn_read16(p.p, 0); + s->annotations.p = 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(struct InterfaceNode *s, InterfaceNode_ptr p) { + s->methods.p = 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(struct InterfaceNode_Method *s, InterfaceNode_Method_ptr p) { + s->name = capn_get_text(p.p, 0); + s->codeOrder = capn_read16(p.p, 0); + s->params.p = capn_getp(p.p, 1); + s->requiredParamCount = capn_read16(p.p, 2); + s->returnType.p = capn_getp(p.p, 2); + s->annotations.p = 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_InterfaceNode_Method_Param(struct InterfaceNode_Method_Param *s, InterfaceNode_Method_Param_ptr p) { + 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.p = 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_ConstNode(struct ConstNode *s, ConstNode_ptr p) { + 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_AnnotationNode(struct AnnotationNode *s, AnnotationNode_ptr p) { + 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); +void read_CodeGeneratorRequest(struct CodeGeneratorRequest *s, CodeGeneratorRequest_ptr p) { + s->nodes.p = capn_getp(p.p, 0); + s->requestedFiles = capn_getp(p.p, 1); } diff --git a/compiler/schema.h b/compiler/schema.h index aca8709..06afa76 100644 --- a/compiler/schema.h +++ b/compiler/schema.h @@ -1,25 +1,109 @@ /* vim: set sw=8 ts=8 sts=8 noet: */ #include -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;}; +#ifdef __cplusplus +extern "C" { +#endif + +struct Node; +struct Node_NestedNode; +struct Type; +struct Value; +struct Annotation; +struct FileNode; +struct FileNode_Import; +struct StructNode; +struct StructNode_Member; +struct StructNode_Field; +struct StructNode_Union; +struct EnumNode; +struct EnumNode_Enumerant; +struct InterfaceNode; +struct InterfaceNode_Method; +struct InterfaceNode_Method_Param; +struct ConstNode; +struct AnnotationNode; +struct CodeGeneratorRequest; + +typedef struct {capn_ptr p;} Node_ptr; +typedef struct {capn_ptr p;} Node_NestedNode_ptr; +typedef struct {capn_ptr p;} Type_ptr; +typedef struct {capn_ptr p;} Value_ptr; +typedef struct {capn_ptr p;} Annotation_ptr; +typedef struct {capn_ptr p;} FileNode_ptr; +typedef struct {capn_ptr p;} FileNode_Import_ptr; +typedef struct {capn_ptr p;} StructNode_ptr; +typedef struct {capn_ptr p;} StructNode_Member_ptr; +typedef struct {capn_ptr p;} StructNode_Field_ptr; +typedef struct {capn_ptr p;} StructNode_Union_ptr; +typedef struct {capn_ptr p;} EnumNode_ptr; +typedef struct {capn_ptr p;} EnumNode_Enumerant_ptr; +typedef struct {capn_ptr p;} InterfaceNode_ptr; +typedef struct {capn_ptr p;} InterfaceNode_Method_ptr; +typedef struct {capn_ptr p;} InterfaceNode_Method_Param_ptr; +typedef struct {capn_ptr p;} ConstNode_ptr; +typedef struct {capn_ptr p;} AnnotationNode_ptr; +typedef struct {capn_ptr p;} CodeGeneratorRequest_ptr; + +typedef struct {capn_ptr p;} Node_list; +typedef struct {capn_ptr p;} Node_NestedNode_list; +typedef struct {capn_ptr p;} Type_list; +typedef struct {capn_ptr p;} Value_list; +typedef struct {capn_ptr p;} Annotation_list; +typedef struct {capn_ptr p;} FileNode_list; +typedef struct {capn_ptr p;} FileNode_Import_list; +typedef struct {capn_ptr p;} StructNode_list; +typedef struct {capn_ptr p;} StructNode_Member_list; +typedef struct {capn_ptr p;} StructNode_Field_list; +typedef struct {capn_ptr p;} StructNode_Union_list; +typedef struct {capn_ptr p;} EnumNode_list; +typedef struct {capn_ptr p;} EnumNode_Enumerant_list; +typedef struct {capn_ptr p;} InterfaceNode_list; +typedef struct {capn_ptr p;} InterfaceNode_Method_list; +typedef struct {capn_ptr p;} InterfaceNode_Method_Param_list; +typedef struct {capn_ptr p;} ConstNode_list; +typedef struct {capn_ptr p;} AnnotationNode_list; +typedef struct {capn_ptr p;} CodeGeneratorRequest_list; + +void read_Node(struct Node*, Node_ptr); +void read_Node_NestedNode(struct Node_NestedNode*, Node_NestedNode_ptr); +void read_Type(struct Type*, Type_ptr); +void read_Value(struct Value*, Value_ptr); +void read_Annotation(struct Annotation*, Annotation_ptr); +void read_FileNode(struct FileNode*, FileNode_ptr); +void read_FileNode_Import(struct FileNode_Import*, FileNode_Import_ptr); +void read_StructNode(struct StructNode*, StructNode_ptr); +void read_StructNode_Member(struct StructNode_Member*, StructNode_Member_ptr); +void read_StructNode_Field(struct StructNode_Field*, StructNode_Field_ptr); +void read_StructNode_Union(struct StructNode_Union*, StructNode_Union_ptr); +void read_EnumNode(struct EnumNode*, EnumNode_ptr); +void read_EnumNode_Enumerant(struct EnumNode_Enumerant*, EnumNode_Enumerant_ptr); +void read_InterfaceNode(struct InterfaceNode*, InterfaceNode_ptr); +void read_InterfaceNode_Method(struct InterfaceNode_Method*, InterfaceNode_Method_ptr); +void read_InterfaceNode_Method_Param(struct InterfaceNode_Method_Param*, InterfaceNode_Method_Param_ptr); +void read_ConstNode(struct ConstNode*, ConstNode_ptr); +void read_AnnotationNode(struct AnnotationNode*, AnnotationNode_ptr); +void read_CodeGeneratorRequest(struct CodeGeneratorRequest*, CodeGeneratorRequest_ptr); + +void get_Node(struct Node*, Node_list, int i); +void get_Node_NestedNode(struct Node_NestedNode*, Node_NestedNode_list, int i); +void get_Type(struct Type*, Type_list, int i); +void get_Value(struct Value*, Value_list, int i); +void get_Annotation(struct Annotation*, Annotation_list, int i); +void get_FileNode(struct FileNode*, FileNode_list, int i); +void get_FileNode_Import(struct FileNode_Import*, FileNode_Import_list, int i); +void get_StructNode(struct StructNode*, StructNode_list, int i); +void get_StructNode_Member(struct StructNode_Member*, StructNode_Member_list, int i); +void get_StructNode_Field(struct StructNode_Field*, StructNode_Field_list, int i); +void get_StructNode_Union(struct StructNode_Union*, StructNode_Union_list, int i); +void get_EnumNode(struct EnumNode*, EnumNode_list, int i); +void get_EnumNode_Enumerant(struct EnumNode_Enumerant*, EnumNode_Enumerant_list, int i); +void get_InterfaceNode(struct InterfaceNode*, InterfaceNode_list, int i); +void get_InterfaceNode_Method(struct InterfaceNode_Method*, InterfaceNode_Method_list, int i); +void get_InterfaceNode_Method_Param(struct InterfaceNode_Method_Param*, InterfaceNode_Method_Param_list, int i); +void get_ConstNode(struct ConstNode*, ConstNode_list, int i); +void get_AnnotationNode(struct AnnotationNode*, AnnotationNode_list, int i); +void get_CodeGeneratorRequest(struct CodeGeneratorRequest*, CodeGeneratorRequest_list, int i); enum Node_body { Node_fileNode = 0, @@ -27,28 +111,28 @@ enum Node_body { Node_enumNode = 2, Node_interfaceNode = 3, Node_constNode = 4, - Node_annotationNode = 5, + Node_annotationNode = 5 }; struct Node { uint64_t id; - struct capn_text displayName; + capn_text displayName; uint64_t scopeId; - struct capn_ptr nestedNodes; /* List(Node_NestedNode) */ - struct capn_ptr annotations; /* List(Annotation) */ + Node_NestedNode_list nestedNodes; + Annotation_list annotations; 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; + FileNode_ptr fileNode; + StructNode_ptr structNode; + EnumNode_ptr enumNode; + InterfaceNode_ptr interfaceNode; + ConstNode_ptr constNode; + AnnotationNode_ptr annotationNode; } body; }; struct Node_NestedNode { - struct capn_text name; + capn_text name; uint64_t id; }; @@ -71,13 +155,13 @@ enum Type_body { Type_enumType = 15, Type_structType = 16, Type_interfaceType = 17, - Type_objectType = 18, + Type_objectType = 18 }; struct Type { enum Type_body body_tag; union { - struct Type_ptr listType; + Type_ptr listType; uint64_t enumType; uint64_t structType; uint64_t interfaceType; @@ -103,7 +187,7 @@ enum Value_body { Value_enumValue = 15, Value_structValue = 16, Value_interfaceValue = 17, - Value_objectValue = 18, + Value_objectValue = 18 }; struct Value { @@ -120,27 +204,27 @@ struct Value { uint64_t uint64Value; float float32Value; double float64Value; - struct capn_text textValue; - struct capn_data dataValue; - struct capn_ptr listValue; + capn_text textValue; + capn_data dataValue; + capn_ptr listValue; uint16_t enumValue; - struct capn_ptr structValue; - struct capn_ptr objectValue; + capn_ptr structValue; + capn_ptr objectValue; } body; }; struct Annotation { uint64_t id; - struct Value_ptr value; + Value_ptr value; }; struct FileNode { - struct capn_ptr imports; /* List(FileNode_Import) */ + FileNode_Import_list imports; }; struct FileNode_Import { uint64_t id; - struct capn_text name; + capn_text name; }; enum ElementSize { @@ -151,81 +235,81 @@ enum ElementSize { ElementSize_fourBytes = 4, ElementSize_eightBytes = 5, ElementSize_pointer = 6, - ElementSize_inlineComposite = 7, + ElementSize_inlineComposite = 7 }; struct StructNode { uint16_t dataSectionWordSize; uint16_t pointerSectionSize; enum ElementSize preferredListEncoding; - struct capn_ptr members; /* List(StructNode_Member) */ + StructNode_Member_list members; }; enum StructNode_Member_body { StructNode_Member_fieldMember = 0, - StructNode_Member_unionMember = 1, + StructNode_Member_unionMember = 1 }; struct StructNode_Member { - struct capn_text name; + capn_text name; uint16_t ordinal; uint16_t codeOrder; - struct capn_ptr annotations; /* List(Annotation) */ + Annotation_list annotations; enum StructNode_Member_body body_tag; union { - struct StructNode_Field_ptr fieldMember; - struct StructNode_Field_ptr unionMember; + StructNode_Field_ptr fieldMember; + StructNode_Union_ptr unionMember; } body; }; struct StructNode_Field { uint32_t offset; - struct Type_ptr type; - struct Value_ptr defaultValue; + Type_ptr type; + Value_ptr defaultValue; }; struct StructNode_Union { uint32_t discriminantOffset; - struct capn_ptr members; /* List(StructNode_Member) */ + StructNode_Member_list members; }; struct EnumNode { - struct capn_ptr enumerants; /* List(EnumNode_Enumerant) */ + EnumNode_Enumerant_list enumerants; }; struct EnumNode_Enumerant { - struct capn_text name; + capn_text name; uint16_t codeOrder; - struct capn_ptr annotations; /* List(Annotation) */ + Annotation_list annotations; }; struct InterfaceNode { - struct capn_ptr methods; /* List(InterfaceNode_Method) */ + InterfaceNode_Method_list methods; }; struct InterfaceNode_Method { - struct capn_text name; + capn_text name; uint16_t codeOrder; - struct capn_ptr params; /* List(InterfaceNode_Method_Param) */ + InterfaceNode_Method_Param_list params; uint16_t requiredParamCount; - struct Type_ptr returnType; - struct capn_ptr annotations; /* List(Annotation) */ + Type_ptr returnType; + Annotation_list annotations; }; struct InterfaceNode_Method_Param { - struct capn_text name; - struct Type_ptr type; - struct Value_ptr defaultValue; - struct capn_ptr annotations; /* List(Annotation) */ + capn_text name; + Type_ptr type; + Value_ptr defaultValue; + Annotation_list annotations; }; struct ConstNode { - struct Type_ptr type; - struct Value_ptr value; + Type_ptr type; + Value_ptr value; }; struct AnnotationNode { - struct Type_ptr type; + Type_ptr type; unsigned int targetsFile : 1; unsigned int targetsConst : 1; unsigned int targetsEnum : 1; @@ -240,27 +324,11 @@ struct AnnotationNode { }; struct CodeGeneratorRequest { - struct capn_ptr nodes; /* List(Node) */ - struct capn_ptr requestedFiles; /* List(uint64_t) */ + Node_list nodes; + 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*); +#ifdef __cplusplus +} +#endif diff --git a/compiler/simple.capnp b/compiler/simple.capnp new file mode 100644 index 0000000..290e715 --- /dev/null +++ b/compiler/simple.capnp @@ -0,0 +1,25 @@ +@0xbee1ff6b75d24d73; + +struct Foo { + body @0 union { + 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; + objectValue @19 :Object; + } +}