[C++0x patch] implement range-based for loops

Rodrigo Rivas rodrigorivascosta@gmail.com
Thu Sep 9 09:31:00 GMT 2010


> One way to avoid the extension would be to wait and fill in DECL_NAME after
> parsing the body block, so that it's not available to name lookup in the
> source.

But these variables are local to the "cp_convert_range_for()" function
so they are not easily available at the end of the block. And
upgrading the FOR_STMT is just overkilling.

I tried to change the name at different points of the code and it
causes ICEs. For example:

begin = build_decl (input_location, VAR_DECL, NULL_TREE, iter_type);
TREE_USED (begin) = 1;
DECL_ARTIFICIAL (begin) = 1;
push_decl (begin);
DECL_NAME (begin) = get_identifier ("__begin");


Anyway, I think it should be better to add a suffix to these, just
like anonymous enums. That will render the extension unusable, and at
the same time solves the debugging of nested loops. Something like
this:

static GTY(()) int range_for_cnt = 0;
static tree
make_range_for_name(const char *id)
{
  char buf[40];
  sprintf(buf, "__range_for_%s_%d", id, range_for_cnt);
/* the counter is incremented outside of the function so
  all identifiers of a loop get the same number */
  return get_identifier (buf);
}

/* ... */
range = build_decl (input_location, VAR_DECL,
make_range_for_name("expr"), range_type);
/* ... */
begin = build_decl (input_location, VAR_DECL,
make_range_for_name("begin"), iter_type);
/* ... */
end = build_decl (input_location, VAR_DECL,
make_range_for_name("end"), iter_type);
/* ... */
range_for_cnt++;

What do you think?


BTW, I didn't get any response from the copyright assignment, and it's
been a month since I sent it. I tried to reply to the e-mail but
without result. Do you know where should I ask? Maybe in the general
"gcc" mailing list?

Regards.
Rodrigo



More information about the Gcc-patches mailing list