-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherror.c
54 lines (46 loc) · 1.25 KB
/
error.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
typedef struct {
char *filepath;
int line;
} SourcePos;
SourcePos pos_builtin = {.filepath = "<builtin>"};
void syntax_error_at(SourcePos pos, char *fmt, ...) {
va_list args;
va_start(args, fmt);
fprintf(stderr, "%s:%d: syntax error: ", pos.filepath, pos.line);
vfprintf(stderr, fmt, args);
fprintf(stderr, "\n");
va_end(args);
// TODO(shaw): DELETE ME! JUST FOR DEVELOPMENT!
assert(0);
}
#define syntax_error(...) syntax_error_at(token.pos, __VA_ARGS__)
void semantic_error(SourcePos pos, char *fmt, ...) {
va_list args;
va_start(args, fmt);
fprintf(stderr, "%s:%d: error: ", pos.filepath, pos.line);
vfprintf(stderr, fmt, args);
fprintf(stderr, "\n");
va_end(args);
// TODO(shaw): DELETE ME! JUST FOR DEVELOPMENT!
assert(0);
}
void fatal_semantic_error(SourcePos pos, char *fmt) {
semantic_error(pos, fmt);
exit(1);
}
void print_note(SourcePos pos, char *fmt, ...) {
va_list args;
va_start(args, fmt);
fprintf(stderr, "%s:%d: note: ", pos.filepath, pos.line);
vfprintf(stderr, fmt, args);
fprintf(stderr, "\n");
va_end(args);
}
void warning(SourcePos pos, char *fmt, ...) {
va_list args;
va_start(args, fmt);
fprintf(stderr, "%s:%d: warning: ", pos.filepath, pos.line);
vfprintf(stderr, fmt, args);
fprintf(stderr, "\n");
va_end(args);
}