gov.llnl.babel.backend.fortran
Class Fortran

java.lang.Object
  extended by gov.llnl.babel.backend.fortran.Fortran
All Implemented Interfaces:
CodeConstants

public class Fortran
extends java.lang.Object
implements CodeConstants

Provide a collection of static methods to provide the mapping of sidl concepts into FORTRAN. This class provides the mapping of symbol names to FORTRAN symbols, the mapping of the wrapper code to a set of files, and the mapping of types.


Field Summary
static java.lang.String s_return
           
 
Fields inherited from interface gov.llnl.babel.backend.CodeConstants
C_AUTO_GEN_SPLICER, C_AUTO_GEN_WARNING, C_BACKSLASH, C_BEGIN_UNREFERENCED_METHODS, C_COMMENT_CLOSE, C_COMMENT_DOC_OPEN, C_COMMENT_F77, C_COMMENT_F90, C_COMMENT_HASH, C_COMMENT_OPEN, C_COMMENT_SLASH, C_COMMENT_SUBSEQUENT, C_DEFINE, C_DESC_CJNI_PREFIX, C_DESC_HEADER_PREFIX, C_DESC_IMPL_PREFIX, C_DESC_IOR_PREFIX, C_DESC_SJNI_PREFIX, C_DESC_SKEL_PREFIX, C_DESC_STUB_PREFIX, C_END_UNREFERENCED_METHODS, C_F77_IMPL_EXTENSION, C_F77_IMPL_METHOD_SUFFIX, C_F77_METHOD_SUFFIX, C_F77_VERSION, C_F7731_IMPL_EXTENSION, C_F90_ALT_SUFFIX, C_F90_IMPL_EXTENSION, C_F90_IMPL_METHOD_SUFFIX, C_F90_METHOD_SUFFIX, C_F90_VERSION, C_FORTRAN_DESC_STUB_PREFIX, C_FORTRAN_IMPL_MODULE_PREFIX, C_FORTRAN_MODULE_PREFIX, C_FORTRAN_TYPE_MODULE_PREFIX, C_GUARD_CLOSE, C_GUARD_OPEN, C_HASH, C_IFDEFINE_CLOSE, C_IFDEFINE_CXX, C_IFDEFINE_OPEN, C_INCLUDE, C_INSERT_HERE, C_INT_BACKSLASH, C_IS_IMPL, C_IS_NOT_IMPL, C_SLASH, C_UNREFERENCED_COMMENT1, C_UNREFERENCED_COMMENT2, C_UNREFERENCED_COMMENT3, MATLAB_COMMENT_OPEN
 
Method Summary
static java.lang.String arrayIndices(java.util.List indices)
           
static java.lang.String arrayIOR(Context context)
           
static Method connectRemoteMethod(Extendable ext, Context context, boolean isF90)
           
static Method createCast(Context context, SymbolID id)
           
static Method createCastTwo(Context context, SymbolID id)
           
static Method createRemoteMethod(Extendable ext, Context context, boolean isF90)
           
static java.util.Set generateStubIncludes(LanguageWriterForC writer, Extendable ext)
          Generates include directives for all the Babel clases used in this fortran stub or skel
static java.lang.String getAltStubName(SymbolID id, Method method)
          Get the function name that should be used for the FORTRAN stubs to the sidl object methods.
static java.lang.String getAltSuffix()
          Return the appropriate FORTRAN alternative stub name.
static java.lang.String getArrayConstructor(SymbolID id, Context context)
          Generate the name of the array constructor function.
static java.lang.String getArrayDestructor(SymbolID id, Context context)
          Generate the name of the array destructor function.
static java.lang.String getArrayDimen(SymbolID id, Context context)
          Generate the name of the array dimension access function.
static java.lang.String getArrayFile(SymbolID id)
           
static java.lang.String getArrayGet(SymbolID id, Context context)
          Generate the name of the array get element function.
static java.lang.String getArrayGet(SymbolID id, int numArgs, Context context)
          Generate the name of the array get element function.
static java.lang.String getArrayLength(SymbolID id, Context context)
          Generate the name of the array length access function.
static java.lang.String getArrayLower(SymbolID id, Context context)
          Generate the name of the array lower bound access function.
static java.lang.String getArrayModule(SymbolID id)
           
static java.lang.String getArrayName(SymbolID id, int dim)
           
static java.lang.String getArraySet(SymbolID id, Context context)
          Generate the name of the array set element function.
static java.lang.String getArraySet(SymbolID id, int numArgs, Context context)
          Generate the name of the array set element function.
static java.lang.String getArrayUpper(SymbolID id, Context context)
          Generate the name of the array upper bound access function.
static java.lang.String getDelRefArray(Type arrayType)
           
static java.lang.String getEnsureArray(Type arrayType)
           
static java.lang.String getEnumStubFile(SymbolID id)
          Return the name of the stub file for a particular enumeration.
static java.lang.String getEnumStubImpl(SymbolID id)
          Return the name of the stub impl file for a particular enumeration.
static java.lang.String getExtendedMethodName(SymbolID id, java.lang.String baseName)
          Return the extended function name (i.e., one with the full name prepended).
static java.lang.String getFortranPrefix(Context context)
          Return the sidl Fortran prefix for macros and types.
static java.lang.String getFortranSymbol(Context context)
          Return the appropriate version of SIDLFortran##Symbol.
static java.lang.String getFortranTypeInC(Type type, Context context)
          Return the C type corresponding to the FORTRAN type corresponding to a particular sidl type.
static int getFortranVersion(Context context)
          Return the appropriate version of Fortran (i.e., 77 or 90).
static java.lang.String getHeaderFile(SymbolID id)
          Return the name of the stub header file for a particular symbol.
static java.lang.String getImplExtension(Context context)
          Return the appropriate FORTRAN extension.
static java.lang.String getImplFile(SymbolID id, Context context)
          Return the name of the file that hold the implementation of the FORTRAN sidl object.
static java.lang.String getImplMethodSuffix(Context context)
          Return the appropriate FORTRAN impl method name suffix based.
static java.lang.String getImplModuleFile(SymbolID id, Context context)
          Return the name of the file that hold the derived types for implementation of the FORTRAN sidl object.
static java.lang.String getInitArray(Type arrayType)
           
static java.lang.String getMethodImplName(SymbolID id, Method method, NameMangler mang, Context context)
          Return the function name that should be used for the FORTRAN subroutine that implements a particular method.
static java.lang.String getMethodSkelName(SymbolID id, Method method)
          Return the C function name that should be used for the skeleton method.
static java.lang.String getMethodStubName(SymbolID id, Method method, Context context)
          Get the function name that should be used for the FORTRAN stubs to the sidl object methods.
static java.lang.String getMethodSuffix(Context context)
          Return the appropriate FORTRAN method name suffix based on the version.
static java.lang.String getMethodSuperImplName(SymbolID id, Method method, NameMangler mang, Context context)
          Return the function name that should be used for the FORTRAN subroutine that implements a particular SUPER method.
static java.lang.String getMethodSuperName(SymbolID id, Method method, NameMangler mang, Context context)
          Get the function name that should be used for the FORTRAN super method in the skels (availible in this Impls).
static java.lang.String getModule(SymbolID id)
           
static java.lang.String getModuleFile(SymbolID id)
          Return the name of the F90 stub module file for a particular symbol.
static java.lang.String getReturnString(Type type, Context context)
          Return the FORTRAN type declaration corresponding to type, a particular sidl type.
static java.lang.String getSkelFile(SymbolID id)
          Return the name of the file that holds the implementation of the skeletons for FORTRAN.
static java.lang.String getStructModuleFile(SymbolID id, Context context)
          Return the name of the file that hold the derived types for Fortran/BindC to C/C++ interoperability.
static java.lang.String getStubDocFile(SymbolID id)
          Return the name of the F77 stub documentation file for a particular symbol.
static java.lang.String getStubFile(SymbolID id)
          Return the name of the stub file for a particular symbol.
static java.lang.String getStubNameFile(SymbolID id)
           
static java.lang.String getSymbolName(SymbolID id)
          Convert a symbol name into string with the pieces of the symbol joined together with underline characters.
static java.lang.String getSymbolNameForFile(SymbolID id)
          Convert a symbol name into string with the pieces of the symbol joined together with underline characters.
static java.lang.String getSymbolNameForFile(SymbolID id, boolean isImpl, Context context)
          Same as above method, but use an extra argument for determining when the file whose name is to be generated corresponds to an impl.
static java.lang.String getTypeFile(SymbolID id)
          Return the name of the F90 type module file for a particular symbol.
static java.lang.String getTypeModule(SymbolID id)
           
static java.lang.String getTypeName(SymbolID id)
           
static boolean hasBindC(Context context)
           
static boolean hasDirectAccess(Type t)
           
static boolean isFortran7731(Context context)
           
static boolean isFortran90(Context context)
           
static boolean needsAbbrev(Context context)
           
static java.util.List reorderArguments(java.util.List args)
          Reorder an argument list to guarantee that all raw arrays occur at the end of the argument list.
static java.lang.String structSerializeStub(SymbolID id, boolean serialize)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

s_return

public static final java.lang.String s_return
See Also:
Constant Field Values
Method Detail

getSymbolName

public static java.lang.String getSymbolName(SymbolID id)
Convert a symbol name into string with the pieces of the symbol joined together with underline characters.

Parameters:
id - the symbol id to convert.
Returns:
a string representation of the symbol with periods replaced with underline characters.

getSymbolNameForFile

public static java.lang.String getSymbolNameForFile(SymbolID id)
Convert a symbol name into string with the pieces of the symbol joined together with underline characters. Generate short file names if the options for generating code in package-dependent subdirectories and excluding external symbols are enabled (--generate-subdirs and --exclude-external).

Parameters:
id - the symbol id to convert.
Returns:
a string representation of the symbol with periods replaced with underline characters.

getSymbolNameForFile

public static java.lang.String getSymbolNameForFile(SymbolID id,
                                                    boolean isImpl,
                                                    Context context)
Same as above method, but use an extra argument for determining when the file whose name is to be generated corresponds to an impl.


getStubFile

public static java.lang.String getStubFile(SymbolID id)
Return the name of the stub file for a particular symbol. The stub file is a C file that receives calls from FORTRAN client.

Parameters:
id - the symbol whose stub file will be returned
Returns:
the filename of a C file containing the implementation of the FORTRAN stubs.

getStubNameFile

public static java.lang.String getStubNameFile(SymbolID id)

getHeaderFile

public static java.lang.String getHeaderFile(SymbolID id)
Return the name of the stub header file for a particular symbol. The stub header file is a C file that globablly externs a few special functions in the fStub.

Parameters:
id - the symbol whose stub file will be returned
Returns:
the filename of a C file containing the implementation of the FORTRAN stubs.

getStubDocFile

public static java.lang.String getStubDocFile(SymbolID id)
Return the name of the F77 stub documentation file for a particular symbol. The documentation file is FORTRAN pseudo-code to document the calling interface for FORTRAN clients.

Parameters:
id - the symbol whose stub documentation file will be returned
Returns:
the filename of a text file containing the documentation of the FORTRAN stubs.

getModuleFile

public static java.lang.String getModuleFile(SymbolID id)
Return the name of the F90 stub module file for a particular symbol. The module file is an F90 file used to package "global data, derived types and their associated operations, interface blocks, and namelist groups."

Parameters:
id - the symbol whose stub documentation file will be returned
Returns:
the filename of a text file containing the documentation of the FORTRAN stubs.

getTypeFile

public static java.lang.String getTypeFile(SymbolID id)
Return the name of the F90 type module file for a particular symbol. The module file is an F90 file used to package the derived type for the symbol.

Parameters:
id - the symbol whose stub documentation file will be returned
Returns:
the filename of a text file containing the documentation of the FORTRAN stubs.

getTypeModule

public static java.lang.String getTypeModule(SymbolID id)

getArrayModule

public static java.lang.String getArrayModule(SymbolID id)

getArrayFile

public static java.lang.String getArrayFile(SymbolID id)

getTypeName

public static java.lang.String getTypeName(SymbolID id)

getArrayName

public static java.lang.String getArrayName(SymbolID id,
                                            int dim)

getModule

public static java.lang.String getModule(SymbolID id)

reorderArguments

public static java.util.List reorderArguments(java.util.List args)
Reorder an argument list to guarantee that all raw arrays occur at the end of the argument list. The relative position of non-raw arrays arguments is unchanged by this function.

Parameters:
args - the incoming list of arguments
Returns:
the incoming list has been reordered such that all raw arrays appear at the end.

structSerializeStub

public static java.lang.String structSerializeStub(SymbolID id,
                                                   boolean serialize)

arrayIndices

public static java.lang.String arrayIndices(java.util.List indices)

hasDirectAccess

public static boolean hasDirectAccess(Type t)

getEnumStubFile

public static java.lang.String getEnumStubFile(SymbolID id)
Return the name of the stub file for a particular enumeration. The stub file is a DEC FORTRAN include file that defines integer parameters that hold the values of the enumerations.

Parameters:
id - the symbol whose stub file will be returned
Returns:
the filename of a FORTRAN inc file containing the implementation of the FORTRAN stubs.

getEnsureArray

public static java.lang.String getEnsureArray(Type arrayType)

getInitArray

public static java.lang.String getInitArray(Type arrayType)

getDelRefArray

public static java.lang.String getDelRefArray(Type arrayType)

getEnumStubImpl

public static java.lang.String getEnumStubImpl(SymbolID id)
Return the name of the stub impl file for a particular enumeration. The stub file is a C source file that holds the array of enumeration stubs.

Parameters:
id - the symbol whose stub file will be returned
Returns:
the filename of a C file containing the implementation of the FORTRAN enum array stubs.

getSkelFile

public static java.lang.String getSkelFile(SymbolID id)
Return the name of the file that holds the implementation of the skeletons for FORTRAN. The skeleton file is written in C, and it is the glue between the IOR and a FORTRAN.


getImplExtension

public static java.lang.String getImplExtension(Context context)
Return the appropriate FORTRAN extension.

Returns:
the FORTRAN file extension.

getImplFile

public static java.lang.String getImplFile(SymbolID id,
                                           Context context)
Return the name of the file that hold the implementation of the FORTRAN sidl object. The BABEL system generates the subroutine declarations, but the user needs to fill in the subroutine bodies.

Parameters:
id - the name of the symbol
Returns:
the filename for the sidl object implementation.

getImplModuleFile

public static java.lang.String getImplModuleFile(SymbolID id,
                                                 Context context)
Return the name of the file that hold the derived types for implementation of the FORTRAN sidl object.

Parameters:
id - the name of the symbol
Returns:
the filename for the sidl impl module file.

getStructModuleFile

public static java.lang.String getStructModuleFile(SymbolID id,
                                                   Context context)
Return the name of the file that hold the derived types for Fortran/BindC to C/C++ interoperability.

Parameters:
id - the name of the symbol
Returns:
the filename for the sidl struct module file.

getMethodStubName

public static java.lang.String getMethodStubName(SymbolID id,
                                                 Method method,
                                                 Context context)
Get the function name that should be used for the FORTRAN stubs to the sidl object methods. This method does not take into account the compiler specific issues (i.e. whether the symbol should be all upper or lower case or whether it has underscores appended); it provides the starting name with potentially mixed case.

Parameters:
id - the name of the symbol who has the method.
method - information about the method to be named.
Returns:
the name of the function to be used in the FORTRAN stub.

getAltStubName

public static java.lang.String getAltStubName(SymbolID id,
                                              Method method)
Get the function name that should be used for the FORTRAN stubs to the sidl object methods. This method does not take into account the compiler specific issues (i.e. whether the symbol should be all upper or lower case or whether it has underscores appended); it provides the starting name with potentially mixed case.

Parameters:
id - the name of the symbol who has the method.
method - information about the method to be named.
Returns:
the name of the function to be used in the FORTRAN stub.

getMethodSuperName

public static java.lang.String getMethodSuperName(SymbolID id,
                                                  Method method,
                                                  NameMangler mang,
                                                  Context context)
                                           throws CodeGenerationException
Get the function name that should be used for the FORTRAN super method in the skels (availible in this Impls). This method does not take into account the compiler specific issues (i.e. whether the symbol should be all upper or lower case or whether it has underscores appended); it provides the starting name with potentially mixed case.

Parameters:
id - the name of the symbol who has the method.
method - information about the method to be named.
Returns:
the name of the function to be used in the FORTRAN stub.
Throws:
CodeGenerationException

getFortranVersion

public static int getFortranVersion(Context context)
Return the appropriate version of Fortran (i.e., 77 or 90).

Returns:
the version of Fortran being generated

getMethodSuffix

public static java.lang.String getMethodSuffix(Context context)
Return the appropriate FORTRAN method name suffix based on the version.

Returns:
the FORTRAN method name suffix.

getAltSuffix

public static java.lang.String getAltSuffix()
Return the appropriate FORTRAN alternative stub name.

Returns:
the FORTRAN method name suffix.

getImplMethodSuffix

public static java.lang.String getImplMethodSuffix(Context context)
Return the appropriate FORTRAN impl method name suffix based.

Returns:
the FORTRAN impl method name suffix.

getFortranSymbol

public static java.lang.String getFortranSymbol(Context context)
Return the appropriate version of SIDLFortran##Symbol.

Returns:
the appropriate version of SIDLFortran##Symbol.

getArrayDestructor

public static java.lang.String getArrayDestructor(SymbolID id,
                                                  Context context)
Generate the name of the array destructor function.


getArrayConstructor

public static java.lang.String getArrayConstructor(SymbolID id,
                                                   Context context)
Generate the name of the array constructor function.


getArraySet

public static java.lang.String getArraySet(SymbolID id,
                                           Context context)
Generate the name of the array set element function.


getArraySet

public static java.lang.String getArraySet(SymbolID id,
                                           int numArgs,
                                           Context context)
Generate the name of the array set element function.


getArrayGet

public static java.lang.String getArrayGet(SymbolID id,
                                           Context context)
Generate the name of the array get element function.


getArrayGet

public static java.lang.String getArrayGet(SymbolID id,
                                           int numArgs,
                                           Context context)
Generate the name of the array get element function.


getArrayDimen

public static java.lang.String getArrayDimen(SymbolID id,
                                             Context context)
Generate the name of the array dimension access function.


getArrayLower

public static java.lang.String getArrayLower(SymbolID id,
                                             Context context)
Generate the name of the array lower bound access function.


getArrayUpper

public static java.lang.String getArrayUpper(SymbolID id,
                                             Context context)
Generate the name of the array upper bound access function.


getArrayLength

public static java.lang.String getArrayLength(SymbolID id,
                                              Context context)
Generate the name of the array length access function.


getMethodImplName

public static java.lang.String getMethodImplName(SymbolID id,
                                                 Method method,
                                                 NameMangler mang,
                                                 Context context)
                                          throws CodeGenerationException
Return the function name that should be used for the FORTRAN subroutine that implements a particular method. The returned string leaves the cast of the components of the name unchanged. If id and the method name have mixed case, this method returns a mixed case string.

Parameters:
id - the name of the symbol who has the method.
method - the information about the method.
mang - the name mangler being used to address long names.
Returns:
the name of the FORTRAN subroutine that implements this method.
Throws:
CodeGenerationException - the name mangler is broken.

getExtendedMethodName

public static java.lang.String getExtendedMethodName(SymbolID id,
                                                     java.lang.String baseName)
Return the extended function name (i.e., one with the full name prepended).

Parameters:
id - the name of the symbol who has the method.
baseName - the base method name.
Returns:
the name of the FORTRAN subroutine that implements this method.

getMethodSuperImplName

public static java.lang.String getMethodSuperImplName(SymbolID id,
                                                      Method method,
                                                      NameMangler mang,
                                                      Context context)
                                               throws CodeGenerationException
Return the function name that should be used for the FORTRAN subroutine that implements a particular SUPER method. The returned string leaves the cast of the components of the name unchanged. If id and the method name have mixed case, this method returns a mixed case string.

Parameters:
id - the name of the symbol who has the method.
method - the information about the method.
mang - the name mangler being used to address long names.
Returns:
the name of the FORTRAN subroutine that implements this method.
Throws:
CodeGenerationException - the name mangler is broken.

getMethodSkelName

public static java.lang.String getMethodSkelName(SymbolID id,
                                                 Method method)
Return the C function name that should be used for the skeleton method. This is a C function that is called by the IOR.

Parameters:
id - the name of the symbol who has the method
method - information about the method.
Returns:
the name of the C skeleton function.

getFortranTypeInC

public static java.lang.String getFortranTypeInC(Type type,
                                                 Context context)
                                          throws CodeGenerationException
Return the C type corresponding to the FORTRAN type corresponding to a particular sidl type. This is the type that a C subroutine would need to pass to FORTRAN, or the type that a C subroutine could expect to receive from a FORTRAN caller.

Parameters:
type - the sidl type description.
Returns:
the C type corresponding to the FORTRAN type corresponding to the sidl type.
Throws:
CodeGenerationException - the type is unsupported.

getFortranPrefix

public static java.lang.String getFortranPrefix(Context context)
Return the sidl Fortran prefix for macros and types.

Returns:
the sidl Fortran prefix

needsAbbrev

public static boolean needsAbbrev(Context context)

isFortran90

public static boolean isFortran90(Context context)

hasBindC

public static boolean hasBindC(Context context)

isFortran7731

public static boolean isFortran7731(Context context)

arrayIOR

public static java.lang.String arrayIOR(Context context)

createCast

public static Method createCast(Context context,
                                SymbolID id)

createCastTwo

public static Method createCastTwo(Context context,
                                   SymbolID id)
                            throws CodeGenerationException
Throws:
CodeGenerationException

getReturnString

public static java.lang.String getReturnString(Type type,
                                               Context context)
                                        throws CodeGenerationException
Return the FORTRAN type declaration corresponding to type, a particular sidl type.

Parameters:
type - a sidl type description.
Returns:
the FORTRAN type used to some something of the given sidl type.
Throws:
CodeGenerationException - the type is unsupported.

generateStubIncludes

public static java.util.Set generateStubIncludes(LanguageWriterForC writer,
                                                 Extendable ext)
                                          throws CodeGenerationException
Generates include directives for all the Babel clases used in this fortran stub or skel

Parameters:
writer - Language writer for C
ext - Extendible (Class or Interface) to generate dependencies
Throws:
CodeGenerationException

createRemoteMethod

public static Method createRemoteMethod(Extendable ext,
                                        Context context,
                                        boolean isF90)

connectRemoteMethod

public static Method connectRemoteMethod(Extendable ext,
                                         Context context,
                                         boolean isF90)