This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [C++0x] avoid extra tentative parse in range-based for loops


On Fri, Nov 26, 2010 at 5:20 PM, Jason Merrill <jason@redhat.com> wrote:
>> That was my first option but sadly it doesn't work. The problem is
>> that cp_parser_expression_statement must be called after
>> begin_for_stmt.
>
> Why? ÂYou moved the scope stuff into begin_for_scope, which is called before
> cp_parser_for_init_statement.

Oh, actually you are right! In a previous unreleased version of this
patch, it needed to be here, but now it can be moved to
cp_parser_for_init_statement. In this way we don't need the kind_for
enumeration, since only two cases are needed a bool is enough.

> That still doesn't cover what happens to *just_one_declarator in the other
> cases.

Please see the new comments in the patch.

> I don't think either message is significantly better, so I'd go with the
> simpler logic.

Ok.

>> Â* Do not issue the error "expected initializer".
>> Â* Pass SD_INITIALIZED to start_decl.
>> Â* Do not parse the initializer, since it is not here.
>> Â* Do not call cp_finish_decl, since it will be called by the upper
>> function.
>
> Right. ÂNot setting is_initialized covers #3, and I think the others should
> be handled by a separate flag instead of special values of the
> initialization variables.
> ...
> I think it's definitely worth it; that's a lot clearer than the magic
> CPP_EOF. ÂAlso, let's rename just_one_declarator to maybe_range_for_decl to
> make it clearer what's going on.

Done and done. I named the flag "range_for_decl_p".

Also I added two testcases (hope that's enough) and rewrote a few more comments.

Regards.
--
Rodrigo

Changelog:

gcc/cp/

2010-11-29  Rodrigo Rivas Costa <rodrigorivascosta@gmail.com>

	* cp-tree.h (begin_for_scope): New prototype.
	(begin_for_stmt): Update prototype.
	(begin_range_for_stmt): Update prototype.
	* init.c (build_vec_init): Update call to begin_for_stmt.
	* parser.c (cp_parser_for): New.
	(cp_parser_c_for): Add three new parameters.
	(cp_parser_range_for): Likewise. Most parsing code removed.
	(cp_parser_iteration_statement): Call cp_parser_for instead of
	cp_parser_c_for and cp_parser_range_for.
	(cp_parser_for_init_statement): Add new parameter and return type.
	(cp_parser_block_declaration): Update call to
	cp_parser_simple_declaration.
	(cp_parser_simple_declaration): Add new parameter.
	Update call to cp_parser_init_declarator.
	(cp_parser_init_declarator): Add new parameter.
	* pt.c (tsubst_expr): Update call to begin_for_stmt.
	* semantics.c (begin_for_scope): New.
	(begin_for_stmt): Add two new parameters.
	(begin_range_for_stmt): Likewise.

gcc/testsuite/

2010-11-29  Rodrigo Rivas Costa <rodrigorivascosta@gmail.com>

	* g++.dg/cpp0x/range-for4.C: Delete useless include and duplicated
	comment.
	* g++.dg/cpp0x/range-for8.C: New.
	* g++.dg/cpp0x/range-for9.C: New.

Attachment: range-for4.txt
Description: Text document


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]