diff options
author | Michael Forney <mforney@mforney.org> | 2022-08-05 12:01:17 -0700 |
---|---|---|
committer | Michael Forney <mforney@mforney.org> | 2022-08-05 12:01:17 -0700 |
commit | 2ef7f2ebdce0f52d112c4c1ccbd731b2702e0ffb (patch) | |
tree | ed075c49d1167ad57f9d0b549dd12b2a39c16305 | |
parent | 83116cabc84ff3478ea19be38e8891d83a60acd6 (diff) |
Add new C23 keywords
-rw-r--r-- | cc.h | 21 | ||||
-rw-r--r-- | decl.c | 14 | ||||
-rw-r--r-- | expr.c | 2 | ||||
-rw-r--r-- | pp.c | 32 | ||||
-rw-r--r-- | token.c | 21 |
5 files changed, 61 insertions, 29 deletions
@@ -15,11 +15,15 @@ enum tokenkind { TSTRINGLIT, /* keyword */ + TALIGNAS, + TALIGNOF, TAUTO, + TBOOL, TBREAK, TCASE, TCHAR, TCONST, + TCONSTEXPR, TCONTINUE, TDEFAULT, TDO, @@ -27,6 +31,7 @@ enum tokenkind { TELSE, TENUM, TEXTERN, + TFALSE, TFLOAT, TFOR, TGOTO, @@ -34,6 +39,7 @@ enum tokenkind { TINLINE, TINT, TLONG, + TNULLPTR, TREGISTER, TRESTRICT, TRETURN, @@ -41,27 +47,30 @@ enum tokenkind { TSIGNED, TSIZEOF, TSTATIC, + TSTATIC_ASSERT, TSTRUCT, TSWITCH, + TTHREAD_LOCAL, + TTRUE, TTYPEDEF, + TTYPEOF, + TTYPEOF_UNQUAL, TUNION, TUNSIGNED, TVOID, TVOLATILE, TWHILE, - T_ALIGNAS, - T_ALIGNOF, T_ATOMIC, - T_BOOL, + T_BITINT, T_COMPLEX, + T_DECIMAL128, + T_DECIMAL32, + T_DECIMAL64, T_GENERIC, T_IMAGINARY, T_NORETURN, - T_STATIC_ASSERT, - T_THREAD_LOCAL, T__ASM__, T__ATTRIBUTE__, - T__TYPEOF__, /* punctuator */ TLBRACK, @@ -83,7 +83,7 @@ storageclass(enum storageclass *sc) case TTYPEDEF: new = SCTYPEDEF; break; case TEXTERN: new = SCEXTERN; break; case TSTATIC: new = SCSTATIC; break; - case T_THREAD_LOCAL: new = SCTHREADLOCAL; break; + case TTHREAD_LOCAL: new = SCTHREADLOCAL; break; case TAUTO: new = SCAUTO; break; case TREGISTER: new = SCREGISTER; break; default: return 0; @@ -323,7 +323,7 @@ declspecs(struct scope *s, enum storageclass *sc, enum funcspec *fs, int *align) ts |= SPECUNSIGNED; next(); break; - case T_BOOL: + case TBOOL: t = &typebool; ++ntypes; next(); @@ -351,9 +351,9 @@ declspecs(struct scope *s, enum storageclass *sc, enum funcspec *fs, int *align) ++ntypes; next(); break; - case T__TYPEOF__: + case TTYPEOF: next(); - expect(TLPAREN, "after '__typeof__'"); + expect(TLPAREN, "after 'typeof'"); t = typename(s, &tq); if (!t) { e = expr(s); @@ -368,7 +368,7 @@ declspecs(struct scope *s, enum storageclass *sc, enum funcspec *fs, int *align) break; /* 6.7.5 Alignment specifier */ - case T_ALIGNAS: + case TALIGNAS: if (!align) error(&tok.loc, "alignment specifier not allowed in this declaration"); next(); @@ -749,9 +749,9 @@ staticassert(struct scope *s) struct stringlit msg; unsigned long long c; - if (!consume(T_STATIC_ASSERT)) + if (!consume(TSTATIC_ASSERT)) return false; - expect(TLPAREN, "after _Static_assert"); + expect(TLPAREN, "after static_assert"); c = intconstexpr(s, true); if (consume(TCOMMA)) { tokencheck(&tok, TSTRINGLIT, "after static assertion expression"); @@ -1037,7 +1037,7 @@ unaryexpr(struct scope *s) e = mkbinaryexpr(&tok.loc, TEQL, e, mkconstexpr(&typeint, 0)); break; case TSIZEOF: - case T_ALIGNOF: + case TALIGNOF: next(); if (consume(TLPAREN)) { t = typename(s, NULL); @@ -536,17 +536,20 @@ keyword(struct token *tok) const char *name; int value; } keywords[] = { - {"_Alignas", T_ALIGNAS}, - {"_Alignof", T_ALIGNOF}, + {"_Alignas", TALIGNAS}, + {"_Alignof", TALIGNOF}, {"_Atomic", T_ATOMIC}, - {"_Bool", T_BOOL}, + {"_Bool", TBOOL}, {"_Complex", T_COMPLEX}, + {"_Decimal128", T_DECIMAL128}, + {"_Decimal32", T_DECIMAL32}, + {"_Decimal64", T_DECIMAL64}, {"_Generic", T_GENERIC}, {"_Imaginary", T_IMAGINARY}, {"_Noreturn", T_NORETURN}, - {"_Static_assert", T_STATIC_ASSERT}, - {"_Thread_local", T_THREAD_LOCAL}, - {"__alignof__", T_ALIGNOF}, + {"_Static_assert", TSTATIC_ASSERT}, + {"_Thread_local", TTHREAD_LOCAL}, + {"__alignof__", TALIGNOF}, {"__asm", T__ASM__}, {"__asm__", T__ASM__}, {"__attribute__", T__ATTRIBUTE__}, @@ -554,15 +557,19 @@ keyword(struct token *tok) {"__inline__", TINLINE}, {"__signed", TSIGNED}, {"__signed__", TSIGNED}, - {"__thread", T_THREAD_LOCAL}, - {"__typeof", T__TYPEOF__}, - {"__typeof__", T__TYPEOF__}, + {"__thread", TTHREAD_LOCAL}, + {"__typeof", TTYPEOF}, + {"__typeof__", TTYPEOF}, {"__volatile__", TVOLATILE}, + {"alignas", TALIGNAS}, + {"alignof", TALIGNOF}, {"auto", TAUTO}, + {"bool", TBOOL}, {"break", TBREAK}, {"case", TCASE}, {"char", TCHAR}, {"const", TCONST}, + {"constexpr", TCONSTEXPR}, {"continue", TCONTINUE}, {"default", TDEFAULT}, {"do", TDO}, @@ -570,6 +577,7 @@ keyword(struct token *tok) {"else", TELSE}, {"enum", TENUM}, {"extern", TEXTERN}, + {"false", TFALSE}, {"float", TFLOAT}, {"for", TFOR}, {"goto", TGOTO}, @@ -578,15 +586,21 @@ keyword(struct token *tok) {"int", TINT}, {"long", TLONG}, {"register", TREGISTER}, + {"nullptr", TNULLPTR}, {"restrict", TRESTRICT}, {"return", TRETURN}, {"short", TSHORT}, {"signed", TSIGNED}, {"sizeof", TSIZEOF}, {"static", TSTATIC}, + {"static_assert", TSTATIC_ASSERT}, {"struct", TSTRUCT}, {"switch", TSWITCH}, + {"thread_local", TTHREAD_LOCAL}, + {"true", TTRUE}, {"typedef", TTYPEDEF}, + {"typeof", TTYPEOF}, + {"typeof_unqual", TTYPEOF_UNQUAL}, {"union", TUNION}, {"unsigned", TUNSIGNED}, {"void", TVOID}, @@ -12,11 +12,15 @@ struct token tok; const char *tokstr[] = { /* keyword */ + [TALIGNAS] = "alignas", + [TALIGNOF] = "alignof", [TAUTO] = "auto", + [TBOOL] = "bool", [TBREAK] = "break", [TCASE] = "case", [TCHAR] = "char", [TCONST] = "const", + [TCONSTEXPR] = "constexpr", [TCONTINUE] = "continue", [TDEFAULT] = "default", [TDO] = "do", @@ -24,6 +28,7 @@ const char *tokstr[] = { [TELSE] = "else", [TENUM] = "enum", [TEXTERN] = "extern", + [TFALSE] = "false", [TFLOAT] = "float", [TFOR] = "for", [TGOTO] = "goto", @@ -31,6 +36,7 @@ const char *tokstr[] = { [TINLINE] = "inline", [TINT] = "int", [TLONG] = "long", + [TNULLPTR] = "nullptr", [TREGISTER] = "register", [TRESTRICT] = "restrict", [TRETURN] = "return", @@ -38,27 +44,30 @@ const char *tokstr[] = { [TSIGNED] = "signed", [TSIZEOF] = "sizeof", [TSTATIC] = "static", + [TSTATIC_ASSERT] = "static_assert", [TSTRUCT] = "struct", [TSWITCH] = "switch", + [TTHREAD_LOCAL] = "thread_local", + [TTRUE] = "true", [TTYPEDEF] = "typedef", + [TTYPEOF] = "typeof", + [TTYPEOF_UNQUAL] = "typeof_unqual", [TUNION] = "union", [TUNSIGNED] = "unsigned", [TVOID] = "void", [TVOLATILE] = "volatile", [TWHILE] = "while", - [T_ALIGNAS] = "_Alignas", - [T_ALIGNOF] = "_Alignof", [T_ATOMIC] = "_Atomic", - [T_BOOL] = "_Bool", + [T_BITINT] = "_BitInt", [T_COMPLEX] = "_Complex", + [T_DECIMAL128] = "_Decimal128", + [T_DECIMAL32] = "_Decimal32", + [T_DECIMAL64] = "_Decimal64", [T_GENERIC] = "_Generic", [T_IMAGINARY] = "_Imaginary", [T_NORETURN] = "_Noreturn", - [T_STATIC_ASSERT] = "_Static_assert", - [T_THREAD_LOCAL] = "_Thread_local", [T__ASM__] = "__asm__", [T__ATTRIBUTE__] = "__attribute__", - [T__TYPEOF__] = "__typeof__", /* punctuator */ [TLBRACK] = "[", |