diff options
| author | phillvancejr <phillipvancejr@gmail.com> | 2022-02-04 13:15:43 -0500 |
|---|---|---|
| committer | phillvancejr <phillipvancejr@gmail.com> | 2022-02-04 13:16:40 -0500 |
| commit | 42364f2fcee1f0f588b006bf2b7e9bc6f88acb93 (patch) | |
| tree | cb285ae39974d72e2f384922204b27acc67317e7 /core/bindgen/errors.odin | |
| parent | 8f600798ef201ce3f34e29d7cdbf07b9bfc5db21 (diff) | |
sync with main
Diffstat (limited to 'core/bindgen/errors.odin')
| -rw-r--r-- | core/bindgen/errors.odin | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/core/bindgen/errors.odin b/core/bindgen/errors.odin new file mode 100644 index 000000000..9564c5244 --- /dev/null +++ b/core/bindgen/errors.odin @@ -0,0 +1,44 @@ +package bindgen + +import "core:fmt" +import "core:os" + +seenWarnings : map[string]bool; + +print_warning :: proc(args : ..any) { + message := tcat(..args); + + if !seenWarnings[message] { + fmt.eprint("[bindgen] Warning: ", message, "\n"); + seenWarnings[message] = true; + } +} + +print_error :: proc(data : ^ParserData, loc := #caller_location, args : ..any) { + message := tcat(..args); + + min : u32 = 0; + for i := data.offset - 1; i > 0; i -= 1 { + if data.bytes[i] == '\n' { + min = i + 1; + break; + } + } + + max := min + 200; + for i := min + 1; i < max; i += 1 { + if data.bytes[i] == '\n' { + max = i; + break; + } + } + + line, _ := get_line_column(data); + + fmt.eprint("[bindgen] Error: ", message, "\n"); + fmt.eprint("[bindgen] ... from ", loc.procedure, "\n"); + fmt.eprint("[bindgen] ... at line ", line, " within this context:\n"); + fmt.eprint("> ", extract_string(data, min, max), "\n"); + + os.exit(1); +} |