[cocci] Matching function pointer casts
Mathias Krause <[email protected]>
| Newsgroups | fr.inria.cocci |
|---|---|
| Message-ID | <[email protected]> |
Hi, I have a hard time trying to come up with a semantic patch that would match function pointer casts, specifically (void (*)(void)) in my case. I want to get rid of these and replace them with a properly typed functions that'd do necessary type conversions. (I already have that part, though.) Below are two attempts I tried and did not work; 1. @pfunc_cast@ identifier fn; fresh identifier fnthunk = "THUNK_" ## fn; @@ - (void (*)(void)) &fn + &fnthunk Above doesn't parse for me (spatch version 1.1.0). 2. @pfunc_cast@ identifier fn; fresh identifier fnthunk = "THUNK_" ## fn; type T =~ "^void (*)(void)$"; @@ - (T) &fn + &fnthunk as well as 3. @pfunc_cast@ identifier fn; fresh identifier fnthunk = "THUNK_" ## fn; type T =~ "void \\(*\\)\\(void\\)"; @@ - (T) &fn + &fnthunk This basically matches all address taking expressions, even without casts, and replaces them by &THUNK_... -- not quite what I want. ;) It looks like to completely ignoring the regular expression for the type match beside complaining about syntax errors when one does some? Is there a way to match function pointer casts in spatch at all? Thanks, Mathias