diff --git a/analyser/module_analyser.c2 b/analyser/module_analyser.c2 index 78611a14..1b55303d 100644 --- a/analyser/module_analyser.c2 +++ b/analyser/module_analyser.c2 @@ -29,7 +29,7 @@ import name_vector local; import src_loc local; import scope; import string_pool; -import warning_flags; +import warning_flags local; import struct_func_list as sf_list; import incr_array_list as ia_list; import value_type local; @@ -49,7 +49,7 @@ public type Analyser struct @(opaque) { string_pool.Pool* astPool; ast_builder.Builder* builder; module_list.List* allmodules; - const warning_flags.Flags* warnings; + const WarningFlags* warnings; // variables below differs per run Module* mod; @@ -93,7 +93,7 @@ public fn Analyser* create(diagnostics.Diags* diags, string_pool.Pool* astPool, ast_builder.Builder* builder, module_list.List* allmodules, - const warning_flags.Flags* warnings, + const WarningFlags* warnings, bool has_asserts, bool check_only) { Analyser* ma = stdlib.calloc(1, sizeof(Analyser)); @@ -328,10 +328,10 @@ fn void Analyser.note(Analyser* ma, SrcLoc loc, const char* format @(printf_form va_end(args); } -fn void Analyser.warn(Analyser* ma, SrcLoc loc, const char* format @(printf_format), ...) { +fn void Analyser.warn(Analyser* ma, WarningKind wk, SrcLoc loc, const char* format @(printf_format), ...) { va_list args; va_start(args, format); - ma.diags.warn2(loc, format, args); + ma.diags.warn2(wk, loc, format, args); va_end(args); } @@ -362,7 +362,7 @@ fn void Analyser.createGlobalScope(void* arg, AST* a) { a.getImports(), ma.mod, ma.mod.getSymbols(), - !ma.warnings.no_unused_variable); + ma.warnings.test(W_unused_variable)); a.setPtr(s); } diff --git a/analyser/module_analyser_call.c2 b/analyser/module_analyser_call.c2 index c4cb0002..53b1ede6 100644 --- a/analyser/module_analyser_call.c2 +++ b/analyser/module_analyser_call.c2 @@ -97,10 +97,10 @@ fn QualType Analyser.analyseCallExpr(Analyser* ma, Expr** e_ptr) { } } - if (fd.hasAttrDeprecated() && !ma.warnings.no_deprecated) { + if (fd.hasAttrDeprecated() && ma.warnings.test(W_deprecated)) { const Attr* deprecated = ((Decl*)fd).getAttr(Deprecated); const char* msg = ma.astPool.idx2str(deprecated.value.text); - ma.warn(origFn.getLoc(), "function %s is deprecated: %s", fd.asDecl().getFullName(), msg); + ma.warn(W_deprecated, origFn.getLoc(), "function %s is deprecated: %s", fd.asDecl().getFullName(), msg); //return QualType_Invalid; } @@ -700,7 +700,7 @@ fn FunctionDecl* Analyser.instantiateTemplateFunction(Analyser* ma, CallExpr* ca d.getAST().getImports(), template_mod, template_mod.getSymbols(), - !ma.warnings.no_unused_variable); + ma.warnings.test(W_unused_variable)); analyser.analyseFunctionBody(instance, tmpScope); tmpScope.free(); analyser.free(); diff --git a/analyser/module_analyser_function.c2 b/analyser/module_analyser_function.c2 index 78207da2..98ff5d2d 100644 --- a/analyser/module_analyser_function.c2 +++ b/analyser/module_analyser_function.c2 @@ -55,7 +55,7 @@ fn void Analyser.analyseFunction(Analyser* ma, FunctionDecl* fd) { } if (canon.isConst()) { - ma.warn(rtype.getLoc(), "'const' type qualifier on return type has no effect"); + ma.warn(W_const_return_type, rtype.getLoc(), "'const' type qualifier on return type has no effect"); } bool is_public = fd.asDecl().isPublic(); @@ -227,7 +227,7 @@ fn bool Analyser.analyseFunctionBody2(Analyser* ma, FunctionDecl* fd, Module* mo fd.asDecl().getAST().getImports(), mod, mod.getSymbols(), - !ma.warnings.no_unused_variable); + ma.warnings.test(W_unused_variable)); analyser.analyseFunctionBody(fd, tmpScope); bool has_error = analyser.has_error; tmpScope.free(); @@ -281,12 +281,12 @@ fn void Analyser.analyseFunctionBody(Analyser* ma, FunctionDecl* fd, scope.Scope } } - if (!ma.warnings.no_unused_parameter && !fd.hasAttrUnusedParams()) { + if (ma.warnings.test(W_unused_parameter) && !fd.hasAttrUnusedParams()) { for (u32 i=0; i> k) & 1; +} + +#if 0 +public fn void WarningFlags.set(WarningFlags *wf, WarningKind k) { + wf.flags |= (u64)1 << k; +} + +public fn void WarningFlags.clear(WarningFlags *wf, WarningKind k) { + wf.flags &= ~((u64)1 << k); +} + +public fn void WarningFlags.setError(WarningFlags *wf, WarningKind k) { + wf.err_flags |= (u64)1 << k; +} + +public fn void WarningFlags.clearError(WarningFlags *wf, WarningKind k) { + wf.err_flags &= ~((u64)1 << k); +} + +public fn void WarningFlags.setAllError(WarningFlags *wf) { wf.err_flags = (u64)-1; } +public fn void WarningFlags.clearAllError(WarningFlags *wf) { wf.err_flags = 0; } +#endif + +public fn void WarningFlags.setAll(WarningFlags *wf) { wf.flags = (u64)-1; } +public fn void WarningFlags.clearAll(WarningFlags *wf) { wf.flags = 0; } + +public fn bool WarningFlags.isError(const WarningFlags *wf, WarningKind k) { + return (wf.err_flags >> k) & 1; } +public fn bool WarningFlags.parseOption(WarningFlags *warnings, const char* option) { + bool enable = true; + if (!string.strncmp(option, "no-", 3)) { + enable = false; + option += 3; + } + if (!string.strncmp(option, "error=", 6)) { + u64 mask = WarningKind.getMask(option + 6); + if (!mask) return false; + if (enable) warnings.err_flags |= mask; + else warnings.err_flags &= ~mask; + return true; + } + if (!string.strcmp(option, "error") + || !string.strcmp(option, "promote-to-error")) { + if (enable) warnings.err_flags = (u64)-1; + else warnings.err_flags = 0; + return true; + } else { + u64 mask = WarningKind.getMask(option); + if (!mask) return false; + if (enable) warnings.flags |= mask; + else warnings.flags &= ~mask; + return true; + } +} diff --git a/compiler/c2recipe_parser.c2 b/compiler/c2recipe_parser.c2 index e42af6fa..4eace391 100644 --- a/compiler/c2recipe_parser.c2 +++ b/compiler/c2recipe_parser.c2 @@ -23,7 +23,7 @@ import source_mgr; import src_loc local; import string_list; import string_pool; -import warning_flags; +import warning_flags local; import csetjmp local; import stdarg local; @@ -532,70 +532,13 @@ fn void Parser.parsePlugin(Parser* p, bool is_global) { fn void Parser.parseWarnings(Parser* p) { p.consumeToken(); p.expect(Text, "expect options"); - warning_flags.Flags* warnings = p.target.getWarnings2(); + WarningFlags* warnings = p.target.getWarnings2(); // TODO no need to store in string pool while (p.is(Text)) { const char* option = p.pool.idx2str(p.token.value); - bool disable = false; - if (!string.strncmp(option, "no-", 3)) { - disable = true; - option += 3; - } - switch (option) { - case "unused": - warnings.no_unused = disable; - warnings.no_unused_variable = disable; - warnings.no_unused_function = disable; - warnings.no_unused_parameter = disable; - warnings.no_unused_type = disable; - warnings.no_unused_module = disable; - warnings.no_unused_import = disable; - warnings.no_unused_public = disable; - warnings.no_unused_label = disable; - warnings.no_unused_enum_constant = disable; - break; - case "unused-variable": - warnings.no_unused_variable = disable; - break; - case "unused-function": - warnings.no_unused_function = disable; - break; - case "unused-parameter": - warnings.no_unused_parameter = disable; - break; - case "unused-type": - warnings.no_unused_type = disable; - break; - case "unused-module": - warnings.no_unused_module = disable; - break; - case "unused-import": - warnings.no_unused_import = disable; - break; - case "unused-public": - warnings.no_unused_public = disable; - break; - case "unused-label": - warnings.no_unused_label = disable; - break; - case "unused-enum-constant": - warnings.no_unused_enum_constant = disable; - break; - case "unreachable-code": - warnings.no_unreachable_code = disable; - break; - case "unknown-attribute": - warnings.no_unknown_attribute = disable; - break; - case "deprecated": - warnings.no_deprecated = disable; - break; - case "promote-to-error": - warnings.are_errors = !disable; - break; - default: - p.warning("unknown warning '%s'", option); - break; + if (!warnings.parseOption(option)) { + if (warnings.test(W_unknown_warning)) + p.warning("unknown warning '%s'", option); } p.consumeToken(); } diff --git a/compiler/compiler.c2 b/compiler/compiler.c2 index c5f06db3..8cc6ea07 100644 --- a/compiler/compiler.c2 +++ b/compiler/compiler.c2 @@ -199,7 +199,8 @@ fn void Compiler.build(Compiler* c, c.target.disableAsserts(); } - diags.setWarningAsError(target.getWarnings().are_errors); + //diags.setWarningAsError(target.getWarnings().are_errors); + c.diags.setWarnings(target.getWarnings()); c.diags.clear(); c.context = ast_context.create(16*1024); diff --git a/compiler/compiler_analyse.c2 b/compiler/compiler_analyse.c2 index 57381420..c468d6f1 100644 --- a/compiler/compiler_analyse.c2 +++ b/compiler/compiler_analyse.c2 @@ -23,7 +23,7 @@ import module_sorter; import string_list; import unused_checker; import utils; -import warning_flags; +import warning_flags local; fn bool Compiler.analyse(Compiler* c) { u64 analysis_start = utils.now(); @@ -64,8 +64,8 @@ fn bool Compiler.analyse(Compiler* c) { c.checkMain(); // check unused - const warning_flags.Flags* warnings = c.target.getWarnings(); - if (!warnings.no_unused) { + const WarningFlags* warnings = c.target.getWarnings(); + if (warnings.test(W_unused)) { c.mainComp.visitModules(Compiler.checkUnused, c); } diff --git a/compiler/main.c2 b/compiler/main.c2 index e7fa2ccd..7f2e8be6 100644 --- a/compiler/main.c2 +++ b/compiler/main.c2 @@ -494,7 +494,7 @@ fn void Context.handle_args(Context* c, i32 argc, char** argv) { for (u32 i = 0; i < c.opts.files.length(); i++) t.addFile(c.opts.files.get_idx(i), 0); - t.disableWarnings(); + //t.disableWarnings(); } else { if (c.opts.use_ir_backend) { console.error("c2c: the IR backend is currently experimental and only works on individual files, not recipes"); diff --git a/parser/c2_parser.c2 b/parser/c2_parser.c2 index b6fce041..e298b5db 100644 --- a/parser/c2_parser.c2 +++ b/parser/c2_parser.c2 @@ -182,7 +182,7 @@ fn void Parser.on_tokenizer_error(void* arg, c2_tokenizer.ErrorLevel level, SrcL p.diags.note(loc, "%s", msg); break; case Warning: - p.diags.warn(loc, "%s", msg); + p.diags.warn(W_unknown, loc, "%s", msg); break; default: p.diags.error(loc, "%s", msg);