dk.brics.string.intermediate
Class Method

java.lang.Object
  extended by dk.brics.string.intermediate.Method

public class Method
extends Object

A Java method.

A method has a body consisting of a list of statements, the first of which is called the entry statement. The statements are connected by control flow edges, forming a directed graph.

The method's parameters are each represented by two variables: One referred to as the parameter, and one referred to as the parameter alias. When the body of a method assigns a new value to a parameter, it is the alias whose value is changed, such that the parameter variables always remember the original arguments to the method. The idea behind this is best illustrated with an example. Consider this small program:

 void foo(StringBuffer a) {
     a = new StringBuffer;
     corrupt a;
     return;
 }
 ..
 StringBuffer b = new StringBuffer;
 foo(b);
 // is b now corrupt??
 
As the comment at the end suggests, we want to know which arguments might be corrupted by a method call. Therefore, at the pseudo-statement "corrupt a", we want to know whether or not "a" refers to one of the original arguments. In this case, the parameter alias "a" was reassigned and is no longer an alias for the parameter, so "b" was not corrupted.


Constructor Summary
Method(Application application, String name, Variable[] params)
          Creates a new method with the given name and parameters.
 
Method Summary
 void addStatement(Statement s)
          Adds the given statement to the list of statements for this method.
 Application getApplication()
          Returns the application containing this method.
 List<Call> getCallSites()
          Returns an (unmodifiable) list of all call sites calling this method.
 MethodHead getEntry()
          Returns the entry point of this method.
 ExceptionalReturn getExceptionalReturn()
          Gets the exceptional exit from this method.
 int getKey()
           
 String getName()
          Returns the name of this method.
 Variable[] getParamAlias()
          Returns the list of alias variables for the method parameters, with non-null entries for mutables.
 List<Return> getReturns()
          Returns the (unmodifiable) list of return points for this method.
 List<Statement> getStatements()
          Returns the (unmodifiable) list of statements for this method.
 void removeNop(Nop s)
          Removes the given Nop statement from the body of this method.
 String toString()
          Returns identifier of this method object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Method

public Method(Application application,
              String name,
              Variable[] params)
Creates a new method with the given name and parameters. Only parameters of relevant types are represented. A MethodHead object is created as the entry point for the method, inheriting the parameters.

Method Detail

addStatement

public void addStatement(Statement s)
Adds the given statement to the list of statements for this method.

Throws:
IllegalStateException - if the statement is already added to a method

getApplication

public Application getApplication()
Returns the application containing this method.

Returns:
application reference

getCallSites

public List<Call> getCallSites()
Returns an (unmodifiable) list of all call sites calling this method.


getEntry

public MethodHead getEntry()
Returns the entry point of this method.


getExceptionalReturn

public ExceptionalReturn getExceptionalReturn()
Gets the exceptional exit from this method.

Returns:
a statement in this method

getKey

public int getKey()

getName

public String getName()
Returns the name of this method.


getParamAlias

public Variable[] getParamAlias()
Returns the list of alias variables for the method parameters, with non-null entries for mutables.


getReturns

public List<Return> getReturns()
Returns the (unmodifiable) list of return points for this method.


getStatements

public List<Statement> getStatements()
Returns the (unmodifiable) list of statements for this method.


removeNop

public void removeNop(Nop s)
Removes the given Nop statement from the body of this method. All control flow edges are updated accordingly.


toString

public String toString()
Returns identifier of this method object.

Overrides:
toString in class Object


Copyright © 2003-2009 Anders Møller, Aske Simon Christensen, Asger Feldthaus.