abc.weaving.aspectinfo
Class Unification

java.lang.Object
  extended by abc.weaving.aspectinfo.Unification

public class Unification
extends java.lang.Object

A class for representing the unification of two Syntax objects. Two such objects s1 and s2 are unifiable if there is a syntax object s and two renamings ren1, ren2 such that ren1(s)=s1, ren2(s)=s2. In general we can replace = by 'equivalent to'. Specifically s can have more free vars than s1 or s2. In this case some vars in s are mapped to an empty VarBox by one of the renamings ren1, ren2.

This class encapsulates the renamings ren1, ren2, as well as the result s. In addition, two typemaps are stored, to give the types of free vars occurring in s1, s2 (to prevent variables of different types from being unified).

A number of special case methods are defined to get and set the Syntax result when its type is known, in particular Pointcut. A number of methods provide access to the renamings and the typemaps. The class does NOT perform unification, it just holds renamings etc in a convenient form. Most methods are duplicated for convenience, one copy for each renaming

Finally, this class contains the unifyWithFirst() property. If this is true, then the intention is that the unification to be performed should return as result s=s1, the first of the two Syntax objects. In this case unification reduces to renaming. When this holds the result value should be set to the same reference as s1, not just an equivalent syntax object. For brevity we refer to this as restricted unification.

Author:
Damien Sereni
See Also:
VarBox

Constructor Summary
Unification(boolean unifyWithFirst)
           
 
Method Summary
 void clearUnifyWithFirst()
          Set the unifyWithFirst() property to false.
 boolean containsKey1(Var key)
          Tests whether the first renaming contains a variable as a key
 boolean containsKey2(Var key)
          Tests whether the second renaming contains a variable as a key
 boolean containsKeyAsString1(java.lang.String s)
          Tests whether the first renaming contains this key, identified by its name
 boolean containsKeyAsString2(java.lang.String s)
          Tests whether the second renaming contains this key, identified by its name
 boolean containsValue1(VarBox val)
          Tests whether the first renaming contains a VarBox as a value
 boolean containsValue2(VarBox val)
          Tests whether the second renaming contains a VarBox as a value
 boolean containsVarValue1(Var v)
          Test whether ren1 contains a key mapping to v (ie mapping to a VarBox containing v)
 boolean containsVarValue2(Var v)
          Test whether ren2 contains a key mapping to v (ie mapping to a VarBox containing v)
 VarBox get1(Var key)
          Get the VarBox associated with a Var under the first renaming
 VarBox get2(Var key)
          Get the VarBox associated with a Var under the second renaming
 ArgPattern getArgPattern()
          Returns the result of unification as an ArgPattern
 Var getByValue1(VarBox val)
          Get the key mapping to a value in ren1, null if there is none
 Var getByValue2(VarBox val)
          Get the key mapping to a value in ren2, null if there is none
 Var getByVarValue1(Var v)
          Get the key mapping to a Var value in ren1, null if there is none
 Var getByVarValue2(Var v)
          Get the key mapping to a Var value in ren2, null if there is none
 VarBox getFromString1(java.lang.String s)
          Get the VarBox bound to a variable of this name (if any, null otherwise) under ren1
 VarBox getFromString2(java.lang.String s)
          Get the VarBox bound to a variable of this name (if any, null otherwise) under ren2
 Pointcut getPointcut()
          Returns the result of unification as a Pointcut
 java.util.Hashtable getRen1()
          Returns the renaming ren1 taking the result s to the first syntax s1
 java.util.Hashtable getRen2()
          Returns the renaming ren2 taking the result s to the first syntax s2
 Syntax getSyntax()
          Returns the result of unification.
 AbcType getType1(java.lang.String s)
          Returns the type of a given free var in the first typemap
 AbcType getType2(java.lang.String s)
          Returns the type of a given free var in the second typemap
 java.util.Hashtable getTypeMap(int dir)
          Returns the typemap assigning types to free vars in either syntax object, depending on dir
 java.util.Hashtable getTypeMap1()
          Returns the typemap assigning types to free vars in the first syntax object s1
 java.util.Hashtable getTypeMap2()
          Returns the typemap assigning types to free vars in the second syntax object s2
 Var getVar()
          Returns the result of unification as a Var
 boolean isTargetSet1(Var v)
          Tests whether the VarBox that v maps to under ren1 contains a variable
 boolean isTargetSet2(Var v)
          Tests whether the VarBox that v maps to under ren2 contains a variable
 java.util.Enumeration keys1()
          The keys in the first renaming
 java.util.Enumeration keys2()
          The keys in the second renaming
 void put1(Var key, VarBox val)
          Add a binding in the first renaming
 void put2(Var key, VarBox val)
          Add a binding in the second renaming
 void putVar1(Var key, Var val)
          Add a binding in the first renaming.
 void putVar2(Var key, Var val)
          Add a binding in the second renaming.
 void removeTargetAsString(int dir, java.lang.String s)
          Remove the target of a binding by its string name from the specified renaming.
 void removeTargetAsString1(java.lang.String s)
          Remove the target of a binding by its string name.
 void removeTargetAsString2(java.lang.String s)
          Remove the target of a binding by its string name.
 void resetBindings()
          Reset the bindings (and the result) of unification BUT does not reset the typemaps
 void setArgPattern(ArgPattern p)
          Sets the result of unification to the ArgPattern p
 void setPointcut(Pointcut pc)
          Sets the result of unification to the pointcut pc
 void setSyntax(Syntax s)
          Sets the result of unification to s (instanceof Syntax)
 void setTypeMap1(java.util.Hashtable typeMap)
          Sets the typemap assigning types to free vars in the first syntax object s1
 void setTypeMap2(java.util.Hashtable typeMap)
          Sets the typemap assigning types to free vars in the second syntax object s2
 void setUnifyWithFirst()
          Set the unifyWithFirst() property to true.
 void setVar(Var v)
          Sets the result of unification to the variable v
 boolean unifyWithFirst()
          Returns true if restricted unification is to be done.
 java.util.Collection values1()
          The values in the first renaming
 java.util.Collection values2()
          The values in the second renaming
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Unification

public Unification(boolean unifyWithFirst)
Method Detail

resetBindings

public void resetBindings()
Reset the bindings (and the result) of unification BUT does not reset the typemaps


setUnifyWithFirst

public void setUnifyWithFirst()
Set the unifyWithFirst() property to true. This signals that restricted unification (where the result is constrained to be the first term) should be performed.


clearUnifyWithFirst

public void clearUnifyWithFirst()
Set the unifyWithFirst() property to false. This signals that general (unrestricted) unification should be performed.


unifyWithFirst

public boolean unifyWithFirst()
Returns true if restricted unification is to be done. In that case, the RESULT of unification (s say) should always be == to the FIRST Syntax object in the unification. Unification then reduces to renaming s1 to s2


getPointcut

public Pointcut getPointcut()
Returns the result of unification as a Pointcut


getArgPattern

public ArgPattern getArgPattern()
Returns the result of unification as an ArgPattern


getVar

public Var getVar()
Returns the result of unification as a Var


getSyntax

public Syntax getSyntax()
Returns the result of unification. This is a Syntax object


getRen1

public java.util.Hashtable getRen1()
Returns the renaming ren1 taking the result s to the first syntax s1

Returns:
The renaming Var->VarBox taking s to s1

getRen2

public java.util.Hashtable getRen2()
Returns the renaming ren2 taking the result s to the first syntax s2

Returns:
The renaming Var->VarBox taking s to s2

setPointcut

public void setPointcut(Pointcut pc)
Sets the result of unification to the pointcut pc

Parameters:
pc - the Pointcut result of unification

setVar

public void setVar(Var v)
Sets the result of unification to the variable v

Parameters:
v - the Var result of unification

setArgPattern

public void setArgPattern(ArgPattern p)
Sets the result of unification to the ArgPattern p

Parameters:
p - the ArgPattern result of unification

setSyntax

public void setSyntax(Syntax s)
Sets the result of unification to s (instanceof Syntax)

Parameters:
s - the result of unification, of type Syntax

setTypeMap1

public void setTypeMap1(java.util.Hashtable typeMap)
Sets the typemap assigning types to free vars in the first syntax object s1

Parameters:
typeMap - a mapping String->AbcType giving types to free vars in s1

setTypeMap2

public void setTypeMap2(java.util.Hashtable typeMap)
Sets the typemap assigning types to free vars in the second syntax object s2

Parameters:
typeMap - a mapping String->AbcType giving types to free vars in s2

getTypeMap1

public java.util.Hashtable getTypeMap1()
Returns the typemap assigning types to free vars in the first syntax object s1

Returns:
the mapping String->AbcType giving types to free vars in s1

getTypeMap2

public java.util.Hashtable getTypeMap2()
Returns the typemap assigning types to free vars in the second syntax object s2

Returns:
the mapping String->AbcType giving types to free vars in s2

getTypeMap

public java.util.Hashtable getTypeMap(int dir)
Returns the typemap assigning types to free vars in either syntax object, depending on dir

Parameters:
dir - 1 for the first syntax object, 2 for the second syntax object
Returns:
the mapping String->AbcType giving types to free vars in the relevant syntax object

getType1

public AbcType getType1(java.lang.String s)
Returns the type of a given free var in the first typemap

Parameters:
s - the name of a free variable in the first Syntax
Returns:
the type of s

getType2

public AbcType getType2(java.lang.String s)
Returns the type of a given free var in the second typemap

Parameters:
s - the name of a free variable in the second Syntax
Returns:
the type of s

keys1

public java.util.Enumeration keys1()
The keys in the first renaming

Returns:
an Enumeration: the keys of the first renaming

keys2

public java.util.Enumeration keys2()
The keys in the second renaming

Returns:
an Enumeration: the keys of the second renaming

values1

public java.util.Collection values1()
The values in the first renaming

Returns:
a Collection: the values in the first renaming

values2

public java.util.Collection values2()
The values in the second renaming

Returns:
a Collection: the values in the second renaming

containsKey1

public boolean containsKey1(Var key)
Tests whether the first renaming contains a variable as a key

Parameters:
key - the variable to test for membership as a key
Returns:
true if key occurs as a key in ren1

containsKey2

public boolean containsKey2(Var key)
Tests whether the second renaming contains a variable as a key

Parameters:
key - the variable to test for membership as a key
Returns:
true if key occurs as a key in ren2

containsValue1

public boolean containsValue1(VarBox val)
Tests whether the first renaming contains a VarBox as a value

Parameters:
val - the VarBox to test for membership as a value
Returns:
true if val occurs as a value in ren1

containsValue2

public boolean containsValue2(VarBox val)
Tests whether the second renaming contains a VarBox as a value

Parameters:
val - the VarBox to test for membership as a value
Returns:
true if val occurs as a value in ren2

get1

public VarBox get1(Var key)
Get the VarBox associated with a Var under the first renaming

Parameters:
key - the Var to get the associated value for
Returns:
the VarBox to which key maps, null if none

get2

public VarBox get2(Var key)
Get the VarBox associated with a Var under the second renaming

Parameters:
key - the Var to get the associated value for
Returns:
the VarBox to which key maps, null if none

put1

public void put1(Var key,
                 VarBox val)
Add a binding in the first renaming

Parameters:
key - the Var to bind under ren1
val - the VarBox to bind key to

put2

public void put2(Var key,
                 VarBox val)
Add a binding in the second renaming

Parameters:
key - the Var to bind under ren2
val - the VarBox to bind key to

putVar1

public void putVar1(Var key,
                    Var val)
Add a binding in the first renaming. Binds a Var to a Var, creating the appropriate VarBox

Parameters:
key - the Var to bind under ren1
val - the Var to bind key to

putVar2

public void putVar2(Var key,
                    Var val)
Add a binding in the second renaming. Binds a Var to a Var, creating the appropriate VarBox

Parameters:
key - the Var to bind under ren2
val - the Var to bind key to

getByValue1

public Var getByValue1(VarBox val)
Get the key mapping to a value in ren1, null if there is none

Parameters:
val - the value to find a key in ren1 for
Returns:
a Var v such that get1(v) = val, null if no such v exists

getByValue2

public Var getByValue2(VarBox val)
Get the key mapping to a value in ren2, null if there is none

Parameters:
val - the value to find a key in ren2 for
Returns:
a Var v such that get2(v) = val, null if no such v exists

containsVarValue1

public boolean containsVarValue1(Var v)
Test whether ren1 contains a key mapping to v (ie mapping to a VarBox containing v)

Parameters:
v - the Var to find as a value in ren1
true - if ren1 contains a key mapping to a VarBox containing v, false otherwise

containsVarValue2

public boolean containsVarValue2(Var v)
Test whether ren2 contains a key mapping to v (ie mapping to a VarBox containing v)

Parameters:
v - the Var to find as a value in ren2
true - if ren2 contains a key mapping to a VarBox containing v, false otherwise

getByVarValue1

public Var getByVarValue1(Var v)
Get the key mapping to a Var value in ren1, null if there is none

Parameters:
val - the Var value to find a key in ren1 for
Returns:
a Var v such that get1(v) is a VarBox containing val, null if no such v exists

getByVarValue2

public Var getByVarValue2(Var v)
Get the key mapping to a Var value in ren2, null if there is none

Parameters:
val - the Var value to find a key in ren2 for
Returns:
a Var v such that get2(v) is a VarBox containing val, null if no such v exists

removeTargetAsString

public void removeTargetAsString(int dir,
                                 java.lang.String s)
Remove the target of a binding by its string name from the specified renaming. If some var with name s is bound by the renaming, the VarBox it is bound to is cleared of it variable. NOTE that this does not remove any bindings from the renaming, it merely transforms an existing binding into a binding of the form v -> (an empty VarBox)

Parameters:
dir - 1 to specify the first renaming, 2 for the second renaming
s - the name of the variable (key) to remove the target binding for.

removeTargetAsString1

public void removeTargetAsString1(java.lang.String s)
Remove the target of a binding by its string name. Equivalent to removeTargetAsString(1,s)

See Also:
removeTargetAsString

removeTargetAsString2

public void removeTargetAsString2(java.lang.String s)
Remove the target of a binding by its string name. Equivalent to removeTargetAsString(2,s)

See Also:
removeTargetAsString

containsKeyAsString1

public boolean containsKeyAsString1(java.lang.String s)
Tests whether the first renaming contains this key, identified by its name

Parameters:
s - the name of a Var to look for as a key
Returns:
true if ren1 contains a key with name s

containsKeyAsString2

public boolean containsKeyAsString2(java.lang.String s)
Tests whether the second renaming contains this key, identified by its name

Parameters:
s - the name of a Var to look for as a key
Returns:
true if ren2 contains a key with name s

getFromString1

public VarBox getFromString1(java.lang.String s)
Get the VarBox bound to a variable of this name (if any, null otherwise) under ren1

Parameters:
s - the name of the variable used as a key
Returns:
the VarBox that a variable with name s is bound to under ren1, null if no such

getFromString2

public VarBox getFromString2(java.lang.String s)
Get the VarBox bound to a variable of this name (if any, null otherwise) under ren2

Parameters:
s - the name of the variable used as a key
Returns:
the VarBox that a variable with name s is bound to under ren2, null if no such

isTargetSet1

public boolean isTargetSet1(Var v)
Tests whether the VarBox that v maps to under ren1 contains a variable

Parameters:
v - the Var to get the binding from ren1 for. NOTE that this assumes that v is bound to a value by ren1
Returns:
true if get1(v) contains a Var, false otherwise

isTargetSet2

public boolean isTargetSet2(Var v)
Tests whether the VarBox that v maps to under ren2 contains a variable

Parameters:
v - the Var to get the binding from ren1 for. NOTE that this assumes that v is bound to a value by ren2
Returns:
true if get2(v) contains a Var, false otherwise