diff options
| author | 2022-08-08 16:06:08 +0200 | |
|---|---|---|
| committer | 2022-08-08 16:06:08 +0200 | |
| commit | fc55daf22dd890860ac9c1a0a29900977a700df2 (patch) | |
| tree | 96735ed737ae499c9dbbf54ad7bec44c6a4b6eb0 /bootstrap/parse.c | |
| parent | cc325dce01101e8b488cfc7e9fddfe0f778c7e17 (diff) | |
start self hosted comler
Diffstat (limited to 'bootstrap/parse.c')
| -rw-r--r-- | bootstrap/parse.c | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/bootstrap/parse.c b/bootstrap/parse.c index 1327e71..67ec66d 100644 --- a/bootstrap/parse.c +++ b/bootstrap/parse.c @@ -621,7 +621,7 @@ exprdup(struct expr ex) { } static const struct type *parseagg(struct parser *P, const char *name, int kind, struct decl **retdecl); -static const struct type *parseenum(struct parser *P, const char *name); +static const struct type *parseenum(struct parser *P, const char *name, struct attr); static const struct type * parseexpandtepl(struct parser *P, struct tepl *tepl) { @@ -763,7 +763,7 @@ parsetype(struct parser *P) { struct decl *_decl; return parseagg(P, NULL, TYunion, &_decl); } else if (lexmatch(P, &tok, TKkw_enum)) { - return parseenum(P, NULL); + return parseenum(P, NULL, (struct attr){0}); } else if (lexmatch(P, &tok, TKkw_typeof)) { const struct type *ty = NULL, *ty2, *ty0; lexexpect(P, '('); @@ -2534,12 +2534,13 @@ parsemacro(struct parser *P) { } static const struct type * -parseenum(struct parser *P, const char *name) { +parseenum(struct parser *P, const char *name, struct attr attr) { struct tok tok; struct type ty = {TYenum}; static int id = 0; i64 iota = 0, max = 0, min = 0; vec_t(struct enumval) vals = {0}; + ty.enu.lax = attr.lax; if (lexmatch(P, &tok, ':')) { ty.enu.intty = unconstify(parsetype(P)); @@ -2905,6 +2906,18 @@ parsedecl(decl_yielder_t yield, void *yarg, struct parser *P, bool toplevel) { int kind; struct decl decl = {0}; struct decl* decl2 = NULL; + struct attr attr = {0}; + + if (lexmatch(P, &tok, '#')) { + lexexpect(P, '['); + while (!lexmatch(P, NULL, ']')) { + const char *a = (tok = lexexpect(P, TKident)).str; + if (!strcmp(a, "lax")) + attr.lax = 1; + else + fatal(P, tok.span, "unknown attribute %T", tok); + } + } if (lexmatch(P, &tok, TKkw_extern)) externp = 1; @@ -2955,7 +2968,7 @@ parsedecl(decl_yielder_t yield, void *yarg, struct parser *P, bool toplevel) { } else { if (externp) fatal(P, tok.span, "enum cannot be `extern'"); decl.name = lexexpects(P, TKident, "enum name").str; - decl.ty = parseenum(P, decl.name); + decl.ty = parseenum(P, decl.name, attr); } } else if (lexmatch(P, &tok, TKkw_struct)) { kind = TYstruct; |