Commit | Line | Data |
---|---|---|
0708f913 C |
1 | |
2 | \section{Tips and Tricks} | |
3 | ||
4 | \subsection{How to remove useless parentheses?} | |
5 | ||
6 | If you want to rewrite any access to a pointer value by a function | |
7 | call, you may use the following semantic patch. | |
8 | ||
9 | \begin{lstlisting}[language=Cocci] | |
10 | @-- a = *b | |
11 | @++ a = readb(b) | |
12 | \end{lstlisting} | |
13 | ||
14 | However, if for some reason your code looks like \verb|bar = *(foo)|, | |
15 | you will end up with \verb|bar = readb((foo))| as the extra | |
16 | parentheses around \texttt{foo} are capture by the metavariable | |
17 | \texttt{b}. | |
18 | ||
19 | In order to generate better output code, you can use the following | |
20 | semantic patch instead. | |
21 | \begin{lstlisting}[language=Cocci] | |
22 | @-- a = *(b) | |
23 | @++ a = readb(b) | |
24 | \end{lstlisting} | |
25 | ||
26 | \noindent | |
27 | And rely on your standard.iso isomorphism file which should contain: | |
28 | \begin{lstlisting}[language=Cocci] | |
29 | Expression | |
30 | @ paren @ | |
31 | expression E; | |
32 | @@ | |
33 | ||
34 | (E) => E | |
35 | \end{lstlisting} | |
36 | ||
37 | Coccinelle will then consider \verb|bar = *(foo)| as equivalent to | |
38 | \verb|bar = *foo| (but not the other way around) and capture both. | |
39 | Finally, it will generate \verb|bar = readb(foo)| as expected. | |
40 | ||
41 | %%% Local Variables: | |
42 | %%% mode: LaTeX | |
43 | %%% TeX-master: "cocci_syntax" | |
44 | %%% coding: latin-9 | |
45 | %%% TeX-PDF-mode: t | |
46 | %%% ispell-local-dictionary: "american" | |
47 | %%% End: |