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
1929 break;1929 break;
1930 1930
1931 case TOK_LINE:1931 case TOK_LINE:
1932 next_nomacro();1932 next();
1933 if (tok != TOK_PPNUM) {1933 if (tok != TOK_CINT) {
1934 _line_err:1934 _line_err:
1935 tcc_error("wrong #line format");1935 tcc_error("wrong #line format");
1936 }1936 }
1937 n = tokc.i;
1937 goto _line_num;1938 goto _line_num;
1938 case TOK_PPNUM:1939 case TOK_PPNUM:
1939 if (parse_flags & PARSE_FLAG_ASM_FILE)1940 if (parse_flags & PARSE_FLAG_ASM_FILE)
1940 goto ignore;1941 goto ignore;
1941 _line_num:
1942 for (n = 0, q = tokc.str.data; *q; ++q) {1942 for (n = 0, q = tokc.str.data; *q; ++q) {
1943 if (!isnum(*q))1943 if (!isnum(*q))
1944 goto _line_err;1944 goto _line_err;
1945 n = n * 10 + *q - '0';1945 n = n * 10 + *q - '0';
1946 }1946 }
1947 next_nomacro();1947 _line_num:
1948 if (tok != TOK_LINEFEED) {1948 next();
1949 if (tok == TOK_PPSTR && tokc.str.data[0] == '"') {1949 if (tok == TOK_STR) {
1950 tokc.str.data[tokc.str.size - 2] = 0;1950 tccpp_putfile(tokc.str.data);
1951 tccpp_putfile(tokc.str.data + 1);1951 n--;
1952 } else1952 }
1953 goto _line_err;1953 else if (tok != TOK_LINEFEED)
1954 }1954 goto _line_err;
1955 if (macro_ptr && *macro_ptr == 0)
1956 macro_stack->save_line_num = n;
1955 if (file->fd > 0)1957 if (file->fd > 0)
1956 total_lines += file->line_num - n;1958 total_lines += file->line_num - n;
1959 file->line_ref += file->line_num - n;
1957 file->line_num = n;1960 file->line_num = n;
1958 goto ignore; /* skip optional level number */1961 goto ignore; /* skip optional level number */
1959 1962
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 @@
11
23
320
422
530
640 "23.S"
750 "file1"
860 "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