diff options
| author | Andrew Kelley <superjoe30@gmail.com> | 2016-02-27 22:06:46 -0700 |
|---|---|---|
| committer | Andrew Kelley <superjoe30@gmail.com> | 2016-03-01 03:13:40 -0700 |
| commit | f1d338194e9a00e56a42da1298f2ac0ed75797df (patch) | |
| tree | 6768d247960a6e8006fbffa00206ce44152c66d5 /src/errmsg.cpp | |
| parent | 28fe994a107b4f66d840c50df614504ac2387587 (diff) | |
| download | zig-f1d338194e9a00e56a42da1298f2ac0ed75797df.tar.gz zig-f1d338194e9a00e56a42da1298f2ac0ed75797df.zip | |
rewrite how importing works
* Introduce the concept of packages. Closes #3
* Add support for error notes.
* Introduce `@import` and `@c_import` builtin functions and
remove the `import` and `c_import` top level declarations.
* Introduce the `use` top level declaration.
* Add `--check-unused` parameter to perform semantic
analysis and codegen on all top level declarations, not
just exported ones and ones referenced by exported ones.
* Delete the root export node and add `--library` argument.
Diffstat (limited to 'src/errmsg.cpp')
| -rw-r--r-- | src/errmsg.cpp | 45 |
1 files changed, 33 insertions, 12 deletions
diff --git a/src/errmsg.cpp b/src/errmsg.cpp index e8ab353efc..7920620418 100644 --- a/src/errmsg.cpp +++ b/src/errmsg.cpp @@ -4,36 +4,57 @@ #include <stdio.h> #define RED "\x1b[31;1m" -#define WHITE "\x1b[37;1m" #define GREEN "\x1b[32;1m" +#define CYAN "\x1b[36;1m" +#define WHITE "\x1b[37;1m" #define RESET "\x1b[0m" -void print_err_msg(ErrorMsg *err, ErrColor color) { +enum ErrType { + ErrTypeError, + ErrTypeNote, +}; + +static void print_err_msg_type(ErrorMsg *err, ErrColor color, ErrType err_type) { + const char *path = buf_ptr(err->path); + int line = err->line_start + 1; + int col = err->column_start + 1; + const char *text = buf_ptr(err->msg); + + if (color == ErrColorOn || (color == ErrColorAuto && os_stderr_tty())) { - fprintf(stderr, WHITE "%s:%d:%d: " RED "error:" WHITE " %s" RESET "\n", - buf_ptr(err->path), - err->line_start + 1, err->column_start + 1, - buf_ptr(err->msg)); + if (err_type == ErrTypeError) { + fprintf(stderr, WHITE "%s:%d:%d: " RED "error:" WHITE " %s" RESET "\n", path, line, col, text); + } else if (err_type == ErrTypeNote) { + fprintf(stderr, WHITE "%s:%d:%d: " CYAN "note:" WHITE " %s" RESET "\n", path, line, col, text); + } else { + zig_unreachable(); + } fprintf(stderr, "%s\n", buf_ptr(&err->line_buf)); for (int i = 0; i < err->column_start; i += 1) { fprintf(stderr, " "); } fprintf(stderr, GREEN "^" RESET "\n"); - } else { - fprintf(stderr, "%s:%d:%d: error: %s\n", - buf_ptr(err->path), - err->line_start + 1, err->column_start + 1, - buf_ptr(err->msg)); + if (err_type == ErrTypeError) { + fprintf(stderr, "%s:%d:%d: error: %s\n", path, line, col, text); + } else if (err_type == ErrTypeNote) { + fprintf(stderr, " %s:%d:%d: note: %s\n", path, line, col, text); + } else { + zig_unreachable(); + } } for (int i = 0; i < err->notes.length; i += 1) { ErrorMsg *note = err->notes.at(i); - print_err_msg(note, color); + print_err_msg_type(note, color, ErrTypeNote); } } +void print_err_msg(ErrorMsg *err, ErrColor color) { + print_err_msg_type(err, color, ErrTypeError); +} + void err_msg_add_note(ErrorMsg *parent, ErrorMsg *note) { parent->notes.append(note); } |
