scale.clef.type
Class ProcedureType

java.lang.Object
  extended by scale.common.Root
      extended by scale.clef.Node
          extended by scale.clef.type.Type
              extended by scale.clef.type.ProcedureType
All Implemented Interfaces:
AnnotationInterface, DisplayNode

public class ProcedureType
extends Type

A ProcedureType represents the type of a procedure.

$Id: ProcedureType.java,v 1.65 2007-08-27 18:13:32 burrill Exp $

Copyright 2008 by the Scale Compiler Group,
Department of Computer Science
University of Massachusetts,
Amherst MA. 01003, USA
All Rights Reserved.


Constructor Summary
protected ProcedureType(Type returnType, Vector<FormalDecl> formals, Vector<Raise> raises)
           
 
Method Summary
 int alignment(Machine machine)
          Calculate the alignment needed for this data type.
static void cleanup()
          Remove static lists of types.
 boolean compareSignatures(ProcedureType s2, boolean matchUnknowns, boolean matchFormalNames, boolean matchFormalModes, boolean matchExceptions, boolean exactExceptionMatch)
          Return true if the specified procedure type matches this procedure type.
 ProcedureType copy(Type returnType)
          Create a procedure type with the same parameters but a different return type.
static ProcedureType create(Type returnType, Vector<FormalDecl> formals, Vector<Raise> raises)
          Re-use an existing instance of a particular procedure type.
 boolean equivalent(Type t)
          Compares two ProcedureTypes for equivalence as defined by the type equivalence rules specified in ted.
 Node getChild(int i)
          Return the specified AST child of this node.
 FormalDecl getFormal(int i)
          Return the specified formal parameter.
 FormalDecl getFormal(java.lang.String name)
          Return the specified formal parameter.
 Raise getRaise(int i)
          Return the specified exception.
 Vector<Raise> getRaiseVector()
          Return a vector of exceptions raised.
 Type getReturnType()
          Return the return type of the procedure.
static java.util.Enumeration<ProcedureType> getTypes()
          Return an enumeration of all the different types.
 boolean isFChar()
          Return true if this is a Fortran FUNCTION that returns a CHARACTER value via an address passed in as in argument.
 boolean isOldStyle()
          Return true if this is an old style C procedure type defined with out a prototype.
 boolean isProcedureType()
          Return true if this type represents a procedure.
 void markAsFChar()
          Mark this as a Fortran FUNCTION that returns a CHARACTER value via an address passed in as in argument.
 void markAsOldStyle()
          Mark this as an old style K&R C procedure type.
 long memorySize(Machine machine)
          Calculate how many addressable memory units are needed to represent the type.
 int numChildren()
          Return the number of AST children of this node.
 int numFormals()
          Return the number of formal parameters.
 int numRaises()
          Return the number of exceptions raised.
 int precedence()
          Return a precedence value for types.
 ProcedureType returnProcedureType()
          Return if this is a ProcedureType, return this.
 boolean sameFormals(Vector<FormalDecl> formals)
          Return true if the formals match.
 boolean sameRaises(Vector<Raise> raises)
          Return true if the formals match.
 java.lang.String toStringSpecial()
          This method allows sub-classes to provide class specific stuff to the string.
 void visit(Predicate p)
          Process a node by calling its associated routine.
 void visit(TypePredicate p)
          Process a node by calling its associated routine.
 
Methods inherited from class scale.clef.type.Type
canBeInRegister, elementSize, getCompleteType, getCoreType, getDisplayColorHint, getDisplayLabel, getDisplayShapeHint, getEquivalentType, getNonAttributeType, getNonConstType, getPointedTo, getPointedToCore, getRank, getSignedType, getTag, getType, isAggregateType, isAllocArrayType, isArrayType, isAtomicType, isAttributeSet, isBooleanType, isCharacterType, isClassType, isComplexType, isCompositeType, isConst, isEnumerationType, isFixedArrayType, isFloatType, isFortranCharType, isIncompleteType, isIntegerType, isNamedType, isNumericType, isPointerType, isRealType, isRefType, isRestricted, isSigned, isUnionType, isVoidType, isVolatile, mapTypeToCString, mapTypeToF77String, memorySizeAsInt, nextVisit, numberOfElements, registerType, returnAggregateType, returnAllocArrayType, returnArrayType, returnAtomicType, returnBooleanType, returnCharacterType, returnComplexType, returnCompositeType, returnEnumerationType, returnFixedArrayType, returnFloatType, returnFortranCharType, returnIncompleteType, returnIntegerType, returnNumericType, returnPointerType, returnRealType, returnRecordType, returnRefType, returnSignedIntegerType, returnUnionType, returnUnsignedIntegerType, returnVoidType, setTag, setVisited, specifyCanBeInRegister, toString, toStringShort, visited
 
Methods inherited from class scale.clef.Node
getDecl, getSourceLineNumber, setAnnotationLevel, setReportLevel, setSourceLineNumber, toString, toStringChildren
 
Methods inherited from class scale.common.Root
addAnnotation, allAnnotations, allMatchingAnnotations, getAnnotation, getDisplayName, getDisplayString, getNodeCount, getNodeID, hasAnnotation, hasEqualAnnotation, hashCode, removeAnnotation, removeAnnotations, toStringAnnotations, toStringClass, trace, trace, trace
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ProcedureType

protected ProcedureType(Type returnType,
                        Vector<FormalDecl> formals,
                        Vector<Raise> raises)
Method Detail

create

public static ProcedureType create(Type returnType,
                                   Vector<FormalDecl> formals,
                                   Vector<Raise> raises)
Re-use an existing instance of a particular procedure type. If no equivalent procedure type exists, create a new one.

Parameters:
returnType - the return type of the routine.
formals - a vector of FormalDecls. If the vector is empty, the routine is of the form r(void).
raises - the exceptions raised by the routine or null if none.

copy

public ProcedureType copy(Type returnType)
Create a procedure type with the same parameters but a different return type.


sameFormals

public boolean sameFormals(Vector<FormalDecl> formals)
Return true if the formals match.


sameRaises

public boolean sameRaises(Vector<Raise> raises)
Return true if the formals match.


isProcedureType

public boolean isProcedureType()
Return true if this type represents a procedure.

Overrides:
isProcedureType in class Type

returnProcedureType

public final ProcedureType returnProcedureType()
Description copied from class: Type
Return if this is a ProcedureType, return this. Otherwise, return null.

Overrides:
returnProcedureType in class Type

isOldStyle

public final boolean isOldStyle()
Return true if this is an old style C procedure type defined with out a prototype.


markAsOldStyle

public final void markAsOldStyle()
Mark this as an old style K&R C procedure type.


isFChar

public final boolean isFChar()
Return true if this is a Fortran FUNCTION that returns a CHARACTER value via an address passed in as in argument.


markAsFChar

public final void markAsFChar()
Mark this as a Fortran FUNCTION that returns a CHARACTER value via an address passed in as in argument.


getReturnType

public final Type getReturnType()
Return the return type of the procedure.


getFormal

public final FormalDecl getFormal(int i)
Return the specified formal parameter.


getFormal

public final FormalDecl getFormal(java.lang.String name)
Return the specified formal parameter.


numFormals

public int numFormals()
Return the number of formal parameters.


getRaiseVector

public final Vector<Raise> getRaiseVector()
Return a vector of exceptions raised.


numRaises

public int numRaises()
Return the number of exceptions raised.


getRaise

public final Raise getRaise(int i)
Return the specified exception.


visit

public void visit(Predicate p)
Description copied from class: Node
Process a node by calling its associated routine. See the "visitor" design pattern in Design Patterns: Elements of Reusable Object-Oriented Software by E. Gamma, et al, Addison Wesley, ISBN 0-201-63361-2.

Each class has a visit(Predicate p) method. For example, in class ABC:

   public void visit(Predicate p)
   {
     p.visitABC(this);
   }
 
and the class that implements Predicate has a method
   public void visitABC(Node n)
   {
     ABC a = (ABC) n;
     ...
   }
 
Thus, the class that implements Predicate can call
   n.visit(this);
 
where n is a Node sub-class without determining which specific sub-class n is. The visit pattern basically avoids implementing a large switch statement or defining different methods in each class for some purpose.

Overrides:
visit in class Type
See Also:
Predicate

visit

public void visit(TypePredicate p)
Description copied from class: Type
Process a node by calling its associated routine. See the "visitor" design pattern in Design Patterns: Elements of Reusable Object-Oriented Software by E. Gamma, et al, Addison Wesley, ISBN 0-201-63361-2.

Each type class has a visit(TypePredicate p) method. For example, in class ABC:

   public void visit(Predicate p)
   {
     p.visitABC(this);
   }
 
and the class that implements Predicate has a method
   public void visitABC(Node n)
   {
     ABC a = (ABC) n;
     ...
   }
 
Thus, the class that implements TypePredicate can call
   n.visit(this);
 
where n is a Node sub-class without determining which specific sub-class n is. The visit pattern basically avoids implementing a large switch statement or defining different methods in each class for some purpose.

Overrides:
visit in class Type
See Also:
TypePredicate

getChild

public Node getChild(int i)
Return the specified AST child of this node.

Overrides:
getChild in class Node

numChildren

public int numChildren()
Return the number of AST children of this node.

Overrides:
numChildren in class Node

toStringSpecial

public java.lang.String toStringSpecial()
Description copied from class: Node
This method allows sub-classes to provide class specific stuff to the string.

Overrides:
toStringSpecial in class Node

compareSignatures

public boolean compareSignatures(ProcedureType s2,
                                 boolean matchUnknowns,
                                 boolean matchFormalNames,
                                 boolean matchFormalModes,
                                 boolean matchExceptions,
                                 boolean exactExceptionMatch)
Return true if the specified procedure type matches this procedure type.

The criterion for considering two signatures equivalent can be modified by the boolean arguments to the method.

If matchUnknowns is false then two parameter lists match if:

Any UnknownFormals instance must always be the last parameter.

Parameters:
s2 - is the other procedure type
matchUnknowns - is true if the signatures don't match when the position of any UnknownFormals instances differ
matchFormalNames - is true is the names of the parameters should be compared
matchFormalModes - is true if the parameter modes should be compared
matchExceptions - is true if the exceptions should be compared
exactExceptionMatch - is true if the exceptions must match excatly

equivalent

public boolean equivalent(Type t)
Compares two ProcedureTypes for equivalence as defined by the type equivalence rules specified in ted.

Specified by:
equivalent in class Type
Returns:
true if the types are equivalent

getTypes

public static java.util.Enumeration<ProcedureType> getTypes()
Return an enumeration of all the different types.


memorySize

public long memorySize(Machine machine)
Calculate how many addressable memory units are needed to represent the type.

Specified by:
memorySize in class Type
Parameters:
machine - is the machine-specific data machine
Returns:
the number of addressable memory units required to represent this type

alignment

public int alignment(Machine machine)
Calculate the alignment needed for this data type.

Specified by:
alignment in class Type

precedence

public int precedence()
Return a precedence value for types. We assign precendence values to declarators that use operators (e.g., arrays, functions, pointers). The precendence values are relative to the other operators - larger values mean higher precedence.

Overrides:
precedence in class Type
Returns:
an integer representing the precendence value for the type relative to the other values.

cleanup

public static void cleanup()
Remove static lists of types.