I've just made a breakthrough concerning refactoring code that contains
alternative code blocks selected by the preprocessor (#if #else #endif
stuffs).
The solution is fairly simple: the transformation that represents a
refactoring applied on a source with multiple code alternatives is the union
of the transformations of the refactoring applied on each code alternative.
Take for example the following slice of code (from boost.filesystem):
---
inline bool dot_or_dot_dot( const char * name )
{
# if !BOOST_WORKAROUND( __BORLANDC__, BOOST_TESTED_AT(0x0564) )
return std::strcmp( name, "." ) == 0
|| std::strcmp( name, ".." ) == 0;
# else
return name[0]=='.'
&& (name[1]=='\0' || (name[1]=='.' && name[2]=='\0'));
# endif
}
---
Say you want to rename the parameter 'name'.
You first apply the refactoring on the code using the first alternative.
You obtains a first set of transformations.
Then, you apply the refactoring on the code using the second
alternative. You obtains a second set of transformations.
Adding the two sets of transformation give you the transformation to two
for this refactoring.
There is still a lot to be worked out (how to you select code
alternatives in a coherent way...), but I believe there core idea is there.
Baptiste.
|