diff --git a/analyser/module_analyser.c2 b/analyser/module_analyser.c2 index 22e30bc72..bf7410d1b 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; @@ -48,7 +48,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; @@ -84,7 +84,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) { Analyser* ma = stdlib.calloc(1, sizeof(Analyser)); ma.diags = diags; @@ -296,10 +296,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); } @@ -330,7 +330,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 0d96d76e2..5d9acccbd 100644 --- a/analyser/module_analyser_call.c2 +++ b/analyser/module_analyser_call.c2 @@ -73,11 +73,11 @@ 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 AST* a = ((Decl*)fd).getAST(); const Attr* deprecated = a.getAttr(((Decl*)fd), 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; } @@ -663,7 +663,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 57ef57214..52728aa2e 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() && !canon.isPointer()) { - 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(); @@ -256,12 +256,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 84e1a25d5..7d1782b7c 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; @@ -412,7 +412,7 @@ fn void Parser.lex_option(Parser* p, Token* result) { case "warnings": result.kind = Kind.Warnings; break; - case "backend": + case "backend": result.kind = Kind.Backend; break; case "disable-asserts": @@ -528,70 +528,13 @@ fn void Parser.parsePlugin(Parser* p, bool is_global) { fn void Parser.parseWarnings(Parser* p) { p.consumeToken(); p.expect(Kind.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(Kind.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 93b0d0a9d..4d5dd8cf2 100644 --- a/compiler/compiler.c2 +++ b/compiler/compiler.c2 @@ -181,7 +181,8 @@ fn void Compiler.build(Compiler* c, c.opts = opts; c.pluginHandler = pluginHandler; - 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 573814208..c468d6f1f 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 46dc9ca21..ea8363e32 100644 --- a/compiler/main.c2 +++ b/compiler/main.c2 @@ -471,7 +471,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 29a25ee22..2a629fd59 100644 --- a/parser/c2_parser.c2 +++ b/parser/c2_parser.c2 @@ -169,7 +169,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); diff --git a/tools/tester/test_db.c2 b/tools/tester/test_db.c2 index 429d61649..3065d4ced 100644 --- a/tools/tester/test_db.c2 +++ b/tools/tester/test_db.c2 @@ -321,7 +321,7 @@ fn bool Db.parseRecipe(Db* db) { db.skipLine(); } - return true; + //return true; } fn bool Db.parseFile(Db* db) {