MESSAGE (specified by the caller) is usually of the form "expected
OTHER-TOKEN".
+ Use RICHLOC as the location of the diagnostic.
+
Do not issue a diagnostic if still recovering from an error.
+ Return true iff an error was actually emitted.
+
??? This is taken from the C++ parser, but building up messages in
this way is not i18n-friendly and some other approach should be
used. */
-void
-c_parser_error (c_parser *parser, const char *gmsgid)
+static bool
+c_parser_error_richloc (c_parser *parser, const char *gmsgid,
+ rich_location *richloc)
{
c_token *token = c_parser_peek_token (parser);
if (parser->error)
- return;
+ return false;
parser->error = true;
if (!gmsgid)
- return;
+ return false;
/* If this is actually a conflict marker, report it as such. */
if (token->type == CPP_LSHIFT
if (c_parser_peek_conflict_marker (parser, token->type, &loc))
{
error_at (loc, "version control conflict marker in file");
- return;
+ return true;
}
}
- /* This diagnostic makes more sense if it is tagged to the line of
- the token we just peeked at. */
- c_parser_set_source_position_from_token (token);
c_parse_error (gmsgid,
/* Because c_parse_error does not understand
CPP_KEYWORD, keywords are treated like
token, we need to pass 0 here and we will not get
the source spelling of some tokens but rather the
canonical spelling. */
- token->value, /*flags=*/0);
+ token->value, /*flags=*/0, richloc);
+ return true;
+}
+
+/* As c_parser_error_richloc, but issue the message at the
+ location of PARSER's next token, or at input_location
+ if the next token is EOF. */
+
+bool
+c_parser_error (c_parser *parser, const char *gmsgid)
+{
+ c_token *token = c_parser_peek_token (parser);
+ c_parser_set_source_position_from_token (token);
+ rich_location richloc (line_table, input_location);
+ return c_parser_error_richloc (parser, gmsgid, &richloc);
+}
+
+/* Some tokens naturally come in pairs e.g.'(' and ')'.
+ This class is for tracking such a matching pair of symbols.
+ In particular, it tracks the location of the first token,
+ so that if the second token is missing, we can highlight the
+ location of the first token when notifying the user about the
+ problem. */
+
+template <typename traits_t>
+class token_pair
+{
+ public:
+ /* token_pair's ctor. */
+ token_pair () : m_open_loc (UNKNOWN_LOCATION) {}
+
+ /* If the next token is the opening symbol for this pair, consume it and
+ return true.
+ Otherwise, issue an error and return false.
+ In either case, record the location of the opening token. */
+
+ bool require_open (c_parser *parser)
+ {
+ c_token *token = c_parser_peek_token (parser);
+ if (token)
+ m_open_loc = token->location;
+
+ return c_parser_require (parser, traits_t::open_token_type,
+ traits_t::open_gmsgid);
+ }
+
+ /* Consume the next token from PARSER, recording its location as
+ that of the opening token within the pair. */
+
+ void consume_open (c_parser *parser)
+ {
+ c_token *token = c_parser_peek_token (parser);
+ gcc_assert (token->type == traits_t::open_token_type);
+ m_open_loc = token->location;
+ c_parser_consume_token (parser);
+ }
+
+ /* If the next token is the closing symbol for this pair, consume it
+ and return true.
+ Otherwise, issue an error, highlighting the location of the
+ corresponding opening token, and return false. */
+
+ bool require_close (c_parser *parser) const
+ {
+ return c_parser_require (parser, traits_t::close_token_type,
+ traits_t::close_gmsgid, m_open_loc);
+ }
+
+ /* Like token_pair::require_close, except that tokens will be skipped
+ until the desired token is found. An error message is still produced
+ if the next token is not as expected. */
+
+ void skip_until_found_close (c_parser *parser) const
+ {
+ c_parser_skip_until_found (parser, traits_t::close_token_type,
+ traits_t::close_gmsgid, m_open_loc);
+ }
+
+ private:
+ location_t m_open_loc;
+};
+
+/* Traits for token_pair<T> for tracking matching pairs of parentheses. */
+
+struct matching_paren_traits
+{
+ static const enum cpp_ttype open_token_type = CPP_OPEN_PAREN;
+ static const char * const open_gmsgid;
+ static const enum cpp_ttype close_token_type = CPP_CLOSE_PAREN;
+ static const char * const close_gmsgid;
+};
+
+const char * const matching_paren_traits::open_gmsgid = "expected %<(%>";
+const char * const matching_paren_traits::close_gmsgid = "expected %<)%>";
+
+/* "matching_parens" is a token_pair<T> class for tracking matching
+ pairs of parentheses. */
+
+typedef token_pair<matching_paren_traits> matching_parens;
+
+/* Traits for token_pair<T> for tracking matching pairs of braces. */
+
+struct matching_brace_traits
+{
+ static const enum cpp_ttype open_token_type = CPP_OPEN_BRACE;
+ static const char * const open_gmsgid;
+ static const enum cpp_ttype close_token_type = CPP_CLOSE_BRACE;
+ static const char * const close_gmsgid;
+};
+
+const char * const matching_brace_traits::open_gmsgid = "expected %<{%>";
+const char * const matching_brace_traits::close_gmsgid = "expected %<}%>";
+
+/* "matching_braces" is a token_pair<T> class for tracking matching
+ pairs of braces. */
+
+typedef token_pair<matching_brace_traits> matching_braces;
+
+/* Get a description of the matching symbol to TYPE e.g. "(" for
+ CPP_CLOSE_PAREN. */
+
+static const char *
+get_matching_symbol (enum cpp_ttype type)
+{
+ switch (type)
+ {
+ default:
+ gcc_unreachable ();
+ return "";
+ case CPP_CLOSE_PAREN:
+ return "(";
+ case CPP_CLOSE_BRACE:
+ return "{";
+ }
}
/* If the next token is of the indicated TYPE, consume it. Otherwise,
issue the error MSGID. If MSGID is NULL then a message has already
been produced and no message will be produced this time. Returns
- true if found, false otherwise. */
+ true if found, false otherwise.
+
+ If MATCHING_LOCATION is not UNKNOWN_LOCATION, then highlight it
+ within any error as the location of an "opening" token matching
+ the close token TYPE (e.g. the location of the '(' when TYPE is
+ CPP_CLOSE_PAREN). */
bool
c_parser_require (c_parser *parser,
enum cpp_ttype type,
- const char *msgid)
+ const char *msgid,
+ location_t matching_location)
{
if (c_parser_next_token_is (parser, type))
{
}
else
{
- c_parser_error (parser, msgid);
+ location_t next_token_loc = c_parser_peek_token (parser)->location;
+ gcc_rich_location richloc (next_token_loc);
+
+ /* If matching_location != UNKNOWN_LOCATION, highlight it.
+ Attempt to consolidate diagnostics by printing it as a
+ secondary range within the main diagnostic. */
+ bool added_matching_location = false;
+ if (matching_location != UNKNOWN_LOCATION)
+ added_matching_location
+ = richloc.add_location_if_nearby (matching_location);
+
+ if (c_parser_error_richloc (parser, msgid, &richloc))
+ /* If we weren't able to consolidate matching_location, then
+ print it as a secondary diagnostic. */
+ if (matching_location != UNKNOWN_LOCATION && !added_matching_location)
+ inform (matching_location, "to match this %qs",
+ get_matching_symbol (type));
+
return false;
}
}
desired token is found. An error message is still produced if the
next token is not as expected. If MSGID is NULL then a message has
already been produced and no message will be produced this
- time. */
+ time.
+
+ If MATCHING_LOCATION is not UNKNOWN_LOCATION, then highlight it
+ within any error as the location of an "opening" token matching
+ the close token TYPE (e.g. the location of the '(' when TYPE is
+ CPP_CLOSE_PAREN). */
void
c_parser_skip_until_found (c_parser *parser,
enum cpp_ttype type,
- const char *msgid)
+ const char *msgid,
+ location_t matching_location)
{
unsigned nesting_depth = 0;
- if (c_parser_require (parser, type, msgid))
+ if (c_parser_require (parser, type, msgid, matching_location))
return;
/* Skip tokens until the desired token is found. */
pedwarn_c99 (assert_loc, OPT_Wpedantic,
"ISO C90 does not support %<_Static_assert%>");
c_parser_consume_token (parser);
- if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
+ matching_parens parens;
+ if (!parens.require_open (parser))
return;
location_t value_tok_loc = c_parser_peek_token (parser)->location;
value = c_parser_expr_no_commas (parser, NULL).value;
parser->lex_untranslated_string = false;
return;
}
- c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>");
+ parens.require_close (parser);
if (!INTEGRAL_TYPE_P (TREE_TYPE (value)))
{
tree name;
gcc_assert (c_dialect_objc ());
c_parser_consume_token (parser);
- if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
+ matching_parens parens;
+ if (!parens.require_open (parser))
goto end_at_defs;
if (c_parser_next_token_is (parser, CPP_NAME)
&& c_parser_peek_token (parser)->id_kind == C_ID_CLASSNAME)
c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
goto end_at_defs;
}
- c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
- "expected %<)%>");
+ parens.skip_until_found_close (parser);
contents = nreverse (objc_get_class_ivars (name));
}
end_at_defs:
c_parser_consume_token (parser);
c_inhibit_evaluation_warnings++;
in_typeof++;
- if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
+ matching_parens parens;
+ if (!parens.require_open (parser))
{
c_inhibit_evaluation_warnings--;
in_typeof--;
if (ret.spec != error_mark_node && TYPE_ATOMIC (ret.spec))
ret.spec = c_build_qualified_type (ret.spec, TYPE_UNQUALIFIED);
}
- c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
+ parens.skip_until_found_close (parser);
return ret;
}
else
pedwarn_c99 (loc, OPT_Wpedantic,
"ISO C90 does not support %<_Alignas%>");
- if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
+ matching_parens parens;
+ if (!parens.require_open (parser))
return ret;
if (c_parser_next_tokens_start_typename (parser, cla_prefer_id))
{
}
else
ret = c_parser_expr_no_commas (parser, NULL).value;
- c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
+ parens.skip_until_found_close (parser);
return ret;
}
lex_untranslated_string kludge. */
parser->lex_untranslated_string = true;
c_parser_consume_token (parser);
- if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
+ matching_parens parens;
+ if (!parens.require_open (parser))
{
parser->lex_untranslated_string = false;
return NULL_TREE;
}
str = c_parser_asm_string_literal (parser);
parser->lex_untranslated_string = false;
- if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
+ if (!parens.require_close (parser))
{
c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
return NULL_TREE;
location_t brace_loc = c_parser_peek_token (parser)->location;
gcc_obstack_init (&braced_init_obstack);
gcc_assert (c_parser_next_token_is (parser, CPP_OPEN_BRACE));
- c_parser_consume_token (parser);
+ matching_braces braces;
+ braces.consume_open (parser);
if (nested_p)
{
finish_implicit_inits (brace_loc, outer_obstack);
ret.value = error_mark_node;
ret.original_code = ERROR_MARK;
ret.original_type = NULL;
- c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, "expected %<}%>");
+ braces.skip_until_found_close (parser);
pop_init_level (brace_loc, 0, &braced_init_obstack, last_init_list_comma);
obstack_free (&braced_init_obstack, NULL);
return ret;
c_parser_paren_condition (c_parser *parser)
{
tree cond;
- if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
+ matching_parens parens;
+ if (!parens.require_open (parser))
return error_mark_node;
cond = c_parser_condition (parser);
- c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
+ parens.skip_until_found_close (parser);
return cond;
}
c_parser_consume_token (parser);
block = c_begin_compound_stmt (flag_isoc99);
bool explicit_cast_p = false;
- if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
+ matching_parens parens;
+ if (parens.require_open (parser))
{
switch_cond_loc = c_parser_peek_token (parser)->location;
if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)
"%<_Cilk_spawn%> statement cannot be used as a condition for switch statement",
switch_cond_loc))
expr = error_mark_node;
- c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
+ parens.skip_until_found_close (parser);
}
else
{
block = c_begin_compound_stmt (flag_isoc99 || c_dialect_objc ());
cond = error_mark_node;
incr = error_mark_node;
- if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
+ matching_parens parens;
+ if (parens.require_open (parser))
{
/* Parse the initialization declaration or expression. */
object_expression = error_mark_node;
incr = c_process_expr_stmt (loc, ce.value);
}
}
- c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
+ parens.skip_until_found_close (parser);
}
save_break = c_break_label;
c_break_label = NULL_TREE;
parser->lex_untranslated_string = true;
ret = NULL;
- if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
+ matching_parens parens;
+ if (!parens.require_open (parser))
goto error;
str = c_parser_asm_string_literal (parser);
}
done_asm:
- if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
+ if (!parens.require_close (parser))
{
c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
goto error;
if (str == NULL_TREE)
return NULL_TREE;
parser->lex_untranslated_string = false;
- if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
+ matching_parens parens;
+ if (!parens.require_open (parser))
{
parser->lex_untranslated_string = true;
return NULL_TREE;
expr = c_parser_expression (parser);
mark_exp_read (expr.value);
parser->lex_untranslated_string = true;
- if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
+ if (!parens.require_close (parser))
{
c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
return NULL_TREE;
struct c_type_name *type_name;
struct c_expr ret;
struct c_expr expr;
- c_parser_consume_token (parser);
+ matching_parens parens;
+ parens.consume_open (parser);
type_name = c_parser_type_name (parser);
- c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
+ parens.skip_until_found_close (parser);
if (type_name == NULL)
{
ret.value = error_mark_node;
/* Either sizeof ( type-name ) or sizeof unary-expression
starting with a compound literal. */
struct c_type_name *type_name;
- c_parser_consume_token (parser);
+ matching_parens parens;
+ parens.consume_open (parser);
expr_loc = c_parser_peek_token (parser)->location;
type_name = c_parser_type_name (parser);
- c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
+ parens.skip_until_found_close (parser);
finish = parser->tokens_buf[0].location;
if (type_name == NULL)
{
location_t loc;
struct c_type_name *type_name;
struct c_expr ret;
- c_parser_consume_token (parser);
+ matching_parens parens;
+ parens.consume_open (parser);
loc = c_parser_peek_token (parser)->location;
type_name = c_parser_type_name (parser);
end_loc = c_parser_peek_token (parser)->location;
- c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
+ parens.skip_until_found_close (parser);
if (type_name == NULL)
{
struct c_expr ret;
pedwarn_c99 (generic_loc, OPT_Wpedantic,
"ISO C90 does not support %<_Generic%>");
- if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
+ matching_parens parens;
+ if (!parens.require_open (parser))
return error_expr;
c_inhibit_evaluation_warnings++;
c_parser_consume_token (parser);
}
- if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
+ if (!parens.require_close (parser))
{
c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
return error_expr;
location_t loc_close_paren = c_parser_peek_token (parser)->location;
set_c_expr_source_range (&expr, loc_open_paren, loc_close_paren);
c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
- "expected %<)%>");
+ "expected %<)%>", loc_open_paren);
}
break;
case CPP_KEYWORD:
{
location_t start_loc = loc;
c_parser_consume_token (parser);
- if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
+ matching_parens parens;
+ if (!parens.require_open (parser))
{
expr.set_error ();
break;
}
break;
case RID_OFFSETOF:
- c_parser_consume_token (parser);
- if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
- {
- expr.set_error ();
- break;
- }
- t1 = c_parser_type_name (parser);
- if (t1 == NULL)
- parser->error = true;
- if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
- gcc_assert (parser->error);
- if (parser->error)
- {
- c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
- expr.set_error ();
- break;
- }
-
{
+ c_parser_consume_token (parser);
+ matching_parens parens;
+ if (!parens.require_open (parser))
+ {
+ expr.set_error ();
+ break;
+ }
+ t1 = c_parser_type_name (parser);
+ if (t1 == NULL)
+ parser->error = true;
+ if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
+ gcc_assert (parser->error);
+ if (parser->error)
+ {
+ c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
+ expr.set_error ();
+ break;
+ }
tree type = groktypename (t1, NULL, NULL);
tree offsetof_ref;
if (type == error_mark_node)
break;
}
case RID_TYPES_COMPATIBLE_P:
- c_parser_consume_token (parser);
- if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
- {
- expr.set_error ();
- break;
- }
- t1 = c_parser_type_name (parser);
- if (t1 == NULL)
- {
- expr.set_error ();
- break;
- }
- if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
- {
- c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
- expr.set_error ();
- break;
- }
- t2 = c_parser_type_name (parser);
- if (t2 == NULL)
- {
- expr.set_error ();
- break;
- }
{
+ c_parser_consume_token (parser);
+ matching_parens parens;
+ if (!parens.require_open (parser))
+ {
+ expr.set_error ();
+ break;
+ }
+ t1 = c_parser_type_name (parser);
+ if (t1 == NULL)
+ {
+ expr.set_error ();
+ break;
+ }
+ if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
+ {
+ c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
+ expr.set_error ();
+ break;
+ }
+ t2 = c_parser_type_name (parser);
+ if (t2 == NULL)
+ {
+ expr.set_error ();
+ break;
+ }
location_t close_paren_loc = c_parser_peek_token (parser)->location;
- c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
- "expected %<)%>");
+ parens.skip_until_found_close (parser);
tree e1, e2;
e1 = groktypename (t1, NULL, NULL);
e2 = groktypename (t2, NULL, NULL);
break;
}
case RID_AT_SELECTOR:
- gcc_assert (c_dialect_objc ());
- c_parser_consume_token (parser);
- if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
- {
- expr.set_error ();
- break;
- }
{
+ gcc_assert (c_dialect_objc ());
+ c_parser_consume_token (parser);
+ matching_parens parens;
+ if (!parens.require_open (parser))
+ {
+ expr.set_error ();
+ break;
+ }
tree sel = c_parser_objc_selector_arg (parser);
location_t close_loc = c_parser_peek_token (parser)->location;
- c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
- "expected %<)%>");
+ parens.skip_until_found_close (parser);
expr.value = objc_build_selector_expr (loc, sel);
set_c_expr_source_range (&expr, loc, close_loc);
}
break;
case RID_AT_PROTOCOL:
- gcc_assert (c_dialect_objc ());
- c_parser_consume_token (parser);
- if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
- {
- expr.set_error ();
- break;
- }
- if (c_parser_next_token_is_not (parser, CPP_NAME))
- {
- c_parser_error (parser, "expected identifier");
- c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
- expr.set_error ();
- break;
- }
{
+ gcc_assert (c_dialect_objc ());
+ c_parser_consume_token (parser);
+ matching_parens parens;
+ if (!parens.require_open (parser))
+ {
+ expr.set_error ();
+ break;
+ }
+ if (c_parser_next_token_is_not (parser, CPP_NAME))
+ {
+ c_parser_error (parser, "expected identifier");
+ c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
+ expr.set_error ();
+ break;
+ }
tree id = c_parser_peek_token (parser)->value;
c_parser_consume_token (parser);
location_t close_loc = c_parser_peek_token (parser)->location;
- c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
- "expected %<)%>");
+ parens.skip_until_found_close (parser);
expr.value = objc_build_protocol_expr (id);
set_c_expr_source_range (&expr, loc, close_loc);
}
break;
case RID_AT_ENCODE:
- /* Extension to support C-structures in the archiver. */
- gcc_assert (c_dialect_objc ());
- c_parser_consume_token (parser);
- if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
- {
- expr.set_error ();
- break;
- }
- t1 = c_parser_type_name (parser);
- if (t1 == NULL)
- {
- expr.set_error ();
- c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
- break;
- }
{
+ /* Extension to support C-structures in the archiver. */
+ gcc_assert (c_dialect_objc ());
+ c_parser_consume_token (parser);
+ matching_parens parens;
+ if (!parens.require_open (parser))
+ {
+ expr.set_error ();
+ break;
+ }
+ t1 = c_parser_type_name (parser);
+ if (t1 == NULL)
+ {
+ expr.set_error ();
+ c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
+ break;
+ }
location_t close_loc = c_parser_peek_token (parser)->location;
- c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
- "expected %<)%>");
+ parens.skip_until_found_close (parser);
tree type = groktypename (t1, NULL, NULL);
expr.value = objc_build_encode_expr (type);
set_c_expr_source_range (&expr, loc, close_loc);
/* We have a category or class extension. */
tree id2;
tree proto = NULL_TREE;
- c_parser_consume_token (parser);
+ matching_parens parens;
+ parens.consume_open (parser);
if (c_parser_next_token_is_not (parser, CPP_NAME))
{
if (iface_p && c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
id2 = c_parser_peek_token (parser)->value;
c_parser_consume_token (parser);
}
- c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
+ parens.skip_until_found_close (parser);
if (!iface_p)
{
objc_start_category_implementation (id1, id2);
*attributes = NULL_TREE;
if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
{
- c_parser_consume_token (parser);
+ matching_parens parens;
+ parens.consume_open (parser);
type = c_parser_objc_type_name (parser);
- c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
+ parens.skip_until_found_close (parser);
}
sel = c_parser_objc_selector (parser);
/* If there is no selector, or a colon follows, we have an
bool seen_open_paren = false;
c_parser_consume_token (parser);
- if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
+ matching_parens parens;
+ if (!parens.require_open (parser))
seen_open_paren = true;
if (c_parser_next_token_is (parser, CPP_ELLIPSIS))
{
parameter_declaration = grokparm (parm, NULL);
}
if (seen_open_paren)
- c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>");
+ parens.require_close (parser);
else
{
/* If there was no open parenthesis, we are recovering from
c_parser_consume_token (parser);
loc = c_parser_peek_token (parser)->location;
objc_maybe_warn_exceptions (loc);
- if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
+ matching_parens parens;
+ if (parens.require_open (parser))
{
struct c_expr ce = c_parser_expression (parser);
ce = convert_lvalue_to_rvalue (loc, ce, false, false);
expr = ce.value;
expr = c_fully_fold (expr, false, NULL);
- c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
+ parens.skip_until_found_close (parser);
}
else
expr = error_mark_node;
/* Parse the optional attribute list... */
if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
{
+ matching_parens parens;
+
/* Eat the '(' */
- c_parser_consume_token (parser);
-
+ parens.consume_open (parser);
+
/* Property attribute keywords are valid now. */
parser->objc_property_attr_context = true;
break;
}
parser->objc_property_attr_context = false;
- c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
+ parens.skip_until_found_close (parser);
}
/* ... and the property declaration(s). */
properties = c_parser_struct_declaration (parser);
vec<tree, va_gc> *args;
tree t, args_tree;
- if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
+ matching_parens parens;
+ if (!parens.require_open (parser))
return list;
args = c_parser_expr_list (parser, false, true, NULL, NULL, NULL, NULL);
}
release_tree_vector (args);
- c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>");
+ parens.require_close (parser);
return list;
}
/* The clauses location. */
location_t loc = c_parser_peek_token (parser)->location;
- if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
+ matching_parens parens;
+ if (parens.require_open (parser))
{
list = c_parser_omp_variable_list (parser, loc, kind, list);
- c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
+ parens.skip_until_found_close (parser);
}
return list;
}
check_no_duplicate_clause (list, OMP_CLAUSE_TILE, "tile");
loc = c_parser_peek_token (parser)->location;
- if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
+ matching_parens parens;
+ if (parens.require_open (parser))
{
num = c_parser_expr_no_commas (parser, NULL).value;
- c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
+ parens.skip_until_found_close (parser);
}
if (num == error_mark_node)
return list;
location_t loc = c_parser_peek_token (parser)->location;
tree c;
- if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
+ matching_parens parens;
+ if (!parens.require_open (parser))
return list;
if (c_parser_next_token_is (parser, CPP_NAME))
{
else
c_parser_error (parser, "expected %<none%> or %<shared%>");
}
- c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
+ parens.skip_until_found_close (parser);
if (kind == OMP_CLAUSE_DEFAULT_UNSPECIFIED)
return list;
location_t location = c_parser_peek_token (parser)->location;
enum tree_code if_modifier = ERROR_MARK;
- if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
+ matching_parens parens;
+ if (!parens.require_open (parser))
return list;
if (is_omp && c_parser_next_token_is (parser, CPP_NAME))
}
tree t = c_parser_condition (parser), c;
- c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
+ parens.skip_until_found_close (parser);
for (c = list; c ; c = OMP_CLAUSE_CHAIN (c))
if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IF)
c_parser_omp_clause_num_threads (c_parser *parser, tree list)
{
location_t num_threads_loc = c_parser_peek_token (parser)->location;
- if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
+ matching_parens parens;
+ if (parens.require_open (parser))
{
location_t expr_loc = c_parser_peek_token (parser)->location;
c_expr expr = c_parser_expression (parser);
tree c, t = expr.value;
t = c_fully_fold (t, false, NULL);
- c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
+ parens.skip_until_found_close (parser);
if (!INTEGRAL_TYPE_P (TREE_TYPE (t)))
{
c_parser_omp_clause_num_tasks (c_parser *parser, tree list)
{
location_t num_tasks_loc = c_parser_peek_token (parser)->location;
- if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
+ matching_parens parens;
+ if (parens.require_open (parser))
{
location_t expr_loc = c_parser_peek_token (parser)->location;
c_expr expr = c_parser_expression (parser);
tree c, t = expr.value;
t = c_fully_fold (t, false, NULL);
- c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
+ parens.skip_until_found_close (parser);
if (!INTEGRAL_TYPE_P (TREE_TYPE (t)))
{
c_parser_omp_clause_grainsize (c_parser *parser, tree list)
{
location_t grainsize_loc = c_parser_peek_token (parser)->location;
- if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
+ matching_parens parens;
+ if (parens.require_open (parser))
{
location_t expr_loc = c_parser_peek_token (parser)->location;
c_expr expr = c_parser_expression (parser);
tree c, t = expr.value;
t = c_fully_fold (t, false, NULL);
- c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
+ parens.skip_until_found_close (parser);
if (!INTEGRAL_TYPE_P (TREE_TYPE (t)))
{
c_parser_omp_clause_priority (c_parser *parser, tree list)
{
location_t priority_loc = c_parser_peek_token (parser)->location;
- if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
+ matching_parens parens;
+ if (parens.require_open (parser))
{
location_t expr_loc = c_parser_peek_token (parser)->location;
c_expr expr = c_parser_expression (parser);
tree c, t = expr.value;
t = c_fully_fold (t, false, NULL);
- c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
+ parens.skip_until_found_close (parser);
if (!INTEGRAL_TYPE_P (TREE_TYPE (t)))
{
c_parser_omp_clause_hint (c_parser *parser, tree list)
{
location_t hint_loc = c_parser_peek_token (parser)->location;
- if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
+ matching_parens parens;
+ if (parens.require_open (parser))
{
location_t expr_loc = c_parser_peek_token (parser)->location;
c_expr expr = c_parser_expression (parser);
tree c, t = expr.value;
t = c_fully_fold (t, false, NULL);
- c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
+ parens.skip_until_found_close (parser);
if (!INTEGRAL_TYPE_P (TREE_TYPE (t)))
{
tree c;
const char *p;
- if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
+ matching_parens parens;
+ if (!parens.require_open (parser))
return list;
if (!c_parser_next_token_is (parser, CPP_NAME))
{
goto out_err;
}
c_parser_consume_token (parser);
- c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
+ parens.skip_until_found_close (parser);
check_no_duplicate_clause (list, OMP_CLAUSE_DEFAULTMAP, "defaultmap");
c = build_omp_clause (loc, OMP_CLAUSE_DEFAULTMAP);
OMP_CLAUSE_CHAIN (c) = list;
return c;
out_err:
- c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
+ parens.skip_until_found_close (parser);
return list;
}
{
location_t loc = c_parser_peek_token (parser)->location;
- if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
+ matching_parens parens;
+ if (!parens.require_open (parser))
return list;
location_t expr_loc = c_parser_peek_token (parser)->location;
tree c, t = expr.value;
t = c_fully_fold (t, false, NULL);
- c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
+ parens.skip_until_found_close (parser);
if (t == error_mark_node)
return list;
location_t loc = c_parser_peek_token (parser)->location;
if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
{
- c_parser_consume_token (parser);
+ matching_parens parens;
+ parens.consume_open (parser);
num = c_parser_expr_no_commas (parser, NULL).value;
- c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
+ parens.skip_until_found_close (parser);
}
if (num == error_mark_node)
return list;
c_parser_omp_clause_reduction (c_parser *parser, tree list)
{
location_t clause_loc = c_parser_peek_token (parser)->location;
- if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
+ matching_parens parens;
+ if (parens.require_open (parser))
{
enum tree_code code = ERROR_MARK;
tree reduc_id = NULL_TREE;
list = nl;
}
- c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
+ parens.skip_until_found_close (parser);
}
return list;
}
location_t loc = c_parser_peek_token (parser)->location;
int modifiers = 0, nmodifiers = 0;
- if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
+ matching_parens parens;
+ if (!parens.require_open (parser))
return list;
c = build_omp_clause (loc, OMP_CLAUSE_SCHEDULE);
else
c_parser_error (parser, "expected integer expression");
- c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
+ parens.skip_until_found_close (parser);
}
else
c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
c_parser_omp_clause_num_teams (c_parser *parser, tree list)
{
location_t num_teams_loc = c_parser_peek_token (parser)->location;
- if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
+ matching_parens parens;
+ if (parens.require_open (parser))
{
location_t expr_loc = c_parser_peek_token (parser)->location;
c_expr expr = c_parser_expression (parser);
tree c, t = expr.value;
t = c_fully_fold (t, false, NULL);
- c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
+ parens.skip_until_found_close (parser);
if (!INTEGRAL_TYPE_P (TREE_TYPE (t)))
{
c_parser_omp_clause_thread_limit (c_parser *parser, tree list)
{
location_t num_thread_limit_loc = c_parser_peek_token (parser)->location;
- if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
+ matching_parens parens;
+ if (parens.require_open (parser))
{
location_t expr_loc = c_parser_peek_token (parser)->location;
c_expr expr = c_parser_expression (parser);
tree c, t = expr.value;
t = c_fully_fold (t, false, NULL);
- c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
+ parens.skip_until_found_close (parser);
if (!INTEGRAL_TYPE_P (TREE_TYPE (t)))
{
location_t clause_loc = c_parser_peek_token (parser)->location;
tree nl, c;
- if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
+ matching_parens parens;
+ if (!parens.require_open (parser))
return list;
nl = c_parser_omp_variable_list (parser, clause_loc,
OMP_CLAUSE_ALIGNED_ALIGNMENT (c) = alignment;
}
- c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
+ parens.skip_until_found_close (parser);
return nl;
}
tree nl, c, step;
enum omp_clause_linear_kind kind = OMP_CLAUSE_LINEAR_DEFAULT;
- if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
+ matching_parens parens;
+ if (!parens.require_open (parser))
return list;
if (!is_cilk_simd_fn
OMP_CLAUSE_LINEAR, list);
if (kind != OMP_CLAUSE_LINEAR_DEFAULT)
- c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
+ parens.skip_until_found_close (parser);
if (c_parser_next_token_is (parser, CPP_COLON))
{
OMP_CLAUSE_LINEAR_KIND (c) = kind;
}
- c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
+ parens.skip_until_found_close (parser);
return nl;
}
location_t clause_loc = c_parser_peek_token (parser)->location;
tree c, t;
- if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
+ matching_parens parens;
+ if (!parens.require_open (parser))
return list;
location_t expr_loc = c_parser_peek_token (parser)->location;
t = NULL_TREE;
}
- c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
+ parens.skip_until_found_close (parser);
if (t == NULL_TREE || t == error_mark_node)
return list;
location_t clause_loc = c_parser_peek_token (parser)->location;
tree c, t;
- if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
+ matching_parens parens;
+ if (!parens.require_open (parser))
return list;
location_t expr_loc = c_parser_peek_token (parser)->location;
t = NULL_TREE;
}
- c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
+ parens.skip_until_found_close (parser);
if (t == NULL_TREE || t == error_mark_node)
return list;
enum omp_clause_depend_kind kind = OMP_CLAUSE_DEPEND_INOUT;
tree nl, c;
- if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
+ matching_parens parens;
+ if (!parens.require_open (parser))
return list;
if (c_parser_next_token_is (parser, CPP_NAME))
OMP_CLAUSE_DEPEND_KIND (c) = kind;
OMP_CLAUSE_DECL (c) = NULL_TREE;
OMP_CLAUSE_CHAIN (c) = list;
- c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
+ parens.skip_until_found_close (parser);
return c;
}
OMP_CLAUSE_DEPEND_KIND (c) = kind;
}
- c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
+ parens.skip_until_found_close (parser);
return nl;
invalid_kind:
c_parser_error (parser, "invalid depend kind");
resync_fail:
- c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
+ parens.skip_until_found_close (parser);
return list;
}
tree always_id = NULL_TREE;
tree nl, c;
- if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
+ matching_parens parens;
+ if (!parens.require_open (parser))
return list;
if (c_parser_next_token_is (parser, CPP_NAME))
if (always_id_kind != C_ID_ID)
{
c_parser_error (parser, "expected identifier");
- c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
+ parens.skip_until_found_close (parser);
return list;
}
}
if (always == 1)
{
- c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
+ parens.skip_until_found_close (parser);
return list;
}
}
for (c = nl; c != list; c = OMP_CLAUSE_CHAIN (c))
OMP_CLAUSE_SET_MAP_KIND (c, kind);
- c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
+ parens.skip_until_found_close (parser);
return nl;
}
c_parser_omp_clause_device (c_parser *parser, tree list)
{
location_t clause_loc = c_parser_peek_token (parser)->location;
- if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
+ matching_parens parens;
+ if (parens.require_open (parser))
{
location_t expr_loc = c_parser_peek_token (parser)->location;
c_expr expr = c_parser_expr_no_commas (parser, NULL);
tree c, t = expr.value;
t = c_fully_fold (t, false, NULL);
- c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
+ parens.skip_until_found_close (parser);
if (!INTEGRAL_TYPE_P (TREE_TYPE (t)))
{
tree c, t = NULL_TREE;
location_t loc = c_parser_peek_token (parser)->location;
- if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
+ matching_parens parens;
+ if (!parens.require_open (parser))
return list;
if (!c_parser_next_token_is_keyword (parser, RID_STATIC))
expr = convert_lvalue_to_rvalue (expr_loc, expr, false, true);
t = expr.value;
t = c_fully_fold (t, false, NULL);
- c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
+ parens.skip_until_found_close (parser);
}
else
c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
enum omp_clause_proc_bind_kind kind;
tree c;
- if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
+ matching_parens parens;
+ if (!parens.require_open (parser))
return list;
if (c_parser_next_token_is (parser, CPP_NAME))
goto invalid_kind;
c_parser_consume_token (parser);
- c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
+ parens.skip_until_found_close (parser);
c = build_omp_clause (clause_loc, OMP_CLAUSE_PROC_BIND);
OMP_CLAUSE_PROC_BIND_KIND (c) = kind;
OMP_CLAUSE_CHAIN (c) = list;
invalid_kind:
c_parser_error (parser, "invalid proc_bind kind");
- c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
+ parens.skip_until_found_close (parser);
return list;
}
/* The clauses location. */
location_t loc = c_parser_peek_token (parser)->location;
- if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
+ matching_parens parens;
+ if (parens.require_open (parser))
{
list = c_parser_omp_variable_list (parser, loc, OMP_CLAUSE_UNIFORM,
list);
- c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
+ parens.skip_until_found_close (parser);
}
return list;
}
{
int bracecount = 0;
- if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
+ matching_parens parens;
+ if (!parens.require_open (parser))
goto pop_scopes;
/* Parse the initialization declaration or expression. */
incr = c_process_expr_stmt (incr_loc,
c_parser_expression (parser).value);
}
- c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
+ parens.skip_until_found_close (parser);
if (decl == NULL || decl == error_mark_node || init == error_mark_node)
fail = true;
clause. Represent it in OpenMP terms. */
check_no_duplicate_clause (clauses, OMP_CLAUSE_SAFELEN, "vectorlength");
- if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
+ matching_parens parens;
+ if (!parens.require_open (parser))
return clauses;
location_t loc = c_parser_peek_token (parser)->location;
}
}
- c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>");
+ parens.require_close (parser);
return clauses;
}
static tree
c_parser_cilk_clause_linear (c_parser *parser, tree clauses)
{
- if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
+ matching_parens parens;
+ if (!parens.require_open (parser))
return clauses;
location_t loc = c_parser_peek_token (parser)->location;
c_parser_consume_token (parser);
}
- c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
+ parens.skip_until_found_close (parser);
return clauses;
}
}
parser->in_transaction = this_in;
- if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
+ matching_parens parens;
+ if (parens.require_open (parser))
{
tree expr = c_parser_expression (parser).value;
ret.original_type = TREE_TYPE (expr);
TRANSACTION_EXPR_RELAXED (ret.value) = 1;
SET_EXPR_LOCATION (ret.value, loc);
ret.original_code = TRANSACTION_EXPR;
- if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
+ if (!parens.require_close (parser))
{
c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
goto error;
static bool cp_parser_friend_p
(const cp_decl_specifier_seq *);
static void cp_parser_required_error
- (cp_parser *, required_token, bool);
+ (cp_parser *, required_token, bool, location_t);
static cp_token *cp_parser_require
- (cp_parser *, enum cpp_ttype, required_token);
+ (cp_parser *, enum cpp_ttype, required_token, location_t = UNKNOWN_LOCATION);
static cp_token *cp_parser_require_keyword
(cp_parser *, enum rid, required_token);
static bool cp_parser_token_starts_function_definition_p
}
}
+ rich_location richloc (line_table, input_location);
c_parse_error (gmsgid,
/* Because c_parser_error does not understand
CPP_KEYWORD, keywords are treated like
identifiers. */
(token->type == CPP_KEYWORD ? CPP_NAME : token->type),
- token->u.value, token->flags);
+ token->u.value, token->flags, &richloc);
}
}
}
};
+/* Some tokens naturally come in pairs e.g.'(' and ')'.
+ This class is for tracking such a matching pair of symbols.
+ In particular, it tracks the location of the first token,
+ so that if the second token is missing, we can highlight the
+ location of the first token when notifying the user about the
+ problem. */
+
+template <typename traits_t>
+class token_pair
+{
+ public:
+ /* token_pair's ctor. */
+ token_pair () : m_open_loc (UNKNOWN_LOCATION) {}
+
+ /* If the next token is the opening symbol for this pair, consume it and
+ return true.
+ Otherwise, issue an error and return false.
+ In either case, record the location of the opening token. */
+
+ bool require_open (cp_parser *parser)
+ {
+ m_open_loc = cp_lexer_peek_token (parser->lexer)->location;
+ return cp_parser_require (parser, traits_t::open_token_type,
+ traits_t::required_token_open);
+ }
+
+ /* Consume the next token from PARSER, recording its location as
+ that of the opening token within the pair. */
+
+ cp_token * consume_open (cp_parser *parser)
+ {
+ cp_token *tok = cp_lexer_consume_token (parser->lexer);
+ gcc_assert (tok->type == traits_t::open_token_type);
+ m_open_loc = tok->location;
+ return tok;
+ }
+
+ /* If the next token is the closing symbol for this pair, consume it
+ and return it.
+ Otherwise, issue an error, highlighting the location of the
+ corresponding opening token, and return NULL. */
+
+ cp_token *require_close (cp_parser *parser) const
+ {
+ return cp_parser_require (parser, traits_t::close_token_type,
+ traits_t::required_token_close,
+ m_open_loc);
+ }
+
+ private:
+ location_t m_open_loc;
+};
+
+/* Traits for token_pair<T> for tracking matching pairs of parentheses. */
+
+struct matching_paren_traits
+{
+ static const enum cpp_ttype open_token_type = CPP_OPEN_PAREN;
+ static const enum required_token required_token_open = RT_OPEN_PAREN;
+ static const enum cpp_ttype close_token_type = CPP_CLOSE_PAREN;
+ static const enum required_token required_token_close = RT_CLOSE_PAREN;
+};
+
+/* "matching_parens" is a token_pair<T> class for tracking matching
+ pairs of parentheses. */
+
+typedef token_pair<matching_paren_traits> matching_parens;
+
+/* Traits for token_pair<T> for tracking matching pairs of braces. */
+
+struct matching_brace_traits
+{
+ static const enum cpp_ttype open_token_type = CPP_OPEN_BRACE;
+ static const enum required_token required_token_open = RT_OPEN_BRACE;
+ static const enum cpp_ttype close_token_type = CPP_CLOSE_BRACE;
+ static const enum required_token required_token_close = RT_CLOSE_BRACE;
+};
+
+/* "matching_braces" is a token_pair<T> class for tracking matching
+ pairs of braces. */
+
+typedef token_pair<matching_brace_traits> matching_braces;
+
+
/* Parse a GNU statement-expression, i.e. ({ stmts }), except for the
enclosing parentheses. */
/* Consume the '('. */
location_t start_loc = cp_lexer_peek_token (parser->lexer)->location;
- cp_lexer_consume_token (parser->lexer);
+ matching_parens parens;
+ parens.consume_open (parser);
/* Start the statement-expression. */
tree expr = begin_stmt_expr ();
/* Parse the compound-statement. */
expr = finish_stmt_expr (expr, false);
/* Consume the ')'. */
location_t finish_loc = cp_lexer_peek_token (parser->lexer)->location;
- if (!cp_parser_require (parser, CPP_CLOSE_PAREN, RT_CLOSE_PAREN))
+ if (!parens.require_close (parser))
cp_parser_skip_to_end_of_statement (parser);
cp_parser_end_tentative_firewall (parser, start, expr);
location_t open_paren_loc = token->location;
/* Consume the `('. */
- cp_lexer_consume_token (parser->lexer);
+ matching_parens parens;
+ parens.consume_open (parser);
/* Within a parenthesized expression, a `>' token is always
the greater-than operator. */
saved_greater_than_is_operator_p
token = cp_lexer_peek_token (parser->lexer);
location_t close_paren_loc = token->location;
expr.set_range (open_paren_loc, close_paren_loc);
- if (!cp_parser_require (parser, CPP_CLOSE_PAREN, RT_CLOSE_PAREN)
+ if (!parens.require_close (parser)
&& !cp_parser_uncommitted_to_tentative_parse_p (parser))
cp_parser_skip_to_end_of_statement (parser);
`va_arg'. Consume the `__builtin_va_arg' token. */
cp_lexer_consume_token (parser->lexer);
/* Look for the opening `('. */
- cp_parser_require (parser, CPP_OPEN_PAREN, RT_OPEN_PAREN);
+ matching_parens parens;
+ parens.require_open (parser);
/* Now, parse the assignment-expression. */
expression = cp_parser_assignment_expression (parser);
/* Look for the `,'. */
/* Look for the closing `)'. */
location_t finish_loc
= cp_lexer_peek_token (parser->lexer)->location;
- cp_parser_require (parser, CPP_CLOSE_PAREN, RT_CLOSE_PAREN);
+ parens.require_close (parser);
/* Using `va_arg' in a constant-expression is not
allowed. */
if (cp_parser_non_integral_constant_expression (parser,
static bool
cp_parser_compound_literal_p (cp_parser *parser)
{
- /* Consume the `('. */
- cp_lexer_consume_token (parser->lexer);
-
cp_lexer_save_tokens (parser->lexer);
/* Skip tokens until the next token is a closing parenthesis.
parser->greater_than_is_operator_p = true;
/* And the expression which is being cast. */
- cp_parser_require (parser, CPP_OPEN_PAREN, RT_OPEN_PAREN);
+ matching_parens parens;
+ parens.require_open (parser);
expression = cp_parser_expression (parser, & idk, /*cast_p=*/true);
cp_token *close_paren = cp_parser_require (parser, CPP_CLOSE_PAREN,
RT_CLOSE_PAREN);
/* Consume the `typeid' token. */
cp_lexer_consume_token (parser->lexer);
/* Look for the `(' token. */
- cp_parser_require (parser, CPP_OPEN_PAREN, RT_OPEN_PAREN);
+ matching_parens parens;
+ parens.require_open (parser);
/* Types cannot be defined in a `typeid' expression. */
saved_message = parser->type_definition_forbidden_message;
parser->type_definition_forbidden_message
/* Look for the `)' token. Otherwise, we can't be sure that
we're not looking at an expression: consider `typeid (int
(3))', for example. */
- cp_token *close_paren = cp_parser_require (parser, CPP_CLOSE_PAREN,
- RT_CLOSE_PAREN);
+ cp_token *close_paren = parens.require_close (parser);
/* If all went well, simply lookup the type-id. */
if (cp_parser_parse_definitely (parser))
postfix_expression = get_typeid (type, tf_warning_or_error);
/* Compute its typeid. */
postfix_expression = build_typeid (expression, tf_warning_or_error);
/* Look for the `)' token. */
- close_paren
- = cp_parser_require (parser, CPP_CLOSE_PAREN, RT_CLOSE_PAREN);
+ close_paren = parens.require_close (parser);
}
/* Restore the saved message. */
parser->type_definition_forbidden_message = saved_message;
cp_parser_parse_tentatively (parser);
+ matching_parens parens;
+ parens.consume_open (parser);
+
/* Avoid calling cp_parser_type_id pointlessly, see comment
in cp_parser_cast_expression about c++/29234. */
if (!cp_parser_compound_literal_p (parser))
parser->in_type_id_in_expr_p = true;
type = cp_parser_type_id (parser);
parser->in_type_id_in_expr_p = saved_in_type_id_in_expr_p;
- /* Look for the `)'. */
- cp_parser_require (parser, CPP_CLOSE_PAREN, RT_CLOSE_PAREN);
+ parens.require_close (parser);
}
/* If things aren't going well, there's no need to
if (non_constant_p)
*non_constant_p = false;
- if (!cp_parser_require (parser, CPP_OPEN_PAREN, RT_OPEN_PAREN))
+ matching_parens parens;
+ if (!parens.require_open (parser))
return NULL;
expression_list = make_tree_vector ();
if (close_paren_loc)
*close_paren_loc = cp_lexer_peek_token (parser->lexer)->location;
- if (!cp_parser_require (parser, CPP_CLOSE_PAREN, RT_CLOSE_PAREN))
+ if (!parens.require_close (parser))
{
int ending;
bool saved_greater_than_is_operator_p;
cp_lexer_consume_token (parser->lexer);
- cp_parser_require (parser, CPP_OPEN_PAREN, RT_OPEN_PAREN);
+ matching_parens parens;
+ parens.require_open (parser);
saved_message = parser->type_definition_forbidden_message;
parser->type_definition_forbidden_message
parser->type_definition_forbidden_message = saved_message;
- cp_parser_require (parser, CPP_CLOSE_PAREN, RT_CLOSE_PAREN);
+ parens.require_close (parser);
return finish_noexcept_expr (expr, tf_warning_or_error);
}
const char *saved_message = parser->type_definition_forbidden_message;
/* Consume the `('. */
- cp_lexer_consume_token (parser->lexer);
+ matching_parens parens;
+ parens.consume_open (parser);
/* Parse the type-id. */
parser->type_definition_forbidden_message
parser->type_definition_forbidden_message = saved_message;
/* Look for the closing `)'. */
- cp_parser_require (parser, CPP_CLOSE_PAREN, RT_CLOSE_PAREN);
+ parens.require_close (parser);
token = cp_lexer_peek_token (parser->lexer);
/* There should not be a direct-new-declarator in this production,
but GCC used to allowed this, so we check and emit a sensible error
parser->type_definition_forbidden_message
= G_("types may not be defined in casts");
/* Consume the `('. */
- cp_token *open_paren = cp_lexer_consume_token (parser->lexer);
+ matching_parens parens;
+ cp_token *open_paren = parens.consume_open (parser);
location_t open_paren_loc = open_paren->location;
location_t close_paren_loc = UNKNOWN_LOCATION;
/* Look for the type-id. */
type = cp_parser_type_id (parser);
/* Look for the closing `)'. */
- cp_token *close_paren
- = cp_parser_require (parser, CPP_CLOSE_PAREN, RT_CLOSE_PAREN);
+ cp_token *close_paren = parens.require_close (parser);
if (close_paren)
close_paren_loc = close_paren->location;
parser->in_type_id_in_expr_p = saved_in_type_id_in_expr_p;
/* Consume the "__builtin_offsetof" token. */
cp_lexer_consume_token (parser->lexer);
/* Consume the opening `('. */
- cp_parser_require (parser, CPP_OPEN_PAREN, RT_OPEN_PAREN);
+ matching_parens parens;
+ parens.require_open (parser);
/* Parse the type-id. */
location_t loc = cp_lexer_peek_token (parser->lexer)->location;
type = cp_parser_type_id (parser);
default:
/* Error. We know the following require will fail, but
that gives the proper error message. */
- cp_parser_require (parser, CPP_CLOSE_PAREN, RT_CLOSE_PAREN);
+ parens.require_close (parser);
cp_parser_skip_to_closing_parenthesis (parser, true, false, true);
expr = error_mark_node;
goto failure;
/* Consume the token. */
cp_lexer_consume_token (parser->lexer);
- cp_parser_require (parser, CPP_OPEN_PAREN, RT_OPEN_PAREN);
+ matching_parens parens;
+ parens.require_open (parser);
{
type_id_in_expr_sentinel s (parser);
}
}
- cp_parser_require (parser, CPP_CLOSE_PAREN, RT_CLOSE_PAREN);
+ parens.require_close (parser);
/* Complete the trait expression, which may mean either processing
the trait expr now or saving it for template instantiation. */
opening parenthesis if present. */
if (cp_lexer_next_token_is (parser->lexer, CPP_OPEN_PAREN))
{
- cp_lexer_consume_token (parser->lexer);
+ matching_parens parens;
+ parens.consume_open (parser);
begin_scope (sk_function_parms, /*entity=*/NULL_TREE);
pedwarn (DECL_SOURCE_LOCATION (TREE_VALUE (t)), OPT_Wpedantic,
"default argument specified for lambda parameter");
- cp_parser_require (parser, CPP_CLOSE_PAREN, RT_CLOSE_PAREN);
+ parens.require_close (parser);
attributes = cp_parser_attributes_opt (parser);
start_lambda_scope (fco);
body = begin_function_body ();
- if (!cp_parser_require (parser, CPP_OPEN_BRACE, RT_OPEN_BRACE))
+ matching_braces braces;
+ if (!braces.require_open (parser))
goto out;
/* Push the proxies for any explicit captures. */
expr = cp_parser_expression (parser, &idk);
cp_parser_require (parser, CPP_SEMICOLON, RT_SEMICOLON);
- cp_parser_require (parser, CPP_CLOSE_BRACE, RT_CLOSE_BRACE);
+ braces.require_close (parser);
if (cp_parser_parse_definitely (parser))
{
while (cp_lexer_next_token_is_keyword (parser->lexer, RID_LABEL))
cp_parser_label_declaration (parser);
cp_parser_statement_seq_opt (parser, NULL_TREE);
- cp_parser_require (parser, CPP_CLOSE_BRACE, RT_CLOSE_BRACE);
+ braces.require_close (parser);
}
finish_compound_stmt (compound_stmt);
int bcs_flags, bool function_body)
{
tree compound_stmt;
+ matching_braces braces;
/* Consume the `{'. */
- if (!cp_parser_require (parser, CPP_OPEN_BRACE, RT_OPEN_BRACE))
+ if (!braces.require_open (parser))
return error_mark_node;
if (DECL_DECLARED_CONSTEXPR_P (current_function_decl)
&& !function_body && cxx_dialect < cxx14)
/* Finish the compound-statement. */
finish_compound_stmt (compound_stmt);
/* Consume the `}'. */
- cp_parser_require (parser, CPP_CLOSE_BRACE, RT_CLOSE_BRACE);
+ braces.require_close (parser);
return compound_stmt;
}
}
/* Look for the `('. */
- if (!cp_parser_require (parser, CPP_OPEN_PAREN, RT_OPEN_PAREN))
+ matching_parens parens;
+ if (!parens.require_open (parser))
{
cp_parser_skip_to_end_of_statement (parser);
return error_mark_node;
/* Parse the condition. */
condition = cp_parser_condition (parser);
/* Look for the `)'. */
- if (!cp_parser_require (parser, CPP_CLOSE_PAREN, RT_CLOSE_PAREN))
+ if (!parens.require_close (parser))
cp_parser_skip_to_closing_parenthesis (parser, true, false,
/*consume_paren=*/true);
/* Begin the while-statement. */
statement = begin_while_stmt ();
/* Look for the `('. */
- cp_parser_require (parser, CPP_OPEN_PAREN, RT_OPEN_PAREN);
+ matching_parens parens;
+ parens.require_open (parser);
/* Parse the condition. */
condition = cp_parser_condition (parser);
finish_while_stmt_cond (condition, statement, ivdep);
/* Look for the `)'. */
- cp_parser_require (parser, CPP_CLOSE_PAREN, RT_CLOSE_PAREN);
+ parens.require_close (parser);
/* Parse the dependent statement. */
parser->in_statement = IN_ITERATION_STMT;
cp_parser_already_scoped_statement (parser, if_p, guard_tinfo);
/* Look for the `while' keyword. */
cp_parser_require_keyword (parser, RID_WHILE, RT_WHILE);
/* Look for the `('. */
- cp_parser_require (parser, CPP_OPEN_PAREN, RT_OPEN_PAREN);
+ matching_parens parens;
+ parens.require_open (parser);
/* Parse the expression. */
expression = cp_parser_expression (parser);
/* We're done with the do-statement. */
finish_do_stmt (expression, statement, ivdep);
/* Look for the `)'. */
- cp_parser_require (parser, CPP_CLOSE_PAREN, RT_CLOSE_PAREN);
+ parens.require_close (parser);
/* Look for the `;'. */
cp_parser_require (parser, CPP_SEMICOLON, RT_SEMICOLON);
}
case RID_FOR:
{
/* Look for the `('. */
- cp_parser_require (parser, CPP_OPEN_PAREN, RT_OPEN_PAREN);
+ matching_parens parens;
+ parens.require_open (parser);
statement = cp_parser_for (parser, ivdep);
/* Look for the `)'. */
- cp_parser_require (parser, CPP_CLOSE_PAREN, RT_CLOSE_PAREN);
+ parens.require_close (parser);
/* Parse the body of the for-statement. */
parser->in_statement = IN_ITERATION_STMT;
{
/* Avoid calling cp_parser_compound_statement, so that we
don't create a new scope. Do everything else by hand. */
- cp_parser_require (parser, CPP_OPEN_BRACE, RT_OPEN_BRACE);
+ matching_braces braces;
+ braces.require_open (parser);
/* If the next keyword is `__label__' we have a label declaration. */
while (cp_lexer_next_token_is_keyword (parser->lexer, RID_LABEL))
cp_parser_label_declaration (parser);
/* Parse an (optional) statement-seq. */
cp_parser_statement_seq_opt (parser, NULL_TREE);
- cp_parser_require (parser, CPP_CLOSE_BRACE, RT_CLOSE_BRACE);
+ braces.require_close (parser);
}
}
cp_ensure_no_oacc_routine (parser);
/* Consume the `{' token. */
- cp_lexer_consume_token (parser->lexer);
+ matching_braces braces;
+ braces.consume_open (parser)->location;
/* Parse the declarations. */
cp_parser_declaration_seq_opt (parser);
/* Look for the closing `}'. */
- cp_parser_require (parser, CPP_CLOSE_BRACE, RT_CLOSE_BRACE);
+ braces.require_close (parser);
}
/* Otherwise, there's just one declaration. */
else
cp_parser_commit_to_tentative_parse (parser);
/* Parse the `(' starting the static assertion condition. */
- cp_parser_require (parser, CPP_OPEN_PAREN, RT_OPEN_PAREN);
+ matching_parens parens;
+ parens.require_open (parser);
/* Parse the constant-expression. Allow a non-constant expression
here in order to give better diagnostics in finish_static_assert. */
/*wide_ok=*/true);
/* A `)' completes the static assertion. */
- if (!cp_parser_require (parser, CPP_CLOSE_PAREN, RT_CLOSE_PAREN))
+ if (!parens.require_close (parser))
cp_parser_skip_to_closing_parenthesis (parser,
/*recovering=*/true,
/*or_comma=*/false,
return error_mark_node;
/* Parse the opening `('. */
- if (!cp_parser_require (parser, CPP_OPEN_PAREN, RT_OPEN_PAREN))
+ matching_parens parens;
+ if (!parens.require_open (parser))
return error_mark_node;
/* decltype (auto) */
&& cp_lexer_next_token_is_keyword (parser->lexer, RID_AUTO))
{
cp_lexer_consume_token (parser->lexer);
- if (!cp_parser_require (parser, CPP_CLOSE_PAREN, RT_CLOSE_PAREN))
+ if (!parens.require_close (parser))
return error_mark_node;
expr = make_decltype_auto ();
AUTO_IS_DECLTYPE (expr) = true;
= saved_non_integral_constant_expression_p;
/* Parse to the closing `)'. */
- if (!cp_parser_require (parser, CPP_CLOSE_PAREN, RT_CLOSE_PAREN))
+ if (!parens.require_close (parser))
{
cp_parser_skip_to_closing_parenthesis (parser, true, false,
/*consume_paren=*/true);
break;
case CPP_OPEN_PAREN:
- /* Consume the `('. */
- cp_lexer_consume_token (parser->lexer);
- /* Look for the matching `)'. */
- cp_parser_require (parser, CPP_CLOSE_PAREN, RT_CLOSE_PAREN);
- return cp_operator_id (CALL_EXPR);
+ {
+ /* Consume the `('. */
+ matching_parens parens;
+ parens.consume_open (parser);
+ /* Look for the matching `)'. */
+ parens.require_close (parser);
+ return cp_operator_id (CALL_EXPR);
+ }
case CPP_OPEN_SQUARE:
/* Consume the `['. */
begin_scope (sk_scoped_enum, type);
/* Consume the opening brace. */
- cp_lexer_consume_token (parser->lexer);
+ matching_braces braces;
+ braces.consume_open (parser);
if (type == error_mark_node)
; /* Nothing to add */
cp_parser_enumerator_list (parser, type);
/* Consume the final '}'. */
- cp_parser_require (parser, CPP_CLOSE_BRACE, RT_CLOSE_BRACE);
+ braces.require_close (parser);
if (scoped_enum_p)
finish_scope ();
warning (OPT_Wnamespaces, "namespace %qD entered", current_namespace);
/* Look for the `{' to validate starting the namespace. */
- if (cp_parser_require (parser, CPP_OPEN_BRACE, RT_OPEN_BRACE))
+ matching_braces braces;
+ if (braces.require_open (parser))
{
/* Parse the body of the namespace. */
cp_parser_namespace_body (parser);
/* Look for the final `}'. */
- cp_parser_require (parser, CPP_CLOSE_BRACE, RT_CLOSE_BRACE);
+ braces.require_close (parser);
}
if (has_visibility)
cp_parser_parse_tentatively (parser);
/* Consume the `('. */
- cp_lexer_consume_token (parser->lexer);
+ matching_parens parens;
+ parens.consume_open (parser);
if (first)
{
/* If this is going to be an abstract declarator, we're
params = cp_parser_parameter_declaration_clause (parser);
/* Consume the `)'. */
- cp_parser_require (parser, CPP_CLOSE_PAREN, RT_CLOSE_PAREN);
+ parens.require_close (parser);
/* If all went well, parse the cv-qualifier-seq,
ref-qualifier and the exception-specification. */
parser->in_declarator_p = saved_in_declarator_p;
/* Consume the `('. */
- cp_lexer_consume_token (parser->lexer);
+ matching_parens parens;
+ parens.consume_open (parser);
/* Parse the nested declarator. */
saved_in_type_id_in_expr_p = parser->in_type_id_in_expr_p;
parser->in_type_id_in_expr_p = true;
parser->in_type_id_in_expr_p = saved_in_type_id_in_expr_p;
first = false;
/* Expect a `)'. */
- if (!cp_parser_require (parser, CPP_CLOSE_PAREN, RT_CLOSE_PAREN))
+ if (!parens.require_close (parser))
declarator = cp_error_declarator;
if (declarator == cp_error_declarator)
break;
location_t start_loc = cp_lexer_peek_token (parser->lexer)->location;
/* Consume the `{' token. */
- cp_lexer_consume_token (parser->lexer);
+ matching_braces braces;
+ braces.consume_open (parser);
/* Create a CONSTRUCTOR to represent the braced-initializer. */
initializer = make_node (CONSTRUCTOR);
/* If it's not a `}', then there is a non-trivial initializer. */
*non_constant_p = false;
/* Now, there should be a trailing `}'. */
location_t finish_loc = cp_lexer_peek_token (parser->lexer)->location;
- cp_parser_require (parser, CPP_CLOSE_BRACE, RT_CLOSE_BRACE);
+ braces.require_close (parser);
TREE_TYPE (initializer) = init_list_type_node;
cp_expr result (initializer);
}
/* Look for the `{'. */
- if (!cp_parser_require (parser, CPP_OPEN_BRACE, RT_OPEN_BRACE))
+ matching_braces braces;
+ if (!braces.require_open (parser))
{
pop_deferring_access_checks ();
return error_mark_node;
cp_parser_member_specification_opt (parser);
/* Look for the trailing `}'. */
- closing_brace = cp_parser_require (parser, CPP_CLOSE_BRACE, RT_CLOSE_BRACE);
+ closing_brace = braces.require_close (parser);
/* Look for trailing attributes to apply to this class. */
if (cp_parser_allow_gnu_extensions_p (parser))
attributes = cp_parser_gnu_attributes_opt (parser);
cp_parser_error (parser,
"a brace-enclosed initializer is not allowed here");
/* Consume the opening brace. */
- cp_lexer_consume_token (parser->lexer);
+ matching_braces braces;
+ braces.consume_open (parser);
/* Skip the initializer. */
cp_parser_skip_to_closing_brace (parser);
/* Look for the trailing `}'. */
- cp_parser_require (parser, CPP_CLOSE_BRACE, RT_CLOSE_BRACE);
+ braces.require_close (parser);
return error_mark_node;
}
if (cp_lexer_peek_token (parser->lexer)->type == CPP_OPEN_PAREN)
{
- cp_lexer_consume_token (parser->lexer);
+ matching_parens parens;
+ parens.consume_open (parser);
if (require_constexpr)
{
*consumed_expr = true;
}
- cp_parser_require (parser, CPP_CLOSE_PAREN, RT_CLOSE_PAREN);
+ parens.require_close (parser);
}
else
{
cp_lexer_consume_token (parser->lexer);
/* Look for the `('. */
- cp_parser_require (parser, CPP_OPEN_PAREN, RT_OPEN_PAREN);
+ matching_parens parens;
+ parens.require_open (parser);
/* Peek at the next token. */
token = cp_lexer_peek_token (parser->lexer);
type_id_list = empty_except_spec;
/* Look for the `)'. */
- cp_parser_require (parser, CPP_CLOSE_PAREN, RT_CLOSE_PAREN);
+ parens.require_close (parser);
return type_id_list;
}
cp_parser_require_keyword (parser, RID_CATCH, RT_CATCH);
handler = begin_handler ();
- cp_parser_require (parser, CPP_OPEN_PAREN, RT_OPEN_PAREN);
+ matching_parens parens;
+ parens.require_open (parser);
declaration = cp_parser_exception_declaration (parser);
finish_handler_parms (declaration, handler);
- cp_parser_require (parser, CPP_CLOSE_PAREN, RT_CLOSE_PAREN);
+ parens.require_close (parser);
cp_parser_compound_statement (parser, NULL, BCS_NORMAL, false);
finish_handler (handler);
}
/* Consume the `asm' token. */
cp_lexer_consume_token (parser->lexer);
/* Look for the `('. */
- cp_parser_require (parser, CPP_OPEN_PAREN, RT_OPEN_PAREN);
+ matching_parens parens;
+ parens.require_open (parser);
/* Look for the string-literal. */
asm_specification = cp_parser_string_literal (parser, false, false);
/* Look for the `)'. */
- cp_parser_require (parser, CPP_CLOSE_PAREN, RT_CLOSE_PAREN);
+ parens.require_close (parser);
return asm_specification;
}
string_literal = cp_parser_string_literal (parser, false, false);
/* Look for the `('. */
- cp_parser_require (parser, CPP_OPEN_PAREN, RT_OPEN_PAREN);
+ matching_parens parens;
+ parens.require_open (parser);
/* Parse the expression. */
expression = cp_parser_expression (parser);
/* Look for the `)'. */
- cp_parser_require (parser, CPP_CLOSE_PAREN, RT_CLOSE_PAREN);
+ parens.require_close (parser);
if (name == error_mark_node
|| string_literal == error_mark_node
/* Consume the `__attribute__' keyword. */
cp_lexer_consume_token (parser->lexer);
/* Look for the two `(' tokens. */
- cp_parser_require (parser, CPP_OPEN_PAREN, RT_OPEN_PAREN);
- cp_parser_require (parser, CPP_OPEN_PAREN, RT_OPEN_PAREN);
+ matching_parens outer_parens;
+ outer_parens.require_open (parser);
+ matching_parens inner_parens;
+ inner_parens.require_open (parser);
/* Peek at the next token. */
token = cp_lexer_peek_token (parser->lexer);
attribute_list = NULL;
/* Look for the two `)' tokens. */
- if (!cp_parser_require (parser, CPP_CLOSE_PAREN, RT_CLOSE_PAREN))
+ if (!inner_parens.require_close (parser))
ok = false;
- if (!cp_parser_require (parser, CPP_CLOSE_PAREN, RT_CLOSE_PAREN))
+ if (!outer_parens.require_close (parser))
ok = false;
if (!ok)
cp_parser_skip_to_end_of_statement (parser);
cp_lexer_consume_token (parser->lexer);
maybe_warn_cpp0x (CPP0X_ATTRIBUTES);
- if (cp_parser_require (parser, CPP_OPEN_PAREN, RT_OPEN_PAREN) == NULL)
+ matching_parens parens;
+ if (!parens.require_open (parser))
{
cp_parser_error (parser, "expected %<(%>");
return error_mark_node;
if (alignas_expr == error_mark_node)
return error_mark_node;
- if (cp_parser_require (parser, CPP_CLOSE_PAREN, RT_CLOSE_PAREN) == NULL)
+ if (!parens.require_close (parser))
{
cp_parser_error (parser, "expected %<)%>");
return error_mark_node;
static tree
cp_parser_requirement_parameter_list (cp_parser *parser)
{
- if (!cp_parser_require (parser, CPP_OPEN_PAREN, RT_OPEN_PAREN))
+ matching_parens parens;
+ if (!parens.require_open (parser))
return error_mark_node;
tree parms = cp_parser_parameter_declaration_clause (parser);
- if (!cp_parser_require (parser, CPP_CLOSE_PAREN, RT_CLOSE_PAREN))
+ if (!parens.require_close (parser))
return error_mark_node;
return parms;
static tree
cp_parser_requirement_body (cp_parser *parser)
{
- if (!cp_parser_require (parser, CPP_OPEN_BRACE, RT_OPEN_BRACE))
+ matching_braces braces;
+ if (!braces.require_open (parser))
return error_mark_node;
tree reqs = cp_parser_requirement_list (parser);
- if (!cp_parser_require (parser, CPP_CLOSE_BRACE, RT_CLOSE_BRACE))
+ if (!braces.require_close (parser))
return error_mark_node;
return reqs;
cp_parser_compound_requirement (cp_parser *parser)
{
/* Parse an expression enclosed in '{ }'s. */
- if (!cp_parser_require (parser, CPP_OPEN_BRACE, RT_OPEN_BRACE))
+ matching_braces braces;
+ if (!braces.require_open (parser))
return error_mark_node;
tree expr = cp_parser_expression (parser, NULL, false, false);
if (!expr || expr == error_mark_node)
return error_mark_node;
- if (!cp_parser_require (parser, CPP_CLOSE_BRACE, RT_CLOSE_BRACE))
+ if (!braces.require_close (parser))
return error_mark_node;
/* Parse the optional noexcept. */
cp_parser_simulate_error (parser);
/* Look for opening brace for introduction. */
- cp_parser_require (parser, CPP_OPEN_BRACE, RT_OPEN_BRACE);
+ matching_braces braces;
+ braces.require_open (parser);
if (!cp_parser_parse_definitely (parser))
return false;
}
/* Look for closing brace for introduction. */
- if (!cp_parser_require (parser, CPP_CLOSE_BRACE, RT_CLOSE_BRACE))
+ if (!braces.require_close (parser))
return true;
if (tmpl_decl == error_mark_node)
cp_lexer_consume_token (parser->lexer);
maybe_warn_variadic_templates ();
+ matching_parens parens;
bool paren = cp_lexer_next_token_is (parser->lexer, CPP_OPEN_PAREN);
if (paren)
- cp_lexer_consume_token (parser->lexer);
+ parens.consume_open (parser);
else
permerror (cp_lexer_peek_token (parser->lexer)->location,
"%<sizeof...%> argument must be surrounded by parentheses");
PACK_EXPANSION_SIZEOF_P (expr) = true;
if (paren)
- cp_parser_require (parser, CPP_CLOSE_PAREN, RT_CLOSE_PAREN);
+ parens.require_close (parser);
return expr;
}
/* We can't be sure yet whether we're looking at a type-id or an
expression. */
cp_parser_parse_tentatively (parser);
+
+ matching_parens parens;
+ parens.consume_open (parser);
+
/* Note: as a GNU Extension, compound literals are considered
postfix-expressions as they are in C99, so they are valid
arguments to sizeof. See comment in cp_parser_cast_expression
/* Look for the type-id. */
type = cp_parser_type_id (parser);
/* Look for the closing `)'. */
- cp_parser_require (parser, CPP_CLOSE_PAREN, RT_CLOSE_PAREN);
+ parens.require_close (parser);
parser->in_type_id_in_expr_p = saved_in_type_id_in_expr_p;
}
return decl_spec_seq_has_spec_p (decl_specifiers, ds_friend);
}
+/* Get a description of the matching symbol to TOKEN_DESC e.g. "(" for
+ RT_CLOSE_PAREN. */
+
+static const char *
+get_matching_symbol (required_token token_desc)
+{
+ switch (token_desc)
+ {
+ default:
+ gcc_unreachable ();
+ return "";
+ case RT_CLOSE_BRACE:
+ return "{";
+ case RT_CLOSE_PAREN:
+ return "(";
+ }
+}
+
/* Issue an error message indicating that TOKEN_DESC was expected.
If KEYWORD is true, it indicated this function is called by
cp_parser_require_keword and the required token can only be
- a indicated keyword. */
+ a indicated keyword.
+
+ If MATCHING_LOCATION is not UNKNOWN_LOCATION, then highlight it
+ within any error as the location of an "opening" token matching
+ the close token TYPE (e.g. the location of the '(' when TOKEN_DESC is
+ RT_CLOSE_PAREN). */
static void
cp_parser_required_error (cp_parser *parser,
required_token token_desc,
- bool keyword)
+ bool keyword,
+ location_t matching_location)
{
+ if (cp_parser_simulate_error (parser))
+ return;
+
+ const char *gmsgid = NULL;
switch (token_desc)
{
case RT_NEW:
- cp_parser_error (parser, "expected %<new%>");
- return;
+ gmsgid = G_("expected %<new%>");
+ break;
case RT_DELETE:
- cp_parser_error (parser, "expected %<delete%>");
- return;
+ gmsgid = G_("expected %<delete%>");
+ break;
case RT_RETURN:
- cp_parser_error (parser, "expected %<return%>");
- return;
+ gmsgid = G_("expected %<return%>");
+ break;
case RT_WHILE:
- cp_parser_error (parser, "expected %<while%>");
- return;
+ gmsgid = G_("expected %<while%>");
+ break;
case RT_EXTERN:
- cp_parser_error (parser, "expected %<extern%>");
- return;
+ gmsgid = G_("expected %<extern%>");
+ break;
case RT_STATIC_ASSERT:
- cp_parser_error (parser, "expected %<static_assert%>");
- return;
+ gmsgid = G_("expected %<static_assert%>");
+ break;
case RT_DECLTYPE:
- cp_parser_error (parser, "expected %<decltype%>");
- return;
+ gmsgid = G_("expected %<decltype%>");
+ break;
case RT_OPERATOR:
- cp_parser_error (parser, "expected %<operator%>");
- return;
+ gmsgid = G_("expected %<operator%>");
+ break;
case RT_CLASS:
- cp_parser_error (parser, "expected %<class%>");
- return;
+ gmsgid = G_("expected %<class%>");
+ break;
case RT_TEMPLATE:
- cp_parser_error (parser, "expected %<template%>");
- return;
+ gmsgid = G_("expected %<template%>");
+ break;
case RT_NAMESPACE:
- cp_parser_error (parser, "expected %<namespace%>");
- return;
+ gmsgid = G_("expected %<namespace%>");
+ break;
case RT_USING:
- cp_parser_error (parser, "expected %<using%>");
- return;
+ gmsgid = G_("expected %<using%>");
+ break;
case RT_ASM:
- cp_parser_error (parser, "expected %<asm%>");
- return;
+ gmsgid = G_("expected %<asm%>");
+ break;
case RT_TRY:
- cp_parser_error (parser, "expected %<try%>");
- return;
+ gmsgid = G_("expected %<try%>");
+ break;
case RT_CATCH:
- cp_parser_error (parser, "expected %<catch%>");
- return;
+ gmsgid = G_("expected %<catch%>");
+ break;
case RT_THROW:
- cp_parser_error (parser, "expected %<throw%>");
- return;
+ gmsgid = G_("expected %<throw%>");
+ break;
case RT_LABEL:
- cp_parser_error (parser, "expected %<__label__%>");
- return;
+ gmsgid = G_("expected %<__label__%>");
+ break;
case RT_AT_TRY:
- cp_parser_error (parser, "expected %<@try%>");
- return;
+ gmsgid = G_("expected %<@try%>");
+ break;
case RT_AT_SYNCHRONIZED:
- cp_parser_error (parser, "expected %<@synchronized%>");
- return;
+ gmsgid = G_("expected %<@synchronized%>");
+ break;
case RT_AT_THROW:
- cp_parser_error (parser, "expected %<@throw%>");
- return;
+ gmsgid = G_("expected %<@throw%>");
+ break;
case RT_TRANSACTION_ATOMIC:
- cp_parser_error (parser, "expected %<__transaction_atomic%>");
- return;
+ gmsgid = G_("expected %<__transaction_atomic%>");
+ break;
case RT_TRANSACTION_RELAXED:
- cp_parser_error (parser, "expected %<__transaction_relaxed%>");
- return;
+ gmsgid = G_("expected %<__transaction_relaxed%>");
+ break;
default:
break;
}
- if (!keyword)
+
+ if (!gmsgid && !keyword)
{
switch (token_desc)
{
case RT_SEMICOLON:
- cp_parser_error (parser, "expected %<;%>");
- return;
+ gmsgid = G_("expected %<;%>");
+ break;
case RT_OPEN_PAREN:
- cp_parser_error (parser, "expected %<(%>");
- return;
+ gmsgid = G_("expected %<(%>");
+ break;
case RT_CLOSE_BRACE:
- cp_parser_error (parser, "expected %<}%>");
- return;
+ gmsgid = G_("expected %<}%>");
+ break;
case RT_OPEN_BRACE:
- cp_parser_error (parser, "expected %<{%>");
- return;
+ gmsgid = G_("expected %<{%>");
+ break;
case RT_CLOSE_SQUARE:
- cp_parser_error (parser, "expected %<]%>");
- return;
+ gmsgid = G_("expected %<]%>");
+ break;
case RT_OPEN_SQUARE:
- cp_parser_error (parser, "expected %<[%>");
- return;
+ gmsgid = G_("expected %<[%>");
+ break;
case RT_COMMA:
- cp_parser_error (parser, "expected %<,%>");
- return;
+ gmsgid = G_("expected %<,%>");
+ break;
case RT_SCOPE:
- cp_parser_error (parser, "expected %<::%>");
- return;
+ gmsgid = G_("expected %<::%>");
+ break;
case RT_LESS:
- cp_parser_error (parser, "expected %<<%>");
- return;
+ gmsgid = G_("expected %<<%>");
+ break;
case RT_GREATER:
- cp_parser_error (parser, "expected %<>%>");
- return;
+ gmsgid = G_("expected %<>%>");
+ break;
case RT_EQ:
- cp_parser_error (parser, "expected %<=%>");
- return;
+ gmsgid = G_("expected %<=%>");
+ break;
case RT_ELLIPSIS:
- cp_parser_error (parser, "expected %<...%>");
- return;
+ gmsgid = G_("expected %<...%>");
+ break;
case RT_MULT:
- cp_parser_error (parser, "expected %<*%>");
- return;
+ gmsgid = G_("expected %<*%>");
+ break;
case RT_COMPL:
- cp_parser_error (parser, "expected %<~%>");
- return;
+ gmsgid = G_("expected %<~%>");
+ break;
case RT_COLON:
- cp_parser_error (parser, "expected %<:%>");
- return;
+ gmsgid = G_("expected %<:%>");
+ break;
case RT_COLON_SCOPE:
- cp_parser_error (parser, "expected %<:%> or %<::%>");
- return;
+ gmsgid = G_("expected %<:%> or %<::%>");
+ break;
case RT_CLOSE_PAREN:
- cp_parser_error (parser, "expected %<)%>");
- return;
+ gmsgid = G_("expected %<)%>");
+ break;
case RT_COMMA_CLOSE_PAREN:
- cp_parser_error (parser, "expected %<,%> or %<)%>");
- return;
+ gmsgid = G_("expected %<,%> or %<)%>");
+ break;
case RT_PRAGMA_EOL:
- cp_parser_error (parser, "expected end of line");
- return;
+ gmsgid = G_("expected end of line");
+ break;
case RT_NAME:
- cp_parser_error (parser, "expected identifier");
- return;
+ gmsgid = G_("expected identifier");
+ break;
case RT_SELECT:
- cp_parser_error (parser, "expected selection-statement");
- return;
+ gmsgid = G_("expected selection-statement");
+ break;
case RT_ITERATION:
- cp_parser_error (parser, "expected iteration-statement");
- return;
+ gmsgid = G_("expected iteration-statement");
+ break;
case RT_JUMP:
- cp_parser_error (parser, "expected jump-statement");
- return;
+ gmsgid = G_("expected jump-statement");
+ break;
case RT_CLASS_KEY:
- cp_parser_error (parser, "expected class-key");
- return;
+ gmsgid = G_("expected class-key");
+ break;
case RT_CLASS_TYPENAME_TEMPLATE:
- cp_parser_error (parser,
- "expected %<class%>, %<typename%>, or %<template%>");
- return;
+ gmsgid = G_("expected %<class%>, %<typename%>, or %<template%>");
+ break;
default:
gcc_unreachable ();
}
}
- else
- gcc_unreachable ();
-}
+ if (gmsgid)
+ {
+ /* Emulate rest of cp_parser_error. */
+ cp_token *token = cp_lexer_peek_token (parser->lexer);
+ cp_lexer_set_source_position_from_token (token);
+
+ gcc_rich_location richloc (input_location);
+
+ /* If matching_location != UNKNOWN_LOCATION, highlight it.
+ Attempt to consolidate diagnostics by printing it as a
+ secondary range within the main diagnostic. */
+ bool added_matching_location = false;
+ if (matching_location != UNKNOWN_LOCATION)
+ added_matching_location
+ = richloc.add_location_if_nearby (matching_location);
+
+ c_parse_error (gmsgid,
+ (token->type == CPP_KEYWORD ? CPP_NAME : token->type),
+ token->u.value, token->flags, &richloc);
+
+ /* If we weren't able to consolidate matching_location, then
+ print it as a secondary diagnostic. */
+ if (matching_location != UNKNOWN_LOCATION && !added_matching_location)
+ inform (matching_location, "to match this %qs",
+ get_matching_symbol (token_desc));
+ }
+}
/* If the next token is of the indicated TYPE, consume it. Otherwise,
issue an error message indicating that TOKEN_DESC was expected.
Returns the token consumed, if the token had the appropriate type.
- Otherwise, returns NULL. */
+ Otherwise, returns NULL.
+
+ If MATCHING_LOCATION is not UNKNOWN_LOCATION, then highlight it
+ within any error as the location of an "opening" token matching
+ the close token TYPE (e.g. the location of the '(' when TOKEN_DESC is
+ RT_CLOSE_PAREN). */
static cp_token *
cp_parser_require (cp_parser* parser,
enum cpp_ttype type,
- required_token token_desc)
+ required_token token_desc,
+ location_t matching_location)
{
if (cp_lexer_next_token_is (parser->lexer, type))
return cp_lexer_consume_token (parser->lexer);
{
/* Output the MESSAGE -- unless we're parsing tentatively. */
if (!cp_parser_simulate_error (parser))
- cp_parser_required_error (parser, token_desc, /*keyword=*/false);
+ cp_parser_required_error (parser, token_desc, /*keyword=*/false,
+ matching_location);
return NULL;
}
}
if (token && token->keyword != keyword)
{
- cp_parser_required_error (parser, token_desc, /*keyword=*/true);
+ cp_parser_required_error (parser, token_desc, /*keyword=*/true,
+ UNKNOWN_LOCATION);
return NULL;
}
location_t start_loc = cp_lexer_peek_token (parser->lexer)->location;
cp_lexer_consume_token (parser->lexer); /* Eat '@encode'. */
- cp_parser_require (parser, CPP_OPEN_PAREN, RT_OPEN_PAREN);
+ matching_parens parens;
+ parens.require_open (parser);
token = cp_lexer_peek_token (parser->lexer);
type = complete_type (cp_parser_type_id (parser));
- cp_parser_require (parser, CPP_CLOSE_PAREN, RT_CLOSE_PAREN);
+ parens.require_close (parser);
if (!type)
{
tree name;
cp_lexer_consume_token (parser->lexer); /* Eat '@defs'. */
- cp_parser_require (parser, CPP_OPEN_PAREN, RT_OPEN_PAREN);
+ matching_parens parens;
+ parens.require_open (parser);
name = cp_parser_identifier (parser);
- cp_parser_require (parser, CPP_CLOSE_PAREN, RT_CLOSE_PAREN);
+ parens.require_close (parser);
return objc_get_class_ivars (name);
}
location_t start_loc = cp_lexer_peek_token (parser->lexer)->location;
cp_lexer_consume_token (parser->lexer); /* Eat '@protocol'. */
- cp_parser_require (parser, CPP_OPEN_PAREN, RT_OPEN_PAREN);
+ matching_parens parens;
+ parens.require_open (parser);
proto = cp_parser_identifier (parser);
- cp_parser_require (parser, CPP_CLOSE_PAREN, RT_CLOSE_PAREN);
+ parens.require_close (parser);
/* Build a location of the form:
@protocol(prot)
location_t loc = cp_lexer_peek_token (parser->lexer)->location;
cp_lexer_consume_token (parser->lexer); /* Eat '@selector'. */
- cp_parser_require (parser, CPP_OPEN_PAREN, RT_OPEN_PAREN);
+ matching_parens parens;
+ parens.require_open (parser);
token = cp_lexer_peek_token (parser->lexer);
while (cp_parser_objc_selector_p (token->type) || token->type == CPP_COLON
}
finish_selector:
- cp_parser_require (parser, CPP_CLOSE_PAREN, RT_CLOSE_PAREN);
+ parens.require_close (parser);
/* Build a location of the form:
{
tree proto_quals, cp_type = NULL_TREE;
- cp_lexer_consume_token (parser->lexer); /* Eat '('. */
+ matching_parens parens;
+ parens.consume_open (parser); /* Eat '('. */
proto_quals = cp_parser_objc_protocol_qualifiers (parser);
/* An ObjC type name may consist of just protocol qualifiers, in which
}
}
- cp_parser_require (parser, CPP_CLOSE_PAREN, RT_CLOSE_PAREN);
+ parens.require_close (parser);
type_name = build_tree_list (proto_quals, cp_type);
}
}
else if (next->type == CPP_OPEN_PAREN)
{
- cp_lexer_consume_token (parser->lexer); /* Eat '('. */
+ matching_parens parens;
+ parens.consume_open (parser); /* Eat '('. */
/* If there is no category name, and this is an @interface, we
have a class extension. */
else
*categ = cp_parser_identifier (parser);
- cp_parser_require (parser, CPP_CLOSE_PAREN, RT_CLOSE_PAREN);
+ parens.require_close (parser);
}
}
cp_parameter_declarator *parm;
tree parameter_declaration = error_mark_node;
bool seen_open_paren = false;
+ matching_parens parens;
cp_lexer_consume_token (parser->lexer);
- if (cp_parser_require (parser, CPP_OPEN_PAREN, RT_OPEN_PAREN))
+ if (parens.require_open (parser))
seen_open_paren = true;
if (cp_lexer_next_token_is (parser->lexer, CPP_ELLIPSIS))
{
/*attrlist=*/NULL);
}
if (seen_open_paren)
- cp_parser_require (parser, CPP_CLOSE_PAREN, RT_CLOSE_PAREN);
+ parens.require_close (parser);
else
{
/* If there was no open parenthesis, we are recovering from
location = cp_lexer_peek_token (parser->lexer)->location;
objc_maybe_warn_exceptions (location);
- cp_parser_require (parser, CPP_OPEN_PAREN, RT_OPEN_PAREN);
+ matching_parens parens;
+ parens.require_open (parser);
lock = cp_parser_expression (parser);
- cp_parser_require (parser, CPP_CLOSE_PAREN, RT_CLOSE_PAREN);
+ parens.require_close (parser);
/* NB: The @synchronized block needs to be wrapped in its own STATEMENT_LIST
node, lest it get absorbed into the surrounding block. */
if (cp_lexer_next_token_is (parser->lexer, CPP_OPEN_PAREN))
{
/* Eat the '('. */
- cp_lexer_consume_token (parser->lexer);
+ matching_parens parens;
+ parens.consume_open (parser);
while (true)
{
"error: expected ‘)’ before ‘,’ token". This is because
cp_parser_require, unlike the C counterpart, will produce an
error even if we are in error recovery. */
- if (!cp_parser_require (parser, CPP_CLOSE_PAREN, RT_CLOSE_PAREN))
+ if (!parens.require_close (parser))
{
cp_parser_skip_to_closing_parenthesis (parser,
/*recovering=*/true,
{
location_t loc = cp_lexer_peek_token (parser->lexer)->location;
- if (!cp_parser_require (parser, CPP_OPEN_PAREN, RT_OPEN_PAREN))
+ matching_parens parens;
+ if (!parens.require_open (parser))
return list;
tree t = cp_parser_assignment_expression (parser, NULL, false, false);
if (t == error_mark_node
- || !cp_parser_require (parser, CPP_CLOSE_PAREN, RT_CLOSE_PAREN))
+ || !parens.require_close (parser))
{
cp_parser_skip_to_closing_parenthesis (parser, /*recovering=*/true,
/*or_comma=*/false,
if (cp_lexer_next_token_is (lexer, CPP_OPEN_PAREN))
{
- cp_lexer_consume_token (lexer);
+ matching_parens parens;
+ parens.consume_open (parser);
do
{
}
while (1);
- if (!cp_parser_require (parser, CPP_CLOSE_PAREN, RT_CLOSE_PAREN))
+ if (!parens.require_close (parser))
goto cleanup_error;
}
HOST_WIDE_INT n;
loc = cp_lexer_peek_token (parser->lexer)->location;
- if (!cp_parser_require (parser, CPP_OPEN_PAREN, RT_OPEN_PAREN))
+ matching_parens parens;
+ if (!parens.require_open (parser))
return list;
num = cp_parser_constant_expression (parser);
- if (!cp_parser_require (parser, CPP_CLOSE_PAREN, RT_CLOSE_PAREN))
+ if (!parens.require_close (parser))
cp_parser_skip_to_closing_parenthesis (parser, /*recovering=*/true,
/*or_comma=*/false,
/*consume_paren=*/true);
enum omp_clause_default_kind kind = OMP_CLAUSE_DEFAULT_UNSPECIFIED;
tree c;
- if (!cp_parser_require (parser, CPP_OPEN_PAREN, RT_OPEN_PAREN))
+ matching_parens parens;
+ if (!parens.require_open (parser))
return list;
if (cp_lexer_next_token_is (parser->lexer, CPP_NAME))
{
}
if (kind == OMP_CLAUSE_DEFAULT_UNSPECIFIED
- || !cp_parser_require (parser, CPP_CLOSE_PAREN, RT_CLOSE_PAREN))
+ || !parens.require_close (parser))
cp_parser_skip_to_closing_parenthesis (parser, /*recovering=*/true,
/*or_comma=*/false,
/*consume_paren=*/true);
{
tree t, c;
- if (!cp_parser_require (parser, CPP_OPEN_PAREN, RT_OPEN_PAREN))
+ matching_parens parens;
+ if (!parens.require_open (parser))
return list;
t = cp_parser_condition (parser);
if (t == error_mark_node
- || !cp_parser_require (parser, CPP_CLOSE_PAREN, RT_CLOSE_PAREN))
+ || !parens.require_close (parser))
cp_parser_skip_to_closing_parenthesis (parser, /*recovering=*/true,
/*or_comma=*/false,
/*consume_paren=*/true);
tree t, c;
enum tree_code if_modifier = ERROR_MARK;
- if (!cp_parser_require (parser, CPP_OPEN_PAREN, RT_OPEN_PAREN))
+ matching_parens parens;
+ if (!parens.require_open (parser))
return list;
if (is_omp && cp_lexer_next_token_is (parser->lexer, CPP_NAME))
t = cp_parser_condition (parser);
if (t == error_mark_node
- || !cp_parser_require (parser, CPP_CLOSE_PAREN, RT_CLOSE_PAREN))
+ || !parens.require_close (parser))
cp_parser_skip_to_closing_parenthesis (parser, /*recovering=*/true,
/*or_comma=*/false,
/*consume_paren=*/true);
{
tree t, c;
- if (!cp_parser_require (parser, CPP_OPEN_PAREN, RT_OPEN_PAREN))
+ matching_parens parens;
+ if (!parens.require_open (parser))
return list;
t = cp_parser_expression (parser);
if (t == error_mark_node
- || !cp_parser_require (parser, CPP_CLOSE_PAREN, RT_CLOSE_PAREN))
+ || !parens.require_close (parser))
cp_parser_skip_to_closing_parenthesis (parser, /*recovering=*/true,
/*or_comma=*/false,
/*consume_paren=*/true);
{
tree t, c;
- if (!cp_parser_require (parser, CPP_OPEN_PAREN, RT_OPEN_PAREN))
+ matching_parens parens;
+ if (!parens.require_open (parser))
return list;
t = cp_parser_expression (parser);
if (t == error_mark_node
- || !cp_parser_require (parser, CPP_CLOSE_PAREN, RT_CLOSE_PAREN))
+ || !parens.require_close (parser))
cp_parser_skip_to_closing_parenthesis (parser, /*recovering=*/true,
/*or_comma=*/false,
/*consume_paren=*/true);
{
tree t, c;
- if (!cp_parser_require (parser, CPP_OPEN_PAREN, RT_OPEN_PAREN))
+ matching_parens parens;
+ if (!parens.require_open (parser))
return list;
t = cp_parser_expression (parser);
if (t == error_mark_node
- || !cp_parser_require (parser, CPP_CLOSE_PAREN, RT_CLOSE_PAREN))
+ || !parens.require_close (parser))
cp_parser_skip_to_closing_parenthesis (parser, /*recovering=*/true,
/*or_comma=*/false,
/*consume_paren=*/true);
{
tree t, c;
- if (!cp_parser_require (parser, CPP_OPEN_PAREN, RT_OPEN_PAREN))
+ matching_parens parens;
+ if (!parens.require_open (parser))
return list;
t = cp_parser_expression (parser);
if (t == error_mark_node
- || !cp_parser_require (parser, CPP_CLOSE_PAREN, RT_CLOSE_PAREN))
+ || !parens.require_close (parser))
cp_parser_skip_to_closing_parenthesis (parser, /*recovering=*/true,
/*or_comma=*/false,
/*consume_paren=*/true);
{
tree t, c;
- if (!cp_parser_require (parser, CPP_OPEN_PAREN, RT_OPEN_PAREN))
+ matching_parens parens;
+ if (!parens.require_open (parser))
return list;
t = cp_parser_expression (parser);
if (t == error_mark_node
- || !cp_parser_require (parser, CPP_CLOSE_PAREN, RT_CLOSE_PAREN))
+ || !parens.require_close (parser))
cp_parser_skip_to_closing_parenthesis (parser, /*recovering=*/true,
/*or_comma=*/false,
/*consume_paren=*/true);
tree c, id;
const char *p;
- if (!cp_parser_require (parser, CPP_OPEN_PAREN, RT_OPEN_PAREN))
+ matching_parens parens;
+ if (!parens.require_open (parser))
return list;
if (!cp_lexer_next_token_is (parser->lexer, CPP_NAME))
goto out_err;
}
cp_lexer_consume_token (parser->lexer);
- if (!cp_parser_require (parser, CPP_CLOSE_PAREN, RT_CLOSE_PAREN))
+ if (!parens.require_close (parser))
goto out_err;
check_no_duplicate_clause (list, OMP_CLAUSE_DEFAULTMAP, "defaultmap",
if (cp_lexer_next_token_is (parser->lexer, CPP_OPEN_PAREN))
{
- cp_lexer_consume_token (parser->lexer);
+ matching_parens parens;
+ parens.consume_open (parser);
num = cp_parser_constant_expression (parser);
- if (!cp_parser_require (parser, CPP_CLOSE_PAREN, RT_CLOSE_PAREN))
+ if (!parens.require_close (parser))
cp_parser_skip_to_closing_parenthesis (parser, /*recovering=*/true,
/*or_comma=*/false,
/*consume_paren=*/true);
tree c, t;
int modifiers = 0, nmodifiers = 0;
- if (!cp_parser_require (parser, CPP_OPEN_PAREN, RT_OPEN_PAREN))
+ matching_parens parens;
+ if (!parens.require_open (parser))
return list;
c = build_omp_clause (location, OMP_CLAUSE_SCHEDULE);
else
OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c) = t;
- if (!cp_parser_require (parser, CPP_CLOSE_PAREN, RT_CLOSE_PAREN))
+ if (!parens.require_close (parser))
goto resync_fail;
}
else if (!cp_parser_require (parser, CPP_CLOSE_PAREN, RT_COMMA_CLOSE_PAREN))
{
tree t, c;
- if (!cp_parser_require (parser, CPP_OPEN_PAREN, RT_OPEN_PAREN))
+ matching_parens parens;
+ if (!parens.require_open (parser))
return list;
t = cp_parser_expression (parser);
if (t == error_mark_node
- || !cp_parser_require (parser, CPP_CLOSE_PAREN, RT_CLOSE_PAREN))
+ || !parens.require_close (parser))
cp_parser_skip_to_closing_parenthesis (parser, /*recovering=*/true,
/*or_comma=*/false,
/*consume_paren=*/true);
{
tree t, c;
- if (!cp_parser_require (parser, CPP_OPEN_PAREN, RT_OPEN_PAREN))
+ matching_parens parens;
+ if (!parens.require_open (parser))
return list;
t = cp_parser_expression (parser);
if (t == error_mark_node
- || !cp_parser_require (parser, CPP_CLOSE_PAREN, RT_CLOSE_PAREN))
+ || !parens.require_close (parser))
cp_parser_skip_to_closing_parenthesis (parser, /*recovering=*/true,
/*or_comma=*/false,
/*consume_paren=*/true);
tree nlist, c, alignment = NULL_TREE;
bool colon;
- if (!cp_parser_require (parser, CPP_OPEN_PAREN, RT_OPEN_PAREN))
+ matching_parens parens;
+ if (!parens.require_open (parser))
return list;
nlist = cp_parser_omp_var_list_no_open (parser, OMP_CLAUSE_ALIGNED, list,
{
alignment = cp_parser_constant_expression (parser);
- if (!cp_parser_require (parser, CPP_CLOSE_PAREN, RT_CLOSE_PAREN))
+ if (!parens.require_close (parser))
cp_parser_skip_to_closing_parenthesis (parser, /*recovering=*/true,
/*or_comma=*/false,
/*consume_paren=*/true);
bool colon;
enum omp_clause_linear_kind kind = OMP_CLAUSE_LINEAR_DEFAULT;
- if (!cp_parser_require (parser, CPP_OPEN_PAREN, RT_OPEN_PAREN))
+ matching_parens parens;
+ if (!parens.require_open (parser))
return list;
if (!is_cilk_simd_fn
colon = cp_lexer_next_token_is (parser->lexer, CPP_COLON);
if (colon)
cp_parser_require (parser, CPP_COLON, RT_COLON);
- else if (!cp_parser_require (parser, CPP_CLOSE_PAREN, RT_CLOSE_PAREN))
+ else if (!parens.require_close (parser))
cp_parser_skip_to_closing_parenthesis (parser, /*recovering=*/true,
/*or_comma=*/false,
/*consume_paren=*/true);
sorry ("using parameters for %<linear%> step is not supported yet");
step = integer_one_node;
}
- if (!cp_parser_require (parser, CPP_CLOSE_PAREN, RT_CLOSE_PAREN))
+ if (!parens.require_close (parser))
cp_parser_skip_to_closing_parenthesis (parser, /*recovering=*/true,
/*or_comma=*/false,
/*consume_paren=*/true);
{
tree t, c;
- if (!cp_parser_require (parser, CPP_OPEN_PAREN, RT_OPEN_PAREN))
+ matching_parens parens;
+ if (!parens.require_open (parser))
return list;
t = cp_parser_constant_expression (parser);
if (t == error_mark_node
- || !cp_parser_require (parser, CPP_CLOSE_PAREN, RT_CLOSE_PAREN))
+ || !parens.require_close (parser))
cp_parser_skip_to_closing_parenthesis (parser, /*recovering=*/true,
/*or_comma=*/false,
/*consume_paren=*/true);
{
tree t, c;
- if (!cp_parser_require (parser, CPP_OPEN_PAREN, RT_OPEN_PAREN))
+ matching_parens parens;
+ if (!parens.require_open (parser))
return list;
t = cp_parser_constant_expression (parser);
if (t == error_mark_node
- || !cp_parser_require (parser, CPP_CLOSE_PAREN, RT_CLOSE_PAREN))
+ || !parens.require_close (parser))
cp_parser_skip_to_closing_parenthesis (parser, /*recovering=*/true,
/*or_comma=*/false,
/*consume_paren=*/true);
tree nlist, c;
enum omp_clause_depend_kind kind = OMP_CLAUSE_DEPEND_INOUT;
- if (!cp_parser_require (parser, CPP_OPEN_PAREN, RT_OPEN_PAREN))
+ matching_parens parens;
+ if (!parens.require_open (parser))
return list;
if (cp_lexer_next_token_is (parser->lexer, CPP_NAME))
OMP_CLAUSE_DEPEND_KIND (c) = kind;
OMP_CLAUSE_DECL (c) = NULL_TREE;
OMP_CLAUSE_CHAIN (c) = list;
- if (!cp_parser_require (parser, CPP_CLOSE_PAREN, RT_CLOSE_PAREN))
+ if (!parens.require_close (parser))
cp_parser_skip_to_closing_parenthesis (parser, /*recovering=*/true,
/*or_comma=*/false,
/*consume_paren=*/true);
{
tree t, c;
- if (!cp_parser_require (parser, CPP_OPEN_PAREN, RT_OPEN_PAREN))
+ matching_parens parens;
+ if (!parens.require_open (parser))
return list;
t = cp_parser_expression (parser);
if (t == error_mark_node
- || !cp_parser_require (parser, CPP_CLOSE_PAREN, RT_CLOSE_PAREN))
+ || !parens.require_close (parser))
cp_parser_skip_to_closing_parenthesis (parser, /*recovering=*/true,
/*or_comma=*/false,
/*consume_paren=*/true);
{
tree c, t;
- if (!cp_parser_require (parser, CPP_OPEN_PAREN, RT_OPEN_PAREN))
+ matching_parens parens;
+ if (!parens.require_open (parser))
return list;
c = build_omp_clause (location, OMP_CLAUSE_DIST_SCHEDULE);
goto resync_fail;
OMP_CLAUSE_DIST_SCHEDULE_CHUNK_EXPR (c) = t;
- if (!cp_parser_require (parser, CPP_CLOSE_PAREN, RT_CLOSE_PAREN))
+ if (!parens.require_close (parser))
goto resync_fail;
}
else if (!cp_parser_require (parser, CPP_CLOSE_PAREN, RT_COMMA_CLOSE_PAREN))
if (cp_lexer_peek_token (parser->lexer)->type == CPP_OPEN_PAREN)
{
- cp_lexer_consume_token (parser->lexer);
+ matching_parens parens;
+ parens.consume_open (parser);
t = cp_parser_expression (parser);
if (t == error_mark_node
- || !cp_parser_require (parser, CPP_CLOSE_PAREN, RT_CLOSE_PAREN))
+ || !parens.require_close (parser))
cp_parser_skip_to_closing_parenthesis (parser, /*recovering=*/true,
/*or_comma=*/false,
/*consume_paren=*/true);
if (cp_lexer_next_token_is (parser->lexer, CPP_OPEN_PAREN))
{
- cp_lexer_consume_token (parser->lexer);
+ matching_parens parens;
+ parens.consume_open (parser);
name = cp_parser_identifier (parser);
if (name == error_mark_node
- || !cp_parser_require (parser, CPP_CLOSE_PAREN, RT_CLOSE_PAREN))
+ || !parens.require_close (parser))
cp_parser_skip_to_closing_parenthesis (parser, /*recovering=*/true,
/*or_comma=*/false,
/*consume_paren=*/true);
}
loc = cp_lexer_consume_token (parser->lexer)->location;
- if (!cp_parser_require (parser, CPP_OPEN_PAREN, RT_OPEN_PAREN))
+ matching_parens parens;
+ if (!parens.require_open (parser))
return NULL;
init = orig_init = decl = real_decl = NULL;
protected_set_expr_location (incr, input_location);
}
- if (!cp_parser_require (parser, CPP_CLOSE_PAREN, RT_CLOSE_PAREN))
+ if (!parens.require_close (parser))
cp_parser_skip_to_closing_parenthesis (parser, /*recovering=*/true,
/*or_comma=*/false,
/*consume_paren=*/true);
bool error_suppress = false;
cp_token *tok;
- if (!cp_parser_require (parser, CPP_OPEN_BRACE, RT_OPEN_BRACE))
+ matching_braces braces;
+ if (!braces.require_open (parser))
return NULL_TREE;
stmt = push_stmt_list ();
substmt = build1 (OMP_SECTION, void_type_node, substmt);
add_stmt (substmt);
}
- cp_parser_require (parser, CPP_CLOSE_BRACE, RT_CLOSE_BRACE);
+ braces.require_close (parser);
substmt = pop_stmt_list (stmt);
if (strcmp (p, "initializer") == 0)
{
cp_lexer_consume_token (parser->lexer);
- if (!cp_parser_require (parser, CPP_OPEN_PAREN, RT_OPEN_PAREN))
+ matching_parens parens;
+ if (!parens.require_open (parser))
return false;
p = "";
if (ctor)
add_decl_expr (omp_orig);
- if (!cp_parser_require (parser, CPP_CLOSE_PAREN, RT_CLOSE_PAREN))
+ if (!parens.require_close (parser))
return false;
}
if (!cp_lexer_next_token_is (parser->lexer, CPP_PRAGMA_EOL))
- cp_parser_required_error (parser, RT_PRAGMA_EOL, /*keyword=*/false);
+ cp_parser_required_error (parser, RT_PRAGMA_EOL, /*keyword=*/false,
+ UNKNOWN_LOCATION);
return true;
}
/* Look for optional '( name )'. */
if (cp_lexer_next_token_is (parser->lexer, CPP_OPEN_PAREN))
{
- cp_lexer_consume_token (parser->lexer); /* '(' */
+ matching_parens parens;
+ parens.consume_open (parser); /* '(' */
/* We parse the name as an id-expression. If it resolves to
anything other than a non-overloaded function at namespace
cp_parser_name_lookup_error (parser, name, decl, NLE_NULL, name_loc);
if (decl == error_mark_node
- || !cp_parser_require (parser, CPP_CLOSE_PAREN, RT_CLOSE_PAREN))
+ || !parens.require_close (parser))
{
cp_parser_skip_to_pragma_eol (parser, pragma_tok);
parser->oacc_routine = NULL;
if (!noex || !noex_expr
|| cp_lexer_peek_token (parser->lexer)->type == CPP_OPEN_PAREN)
{
- cp_parser_require (parser, CPP_OPEN_PAREN, RT_OPEN_PAREN);
+ matching_parens parens;
+ parens.require_open (parser);
expr = cp_parser_expression (parser);
expr = finish_parenthesized_expr (expr);
- cp_parser_require (parser, CPP_CLOSE_PAREN, RT_CLOSE_PAREN);
+ parens.require_close (parser);
}
else
{
check_no_duplicate_clause (clauses, OMP_CLAUSE_SIMDLEN, "vectorlength",
loc);
- if (!cp_parser_require (parser, CPP_OPEN_PAREN, RT_OPEN_PAREN))
+ matching_parens parens;
+ if (!parens.require_open (parser))
return error_mark_node;
expr = cp_parser_constant_expression (parser);
}
}
- if (!cp_parser_require (parser, CPP_CLOSE_PAREN, RT_CLOSE_PAREN))
+ if (!parens.require_close (parser))
return error_mark_node;
return clauses;
}