Class Compile
- java.lang.Object
-
- com.sun.tools.corba.ee.idl.Compile
-
- Direct Known Subclasses:
Compile
public class Compile extends java.lang.Object
Compiler usage:
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
Fields Modifier and Type Field Description Arguments
arguments
This is the repository of emitter arguments.private java.util.Enumeration<SymtabEntry>
emitList
private ExprFactory
exprFactory
private GenFactory
genFactory
private java.util.Vector<IncludeEntry>
includeEntries
This is a vector of IncludeEntry's.protected java.util.Vector<java.lang.String>
includes
This is a vector of strings of the form "IDLfile" or <IDLfile>.private java.lang.String[]
keywords
private static Noop
noop
protected java.util.Hashtable<java.lang.String,java.lang.String>
overrideNames
This hashtable contains <real name, alias> pairs.private Parser
parser
private Preprocessor
preprocessor
protected java.util.Hashtable<java.lang.String,SymtabEntry>
symbolTable
This is the symbol table.private SymtabFactory
symtabFactory
-
Constructor Summary
Constructors Constructor Description Compile()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
displayVersion()
Write the version number of this compiler to standard out.protected Factories
factories()
protected void
generate()
Invoke the generators.protected void
init(java.lang.String[] args)
Initialize the framework.private void
initFactories()
private void
initGenerators()
static void
main(java.lang.String[] args)
protected java.util.Enumeration
parse()
Parse the IDL file and return an enumeration of the symbols to be generated.void
start(java.lang.String[] args)
Start the parse/code generation process.
-
-
-
Field Detail
-
arguments
public Arguments arguments
This is the repository of emitter arguments.
-
overrideNames
protected java.util.Hashtable<java.lang.String,java.lang.String> 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
protected java.util.Hashtable<java.lang.String,SymtabEntry> 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
protected java.util.Vector<java.lang.String> 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
private java.util.Vector<IncludeEntry> 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
private static Noop noop
-
genFactory
private GenFactory genFactory
-
symtabFactory
private SymtabFactory symtabFactory
-
exprFactory
private ExprFactory exprFactory
-
parser
private Parser parser
-
preprocessor
private Preprocessor preprocessor
-
emitList
private java.util.Enumeration<SymtabEntry> emitList
-
keywords
private java.lang.String[] keywords
-
-
Method Detail
-
main
public static void main(java.lang.String[] args)
-
factories
protected Factories factories()
-
init
protected void init(java.lang.String[] args) throws InvalidArgument
Initialize the framework.- Parameters:
args
- command line arguments- Throws:
InvalidArgument
-
parse
protected java.util.Enumeration parse() throws java.io.IOException
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:
java.io.IOException
- if there was an error reading the file
-
generate
protected void generate()
Invoke the generators.
-
start
public void start(java.lang.String[] args)
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.
-
-