File tree 3 files changed +34
-5
lines changed
3 files changed +34
-5
lines changed Original file line number Diff line number Diff line change @@ -77,7 +77,8 @@ typedef enum {
77
77
T_cppd_elif ,
78
78
T_cppd_else ,
79
79
T_cppd_endif ,
80
- T_cppd_ifdef
80
+ T_cppd_ifdef ,
81
+ T_cppd_ifndef
81
82
} token_t ;
82
83
83
84
char token_str [MAX_TOKEN_LEN ];
@@ -206,6 +207,8 @@ token_t lex_token_internal(bool aliasing)
206
207
return T_cppd_elif ;
207
208
if (!strcmp (token_str , "#ifdef" ))
208
209
return T_cppd_ifdef ;
210
+ if (!strcmp (token_str , "#ifndef" ))
211
+ return T_cppd_ifndef ;
209
212
if (!strcmp (token_str , "#else" ))
210
213
return T_cppd_else ;
211
214
if (!strcmp (token_str , "#endif" ))
Original file line number Diff line number Diff line change @@ -334,9 +334,9 @@ void cppd_control_flow_skip_lines()
334
334
skip_whitespace ();
335
335
}
336
336
337
- void check_def (char * alias )
337
+ void check_def (char * alias , bool expected )
338
338
{
339
- if (find_alias (alias ))
339
+ if (( find_alias (alias ) != NULL ) == expected )
340
340
preproc_match = true;
341
341
}
342
342
@@ -349,7 +349,7 @@ void read_defined_macro()
349
349
lex_ident (T_identifier , lookup_alias );
350
350
lex_expect (T_close_bracket );
351
351
352
- check_def (lookup_alias );
352
+ check_def (lookup_alias , true );
353
353
}
354
354
355
355
/* read preprocessor directive at each potential positions: e.g.,
@@ -485,7 +485,20 @@ bool read_preproc_directive()
485
485
if (lex_accept_internal (T_cppd_ifdef , false)) {
486
486
preproc_match = false;
487
487
lex_ident (T_identifier , token );
488
- check_def (token );
488
+ check_def (token , true);
489
+
490
+ if (preproc_match ) {
491
+ skip_whitespace ();
492
+ return true;
493
+ }
494
+
495
+ cppd_control_flow_skip_lines ();
496
+ return true;
497
+ }
498
+ if (lex_accept_internal (T_cppd_ifndef , false)) {
499
+ preproc_match = false;
500
+ lex_ident (T_identifier , token );
501
+ check_def (token , false);
489
502
490
503
if (preproc_match ) {
491
504
skip_whitespace ();
Original file line number Diff line number Diff line change @@ -458,6 +458,19 @@ int main()
458
458
}
459
459
EOF
460
460
461
+ # #ifndef...#else...#endif
462
+ try_ 0 << EOF
463
+ #ifndef A
464
+ #define A 0
465
+ #else
466
+ #define A 1
467
+ #endif
468
+ int main()
469
+ {
470
+ return A;
471
+ }
472
+ EOF
473
+
461
474
# #if defined(...) ... #elif defined(...) ... #else ... #endif
462
475
try_ 0 << EOF
463
476
#define A 0
You can’t perform that action at this time.
0 commit comments