+ pp_conditional_t *conditional = push_conditional();
+ conditional->source_position = pp_token.source_position;
+ conditional->skip = true;
+ return;
+ }
+
+ if (pp_token.type != TP_IDENTIFIER) {
+ errorf(&pp_token.source_position,
+ "expected identifier after #%s, got '%t'",
+ is_ifndef ? "ifndef" : "ifdef", &pp_token);
+ eat_pp_directive();
+
+ /* just take the true case in the hope to avoid further errors */
+ condition = true;
+ } else {
+ symbol_t *symbol = pp_token.v.symbol;
+ pp_definition_t *pp_definition = symbol->pp_definition;
+ next_preprocessing_token();
+
+ if (pp_token.type != '\n') {
+ errorf(&pp_token.source_position,
+ "extra tokens at end of #%s",
+ is_ifndef ? "ifndef" : "ifdef");
+ eat_pp_directive();
+ }
+
+ /* evaluate wether we are in true or false case */
+ condition = is_ifndef ? pp_definition == NULL : pp_definition != NULL;
+ }
+
+ pp_conditional_t *conditional = push_conditional();
+ conditional->source_position = pp_token.source_position;
+ conditional->condition = condition;
+
+ if (!condition) {
+ skip_mode = true;
+ }
+}
+
+static void parse_else_directive(void)
+{
+ eat_pp(TP_else);
+
+ if (pp_token.type != '\n') {
+ if (!skip_mode) {
+ warningf(&pp_token.source_position, "extra tokens at end of #else");
+ }
+ eat_pp_directive();
+ }
+
+ pp_conditional_t *conditional = conditional_stack;
+ if (conditional == NULL) {
+ errorf(&pp_token.source_position, "#else without prior #if");
+ return;
+ }
+
+ if (conditional->in_else) {
+ errorf(&pp_token.source_position,
+ "#else after #else (condition started %P)",
+ conditional->source_position);
+ skip_mode = true;
+ return;
+ }
+
+ conditional->in_else = true;
+ if (!conditional->skip) {
+ skip_mode = conditional->condition;
+ }
+ conditional->source_position = pp_token.source_position;
+}
+
+static void parse_endif_directive(void)
+{
+ eat_pp(TP_endif);
+
+ if (pp_token.type != '\n') {
+ if (!skip_mode) {
+ warningf(&pp_token.source_position,
+ "extra tokens at end of #endif");
+ }
+ eat_pp_directive();
+ }
+
+ pp_conditional_t *conditional = conditional_stack;
+ if (conditional == NULL) {
+ errorf(&pp_token.source_position, "#endif without prior #if");
+ return;
+ }
+
+ if (!conditional->skip) {
+ skip_mode = false;
+ }
+ pop_conditional();
+}
+
+static void parse_preprocessing_directive(void)
+{
+ do_print_spaces = false;
+ do_expansions = false;
+ eat_pp('#');
+
+ if (skip_mode) {
+ switch(pp_token.type) {
+ case TP_ifdef:
+ case TP_ifndef:
+ parse_ifdef_ifndef_directive();
+ break;
+ case TP_else:
+ parse_else_directive();
+ break;
+ case TP_endif:
+ parse_endif_directive();
+ break;
+ default:
+ eat_pp_directive();
+ break;
+ }
+ } else {
+ switch(pp_token.type) {
+ case TP_define:
+ parse_define_directive();
+ break;
+ case TP_undef:
+ parse_undef_directive();
+ break;
+ case TP_ifdef:
+ case TP_ifndef:
+ parse_ifdef_ifndef_directive();
+ break;
+ case TP_else:
+ parse_else_directive();
+ break;
+ case TP_endif:
+ parse_endif_directive();
+ break;
+ case TP_include: {
+ bool in_new_source = parse_include_directive();
+ /* no need to do anything if source file switched */
+ if (in_new_source)
+ return;
+ break;
+ }
+ case '\n':
+ /* the nop directive */
+ break;
+ default:
+ errorf(&pp_token.source_position,
+ "invalid preprocessing directive #%t", &pp_token);
+ eat_pp_directive();
+ break;
+ }