162306a36Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-only
262306a36Sopenharmony_cistatic struct resword {
362306a36Sopenharmony_ci	const char *name;
462306a36Sopenharmony_ci	int token;
562306a36Sopenharmony_ci} keywords[] = {
662306a36Sopenharmony_ci	{ "__GENKSYMS_EXPORT_SYMBOL", EXPORT_SYMBOL_KEYW },
762306a36Sopenharmony_ci	{ "__asm", ASM_KEYW },
862306a36Sopenharmony_ci	{ "__asm__", ASM_KEYW },
962306a36Sopenharmony_ci	{ "__attribute", ATTRIBUTE_KEYW },
1062306a36Sopenharmony_ci	{ "__attribute__", ATTRIBUTE_KEYW },
1162306a36Sopenharmony_ci	{ "__const", CONST_KEYW },
1262306a36Sopenharmony_ci	{ "__const__", CONST_KEYW },
1362306a36Sopenharmony_ci	{ "__extension__", EXTENSION_KEYW },
1462306a36Sopenharmony_ci	{ "__inline", INLINE_KEYW },
1562306a36Sopenharmony_ci	{ "__inline__", INLINE_KEYW },
1662306a36Sopenharmony_ci	{ "__signed", SIGNED_KEYW },
1762306a36Sopenharmony_ci	{ "__signed__", SIGNED_KEYW },
1862306a36Sopenharmony_ci	{ "__typeof", TYPEOF_KEYW },
1962306a36Sopenharmony_ci	{ "__typeof__", TYPEOF_KEYW },
2062306a36Sopenharmony_ci	{ "__volatile", VOLATILE_KEYW },
2162306a36Sopenharmony_ci	{ "__volatile__", VOLATILE_KEYW },
2262306a36Sopenharmony_ci	{ "__builtin_va_list", VA_LIST_KEYW },
2362306a36Sopenharmony_ci
2462306a36Sopenharmony_ci	{ "__int128", BUILTIN_INT_KEYW },
2562306a36Sopenharmony_ci	{ "__int128_t", BUILTIN_INT_KEYW },
2662306a36Sopenharmony_ci	{ "__uint128_t", BUILTIN_INT_KEYW },
2762306a36Sopenharmony_ci
2862306a36Sopenharmony_ci	// According to rth, c99 defines "_Bool", "__restrict", "__restrict__", "restrict".  KAO
2962306a36Sopenharmony_ci	{ "_Bool", BOOL_KEYW },
3062306a36Sopenharmony_ci	{ "__restrict", RESTRICT_KEYW },
3162306a36Sopenharmony_ci	{ "__restrict__", RESTRICT_KEYW },
3262306a36Sopenharmony_ci	{ "restrict", RESTRICT_KEYW },
3362306a36Sopenharmony_ci	{ "asm", ASM_KEYW },
3462306a36Sopenharmony_ci
3562306a36Sopenharmony_ci	// c11 keywords that can be used at module scope
3662306a36Sopenharmony_ci	{ "_Static_assert", STATIC_ASSERT_KEYW },
3762306a36Sopenharmony_ci
3862306a36Sopenharmony_ci	// attribute commented out in modutils 2.4.2.  People are using 'attribute' as a
3962306a36Sopenharmony_ci	// field name which breaks the genksyms parser.  It is not a gcc keyword anyway.
4062306a36Sopenharmony_ci	// KAO. },
4162306a36Sopenharmony_ci	// { "attribute", ATTRIBUTE_KEYW },
4262306a36Sopenharmony_ci
4362306a36Sopenharmony_ci	{ "auto", AUTO_KEYW },
4462306a36Sopenharmony_ci	{ "char", CHAR_KEYW },
4562306a36Sopenharmony_ci	{ "const", CONST_KEYW },
4662306a36Sopenharmony_ci	{ "double", DOUBLE_KEYW },
4762306a36Sopenharmony_ci	{ "enum", ENUM_KEYW },
4862306a36Sopenharmony_ci	{ "extern", EXTERN_KEYW },
4962306a36Sopenharmony_ci	{ "float", FLOAT_KEYW },
5062306a36Sopenharmony_ci	{ "inline", INLINE_KEYW },
5162306a36Sopenharmony_ci	{ "int", INT_KEYW },
5262306a36Sopenharmony_ci	{ "long", LONG_KEYW },
5362306a36Sopenharmony_ci	{ "register", REGISTER_KEYW },
5462306a36Sopenharmony_ci	{ "short", SHORT_KEYW },
5562306a36Sopenharmony_ci	{ "signed", SIGNED_KEYW },
5662306a36Sopenharmony_ci	{ "static", STATIC_KEYW },
5762306a36Sopenharmony_ci	{ "struct", STRUCT_KEYW },
5862306a36Sopenharmony_ci	{ "typedef", TYPEDEF_KEYW },
5962306a36Sopenharmony_ci	{ "typeof", TYPEOF_KEYW },
6062306a36Sopenharmony_ci	{ "union", UNION_KEYW },
6162306a36Sopenharmony_ci	{ "unsigned", UNSIGNED_KEYW },
6262306a36Sopenharmony_ci	{ "void", VOID_KEYW },
6362306a36Sopenharmony_ci	{ "volatile", VOLATILE_KEYW },
6462306a36Sopenharmony_ci};
6562306a36Sopenharmony_ci
6662306a36Sopenharmony_ci#define NR_KEYWORDS (sizeof(keywords)/sizeof(struct resword))
6762306a36Sopenharmony_ci
6862306a36Sopenharmony_cistatic int is_reserved_word(register const char *str, register unsigned int len)
6962306a36Sopenharmony_ci{
7062306a36Sopenharmony_ci	int i;
7162306a36Sopenharmony_ci	for (i = 0; i < NR_KEYWORDS; i++) {
7262306a36Sopenharmony_ci		struct resword *r = keywords + i;
7362306a36Sopenharmony_ci		int l = strlen(r->name);
7462306a36Sopenharmony_ci		if (len == l && !memcmp(str, r->name, len))
7562306a36Sopenharmony_ci			return r->token;
7662306a36Sopenharmony_ci	}
7762306a36Sopenharmony_ci	return -1;
7862306a36Sopenharmony_ci}
79