diff options
| -rw-r--r-- | pre-process.c | 9 | ||||
| -rw-r--r-- | validation/preprocessor/dynamic.c | 4 | ||||
| -rw-r--r-- | validation/preprocessor/include-level.c | 14 | ||||
| -rw-r--r-- | validation/preprocessor/include-level.h | 1 |
4 files changed, 28 insertions, 0 deletions
diff --git a/pre-process.c b/pre-process.c index 1e472543..14c39b7a 100644 --- a/pre-process.c +++ b/pre-process.c @@ -47,6 +47,7 @@ static struct ident_list *macros; // only needed for -dD static int false_nesting = 0; static int counter_macro = 0; // __COUNTER__ expansion +static int include_level = 0; #define INCLUDEPATHS 300 const char *includepath[INCLUDEPATHS+1] = { @@ -190,6 +191,11 @@ static void expand_counter(struct token *token) replace_with_integer(token, counter_macro++); } +static void expand_include_level(struct token *token) +{ + replace_with_integer(token, include_level - 1); +} + static int expand_one_symbol(struct token **list) { struct token *token = *list; @@ -1921,6 +1927,7 @@ static void init_preprocessor(void) { "__DATE__", expand_date }, { "__TIME__", expand_time }, { "__COUNTER__", expand_counter }, + { "__INCLUDE_LEVEL__", expand_include_level }, }; for (i = 0; i < ARRAY_SIZE(normal); i++) { @@ -2021,9 +2028,11 @@ static void do_preprocess(struct token **list) if (!stream->dirty) stream->constant = CONSTANT_FILE_YES; *list = next->next; + include_level--; continue; case TOKEN_STREAMBEGIN: *list = next->next; + include_level++; continue; default: diff --git a/validation/preprocessor/dynamic.c b/validation/preprocessor/dynamic.c index a829542f..9d1dcc08 100644 --- a/validation/preprocessor/dynamic.c +++ b/validation/preprocessor/dynamic.c @@ -13,6 +13,9 @@ time #if defined(__COUNTER__) counter #endif +#if defined(__INCLUDE_LEVEL__) +__INCLUDE_LEVEL__ +#endif /* * check-name: dynamic-macros @@ -25,5 +28,6 @@ counter date time counter +0 * check-output-end */ diff --git a/validation/preprocessor/include-level.c b/validation/preprocessor/include-level.c new file mode 100644 index 00000000..b5e5e603 --- /dev/null +++ b/validation/preprocessor/include-level.c @@ -0,0 +1,14 @@ +__FILE__: __INCLUDE_LEVEL__ + +#include "include-level.h" + +/* + * check-name: include-level + * check-command: sparse -E $file + * + * check-output-start + +"preprocessor/include-level.c": 0 +"preprocessor/include-level.h": 1 + * check-output-end + */ diff --git a/validation/preprocessor/include-level.h b/validation/preprocessor/include-level.h new file mode 100644 index 00000000..cbc10182 --- /dev/null +++ b/validation/preprocessor/include-level.h @@ -0,0 +1 @@ +__FILE__: __INCLUDE_LEVEL__ |
