[PATCH 3/4] dyn-macro: add support for __INCLUDE_LEVEL__

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This macro, which is supported by GCC, wasn't yet by sparse.

Add support for it.

Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@xxxxxxxxx>
---
 pre-process.c                           |  9 +++++++++
 validation/preprocessor/dynamic.c       |  4 ++++
 validation/preprocessor/include-level.c | 14 ++++++++++++++
 validation/preprocessor/include-level.h |  1 +
 4 files changed, 28 insertions(+)
 create mode 100644 validation/preprocessor/include-level.c
 create mode 100644 validation/preprocessor/include-level.h

diff --git a/pre-process.c b/pre-process.c
index 1e4725439..14c39b7af 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 a829542f8..9d1dcc085 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 000000000..b5e5e6036
--- /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 000000000..cbc101825
--- /dev/null
+++ b/validation/preprocessor/include-level.h
@@ -0,0 +1 @@
+__FILE__: __INCLUDE_LEVEL__
-- 
2.17.1

--
To unsubscribe from this list: send the line "unsubscribe linux-sparse" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Newbies FAQ]     [LKML]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Trinity Fuzzer Tool]

  Powered by Linux