]> git.rm.cloudns.org Git - xonotic/gmqcc.git/commitdiff
error about too many elements in initializer; added test for initialized arrays:...
authorWolfgang Bumiller <wry.git@bumiller.com>
Wed, 12 Jun 2013 12:41:38 +0000 (14:41 +0200)
committerWolfgang Bumiller <wry.git@bumiller.com>
Wed, 12 Jun 2013 12:41:38 +0000 (14:41 +0200)
ast.c
tests/arrays.tmpl
tests/arrays2.qc [new file with mode: 0644]
tests/arrays2.tmpl [new file with mode: 0644]

diff --git a/ast.c b/ast.c
index 3d1f30b2203e7ab8c01635e4018c67a6bb8f1b76..c1d8cb9c4c1f0b8096bbec6bdab9a023d64cf586 100644 (file)
--- 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:
index bbeba1000a785e8dbc6b888f784d56f7f79e9ee9..6e21f8743ebda293ab288649c91c2f2401a0b037 100644 (file)
@@ -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 (file)
index 0000000..f89739f
--- /dev/null
@@ -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 (file)
index 0000000..bbeba10
--- /dev/null
@@ -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