File tree Expand file tree Collapse file tree 3 files changed +33
-5
lines changed Expand file tree Collapse file tree 3 files changed +33
-5
lines changed Original file line number Diff line number Diff line change @@ -77,7 +77,8 @@ typedef enum {
7777 T_cppd_elif ,
7878 T_cppd_else ,
7979 T_cppd_endif ,
80- T_cppd_ifdef
80+ T_cppd_ifdef ,
81+ T_cppd_ifndef
8182} token_t ;
8283
8384char token_str [MAX_TOKEN_LEN ];
@@ -206,6 +207,8 @@ token_t lex_token_internal(bool aliasing)
206207 return T_cppd_elif ;
207208 if (!strcmp (token_str , "#ifdef" ))
208209 return T_cppd_ifdef ;
210+ if (!strcmp (token_str , "#ifndef" ))
211+ return T_cppd_ifndef ;
209212 if (!strcmp (token_str , "#else" ))
210213 return T_cppd_else ;
211214 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()
334334 skip_whitespace ();
335335}
336336
337- void check_def (char * alias )
337+ void check_def (char * alias , bool expected )
338338{
339- if (find_alias (alias ))
339+ if (( find_alias (alias ) != NULL ) == expected )
340340 preproc_match = true;
341341}
342342
@@ -349,7 +349,7 @@ void read_defined_macro()
349349 lex_ident (T_identifier , lookup_alias );
350350 lex_expect (T_close_bracket );
351351
352- check_def (lookup_alias );
352+ check_def (lookup_alias , true );
353353}
354354
355355/* read preprocessor directive at each potential positions: e.g.,
@@ -485,7 +485,20 @@ bool read_preproc_directive()
485485 if (lex_accept_internal (T_cppd_ifdef , false)) {
486486 preproc_match = false;
487487 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);
489502
490503 if (preproc_match ) {
491504 skip_whitespace ();
Original file line number Diff line number Diff line change @@ -458,6 +458,18 @@ int main()
458458}
459459EOF
460460
461+ try_ 0 << EOF
462+ #ifndef A
463+ #define A 0
464+ #else
465+ #define A 1
466+ #endif
467+ int main()
468+ {
469+ return A;
470+ }
471+ EOF
472+
461473# #if defined(...) ... #elif defined(...) ... #else ... #endif
462474try_ 0 << EOF
463475#define A 0
You can’t perform that action at this time.
0 commit comments