abc.weaving.aspectinfo
Class Pointcut

java.lang.Object
  extended by abc.weaving.aspectinfo.Syntax
      extended by abc.weaving.aspectinfo.Pointcut
Direct Known Subclasses:
AndPointcut, CastPointcutVar, CflowPointcut, DynamicValuePointcut, If, LexicalPointcut, LocalPointcutVars, NotPointcut, OrPointcut, PointcutRef, ShadowPointcut

public abstract class Pointcut
extends Syntax

This is the base class for pointcut designators; it is constructed by the frontend. A pointcut designator is primarily responsible for calculating the residue for itself at a given join point shadow.

Author:
Ganesh Sittampalam

Nested Class Summary
protected static class Pointcut.DNF
          This class is used to calculate the disjunctive normal form of pointcuts.
 
Constructor Summary
Pointcut(Position pos)
           
 
Method Summary
protected  Pointcut.DNF dnf()
          Return the DNF form of this pointcut.
static java.lang.String freshVar()
          Return a freshly named pointcut variable
abstract  void getFreeVars(java.util.Set result)
          Get a list of free variables bound by this pointcut
protected abstract  Pointcut inline(java.util.Hashtable renameEnv, java.util.Hashtable typeEnv, Aspect context, int cflowdepth)
          Inlining should remove all PointcutRefs, and return a pointcut that is alpha-renamed
abstract  Residue matchesAt(WeavingEnv env, SootClass cls, SootMethod method, ShadowMatch sm)
          Given a context and weaving environment, produce a residue
static Pointcut normalize(Pointcut pc, java.util.List formals, Aspect context)
          Return a "normalized" version of this pointcut.
protected abstract  void registerSetupAdvice(Aspect context, java.util.Hashtable typeEnv)
          If any synthetic advice is required to implement this pointcut, this method should take care of adding it.
abstract  java.lang.String toString()
          Subclasses must define toString, for debugging purposes
 boolean unify(Pointcut otherpc, Unification unification)
          Attempt to unify two pointcuts. pc.unify(pc', unification) should return true if the pointcuts can be unified, and set the renamings appropriately in unification.
 
Methods inherited from class abc.weaving.aspectinfo.Syntax
getPosition
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Pointcut

public Pointcut(Position pos)
Parameters:
The - source position of the pointcut
Method Detail

toString

public abstract java.lang.String toString()
Subclasses must define toString, for debugging purposes

Overrides:
toString in class java.lang.Object

matchesAt

public abstract Residue matchesAt(WeavingEnv env,
                                  SootClass cls,
                                  SootMethod method,
                                  ShadowMatch sm)
                           throws SemanticException
Given a context and weaving environment, produce a residue

Throws:
SemanticException

normalize

public static Pointcut normalize(Pointcut pc,
                                 java.util.List formals,
                                 Aspect context)
Return a "normalized" version of this pointcut. The result has the following properties:

Parameters:
pc - The pointcut to normalize
formals - A list of Formals that are in scope for this pointcut
context - The aspect in which the pointcut occurs
Returns:
The normalized pointcut

dnf

protected Pointcut.DNF dnf()
Return the DNF form of this pointcut. For pointcuts without children this default implementation is fine; for pointcuts with children it should be overridden so that at the very least the children are converted to DNF.


inline

protected abstract Pointcut inline(java.util.Hashtable renameEnv,
                                   java.util.Hashtable typeEnv,
                                   Aspect context,
                                   int cflowdepth)
Inlining should remove all PointcutRefs, and return a pointcut that is alpha-renamed

Parameters:
renameEnv - A mapping from pointcut names to the Vars they should be renamed to. If a name isn't in the map, it doesn't need to be renamed.
typeEnv - A mapping from pointcut names to AbcTypes. Every variable that can appear free in the pointcut must be listed. The names are those before any renaming takes place.
context - The Aspect in which the root pointcut is defined. This is required because references to abstract pointcuts must be resolved to the concrete pointcut using this aspect.
cflowdepth - The number of surrounding cflows. This is required to determine the correct precedence for the synthetic advice used to implement cflow.
Returns:
The inlined pointcut

freshVar

public static java.lang.String freshVar()
Return a freshly named pointcut variable


registerSetupAdvice

protected abstract void registerSetupAdvice(Aspect context,
                                            java.util.Hashtable typeEnv)
If any synthetic advice is required to implement this pointcut, this method should take care of adding it.

Parameters:
context - The aspect in which the pointcut is defined
typeEnv - A mapping from formal name to AbcType for all the formal parameters to the pointcut

getFreeVars

public abstract void getFreeVars(java.util.Set result)
Get a list of free variables bound by this pointcut

Parameters:
result - The results should be placed in this set (having it as a parameter allows it to be built up incrementally, which is more efficient than repeatedly taking the union of sets)

unify

public boolean unify(Pointcut otherpc,
                     Unification unification)
Attempt to unify two pointcuts. pc.unify(pc', unification) should return true if the pointcuts can be unified, and set the renamings appropriately in unification. There are two cases for unification: if unification.unifyWithFirst() is true, then the unification should only succeed if this pc can be renamed to pc', with the unification pointcut equal to this. Otherwise, the unification pointcut can be anything, as long as it can be renamed both to this and pc'.

A default implementation is provided, but all subclasses should override this - otherwise cflow CSE will be disabled for cflow that use these pointcuts.

Typical implementations for pointcuts that introduce no free variables are straightforward (see the And pointcut, for example). For pointcuts that introduce free variables, the Var.unify method is used to actually update the renamings (see the Args pointcut).

Parameters:
otherpc - the pointcut that should be unify with this
unification - the Unification that should be set.
Returns:
true iff the unification is succesful. If true is returned, then Unification.setPointcut(the unified pointcut) must have been called in the body of unify().
See Also:
AndPointcut.unify example, Var.unify, Unification