From: Wolfgang Bumiller Date: Wed, 12 Jun 2013 12:41:38 +0000 (+0200) Subject: error about too many elements in initializer; added test for initialized arrays:... X-Git-Tag: v0.3.0~145 X-Git-Url: https://git.xonotic.org/?p=xonotic%2Fgmqcc.git;a=commitdiff_plain;h=dc91918c1f07b5aaeaf5ff911c5791ee15d1905a error about too many elements in initializer; added test for initialized arrays: arrays2.tmpl/qc --- diff --git a/ast.c b/ast.c index 3d1f30b..c1d8cb9 100644 --- a/ast.c +++ b/ast.c @@ -1212,6 +1212,16 @@ static bool ast_global_array_set(ast_value *self) size_t count = vec_size(self->initlist); size_t i; + if (count > self->expression.count) { + compile_error(ast_ctx(self), "too many elements in initializer"); + count = self->expression.count; + } + else if (count < self->expression.count) { + /* add this? + compile_warning(ast_ctx(self), "not all elements are initialized"); + */ + } + for (i = 0; i != count; ++i) { switch (self->expression.next->vtype) { case TYPE_FLOAT: diff --git a/tests/arrays.tmpl b/tests/arrays.tmpl index bbeba10..6e21f87 100644 --- a/tests/arrays.tmpl +++ b/tests/arrays.tmpl @@ -1,7 +1,6 @@ -I: arrays.qc -D: array accessors and functionality +I: arrays2.qc +D: initialized arrays T: -execute C: -std=fteqcc -M: 1001 1101 1201 1301 1401 1501 -M: 1001 1101 1201 1301 1401 1501 1601 -M: 1001 1101 1201 1301 1401 1501 +M: 10 20 30 40 50 60 70 +M: 100 200 300 400 500 600 0 diff --git a/tests/arrays2.qc b/tests/arrays2.qc new file mode 100644 index 0000000..f89739f --- /dev/null +++ b/tests/arrays2.qc @@ -0,0 +1,15 @@ +float glob1[7] = { 10, 20, 30, 40, 50, 60, 70 }; +float glob2[7] = { 100, 200, 300, 400, 500, 600 }; + +void main() { + float i; + print(ftos(glob1[0])); + for (i = 1; i != 7; ++i) + print(" ", ftos(glob1[i])); + print("\n"); + + print(ftos(glob2[0])); + for (i = 1; i != 7; ++i) + print(" ", ftos(glob2[i])); + print("\n"); +} diff --git a/tests/arrays2.tmpl b/tests/arrays2.tmpl new file mode 100644 index 0000000..bbeba10 --- /dev/null +++ b/tests/arrays2.tmpl @@ -0,0 +1,7 @@ +I: arrays.qc +D: array accessors and functionality +T: -execute +C: -std=fteqcc +M: 1001 1101 1201 1301 1401 1501 +M: 1001 1101 1201 1301 1401 1501 1601 +M: 1001 1101 1201 1301 1401 1501