diff options
| author | gingerBill <bill@gingerbill.org> | 2019-01-30 14:24:14 +0000 |
|---|---|---|
| committer | gingerBill <bill@gingerbill.org> | 2019-01-30 14:24:14 +0000 |
| commit | dee28d998ff6583dab49a57ee4b792d9e289a18f (patch) | |
| tree | 159c1cde3953d7f748848fc53ad32e3b305e038c /src | |
| parent | 96ef6aa7f34677a8fc46f7807f2d12346c02a5bb (diff) | |
Allow for @indent for attributes that don't require any parameters; Add -ignore-unknown-attributes
Diffstat (limited to 'src')
| -rw-r--r-- | src/build_settings.cpp | 1 | ||||
| -rw-r--r-- | src/checker.cpp | 4 | ||||
| -rw-r--r-- | src/main.cpp | 6 | ||||
| -rw-r--r-- | src/parser.cpp | 46 |
4 files changed, 37 insertions, 20 deletions
diff --git a/src/build_settings.cpp b/src/build_settings.cpp index 3b184ed12..ca9a77902 100644 --- a/src/build_settings.cpp +++ b/src/build_settings.cpp @@ -101,6 +101,7 @@ struct BuildContext { i32 optimization_level; bool show_timings; bool keep_temp_files; + bool ignore_unknown_attributes; bool no_bounds_check; bool no_output_files; bool no_crt; diff --git a/src/checker.cpp b/src/checker.cpp index 94006510a..9cac82911 100644 --- a/src/checker.cpp +++ b/src/checker.cpp @@ -2150,7 +2150,9 @@ void check_decl_attributes(CheckerContext *c, Array<Ast *> const &attributes, De } if (!proc(c, elem, name, value, ac)) { - error(elem, "Unknown attribute element name '%.*s'", LIT(name)); + if (!build_context.ignore_unknown_attributes) { + error(elem, "Unknown attribute element name '%.*s'", LIT(name)); + } } } } diff --git a/src/main.cpp b/src/main.cpp index 03368c709..dcea12aa7 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -215,6 +215,7 @@ enum BuildFlagKind { BuildFlag_NoCRT, BuildFlag_UseLLD, BuildFlag_Vet, + BuildFlag_IgnoreUnknownAttributes, BuildFlag_COUNT, }; @@ -258,6 +259,7 @@ bool parse_build_flags(Array<String> args) { add_flag(&build_flags, BuildFlag_NoCRT, str_lit("no-crt"), BuildFlagParam_None); add_flag(&build_flags, BuildFlag_UseLLD, str_lit("lld"), BuildFlagParam_None); add_flag(&build_flags, BuildFlag_Vet, str_lit("vet"), BuildFlagParam_None); + add_flag(&build_flags, BuildFlag_IgnoreUnknownAttributes, str_lit("-ignore-unknown-attributes"), BuildFlagParam_None); GB_ASSERT(args.count >= 3); Array<String> flag_args = array_slice(args, 3, args.count); @@ -569,6 +571,10 @@ bool parse_build_flags(Array<String> args) { case BuildFlag_Vet: build_context.vet = true; break; + + case BuildFlag_IgnoreUnknownAttributes: + build_context.ignore_unknown_attributes = true; + break; } } diff --git a/src/parser.cpp b/src/parser.cpp index ee67db3be..ab5f1589c 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -3650,30 +3650,38 @@ Ast *parse_foreign_decl(AstFile *f) { Ast *parse_attribute(AstFile *f, Token token, TokenKind open_kind, TokenKind close_kind) { Array<Ast *> elems = {}; - Token open = expect_token(f, open_kind); - f->expr_level++; - if (f->curr_token.kind != close_kind) { - elems = array_make<Ast *>(heap_allocator()); - while (f->curr_token.kind != close_kind && - f->curr_token.kind != Token_EOF) { - Ast *elem = nullptr; - elem = parse_ident(f); - if (f->curr_token.kind == Token_Eq) { - Token eq = expect_token(f, Token_Eq); - Ast *value = parse_value(f); - elem = ast_field_value(f, elem, value, eq); - } + Token open = {}; + Token close = {}; - array_add(&elems, elem); + if (f->curr_token.kind == Token_Ident) { + elems = array_make<Ast *>(heap_allocator(), 0, 1); + Ast *elem = parse_ident(f); + array_add(&elems, elem); + } else { + open = expect_token(f, open_kind); + f->expr_level++; + if (f->curr_token.kind != close_kind) { + elems = array_make<Ast *>(heap_allocator()); + while (f->curr_token.kind != close_kind && + f->curr_token.kind != Token_EOF) { + Ast *elem = nullptr; + elem = parse_ident(f); + if (f->curr_token.kind == Token_Eq) { + Token eq = expect_token(f, Token_Eq); + Ast *value = parse_value(f); + elem = ast_field_value(f, elem, value, eq); + } - if (!allow_token(f, Token_Comma)) { - break; + array_add(&elems, elem); + + if (!allow_token(f, Token_Comma)) { + break; + } } } + f->expr_level--; + close = expect_closing(f, close_kind, str_lit("attribute")); } - f->expr_level--; - Token close = expect_closing(f, close_kind, str_lit("attribute")); - Ast *attribute = ast_attribute(f, token, open, close, elems); Ast *decl = parse_stmt(f); |