[Cocci] Whole-directory handling not functional?

Carl-Daniel Hailfinger c-d.hailfinger.devel.2006 at gmx.net
Fri Mar 6 23:18:58 CET 2009


Hi,

to solve a naming collision, I want to rename every call to
{read,write}[bwl] with chip_{read,write}[bwl] and functions with these
names in the header file should be renamed as well.

The sed script to solve this is "s/\(read\|write\)\([bwl](\)/chip_\1\2/"
but that has no type checking nor can it handle unexpected whitespace.
It's rather short, though.

Function signatures:
static inline void writeb(uint8_t b, volatile void *addr)
static inline void writew(uint16_t b, volatile void *addr)
static inline void writel(uint32_t b, volatile void *addr)
static inline uint8_t readb(const volatile void *addr)
static inline uint16_t readw(const volatile void *addr)
static inline uint32_t readl(const volatile void *addr)

There's probably a more correct and efficient variant of the following
semantic patch. For starters, I didn't yet match on the correct function
signature. The patch was written before you told me about the cool
feature of matching multiple variable types with the {uint8_t,
uint16_t}syntax.
@@
typedef uint8_t;
typedef uint16_t;
typedef uint32_t;
@@
- writeb
+ chip_writeb
@@
@@
- writew
+ chip_writew
@@
@@
- writel
+ chip_writel
@@
@@
- readb
+ chip_readb
@@
@@
- readw
+ chip_readw
@@
@@
- readl
+ chip_readl

There are two small speedbumps I encountered when trying the patch above:

This command processes all files, but does nothing:
spatch -noif0_passing -inplace -cocci_file
cocci/renamechipaccessors.cocci -dir .

These command processes all files, but it converts only .c files and
leaves the function defined in the header file unchanged:
spatch -noif0_passing -inplace -cocci_file
cocci/renamechipaccessors.cocci *.[ch]
spatch -noif0_passing -inplace -include_headers -cocci_file
cocci/renamechipaccessors.cocci *.[ch]
spatch -noif0_passing -inplace -include_headers -I . -cocci_file
cocci/renamechipaccessors.cocci *.[ch]
spatch -noif0_passing -inplace -include_headers -I . -all_includes
-cocci_file cocci/renamechipaccessors.cocci *.[ch]

Hints about why this happens are welcome. The header files and the .c
files are all in one common directory. There are no subdirectories.


Regards,
Carl-Daniel


More information about the Cocci mailing list