@@ -66,6 +66,7 @@ int get_size(var_t *var, type_t *type)
66
66
* whitespace */
67
67
void skip_line (int invalidate )
68
68
{
69
+ /* FIXME: Comments will causes current validation failed. */
69
70
skip_whitespace ();
70
71
do {
71
72
if (invalidate && !is_whitespace (peek_char (0 )) &&
@@ -75,28 +76,14 @@ void skip_line(int invalidate)
75
76
} while (read_char (0 ) != '\n' );
76
77
}
77
78
78
- void if_elif_skip_lines ()
79
- {
80
- char peek_c ;
81
- int i ;
82
-
83
- do {
84
- skip_whitespace ();
85
- i = 0 ;
86
- do {
87
- token_str [i ++ ] = next_char ;
88
- } while (read_char (0 ) != '\n' );
89
- token_str [i ] = 0 ;
90
- read_char (1 );
91
- peek_c = peek_char (1 );
92
- } while (next_char != '#' || (next_char == '#' && peek_c == 'd' ));
93
- skip_whitespace ();
94
- }
95
-
96
- void ifdef_else_skip_lines ()
79
+ /* Skips lines where preprocessor match is false, this will stop once next
80
+ * token is either `T_cppd_elif`, `T_cppd_else` or `cppd_endif`.
81
+ */
82
+ void cppd_control_flow_skip_lines ()
97
83
{
98
- while (!lex_peek (T_cppd_else , NULL ) && !lex_peek (T_cppd_endif , NULL )) {
99
- next_token = get_next_token ();
84
+ while (!lex_peek (T_cppd_elif , NULL ) && !lex_peek (T_cppd_else , NULL ) &&
85
+ !lex_peek (T_cppd_endif , NULL )) {
86
+ next_token = lex_token ();
100
87
}
101
88
skip_whitespace ();
102
89
}
@@ -111,12 +98,10 @@ void read_defined_macro()
111
98
{
112
99
char lookup_alias [MAX_TOKEN_LEN ];
113
100
114
- preproc_aliasing = 0 ; /* to prevent aggressive aliasing */
115
101
lex_expect (T_identifier ); /* defined */
116
- lex_expect (T_open_bracket );
102
+ lex_expect_internal (T_open_bracket , 0 );
117
103
lex_ident (T_identifier , lookup_alias );
118
104
lex_expect (T_close_bracket );
119
- preproc_aliasing = 1 ;
120
105
121
106
check_def (lookup_alias );
122
107
}
@@ -169,10 +154,8 @@ int read_preproc_directive()
169
154
if (lex_peek (T_cppd_undef , token )) {
170
155
char alias [MAX_VAR_LEN ];
171
156
172
- preproc_aliasing = 0 ;
173
- lex_expect (T_cppd_undef );
157
+ lex_expect_internal (T_cppd_undef , 0 );
174
158
lex_peek (T_identifier , alias );
175
- preproc_aliasing = 1 ;
176
159
lex_expect (T_identifier );
177
160
178
161
remove_alias (alias );
@@ -201,7 +184,7 @@ int read_preproc_directive()
201
184
return 1 ;
202
185
}
203
186
204
- if_elif_skip_lines ();
187
+ cppd_control_flow_skip_lines ();
205
188
} else {
206
189
/* TODO: parse and evaluate constant expression here */
207
190
}
@@ -210,7 +193,7 @@ int read_preproc_directive()
210
193
if (lex_accept (T_cppd_elif )) {
211
194
if (preproc_match ) {
212
195
while (!lex_peek (T_cppd_endif , NULL )) {
213
- next_token = get_next_token ();
196
+ next_token = lex_token ();
214
197
}
215
198
return 1 ;
216
199
}
@@ -223,7 +206,7 @@ int read_preproc_directive()
223
206
return 1 ;
224
207
}
225
208
226
- if_elif_skip_lines ();
209
+ cppd_control_flow_skip_lines ();
227
210
} else {
228
211
/* TODO: parse and evaluate constant expression here */
229
212
}
@@ -240,16 +223,15 @@ int read_preproc_directive()
240
223
return 1 ;
241
224
}
242
225
243
- /* skip lines until #else or #endif */
244
- ifdef_else_skip_lines ();
226
+ cppd_control_flow_skip_lines ();
245
227
return 1 ;
246
228
}
247
229
if (lex_accept (T_cppd_endif )) {
248
230
preproc_match = 0 ;
249
231
skip_whitespace ();
250
232
return 1 ;
251
233
}
252
- if (lex_accept (T_cppd_ifdef )) {
234
+ if (lex_accept_internal (T_cppd_ifdef , 0 )) {
253
235
preproc_match = 0 ;
254
236
lex_ident (T_identifier , token );
255
237
check_def (token );
@@ -259,8 +241,7 @@ int read_preproc_directive()
259
241
return 1 ;
260
242
}
261
243
262
- /* skip lines until #else or #endif */
263
- ifdef_else_skip_lines ();
244
+ cppd_control_flow_skip_lines ();
264
245
return 1 ;
265
246
}
266
247
@@ -677,12 +658,12 @@ void read_expr_operand(block_t *parent, basic_block_t **bb)
677
658
for (i = 0 ; i < remainder ; i ++ ) {
678
659
source_idx = macro -> params [macro -> num_params - remainder + i ];
679
660
next_char = SOURCE [source_idx ];
680
- next_token = get_next_token ();
661
+ next_token = lex_token ();
681
662
read_expr (parent , bb );
682
663
}
683
664
source_idx = t ;
684
665
next_char = SOURCE [source_idx ];
685
- next_token = get_next_token ();
666
+ next_token = lex_token ();
686
667
} else if (mac ) {
687
668
if (parent -> macro )
688
669
error ("Nested macro is not yet supported" );
@@ -695,7 +676,7 @@ void read_expr_operand(block_t *parent, basic_block_t **bb)
695
676
while (!lex_peek (T_close_bracket , NULL )) {
696
677
mac -> params [mac -> num_params ++ ] = source_idx ;
697
678
do {
698
- next_token = get_next_token ();
679
+ next_token = lex_token ();
699
680
} while (next_token != T_comma &&
700
681
next_token != T_close_bracket );
701
682
}
@@ -717,11 +698,11 @@ void read_expr_operand(block_t *parent, basic_block_t **bb)
717
698
int t = source_idx ;
718
699
source_idx = macro_param_idx ;
719
700
next_char = SOURCE [source_idx ];
720
- next_token = get_next_token ();
701
+ next_token = lex_token ();
721
702
read_expr (parent , bb );
722
703
source_idx = t ;
723
704
next_char = SOURCE [source_idx ];
724
- next_token = get_next_token ();
705
+ next_token = lex_token ();
725
706
} else if (con ) {
726
707
ph1_ir = add_ph1_ir (OP_load_constant );
727
708
vd = require_var (parent );
@@ -1599,15 +1580,15 @@ void eval_ternary_imm(int cond, char *token)
1599
1580
{
1600
1581
if (cond == 0 ) {
1601
1582
while (next_token != T_colon ) {
1602
- next_token = get_next_token ();
1583
+ next_token = lex_token ();
1603
1584
}
1604
1585
lex_accept (T_colon );
1605
1586
read_global_assignment (token );
1606
1587
} else {
1607
1588
read_global_assignment (token );
1608
1589
lex_expect (T_colon );
1609
1590
while (!lex_peek (T_semicolon , NULL )) {
1610
- next_token = get_next_token ();
1591
+ next_token = lex_token ();
1611
1592
}
1612
1593
}
1613
1594
}
@@ -2453,7 +2434,7 @@ basic_block_t *read_body_statement(block_t *parent, basic_block_t *bb)
2453
2434
while (!lex_peek (T_close_bracket , NULL )) {
2454
2435
mac -> params [mac -> num_params ++ ] = source_idx ;
2455
2436
do {
2456
- next_token = get_next_token ();
2437
+ next_token = lex_token ();
2457
2438
} while (next_token != T_comma && next_token != T_close_bracket );
2458
2439
}
2459
2440
/* move `source_idx` to the macro body */
0 commit comments