Linux-Sparse Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH 0/3] make the keyword table more readable
@ 2020-07-08 19:26 Luc Van Oostenryck
  2020-07-08 19:26 ` [PATCH 1/3] keyword: reorganize the keyword table Luc Van Oostenryck
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Luc Van Oostenryck @ 2020-07-08 19:26 UTC (permalink / raw)
  To: linux-sparse; +Cc: Luc Van Oostenryck

This is a three-easy-steps series to improve the readability
of the keyword table.

Luc Van Oostenryck (3):
  keyword: reorganize the keyword table
  keyword: reorder the keywords
  keyword: use some macros to avoid duplication

 parse.c | 286 ++++++++++++++++++++++++++------------------------------
 1 file changed, 132 insertions(+), 154 deletions(-)

-- 
2.27.0


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 1/3] keyword: reorganize the keyword table
  2020-07-08 19:26 [PATCH 0/3] make the keyword table more readable Luc Van Oostenryck
@ 2020-07-08 19:26 ` Luc Van Oostenryck
  2020-07-08 19:26 ` [PATCH 2/3] keyword: reorder the keywords Luc Van Oostenryck
  2020-07-08 19:26 ` [PATCH 3/3] keyword: use some macros to avoid duplication Luc Van Oostenryck
  2 siblings, 0 replies; 4+ messages in thread
From: Luc Van Oostenryck @ 2020-07-08 19:26 UTC (permalink / raw)
  To: linux-sparse; +Cc: Luc Van Oostenryck

With time, the keyword table has become quite hard to read.

So, split the table in 2: one for NS_TYPEDEF and one for NS_KEYWORD.
This allows to remove one argument, making more place for those
that really matter.

Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
 parse.c | 287 +++++++++++++++++++++++++++++---------------------------
 1 file changed, 148 insertions(+), 139 deletions(-)

diff --git a/parse.c b/parse.c
index a9222e7cbf08..4a2b62974612 100644
--- a/parse.c
+++ b/parse.c
@@ -455,159 +455,163 @@ static struct symbol_op mode_word_op = {
 	.to_mode = to_word_mode
 };
 
-/* Using NS_TYPEDEF will also make the keyword a reserved one */
+/*
+ * Define the keyword and their effects.
+ * The entries in the 'typedef' and put in NS_TYPEDEF and
+ * are automatically set as reserved keyword while the ones
+ * in the 'keyword' table are just put in NS_KEYWORD.
+ */
 static struct init_keyword {
 	const char *name;
-	enum namespace ns;
-	unsigned long modifiers;
 	struct symbol_op *op;
 	struct symbol *type;
-} keyword_table[] = {
+	unsigned long mods;
+} typedefs[] = {
 	/* Type qualifiers */
-	{ "const",	NS_TYPEDEF, .op = &const_op },
-	{ "__const",	NS_TYPEDEF, .op = &const_op },
-	{ "__const__",	NS_TYPEDEF, .op = &const_op },
-	{ "volatile",	NS_TYPEDEF, .op = &volatile_op },
-	{ "__volatile",		NS_TYPEDEF, .op = &volatile_op },
-	{ "__volatile__", 	NS_TYPEDEF, .op = &volatile_op },
-	{ "restrict",	NS_TYPEDEF, .op = &restrict_op},
-	{ "__restrict",	NS_TYPEDEF, .op = &restrict_op},
-	{ "__restrict__",	NS_TYPEDEF, .op = &restrict_op},
-	{ "_Atomic",	NS_TYPEDEF, .op = &atomic_op},
+	{ "const",		&const_op },
+	{ "__const__",		&const_op },
+	{ "__const",		&const_op },
+	{ "volatile",		&volatile_op },
+	{ "__volatile__",	&volatile_op },
+	{ "__volatile",		&volatile_op },
+	{ "restrict",		&restrict_op },
+	{ "__restrict__",	&restrict_op },
+	{ "__restrict",		&restrict_op },
+	{ "_Atomic",		&atomic_op },
 
 	/* Typedef.. */
-	{ "typedef",	NS_TYPEDEF, .op = &typedef_op },
+	{ "typedef",		&typedef_op },
 
 	/* Type specifiers */
-	{ "void",	NS_TYPEDEF, .type = &void_ctype, .op = &spec_op},
-	{ "char",	NS_TYPEDEF, .op = &char_op },
-	{ "short",	NS_TYPEDEF, .op = &short_op },
-	{ "int",	NS_TYPEDEF, .op = &int_op },
-	{ "long",	NS_TYPEDEF, .op = &long_op },
-	{ "float",	NS_TYPEDEF, .op = &float_op },
-	{ "double",	NS_TYPEDEF, .op = &double_op },
-	{ "signed",	NS_TYPEDEF, .op = &signed_op },
-	{ "__signed",	NS_TYPEDEF, .op = &signed_op },
-	{ "__signed__",	NS_TYPEDEF, .op = &signed_op },
-	{ "unsigned",	NS_TYPEDEF, .op = &unsigned_op },
-	{ "__int128",	NS_TYPEDEF, .op = &int128_op },
-	{ "_Bool",	NS_TYPEDEF, .type = &bool_ctype, .op = &spec_op },
+	{ "void",		&spec_op,	.type = &void_ctype },
+	{ "char",		&char_op },
+	{ "short",		&short_op },
+	{ "int",		&int_op },
+	{ "long",		&long_op },
+	{ "float",		&float_op },
+	{ "double",		&double_op },
+	{ "signed",		&signed_op },
+	{ "__signed__",		&signed_op },
+	{ "__signed",		&signed_op },
+	{ "unsigned",		&unsigned_op },
+	{ "__int128",		&int128_op },
+	{ "_Bool",		&spec_op,	.type = &bool_ctype },
 
 	/* Predeclared types */
-	{ "__builtin_va_list", NS_TYPEDEF, .type = &ptr_ctype, .op = &spec_op },
-	{ "__builtin_ms_va_list", NS_TYPEDEF, .type = &ptr_ctype, .op = &spec_op },
-	{ "__int128_t",	NS_TYPEDEF, .type = &sint128_ctype, .op = &spec_op },
-	{ "__uint128_t",NS_TYPEDEF, .type = &uint128_ctype, .op = &spec_op },
-	{ "_Float32",	NS_TYPEDEF, .type = &float32_ctype, .op = &spec_op },
-	{ "_Float32x",	NS_TYPEDEF, .type = &float32x_ctype, .op = &spec_op },
-	{ "_Float64",	NS_TYPEDEF, .type = &float64_ctype, .op = &spec_op },
-	{ "_Float64x",	NS_TYPEDEF, .type = &float64x_ctype, .op = &spec_op },
-	{ "_Float128",	NS_TYPEDEF, .type = &float128_ctype, .op = &spec_op },
+	{ "__builtin_va_list",	&spec_op,	.type = &ptr_ctype },
+	{ "__builtin_ms_va_list",&spec_op,	.type = &ptr_ctype },
+	{ "__int128_t",		&spec_op,	.type = &sint128_ctype },
+	{ "__uint128_t",	&spec_op,	.type = &uint128_ctype },
+	{ "_Float32",		&spec_op,	.type = &float32_ctype },
+	{ "_Float32x",		&spec_op,	.type = &float32x_ctype },
+	{ "_Float64",		&spec_op,	.type = &float64_ctype },
+	{ "_Float64x",		&spec_op,	.type = &float64x_ctype },
+	{ "_Float128",		&spec_op,	.type = &float128_ctype },
 
 	/* Extended types */
-	{ "typeof", 	NS_TYPEDEF, .op = &typeof_op },
-	{ "__typeof", 	NS_TYPEDEF, .op = &typeof_op },
-	{ "__typeof__",	NS_TYPEDEF, .op = &typeof_op },
-	{ "__auto_type",NS_TYPEDEF, .op = &autotype_op },
+	{ "typeof",		&typeof_op },
+	{ "__typeof__",		&typeof_op },
+	{ "__typeof",		&typeof_op },
+	{ "__auto_type",	&autotype_op },
 
-	{ "__attribute",   NS_TYPEDEF, .op = &attribute_op },
-	{ "__attribute__", NS_TYPEDEF, .op = &attribute_op },
+	{ "__attribute",	&attribute_op },
+	{ "__attribute__",	&attribute_op },
 
-	{ "struct",	NS_TYPEDEF, .op = &struct_op },
-	{ "union", 	NS_TYPEDEF, .op = &union_op },
-	{ "enum", 	NS_TYPEDEF, .op = &enum_op },
+	{ "struct",		&struct_op },
+	{ "union",		&union_op },
+	{ "enum",		&enum_op },
 
-	{ "inline",	NS_TYPEDEF, .op = &inline_op },
-	{ "__inline",	NS_TYPEDEF, .op = &inline_op },
-	{ "__inline__",	NS_TYPEDEF, .op = &inline_op },
+	{ "inline",		&inline_op },
+	{ "__inline__",		&inline_op },
+	{ "__inline",		&inline_op },
 
-	{ "_Noreturn",	NS_TYPEDEF, .op = &noreturn_op },
+	{ "_Noreturn",		&noreturn_op },
 
-	{ "_Alignas",	NS_TYPEDEF, .op = &alignas_op },
+	{ "_Alignas",		&alignas_op },
 
-	/* Static assertion */
-	{ "_Static_assert", NS_KEYWORD, .op = &static_assert_op },
 
 	/* Storage class */
-	{ "auto",	NS_TYPEDEF, .op = &auto_op },
-	{ "register",	NS_TYPEDEF, .op = &register_op },
-	{ "static",	NS_TYPEDEF, .op = &static_op },
-	{ "extern",	NS_TYPEDEF, .op = &extern_op },
-	{ "__thread",	NS_TYPEDEF, .op = &thread_op },
-	{ "_Thread_local",	NS_TYPEDEF, .op = &thread_op },
-
+	{ "auto",		&auto_op },
+	{ "register",		&register_op },
+	{ "static",		&static_op },
+	{ "extern",		&extern_op },
+	{ "__thread",		&thread_op },
+	{ "_Thread_local",	&thread_op },
+
+}, keywords[] = {
 	/* Statement */
-	{ "if",		NS_KEYWORD, .op = &if_op },
-	{ "return",	NS_KEYWORD, .op = &return_op },
-	{ "break",	NS_KEYWORD, .op = &loop_iter_op },
-	{ "continue",	NS_KEYWORD, .op = &loop_iter_op },
-	{ "default",	NS_KEYWORD, .op = &default_op },
-	{ "case",	NS_KEYWORD, .op = &case_op },
-	{ "switch",	NS_KEYWORD, .op = &switch_op },
-	{ "for",	NS_KEYWORD, .op = &for_op },
-	{ "while",	NS_KEYWORD, .op = &while_op },
-	{ "do",		NS_KEYWORD, .op = &do_op },
-	{ "goto",	NS_KEYWORD, .op = &goto_op },
-	{ "context",	NS_KEYWORD, .op = &context_op },
-	{ "__context__",NS_KEYWORD, .op = &__context___op },
-	{ "__range__",	NS_KEYWORD, .op = &range_op },
-	{ "asm",	NS_KEYWORD, .op = &asm_op },
-	{ "__asm",	NS_KEYWORD, .op = &asm_op },
-	{ "__asm__",	NS_KEYWORD, .op = &asm_op },
+	{ "if",			&if_op },
+	{ "return",		&return_op },
+	{ "break",		&loop_iter_op },
+	{ "continue",		&loop_iter_op },
+	{ "default",		&default_op },
+	{ "case",		&case_op },
+	{ "switch",		&switch_op },
+	{ "for",		&for_op },
+	{ "while",		&while_op },
+	{ "do",			&do_op },
+	{ "goto",		&goto_op },
+	{ "context",		&context_op },
+	{ "__context__",	&__context___op },
+	{ "__range__",		&range_op },
+	{ "asm",		&asm_op },
+	{ "__asm__",		&asm_op },
+	{ "__asm",		&asm_op },
+	{ "_Static_assert",	&static_assert_op },
 
 	/* Attribute */
-	{ "packed",	NS_KEYWORD, .op = &packed_op },
-	{ "__packed__",	NS_KEYWORD, .op = &packed_op },
-	{ "aligned",	NS_KEYWORD, .op = &aligned_op },
-	{ "__aligned__",NS_KEYWORD, .op = &aligned_op },
-	{ "nocast",	NS_KEYWORD,	MOD_NOCAST,	.op = &attr_mod_op },
-	{ "__nocast__",	NS_KEYWORD,	MOD_NOCAST,	.op = &attr_mod_op },
-	{ "noderef",	NS_KEYWORD,	MOD_NODEREF,	.op = &attr_mod_op },
-	{ "__noderef__",NS_KEYWORD,	MOD_NODEREF,	.op = &attr_mod_op },
-	{ "safe",	NS_KEYWORD,	MOD_SAFE, 	.op = &attr_mod_op },
-	{ "__safe__",	NS_KEYWORD,	MOD_SAFE, 	.op = &attr_mod_op },
-	{ "unused",	NS_KEYWORD,	MOD_UNUSED,	.op = &attr_mod_op },
-	{ "__unused__",	NS_KEYWORD,	MOD_UNUSED,	.op = &attr_mod_op },
-	{ "externally_visible",	NS_KEYWORD, MOD_EXT_VISIBLE,.op = &attr_mod_op },
-	{ "__externally_visible__", NS_KEYWORD,MOD_EXT_VISIBLE,.op = &attr_mod_op },
-	{ "force",	NS_KEYWORD,	.op = &attr_force_op },
-	{ "__force__",	NS_KEYWORD,	.op = &attr_force_op },
-	{ "bitwise",	NS_KEYWORD,	MOD_BITWISE,	.op = &attr_bitwise_op },
-	{ "__bitwise__",NS_KEYWORD,	MOD_BITWISE,	.op = &attr_bitwise_op },
-	{ "address_space",NS_KEYWORD,	.op = &address_space_op },
-	{ "__address_space__",NS_KEYWORD,	.op = &address_space_op },
-	{ "designated_init",	NS_KEYWORD,	.op = &designated_init_op },
-	{ "__designated_init__",	NS_KEYWORD,	.op = &designated_init_op },
-	{ "transparent_union",	NS_KEYWORD,	.op = &transparent_union_op },
-	{ "__transparent_union__",	NS_KEYWORD,	.op = &transparent_union_op },
-	{ "noreturn",	NS_KEYWORD,	MOD_NORETURN,	.op = &attr_fun_op },
-	{ "__noreturn__",	NS_KEYWORD,	MOD_NORETURN,	.op = &attr_fun_op },
-	{ "pure",	NS_KEYWORD,	MOD_PURE,	.op = &attr_fun_op },
-	{"__pure__",	NS_KEYWORD,	MOD_PURE,	.op = &attr_fun_op },
-	{"const",	NS_KEYWORD,	MOD_PURE,	.op = &attr_fun_op },
-	{"__const",	NS_KEYWORD,	MOD_PURE,	.op = &attr_fun_op },
-	{"__const__",	NS_KEYWORD,	MOD_PURE,	.op = &attr_fun_op },
-	{"gnu_inline",	NS_KEYWORD,	MOD_GNU_INLINE,	.op = &attr_fun_op },
-	{"__gnu_inline__",NS_KEYWORD,	MOD_GNU_INLINE,	.op = &attr_fun_op },
-
-	{ "mode",	NS_KEYWORD,	.op = &mode_op },
-	{ "__mode__",	NS_KEYWORD,	.op = &mode_op },
-	{ "QI",		NS_KEYWORD,	.op = &mode_QI_op },
-	{ "__QI__",	NS_KEYWORD,	.op = &mode_QI_op },
-	{ "HI",		NS_KEYWORD,	.op = &mode_HI_op },
-	{ "__HI__",	NS_KEYWORD,	.op = &mode_HI_op },
-	{ "SI",		NS_KEYWORD,	.op = &mode_SI_op },
-	{ "__SI__",	NS_KEYWORD,	.op = &mode_SI_op },
-	{ "DI",		NS_KEYWORD,	.op = &mode_DI_op },
-	{ "__DI__",	NS_KEYWORD,	.op = &mode_DI_op },
-	{ "TI",		NS_KEYWORD,	.op = &mode_TI_op },
-	{ "__TI__",	NS_KEYWORD,	.op = &mode_TI_op },
-	{ "byte",	NS_KEYWORD,	.op = &mode_QI_op },
-	{ "__byte__",	NS_KEYWORD,	.op = &mode_QI_op },
-	{ "pointer",	NS_KEYWORD,	.op = &mode_pointer_op },
-	{ "__pointer__",NS_KEYWORD,	.op = &mode_pointer_op },
-	{ "word",	NS_KEYWORD,	.op = &mode_word_op },
-	{ "__word__",	NS_KEYWORD,	.op = &mode_word_op },
+	{ "packed",		&packed_op },
+	{ "__packed__",		&packed_op },
+	{ "aligned",		&aligned_op },
+	{ "__aligned__",	&aligned_op },
+	{ "nocast",		&attr_mod_op,		.mods = MOD_NOCAST },
+	{ "__nocast__",		&attr_mod_op,		.mods = MOD_NOCAST },
+	{ "noderef",		&attr_mod_op,		.mods = MOD_NODEREF },
+	{ "__noderef__",	&attr_mod_op,		.mods = MOD_NODEREF },
+	{ "safe",		&attr_mod_op,		.mods = MOD_SAFE },
+	{ "__safe__",		&attr_mod_op,		.mods = MOD_SAFE },
+	{ "unused",		&attr_mod_op,		.mods = MOD_UNUSED },
+	{ "__unused__",		&attr_mod_op,		.mods = MOD_UNUSED },
+	{ "externally_visible",&attr_mod_op,		.mods = MOD_EXT_VISIBLE },
+	{ "__externally_visible__",&attr_mod_op,	.mods = MOD_EXT_VISIBLE },
+	{ "force",		&attr_force_op },
+	{ "__force__",		&attr_force_op },
+	{ "bitwise",		&attr_bitwise_op,	.mods = MOD_BITWISE },
+	{ "__bitwise__",	&attr_bitwise_op,	.mods = MOD_BITWISE },
+	{ "address_space",	&address_space_op },
+	{ "__address_space__",	&address_space_op },
+	{ "designated_init",	&designated_init_op },
+	{ "__designated_init__",&designated_init_op },
+	{ "transparent_union",	&transparent_union_op },
+	{ "__transparent_union__",&transparent_union_op },
+	{ "noreturn",		&attr_fun_op,		.mods = MOD_NORETURN },
+	{ "__noreturn__",	&attr_fun_op,		.mods = MOD_NORETURN },
+	{ "pure",		&attr_fun_op,		.mods = MOD_PURE },
+	{ "__pure__",		&attr_fun_op,		.mods = MOD_PURE },
+	{ "const",		&attr_fun_op,		.mods = MOD_PURE },
+	{ "__const__",		&attr_fun_op,		.mods = MOD_PURE },
+	{ "__const",		&attr_fun_op,		.mods = MOD_PURE },
+	{ "gnu_inline",		&attr_fun_op,		.mods = MOD_GNU_INLINE },
+	{ "__gnu_inline__",	&attr_fun_op,		.mods = MOD_GNU_INLINE },
+
+	{ "mode",		&mode_op },
+	{ "__mode__",		&mode_op },
+	{ "QI",			&mode_QI_op },
+	{ "__QI__",		&mode_QI_op },
+	{ "HI",			&mode_HI_op },
+	{ "__HI__",		&mode_HI_op },
+	{ "SI",			&mode_SI_op },
+	{ "__SI__",		&mode_SI_op },
+	{ "DI",			&mode_DI_op },
+	{ "__DI__",		&mode_DI_op },
+	{ "TI",			&mode_TI_op },
+	{ "__TI__",		&mode_TI_op },
+	{ "byte",		&mode_QI_op },
+	{ "__byte__",		&mode_QI_op },
+	{ "pointer",		&mode_pointer_op },
+	{ "__pointer__",	&mode_pointer_op },
+	{ "word",		&mode_word_op },
+	{ "__word__",		&mode_word_op },
 };
 
 
@@ -629,19 +633,24 @@ static const char *ignored_attributes[] = {
 };
 
 
+static void init_keyword(int stream, struct init_keyword *kw, enum namespace ns)
+{
+	struct symbol *sym = create_symbol(stream, kw->name, SYM_KEYWORD, ns);
+	sym->ident->keyword = 1;
+	sym->ident->reserved |= (ns == NS_TYPEDEF);
+	sym->ctype.modifiers = kw->mods;
+	sym->ctype.base_type = kw->type;
+	sym->op = kw->op;
+}
+
 void init_parser(int stream)
 {
 	int i;
-	for (i = 0; i < ARRAY_SIZE(keyword_table); i++) {
-		struct init_keyword *ptr = keyword_table + i;
-		struct symbol *sym = create_symbol(stream, ptr->name, SYM_KEYWORD, ptr->ns);
-		sym->ident->keyword = 1;
-		if (ptr->ns == NS_TYPEDEF)
-			sym->ident->reserved = 1;
-		sym->ctype.modifiers = ptr->modifiers;
-		sym->ctype.base_type = ptr->type;
-		sym->op = ptr->op;
-	}
+
+	for (i = 0; i < ARRAY_SIZE(typedefs); i++)
+		init_keyword(stream, &typedefs[i], NS_TYPEDEF);
+	for (i = 0; i < ARRAY_SIZE(keywords); i++)
+		init_keyword(stream, &keywords[i], NS_KEYWORD);
 
 	for (i = 0; i < ARRAY_SIZE(ignored_attributes); i++) {
 		const char * name = ignored_attributes[i];
-- 
2.27.0


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 2/3] keyword: reorder the keywords
  2020-07-08 19:26 [PATCH 0/3] make the keyword table more readable Luc Van Oostenryck
  2020-07-08 19:26 ` [PATCH 1/3] keyword: reorganize the keyword table Luc Van Oostenryck
@ 2020-07-08 19:26 ` Luc Van Oostenryck
  2020-07-08 19:26 ` [PATCH 3/3] keyword: use some macros to avoid duplication Luc Van Oostenryck
  2 siblings, 0 replies; 4+ messages in thread
From: Luc Van Oostenryck @ 2020-07-08 19:26 UTC (permalink / raw)
  To: linux-sparse; +Cc: Luc Van Oostenryck

Reorder the keywords to make them even more logically organized.

Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
 parse.c | 72 +++++++++++++++++++++++++++------------------------------
 1 file changed, 34 insertions(+), 38 deletions(-)

diff --git a/parse.c b/parse.c
index 4a2b62974612..c18a9e66e0a8 100644
--- a/parse.c
+++ b/parse.c
@@ -467,6 +467,25 @@ static struct init_keyword {
 	struct symbol *type;
 	unsigned long mods;
 } typedefs[] = {
+	/* Storage classes */
+	{ "auto",		&auto_op },
+	{ "register",		&register_op },
+	{ "static",		&static_op },
+	{ "extern",		&extern_op },
+	{ "__thread",		&thread_op },
+	{ "_Thread_local",	&thread_op },
+
+	{ "inline",		&inline_op },
+	{ "__inline__",		&inline_op },
+	{ "__inline",		&inline_op },
+
+	/* Typedef ... */
+	{ "typedef",		&typedef_op },
+	{ "typeof",		&typeof_op },
+	{ "__typeof__",		&typeof_op },
+	{ "__typeof",		&typeof_op },
+	{ "__auto_type",	&autotype_op },
+
 	/* Type qualifiers */
 	{ "const",		&const_op },
 	{ "__const__",		&const_op },
@@ -477,12 +496,19 @@ static struct init_keyword {
 	{ "restrict",		&restrict_op },
 	{ "__restrict__",	&restrict_op },
 	{ "__restrict",		&restrict_op },
+
 	{ "_Atomic",		&atomic_op },
+	{ "_Noreturn",		&noreturn_op },
+	{ "_Alignas",		&alignas_op },
 
-	/* Typedef.. */
-	{ "typedef",		&typedef_op },
+	{ "__attribute__",	&attribute_op },
+	{ "__attribute",	&attribute_op },
 
 	/* Type specifiers */
+	{ "struct",		&struct_op },
+	{ "union",		&union_op },
+	{ "enum",		&enum_op },
+
 	{ "void",		&spec_op,	.type = &void_ctype },
 	{ "char",		&char_op },
 	{ "short",		&short_op },
@@ -507,39 +533,8 @@ static struct init_keyword {
 	{ "_Float64",		&spec_op,	.type = &float64_ctype },
 	{ "_Float64x",		&spec_op,	.type = &float64x_ctype },
 	{ "_Float128",		&spec_op,	.type = &float128_ctype },
-
-	/* Extended types */
-	{ "typeof",		&typeof_op },
-	{ "__typeof__",		&typeof_op },
-	{ "__typeof",		&typeof_op },
-	{ "__auto_type",	&autotype_op },
-
-	{ "__attribute",	&attribute_op },
-	{ "__attribute__",	&attribute_op },
-
-	{ "struct",		&struct_op },
-	{ "union",		&union_op },
-	{ "enum",		&enum_op },
-
-	{ "inline",		&inline_op },
-	{ "__inline__",		&inline_op },
-	{ "__inline",		&inline_op },
-
-	{ "_Noreturn",		&noreturn_op },
-
-	{ "_Alignas",		&alignas_op },
-
-
-	/* Storage class */
-	{ "auto",		&auto_op },
-	{ "register",		&register_op },
-	{ "static",		&static_op },
-	{ "extern",		&extern_op },
-	{ "__thread",		&thread_op },
-	{ "_Thread_local",	&thread_op },
-
 }, keywords[] = {
-	/* Statement */
+	/* Statements */
 	{ "if",			&if_op },
 	{ "return",		&return_op },
 	{ "break",		&loop_iter_op },
@@ -551,15 +546,15 @@ static struct init_keyword {
 	{ "while",		&while_op },
 	{ "do",			&do_op },
 	{ "goto",		&goto_op },
-	{ "context",		&context_op },
-	{ "__context__",	&__context___op },
-	{ "__range__",		&range_op },
 	{ "asm",		&asm_op },
 	{ "__asm__",		&asm_op },
 	{ "__asm",		&asm_op },
+	{ "context",		&context_op },
+	{ "__context__",	&__context___op },
+	{ "__range__",		&range_op },
 	{ "_Static_assert",	&static_assert_op },
 
-	/* Attribute */
+	/* Attributes */
 	{ "packed",		&packed_op },
 	{ "__packed__",		&packed_op },
 	{ "aligned",		&aligned_op },
@@ -594,6 +589,7 @@ static struct init_keyword {
 	{ "gnu_inline",		&attr_fun_op,		.mods = MOD_GNU_INLINE },
 	{ "__gnu_inline__",	&attr_fun_op,		.mods = MOD_GNU_INLINE },
 
+	/* Modes */
 	{ "mode",		&mode_op },
 	{ "__mode__",		&mode_op },
 	{ "QI",			&mode_QI_op },
-- 
2.27.0


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 3/3] keyword: use some macros to avoid duplication
  2020-07-08 19:26 [PATCH 0/3] make the keyword table more readable Luc Van Oostenryck
  2020-07-08 19:26 ` [PATCH 1/3] keyword: reorganize the keyword table Luc Van Oostenryck
  2020-07-08 19:26 ` [PATCH 2/3] keyword: reorder the keywords Luc Van Oostenryck
@ 2020-07-08 19:26 ` Luc Van Oostenryck
  2 siblings, 0 replies; 4+ messages in thread
From: Luc Van Oostenryck @ 2020-07-08 19:26 UTC (permalink / raw)
  To: linux-sparse; +Cc: Luc Van Oostenryck

Most keywords have a variant with the leading nd trailing
double-underscore. Some have also a variant with only the
leading underscores. But only the identifier change, the
remaining of the information is duplicated for them.

So, use some macros to define the corresponding entries
without duplication.

Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
 parse.c | 223 +++++++++++++++++++++++++-------------------------------
 1 file changed, 98 insertions(+), 125 deletions(-)

diff --git a/parse.c b/parse.c
index c18a9e66e0a8..188b7485c61b 100644
--- a/parse.c
+++ b/parse.c
@@ -460,6 +460,12 @@ static struct symbol_op mode_word_op = {
  * The entries in the 'typedef' and put in NS_TYPEDEF and
  * are automatically set as reserved keyword while the ones
  * in the 'keyword' table are just put in NS_KEYWORD.
+ *
+ * The entries are added via the 3 macros:
+ *   N() for entries with "name" only,
+ *   D() for entries with "name" & "__name__",
+ *   A() for entries with "name", "__name" & "__name__",
+ *   U() for entries with "__name" & "__name__".
  */
 static struct init_keyword {
 	const char *name;
@@ -467,147 +473,114 @@ static struct init_keyword {
 	struct symbol *type;
 	unsigned long mods;
 } typedefs[] = {
+#define N(I, O,...)	{ I, O,##__VA_ARGS__ }
+#define D(I, O,...)	N(I,O,##__VA_ARGS__ ),		\
+			N("__" I "__",O,##__VA_ARGS__)
+#define A(I, O,...)	N(I,O,##__VA_ARGS__ ),		\
+			N("__" I,O,##__VA_ARGS__),	\
+			N("__" I "__",O,##__VA_ARGS__)
+#define U(I, O,...)	N("__" I,O,##__VA_ARGS__),	\
+			N("__" I "__",O,##__VA_ARGS__)
 	/* Storage classes */
-	{ "auto",		&auto_op },
-	{ "register",		&register_op },
-	{ "static",		&static_op },
-	{ "extern",		&extern_op },
-	{ "__thread",		&thread_op },
-	{ "_Thread_local",	&thread_op },
+	N("auto",		&auto_op),
+	N("register",		&register_op),
+	N("static",		&static_op),
+	N("extern",		&extern_op),
+	N("__thread",		&thread_op),
+	N("_Thread_local",	&thread_op),
 
-	{ "inline",		&inline_op },
-	{ "__inline__",		&inline_op },
-	{ "__inline",		&inline_op },
+	A("inline",		&inline_op),
 
 	/* Typedef ... */
-	{ "typedef",		&typedef_op },
-	{ "typeof",		&typeof_op },
-	{ "__typeof__",		&typeof_op },
-	{ "__typeof",		&typeof_op },
-	{ "__auto_type",	&autotype_op },
+	N("typedef",		&typedef_op),
+	A("typeof",		&typeof_op),
+	N("__auto_type",	&autotype_op),
 
 	/* Type qualifiers */
-	{ "const",		&const_op },
-	{ "__const__",		&const_op },
-	{ "__const",		&const_op },
-	{ "volatile",		&volatile_op },
-	{ "__volatile__",	&volatile_op },
-	{ "__volatile",		&volatile_op },
-	{ "restrict",		&restrict_op },
-	{ "__restrict__",	&restrict_op },
-	{ "__restrict",		&restrict_op },
-
-	{ "_Atomic",		&atomic_op },
-	{ "_Noreturn",		&noreturn_op },
-	{ "_Alignas",		&alignas_op },
-
-	{ "__attribute__",	&attribute_op },
-	{ "__attribute",	&attribute_op },
+	A("const",		&const_op),
+	A("volatile",		&volatile_op),
+	A("restrict",		&restrict_op),
+
+	N("_Atomic",		&atomic_op),
+	N("_Noreturn",		&noreturn_op),
+	N("_Alignas",		&alignas_op),
+
+	U("attribute",		&attribute_op),
 
 	/* Type specifiers */
-	{ "struct",		&struct_op },
-	{ "union",		&union_op },
-	{ "enum",		&enum_op },
-
-	{ "void",		&spec_op,	.type = &void_ctype },
-	{ "char",		&char_op },
-	{ "short",		&short_op },
-	{ "int",		&int_op },
-	{ "long",		&long_op },
-	{ "float",		&float_op },
-	{ "double",		&double_op },
-	{ "signed",		&signed_op },
-	{ "__signed__",		&signed_op },
-	{ "__signed",		&signed_op },
-	{ "unsigned",		&unsigned_op },
-	{ "__int128",		&int128_op },
-	{ "_Bool",		&spec_op,	.type = &bool_ctype },
+	N("struct",		&struct_op),
+	N("union",		&union_op),
+	N("enum",		&enum_op),
+
+	N("void",		&spec_op,	.type = &void_ctype),
+	N("char",		&char_op),
+	N("short",		&short_op),
+	N("int",		&int_op),
+	N("long",		&long_op),
+	N("float",		&float_op),
+	N("double",		&double_op),
+	A("signed",		&signed_op),
+	N("unsigned",		&unsigned_op),
+	N("__int128",		&int128_op),
+	N("_Bool",		&spec_op,	.type = &bool_ctype),
 
 	/* Predeclared types */
-	{ "__builtin_va_list",	&spec_op,	.type = &ptr_ctype },
-	{ "__builtin_ms_va_list",&spec_op,	.type = &ptr_ctype },
-	{ "__int128_t",		&spec_op,	.type = &sint128_ctype },
-	{ "__uint128_t",	&spec_op,	.type = &uint128_ctype },
-	{ "_Float32",		&spec_op,	.type = &float32_ctype },
-	{ "_Float32x",		&spec_op,	.type = &float32x_ctype },
-	{ "_Float64",		&spec_op,	.type = &float64_ctype },
-	{ "_Float64x",		&spec_op,	.type = &float64x_ctype },
-	{ "_Float128",		&spec_op,	.type = &float128_ctype },
+	N("__builtin_va_list",	&spec_op,	.type = &ptr_ctype),
+	N("__builtin_ms_va_list",&spec_op,	.type = &ptr_ctype),
+	N("__int128_t",		&spec_op,	.type = &sint128_ctype),
+	N("__uint128_t",	&spec_op,	.type = &uint128_ctype),
+	N("_Float32",		&spec_op,	.type = &float32_ctype),
+	N("_Float32x",		&spec_op,	.type = &float32x_ctype),
+	N("_Float64",		&spec_op,	.type = &float64_ctype),
+	N("_Float64x",		&spec_op,	.type = &float64x_ctype),
+	N("_Float128",		&spec_op,	.type = &float128_ctype),
 }, keywords[] = {
 	/* Statements */
-	{ "if",			&if_op },
-	{ "return",		&return_op },
-	{ "break",		&loop_iter_op },
-	{ "continue",		&loop_iter_op },
-	{ "default",		&default_op },
-	{ "case",		&case_op },
-	{ "switch",		&switch_op },
-	{ "for",		&for_op },
-	{ "while",		&while_op },
-	{ "do",			&do_op },
-	{ "goto",		&goto_op },
-	{ "asm",		&asm_op },
-	{ "__asm__",		&asm_op },
-	{ "__asm",		&asm_op },
-	{ "context",		&context_op },
-	{ "__context__",	&__context___op },
-	{ "__range__",		&range_op },
-	{ "_Static_assert",	&static_assert_op },
+	N("if",			&if_op),
+	N("return",		&return_op),
+	N("break",		&loop_iter_op),
+	N("continue",		&loop_iter_op),
+	N("default",		&default_op),
+	N("case",		&case_op),
+	N("switch",		&switch_op),
+	N("for",		&for_op),
+	N("while",		&while_op),
+	N("do",			&do_op),
+	N("goto",		&goto_op),
+	A("asm",		&asm_op),
+	N("context",		&context_op),
+	N("__context__",	&__context___op),
+	N("__range__",		&range_op),
+	N("_Static_assert",	&static_assert_op),
 
 	/* Attributes */
-	{ "packed",		&packed_op },
-	{ "__packed__",		&packed_op },
-	{ "aligned",		&aligned_op },
-	{ "__aligned__",	&aligned_op },
-	{ "nocast",		&attr_mod_op,		.mods = MOD_NOCAST },
-	{ "__nocast__",		&attr_mod_op,		.mods = MOD_NOCAST },
-	{ "noderef",		&attr_mod_op,		.mods = MOD_NODEREF },
-	{ "__noderef__",	&attr_mod_op,		.mods = MOD_NODEREF },
-	{ "safe",		&attr_mod_op,		.mods = MOD_SAFE },
-	{ "__safe__",		&attr_mod_op,		.mods = MOD_SAFE },
-	{ "unused",		&attr_mod_op,		.mods = MOD_UNUSED },
-	{ "__unused__",		&attr_mod_op,		.mods = MOD_UNUSED },
-	{ "externally_visible",&attr_mod_op,		.mods = MOD_EXT_VISIBLE },
-	{ "__externally_visible__",&attr_mod_op,	.mods = MOD_EXT_VISIBLE },
-	{ "force",		&attr_force_op },
-	{ "__force__",		&attr_force_op },
-	{ "bitwise",		&attr_bitwise_op,	.mods = MOD_BITWISE },
-	{ "__bitwise__",	&attr_bitwise_op,	.mods = MOD_BITWISE },
-	{ "address_space",	&address_space_op },
-	{ "__address_space__",	&address_space_op },
-	{ "designated_init",	&designated_init_op },
-	{ "__designated_init__",&designated_init_op },
-	{ "transparent_union",	&transparent_union_op },
-	{ "__transparent_union__",&transparent_union_op },
-	{ "noreturn",		&attr_fun_op,		.mods = MOD_NORETURN },
-	{ "__noreturn__",	&attr_fun_op,		.mods = MOD_NORETURN },
-	{ "pure",		&attr_fun_op,		.mods = MOD_PURE },
-	{ "__pure__",		&attr_fun_op,		.mods = MOD_PURE },
-	{ "const",		&attr_fun_op,		.mods = MOD_PURE },
-	{ "__const__",		&attr_fun_op,		.mods = MOD_PURE },
-	{ "__const",		&attr_fun_op,		.mods = MOD_PURE },
-	{ "gnu_inline",		&attr_fun_op,		.mods = MOD_GNU_INLINE },
-	{ "__gnu_inline__",	&attr_fun_op,		.mods = MOD_GNU_INLINE },
+	D("packed",		&packed_op),
+	D("aligned",		&aligned_op),
+	D("nocast",		&attr_mod_op,		.mods = MOD_NOCAST),
+	D("noderef",		&attr_mod_op,		.mods = MOD_NODEREF),
+	D("safe",		&attr_mod_op,		.mods = MOD_SAFE),
+	D("unused",		&attr_mod_op,		.mods = MOD_UNUSED),
+	D("externally_visible",	&attr_mod_op,		.mods = MOD_EXT_VISIBLE),
+	D("force",		&attr_force_op),
+	D("bitwise",		&attr_bitwise_op,	.mods = MOD_BITWISE),
+	D("address_space",	&address_space_op),
+	D("designated_init",	&designated_init_op),
+	D("transparent_union",	&transparent_union_op),
+	D("noreturn",		&attr_fun_op,		.mods = MOD_NORETURN),
+	D("pure",		&attr_fun_op,		.mods = MOD_PURE),
+	A("const",		&attr_fun_op,		.mods = MOD_PURE),
+	D("gnu_inline",		&attr_fun_op,		.mods = MOD_GNU_INLINE),
 
 	/* Modes */
-	{ "mode",		&mode_op },
-	{ "__mode__",		&mode_op },
-	{ "QI",			&mode_QI_op },
-	{ "__QI__",		&mode_QI_op },
-	{ "HI",			&mode_HI_op },
-	{ "__HI__",		&mode_HI_op },
-	{ "SI",			&mode_SI_op },
-	{ "__SI__",		&mode_SI_op },
-	{ "DI",			&mode_DI_op },
-	{ "__DI__",		&mode_DI_op },
-	{ "TI",			&mode_TI_op },
-	{ "__TI__",		&mode_TI_op },
-	{ "byte",		&mode_QI_op },
-	{ "__byte__",		&mode_QI_op },
-	{ "pointer",		&mode_pointer_op },
-	{ "__pointer__",	&mode_pointer_op },
-	{ "word",		&mode_word_op },
-	{ "__word__",		&mode_word_op },
+	D("mode",		&mode_op),
+	D("QI",			&mode_QI_op),
+	D("HI",			&mode_HI_op),
+	D("SI",			&mode_SI_op),
+	D("DI",			&mode_DI_op),
+	D("TI",			&mode_TI_op),
+	D("byte",		&mode_QI_op),
+	D("pointer",		&mode_pointer_op),
+	D("word",		&mode_word_op),
 };
 
 
-- 
2.27.0


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, back to index

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-08 19:26 [PATCH 0/3] make the keyword table more readable Luc Van Oostenryck
2020-07-08 19:26 ` [PATCH 1/3] keyword: reorganize the keyword table Luc Van Oostenryck
2020-07-08 19:26 ` [PATCH 2/3] keyword: reorder the keywords Luc Van Oostenryck
2020-07-08 19:26 ` [PATCH 3/3] keyword: use some macros to avoid duplication Luc Van Oostenryck

Linux-Sparse Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-sparse/0 linux-sparse/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-sparse linux-sparse/ https://lore.kernel.org/linux-sparse \
		linux-sparse@vger.kernel.org
	public-inbox-index linux-sparse

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-sparse


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git