how to write an spatch in order to replace guard vs #prama once
Hello,
I am trying to write an spatch in order to replace in my code, the header guard, by the #pragma once.
Is there somewhere a repository of spatches, where I can inspire myself ?
thanks for your help
Frederic
Quoted 5 lines · PICCA Frederic-Emmanuel
Hello,
I am trying to write an spatch in order to replace in my code, the header guard, by the #pragma once.
Is there somewhere a repository of spatches, where I can inspire myself ?
Could you make a small example of what you are trying to do?
There is this page, but I don't know if it has examples related to #pragma,
julia
something like this
// replace guard by pragma once
@@
expression E;
@@
-#ifndef E
-#define E
+#pragma once
...
-#endif
where the #endif is the matching one of the first #ifndef
Fred
Quoted 18 lines · PICCA Frederic-Emmanuel
something like this
// replace guard by pragma once
@@
expression E;
@@(quoted diff) +1
-3-#ifndef E -#define E +#pragma once -#endif
Quoted 1 line
where the #endif is the matching one of the first #ifndef
I'm sorry, but I doubt that it will be possible. The treatment of #ifdef etc is quite limited, and there is nothing to match the #ifndef up to the corresponding #endif. Coccinelle parses the source code, and these preprocessor options can appear in places that don't really follow the parse tree structure.
julia
Quoted 5 lines
I'm sorry, but I doubt that it will be possible. The treatment of #ifdef etc is quite limited, and there is nothing to match the #ifndef up to the corresponding #endif. Coccinelle parses the source code, and these preprocessor options can appear in places that don't really follow the parse tree structure.
snif ;)
have a good end of day.
Fred
Quoted 18 lines
something like this
// replace guard by pragma once
@@
expression E;
@@(quoted diff) +1
-3-#ifndef E -#define E +#pragma once -#endif
Quoted 1 line
where the #endif is the matching one of the first #ifndef
There are several software development challenges involved so far for such a source code transformation.
I am unsure under which circumstances the corresponding support can grow also for preprocessor directives.
Regards,
Markus