Selective Matching

As compared to other aspect-oriented languages, AspectMatlab eliminates the need of a separate pattern for capturing arrays and then using another pattern to specialize the matching. In MATLAB a function call does not necessarily have to provide exactly as many arguments as specified in a function signature. Also in the case of array operations, subarrays can be accessed by providing fewer dimensions than the actual dimensions of an array.

Moreover, the syntax to make a function/script call and array access in MATLAB is the same. So the pattern specification grammar was enriched to incorporate matching based upon the number of arguments involved. Section 2.2.1 and Section 2.2.2 describe simple function and array-related patterns. In this section, we provide examples of more selective matching.

As shown in the Listing 5, pattern call2args will match all calls, but only the ones made with two or more parameters, thus ignoring the calls with one or no parameters. If we want to match on all the arrays which are being initialized or replaced completely, pattern fullSet will help us achieve that.


\begin{lstlisting}[language=MATLAB, frame=htbp, caption={Selective Matching}, la...
...]
patterns
call2args : call(*(*,..));
fullSet : set(*());
end
\end{lstlisting}

AspectJ also provides this facility of selective matching, but it uses separate notations for different pointcuts. The MATLAB syntax allows us to come up with a general matching notation applicable for both call/execution and get/set patterns. A list of possible use cases of such matching for the call pattern is given in Table II.


Table II: Selective Pattern Matching
call(foo) matches all calls to foo (function or script)
call(foo()) matches calls with no arguments (function or script)
call(foo(*)) matches calls with exactly one argument (function only)
call(foo(..)) matches calls with 1 or more argument(s) (function only)
call(foo(*,..)) matches calls with 2 or more arguments (function only)
  ...and so on
set(arr) matches all assignments to arr
set(arr()) matches assignments with no indices
set(arr(*)) matches assignments with exactly one index
set(arr(..)) matches assignments with 1 or more index/indices
set(arr(*,..)) matches assignments with 2 or more indices
  ...and so on
 


Toheed ASLAM 2010-04-24