Class Compile
- Direct Known Subclasses:
Compile
java com.sun.tools.corba.ee.idl.toJava.compile [options] <idl file>
where <idl file> is the name of a file containing IDL definitions, and [options] is any combination of the options listed below. The options and the idl file name can appear in any order.
Options:
- -i <include path>
- By default, the current directory is scanned for included files. This option adds another directory. See also Note 1 below.
- -d <symbol>
- This is equivalent to the following line in an IDL file: #define <symbol>
- -emitAll
- Emit all types, including those found in #included files.
- -v
- Verbose mode.
includes=<path1><path2>;...;<pathN>Note that the path separator character, here shown as a semicolon, is machine dependent. For instance, on Windows 95 this character is a semicolon, on UNIX it is a colon.
Note 2: If you are directly invoking the main method on this class (not
a subclass), then it will only check that the IDL file is syntactically
correct. It does not generate any files. Only extensions to this
framework generate files, therefore an extension must be invoked if you
want files to be generated.
To Extend the compiler:
You only need to extend the compiler if you want it to generate something
other than what it currently generates.
Step 1 - Implement the generator interfaces:
Each generator interface defines one method: generate (Hashtable, XXXEntry, PrintWriter);
- The Hashtable is the symbol table; each element is a SymtabEntry (or a
subclass of SymtabEntry) and is keyed by its fully qualified name;
- XXXEntry is the appropriate entry for the type to be generated. For
example: AttributeGen defines generate (Hashtable, AttributeEntry, PrintWriter);
ConstGen defines generate (Hashtable, ConstEntry, PrintWriter); etc.
- The PrintWriter is a stream to the file being generated. For the
generators called by the compiler framework, this will be null. The
generator is responsible for creating and opening files. But for
generators that are called by other generators - for instance,
MethodGen.generate will most likely be called by InterfaceGen.generate -
this parameter is provided so that the proper file can be written to.
Step 2 - Implement the GenFactory interface:
All of the generators implemented in Step 1 must be created somehow. There
is an interface for a factory, GenFactory, which must be implemented. The
name of this factory must be set in the extension to the Compile class (see
Step 3, below).
Step 3 - Extend Factories:
Extend Factories and override the method genFactory. This
method must return an instance of the factory which you implemented in
step 2. Your extension of this class may also do more, this is only the
minimum. See Factories for more information.
Step 4 - Extend Compile:
Your extension of Compile should contain a minimum of
two methods:
- protected Factories ()
- This method overrides Compile.factories and returns your extension from Step 3.
- public static void main (String[] args)
- This main method must instantiate this class and call its start method.
public class MyCompile extends Compile { protected Factories factories () { return new MyFactories (); } public static void main (String[] args) { MyCompile compile = new MyCompile (); compile.start (args); } }If you would like a bit more control over the processing of the framework, you can replace compile.start with what it calls. But then you also have to handle the exceptions which start handles for you:
public class MyCompile extends Compile { ... public static void main (String[] args) { MyCompile compile = new MyCompile (); try { compile.init (args); java.util.Enumeration emitList = compile.parse (); compile.generate (); } catch (InvalidArgument e) { System.err.println (e); } catch (java.io.IOException e) { System.err.println (e); } } }Note that compile.parse returns an enumeration. This enumerates the SymtabEntry's which should be generated. If the parse method detects errors, it returns null. Note that you do not have to check that `emitList' is valid before calling generate (that's done internally), but if you do any processing between parse and generate, emitList should be checked before executing that code.
-
Field Summary
FieldsModifier and TypeFieldDescriptionThis is the repository of emitter arguments.private Enumeration
<SymtabEntry> private ExprFactory
private GenFactory
private Vector
<IncludeEntry> This is a vector of IncludeEntry's.This is a vector of strings of the form "IDLfile" or <IDLfile>.private String[]
private static Noop
This hashtable contains <real name, alias> pairs.private Parser
private Preprocessor
protected Hashtable
<String, SymtabEntry> This is the symbol table.private SymtabFactory
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected void
Write the version number of this compiler to standard out.protected Factories
protected void
generate()
Invoke the generators.protected void
Initialize the framework.private void
private void
static void
protected Enumeration
parse()
Parse the IDL file and return an enumeration of the symbols to be generated.void
Start the parse/code generation process.
-
Field Details
-
arguments
This is the repository of emitter arguments. -
overrideNames
This hashtable contains <real name, alias> pairs. It is filled in by extenders in cases where they wish to override an IDL type name with some other name. For instance, when mapping to Java, there could be an overrideNames entry of <"TRUE", "true">. NOTE: Do NOT change this variable to a new Hash table. Just add elements to it. -
symbolTable
This is the symbol table. It will be empty until the parse method executes. If errors are encountered, the state of the symbol table is undefined. -
includes
This is a vector of strings of the form "IDLfile" or <IDLfile>. It is a list of the files included in the given IDL file. It will be empty until the parse method executes. If errors are encountered, the state of this vector is undefined. -
includeEntries
This is a vector of IncludeEntry's. It is a list of the files included in the given IDL file. It mirrors the includes vector. It will be empty until the parse method executes. If errors are encountered, the state of this vector is undefined. -
noop
-
genFactory
-
symtabFactory
-
exprFactory
-
parser
-
preprocessor
-
emitList
-
keywords
-
-
Constructor Details
-
Compile
public Compile()
-
-
Method Details
-
main
-
factories
-
init
Initialize the framework.- Parameters:
args
- command line arguments- Throws:
InvalidArgument
-
parse
Parse the IDL file and return an enumeration of the symbols to be generated. All elements of the Enumeration will be extensions of SymtabEntry. If any errors were encountered during parsing, null will be returned.- Returns:
Enumeration
<SymtabEntry
> or null if a non-IO error occured- Throws:
IOException
- if there was an error reading the file
-
generate
protected void generate()Invoke the generators. -
start
Start the parse/code generation process. This method calls init, parse, generate. If more control is desired, rather than call start, those three methods could be called explicitly.- Parameters:
args
- command-line arguments
-
initFactories
private void initFactories() -
initGenerators
private void initGenerators() -
displayVersion
protected void displayVersion()Write the version number of this compiler to standard out.
-