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