]> git.rm.cloudns.org Git - xonotic/gmqcc.git/commitdiff
Added diagnostic for expected tokens, a test, and a testsuite underflow bug.
authorDale Weiler <killfieldengine@gmail.com>
Fri, 31 May 2013 06:10:32 +0000 (06:10 +0000)
committerDale Weiler <killfieldengine@gmail.com>
Fri, 31 May 2013 06:10:32 +0000 (06:10 +0000)
diag.c
gmqcc.h
parser.c
test.c
tests/diag/expected.qc [new file with mode: 0644]
tests/diag/expected.tmpl [new file with mode: 0644]

diff --git a/diag.c b/diag.c
index c6476b4a5c56b46f5fe8cc9ad4d64a0a8cd94d0f..73807f2b2776dc0357b95a7eb3cfca0ca67df643 100644 (file)
--- a/diag.c
+++ b/diag.c
@@ -103,7 +103,7 @@ static void diagnostic_line(const char *file, size_t line, diagnostic_data_t ***
         vec_push((*read), datas[feed]);
 }
 
-static void diagnostic_feed(const char *file, size_t line, size_t beg, size_t end, bool marker, size_t diagnostic) {
+static void diagnostic_feed(const char *file, size_t line, size_t column, size_t beg, size_t end, bool marker, size_t diagnostic) {
     diagnostic_data_t  **read  = NULL;
     size_t               feed  = 0;
     size_t               space = 6;
@@ -160,6 +160,15 @@ static void diagnostic_feed(const char *file, size_t line, size_t beg, size_t en
             space -= beg - end;
             break;
             
+        case DIAGNOSTIC_EXPECTED:
+            /*
+             * use the column number here, it's the EASIEST method yet
+             * because it points to the exact space.
+             */
+            space += column;
+            len    = 0;
+            break;
+            
         case DIAGNOSTIC_UNEXPECTED_IDENT:
             for (itr = 0; len < vec_size(vec_last(read)->tokens); len++) {
                 if (vec_last(read)->tokens[len] == TOKEN_IDENT)
@@ -212,7 +221,7 @@ void diagnostic_destroy() {
     util_htrem(diagnostic_table, diagnostic_destory_data);
 }
 
-void diagnostic_calculate(const char *file, size_t line, size_t diagnostic) {
+void diagnostic_calculate(const char *file, size_t line, size_t column, size_t diagnostic) {
     size_t linebeg = 1;
     size_t linecnt = 1;
     bool   marker  = false;
@@ -234,6 +243,10 @@ void diagnostic_calculate(const char *file, size_t line, size_t diagnostic) {
             marker = true;
             break;
 
+        case DIAGNOSTIC_EXPECTED:
+            marker = true;
+            break;
+            
         case DIAGNOSTIC_UNEXPECTED_IDENT:
             marker = true;
             break;
@@ -243,5 +256,5 @@ void diagnostic_calculate(const char *file, size_t line, size_t diagnostic) {
             return;
     }
 
-    diagnostic_feed(file, line, linebeg, linecnt, marker, diagnostic);
+    diagnostic_feed(file, line, column, linebeg, linecnt, marker, diagnostic);
 }
diff --git a/gmqcc.h b/gmqcc.h
index 238f2d1d51d007497049d992ce6561e0a1c47dcb..1882a30043c38b5137cb2897caf92ad47dbd5069 100644 (file)
--- a/gmqcc.h
+++ b/gmqcc.h
@@ -1034,11 +1034,12 @@ enum {
     DIAGNOSTIC_NULL,
     DIAGNOSTIC_SEMICOLON,
     DIAGNOSTIC_EXPRESSION_CASE,
-    DIAGNOSTIC_UNEXPECTED_IDENT
+    DIAGNOSTIC_UNEXPECTED_IDENT,
+    DIAGNOSTIC_EXPECTED
 };
 
 void diagnostic_destroy();
-void diagnostic_calculate(const char *file, size_t line, size_t diagnostic);
+void diagnostic_calculate(const char *file, size_t line, size_t column, size_t diagnostic);
 
 
 /*===================================================================*/
index d0aaf4a440e58ce0ad9a5bf2490bad614999d5cd..2d6cd1d1be121f5ad930e57c18d97f664e96f7d2 100644 (file)
--- a/parser.c
+++ b/parser.c
@@ -139,7 +139,7 @@ static void parseerror(parser_t *parser, const char *fmt, ...)
     vcompile_error(parser->lex->tok.ctx, fmt, ap);
     va_end(ap);
 
-    diagnostic_calculate(parser->lex->name, parser->lex->line, parser->diagnostic);
+    diagnostic_calculate(parser->lex->name, parser->lex->line, parser->lex->column, parser->diagnostic);
 }
 
 /* returns true if it counts as an error */
@@ -151,7 +151,7 @@ static bool GMQCC_WARN parsewarning(parser_t *parser, int warntype, const char *
     r = vcompile_warning(parser->lex->tok.ctx, warntype, fmt, ap);
     va_end(ap);
     
-    diagnostic_calculate(parser->lex->name, parser->lex->line, parser->diagnostic);
+    diagnostic_calculate(parser->lex->name, parser->lex->line, parser->lex->column, parser->diagnostic);
     return r;
 }
 
@@ -3898,6 +3898,7 @@ static bool parse_enum(parser_t *parser)
         parser_addglobal(parser, var->name, (ast_expression*)var);
 
         if (!parser_next(parser)) {
+            parser->diagnostic = DIAGNOSTIC_EXPECTED;
             parseerror(parser, "expected `=`, `}` or comma after identifier");
             goto onerror;
         }
@@ -3907,6 +3908,7 @@ static bool parse_enum(parser_t *parser)
         if (parser->tok == '}')
             break;
         if (parser->tok != '=') {
+            parser->diagnostic = DIAGNOSTIC_EXPECTED;
             parseerror(parser, "expected `=`, `}` or comma after identifier");
             goto onerror;
         }
diff --git a/test.c b/test.c
index 445fa3d02f00bfd5f6b718faa170dcbd60a1cfba..e68211b8b1f574e9eaf7e495ba104510bd7f39aa 100644 (file)
--- a/test.c
+++ b/test.c
@@ -436,7 +436,7 @@ static bool task_template_parse(const char *file, task_template_t *tmpl, FILE *f
                     goto failure;
                 }
 
-                if (value && *value && (*value == ' ' || *value == '\t'))
+                if (value && (*value == ' ' || *value == '\t'))
                     value++;
 
                 /*
@@ -449,6 +449,7 @@ static bool task_template_parse(const char *file, task_template_t *tmpl, FILE *f
                     exit(EXIT_FAILURE);
 
                 vec_push(tmpl->comparematch, util_strdup(value));
+                printf("VALUE: %s\n", value);
 
                 break;
             }
@@ -1230,7 +1231,7 @@ static void task_schedualize(size_t *pad) {
             );
             for (; d < vec_size(task_tasks[i].tmpl->comparematch); d++) {
                 char  *select = task_tasks[i].tmpl->comparematch[d];
-                size_t length = 40 - strlen(select);
+                size_t length = 60 - strlen(select);
 
                 con_out("        Expected: \"%s\"", select);
                 while (length --)
diff --git a/tests/diag/expected.qc b/tests/diag/expected.qc
new file mode 100644 (file)
index 0000000..1b24a57
--- /dev/null
@@ -0,0 +1 @@
+enum { A B };
diff --git a/tests/diag/expected.tmpl b/tests/diag/expected.tmpl
new file mode 100644 (file)
index 0000000..a665769
--- /dev/null
@@ -0,0 +1,7 @@
+I: expected.qc
+D: expected comma after identifier
+T: -diagnostic
+C: -std=gmqcc
+M: expected `=`, `}` or comma after identifier
+M:     1: enum { A B };
+M:                ^