aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorlemon <lsof@mailbox.org>2025-12-21 13:55:01 +0100
committerlemon <lsof@mailbox.org>2025-12-21 16:44:43 +0100
commit3e74de26d16780e626241e0c42313fcb37b91cf2 (patch)
tree76092ff61192c0f8e36d7bd50c58fc7b57b7999b
parent201f015408a160583b6644c0c3ea07b3139c8d91 (diff)
c: keyword aliases
Some linux headers use __signed__ for whatever reason.. this is a general fix for those alternate keyword
-rw-r--r--c/keywords.def124
-rw-r--r--c/lex.c21
-rw-r--r--c/lex.h2
-rw-r--r--io.c2
4 files changed, 82 insertions, 67 deletions
diff --git a/c/keywords.def b/c/keywords.def
index f971830..2f20e58 100644
--- a/c/keywords.def
+++ b/c/keywords.def
@@ -1,65 +1,67 @@
/* !SORTED */
-_(_Alignas, STDC11)
-_(_Alignof, STDC11)
-_(_Atomic, STDC11)
-_(_BitInt, STDC23)
-_(_Bool, STDC99)
-_(_Complex, STDC99)
-_(_Decimal128, STDC23)
-_(_Decimal32, STDC23)
-_(_Decimal64, STDC23)
-_(_Generic, STDC11)
-_(_Imaginary, STDC99)
-_(_Noreturn, STDC11)
-_(_Static_assert, STDC11)
-_(_Thread_local, STDC11)
-_(__builtin_va_arg, 0)
-_(__typeof__, 0)
-_(alignas, STDC23)
-_(alignof, STDC23)
-_(auto, 0)
-_(bool, STDC23)
-_(break, 0)
-_(case, 0)
-_(char, 0)
-_(const, 0)
-_(constexpr, STDC23)
-_(continue, 0)
-_(default, 0)
-_(do, 0)
-_(double, 0)
-_(else, 0)
-_(enum, 0)
-_(extern, 0)
-_(false, STDC23)
-_(float, 0)
-_(for, 0)
-_(goto, 0)
-_(if, 0)
-_(inline, STDC99)
-_(int, 0)
-_(long, 0)
-_(nullptr, STDC23)
-_(register, 0)
-_(restrict, STDC99)
-_(return, 0)
-_(short, 0)
-_(signed, 0)
-_(sizeof, 0)
-_(static, 0)
-_(static_assert, STDC23)
-_(struct, 0)
-_(switch, 0)
-_(thread_local, STDC23)
-_(true, STDC23)
-_(typedef, 0)
-_(typeof, STDC23)
-_(typeof_unqual, STDC23)
-_(union, 0)
-_(unsigned, 0)
-_(void, 0)
-_(volatile, 0)
-_(while, 0)
+/* token cstd (alias) */
+_(_Alignas, STDC11, )
+_(_Alignof, STDC11, )
+_(_Atomic, STDC11, )
+_(_BitInt, STDC23, )
+_(_Bool, STDC99, )
+_(_Complex, STDC99, "__complex", "__complex__")
+_(_Decimal128, STDC23, )
+_(_Decimal32, STDC23, )
+_(_Decimal64, STDC23, )
+_(_Generic, STDC11, )
+_(_Imaginary, STDC99, )
+_(_Noreturn, STDC11, )
+_(_Static_assert, STDC11, )
+_(_Thread_local, STDC11, )
+_(__attribute__, 0, )
+_(__builtin_va_arg, 0, )
+_(__typeof__, 0, "__typeof")
+_(alignas, STDC23, )
+_(alignof, STDC23, )
+_(auto, 0, )
+_(bool, STDC23, )
+_(break, 0, )
+_(case, 0, )
+_(char, 0, )
+_(const, 0, "__const", "__const__")
+_(constexpr, STDC23, )
+_(continue, 0, )
+_(default, 0, )
+_(do, 0, )
+_(double, 0, )
+_(else, 0, )
+_(enum, 0, )
+_(extern, 0, )
+_(false, STDC23, )
+_(float, 0, )
+_(for, 0, )
+_(goto, 0, )
+_(if, 0, )
+_(inline, STDC99, "__inline", "__inline__")
+_(int, 0, )
+_(long, 0, )
+_(nullptr, STDC23, )
+_(register, 0, )
+_(restrict, STDC99, "__restrict", "__restrict__")
+_(return, 0, )
+_(short, 0, )
+_(signed, 0, "__signed", "__signed__")
+_(sizeof, 0, )
+_(static, 0, )
+_(static_assert, STDC23, )
+_(struct, 0, )
+_(switch, 0, )
+_(thread_local, STDC23, )
+_(true, STDC23, )
+_(typedef, 0, )
+_(typeof, STDC23, )
+_(typeof_unqual, STDC23, )
+_(union, 0, )
+_(unsigned, 0, )
+_(void, 0, )
+_(volatile, 0, "__volatile", "__volatile__")
+_(while, 0, )
#ifndef TKWBEGIN_
# define TKWBEGIN_ TKW_Alignas
diff --git a/c/lex.c b/c/lex.c
index 803cddb..9b6de51 100644
--- a/c/lex.c
+++ b/c/lex.c
@@ -1746,24 +1746,37 @@ findppcmd(const struct token *tk)
static void
identkeyword(struct token *tk)
{
+#ifdef __GNUC__
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wmissing-braces"
+#endif
static const struct {
const char *s;
struct kw { uchar t, cstd : 4, ext : 1; } kw;
+ const char *alias[2];
} kwtab[] = {
-#define _(kw, cstd) { #kw, {TKW##kw, cstd} },
+#define _(kw, cstd, ...) { #kw, {TKW##kw, cstd}, __VA_ARGS__ },
#include "keywords.def"
#undef _
};
+#ifdef __GNUC__
+#pragma GCC diagnostic pop
+#endif
static pmap_of(struct kw) kwmap;
if (!kwmap.v) {
pmap_init(&kwmap, 128);
for (int i = 0; i < countof(kwtab); ++i) {
+ struct kw kw = kwtab[i].kw;
/* allow future keywords but only if they begin with _ */
- if (kwtab[i].kw.cstd <= ccopt.cstd || kwtab[i].s[0] == '_') {
- struct kw kw = kwtab[i].kw;
- kw.ext = kwtab[i].kw.cstd > ccopt.cstd;
+ if (kw.cstd <= ccopt.cstd || kwtab[i].s[0] == '_') {
+ kw.ext = kw.cstd > ccopt.cstd;
pmap_set(&kwmap, intern(kwtab[i].s), kw);
}
+ for (const char *const *palias = kwtab[i].alias, *const *end = palias+2;
+ palias != end && *palias; ++palias)
+ {
+ pmap_set(&kwmap, intern(*palias), kw);
+ }
}
}
struct kw *kw = pmap_get(&kwmap, tk->name);
diff --git a/c/lex.h b/c/lex.h
index 20b1bbd..c4c38e8 100644
--- a/c/lex.h
+++ b/c/lex.h
@@ -44,7 +44,7 @@ enum toktag { /* single-character tokens' tag value is the character itself */
TKSETSHL, /* <<= */
TKSETSHR, /* >>= */
TKIDENT = 0x80,
-#define _(kw, stdc) TKW##kw,
+#define _(kw, stdc, ...) TKW##kw,
#include "keywords.def"
#undef _
NTOKTAG,
diff --git a/io.c b/io.c
index 35da15a..9b57133 100644
--- a/io.c
+++ b/io.c
@@ -592,7 +592,7 @@ vbfmt(struct wbuf *out, const char *fmt, va_list ap)
default:
if (tok->t >= TKWBEGIN_ && tok->t <= TKWEND_) {
static const char *tab[] = {
- #define _(kw, c) #kw,
+ #define _(kw, c, ...) #kw,
#include "c/keywords.def"
#undef _
};