History

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

herman ten brugge committed 1 year ago

Commit 999ec461 parent 68000c03 files · +41 −11Browse files

Unified · Split

3 files
  1. tccpp.c +14 −11
  2. tests/pp/23.S +19 −0
  3. tests/pp/23.expect +8 −0
tccpp.c+14−11
@@ -1929,31 +1929,34 @@ ST_FUNC void preprocess(int is_bof) · 1928 unmodified lines
19291929 break;
19301930
19311931 case TOK_LINE:
1932− next_nomacro();
1933− if (tok != TOK_PPNUM) {
1932+ next();
1933+ if (tok != TOK_CINT) {
19341934 _line_err:
19351935 tcc_error("wrong #line format");
19361936 }
1937+ n = tokc.i;
19371938 goto _line_num;
19381939 case TOK_PPNUM:
19391940 if (parse_flags & PARSE_FLAG_ASM_FILE)
19401941 goto ignore;
1941− _line_num:
19421942 for (n = 0, q = tokc.str.data; *q; ++q) {
19431943 if (!isnum(*q))
19441944 goto _line_err;
19451945 n = n * 10 + *q - '0';
19461946 }
1947− next_nomacro();
1948− if (tok != TOK_LINEFEED) {
1949− if (tok == TOK_PPSTR && tokc.str.data[0] == '"') {
1950− tokc.str.data[tokc.str.size - 2] = 0;
1951− tccpp_putfile(tokc.str.data + 1);
1952− } else
1953− goto _line_err;
1954− }
1947+ _line_num:
1948+ next();
1949+ if (tok == TOK_STR) {
1950+ tccpp_putfile(tokc.str.data);
1951+ n--;
1952+ }
1953+ else if (tok != TOK_LINEFEED)
1954+ goto _line_err;
1955+ if (macro_ptr && *macro_ptr == 0)
1956+ macro_stack->save_line_num = n;
19551957 if (file->fd > 0)
19561958 total_lines += file->line_num - n;
1959+ file->line_ref += file->line_num - n;
19571960 file->line_num = n;
19581961 goto ignore; /* skip optional level number */
19591962
tests/pp/23.S+19−0
@@ -0,0 +1,19 @@
1+__LINE__
2+# 10
3+__LINE__
4+# line 20
5+__LINE__
6+# 64mb
7+__LINE__
8+# line 30
9+__LINE__
10+#define LINE1 40
11+# line LINE1
12+__LINE__ __FILE__
13+#define LINE2 50
14+# line LINE2 "file1"
15+__LINE__ __FILE__
16+#define LINE3 60
17+#define FILE "file2"
18+# line LINE3 FILE
19+__LINE__ __FILE__
tests/pp/23.expect+8−0
@@ -0,0 +1,8 @@
1+1
2+3
3+20
4+22
5+30
6+40 "23.S"
7+50 "file1"
8+60 "file2"

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