| 1 |
%% LaTeX2e file `tmp-gen-recursive-with-bug.tex' |
| 2 |
%% generated by the `filecontents' environment |
| 3 |
%% from source `codeanatomy.lstlisting' on 2025/10/19. |
| 4 |
%% |
| 5 |
\tikzstyle{token} = [code part, fill=yellow] |
| 6 |
\tikzstyle{bug} = [code part, fill=red!50] |
| 7 |
\begin{lrbox}{\mycodebox} |
| 8 |
\lstset{ |
| 9 |
escapeinside={!}{!} |
| 10 |
,basicstyle=\linespread{1.8} |
| 11 |
} |
| 12 |
\begin{lstlisting}[basicstyle=\small\ttfamily] |
| 13 |
function !\cPart[token]{fnName}{gcd}! (p,q) { |
| 14 |
if (q === 0) { |
| 15 |
return !\cPart[bug]{bug}{q}!; |
| 16 |
} else { |
| 17 |
let r = p % q; |
| 18 |
return !\cPart[token]{recursive}{gcd}!(q, r); |
| 19 |
} |
| 20 |
} |
| 21 |
\end{lstlisting} |
| 22 |
\end{lrbox} |
| 23 |
|
| 24 |
\begin{tikzpicture}[remember picture] |
| 25 |
\node(code) [anatomy] at (0,0) {\usebox\mycodebox}; |
| 26 |
|
| 27 |
\codeAnnotation{recursiveText} (-1,2) {Function can\\call itself.} |
| 28 |
\codeAnnotation{bugText} ( 5,2.25) {This is\\the bug.} |
| 29 |
|
| 30 |
\draw[->, annotation] (recursiveText) to[out=50, in=190] (fnName); |
| 31 |
\draw[->, annotation] (recursiveText) to[out=-20, in=175] (recursive.north west); |
| 32 |
\draw[->, annotation] (bugText) to[out=190,in=-20] (bug.south east); |
| 33 |
\end{tikzpicture} |