minijava.typecheck
Class Method

java.lang.Object
  extended by minijava.typecheck.Method

public class Method
extends java.lang.Object

This class represents a method. It stores type information about its return type, local variables, signature and formal parameters. Note that the signature types must be appended in order since ordering matters. Parameters and local variables are stored as a mapping of identifiers to types.

Author:
Santoso Wijaya
See Also:
Symbol, Type

Constructor Summary
Method()
          Creates an empty method object.
 
Method Summary
 boolean addLocalVariable(Type type, java.lang.String iden)
           
 boolean addLocalVariable(Type type, Symbol iden)
           
 boolean appendParameterSignature(Type type, Symbol iden)
           
 java.util.Set<Symbol> getLocalVariableIdentifiers()
           
 Type getLocalVariableType(java.lang.String sym)
           
 Type getLocalVariableType(Symbol sym)
           
 int getParameterCount()
           
 Symbol getParameterIdentifierAt(int pos)
          Pre-condition: pos < getParameterCount()
 Type getParameterTypeAt(int pos)
          Pre-condition: pos < getParameterCount()
 Type getReturnType()
           
 void setReturnType(Type returnType)
           
 java.lang.String toString()
          A string representation of the method in the form of: method(#param:type)* -> type.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Method

public Method()
Creates an empty method object. When created, its semantic is invalid as is until at least the return type is defined.

Method Detail

getReturnType

public Type getReturnType()
Returns:
the return type

setReturnType

public void setReturnType(Type returnType)
Parameters:
returnType - the return type to set

getParameterCount

public int getParameterCount()
Returns:
the number of parameters in method signature

getParameterTypeAt

public Type getParameterTypeAt(int pos)
Pre-condition: pos < getParameterCount()

Parameters:
pos - the index into parameter signature
Returns:
the parameter type at the pos'th position in the method signature (list of formal parameters)

getParameterIdentifierAt

public Symbol getParameterIdentifierAt(int pos)
Pre-condition: pos < getParameterCount()

Parameters:
pos - the index into parameter signature
Returns:
the parameter identifier at the pos'th position in the method signature (list of formal parameters)

appendParameterSignature

public boolean appendParameterSignature(Type type,
                                        Symbol iden)
Parameters:
type - append a parameter type at the end of this method's signature
Returns:
true if the operation succeeds, false if a binding of such parameter has already been entered

addLocalVariable

public boolean addLocalVariable(Type type,
                                Symbol iden)
Parameters:
type - the type of the variable
iden - the identifier of the variable
Returns:
true if the operation succeeds, false if a binding of such variable has already been entered either in this method's local variables or its formal parameters

addLocalVariable

public boolean addLocalVariable(Type type,
                                java.lang.String iden)
Parameters:
type - the type of the variable
iden - the identifier of the variable
Returns:
true if the operation succeeds, false if a binding of such variable has already been entered either in this method's local variables or its formal parameters

getLocalVariableType

public Type getLocalVariableType(Symbol sym)
Parameters:
sym - the local variable identifier
Returns:
the type of the local variable with the given identifier; null if no such identifier exists

getLocalVariableType

public Type getLocalVariableType(java.lang.String sym)
Parameters:
sym - the local variable identifier
Returns:
the type of the local variable with the given identifier; null if no such identifier exists

getLocalVariableIdentifiers

public java.util.Set<Symbol> getLocalVariableIdentifiers()
Returns:
the set of local variable identifiers to this method

toString

public java.lang.String toString()
A string representation of the method in the form of: method(#param:type)* -> type.

Overrides:
toString in class java.lang.Object
Returns:
a string representation of the method in the form of: method(#param:type)* -> type