compiler: If an explicit symbol wasn't provided, make generated capn_val%d variables static.

This commit is contained in:
Alex Helfet 2017-03-23 06:53:33 +00:00
parent 49031ea638
commit 362173091d

View file

@ -8,6 +8,7 @@
#include "schema.capnp.h" #include "schema.capnp.h"
#include "str.h" #include "str.h"
#include <stdbool.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <errno.h> #include <errno.h>
@ -261,6 +262,7 @@ static void decode_value(struct value* v, Type_ptr type, Value_ptr value, const
v->ptrval = p; v->ptrval = p;
bool symbol_provided = symbol;
if (!symbol) { if (!symbol) {
static struct str buf = STR_INIT; static struct str buf = STR_INIT;
v->intval = ++g_valc; v->intval = ++g_valc;
@ -268,7 +270,7 @@ static void decode_value(struct value* v, Type_ptr type, Value_ptr value, const
} }
str_addf(&SRC, "%scapn_text %s = {%d,(char*)&capn_buf[%d],(struct capn_segment*)&capn_seg};\n", str_addf(&SRC, "%scapn_text %s = {%d,(char*)&capn_buf[%d],(struct capn_segment*)&capn_seg};\n",
symbol ? "" : "static ", symbol_provided ? "" : "static ",
symbol, symbol,
p.len-1, p.len-1,
(int) (p.data-p.seg->data-8)); (int) (p.data-p.seg->data-8));
@ -291,13 +293,14 @@ static void decode_value(struct value* v, Type_ptr type, Value_ptr value, const
v->ptrval = p; v->ptrval = p;
bool symbol_provided = symbol;
if (!symbol) { if (!symbol) {
static struct str buf = STR_INIT; static struct str buf = STR_INIT;
v->intval = ++g_valc; v->intval = ++g_valc;
symbol = strf(&buf, "capn_val%d", (int) v->intval); symbol = strf(&buf, "capn_val%d", (int) v->intval);
} }
str_addf(&SRC, "%s%s %s = {", symbol ? "" : "static ", v->tname, symbol); str_addf(&SRC, "%s%s %s = {", symbol_provided ? "" : "static ", v->tname, symbol);
if (strcmp(v->tname, "capn_ptr")) if (strcmp(v->tname, "capn_ptr"))
str_addf(&SRC, "{"); str_addf(&SRC, "{");