forked from Mirrors/tinycc
tccpp: Implement __BASE_FILE__ macro
Like __FILE__ but always refers to the command line file name also from inside headers.master
parent
8a1a2a6033
commit
b7e0b693a6
6
tccpp.c
6
tccpp.c
|
@ -3465,6 +3465,7 @@ ST_INLN void unget_tok(int last_tok)
|
||||||
|
|
||||||
ST_FUNC void preprocess_start(TCCState *s1)
|
ST_FUNC void preprocess_start(TCCState *s1)
|
||||||
{
|
{
|
||||||
|
char *buf;
|
||||||
s1->include_stack_ptr = s1->include_stack;
|
s1->include_stack_ptr = s1->include_stack;
|
||||||
/* XXX: move that before to avoid having to initialize
|
/* XXX: move that before to avoid having to initialize
|
||||||
file->ifdef_stack_ptr ? */
|
file->ifdef_stack_ptr ? */
|
||||||
|
@ -3480,6 +3481,11 @@ ST_FUNC void preprocess_start(TCCState *s1)
|
||||||
s1->dollars_in_identifiers ? IS_ID : 0;
|
s1->dollars_in_identifiers ? IS_ID : 0;
|
||||||
isidnum_table['.' - CH_EOF] =
|
isidnum_table['.' - CH_EOF] =
|
||||||
(parse_flags & PARSE_FLAG_ASM_FILE) ? IS_ID : 0;
|
(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) {
|
if (s1->nb_cmd_include_files) {
|
||||||
CString cstr;
|
CString cstr;
|
||||||
int i;
|
int i;
|
||||||
|
|
|
@ -59,6 +59,8 @@
|
||||||
|
|
||||||
#include "tcclib.h"
|
#include "tcclib.h"
|
||||||
|
|
||||||
|
#include "tcctest.h"
|
||||||
|
|
||||||
void intdiv_test();
|
void intdiv_test();
|
||||||
void string_test();
|
void string_test();
|
||||||
void expr_test();
|
void expr_test();
|
||||||
|
@ -389,6 +391,11 @@ comment
|
||||||
/* And again when the name and parenthes are separated by a
|
/* And again when the name and parenthes are separated by a
|
||||||
comment. */
|
comment. */
|
||||||
TEST2 /* the comment */ ();
|
TEST2 /* the comment */ ();
|
||||||
|
|
||||||
|
printf("%s\n", get_basefile_from_header());
|
||||||
|
printf("%s\n", __BASE_FILE__);
|
||||||
|
printf("%s\n", get_file_from_header());
|
||||||
|
printf("%s\n", __FILE__);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,9 @@
|
||||||
|
static inline const char *get_basefile_from_header(void)
|
||||||
|
{
|
||||||
|
return __BASE_FILE__;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline const char *get_file_from_header(void)
|
||||||
|
{
|
||||||
|
return __FILE__;
|
||||||
|
}
|
Loading…
Reference in New Issue