History

Preprocessor fix + new testcase

herman ten brugge committed 2 years ago

Commit 6379f2e1 parent 48798963 files · +122 −1Browse files

Unified · Split

3 files
  1. tccpp.c +2 −1
  2. tests/pp/23.c +117 −0
  3. tests/pp/23.expect +3 −0
tccpp.c+2−1
@@ -3023,7 +3023,8 @@ static int *macro_arg_subst(Sym **nested_list, const int *macro_str, Sym *args) · 3022 unmodified lines
30233023 }
30243024 if (*st <= 0) {
30253025 /* expanded to empty string */
3026− tok_str_add(&str, TOK_PLCHLDR);
3026+ if (str.len)
3027+ tok_str_add(&str, TOK_PLCHLDR);
30273028 } else for (;;) {
30283029 int t2;
30293030 TOK_GET(&t2, &st, &cval);
tests/pp/23.c+117−0
@@ -0,0 +1,117 @@
1+#define M_DEFERRED_COMMA ,
2+
3+#define M_EAT(...)
4+#define M_APPLY(a, ...) a (__VA_ARGS__)
5+#define M_ID(...) __VA_ARGS__
6+
7+#define M_C2I(a, ...) a ## __VA_ARGS__
8+#define M_C(a, ...) M_C2I(a, __VA_ARGS__)
9+#define M_C3I(a, b, ...) a ## b ## __VA_ARGS__
10+#define M_C3(a, b, ...) M_C3I(a ,b, __VA_ARGS__)
11+#define M_C4I(a, b, c, ...) a ## b ## c ## __VA_ARGS__
12+#define M_C4(a, b, c, ...) M_C4I(a ,b, c, __VA_ARGS__)
13+
14+#define M_INVI_0 1
15+#define M_INVI_1 0
16+#define M_INV(x) M_C(M_INVI_, x)
17+
18+#define M_ANDI_00 0
19+#define M_ANDI_01 0
20+#define M_ANDI_10 0
21+#define M_ANDI_11 1
22+#define M_AND(x,y) M_C3(M_ANDI_, x, y)
23+
24+#define M_ANDI_000 0
25+#define M_ANDI_001 0
26+#define M_ANDI_010 0
27+#define M_ANDI_011 0
28+#define M_ANDI_100 0
29+#define M_ANDI_101 0
30+#define M_ANDI_110 0
31+#define M_ANDI_111 1
32+#define M_AND3(x,y,z) M_C4(M_ANDI_, x, y, z)
33+
34+#define M_ORI_00 0
35+#define M_ORI_01 1
36+#define M_ORI_10 1
37+#define M_ORI_11 1
38+#define M_OR(x,y) M_C3(M_ORI_, x, y)
39+
40+#define M_ORI_000 0
41+#define M_ORI_001 1
42+#define M_ORI_010 1
43+#define M_ORI_011 1
44+#define M_ORI_100 1
45+#define M_ORI_101 1
46+#define M_ORI_110 1
47+#define M_ORI_111 1
48+#define M_OR3(x,y,z) M_C4(M_ORI_, x, y, z)
49+
50+#define M_RETI_ARG2(_1, _2, ...) _2
51+#define M_RET_ARG2(...) M_RETI_ARG2(__VA_ARGS__,)
52+
53+#define M_RETI_ARG4(_1, _2, _3, _4, ...) _4
54+#define M_RET_ARG4(...) M_RETI_ARG4(__VA_ARGS__,)
55+
56+#define M_TOBOOLI_0 1, 0,
57+#define M_BOOL(x) M_RET_ARG2(M_C(M_TOBOOLI_, x), 1, useless)
58+
59+#define M_IFI_0(true_c, ...) __VA_ARGS__
60+#define M_IFI_1(true_c, ...) true_c
61+#define M_IF(c) M_C(M_IFI_, M_BOOL(c))
62+
63+#define M_NARGS(...) M_RET_ARG4(__VA_ARGS__, 3, 2, 1, useless)
64+
65+#define M_MAP(...) M_MAP_0(__VA_ARGS__)
66+#define M_MAP_0(f, ...) M_C(M_MAP_, M_NARGS(__VA_ARGS__))(f, __VA_ARGS__)
67+#define M_MAP_1(f, _1) f(_1)
68+#define M_MAP_2(f, _1, _2) f(_1) f(_2)
69+#define M_MAP_3(f, _1, _2, _3) f(_1) f(_2) f(_3)
70+
71+#define M_MAP2(...) M_MAP2I_0(__VA_ARGS__)
72+#define M_MAP2I_0(f, d, ...) M_C(M_MAP2I_, M_NARGS(__VA_ARGS__))(f, d, __VA_ARGS__)
73+#define M_MAP2I_1(f, d, _1) f(d, _1)
74+#define M_MAP2I_2(f, d, _1, _2) f(d, _1) f(d, _2)
75+#define M_MAP2I_3(f, d, _1, _2, _3) f(d, _1) f(d, _2) f(d, _3)
76+
77+#define M_CROSS_MAP(f, alist, blist) M_CROSSI_MAP1(f, alist, blist)
78+#define M_CROSSI_MAP1(f, alist, blist) M_C(M_CROSSI_MAP1_, M_NARGS alist)(f, blist, M_ID alist)
79+#define M_CROSSI_MAP1_1(...) M_CROSSI_MAP1_1b(__VA_ARGS__)
80+#define M_CROSSI_MAP1_1b(f, blist, a1) M_MAP2(f, a1, M_ID blist)
81+#define M_CROSSI_MAP1_2(...) M_CROSSI_MAP1_2b(__VA_ARGS__)
82+#define M_CROSSI_MAP1_2b(f, blist, a1, a2) M_MAP2(f, a1, M_ID blist) M_MAP2(f, a2, M_ID blist)
83+#define M_CROSSI_MAP1_3(...) M_CROSSI_MAP1_3b(__VA_ARGS__)
84+#define M_CROSSI_MAP1_3b(f, blist, a1, a2, a3) M_MAP2(f, a1, M_ID blist) M_MAP2(f, a2, M_ID blist) M_MAP2(f, a3, M_ID blist)
85+
86+#define M_COMMA_P(...) M_RETI_ARG4(__VA_ARGS__, 1, 1, 0, useless)
87+
88+#define M_PARENTHESISI_DETECT1(...) ,
89+#define M_PARENTHESIS_P(...) \
90+ M_AND3(M_COMMA_P(M_PARENTHESISI_DETECT1 __VA_ARGS__), \
91+ M_INV(M_COMMA_P(__VA_ARGS__)), \
92+ M_EMPTY_P(M_EAT __VA_ARGS__))
93+
94+#define M_EMPTYI_DETECT(...) ,
95+#define M_EMPTYI_P_C1(...) M_COMMA_P(M_EMPTYI_DETECT __VA_ARGS__ () )
96+#define M_EMPTYI_P_C2(...) M_COMMA_P(M_EMPTYI_DETECT __VA_ARGS__)
97+#define M_EMPTYI_P_C3(...) M_COMMA_P(__VA_ARGS__ () )
98+#define M_EMPTY_P(...) M_AND(M_EMPTYI_P_C1(__VA_ARGS__), M_INV(M_OR3(M_EMPTYI_P_C2(__VA_ARGS__), M_COMMA_P(__VA_ARGS__),M_EMPTYI_P_C3(__VA_ARGS__))))
99+
100+#define M_G3N_IS_PRESENT(num) \
101+ M_IF(M_PARENTHESIS_P(M_C(M_GENERIC_ORG_, num)() ))(M_DEFERRED_COMMA M_ID M_C(M_GENERIC_ORG_, num)(), )
102+
103+#define M_G3N_IS_PRESENT2(el1, num) \
104+ M_IF(M_PARENTHESIS_P(M_C4(M_GENERIC_ORG_, el1, _COMP_, num)()))(M_DEFERRED_COMMA M_APPLY(M_C3, el1, _COMP_, M_ID M_C4(M_GENERIC_ORG_, el1, _COMP_, num)()), )
105+
106+#define FLT1 (GENTYPE(float), TYPE(float) )
107+
108+#define M_GENERIC_ORG_2() (USER)
109+#define M_GENERIC_ORG_USER_COMP_1() (CORE)
110+#define M_GENERIC_ORG_USER_COMP_CORE_OPLIST_6() FLT1
111+
112+// Shall expand to ", USER"
113+M_MAP(M_G3N_IS_PRESENT, 1, 2, 3)
114+// Shall expand to ", USER_COMP_CORE"
115+M_CROSS_MAP(M_G3N_IS_PRESENT2, (MLIB , USER), ( 1, 2, 3 ) )
116+// Shall expand to ", USER_COMP_CORE" (composition of both) [fail]
117+M_CROSS_MAP(M_G3N_IS_PRESENT2, (MLIB M_MAP(M_G3N_IS_PRESENT, 1, 2, 3)), ( 1, 2, 3 ) )
tests/pp/23.expect+3−0
@@ -0,0 +1,3 @@
1+ , USER
2+ , USER_COMP_CORE
3+ , USER_COMP_CORE

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