[PATCH] add real support for __BASE_FILE__

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

 



There was some support for it but it was just a define
that expanded to the fixed name "base_file.c".

Implement the real thing by saving the input filename
and replacing __BASE_FILE__ by it.

Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@xxxxxxxxx>
---
 ident-list.h                        |  1 +
 lib.c                               |  6 +++---
 lib.h                               |  2 ++
 pre-process.c                       |  2 ++
 validation/preprocessor/base-file.c | 17 +++++++++++++++++
 validation/preprocessor/base-file.h |  2 ++
 6 files changed, 27 insertions(+), 3 deletions(-)
 create mode 100644 validation/preprocessor/base-file.c
 create mode 100644 validation/preprocessor/base-file.h

diff --git a/ident-list.h b/ident-list.h
index 2f1fecb48..5e9daca52 100644
--- a/ident-list.h
+++ b/ident-list.h
@@ -63,6 +63,7 @@ __IDENT(pragma_ident, "__pragma__", 0);
 __IDENT(__VA_ARGS___ident, "__VA_ARGS__", 0);
 __IDENT(__LINE___ident, "__LINE__", 0);
 __IDENT(__FILE___ident, "__FILE__", 0);
+__IDENT(__BASE_FILE___ident, "__BASE_FILE__", 0);
 __IDENT(__DATE___ident, "__DATE__", 0);
 __IDENT(__TIME___ident, "__TIME__", 0);
 __IDENT(__func___ident, "__func__", 0);
diff --git a/lib.c b/lib.c
index 0be4548a6..3a3bb93a6 100644
--- a/lib.c
+++ b/lib.c
@@ -60,6 +60,8 @@ int gcc_major = __GNUC__;
 int gcc_minor = __GNUC_MINOR__;
 int gcc_patchlevel = __GNUC_PATCHLEVEL__;
 
+const char *base_filename;
+
 static const char *gcc_base_dir = GCC_BASE;
 static const char *multiarch_dir = MULTIARCH_TRIPLET;
 
@@ -1234,9 +1236,6 @@ static void create_builtin_stream(void)
 	add_pre_buffer("#define __builtin_ms_va_end(arg)\n");
 	add_pre_buffer("#define __builtin_va_arg_pack()\n");
 
-	/* FIXME! We need to do these as special magic macros at expansion time! */
-	add_pre_buffer("#define __BASE_FILE__ \"base_file.c\"\n");
-
 	if (optimize_level)
 		add_pre_buffer("#define __OPTIMIZE__ 1\n");
 	if (optimize_size)
@@ -1292,6 +1291,7 @@ static struct symbol_list *sparse_file(const char *filename)
 		if (fd < 0)
 			die("No such file: %s", filename);
 	}
+	base_filename = filename;
 
 	// Tokenize the input stream
 	token = tokenize(filename, fd, NULL, includepath);
diff --git a/lib.h b/lib.h
index aea46741d..89644d476 100644
--- a/lib.h
+++ b/lib.h
@@ -46,6 +46,8 @@ extern int die_if_error;
 extern int repeat_phase;
 extern int gcc_major, gcc_minor, gcc_patchlevel;
 
+extern const char *base_filename;
+
 extern unsigned int hexval(unsigned int c);
 
 struct position {
diff --git a/pre-process.c b/pre-process.c
index 7d335ab0c..9d0d981b4 100644
--- a/pre-process.c
+++ b/pre-process.c
@@ -173,6 +173,8 @@ static int expand_one_symbol(struct token **list)
 		replace_with_integer(token, token->pos.line);
 	} else if (token->ident == &__FILE___ident) {
 		replace_with_string(token, stream_name(token->pos.stream));
+	} else if (token->ident == &__BASE_FILE___ident) {
+		replace_with_string(token, base_filename);
 	} else if (token->ident == &__DATE___ident) {
 		if (!t)
 			time(&t);
diff --git a/validation/preprocessor/base-file.c b/validation/preprocessor/base-file.c
new file mode 100644
index 000000000..61a290cb0
--- /dev/null
+++ b/validation/preprocessor/base-file.c
@@ -0,0 +1,17 @@
+__FILE__
+__BASE_FILE__
+
+#include "base-file.h"
+
+/*
+ * check-name: base file
+ * check-command: sparse -E $file
+ *
+ * check-output-start
+
+"preprocessor/base-file.c"
+"preprocessor/base-file.c"
+"preprocessor/base-file.h"
+"preprocessor/base-file.c"
+ * check-output-end
+ */
diff --git a/validation/preprocessor/base-file.h b/validation/preprocessor/base-file.h
new file mode 100644
index 000000000..018b16c54
--- /dev/null
+++ b/validation/preprocessor/base-file.h
@@ -0,0 +1,2 @@
+__FILE__
+__BASE_FILE__
-- 
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