Start having nicer stage 4 error messages.
authorMario de Sousa <msousa@fe.up.pt>
Wed, 18 Apr 2012 13:29:08 +0100
changeset 522 f9cff11ae622
parent 521 3127ddda2be2
child 523 773303b7f31f
Start having nicer stage 4 error messages.
stage4/generate_c/generate_c.cc
stage4/stage4.cc
stage4/stage4.hh
--- a/stage4/generate_c/generate_c.cc	Tue Apr 17 17:41:58 2012 +0200
+++ b/stage4/generate_c/generate_c.cc	Wed Apr 18 13:29:08 2012 +0100
@@ -49,6 +49,11 @@
 /* function defined in main.cc */
 extern void error_exit(const char *file_name, int line_no);
 
+
+#define STAGE4_ERROR(symbol1, symbol2, ...) {stage4err("while generating C code", symbol1, symbol2, __VA_ARGS__); exit(EXIT_FAILURE);}
+
+
+
 /***********************************************************************/
 
 /* Unlike Programs and Configurations which get mapped onto C++ classes,
@@ -375,7 +380,7 @@
     /* SYM_REF2(duration_c, neg, interval) */
     void *visit(duration_c *symbol) {
       if (symbol->neg != NULL)
-        ERROR;
+        {STAGE4_ERROR(symbol, symbol, "Negative TIME literals are not currently supported"); ERROR;}
       symbol->interval->accept(*this);
       return NULL;
     }
@@ -2484,6 +2489,7 @@
 
           if (configuration_count++) {
             /* the first configuration is the one we will use!! */
+            STAGE4_ERROR(symbol, symbol, "A previous CONFIGURATION has already been declared (C code generation currently only allows a single configuration).");
             ERROR;
           }
 
@@ -2494,7 +2500,7 @@
             symbol->accept(calculate_common_ticktime);
             common_ticktime = calculate_common_ticktime.get_common_ticktime();
             if (common_ticktime == 0) {
-              fprintf(stderr, "\nYou must at least define a periodic task to set cycle period!");
+              STAGE4_ERROR(symbol, symbol, "You must define at least one periodic task (to set cycle period)!");
               ERROR;
             }
 
--- a/stage4/stage4.cc	Tue Apr 17 17:41:58 2012 +0200
+++ b/stage4/stage4.cc	Wed Apr 18 13:29:08 2012 +0100
@@ -48,7 +48,23 @@
 #include "stage4.hh"
 
 
-
+#define FIRST_(symbol1, symbol2) (((symbol1)->first_order < (symbol2)->first_order)   ? (symbol1) : (symbol2))
+#define  LAST_(symbol1, symbol2) (((symbol1)->last_order  > (symbol2)->last_order)    ? (symbol1) : (symbol2))
+#include <stdarg.h>
+
+void stage4err(const char *stage4_generator_id, symbol_c *symbol1, symbol_c *symbol2, const char *errmsg, ...) {
+    va_list argptr;
+    va_start(argptr, errmsg); /* second argument is last fixed pamater of stage4err() */
+
+    fprintf(stderr, "%s:%d-%d..%d-%d: error %s: ",
+            FIRST_(symbol1,symbol2)->first_file, FIRST_(symbol1,symbol2)->first_line, FIRST_(symbol1,symbol2)->first_column,
+                                                 LAST_(symbol1,symbol2) ->last_line,  LAST_(symbol1,symbol2) ->last_column,
+            stage4_generator_id);
+    vfprintf(stderr, errmsg, argptr);
+    fprintf(stderr, "\n");
+    // error_count++;
+    va_end(argptr);
+}
 
 
 
--- a/stage4/stage4.hh	Tue Apr 17 17:41:58 2012 +0200
+++ b/stage4/stage4.hh	Wed Apr 18 13:29:08 2012 +0100
@@ -39,6 +39,10 @@
 
 #include "../absyntax/absyntax.hh"
 
+
+void stage4err(const char *stage4_generator_id, symbol_c *symbol1, symbol_c *symbol2, const char *errmsg, ...);
+
+
 class stage4out_c {
   public:
     std::string indent_level;