FreeBSD/contrib/gcc/cp/parser.c
/* Parse a selection-statement.

   selection-statement:
     if ( condition ) statement
     if ( condition ) statement else statement
     switch ( condition ) statement

   Returns the new IF_STMT or SWITCH_STMT.

   If IF_P is not NULL, *IF_P is set to indicate whether the statement
   is a (possibly labeled) if statement which is not enclosed in
   braces and has an else clause.  This is used to implement
   -Wparentheses.  */
Parse a selection-statement.



If IF_P is not NULL, *IF_P is set to indicate whether the statement
is a (possibly labeled) if statement which is not enclosed in
braces and has an else clause.  This is used to implement
Wparentheses.
Parse a selection - statement . If IF_P is not NULL * IF_P is set to indicate whether the statement is a ( possibly labeled ) if statement which is not enclosed in braces and has an else clause . This is used to implement Wparentheses .
static tree
cp_parser_selection_statement (cp_parser* parser, bool *if_p)
{
  cp_token *token;
  enum rid keyword;
  if (if_p != NULL)
    *if_p = false;
  token = cp_parser_require (parser, CPP_KEYWORD, "selection-statement");
  keyword = token->keyword;
  switch (keyword)
    {
    case RID_IF:
    case RID_SWITCH:
      {
	tree statement;
	tree condition;
	if (!cp_parser_require (parser, CPP_OPEN_PAREN, "`('"))
	  {
	    cp_parser_skip_to_end_of_statement (parser);
	    return error_mark_node;
	  }
	if (keyword == RID_IF)
	  statement = begin_if_stmt ();
	else
	  statement = begin_switch_stmt ();
	condition = cp_parser_condition (parser);
	if (!cp_parser_require (parser, CPP_CLOSE_PAREN, "`)'"))
	  cp_parser_skip_to_closing_parenthesis (parser, true, false,
						 true);
	if (keyword == RID_IF)
	  {
	    bool nested_if;
	    finish_if_stmt_cond (condition, statement);
	    cp_parser_implicitly_scoped_statement (parser, &nested_if);
	    finish_then_clause (statement);
	    if (cp_lexer_next_token_is_keyword (parser->lexer,
						RID_ELSE))
	      {
		cp_lexer_consume_token (parser->lexer);
		begin_else_clause (statement);
		cp_parser_implicitly_scoped_statement (parser, NULL);
		finish_else_clause (statement);
		if (if_p != NULL)
		  *if_p = true;
	      }
	    else
	      {
		if (nested_if)
		  warning (OPT_Wparentheses,
			   ("%Hsuggest explicit braces "
			    "to avoid ambiguous %<else%>"),
			   EXPR_LOCUS (statement));
	      }
	    finish_if_stmt (statement);
	  }
	else
	  {
	    bool in_switch_statement_p;
	    unsigned char in_statement;
	    finish_switch_cond (condition, statement);
	    in_switch_statement_p = parser->in_switch_statement_p;
	    in_statement = parser->in_statement;
	    parser->in_switch_statement_p = true;
	    parser->in_statement |= IN_SWITCH_STMT;
	    cp_parser_implicitly_scoped_statement (parser, NULL);
	    parser->in_switch_statement_p = in_switch_statement_p;
	    parser->in_statement = in_statement;
	    finish_switch_stmt (statement);
	  }
	return statement;
      }
      break;
    default:
      cp_parser_error (parser, "expected selection-statement");
      return error_mark_node;
    }
}
static tree cp_parser_selection_statement ( cp_parser * parser , bool * if_p ) { cp_token * token ; enum rid keyword ; if ( if_p != NULL ) * if_p = false ; token = cp_parser_require ( parser , CPP_KEYWORD , " " ) ; keyword = token -> keyword ; switch ( keyword ) { case RID_IF : case RID_SWITCH : { tree statement ; tree condition ; if ( ! cp_parser_require ( parser , CPP_OPEN_PAREN , " " ) ) { cp_parser_skip_to_end_of_statement ( parser ) ; return error_mark_node ; } if ( keyword == RID_IF ) statement = begin_if_stmt ( ) ; else statement = begin_switch_stmt ( ) ; condition = cp_parser_condition ( parser ) ; if ( ! cp_parser_require ( parser , CPP_CLOSE_PAREN , " " ) ) cp_parser_skip_to_closing_parenthesis ( parser , true , false , true ) ; if ( keyword == RID_IF ) { bool nested_if ; finish_if_stmt_cond ( condition , statement ) ; cp_parser_implicitly_scoped_statement ( parser , & nested_if ) ; finish_then_clause ( statement ) ; if ( cp_lexer_next_token_is_keyword ( parser -> lexer , RID_ELSE ) ) { cp_lexer_consume_token ( parser -> lexer ) ; begin_else_clause ( statement ) ; cp_parser_implicitly_scoped_statement ( parser , NULL ) ; finish_else_clause ( statement ) ; if ( if_p != NULL ) * if_p = true ; } else { if ( nested_if ) warning ( OPT_Wparentheses , ( " " " " ) , EXPR_LOCUS ( statement ) ) ; } finish_if_stmt ( statement ) ; } else { bool in_switch_statement_p ; unsigned char in_statement ; finish_switch_cond ( condition , statement ) ; in_switch_statement_p = parser -> in_switch_statement_p ; in_statement = parser -> in_statement ; parser -> in_switch_statement_p = true ; parser -> in_statement |= IN_SWITCH_STMT ; cp_parser_implicitly_scoped_statement ( parser , NULL ) ; parser -> in_switch_statement_p = in_switch_statement_p ; parser -> in_statement = in_statement ; finish_switch_stmt ( statement ) ; } return statement ; } break ; default : cp_parser_error ( parser , " " ) ; return error_mark_node ; } }
Parse a selection-statement.
Parse a selection - statement .
/* Peek at the next token.  */ /* See what kind of keyword it is.  */ /* Look for the `('.  */ /* Begin the selection-statement.  */ /* Parse the condition.  */ /* Look for the `)'.  */ /*consume_paren=*/ /* Add the condition.  */ /* Parse the then-clause.  */ /* If the next token is `else', parse the else-clause.  */ /* Consume the `else' keyword.  */ /* Parse the else-clause.  */ /* If we are currently parsing a then-clause, then
		   IF_P will not be NULL.  We set it to true to
		   indicate that this if statement has an else clause.
		   This may trigger the Wparentheses warning below
		   when we get back up to the parent if statement.  */ /* This if statement does not have an else clause.  If
		   NESTED_IF is true, then the then-clause is an if
		   statement which does have an else clause.  We warn
		   about the potential ambiguity.  */ /* Now we're all done with the if-statement.  */ /* Add the condition.  */ /* Parse the body of the switch-statement.  */ /* Now we're all done with the switch-statement.  */