gov.llnl.babel.symbols
Class Method

java.lang.Object
  extended by gov.llnl.babel.symbols.ASTNode
      extended by gov.llnl.babel.symbols.Method
All Implemented Interfaces:
java.lang.Cloneable

public class Method
extends ASTNode
implements java.lang.Cloneable

The Method class defines a SIDL method, including modifiers, return type, name, arguments, and exceptions. Methods may have one of three definition modifiers: final, static, or abstract. They may also have one of two communication modifiers: local or oneway. The return type is either a type or null (which indicates void). The method name is a simple identifier string. The optional arguments are an ordered collecton or arguments. The method may throw any number of exceptions.


Nested Class Summary
 class Method.RarrayInfo
           
 
Field Summary
static int ABSTRACT
           
static int FINAL
           
static int LOCAL
           
static int NORMAL
           
static int ONEWAY
           
static java.lang.String[] s_comm_mod
           
static java.lang.String[] s_def_mod
           
static int STATIC
           
 
Constructor Summary
Method()
          Create an empty Method object that will be built by calls to other member functions.
 
Method Summary
 void addArgument(Argument arg)
          Add another argument to the end of the list of method arguments.
 void addAssertion(Assertion assertion)
          Add the specified assertion to the proper assertion list for this method.
 void addRarrayIndex(java.util.Collection new_indices)
          add a set of required rarray indices to the set of indices
 void addRarrayIndex(java.lang.String s)
          add a required rarray index to the set of indices
 void addThrows(SymbolID id)
          Add a symbol identifier to the list of supported exceptions for this method.
 Method cloneMethod()
          Return a shallow copy of this method object.
 boolean equals(java.lang.Object o)
           
 Argument getArgumentByName(java.lang.String s)
          Return an the argument whose formal name matches the passed in string.
 java.util.ArrayList getArgumentList()
          Return the array of arguments in an ArrayList, where each element is an Argument.
 java.util.ArrayList getArgumentListWithIndices()
          Return the array of arguments in an ArrayList container.
 java.util.ArrayList getArgumentListWithOutIndices()
          Return the array of arguments in an ArrayList container.
 int getArgumentMode(java.lang.String name)
          Return the mode of the argument with the specified formal name, if any; otherwise, return -1.
 Type getArgumentType(java.lang.String name)
          Return the Type of the argument with the specified formal name, if any; otherwise, return null.
 java.util.Set getBasicArrays()
          Return the Set of basic array references including arrays of fundamental types such as double, int, etc.
 Comment getComment()
          Return the comment for the method.
 int getCommunicationModifier()
          Return the communication modifier for this method.
 java.lang.String getCommunicationModifierString()
          Return the communication modifier string for this method.
 int getDefinitionModifier()
          Return the definition modifier for the method.
 java.lang.String getDefinitionModifier(boolean is_interface)
          Return the explicit definition modifier string for the method based on the type of extendable in which it belongs.
 java.lang.String getLongMethodName()
          Return the long method name (a standard SIDL identifier).
 int getMaxArrayIterMacros(char type)
          Return the number of array iteration macros in the assertions of the method of the specified return type.
 java.lang.String getNameExtension()
          Return the method name extension (a standard SIDL identifier).
 java.util.ArrayList getPostconditions()
          Return the list of postconditions as an ArrayList of Assertion elements.
 java.util.ArrayList getPreconditions()
          Return the list of preconditions as an ArrayList of Assertion elements.
 java.util.Set getRarrayIndices()
          Return the set of rarray indices required in the arg list.
 java.util.HashMap getRarrayInfo()
          This returns an array list of RarrayInfo objects that contains the info for every rarray index used in this method.
 Type getReturnType()
          Return the return type for the method.
 java.lang.String getReturnType(java.lang.String parent_pkg)
          Return the string corresponding to the return type for this method.
 java.lang.String getShortMethodName()
          Return the short method name (a standard SIDL identifier).
 java.lang.String getSignature()
          Return the signature of the method.
 java.lang.String getSignature(boolean is_interface, java.lang.String parent_pkg)
          Return the signature of the method, including the definition modifier based on the extendable type.
 java.lang.String getSignaturePreface(boolean is_interface, java.lang.String parent_pkg)
          Return the concatenation of the explicit definition modifier, copy, return type, name and extension.
 java.util.Set getSymbolReferences()
          Return the Set of symbols referred to by this method.
 java.util.Set getThrows()
          Return the Set of exceptions that may be thrown by this method.
 boolean hasArrayOrderSpec()
          Return TRUE if and only if at least one argument of this method is an array with an ordering specification.
 int hashCode()
           
 boolean hasPureAssertion()
          Return TRUE if PURE clause appears in the assertions associated with this method; otherwise, return FALSE.
 boolean hasRarray()
          Returns true if this method has an rarray in it's signature
 boolean hasReservedMethodAssertion(java.util.ArrayList list, int type)
          Return TRUE if the list of assertions has the specified reserved method assertion; FALSE otherwise.
 boolean hasReservedMethodAssertion(int type)
          Return TRUE if the method has the specified reserved method assertion; FALSE otherwise.
 boolean hasUnreservedMethodAssertion(java.util.ArrayList list, boolean any)
          Return TRUE if the list of assertions has the type of unreserved method assertion; FALSE otherwise.
 boolean hasUnreservedMethodAssertion(boolean any)
          Return TRUE if the method has any unreserved method (when any is TRUE) assertion or has an unreserved method assertion with a throws clause (if any is FALSE); otherwise, return FALSE.
 boolean isAbstract()
          Return TRUE if the method is abstract; otherwise, return FALSE.
 boolean isFinal()
          Return TRUE if the method is final; otherwise, return FALSE.
 boolean isReturnCopy()
          Return the copy mode for the return type.
 boolean isStatic()
          Return TRUE if the method is static; otherwise, return FALSE.
 boolean sameBaseSignature(Method m)
          Return TRUE if the base signature of the specified method matches that of this method; otherwise, return FALSE.
 boolean sameSignature(Method m)
          Return TRUE if the signature of the specified method matches that of this method; otherwise, return FALSE.
 void setComment(Comment comment)
          Set the comment for the method.
 void setCommunicationModifier(int modifier)
          Set the communication modifier for the method.
 void setDefinitionModifier(int modifier)
          Set the definition modifier for the method.
 void setMethodName(java.lang.String shortName)
          Set the names of the method (a standard SIDL identifier).
 void setMethodName(java.lang.String shortName, java.lang.String extension)
          Set the names of the method (a standard SIDL identifier).
 void setReturnCopy(boolean copy)
          Set the copy mode for the return type.
 void setReturnType(Type type)
          Set the return type for the method.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NORMAL

public static final int NORMAL
See Also:
Constant Field Values

ABSTRACT

public static final int ABSTRACT
See Also:
Constant Field Values

FINAL

public static final int FINAL
See Also:
Constant Field Values

STATIC

public static final int STATIC
See Also:
Constant Field Values

LOCAL

public static final int LOCAL
See Also:
Constant Field Values

ONEWAY

public static final int ONEWAY
See Also:
Constant Field Values

s_def_mod

public static final java.lang.String[] s_def_mod

s_comm_mod

public static final java.lang.String[] s_comm_mod
Constructor Detail

Method

public Method()
Create an empty Method object that will be built by calls to other member functions.

Method Detail

cloneMethod

public Method cloneMethod()
Return a shallow copy of this method object. This method should never fail since this method is cloneable. Send in the clones.


addArgument

public void addArgument(Argument arg)
Add another argument to the end of the list of method arguments.

Parameters:
arg - The argument to be appended to the object's argument list

getArgumentList

public java.util.ArrayList getArgumentList()
Return the array of arguments in an ArrayList, where each element is an Argument.


getArgumentListWithOutIndices

public java.util.ArrayList getArgumentListWithOutIndices()
Return the array of arguments in an ArrayList container. This method returns only arguments that are not used as indices to an Rarray


getArgumentListWithIndices

public java.util.ArrayList getArgumentListWithIndices()
Return the array of arguments in an ArrayList container. This returns all the arguments in the argument list, including those that are indices to an Rarray.


addRarrayIndex

public void addRarrayIndex(java.lang.String s)
add a required rarray index to the set of indices


addRarrayIndex

public void addRarrayIndex(java.util.Collection new_indices)
add a set of required rarray indices to the set of indices


getRarrayIndices

public java.util.Set getRarrayIndices()
Return the set of rarray indices required in the arg list. (Returns null if there are no indices required)


hasRarray

public boolean hasRarray()
Returns true if this method has an rarray in it's signature


getArgumentType

public Type getArgumentType(java.lang.String name)
Return the Type of the argument with the specified formal name, if any; otherwise, return null.

Parameters:
name - The formal argument name whose type is to be returned.

getArgumentMode

public int getArgumentMode(java.lang.String name)
Return the mode of the argument with the specified formal name, if any; otherwise, return -1.

Parameters:
name - The formal argument name whose type is to be returned.

setComment

public void setComment(Comment comment)
Set the comment for the method.

Parameters:
comment - The comment associated with the method. May be null.

getComment

public Comment getComment()
Return the comment for the method. This may be null if there is no comment.


setCommunicationModifier

public void setCommunicationModifier(int modifier)
Set the communication modifier for the method.

Parameters:
modifier - The method's communication modifier. Valid values are NORMAL, LOCAL, and ONEWAY.

getCommunicationModifier

public int getCommunicationModifier()
Return the communication modifier for this method.


getCommunicationModifierString

public java.lang.String getCommunicationModifierString()
Return the communication modifier string for this method.


setDefinitionModifier

public void setDefinitionModifier(int modifier)
Set the definition modifier for the method.

Parameters:
modifier - The method's definnition modifier. Valid values are NORMAL, ABSTRACT, FINAL, and STATIC.

getDefinitionModifier

public int getDefinitionModifier()
Return the definition modifier for the method.


getDefinitionModifier

public java.lang.String getDefinitionModifier(boolean is_interface)
Return the explicit definition modifier string for the method based on the type of extendable in which it belongs.

Parameters:
is_interface - If TRUE, then the extendable is an interface so do NOT include ABSTRACT since it is implicit.
Returns:
the string associated with the explicit definition modifier

isAbstract

public boolean isAbstract()
Return TRUE if the method is abstract; otherwise, return FALSE.


isFinal

public boolean isFinal()
Return TRUE if the method is final; otherwise, return FALSE.


isStatic

public boolean isStatic()
Return TRUE if the method is static; otherwise, return FALSE.


hasArrayOrderSpec

public boolean hasArrayOrderSpec()
Return TRUE if and only if at least one argument of this method is an array with an ordering specification. For example, calling this on methods without array arguments will return FALSE while calling it on something like void doIt(in array<int, 2, row-major> x); will return TRUE.


setMethodName

public void setMethodName(java.lang.String shortName,
                          java.lang.String extension)
Set the names of the method (a standard SIDL identifier).

Parameters:
shortName - The short name of the method
extension - The method name extension used in combination with the short name to uniquely identify this method

setMethodName

public void setMethodName(java.lang.String shortName)
Set the names of the method (a standard SIDL identifier). Use of this method will result in the long and short name being identical.

Parameters:
shortName - The short name of the method

getShortMethodName

public java.lang.String getShortMethodName()
Return the short method name (a standard SIDL identifier).


getNameExtension

public java.lang.String getNameExtension()
Return the method name extension (a standard SIDL identifier).


getLongMethodName

public java.lang.String getLongMethodName()
Return the long method name (a standard SIDL identifier).


setReturnCopy

public void setReturnCopy(boolean copy)
Set the copy mode for the return type.

Parameters:
copy - If TRUE then the return interface/class is to be copied to the caller; otherwise, it is not.

isReturnCopy

public boolean isReturnCopy()
Return the copy mode for the return type.


setReturnType

public void setReturnType(Type type)
Set the return type for the method.

Parameters:
type - The return type to be used. Note that a void return type must be represented by a Type.VOID NOT a null Type reference.

getReturnType

public Type getReturnType()
Return the return type for the method.


addThrows

public void addThrows(SymbolID id)
Add a symbol identifier to the list of supported exceptions for this method. No error checking is performed to ensure that the specified symbol is valid in the throws clause; such checking must be performed by the parser.

Parameters:
id - The symbol identifier to be added

getThrows

public java.util.Set getThrows()
Return the Set of exceptions that may be thrown by this method. Each element of the set is a SymbolID.


getSymbolReferences

public java.util.Set getSymbolReferences()
Return the Set of symbols referred to by this method. Each element of the set is a SymbolID.


getBasicArrays

public java.util.Set getBasicArrays()
Return the Set of basic array references including arrays of fundamental types such as double, int, etc. Each element of the set is a SymbolID.


getReturnType

public java.lang.String getReturnType(java.lang.String parent_pkg)
Return the string corresponding to the return type for this method. Note the string may represent an abbreviated return type (i.e., a type stripped of its package information).

Parameters:
parent_pkg - The string containing the parent package. When not null, it is used to strip the package from the return string if it is in the specified package.
Returns:
the string containing the possibly abbreviated return type.

getSignaturePreface

public java.lang.String getSignaturePreface(boolean is_interface,
                                            java.lang.String parent_pkg)
Return the concatenation of the explicit definition modifier, copy, return type, name and extension.

Parameters:
is_interface - TRUE if an interface and want the implicit definition modifier excluded from the result; otherwise, FALSE.
parent_pkg - The string containing the parent package. When not null, it is used to strip the package from the return string if it is in the specified package.
Returns:
the string containing the preface

getSignature

public java.lang.String getSignature(boolean is_interface,
                                     java.lang.String parent_pkg)
Return the signature of the method, including the definition modifier based on the extendable type. Also, optionally abbreviate type if in specified package.

Parameters:
is_interface - TRUE if interface and want the implicit definition modifier excluded from the result; otherwise, FALSE
parent_pkg - The string containing the parent package. When not null, it is used to strip the package from the return string if it is in the specified package.
Returns:
The string containing the full signature.

getSignature

public java.lang.String getSignature()
Return the signature of the method. The signature does not include the attributes abstract, final, or static. It also does not abbreviate package names.


sameSignature

public boolean sameSignature(Method m)
Return TRUE if the signature of the specified method matches that of this method; otherwise, return FALSE. For signatures to match, the methods must have the same return types and mode, the same names, the same arguments, and the same throws clauses. They must also have the same communication modifiers. The signature does not include modifiers static, abstract, or final.

Parameters:
m - The method whose signature is being compared with.

sameBaseSignature

public boolean sameBaseSignature(Method m)
Return TRUE if the base signature of the specified method matches that of this method; otherwise, return FALSE. For them to match, the methods must have the same short and the same arguments.

Parameters:
m - The method whose base signature is being compared.

getArgumentByName

public Argument getArgumentByName(java.lang.String s)
Return an the argument whose formal name matches the passed in string. Return null if the string does not match anything.


hasPureAssertion

public boolean hasPureAssertion()
Return TRUE if PURE clause appears in the assertions associated with this method; otherwise, return FALSE.


addAssertion

public void addAssertion(Assertion assertion)
                  throws AssertionException
Add the specified assertion to the proper assertion list for this method.

Parameters:
assertion - The assertion to be added.
Throws:
AssertionException - The exception thrown if the assertion is not valid.

getPreconditions

public java.util.ArrayList getPreconditions()
Return the list of preconditions as an ArrayList of Assertion elements.


getPostconditions

public java.util.ArrayList getPostconditions()
Return the list of postconditions as an ArrayList of Assertion elements.


hasReservedMethodAssertion

public boolean hasReservedMethodAssertion(java.util.ArrayList list,
                                          int type)
Return TRUE if the list of assertions has the specified reserved method assertion; FALSE otherwise.


getMaxArrayIterMacros

public int getMaxArrayIterMacros(char type)
Return the number of array iteration macros in the assertions of the method of the specified return type. Valid types are given in MethodCall.java as MACRO_RETURNS_* values.


hasReservedMethodAssertion

public boolean hasReservedMethodAssertion(int type)
Return TRUE if the method has the specified reserved method assertion; FALSE otherwise.


hasUnreservedMethodAssertion

public boolean hasUnreservedMethodAssertion(java.util.ArrayList list,
                                            boolean any)
Return TRUE if the list of assertions has the type of unreserved method assertion; FALSE otherwise.


hasUnreservedMethodAssertion

public boolean hasUnreservedMethodAssertion(boolean any)
Return TRUE if the method has any unreserved method (when any is TRUE) assertion or has an unreserved method assertion with a throws clause (if any is FALSE); otherwise, return FALSE.


getRarrayInfo

public java.util.HashMap getRarrayInfo()
This returns an array list of RarrayInfo objects that contains the info for every rarray index used in this method.


hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

equals

public boolean equals(java.lang.Object o)
Overrides:
equals in class java.lang.Object