gov.llnl.babel.backend.fortran
Class StubSource

java.lang.Object
  extended by gov.llnl.babel.backend.fortran.StubSource

public class StubSource
extends java.lang.Object

This class generates the C code that sits between a FORTRAN client and the internal object representation (IOR) of a sidl object/interface. For each method, this generates a C function that will be called from FORTRAN. This C function massages the arguments from Fortran, calls the IOR, massages the out values from the IOR call, and returns the outgoing values to the Fortran caller.


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
StubSource(LanguageWriter writer, Context context)
          Create an object to generate the stub code for a sidl class/interface.
 
Method Summary
static java.lang.String charCheck(Context context)
          An #ifdef to check whether character argument should be treated like strings.
static boolean comma(LanguageWriter writer, boolean needComma)
          Write a comma and newline to writer iff needComma is true.
static java.util.List convertRarrayToArray(java.util.List args, Context context)
          Convert any rarray arguments to normal array arguments.
static boolean declareArgument(LanguageWriter writer, java.lang.String argName, Type argType, boolean needComma, Context context, Method method)
          Write an argument declaration in C for an argument being passed in from a FORTRAN caller or from C to a FORTRAN subroutine.
static java.util.List extendArgs(SymbolID selfId, Method m, Context context, boolean indices)
          Add extra arguments to the original argument list of a method as needed for the self pointer, the return value and the exception argument.
static java.util.Set extendedReferences(Extendable ext, Context context)
          Generate the expanded set of referenced SymbolID's.
 void generateCode(Symbol symbol)
          Generate a C file to provide FORTRAN stubs for a sidl object/interface.
static void generateCode(Symbol ext, LanguageWriter writer, Context context)
          Generate a C file to provide FORTRAN stubs for a sidl object/interface.
 void generateEnum(Enumeration enm)
          Generate a FORTRAN include file containing integer constants for the members of an enumerated type.
static void generateIncludes(LanguageWriterForC writer, Extendable ext, Context context)
          Generate a sequence of #include preprocessor directives required by the stub.
static void generateMethodSymbol(LanguageWriter writer, java.lang.String methodName, Context context, Type type, boolean fromSkelFunc)
          Generate the compiler independent form of the function name.
static void generateSignature(LanguageWriter writer, java.lang.String methodName, java.util.List arguments, Context context, Method method, boolean fromSkelFunc)
          Generate the C signature for a FORTRAN subroutine to be called from C or for a C function to be called from FORTRAN.
 void generateSupers(Class cls)
           
static void generateSupers(Class cls, LanguageWriter writer, Context context)
          This is a convenience utility function specifically for the generation of super "Stub" functions in the Impl files.
static boolean hasProxy(Type t)
          Return true iff the type present requires a proxy.
static boolean isPointer(Type t)
          Return true if a particular sidl type is implemented using a pointer type.
static void writeStructSerializeSig(LanguageWriter writer, SymbolID structid, boolean serialize)
           
 
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++. In FORTRAN, the object has to be passed explicitly.

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

StubSource

public StubSource(LanguageWriter writer,
                  Context context)
Create an object to generate the stub code for a sidl class/interface. This is frequently called from generateCode rather than used directly.

Parameters:
writer - the stub code is generated to this output device.
Method Detail

charCheck

public static final java.lang.String charCheck(Context context)
An #ifdef to check whether character argument should be treated like strings.


generateSupers

public static void generateSupers(Class cls,
                                  LanguageWriter writer,
                                  Context context)
                           throws CodeGenerationException
This is a convenience utility function specifically for the generation of super "Stub" functions in the Impl files. The output stream is not closed on exit. A code generation exception is thrown if an error is detected.

Parameters:
cls - The class in which these supers are to be generated
writer - the output writer to which the stub source will be written. This will not be closed.
Throws:
CodeGenerationException - this is a catch all exception. It can be caused by I/O trouble or violations of the data type invariants.

generateSupers

public void generateSupers(Class cls)
                    throws CodeGenerationException
Throws:
CodeGenerationException

comma

public static boolean comma(LanguageWriter writer,
                            boolean needComma)
Write a comma and newline to writer iff needComma is true. This always returns false.

Parameters:
writer - the device to which the comma should be output.
needComma - If true, this method will write a comma followed by a newline; otherwise, this method takes no action.
Returns:
false is always returned.

declareArgument

public static boolean declareArgument(LanguageWriter writer,
                                      java.lang.String argName,
                                      Type argType,
                                      boolean needComma,
                                      Context context,
                                      Method method)
                               throws CodeGenerationException
Write an argument declaration in C for an argument being passed in from a FORTRAN caller or from C to a FORTRAN subroutine.

Parameters:
writer - the place where the code is generated.
argName - the formal name of the argument.
argType - the type of the argument.
needComma - whether a comma is needed or not.
Returns:
true means a comma is needed before the next argument; false means a comma is not needed.
Throws:
CodeGenerationException - the type of the argument is unsupported.

generateMethodSymbol

public static void generateMethodSymbol(LanguageWriter writer,
                                        java.lang.String methodName,
                                        Context context,
                                        Type type,
                                        boolean fromSkelFunc)
                                 throws CodeGenerationException
Generate the compiler independent form of the function name.

Parameters:
writer - the place where the symbol is written
methodName - the potentially mixed case form of the function name.
Throws:
CodeGenerationException

generateSignature

public static void generateSignature(LanguageWriter writer,
                                     java.lang.String methodName,
                                     java.util.List arguments,
                                     Context context,
                                     Method method,
                                     boolean fromSkelFunc)
                              throws CodeGenerationException
Generate the C signature for a FORTRAN subroutine to be called from C or for a C function to be called from FORTRAN. This uses a set of preprocessor macros to handle the conventions of the FORTRAN compiler.

Parameters:
writer - the place where the signature is written.
methodName - the name of the function.
arguments - a list of Argument objects.
fromSkelFunc - Need different logic to deal with Fortran Functions in the skel file.
Throws:
CodeGenerationException - something went wrong -- probably an unsupported type.

hasProxy

public static boolean hasProxy(Type t)
Return true iff the type present requires a proxy. A proxy is required when the FORTRAN types is not directly compatible with the C type for a particular sidl type.

Parameters:
t - the sidl type description
Returns:
true means that t requires a proxy; false means that t does not require a proxy.

isPointer

public static boolean isPointer(Type t)
Return true if a particular sidl type is implemented using a pointer type.

Parameters:
t - the sidl type description.
Returns:
true means the type is implemented using a pointer type; false means the type is not implemented using a pointer type.

convertRarrayToArray

public static java.util.List convertRarrayToArray(java.util.List args,
                                                  Context context)
Convert any rarray arguments to normal array arguments.


extendArgs

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

Parameters:
selfId - the name of the class/interface who owns the method.
m - the method whose argument list will be extended.
indices - If true, get the argument list including rarray indices. Should be true for places that support rarrays.
Throws:
CodeGenerationException - a catch all exception for problems in the code generation phase.

extendedReferences

public static java.util.Set extendedReferences(Extendable ext,
                                               Context context)
                                        throws CodeGenerationException
Generate the expanded set of referenced SymbolID's. This includes sidl.BaseException if any of the methods throws an exception.

Parameters:
ext - the class or interface to generate includes for.
Throws:
CodeGenerationException - a catch all exception for problems in the code generation phase.

generateIncludes

public static void generateIncludes(LanguageWriterForC writer,
                                    Extendable ext,
                                    Context context)
                             throws CodeGenerationException
Generate a sequence of #include preprocessor directives required by the stub.

Parameters:
writer - the output device where output is sent.
ext - the class or interface to generate includes for.
Throws:
CodeGenerationException - a catch all exception for problems in the code generation phase.

generateEnum

public void generateEnum(Enumeration enm)
                  throws CodeGenerationException
Generate a FORTRAN include file containing integer constants for the members of an enumerated type.

Parameters:
enm - an enumeration object to provide an include file for.
Throws:
CodeGenerationException - a catch all exception to indicate problems during the code generation phase of the sidl processing.

generateCode

public void generateCode(Symbol symbol)
                  throws CodeGenerationException
Generate a C file to provide FORTRAN stubs for a sidl object/interface. The stubs allow FORTRAN clients to make calls on objects and interfaces or static methods. No stub code is generated enumerated types and packages. Outside clients typically use generateCode instead of calling this method directly.

Parameters:
symbol - the symbol for which stubs will be generated.
Throws:
CodeGenerationException - a catch all exception to indicate problems during the code generation phase of the sidl processing.

generateCode

public static void generateCode(Symbol ext,
                                LanguageWriter writer,
                                Context context)
                         throws CodeGenerationException
Generate a C file to provide FORTRAN stubs for a sidl object/interface. The stubs allow FORTRAN clients to make calls on objects and interfaces or static methods. No stub code is generated enumerated types and packages.

Parameters:
ext - the symbol for which stubs will be generated.
writer - the output device where the stub should be written.
Throws:
CodeGenerationException - a catch all exception to indicate problems during the code generation phase of the sidl processing.

writeStructSerializeSig

public static void writeStructSerializeSig(LanguageWriter writer,
                                           SymbolID structid,
                                           boolean serialize)
                                    throws CodeGenerationException
Throws:
CodeGenerationException