gov.llnl.babel.backend

Class 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 String
s_exception
The argument name that holds the exception pointer which a method may throw an exception.
static String
s_self
The argument name that holds the object/interface pointer in a call to an object method.

Method Summary

static String
capitalize(String str)
static Collection
convertIdsToSymbols(Context context, Collection symbolIDs)
Convert a collection of SymbolID objects into a collection of Symbol objects using the symbol table.
static 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 Set
getAllParents(Class cls)
Return all parents of this class, including both class parents and interface parents.
static String
getEnumInitialization(Context context, SymbolID enumID)
static String
getTypeInitialization(Type type, Context context)
static Set
getUniqueInterfaceIDs(Class cls)
Extract the unique interfaces from this class and return them as a set of SymbolID objects.
static Set
getUniqueInterfaces(Class cls)
Extract the unique interfaces from this class.
static int
getWidth(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, 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 String
replace(String source, String from, String to)
This method allows substring replacement Unfortunately the java.lang.String class has a replace function for characters but not strings.
static ArrayList
sort(Collection collection)
Sort a Collection of objects into ascending order and return the sorted list in an ArrayList object.

Field Details

s_exception

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

s_self

public static final 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++.

Method Details

capitalize

public static String capitalize(String str)

convertIdsToSymbols

public static Collection convertIdsToSymbols(Context context,
                                             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

extendArgs

public static 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.

getAllParents

public static 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.

getEnumInitialization

public static String getEnumInitialization(Context context,
                                           SymbolID enumID)
            throws CodeGenerationException

getTypeInitialization

public static String getTypeInitialization(Type type,
                                           Context context)
            throws CodeGenerationException

getUniqueInterfaceIDs

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

getUniqueInterfaces

public static 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.

getWidth

public static int getWidth(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.

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.

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.

lookupSymbol

public static Symbol lookupSymbol(Context context,
                                  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.

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.

replace

public static String replace(String source,
                             String from,
                             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"

sort

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