Small Example

In Figure 9, we present an example of an aspect, which counts all the function calls made with at least two arguments. To do so, we need to have a $call$ pattern to capture all such calls. The $mainexecution$ pattern is used to display the number of calls made at the end of the program.

Figure 9: Aspect to count all calls made with at least 2 arguments
\begin{figure}\begin{lstlisting}[language=MATLAB, frame=htbp]
aspect myAspect
\p...
...str(total)]);
end
end %actions
\par
end %myAspect
\end{lstlisting}
\end{figure}

To demonstrate the application of the aspect from Figure 9, consider a small base program consisting of the simple MATLAB function given in Figure 10.

Figure 10: Simple MATLAB Function
\begin{figure}\begin{lstlisting}[language=MATLAB, frame=htbp]
function [m, s, d]...
...ics
m = mean(y);
s = std(y);
d = median(y);
end
\end{lstlisting}
\end{figure}

The function histo takes one input argument n and returns three values m,s,d. Values are returned by declaring variables to be return parameters in the function header, then assigning these variables a value. This function first generates some random-sized vectors, then calls several MATLAB functions to generate a histogram, and finally computes some basic statistics.

Once compiled along with the aspect presented in Figure 9, pattern call2args finds only three matching join points (at lines 5, 6 and 9) where the function calls carry two arguments each. So, corresponding action function calls will be woven only at those program points. Note that the function calls with a single input argument (at lines 11, 12 and 13) do not match. Moreover, the action actexecution is an $after$ action, so it will be woven at the end of the function.

Toheed ASLAM 2010-04-24