Typedef removal tool
julia at diku.dk
Wed Aug 12 15:57:06 UTC 2009
> BTW I was under the impression spatch wouldn't touch header files or
> dive in to untangle macros. Is that incorrect? Would the cocci files
> allow spatch to not only change typdef usages with simple struct uses
> but also redefine a typedef declaration to a simple struct definition
> through header files? For upstream work I don't expect as much macro
> mess as you would with typical vendor drivers. For drivers which do
> need to get ported I do expect an tangling web of macro mess one may
> need to put up with at times.
spatch looks at header files to a user-controllable degree: -no_includes
means ignore all #includes, -local_includes means consider include
files in the current directory, and -all_includes means consider all
direct #includes. There is no option to consider files that are included
by included files.
If a header file is included, then spatch is willing to generate patches
for transformations within the header file. An inconvenience is that
if a single header file is included multiple times, a patch will be
generated for it each time as well. In the worst case, these patches
might not even be consistent.
There is also an increasing effort to take into account macro definitions,
when they are available and useful. I don't know the exact current status
of that, however. Perhaps Yoann (in CC) can explain.
In the general case, there it is not possible to write a rule to change a
typedef to a simple structure declaration with the same name as the
typedef. The problem is that typedef declares something that is parsed as
a type and the name of a struct is an identifier. Spacth doesn't allow
you to put a type in a position where an identifier is expected.
Nicolas' code, however, gets around the problem by using python to
generate new semantic patches. In the new semantic patch, the typedef
name is just a constant, and thus parsed as convenient for the position in
which it appears (once as a type name and once as a struct name).
More information about the devel