implement #strong_undef
PATCH 7/7 implement #strong_undef
Example
// pre-buffer #strong_undef CONFIG_SMP // include/linux/autoconf.h #define CONFIG_SMP 1 // silently ignored #ifdef CONFIG_SMP ... // not taken #endif
Signed-off-by Oleg Nesterov <[email protected]>
pre-process.c renamed from pre-process.c~7_UNDEF +24 -6
@@ -1084,14 +1084,14 @@ static int do_handle_define(struct streareturn 1 ; ret =1 ; - sym =lookup_macro (name); + sym =lookup_symbol (name,NS_MACRO |NS_UNDEF );if (sym) {int clean;if (attr < sym->attr) goto out; - clean = (attr == sym->attr); + clean = (attr == sym->attr && sym->namespace ==NS_MACRO );if (token_list_different (sym->expansion, expansion) ||token_list_different (sym->arglist, arglist)) {
@@ -1118,6 +1118,7 @@ static int do_handle_define(struct strea__free_token (token);/* Free the "define" token, but not the rest of the line */ } + sym->namespace =NS_MACRO ; sym->used_in =NULL ; sym->attr = attr; out:
@@ -1139,7 +1140,7 @@ static int handle_strong_define(struct sreturn do_handle_define (stream, line, token,SYM_ATTR_STRONG ); } -static int handle_undef (struct stream *stream,struct token **line,struct token *token) +static int do_handle_undef (struct stream *stream,struct token **line,struct token *token,int attr) {struct token *left = token->next;struct symbol *sym;
@@ -1149,21 +1150,37 @@ static int handle_undef(struct stream *sreturn 1 ; } - sym =lookup_macro (left->ident); -if (!sym || sym->attr >SYM_ATTR_NORMAL ) + sym =lookup_symbol (left->ident,NS_MACRO |NS_UNDEF ); +if (sym) { +if (attr < sym->attr) +return 1 ; +if (attr == sym->attr && sym->namespace ==NS_UNDEF ) +return 1 ; + }else if (attr <=SYM_ATTR_NORMAL )return 1 ; -if (sym->scope != file_scope) { +if (!sym || sym->scope != file_scope) { sym =alloc_symbol (left->pos,SYM_NODE );bind_symbol (sym, left->ident,NS_MACRO ); } sym->namespace =NS_UNDEF ; sym->used_in =NULL ; + sym->attr = attr;return 1 ; } +static int handle_undef (struct stream *stream,struct token **line,struct token *token) +{ +return do_handle_undef (stream, line, token,SYM_ATTR_NORMAL ); +} + +static int handle_strong_undef (struct stream *stream,struct token **line,struct token *token) +{ +return do_handle_undef (stream, line, token,SYM_ATTR_STRONG ); +} +static int preprocessor_if (struct stream *stream,struct token *token,int true) {token_type (token) = false_nesting ?TOKEN_SKIP_GROUPS :TOKEN_IF ;
@@ -1574,6 +1591,7 @@ static void init_preprocessor(void) { "weak_define", handle_weak_define }, { "strong_define", handle_strong_define }, { "undef", handle_undef }, + { "strong_undef", handle_strong_undef }, { "warning", handle_warning }, { "error", handle_error }, { "include", handle_include },