From 865b2515054c9345c7119c2d678ebd38d4b5afe0 Mon Sep 17 00:00:00 2001 From: NeilBrown Date: Tue, 2 Apr 2019 12:36:35 +1100 Subject: [PATCH] oceani: don't store 'tail' in 'struct value'. It is never used so there isn't much point storing it. If/When we do use it, we'll parse it immediately and store the meaning. And in any case, it should be char[3]. Signed-off-by: NeilBrown --- csrc/oceani.mdc | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/csrc/oceani.mdc b/csrc/oceani.mdc index 90b1492..a8da9fb 100644 --- a/csrc/oceani.mdc +++ b/csrc/oceani.mdc @@ -399,10 +399,7 @@ fractions, strings, Booleans and labels. When analysing the program we also need to allow for places where no value is meaningful (`Vnone`) and where we don't know what type to expect yet (`Vunknown` which can be anything and `Vnolabel` which can be anything except a -label). A 2 character 'tail' is included in each value as the scanner -wants to parse that from the end of numbers and we need somewhere to -put it. It is currently ignored but one day might allow for -e.g. "imaginary" numbers. +label). Values are never shared, they are always copied when used, and freed when no longer needed. @@ -440,7 +437,6 @@ to parse each type from a string. int bool; void *label; }; - char tail[2]; }; char *vtype_names[] = {"nolabel", "unknown", "none", "string", @@ -582,6 +578,8 @@ to parse each type from a string. { struct text tx; int neg = 0; + char tail[3] = ""; + switch(vl->vtype) { case Vnolabel: case Vlabel: @@ -599,10 +597,14 @@ to parse each type from a string. arg++; } tx.txt = arg; tx.len = strlen(tx.txt); - if (number_parse(vl->num, vl->tail, tx) == 0) + if (number_parse(vl->num, tail, tx) == 0) mpq_init(vl->num); else if (neg) mpq_neg(vl->num, vl->num); + if (tail[0]) { + printf("Unsupported suffix: %s\n", arg); + return 0; + } break; case Vbool: if (strcasecmp(arg, "true") == 0 || @@ -1291,27 +1293,36 @@ an executable. | NUMBER ${ $0 = new_pos(val, $1); $0->val.vtype = Vnum; - if (number_parse($0->val.num, $0->val.tail, $1.txt) == 0) + { + char tail[3]; + if (number_parse($0->val.num, tail, $1.txt) == 0) mpq_init($0->val.num); - if ($0->val.tail[0]) + if (tail[0]) tok_err(config2context(config), "error: unsupported number suffix.", &$1); + } }$ | STRING ${ $0 = new_pos(val, $1); $0->val.vtype = Vstr; - string_parse(&$1, '\\', &$0->val.str, $0->val.tail); - if ($0->val.tail[0]) + { + char tail[3]; + string_parse(&$1, '\\', &$0->val.str, tail); + if (tail[0]) tok_err(config2context(config), "error: unsupported string suffix.", &$1); + } }$ | MULTI_STRING ${ $0 = new_pos(val, $1); $0->val.vtype = Vstr; - string_parse(&$1, '\\', &$0->val.str, $0->val.tail); - if ($0->val.tail[0]) + { + char tail[3]; + string_parse(&$1, '\\', &$0->val.str, tail); + if (tail[0]) tok_err(config2context(config), "error: unsupported string suffix.", &$1); + } }$ ###### print exec cases -- 2.43.0