Allow macro in #line directive
Using: #define LINE1 10 #line LINE1 #define LINE2 20 #define FILE "file" #line LINE2 FILE Should now work. Add new testcase tests/pp/23.S
This commit is contained in:
parent
68000c01ae
commit
999ec460a6
3 changed files with 40 additions and 10 deletions
23
tccpp.c
23
tccpp.c
|
@ -1929,31 +1929,34 @@ ST_FUNC void preprocess(int is_bof)
|
|||
break;
|
||||
|
||||
case TOK_LINE:
|
||||
next_nomacro();
|
||||
if (tok != TOK_PPNUM) {
|
||||
next();
|
||||
if (tok != TOK_CINT) {
|
||||
_line_err:
|
||||
tcc_error("wrong #line format");
|
||||
}
|
||||
n = tokc.i;
|
||||
goto _line_num;
|
||||
case TOK_PPNUM:
|
||||
if (parse_flags & PARSE_FLAG_ASM_FILE)
|
||||
goto ignore;
|
||||
_line_num:
|
||||
for (n = 0, q = tokc.str.data; *q; ++q) {
|
||||
if (!isnum(*q))
|
||||
goto _line_err;
|
||||
n = n * 10 + *q - '0';
|
||||
}
|
||||
next_nomacro();
|
||||
if (tok != TOK_LINEFEED) {
|
||||
if (tok == TOK_PPSTR && tokc.str.data[0] == '"') {
|
||||
tokc.str.data[tokc.str.size - 2] = 0;
|
||||
tccpp_putfile(tokc.str.data + 1);
|
||||
} else
|
||||
goto _line_err;
|
||||
_line_num:
|
||||
next();
|
||||
if (tok == TOK_STR) {
|
||||
tccpp_putfile(tokc.str.data);
|
||||
n--;
|
||||
}
|
||||
else if (tok != TOK_LINEFEED)
|
||||
goto _line_err;
|
||||
if (macro_ptr && *macro_ptr == 0)
|
||||
macro_stack->save_line_num = n;
|
||||
if (file->fd > 0)
|
||||
total_lines += file->line_num - n;
|
||||
file->line_ref += file->line_num - n;
|
||||
file->line_num = n;
|
||||
goto ignore; /* skip optional level number */
|
||||
|
||||
|
|
19
tests/pp/23.S
Normal file
19
tests/pp/23.S
Normal file
|
@ -0,0 +1,19 @@
|
|||
__LINE__
|
||||
# 10
|
||||
__LINE__
|
||||
# line 20
|
||||
__LINE__
|
||||
# 64mb
|
||||
__LINE__
|
||||
# line 30
|
||||
__LINE__
|
||||
#define LINE1 40
|
||||
# line LINE1
|
||||
__LINE__ __FILE__
|
||||
#define LINE2 50
|
||||
# line LINE2 "file1"
|
||||
__LINE__ __FILE__
|
||||
#define LINE3 60
|
||||
#define FILE "file2"
|
||||
# line LINE3 FILE
|
||||
__LINE__ __FILE__
|
8
tests/pp/23.expect
Normal file
8
tests/pp/23.expect
Normal file
|
@ -0,0 +1,8 @@
|
|||
1
|
||||
3
|
||||
20
|
||||
22
|
||||
30
|
||||
40 "23.S"
|
||||
50 "file1"
|
||||
60 "file2"
|
Loading…
Reference in a new issue