aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
-rw-r--r--lib.c6
-rw-r--r--lib.h2
-rw-r--r--pre-process.c6
-rw-r--r--validation/preprocessor/base-file.c17
-rw-r--r--validation/preprocessor/base-file.h2
-rw-r--r--validation/preprocessor/dynamic.c4
6 files changed, 34 insertions, 3 deletions
diff --git a/lib.c b/lib.c
index c451a88c..30d1cf6d 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;
@@ -1256,9 +1258,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)
@@ -1314,6 +1313,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 d7bd3651..4d613936 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 14c39b7a..88be02f1 100644
--- a/pre-process.c
+++ b/pre-process.c
@@ -165,6 +165,11 @@ static void expand_file(struct token *token)
replace_with_string(token, stream_name(token->pos.stream));
}
+static void expand_basefile(struct token *token)
+{
+ replace_with_string(token, base_filename);
+}
+
static time_t t = 0;
static void expand_date(struct token *token)
{
@@ -1924,6 +1929,7 @@ static void init_preprocessor(void)
} dynamic[] = {
{ "__LINE__", expand_line },
{ "__FILE__", expand_file },
+ { "__BASE_FILE__", expand_basefile },
{ "__DATE__", expand_date },
{ "__TIME__", expand_time },
{ "__COUNTER__", expand_counter },
diff --git a/validation/preprocessor/base-file.c b/validation/preprocessor/base-file.c
new file mode 100644
index 00000000..61a290cb
--- /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 00000000..018b16c5
--- /dev/null
+++ b/validation/preprocessor/base-file.h
@@ -0,0 +1,2 @@
+__FILE__
+__BASE_FILE__
diff --git a/validation/preprocessor/dynamic.c b/validation/preprocessor/dynamic.c
index 9d1dcc08..f791ba39 100644
--- a/validation/preprocessor/dynamic.c
+++ b/validation/preprocessor/dynamic.c
@@ -4,6 +4,9 @@ __LINE__
#if defined(__FILE__)
__FILE__
#endif
+#if defined(__BASE_FILE__)
+__BASE_FILE__
+#endif
#if defined(__DATE__)
date
#endif
@@ -25,6 +28,7 @@ __INCLUDE_LEVEL__
2
"preprocessor/dynamic.c"
+"preprocessor/dynamic.c"
date
time
counter