Make -verbose-errors the default; -terse-errors to disable it

This commit is contained in:
gingerBill
2023-02-22 11:48:10 +00:00
parent f5d507a9b9
commit 090e30f07b
5 changed files with 40 additions and 12 deletions
+2 -2
View File
@@ -288,7 +288,7 @@ struct BuildContext {
bool ignore_warnings;
bool warnings_as_errors;
bool show_error_line;
bool hide_error_line;
bool ignore_lazy;
bool ignore_llvm_build;
@@ -1033,7 +1033,7 @@ gb_internal String get_fullpath_core(gbAllocator a, String path) {
}
gb_internal bool show_error_line(void) {
return build_context.show_error_line;
return !build_context.hide_error_line;
}
gb_internal bool has_asm_extension(String const &path) {
+5 -1
View File
@@ -1679,9 +1679,13 @@ gb_internal bool check_unary_op(CheckerContext *c, Operand *o, Token op) {
case Token_Not:
if (!is_type_boolean(type)) {
ERROR_BLOCK();
str = expr_to_string(o->expr);
error(op, "Operator '%.*s' is only allowed on boolean expression", LIT(op.string));
error(op, "Operator '%.*s' is only allowed on boolean expressions", LIT(op.string));
gb_string_free(str);
if (is_type_integer(type)) {
error_line("\tSuggestion: Did you mean to use the bitwise not operator '~'?\n");
}
}
break;
+24 -5
View File
@@ -121,7 +121,26 @@ gb_internal void end_error_block(void) {
isize n = global_error_collector.error_buffer.count;
if (n > 0) {
u8 *text = global_error_collector.error_buffer.data;
if (show_error_line() && n >= 2 && !(text[n-2] == '\n' && text[n-1] == '\n')) {
bool add_extra_newline = false;
if (show_error_line()) {
if (n >= 2 && !(text[n-2] == '\n' && text[n-1] == '\n')) {
add_extra_newline = true;
}
} else {
isize newline_count = 0;
for (isize i = 0; i < n; i++) {
if (text[i] == '\n') {
newline_count += 1;
}
}
if (newline_count > 1) {
add_extra_newline = true;
}
}
if (add_extra_newline) {
// add an extra new line as padding when the error line is being shown
error_line("\n");
}
@@ -198,12 +217,12 @@ gb_internal bool show_error_on_line(TokenPos const &pos, TokenPos end) {
// TODO(bill): This assumes ASCII
enum {
MAX_LINE_LENGTH = 76,
MAX_LINE_LENGTH = 80,
MAX_TAB_WIDTH = 8,
ELLIPSIS_PADDING = 8
ELLIPSIS_PADDING = 8 // `... ...`
};
error_out("\n\t");
error_out("\t");
if (line.len+MAX_TAB_WIDTH+ELLIPSIS_PADDING > MAX_LINE_LENGTH) {
i32 const half_width = MAX_LINE_LENGTH/2;
i32 left = cast(i32)(offset);
@@ -244,7 +263,7 @@ gb_internal bool show_error_on_line(TokenPos const &pos, TokenPos end) {
}
}
error_out("\n\n");
error_out("\n");
return true;
}
return false;
+1 -3
View File
@@ -578,9 +578,7 @@ gb_internal ExactValue exact_unary_operator_value(TokenKind op, ExactValue v, i3
}
}
failure:
GB_PANIC("Invalid unary operation, %.*s", LIT(token_strings[op]));
failure:;
ExactValue error_value = {};
return error_value;
}
+8 -1
View File
@@ -659,6 +659,7 @@ enum BuildFlagKind {
BuildFlag_IgnoreWarnings,
BuildFlag_WarningsAsErrors,
BuildFlag_TerseErrors,
BuildFlag_VerboseErrors,
BuildFlag_ErrorPosStyle,
@@ -832,6 +833,7 @@ gb_internal bool parse_build_flags(Array<String> args) {
add_flag(&build_flags, BuildFlag_IgnoreWarnings, str_lit("ignore-warnings"), BuildFlagParam_None, Command_all);
add_flag(&build_flags, BuildFlag_WarningsAsErrors, str_lit("warnings-as-errors"), BuildFlagParam_None, Command_all);
add_flag(&build_flags, BuildFlag_TerseErrors, str_lit("terse-errors"), BuildFlagParam_None, Command_all);
add_flag(&build_flags, BuildFlag_VerboseErrors, str_lit("verbose-errors"), BuildFlagParam_None, Command_all);
add_flag(&build_flags, BuildFlag_ErrorPosStyle, str_lit("error-pos-style"), BuildFlagParam_String, Command_all);
@@ -1462,8 +1464,13 @@ gb_internal bool parse_build_flags(Array<String> args) {
}
break;
}
case BuildFlag_TerseErrors:
build_context.hide_error_line = true;
break;
case BuildFlag_VerboseErrors:
build_context.show_error_line = true;
gb_printf_err("-verbose-errors is not the default, -terse-errors can now disable it\n");
build_context.hide_error_line = false;
break;
case BuildFlag_ErrorPosStyle: