On Sun, 5 Jan 2020, Markus Elfring wrote: > > I would prefer that the macros were written with the do-while pattern, > > but it's a legacy codebase that uses HGOTO_ERROR() no fewer than 12,000 > > times, and most occurrences have no semicolon. I will have to automate > > the conversion, and I guess that I cannot use spatch to do it. > > Would you like to try out how good semicolons can be added behind > these macro calls by a small script for the semantic patch language?
The problem is that the arguemnt list is considered to be comments. THere is no way to specify to put a semicolon at the end of a comment. The only short term suggestion I have is the following: @r@ statement s : script:ocaml() { List.hd (Str.split (Str.regexp " *(") s) = "ASSERT" }; statement s1,s2; position p1; @@ s s1@p1 @@ statement r.s1; position r.p1; @@ +; s1@p1 ------------------- This uses ASSERT as an example, because standard.h already contains #define ASSERT(x) MACROSTATEMENT It uses a regular expression to detect that a statement starts with the word ASSERT, and matches the next statement as well, and then in another rule adds a ; before the subsequent statement. If you add the ; after the ASSERT statement it comes out after ASSERT, not after the commented argument list. But with this semantic patch, the ; comes out on a line of its own, and would have to be moved up manually. So I don't know if that gives any real benefit. It obviously also doesn't work if the ASSERT is at the end of a function. julia _______________________________________________ Cocci mailing list Cocci@systeme.lip6.fr https://systeme.lip6.fr/mailman/listinfo/cocci