I've just added IdentifierResolver and IdentifierResolverContext. Those
two classes will replace respectively ScopeGenerator and ScopeHolder.
IdentifierResolver basically visit the AST and IdentifierResolverContext
manages variable visibility and identifier resolution during the visitation.
I expect IdentifierResolverContext to become a Strategy over time.
I initially started changing ScopeGenerator to handle the new if ( int x
= 3 ) case, but the code was getting too complicated for my taste. Also, the
ReduceLocalVariableScope refactoring need to know what is the statement
that generated the scope: a variable declaration can only be moved into a
compound statement, and if a compound statement does not exist, it may need
to be created.
int x =3;
if ( true )
++x;
=>
if ( true )
{
int x = 3;
++x;
}
This would not have been possible with the previous scheme. The
visitor/strategy based identifier is a lot more flexible and extensible.
Also, the implementation is much more simple.
Both classes still need testing (should be able to reuse some of
ScopeGenerator tests). I'll try to do that tomorrow. It's time for me to
call it a day (I'll answer the other mails tomorrow).
Baptiste.
|