minijava.typecheck
Class Class

java.lang.Object
  extended by minijava.typecheck.Type
      extended by minijava.typecheck.Class
All Implemented Interfaces:
Binding

public class Class
extends Type

This class represents a class type. It records a mapping of identifiers to Types for the class' declared fields, a mapping of identifiers to Method objects, and a reference to a parent class if this class extends any.

Author:
Santoso Wijaya
See Also:
Method

Constructor Summary
Class(java.lang.String clsym)
          Creates a class object without parent reference.
Class(java.lang.String clsym, Class parent)
          Creates a class object that extends another class.
Class(Symbol clsym)
          Creates a class object without parent reference.
Class(Symbol clsym, Class parent)
          Creates a class object that extends another class.
 
Method Summary
 boolean addField(Type type, java.lang.String iden)
          Adds a field declaration to this class.
 boolean addField(Type type, Symbol iden)
          Adds a field declaration to this class.
 boolean addMethod(java.lang.String sym, Method method)
          Adds a method object to this class' mapping of symbols to method objects.
 boolean addMethod(Symbol sym, Method method)
          Adds a method object to this class' mapping of symbols to method objects.
 boolean agrees(Type rhs)
          Checks whether this Type "agrees" with the given argument.
static Class getClass(Symbol sym)
          Deprecated. rather than using its own table, access class objects in the general symbol table that contains its reference
 int getFieldOrder(java.lang.String iden)
          Looks up the order number of the given field's identifier.
 int getFieldOrder(Symbol iden)
          Looks up the order number of the given field's identifier.
 int getFieldsSize()
          Returns the number of fields an object of this class would have.
 Type getFieldType(java.lang.String iden)
          Looks up the type of this class' field by the given identifier.
 Type getFieldType(Symbol iden)
          Looks up the type of this class' field by the given identifier.
 Method getMethod(java.lang.String iden)
          Looks up a method in this class with the given identifier.
 Method getMethod(Symbol iden)
          Looks up a method in this class with the given identifier.
 java.util.Set<Symbol> getMethodIdentifiers()
          Returns the set of method identifiers (symbols) specific to this class (exluding the base class').
 int getMethodOrder(java.lang.String iden)
          Looks up the order number of the given method's identifier.
 int getMethodOrder(Symbol iden)
          Looks up the order number of the given method's identifier.
 java.util.List<Symbol> getMethodSymbolsInOrder()
          Returns a list of method symbols local to this class, in the order that they were added.
 Class getParent()
           
 java.util.Set<Symbol> getVariableIdentifiers()
          Returns the set of instance variable identifiers (symbols) specific to this class (excluding the base class').
 void setParent(Class parent)
           
 
Methods inherited from class minijava.typecheck.Type
equals, getTypeName, hashCode, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Class

public Class(Symbol clsym)
Creates a class object without parent reference.

Parameters:
clsym - the class identifier

Class

public Class(java.lang.String clsym)
Creates a class object without parent reference.

Parameters:
clsym - the class identifier

Class

public Class(Symbol clsym,
             Class parent)
Creates a class object that extends another class.

Parameters:
clsym - the class identifier
parent - the parent class of this class

Class

public Class(java.lang.String clsym,
             Class parent)
Creates a class object that extends another class.

Parameters:
clsym - the class identifier
parent - the parent class of this class
Method Detail

getClass

@Deprecated
public static Class getClass(Symbol sym)
Deprecated. rather than using its own table, access class objects in the general symbol table that contains its reference

Gets a (singleton) Class object that is represented by the parameter symbol. If one does not exist yet, creates one and stores it in the internal repository, before returning it.

Parameters:
sym - the symbol that represents a class identifier
Returns:
a class reference

getParent

public Class getParent()
Returns:
the reference to parent class to this class

setParent

public void setParent(Class parent)
Parameters:
parent - the reference to parent class to this class

addField

public boolean addField(Type type,
                        Symbol iden)
Adds a field declaration to this class. If one has already been declared previously, the method does nothing and returns false. Note that a field by the same name declared in the super class of this class counts as having been declared (an exception will be thrown).

Parameters:
type - the type of the new field
iden - the field identifier to be added
Returns:
true if the field is successfully added to the class

addField

public boolean addField(Type type,
                        java.lang.String iden)
Adds a field declaration to this class. If one has already been declared previously, the method does nothing and returns false. Note that a field by the same name declared in the super class of this class counts as having been declared (an exception will be thrown).

Parameters:
type - the type of the new field
iden - the field identifier to be added
Returns:
true if the field is successfully added to the class

addMethod

public boolean addMethod(Symbol sym,
                         Method method)
Adds a method object to this class' mapping of symbols to method objects. If one such mapping already exists for a given symbol, do nothing and return false.

Parameters:
sym - the identifier for the method name
method - the method object associated with the identifier
Returns:
false if a mapping of the identifier to a method object already exists, true otherwise

addMethod

public boolean addMethod(java.lang.String sym,
                         Method method)
Adds a method object to this class' mapping of symbols to method objects. If one such mapping already exists for a given symbol, do nothing and return false.

Parameters:
sym - the identifier for the method name
method - the method object associated with the identifier
Returns:
false if a mapping of the identifier to a method object already exists, true otherwise

getMethodSymbolsInOrder

public java.util.List<Symbol> getMethodSymbolsInOrder()
Returns a list of method symbols local to this class, in the order that they were added.

Returns:
a list of method symbols local to this class

getMethodOrder

public int getMethodOrder(Symbol iden)
Looks up the order number of the given method's identifier. The order number refers to the ordering where the method is declared. This is important for building a virtual method table to implement polymorphism of functions.

Parameters:
iden - the method identifier
Returns:
the order number, if such field with the given identifier exists; otherwise -1 is returned.

getMethodOrder

public int getMethodOrder(java.lang.String iden)
Looks up the order number of the given method's identifier. The order number refers to the ordering where the method is declared. This is important for building a virtual method table to implement polymorphism of functions.

Parameters:
iden - the method identifier
Returns:
the order number, if such field with the given identifier exists; otherwise -1 is returned.

getFieldType

public Type getFieldType(Symbol iden)
Looks up the type of this class' field by the given identifier. Searches up the clas hierarchy until the top-most parent is reached.

Parameters:
iden - the field identifier
Returns:
the type of this class' field with the given identifier, null if no such field identifier exists

getFieldType

public Type getFieldType(java.lang.String iden)
Looks up the type of this class' field by the given identifier. Searches up the clas hierarchy until the top-most parent is reached.

Parameters:
iden - the field identifier
Returns:
the type of this class' field with the given identifier, null if no such field identifier exists

getFieldOrder

public int getFieldOrder(Symbol iden)
Looks up the order number of the given field's identifier. The order number refers to the ordering where the field is declared (0 based).

Parameters:
iden - the field identifier
Returns:
the order number, if such field with the given identifier exists; otherwise -1 is returned.

getFieldOrder

public int getFieldOrder(java.lang.String iden)
Looks up the order number of the given field's identifier. The order number refers to the ordering where the field is declared (0 based).

Parameters:
iden - the field identifier
Returns:
the order number, if such field with the given identifier exists; otherwise -1 is returned.

getFieldsSize

public int getFieldsSize()
Returns the number of fields an object of this class would have. Includes the number of fields of this class' parents.

Returns:
the number of fields

getVariableIdentifiers

public java.util.Set<Symbol> getVariableIdentifiers()
Returns the set of instance variable identifiers (symbols) specific to this class (excluding the base class').

Returns:
the (unmodifiable) set of variable identifiers

getMethod

public Method getMethod(Symbol iden)
Looks up a method in this class with the given identifier. Searches up the class hierarchy until the top-most parent is reached.

Parameters:
iden - the method identifier
Returns:
a method object that the given identifier maps to, null if no such mapping exists

getMethod

public Method getMethod(java.lang.String iden)
Looks up a method in this class with the given identifier. Searches up the class hierarchy until the top-most parent is reached.

Parameters:
iden - the method identifier
Returns:
a method object that the given identifier maps to, null if no such mapping exists

getMethodIdentifiers

public java.util.Set<Symbol> getMethodIdentifiers()
Returns the set of method identifiers (symbols) specific to this class (exluding the base class').

Returns:
the (unmodifiable) set of method identifiers

agrees

public boolean agrees(Type rhs)
Description copied from class: Type
Checks whether this Type "agrees" with the given argument. Two types are agreeable if they are equal primitives or, if they are class types, rhs is a subclass/subtype of this type.

Specified by:
agrees in class Type
Parameters:
rhs - the right hand side in the equivalence test
Returns:
true if type(this) == type(rhs), or ig type(this) == supertype(rhs), and false otherwise