Skip to content

Commit 5f7c0aa

Browse files
committed
Improved error handling and detection
1 parent de32af6 commit 5f7c0aa

File tree

4 files changed

+15
-13
lines changed

4 files changed

+15
-13
lines changed

src/compiler/gravity_codegen.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,20 +64,20 @@ typedef struct codegen_t codegen_t;
6464
static void report_error (gvisitor_t *self, gnode_t *node, const char *format, ...) {
6565
codegen_t *current = (codegen_t *)self->data;
6666

67-
// check last error line in order to prevent to emit multiple errors for the same row
67+
// check last error line in order to prevent to emit multiple errors for the same row
68+
if (node && node->token.lineno == current->lasterror) return;
69+
6870
// increment internal error counter and save location of the last reported error (no WARNING cases here)
6971
++self->nerr;
7072
current->lasterror = (node) ? node->token.lineno : 0;
71-
72-
if (!node || node->token.lineno == current->lasterror) return;
7373

7474
// get error callback (if any)
7575
void *data = (self->delegate) ? ((gravity_delegate_t *)self->delegate)->xdata : NULL;
7676
gravity_error_callback error_fn = (self->delegate) ? ((gravity_delegate_t *)self->delegate)->error_callback : NULL;
7777

7878
// build error message
79-
char buffer[1024];
80-
va_list arg;
79+
char buffer[1024];
80+
va_list arg;
8181
if (format) {
8282
va_start (arg, format);
8383
vsnprintf(buffer, sizeof(buffer), format, arg);

src/compiler/gravity_semacheck1.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ static int ident =0;
3030
// MARK: -
3131

3232
static void report_error (gvisitor_t *self, gnode_t *node, const char *format, ...) {
33+
// TODO: add lasterror here like in semacheck2
34+
3335
// increment internal error counter
3436
++self->nerr;
3537

src/compiler/gravity_semacheck2.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,13 @@ static void report_error (gvisitor_t *self, error_type_t error_type, gnode_t *no
5252
semacheck_t *current = (semacheck_t *)self->data;
5353

5454
// check last error line in order to prevent to emit multiple errors for the same row
55+
if (node && node->token.lineno == current->lasterror) return;
56+
5557
// increment internal error counter (and save last reported line) only if it was a real error
5658
if (error_type != GRAVITY_WARNING) {
5759
++self->nerr;
5860
current->lasterror = (node) ? node->token.lineno : 0;
5961
}
60-
61-
if (!node || node->token.lineno == current->lasterror) return;
6262

6363
// get error callback (if any)
6464
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
7575

7676
// setup error struct
7777
error_desc_t error_desc = {
78-
.lineno = node->token.lineno,
79-
.colno = node->token.colno,
80-
.fileid = node->token.fileid,
81-
.offset = node->token.position
78+
.lineno = (node) ? node->token.lineno : 0,
79+
.colno = (node) ? node->token.colno : 0,
80+
.fileid = (node) ? node->token.fileid : 0,
81+
.offset = (node) ? node->token.position : 0
8282
};
8383

8484
// finally call error callback

src/shared/gravity_value.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@
6666
extern "C" {
6767
#endif
6868

69-
#define GRAVITY_VERSION "0.7.9" // git tag 0.7.9
70-
#define GRAVITY_VERSION_NUMBER 0x000709 // git push --tags
69+
#define GRAVITY_VERSION "0.8.0" // git tag 0.8.0
70+
#define GRAVITY_VERSION_NUMBER 0x000800 // git push --tags
7171
#define GRAVITY_BUILD_DATE __DATE__
7272

7373
#ifndef GRAVITY_ENABLE_DOUBLE

0 commit comments

Comments
 (0)