This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
[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,Jason Merrill <jason at redhat dot com>
- Date: Mon, 17 Jun 2002 17:07:35 +0100
- Subject: [ast-optimizer-branch] simplifying C++
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. The second is more complex; I
think the best way to deal with it is to move the test into the loop body.
So given
struct A {
A(bool);
operator bool();
~A();
};
this
for (int i = 42; A a (i == 24); --i)
{
...
}
becomes this pseudocode:
{
int i;
for (i = 42; ; --i)
{
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.
Make sense?
Jason