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 patch] implement range-based for loops


> Let's adjust the code factoring a bit. ÂPlease move the variables range_decl
> and range_expr, and the calls to cp_convert_range_for and
> finish_range_for_decl, into cp_parser_range_for; factor the code to parse
> C-style for-statements into another function cp_parser_c_for; share the code
> starting with "look for the )"; and make finish_for_stmt handle
> RANGE_FOR_STMT as well.
Ok. The code looks much nicer now.

>> + Âif (flag_new_for_scope > 0)
>> + Â ÂTREE_CHAIN (r) = do_pushlevel (sk_for);
>
> We should push the scope for range-fors regardless of flag_new_for_scope,
> since they didn't exist before the change to for-statement scope. ÂIt's
> probably (past) time to deprecate that option anyway.

Yes, I don't think anybody cares about this flag any more, although
now this patch would be a bit simpler if we keep it in, just for
symmetry. Anyway I did as you suggested (I really don't care about
this flag).

>> + Â/* Create the __range variable */
>> + Ârange_temp = create_temporary_var (range_type);
>> + Âbegin = create_temporary_var (iter_type);
>> + Âend = create_temporary_var (iter_type);
>
> Let's actually call these __range, __begin and __end (and not set
> DECL_IGNORED_P) so that people can examine them in the debugger.
I've changed it to:

  range_temp = build_decl (input_location, VAR_DECL,
                           get_identifier ("__range"), range_type);
  TREE_USED (range_temp) = 1;
  DECL_ARTIFICIAL (range_temp) = 1;
  pushdecl (range_temp);

And so on. Now I can see it in the debugger, but I can also use these
names in the code. This makes it, effectively, a GNU extension, even
with "-std=c++0x". I don't know... being able to debug it is nice, but
to allow the user to use a non-standard feature for not real gain may
be problematic. Is it possible to prevent the user from using the
names while allowing the debugger to see them?

> Line-wrapped arguments need to line up with the (.
Argh! Vim keeps moving them around!

Regards.
--
Rodrigo.

New changelog.
--
gcc/cp/

2010-09-07  Rodrigo Rivas <rodrigorivascosta@gmail.com>

	Implement range-based for-statements.
	* cp-tree.def (RANGE_FOR_STMT): New.
	* cp-tree.h (RANGE_FOR_DECL, RANGE_FOR_EXPR, RANGE_FOR_BODY): New.
	(cp_convert_range_for): Declare.
	* pt.c (tsubst_expr): Add RANGE_FOR_STMT.
	(tsubst_copy_and_build): perform_koenig_lookup takes extra argument.
	* semantics.c (begin_range_for_stmt): New.
	(finish_range_for_decl): New.
	(finish_for_stmt): Accept also RANGE_FOR_STMT.
	(perform_koenig_lookup): Add extra argument include_std.
	* parser.c (cp_parser_c_for): New with code from
	cp_parser_iteration_statement().
	(cp_parser_range_for): New.
	(cp_convert_range_for): New.
	(cp_parser_iteration_statement): Add range-for support.
	(cp_parser_condition): Adjust comment.
	(cp_parser_postfix_expression): perform_koenig_lookup takes extra
	argument.
	* dump.c (cp_dump_tree): Add RANGE_FOR_STMT.
	* cxx-pretty-print.c (): Likewise.
	* lex.c (cxx_init): Likewise.
	* name-lookup.c (lookup_function_nonclass): Add extra argument
	include_std.
	(lookup_arg_dependent): Likewise.
	* name-lookup.h (): Likewise.

gcc/testsuite/

2010-09-07  Rodrigo Rivas <rodrigorivascosta@gmail.com>

	* g++.dg/cpp0x/range-for1.C: New.
	* g++.dg/cpp0x/range-for2.C: New.
	* g++.dg/cpp0x/range-for3.C: New.
	* g++.dg/cpp0x/range-for4.C: New.
	* g++.dg/cpp0x/range-for5.C: New.
	* g++.dg/cpp0x/range-for6.C: New.

Attachment: range-for.txt
Description: Text document


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