This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: [ast-optimizer-branch] simplifying C++
- From: Jason Merrill <jason at redhat dot com>
- To: Diego Novillo <dnovillo at redhat dot com>
- Cc: Daniel Berlin <dberlin at dberlin dot org>,"gcc at gcc dot gnu dot org" <gcc at gcc dot gnu dot org>, Jason Merrill <jason at redhat dot com>
- Date: Mon, 17 Jun 2002 20:01:46 +0100
- Subject: Re: [ast-optimizer-branch] simplifying C++
- References: <wvlsn3l6g8o.fsf@prospero.cambridge.redhat.com><1024331091.1209.44.camel@shadowfax>
>>>>> "Diego" == Diego Novillo <dnovillo@redhat.com> writes:
> On Mon, 2002-06-17 at 12:07, Jason Merrill wrote:
>> I've been thinking about simplifying C++, and the complex scoping that C++
>> loops have. In a for loop, a decl in the for-init-stmt is in scope for the
>> duration of the loop; a decl in the condition is in scope within an
>> iteration, goes out of scope, and back in. The first can be dealt with
>> simply by wrapping the loop in a scope.
>>
> Are these the same rules as for C99? When I ran into this one last
> week, the front end was already enclosing the loop in a scope, so the
> simplifier didn't have to do much more than recognizing DECL_STMTs
> inside FOR_INIT_STMT.
Yep, it's the same.
>> {
>> int i;
>> for (i = 42; ; i = i - 1)
>> {
>> A* T.1;
>> bool T.2;
>> bool T.3;
>> A a;
>> T.1 = &a;
>> T.2 = i == 24;
>> A::ctor (T.1, T.2);
>> __with_cleanup (A::dtor (T.1))
>> {
>> T.3 = a.operator bool();
>> if (T.3 == 0)
>> break;
>> ...
>> }
>> }
>> }
>>
>> I think it's best to leave the cleanup in this structured form initially,
>> and deal with adding it to the various block exits later.
> Not pretty, but that's how we're dealing with statement expressions
> now. Ideally, we should inline expand all these constructs.
What do you mean? What would you expand inline?
> Would it be too inconvenient to replace the FOR_EXPR with T.3 in the
> above code instead of having a break inside __with_cleanup?
Do you mean the FOR_COND, i.e. something like this?
{
int i;
bool T.3;
T.3 = true;
for (i = 42; T.3; i = i - 1)
{
A* T.1;
bool T.2;
A a;
T.1 = &a;
T.2 = i == 24;
A::ctor (T.1, T.2);
__with_cleanup (A::dtor (T.1))
{
T.3 = a.operator bool();
if (T.3)
{
...
}
}
}
}
I suppose that would work, too.
Jason