aboutsummaryrefslogtreecommitdiff
path: root/tccpp.c
diff options
context:
space:
mode:
authorMichael Matz <matz@suse.de>2016-07-13 15:37:36 +0200
committerMichael Matz <matz@suse.de>2016-12-15 17:47:08 +0100
commitb7e0b693a65793a5aeee51cf9fa58638376c6f06 (patch)
treedcef22c357f914889f930807c88ccd6574893bfe /tccpp.c
parent8a1a2a60336264a5f96fae4c7f02424c6928b7c3 (diff)
downloadtinycc-b7e0b693a65793a5aeee51cf9fa58638376c6f06.tar.gz
tinycc-b7e0b693a65793a5aeee51cf9fa58638376c6f06.tar.bz2
tccpp: Implement __BASE_FILE__ macro
Like __FILE__ but always refers to the command line file name also from inside headers.
Diffstat (limited to 'tccpp.c')
-rw-r--r--tccpp.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/tccpp.c b/tccpp.c
index 151bce6..1838a3a 100644
--- a/tccpp.c
+++ b/tccpp.c
@@ -3465,6 +3465,7 @@ ST_INLN void unget_tok(int last_tok)
ST_FUNC void preprocess_start(TCCState *s1)
{
+ char *buf;
s1->include_stack_ptr = s1->include_stack;
/* XXX: move that before to avoid having to initialize
file->ifdef_stack_ptr ? */
@@ -3480,6 +3481,11 @@ ST_FUNC void preprocess_start(TCCState *s1)
s1->dollars_in_identifiers ? IS_ID : 0;
isidnum_table['.' - CH_EOF] =
(parse_flags & PARSE_FLAG_ASM_FILE) ? IS_ID : 0;
+ buf = tcc_malloc(3 + strlen(file->filename));
+ sprintf(buf, "\"%s\"", file->filename);
+ tcc_undefine_symbol(s1, "__BASE_FILE__");
+ tcc_define_symbol(s1, "__BASE_FILE__", buf);
+ tcc_free(buf);
if (s1->nb_cmd_include_files) {
CString cstr;
int i;