History

tccpp: Implement __BASE_FILE__ macro

Like __FILE__ but always refers to the command line file name also from inside headers.

Michael Matz committed 10 years ago

Commit b7e0b691 parent 8a1a2a63 files · +22 −0Browse files

Unified · Split

3 files
  1. tccpp.c +6 −0
  2. tests/tcctest.c +7 −0
  3. tests/tcctest.h +9 −0
tccpp.c+6−0
@@ -3465,6 +3465,7 @@ ST_INLN void unget_tok(int last_tok) · 3464 unmodified lines
3465 3465
3466ST_FUNC void preprocess_start(TCCState *s1)3466ST_FUNC void preprocess_start(TCCState *s1)
3467{3467{
3468 char *buf;
3468 s1->include_stack_ptr = s1->include_stack;3469 s1->include_stack_ptr = s1->include_stack;
3469 /* XXX: move that before to avoid having to initialize3470 /* XXX: move that before to avoid having to initialize
3470 file->ifdef_stack_ptr ? */3471 file->ifdef_stack_ptr ? */
@@ -3480,6 +3481,11 @@ ST_FUNC void preprocess_start(TCCState *s1) · 9 unmodified lines
3480 s1->dollars_in_identifiers ? IS_ID : 0;3481 s1->dollars_in_identifiers ? IS_ID : 0;
3481 isidnum_table['.' - CH_EOF] =3482 isidnum_table['.' - CH_EOF] =
3482 (parse_flags & PARSE_FLAG_ASM_FILE) ? IS_ID : 0;3483 (parse_flags & PARSE_FLAG_ASM_FILE) ? IS_ID : 0;
3484 buf = tcc_malloc(3 + strlen(file->filename));
3485 sprintf(buf, "\"%s\"", file->filename);
3486 tcc_undefine_symbol(s1, "__BASE_FILE__");
3487 tcc_define_symbol(s1, "__BASE_FILE__", buf);
3488 tcc_free(buf);
3483 if (s1->nb_cmd_include_files) {3489 if (s1->nb_cmd_include_files) {
3484 CString cstr;3490 CString cstr;
3485 int i;3491 int i;
tests/tcctest.c+7−0
@@ -59,6 +59,8 @@ · 58 unmodified lines
59 59
60#include "tcclib.h"60#include "tcclib.h"
61 61
62#include "tcctest.h"
63
62void intdiv_test();64void intdiv_test();
63void string_test();65void string_test();
64void expr_test();66void expr_test();
@@ -389,6 +391,11 @@ comment · 324 unmodified lines
389 /* And again when the name and parenthes are separated by a391 /* And again when the name and parenthes are separated by a
390 comment. */392 comment. */
391 TEST2 /* the comment */ ();393 TEST2 /* the comment */ ();
394
395 printf("%s\n", get_basefile_from_header());
396 printf("%s\n", __BASE_FILE__);
397 printf("%s\n", get_file_from_header());
398 printf("%s\n", __FILE__);
392}399}
393 400
394 401
tests/tcctest.h+9−0
@@ -0,0 +1,9 @@
1static inline const char *get_basefile_from_header(void)
2{
3 return __BASE_FILE__;
4}
5
6static inline const char *get_file_from_header(void)
7{
8 return __FILE__;
9}

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t