compiler: add annotation to enable field get/set
Generating per-field getters/setters adds a lot of functions; this makes them switchable with an annotation in the source schema.
This commit is contained in:
parent
52ca907f14
commit
da663f83ef
2 changed files with 15 additions and 1 deletions
|
|
@ -21,6 +21,7 @@
|
||||||
|
|
||||||
@0xc0183dd65ffef0f3;
|
@0xc0183dd65ffef0f3;
|
||||||
|
|
||||||
|
annotation nameinfix @0x85a8d86d736ba637 (file): Text;
|
||||||
# add an infix (middle insert) for output file names
|
# add an infix (middle insert) for output file names
|
||||||
#
|
#
|
||||||
# "make" generally has implicit rules for compiling "foo.c" => "foo". This
|
# "make" generally has implicit rules for compiling "foo.c" => "foo". This
|
||||||
|
|
@ -29,4 +30,8 @@
|
||||||
# before the ".c", so the filename becomes "foo-gen.c"
|
# before the ".c", so the filename becomes "foo-gen.c"
|
||||||
#
|
#
|
||||||
# ("foo" is really "foo.capnp", so it's foo.capnp-gen.c)
|
# ("foo" is really "foo.capnp", so it's foo.capnp-gen.c)
|
||||||
annotation nameinfix @0x85a8d86d736ba637 (file): Text;
|
|
||||||
|
annotation fieldgetset @0xf72bc690355d66de (file): Void;
|
||||||
|
# generate getter & setter functions for accessing fields
|
||||||
|
#
|
||||||
|
# allows grabbing/putting values without de-/encoding the entire struct.
|
||||||
|
|
|
||||||
|
|
@ -46,6 +46,8 @@ static struct capn_segment g_valseg;
|
||||||
static int g_valc;
|
static int g_valc;
|
||||||
static int g_val0used, g_nullused;
|
static int g_val0used, g_nullused;
|
||||||
|
|
||||||
|
static int g_fieldgetset = 0;
|
||||||
|
|
||||||
static struct capn_tree *g_node_tree;
|
static struct capn_tree *g_node_tree;
|
||||||
|
|
||||||
static struct node *find_node_mayfail(uint64_t id) {
|
static struct node *find_node_mayfail(uint64_t id) {
|
||||||
|
|
@ -908,6 +910,10 @@ static void define_group(struct strings *s, struct node *n, const char *group_na
|
||||||
for (f = n->fields; f < n->fields + flen && !in_union(f); f++) {
|
for (f = n->fields; f < n->fields + flen && !in_union(f); f++) {
|
||||||
define_field(s, f);
|
define_field(s, f);
|
||||||
|
|
||||||
|
if (!g_fieldgetset) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if ((n->n.which == Node__struct && n->n._struct.isGroup)) {
|
if ((n->n.which == Node__struct && n->n._struct.isGroup)) {
|
||||||
// Don't emit in-place getters and setters for groups because they
|
// Don't emit in-place getters and setters for groups because they
|
||||||
// are defined as anonymous structs inside their parent struct.
|
// are defined as anonymous structs inside their parent struct.
|
||||||
|
|
@ -1280,6 +1286,9 @@ int main() {
|
||||||
}
|
}
|
||||||
nameinfix = v.text.str ? v.text.str : "";
|
nameinfix = v.text.str ? v.text.str : "";
|
||||||
break;
|
break;
|
||||||
|
case 0xf72bc690355d66deUL: /* $C::fieldgetset */
|
||||||
|
g_fieldgetset = 1;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!nameinfix)
|
if (!nameinfix)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue