@@ -104,6 +104,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);
@@ -1038,9 +1038,6 @@ 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)
add_pre_buffer("#define __OPTIMIZE__ 1\n");
if (optimize_size)
@@ -172,6 +172,10 @@ 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) {
+ const char *base = stream_name(token->pos.stream);
+ base = sparse_basename(base);
+ replace_with_string(token, base);
} else if (token->ident == &__DATE___ident) {
if (!t)
time(&t);
new file mode 100644
@@ -0,0 +1,11 @@
+__BASE_FILE__
+
+/*
+ * check-name: __BASE_FILE__
+ * check-command: sparse -E $file
+ *
+ * check-output-start
+
+"__BASE_FILE__.c"
+ * check-output-end
+ */
There was some support of it but it was probably just for sparse to not complain as it was a define that expanded to the fixed name "base_file.c". Fix this by letting it expand to the basename of the input file. Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com> --- ident-list.h | 1 + lib.c | 3 --- pre-process.c | 4 ++++ validation/preprocessor/__BASE_FILE__.c | 11 +++++++++++ 4 files changed, 16 insertions(+), 3 deletions(-) create mode 100644 validation/preprocessor/__BASE_FILE__.c