Array Patterns

AspectJ provides array pointcuts functionality. However, the pointcuts of AspectJ do not support array objects in full. When an element of an array object is set or referenced, the corresponding index values and the assigned value are not exposed to the advice. AspectJ was extended to add array pointcuts but these extensions either just work for one-dimensional arrays or they force programmers to use other pointcuts in order to be able to perform selective matching and to fetch context information.

AspectMatlab provides simple, yet powerful, patterns to capture array accesses, $get$ and $set$. As shown is Figure 4, the first assignment statement is a $set$ join point where arr1 is being assigned a new value. The second statement is also a $set$ join point for arr2, but the right hand side actually reads arr1. So the right hand side of the second assignment statement is a $get$ join point.

Figure 4: Array Join Points
\includegraphics[width=2.5in]{images/array.eps}

Figure 5 shows an example of a more complicated $get$ match. Here we have array accesses within another array access and we have to sort out the order in which all these join points are matched. We decided to follow the evaluation order of an expression, where all the sub-expressions are evaluated before the containing expression. So, the first $get$ join point in the second assigment statement is the access of x, followed by the second $get$ join point for y and finally, the third $get$ join point is the whole right hand side.

Figure 5: Array Join Points - Order
\includegraphics[width=3in]{images/array2.eps}

Examples of array patterns are given in Listing 4. Pattern pGetX matches all the join points in the source code where any array or MATLAB matrix access operation is performed. Similarly, all the write operations on the arrays can be captured using pattern pSetX.


\begin{lstlisting}[language=MATLAB, frame=htbp, caption={Array Patterns}, label=ex:arraypat]
patterns
pGetX : get(*);
pSetX : set(*);
end
\end{lstlisting}

Toheed ASLAM 2010-04-24