Re: [PATCH] matching tokens: C++ parts (v3)

2017-08-09 Thread Jason Merrill
On Tue, Aug 8, 2017 at 5:01 PM, David Malcolm  wrote:
> On Mon, 2017-08-07 at 14:25 -0400, Jason Merrill wrote:
>
> Thanks for looking at this.
>
>> On 08/01/2017 04:21 PM, David Malcolm wrote:
>> > @@ -27632,6 +27769,9 @@ cp_parser_sizeof_operand (cp_parser*
>> > parser, enum rid keyword)
>> >  {
>> >tree type = NULL_TREE;
>> >
>> > +  matching_parens parens;
>> > +  parens.peek_open (parser);
>>
>> I was puzzled by this until I found that
>> cp_parser_compound_literal_p
>> consumes the open paren.  Let's remove that in favor of calling
>> consume_open here, so we don't need peek_open anymore.
>
> Done.
>
>> About passing parser in or not, I'm happy with the current approach;
>> adding things to the stack isn't free in a highly recursive program
>> like GCC.
>
> Thanks; I'll keep "parser" out of the new classes then.
>
> Here's an updated "v3" patch.
>
> Successfully bootstrapped on x86_64-pc-linux-gnu in conjunction
> with the other patches (1 and 2 of the v2 kit).
>
> OK for trunk, assuming the other patches are approved? (patch 2 in the kit,
> for the C frontend, still needs approval).

OK.

Jason


[PATCH] matching tokens: C++ parts (v3)

2017-08-08 Thread David Malcolm
On Mon, 2017-08-07 at 14:25 -0400, Jason Merrill wrote:

Thanks for looking at this.

> On 08/01/2017 04:21 PM, David Malcolm wrote:
> > @@ -27632,6 +27769,9 @@ cp_parser_sizeof_operand (cp_parser*
> > parser, enum rid keyword)
> >  {
> >tree type = NULL_TREE;
> >
> > +  matching_parens parens;
> > +  parens.peek_open (parser);
>
> I was puzzled by this until I found that
> cp_parser_compound_literal_p
> consumes the open paren.  Let's remove that in favor of calling
> consume_open here, so we don't need peek_open anymore.

Done.

> About passing parser in or not, I'm happy with the current approach;
> adding things to the stack isn't free in a highly recursive program
> like
> GCC.

Thanks; I'll keep "parser" out of the new classes then.

Here's an updated "v3" patch.

Successfully bootstrapped on x86_64-pc-linux-gnu in conjunction
with the other patches (1 and 2 of the v2 kit).

OK for trunk, assuming the other patches are approved? (patch 2 in the kit,
for the C frontend, still needs approval).

Changes in v3:

Here's a ChangeLog for the change relative to the previous v2 patch:

gcc/cp/ChangeLog:
* parser.c (token_pair::require_open): Use tabs rather than spaces.
(token_pair::peek_open): Delete.
(token_pair::require_close): Use tabs rather than spaces.
(cp_parser_compound_literal_p): Remove consumption of opening
paren.
(cp_parser_postfix_expression): Add matching_parens instance.  Use
it to consume the opening paren previously consumed by
cp_parser_compound_literal_p.  Convert call to cp_parser_require
to parens.require_close.
(cp_parser_sizeof_operand): Convert call to parens.peek_open to
call to consume_open to consume the opening paren previously
consumed by cp_parser_compound_literal_p.

Here's an integrated ChangeLog for the patch as a whole:

gcc/cp/ChangeLog:
* parser.c (cp_parser_error): Update for new param to
c_parse_error.
(class token_pair): New class.
(struct matching_paren_traits): New struct.
(matching_parens): New typedef.
(struct matching_brace_traits): New struct.
(matching_braces): New typedef.
(cp_parser_statement_expr): Convert explicit parsing of
CPP_OPEN_PAREN and CPP_CLOSE_PAREN to use of
class matching_parens, so that the pertinent open parenthesis is
highlighted when there are problems locating the close
parenthesis.
(cp_parser_primary_expression): Likewise.
(cp_parser_compound_literal_p): Remove consumption of opening
paren.
(cp_parser_postfix_expression): Convert explicit parsing of
CPP_OPEN_PAREN and CPP_CLOSE_PAREN to use matching parens, as
above.  Use it to consume the opening paren previously consumed by
cp_parser_compound_literal_p.
(cp_parser_parenthesized_expression_list): Likewise.
(cp_parser_unary_expression): Likewise.
(cp_parser_new_expression): Likewise.
(cp_parser_cast_expression): Likewise.
(cp_parser_builtin_offsetof): Likewise.
(cp_parser_trait_expr): Likewise.
(cp_parser_lambda_declarator_opt): Likewise.
(cp_parser_lambda_body): Likewise, for matching_braces.
(cp_parser_compound_statement): Likewise.
(cp_parser_selection_statement): Likewise, for matching_parens.
(cp_parser_iteration_statement): Likewise.
(cp_parser_already_scoped_statement): Likewise, for
matching_braces.
(cp_parser_linkage_specification): Likewise.
(cp_parser_static_assert): Likewise, for matching_parens.
(cp_parser_decltype): Likewise.
(cp_parser_operator): Likewise.
(cp_parser_enum_specifier): Likewise.
(cp_parser_namespace_definition): Likewise.
(cp_parser_direct_declarator): Likewise.
(cp_parser_braced_list): Likewise.
(cp_parser_class_specifier_1): Likewise, for matching_braces.
(cp_parser_constant_initializer): Likewise.
(cp_parser_noexcept_specification_opt): Likewise, for
matching_parens.
(cp_parser_exception_specification_opt): Likewise.
(cp_parser_handler): Likewise.
(cp_parser_asm_specification_opt): Likewise.
(cp_parser_asm_operand_list): Likewise.
(cp_parser_gnu_attributes_opt): Likewise.
(cp_parser_std_attribute_spec): Likewise.
(cp_parser_requirement_parameter_list): Likewise.
(cp_parser_requirement_body): Likewise, for matching_braces.
(cp_parser_compound_requirement): Likewise.
(cp_parser_template_introduction): Likewise.
(cp_parser_sizeof_pack): Likewise, for matching_parens.
(cp_parser_sizeof_operand): Likewise; use it to consume the
opening paren previously consumed by cp_parser_compound_literal_p.
(get_matching_symbol): New function.
(cp_parser_required_error): Add param