Skip to content

Commit

Permalink
Improved error handling and detection
Browse files Browse the repository at this point in the history
  • Loading branch information
marcobambini committed Nov 5, 2020
1 parent de32af6 commit 5f7c0aa
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 13 deletions.
10 changes: 5 additions & 5 deletions src/compiler/gravity_codegen.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions src/compiler/gravity_semacheck1.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
12 changes: 6 additions & 6 deletions src/compiler/gravity_semacheck2.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/shared/gravity_value.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 5f7c0aa

Please sign in to comment.