فهرست منبع

Improved error handling and detection

Marco Bambini 5 سال پیش
والد
کامیت
5f7c0aa62f
4فایلهای تغییر یافته به همراه15 افزوده شده و 13 حذف شده
  1. 5 5
      src/compiler/gravity_codegen.c
  2. 2 0
      src/compiler/gravity_semacheck1.c
  3. 6 6
      src/compiler/gravity_semacheck2.c
  4. 2 2
      src/shared/gravity_value.h

+ 5 - 5
src/compiler/gravity_codegen.c

@@ -64,20 +64,20 @@ typedef struct codegen_t codegen_t;
 static void report_error (gvisitor_t *self, gnode_t *node, const char *format, ...) {
     codegen_t *current = (codegen_t *)self->data;
     
-     // check last error line in order to prevent to emit multiple errors for the same row
+    // check last error line in order to prevent to emit multiple errors for the same row
+    if (node && node->token.lineno == current->lasterror) return;
+    
     // increment internal error counter and save location of the last reported error (no WARNING cases here)
     ++self->nerr;
     current->lasterror = (node) ? node->token.lineno : 0;
-    
-    if (!node || node->token.lineno == current->lasterror) return;
 
     // get error callback (if any)
     void *data = (self->delegate) ? ((gravity_delegate_t *)self->delegate)->xdata : NULL;
     gravity_error_callback error_fn = (self->delegate) ? ((gravity_delegate_t *)self->delegate)->error_callback : NULL;
 
     // build error message
-    char        buffer[1024];
-    va_list        arg;
+    char buffer[1024];
+    va_list arg;
     if (format) {
         va_start (arg, format);
         vsnprintf(buffer, sizeof(buffer), format, arg);

+ 2 - 0
src/compiler/gravity_semacheck1.c

@@ -30,6 +30,8 @@ static int ident =0;
 // MARK: -
 
 static void report_error (gvisitor_t *self, gnode_t *node, const char *format, ...) {
+    // TODO: add lasterror here like in semacheck2
+    
     // increment internal error counter
     ++self->nerr;
 

+ 6 - 6
src/compiler/gravity_semacheck2.c

@@ -52,13 +52,13 @@ static void report_error (gvisitor_t *self, error_type_t error_type, gnode_t *no
     semacheck_t *current = (semacheck_t *)self->data;
     
     // check last error line in order to prevent to emit multiple errors for the same row
+    if (node && node->token.lineno == current->lasterror) return;
+    
     // increment internal error counter (and save last reported line) only if it was a real error
     if (error_type != GRAVITY_WARNING) {
         ++self->nerr;
         current->lasterror = (node) ? node->token.lineno : 0;
     }
-    
-    if (!node || node->token.lineno == current->lasterror) return;
 
     // get error callback (if any)
     void *data = (self->delegate) ? ((gravity_delegate_t *)self->delegate)->xdata : NULL;
@@ -75,10 +75,10 @@ static void report_error (gvisitor_t *self, error_type_t error_type, gnode_t *no
 
     // setup error struct
     error_desc_t error_desc = {
-        .lineno = node->token.lineno,
-        .colno = node->token.colno,
-        .fileid = node->token.fileid,
-        .offset = node->token.position
+        .lineno = (node) ? node->token.lineno : 0,
+        .colno = (node) ? node->token.colno : 0,
+        .fileid = (node) ? node->token.fileid : 0,
+        .offset = (node) ? node->token.position : 0
     };
 
     // finally call error callback

+ 2 - 2
src/shared/gravity_value.h

@@ -66,8 +66,8 @@
 extern "C" {
 #endif
 
-#define GRAVITY_VERSION						"0.7.9"     // git tag 0.7.9
-#define GRAVITY_VERSION_NUMBER				0x000709    // git push --tags
+#define GRAVITY_VERSION						"0.8.0"     // git tag 0.8.0
+#define GRAVITY_VERSION_NUMBER				0x000800    // git push --tags
 #define GRAVITY_BUILD_DATE                  __DATE__
 
 #ifndef GRAVITY_ENABLE_DOUBLE