CS 536 Fall 2007, Project 5

Class Type

Object
  extended by Type

public class Type
extends Object

A object representing a type in the Ada536 langauge.


Nested Class Summary
static class Type.BaseType
          Basic types: int, bool, void, string, or error.
static class Type.Kind
          One of SCALAR, PROCEDURE, or ARRAY.
 
Field Summary
 Type.BaseType baseType
          The "base" type.
static Type ERROR
          A constant Type representing the "type" of an expression that contains a type error.
 Type.Kind kind
          The "kind" of this type.
 ProcDeclNode.Mode[] paramModes
          The modes of the parameters to this function.
 String[] paramNames
          The names of the parameters to this function.
 Type[] paramTypes
          The types of the parameters to this function.
 int size
          The size of this array type.
 
Constructor Summary
Type(String[] paramNames, Type[] paramTypes, ProcDeclNode.Mode[] paramModes, Type.BaseType returnType)
          Creates a new PROCEDURE type.
Type(Type.BaseType baseType)
          Creates a new SCALAR type.
Type(Type.BaseType baseType, int size)
          Creates a new ARRAY type.
 
Method Summary
 int bytes()
          Returns the size, in bytes, of an instance of this type.
 boolean isBool()
          Tests whether this Type is the scalar type BOOL.
 boolean isError()
          Tests whether this Type is the scalar type ERROR.
 boolean isInt()
          Tests whether this Type is the scalar type INT.
 boolean matches(Type that)
          Tests whether this Type matches other Type.
 String toString()
          Converts this type into String for debugging.
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

kind

public final Type.Kind kind
The "kind" of this type.


ERROR

public static final Type ERROR
A constant Type representing the "type" of an expression that contains a type error. Used to avoid cascading errors.


baseType

public final Type.BaseType baseType
The "base" type. For kind == SCALAR, this is the type. For kind == PROCEDURE, this is the return type of a fun or VOID for a proc. For kind == ARRAY, this is the type of an element of the array.


paramNames

public final String[] paramNames
The names of the parameters to this function. For kind != PROCEDURE, this field is unused (and should be null). Otherwise, it must have the same number of elements as paramTypes and paramModes.


paramTypes

public final Type[] paramTypes
The types of the parameters to this function. For kind != PROCEDURE, this field is unused (and should be null). Otherwise, it must have the same number of elements as paramNames and paramModes.


paramModes

public final ProcDeclNode.Mode[] paramModes
The modes of the parameters to this function. For kind != PROCEDURE, this field is unused (and should be null). Otherwise, it must have the same number of elements as paramTypes and paramNames.


size

public final int size
The size of this array type. For kinds != ARRAY, this field is unused (and should be zero). For an array declared as "array (0..n) of X", size is n+1.

Constructor Detail

Type

public Type(Type.BaseType baseType)
Creates a new SCALAR type.

Parameters:
baseType - the baseType.

Type

public Type(Type.BaseType baseType,
            int size)
Creates a new ARRAY type.

Parameters:
baseType - the element type of the array.
size - the number of elements in the array.

Type

public Type(String[] paramNames,
            Type[] paramTypes,
            ProcDeclNode.Mode[] paramModes,
            Type.BaseType returnType)
Creates a new PROCEDURE type. The arrays paramNames, paramTypes, and paramNodes must be non-null and the same length.

Parameters:
paramNames - the names of the parameters.
paramTypes - the types of the parameters.
paramModes - the modes of the parameters.
returnType - the type returned by the function.
Method Detail

toString

public String toString()
Converts this type into String for debugging. The result is something like "bool", "int[5]", or "(x:in int,y:out int):void". Note that the result is an abbreviated version of the ada536 declaration. The three examples above might appear in the source program as "boolean", "array (0..4) of integer", and "procedure ... (x : in integer, y : out integer)", respectively.

Overrides:
toString in class Object
Returns:
a string representation of this Type.

matches

public boolean matches(Type that)
Tests whether this Type matches other Type.

Parameters:
that - the other type.
Returns:
true if the types are equivalent.

isInt

public boolean isInt()
Tests whether this Type is the scalar type INT.

Returns:
true if this is the scalar type INT.

isBool

public boolean isBool()
Tests whether this Type is the scalar type BOOL.

Returns:
true if this is the scalar type BOOL.

isError

public boolean isError()
Tests whether this Type is the scalar type ERROR.

Returns:
true if this is the scalar type ERROR.

bytes

public int bytes()
Returns the size, in bytes, of an instance of this type.

Returns:
the size in bytes

CS 536 Fall 2007, Project 5