Sophie

Sophie

distrib > Fedora > 15 > i386 > by-pkgid > ba8689ef46129012bc8659c99e8e1650 > files > 33

coccinelle-doc-1.0.0-0.rc4.2.fc15.i686.rpm


\section{Tips and Tricks}

\subsection{How to remove useless parentheses?}

If you want to rewrite any access to a pointer value by a function
call, you may use the following semantic patch.

\begin{lstlisting}[language=Cocci]
@-- a = *b
@++ a = readb(b)
\end{lstlisting}

However, if for some reason your code looks like \verb|bar = *(foo)|,
you will end up with \verb|bar = readb((foo))| as the extra
parentheses around \texttt{foo} are capture by the metavariable
\texttt{b}.

In order to generate better output code, you can use the following
semantic patch instead.
\begin{lstlisting}[language=Cocci]
@-- a = *(b)
@++ a = readb(b)
\end{lstlisting}

\noindent
And rely on your standard.iso isomorphism file which should contain:
\begin{lstlisting}[language=Cocci]
Expression
@ paren @
expression E;
@@

 (E) => E
\end{lstlisting}

Coccinelle will then consider \verb|bar = *(foo)| as equivalent to
\verb|bar = *foo| (but not the other way around) and capture both.
Finally, it will generate \verb|bar = readb(foo)| as expected.

%%% Local Variables:
%%% mode: LaTeX
%%% TeX-master: "main_grammar"
%%% coding: utf-8
%%% TeX-PDF-mode: t
%%% ispell-local-dictionary: "american"
%%% End: