Skip to contentSkip to conversation

Free up some special bits in modifiers.

PATCH Applied Christopher Li 1 participant 1 message Mar 7, 2007 Sparse checker

lore
Share & tools
lore

Christopher Li

author maintainer
#0 lore raw

PATCH 2/5 Free up some special bits in modifiers.

This change using symbol_op to contain the specifier parsing function. It is easier to add new specifiers. We don't need special bits any more.

parse.h +1 -0
Index: sparse/parse.h
===================================================================
@@ -133,5 +133,6 @@ extern struct symbol *ctype_fp(unsigned 
 extern void copy_statement(struct statement *src, struct statement *dst);
 extern int inline_function(struct expression *expr, struct symbol *sym);
 extern void uninline(struct symbol *sym);
+extern void init_parser(int);
 
 #endif /* PARSE_H */
symbol.c +1 -34
Index: sparse/symbol.c
===================================================================
@@ -678,43 +678,9 @@ static struct sym_init {
 	{ "__label__",	&label_ctype,	MOD_LABEL | MOD_UNSIGNED },
 	{ "_Bool",	&bool_ctype,	MOD_UNSIGNED },
 
-	/* Type qualifiers */
-	{ "const",	NULL,		MOD_CONST },
-	{ "__const",	NULL,		MOD_CONST },
-	{ "__const__",	NULL,		MOD_CONST },
-	{ "volatile",	NULL,		MOD_VOLATILE },
-	{ "__volatile",	NULL,		MOD_VOLATILE },
-	{ "__volatile__", NULL,		MOD_VOLATILE },
-
 	/* Predeclared types */
 	{ "__builtin_va_list", &int_type, 0 },
 
-	/* Typedef.. */
-	{ "typedef",	NULL,		MOD_TYPEDEF },
-
-	/* Extended types */
-	{ "typeof",	NULL,		MOD_TYPEOF },
-	{ "__typeof",	NULL,		MOD_TYPEOF },
-	{ "__typeof__",	NULL,		MOD_TYPEOF },
-
-#if 0
-	{ "attribute",	NULL,		MOD_ATTRIBUTE },
-#endif
-	{ "__attribute", NULL,		MOD_ATTRIBUTE },
-	{ "__attribute__", NULL,	MOD_ATTRIBUTE },
-
-	{ "struct",	NULL,		MOD_STRUCTOF },
-	{ "union",	NULL,		MOD_UNIONOF },
-	{ "enum",	NULL,		MOD_ENUMOF },
-
-	{ "inline",	NULL,		MOD_INLINE },
-	{ "__inline",	NULL,		MOD_INLINE },
-	{ "__inline__",	NULL,		MOD_INLINE },
-
-	/* Ignored for now.. */
-	{ "restrict",	NULL,		0 },
-	{ "__restrict",	NULL,		0 },
-
 	{ NULL,		NULL,		0 }
 };
 
@@ -794,6 +760,7 @@ void init_symbols(void)
 	hash_ident(&n)
 #include "ident-list.h"
 
+	init_parser(stream);
 	for (ptr = symbol_init_table; ptr->name; ptr++) {
 		struct symbol *sym;
 		sym = create_symbol(stream, ptr->name, SYM_NODE, NS_TYPEDEF);
parse.c +114 -25

204 lines not on this page · raw message

symbol.h +15 -7
Index: sparse/symbol.h
===================================================================
@@ -33,6 +33,7 @@ enum namespace {
 	NS_ITERATOR = 32,
 	NS_PREPROCESSOR = 64,
 	NS_UNDEF = 128,
+	NS_KEYWORD = 256,
 };
 
 enum type {
@@ -53,9 +54,18 @@ enum type {
 	SYM_LABEL,
 	SYM_RESTRICT,
 	SYM_FOULED,
+	SYM_KEYWORD,
 	SYM_BAD,
 };
 
+enum keyword {
+	KW_SPECIFIER 	= 1 << 0,
+	KW_MODIFIER	= 1 << 1,
+	KW_QUALIFIER	= 1 << 2,
+	KW_ATTRIBUTE	= 1 << 3,
+	KW_TYPEOF	= 1 << 4,
+};
+
 struct context {
 	struct expression *context;
 	unsigned int in, out;
@@ -74,9 +84,13 @@ struct ctype {
 };
 
 struct symbol_op {
+	enum keyword type;
 	int (*evaluate)(struct expression *);
 	int (*expand)(struct expression *, int);
 	int (*args)(struct expression *);
+
+	/* keywrods */
+	struct token *(*declarator)(struct token *token, struct ctype *ctype);
 };	
 
 extern int expand_safe_p(struct expression *expr, int cost);
@@ -87,8 +101,8 @@ extern int expand_constant_p(struct expr
 #define SYM_ATTR_STRONG		2
 
 struct symbol {
-	enum namespace namespace:8;
 	enum type type:8;
+	enum namespace namespace:9;
 	unsigned char used:1, attr:2;
 	struct position pos;		/* Where this symbol was declared */
 	struct ident *ident;		/* What identifier this symbol is associated with */
@@ -159,12 +173,7 @@ struct symbol {
 #define MOD_LONGLONG	0x0800
 
 #define MOD_TYPEDEF	0x1000
-#define MOD_STRUCTOF	0x2000
-#define MOD_UNIONOF	0x4000
-#define MOD_ENUMOF	0x8000
 
-#define MOD_TYPEOF	0x10000
-#define MOD_ATTRIBUTE	0x20000
 #define MOD_INLINE	0x40000
 #define MOD_ADDRESSABLE	0x80000
 
@@ -185,7 +194,6 @@ struct symbol {
 
 #define MOD_NONLOCAL	(MOD_EXTERN | MOD_TOPLEVEL)
 #define MOD_STORAGE	(MOD_AUTO | MOD_REGISTER | MOD_STATIC | MOD_EXTERN | MOD_INLINE | MOD_TOPLEVEL)
-#define MOD_SPECIALBITS (MOD_STRUCTOF | MOD_UNIONOF | MOD_ENUMOF | MOD_ATTRIBUTE | MOD_TYPEOF)
 #define MOD_SIGNEDNESS	(MOD_SIGNED | MOD_UNSIGNED | MOD_EXPLICITLY_SIGNED)
 #define MOD_SPECIFIER	(MOD_CHAR | MOD_SHORT | MOD_LONG | MOD_LONGLONG | MOD_SIGNEDNESS)
 #define MOD_SIZE	(MOD_CHAR | MOD_SHORT | MOD_LONG | MOD_LONGLONG)

Index: sparse/lib.c
===================================================================

token.h +2 -1
Index: sparse/token.h
===================================================================
@@ -54,7 +54,8 @@ struct ident {
 	struct symbol *symbols;	/* Pointer to semantic meaning list */
 	unsigned char len;	/* Length of identifier name */
 	unsigned char tainted:1,
-	              reserved:1;
+	              reserved:1,
+		      keyword:1;
 	char name[];		/* Actual identifier */
 };