gov.llnl.babel.backend
Class Utilities

java.lang.Object
  extended by gov.llnl.babel.backend.Utilities

public class Utilities
extends java.lang.Object

The Utilities class contains a variety of common utility functions, such as sorting a collection of data or determining the maximum string width of a collection of data.


Field Summary
static java.lang.String s_exception
          The argument name that holds the exception pointer which a method may throw an exception.
static java.lang.String s_self
          The argument name that holds the object/interface pointer in a call to an object method.
 
Constructor Summary
Utilities()
           
 
Method Summary
static java.lang.String capitalize(java.lang.String str)
           
static java.util.Collection convertIdsToSymbols(Context context, java.util.Collection symbolIDs)
          Convert a collection of SymbolID objects into a collection of Symbol objects using the symbol table.
static java.util.List extendArgs(SymbolID selfId, Method m, boolean indices, Context context)
          Add extra arguments to the original argument list of a method as needed for the self pointer and the exception argument.
static java.util.Set getAllParents(Class cls)
          Return all parents of this class, including both class parents and interface parents.
static java.lang.String getEnumInitialization(Context context, SymbolID enumID)
           
static java.lang.String getTypeInitialization(Type type, Context context)
           
static java.util.Set getUniqueInterfaceIDs(Class cls)
          Extract the unique interfaces from this class and return them as a set of SymbolID objects.
static java.util.Set getUniqueInterfaces(Class cls)
          Extract the unique interfaces from this class.
static int getWidth(java.util.Collection collection)
          Determine the maximum width of a set of objects.
static boolean isException(Symbol sym, Context context)
          Return true if and only if the extendable is a class that is the base exception class, is an interface that is the base exception interface, or it has the base exception class or interface in its type ancestry.
static boolean isPointer(Type t)
          Return true if and only if this type is implemented in C by a type that is a pointer.
static Symbol lookupSymbol(Context context, java.lang.String fqn)
          Lookup a symbol entry in the singleton symbol table by fully qualified name.
static Symbol lookupSymbol(Context context, SymbolID id)
          Lookup a symbol entry in the singleton symbol table.
static java.lang.String replace(java.lang.String source, java.lang.String from, java.lang.String to)
          This method allows substring replacement Unfortunately the java.lang.String class has a replace function for characters but not strings.
static java.util.ArrayList sort(java.util.Collection collection)
          Sort a Collection of objects into ascending order and return the sorted list in an ArrayList object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

s_self

public static final java.lang.String s_self
The argument name that holds the object/interface pointer in a call to an object method. It's conceptually like the this pointer in C++.

See Also:
Constant Field Values

s_exception

public static final java.lang.String s_exception
The argument name that holds the exception pointer which a method may throw an exception.

See Also:
Constant Field Values
Constructor Detail

Utilities

public Utilities()
Method Detail

sort

public static java.util.ArrayList sort(java.util.Collection collection)
Sort a Collection of objects into ascending order and return the sorted list in an ArrayList object.


getWidth

public static int getWidth(java.util.Collection collection)
Determine the maximum width of a set of objects. The meaning of "width" depends on the type of object in the collection. Supported types are strings, map entries with a key string, methods, symbols, and symbol identifiers.


getUniqueInterfaces

public static java.util.Set getUniqueInterfaces(Class cls)
Extract the unique interfaces from this class. The unique interfaces are those that belong to this class but do not belong to one of its parents (if they exit). The returned set consists of objects of the type Interface.


getUniqueInterfaceIDs

public static java.util.Set getUniqueInterfaceIDs(Class cls)
Extract the unique interfaces from this class and return them as a set of SymbolID objects.


getAllParents

public static java.util.Set getAllParents(Class cls)
Return all parents of this class, including both class parents and interface parents. The return Set contains the symbol identifiers of all parents.


lookupSymbol

public static Symbol lookupSymbol(Context context,
                                  SymbolID id)
                           throws CodeGenerationException
Lookup a symbol entry in the singleton symbol table. If the symbol does not exist or there is a conflict with an existing symbol, then throw a code generation exception.

Throws:
CodeGenerationException

lookupSymbol

public static Symbol lookupSymbol(Context context,
                                  java.lang.String fqn)
                           throws CodeGenerationException
Lookup a symbol entry in the singleton symbol table by fully qualified name. If the symbol does not exist, then throw a code generation exception.

Throws:
CodeGenerationException

getEnumInitialization

public static java.lang.String getEnumInitialization(Context context,
                                                     SymbolID enumID)
                                              throws CodeGenerationException
Throws:
CodeGenerationException

getTypeInitialization

public static java.lang.String getTypeInitialization(Type type,
                                                     Context context)
                                              throws CodeGenerationException
Throws:
CodeGenerationException

convertIdsToSymbols

public static java.util.Collection convertIdsToSymbols(Context context,
                                                       java.util.Collection symbolIDs)
Convert a collection of SymbolID objects into a collection of Symbol objects using the symbol table.

Parameters:
symbolIDs - a collection of SymbolID objects.
Returns:
a collection of Symbol objects. There is a one-to-one and onto correspondence between elements in the return value and elements in symbolIDs.
See Also:
Symbol, SymbolID

replace

public static java.lang.String replace(java.lang.String source,
                                       java.lang.String from,
                                       java.lang.String to)
This method allows substring replacement Unfortunately the java.lang.String class has a replace function for characters but not strings.

Parameters:
source - The string to do the replacement on
from - The substring to match and replace
to - The new string to insert in place of the matched substring
Returns:
the new string with all instances of "from" replaced by "to"

isPointer

public static boolean isPointer(Type t)
Return true if and only if this type is implemented in C by a type that is a pointer.

Parameters:
t - the type to be evaluated.
Returns:
true is returned if and only if this type is implemented by a type that is a pointer.

extendArgs

public static java.util.List extendArgs(SymbolID selfId,
                                        Method m,
                                        boolean indices,
                                        Context context)
                                 throws CodeGenerationException
Add extra arguments to the original argument list of a method as needed for the self pointer and the exception argument. This makes these implicit arguments explicit and prevents having each of these be a special case throughout the code. The additional arguments are appropriate for the IOR and C binding.

Parameters:
selfId - the name of the class/interface who owns the method.
m - the method whose argument list will be extended.
indices - True if the argument list should include rarray indices. True from C binding.
Throws:
CodeGenerationException - a catch all exception for problems in the code generation phase.

isException

public static boolean isException(Symbol sym,
                                  Context context)
Return true if and only if the extendable is a class that is the base exception class, is an interface that is the base exception interface, or it has the base exception class or interface in its type ancestry.


capitalize

public static java.lang.String capitalize(java.lang.String str)