ILOG JRules

ilog.rules.brl.translation.codegen
Class IlrAbstractCodeGenerator

java.lang.Object
  extended by ilog.rules.brl.translation.codegen.IlrAbstractCodeGenerator
All Implemented Interfaces:
IlrCodeGenerator, IlrIntermediateForm.Visitor
Direct Known Subclasses:
IlrBOMBasedCodeGenerator

public abstract class IlrAbstractCodeGenerator
extends Object
implements IlrCodeGenerator, IlrIntermediateForm.Visitor

Generic base class for Code Generators.

Provides a set of printXXX methods and a simple code generator extension mechanism.


Field Summary
 IlrRuleStatement currentRuleStatement
          Public attribute for the current rule statement cursor.
 
Constructor Summary
IlrAbstractCodeGenerator()
          Creates a new IlrAbstractCodeGenerator.
 
Method Summary
 void addIndent(int count)
          Increments the indentation by the given amount.
 void close()
          Closes the stream.
 void flush()
          Flushes the stream.
 void generateCode(IlrIntermediateForm iform, Writer writer)
          Generates the code for the specified IlrIntermediateForm instance, and into the provided writer.
 IlrCodeGeneratorExtender getExtender(IlrSyntaxTree.Node node)
          Returns the extender registered for the grammar node of node.
 int getIndent()
          Gets the indentation multiplied by the indent size.
 int getIndentSize()
          Gets the indent size.
 IlrTranslationSupport getTranslationSupport()
          Gets the translation support.
 IlrBRLTranslator getTranslator()
          Returns the translator of this code generator.
 IlrVocabulary getVocabulary()
          Returns the vocabulary.
 boolean ignoreNewline()
          Returns the value of the IgnoreLine flag.
 void ignoreNewline(boolean flag)
          Sets the IgnoreNewline flag.
 void indent()
          Prints getIndent() white spaces.
 void indent(int count)
          Prints the given number of white spaces.
 void newline()
          Prints a newline.
 void print(char ch)
          Prints a character.
 void print(String text)
          Prints a string.
 void println(String str)
          Prints a string followed by a newline.
 boolean reportDuplicateVariables()
          This method returns whether this code generator should reprot duplicate variables
 void reportDuplicateVariables(boolean flag)
          this method set whether this code generator should report duplicate variables
protected  void reset()
          Resets this code generator and prepare it for a new code generation.
 void setIndentSize(int size)
          Sets the indent size.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface ilog.rules.brl.translation.codegen.IlrCodeGenerator
getTargetLanguage, setTranslator
 
Methods inherited from interface ilog.rules.brl.translation.IlrIntermediateForm.Visitor
visit, visit, visit, visit, visit, visit, visit, visit, visit
 

Field Detail

currentRuleStatement

public IlrRuleStatement currentRuleStatement
Public attribute for the current rule statement cursor.

Constructor Detail

IlrAbstractCodeGenerator

public IlrAbstractCodeGenerator()
Creates a new IlrAbstractCodeGenerator.

Method Detail

reset

protected void reset()
Resets this code generator and prepare it for a new code generation.


generateCode

public void generateCode(IlrIntermediateForm iform,
                         Writer writer)
Generates the code for the specified IlrIntermediateForm instance, and into the provided writer.

Specified by:
generateCode in interface IlrCodeGenerator
Parameters:
iform - The intermediate form.
writer - The writer.

reportDuplicateVariables

public void reportDuplicateVariables(boolean flag)
this method set whether this code generator should report duplicate variables


reportDuplicateVariables

public boolean reportDuplicateVariables()
This method returns whether this code generator should reprot duplicate variables

Returns:
true if this code generator reports duplicate variables and false otherwise

getTranslator

public IlrBRLTranslator getTranslator()
Returns the translator of this code generator.

Specified by:
getTranslator in interface IlrCodeGenerator
Returns:
The translator of this code generator.

getTranslationSupport

public IlrTranslationSupport getTranslationSupport()
Gets the translation support.

Returns:
The translation support.

getVocabulary

public IlrVocabulary getVocabulary()
Returns the vocabulary.

Returns:
The vocabulary.

getExtender

public IlrCodeGeneratorExtender getExtender(IlrSyntaxTree.Node node)
Returns the extender registered for the grammar node of node.

Parameters:
node - The node.
Returns:
The code generator extender, or null if no code generator extender has been registered for this node.

print

public void print(String text)
Prints a string.

Parameters:
text - The string to print.

println

public void println(String str)
Prints a string followed by a newline.

Parameters:
str - The string to print.

print

public void print(char ch)
Prints a character.

Parameters:
ch - The character to print.

indent

public void indent(int count)
Prints the given number of white spaces.

Parameters:
count - The number of white space characters to print.

indent

public void indent()
Prints getIndent() white spaces.


getIndent

public int getIndent()
Gets the indentation multiplied by the indent size.


addIndent

public void addIndent(int count)
Increments the indentation by the given amount.

Parameters:
count - The amount by which the indentation is to be increased.

setIndentSize

public void setIndentSize(int size)
Sets the indent size.

Parameters:
size - The size of the indent.

getIndentSize

public int getIndentSize()
Gets the indent size.

Returns:
The size of the indent.

newline

public void newline()
Prints a newline.


ignoreNewline

public void ignoreNewline(boolean flag)
Sets the IgnoreNewline flag.

When true, the newLine property is not taken in account by the printToken() methods.

Parameters:
flag - The new value for the IgnoreNewline flag.

ignoreNewline

public boolean ignoreNewline()
Returns the value of the IgnoreLine flag.

Returns:
The value of the IgnoreLine flag.
See Also:
ignoreNewline(boolean)

flush

public void flush()
Flushes the stream.


close

public void close()
Closes the stream.


ILOG JRules