public class TranslateToJava extends Pass
Modifier and Type | Field and Description |
---|---|
static String |
disclaimer
The commented message appearing at the top of all generated files.
|
ast, canAddErrorsAndWarnings, fatalError, root
Constructor and Description |
---|
TranslateToJava(AST ast)
Associates an AST with this pass.
|
Modifier and Type | Method and Description |
---|---|
static void |
compressAndPrint(StringBuffer buffer,
PrintStream out)
Compress the textual representation of an
ASTNode , convert to ASCII hexadecimal, and
write the result to the specified stream. |
void |
generateBoundedQuantifier(QuantifiedConstraintExpression e)
AtLeastQuantifierExpression s and AtMostQuantifierExpression s generate their
code through this method. |
static void |
generateHashingMethods(PrintStream out,
String name)
Generates the
equals(Object) method, which evaluates to true
whenever the two objects are of the same type. |
static void |
generateLearnerBody(PrintStream out,
LearningClassifierExpression lce)
Generate the code that overrides certain methods of
Learner to check types and call themselves on
the unique instance; also declares other methods and fields of the classifier's
implementation. |
static StringBuffer |
generateTypeChecking(String indent,
String name,
String type,
boolean array,
String input,
int line,
String exampleName,
boolean preExtracted)
Generates the code appearing at the beginning of, for example, many classifiers'
Classifier.classify(Object) methods that checks to see if that input
Object has the appropriate type. |
String |
getMethodBody()
Gives access to the
methodBody member variable so that this pass can be invoked
selectively on some subset of a method body. |
static String |
makeTypeReadable(String name)
The value returned by the
Class.getName() method is not recognizable as a type
by javac if the given class is an array; this method produces a representation
that is recognizable by javac . |
static PrintStream |
open(CodeGenerator node)
Create a
PrintStream that writes to a Java file corresponding to the specified
CodeGenerator . |
static PrintStream |
open(String name)
Create a
PrintStream that writes to the specified file. |
void |
run(Argument a)
Runs this pass on all nodes of the indicated type.
|
void |
run(ArrayCreationExpression e)
Runs this pass on all nodes of the indicated type.
|
void |
run(ArrayInitializer e)
Runs this pass on all nodes of the indicated type.
|
void |
run(ArrayType t)
Runs this pass on all nodes of the indicated type.
|
void |
run(AssertStatement s)
Runs this pass on all nodes of the indicated type.
|
void |
run(Assignment e)
Runs this pass on all nodes of the indicated type.
|
void |
run(AST ast)
Runs this pass on all nodes of the indicated type.
|
void |
run(AtLeastQuantifierExpression e)
Runs this pass on all nodes of the indicated type.
|
void |
run(AtMostQuantifierExpression e)
Runs this pass on all nodes of the indicated type.
|
void |
run(BinaryConstraintExpression e)
Runs this pass on all nodes of the indicated type.
|
void |
run(BinaryExpression be)
Runs this pass on all nodes of the indicated type.
|
void |
run(Block b)
Runs this pass on all nodes of the indicated type.
|
void |
run(BreakStatement s)
Runs this pass on all nodes of the indicated type.
|
void |
run(CastExpression e)
Runs this pass on all nodes of the indicated type.
|
void |
run(CatchClause c)
Runs this pass on all nodes of the indicated type.
|
void |
run(CatchList l)
Runs this pass on all nodes of the indicated type.
|
void |
run(ClassifierName cn)
Code is only generated for a
ClassifierName when it is the only
ClassifierExpression on the right hand side of the arrow (and there really shouldn't
be a reason that a programmer would want to write such a declaration, but if he does, it will
work). |
void |
run(CodedClassifier cc)
Generates code for all nodes of the indicated type.
|
void |
run(CompositeGenerator cg)
Generates code for all nodes of the indicated type.
|
void |
run(Conditional e)
Runs this pass on all nodes of the indicated type.
|
void |
run(Conjunction c)
Generates code for all nodes of the indicated type.
|
void |
run(Constant e)
Runs this pass on all nodes of the indicated type.
|
void |
run(ConstraintDeclaration cd)
Generates code for all nodes of the indicated type.
|
void |
run(ConstraintEqualityExpression e)
Runs this pass on all nodes of the indicated type.
|
void |
run(ConstraintInvocation e)
Runs this pass on all nodes of the indicated type.
|
void |
run(ConstraintStatementExpression e)
Runs this pass on all nodes of the indicated type.
|
void |
run(ContinueStatement s)
Runs this pass on all nodes of the indicated type.
|
void |
run(DoStatement s)
Runs this pass on all nodes of the indicated type.
|
void |
run(ExistentialQuantifierExpression e)
Runs this pass on all nodes of the indicated type.
|
void |
run(ExpressionList l)
Runs this pass on all nodes of the indicated type.
|
void |
run(ExpressionStatement s)
Runs this pass on all nodes of the indicated type.
|
void |
run(FieldAccess e)
Runs this pass on all nodes of the indicated type.
|
void |
run(ForStatement s)
Runs this pass on all nodes of the indicated type.
|
void |
run(IfStatement s)
Runs this pass on all nodes of the indicated type.
|
void |
run(IncrementExpression e)
Runs this pass on all nodes of the indicated type.
|
void |
run(InferenceDeclaration.HeadFinder h)
Runs this pass on all nodes of the indicated type.
|
void |
run(InferenceDeclaration in)
Generates code for all nodes of the indicated type.
|
void |
run(InferenceInvocation ii)
Generates code for all nodes of the indicated type.
|
void |
run(InstanceCreationExpression e)
Runs this pass on all nodes of the indicated type.
|
void |
run(InstanceofExpression e)
Runs this pass on all nodes of the indicated type.
|
void |
run(LabeledStatement s)
Runs this pass on all nodes of the indicated type.
|
void |
run(LearningClassifierExpression lce)
Generates code for all nodes of the indicated type.
|
void |
run(MethodInvocation e)
Runs this pass on all nodes of the indicated type.
|
void |
run(Name n)
Runs this pass on all nodes of the indicated type.
|
void |
run(NegatedConstraintExpression e)
Runs this pass on all nodes of the indicated type.
|
void |
run(Operator o)
Runs this pass on all nodes of the indicated type.
|
void |
run(ParameterSet e)
Runs this pass on all nodes of the indicated type.
|
void |
run(PrimitiveType t)
Runs this pass on all nodes of the indicated type.
|
void |
run(ReferenceType t)
Runs this pass on all nodes of the indicated type.
|
void |
run(ReturnStatement s)
Runs this pass on all nodes of the indicated type.
|
void |
run(SenseStatement ss)
Runs this pass on all nodes of the indicated type.
|
void |
run(StatementList l)
Runs this pass on all nodes of the indicated type.
|
void |
run(SubscriptVariable e)
Runs this pass on all nodes of the indicated type.
|
void |
run(SwitchGroup g)
Runs this pass on all nodes of the indicated type.
|
void |
run(SwitchGroupList l)
Runs this pass on all nodes of the indicated type.
|
void |
run(SwitchLabel l)
Runs this pass on all nodes of the indicated type.
|
void |
run(SwitchLabelList l)
Runs this pass on all nodes of the indicated type.
|
void |
run(SwitchStatement s)
Runs this pass on all nodes of the indicated type.
|
void |
run(SynchronizedStatement s)
Runs this pass on all nodes of the indicated type.
|
void |
run(ThrowStatement s)
Runs this pass on all nodes of the indicated type.
|
void |
run(TryStatement s)
Runs this pass on all nodes of the indicated type.
|
void |
run(UnaryExpression e)
Runs this pass on all nodes of the indicated type.
|
void |
run(UniversalQuantifierExpression e)
Runs this pass on all nodes of the indicated type.
|
void |
run(VariableDeclaration s)
Runs this pass on all nodes of the indicated type.
|
void |
run(WhileStatement s)
Runs this pass on all nodes of the indicated type.
|
void |
setCurrentCG(CodeGenerator cg)
Sets the current code generator for this translator.
|
void |
setIndent(int i)
Sets the indentation level.
|
static String |
signature(Method m,
int modifiers,
Class returned,
String name,
Class[] parameters)
This method generates a string signature of the given method.
|
static void |
typeCheckClassifyArray(PrintStream out,
String name,
Type input,
int line)
Generates code that overrides the
Classifier.classify(Object[]) method so that it
checks the types of its arguments. |
static void |
typeReturningMethods(PrintStream out,
Type input,
ClassifierReturnType output)
Generate code that overrides the methods of
Classifier that return type information. |
public static final String disclaimer
public TranslateToJava(AST ast)
ast
- The AST to associate with this pass.public void setCurrentCG(CodeGenerator cg)
cg
- The new current code generator.public void setIndent(int i)
i
- The new indentation level.public String getMethodBody()
methodBody
member variable so that this pass can be invoked
selectively on some subset of a method body.methodBody
in a String
.public static PrintStream open(CodeGenerator node)
PrintStream
that writes to a Java file corresponding to the specified
CodeGenerator
.node
- The code producing node.null
if it couldn't be created.public static PrintStream open(String name)
PrintStream
that writes to the specified file.name
- The name of the file to open.null
if it couldn't be created.public static void generateLearnerBody(PrintStream out, LearningClassifierExpression lce)
Learner
to check types and call themselves on
the unique instance; also declares other methods and fields of the classifier's
implementation. The explicitly overridden methods are:
getInputType()
getOutputType()
allowableValues()
learn(Object)
learn(Object[])
classify(Object)
classify(Object[])
Learner
down to the super class of this learner
are overridden to call the super class's implementation on the unique instance.out
- The stream to write to.lce
- The LearningClassifierExpression
representing the learner.public static String signature(Method m, int modifiers, Class returned, String name, Class[] parameters)
m
are supplied as arguments for efficiency reasons, since this method is only
called by one other method.m
- The method object.modifiers
- The integer representation of the method's modifiers.returned
- The return type of the method.name
- The name of the method.parameters
- The parameter types of the method.noOverride
array.generateLearnerBody(PrintStream,LearningClassifierExpression)
public static String makeTypeReadable(String name)
Class.getName()
method is not recognizable as a type
by javac
if the given class is an array; this method produces a representation
that is recognizable by javac
. This method also replaces '$' characters with '.'
characters, under the assumption that '$' only appears in the name of an inner class.name
- The name of a class as produced by Class.getName()
.javac
.public static void typeReturningMethods(PrintStream out, Type input, ClassifierReturnType output)
Classifier
that return type information.
The methods overridden are:
getInputType()
getOutputType()
allowableValues()
out
- The stream to write to.input
- The input type of the classifier whose code this is.output
- The return type of the classifier whose code this is.public static void typeCheckClassifyArray(PrintStream out, String name, Type input, int line)
Classifier.classify(Object[])
method so that it
checks the types of its arguments.out
- The stream to write to.name
- The name of the classifier whose code this is.input
- The input type of the classifier whose code this is.line
- The line number on which this classifier is defined.public static void generateHashingMethods(PrintStream out, String name)
equals(Object)
method, which evaluates to true
whenever the two objects are of the same type. This method should not be called when
generating code for a InferenceDeclaration
.out
- The stream to write to.name
- The name of the node whose equals(Object)
method is being generated.public static StringBuffer generateTypeChecking(String indent, String name, String type, boolean array, String input, int line, String exampleName, boolean preExtracted)
Classifier.classify(Object)
methods that checks to see if that input
Object
has the appropriate type.indent
- The whitespace indentation in the generated code.name
- The name of the CodeGenerator
whose input is being checked.type
- The type of CodeGenerator
whose input is being checked (capitalized).array
- Whether or not the method being type checked takes an array of the input type.input
- The correct input type of the CodeGenerator
.line
- The line number on which the CodeGenerator
appears.exampleName
- The name of the example variable.preExtracted
- Whether or not the generated code should allow object arrays containing
indexed features, as a learner can take as input.public static void compressAndPrint(StringBuffer buffer, PrintStream out)
ASTNode
, convert to ASCII hexadecimal, and
write the result to the specified stream.buffer
- The text representation to be written.out
- The stream to write to.public void run(AST ast)
public void run(ClassifierName cn)
ClassifierName
when it is the only
ClassifierExpression
on the right hand side of the arrow (and there really shouldn't
be a reason that a programmer would want to write such a declaration, but if he does, it will
work).public void run(CodedClassifier cc)
public void run(CompositeGenerator cg)
public void run(InferenceInvocation ii)
public void run(LearningClassifierExpression lce)
public void run(Conjunction c)
public void run(ConstraintDeclaration cd)
public void run(InferenceDeclaration in)
public void run(InferenceDeclaration.HeadFinder h)
public void run(Block b)
public void run(StatementList l)
public void run(AssertStatement s)
public void run(BreakStatement s)
public void run(ContinueStatement s)
public void run(ExpressionStatement s)
public void run(ForStatement s)
public void run(IfStatement s)
public void run(LabeledStatement s)
public void run(ReturnStatement s)
public void run(SenseStatement ss)
public void run(SwitchStatement s)
public void run(SynchronizedStatement s)
public void run(ThrowStatement s)
public void run(TryStatement s)
public void run(VariableDeclaration s)
public void run(WhileStatement s)
public void run(DoStatement s)
public void run(SwitchGroupList l)
public void run(SwitchGroup g)
public void run(SwitchLabelList l)
public void run(SwitchLabel l)
public void run(CatchList l)
public void run(CatchClause c)
public void run(Argument a)
public void run(ConstraintStatementExpression e)
public void run(BinaryConstraintExpression e)
public void run(NegatedConstraintExpression e)
public void run(ConstraintEqualityExpression e)
public void run(ConstraintInvocation e)
public void run(UniversalQuantifierExpression e)
public void run(ExistentialQuantifierExpression e)
public void generateBoundedQuantifier(QuantifiedConstraintExpression e)
AtLeastQuantifierExpression
s and AtMostQuantifierExpression
s generate their
code through this method.e
- The node to process.public void run(AtLeastQuantifierExpression e)
public void run(AtMostQuantifierExpression e)
public void run(ExpressionList l)
public void run(ArrayCreationExpression e)
public void run(ArrayInitializer e)
public void run(CastExpression e)
public void run(Conditional e)
public void run(Constant e)
public void run(ParameterSet e)
public void run(InstanceofExpression e)
public void run(Assignment e)
public void run(IncrementExpression e)
public void run(InstanceCreationExpression e)
public void run(MethodInvocation e)
public void run(BinaryExpression be)
public void run(UnaryExpression e)
public void run(FieldAccess e)
public void run(SubscriptVariable e)
public void run(Name n)
public void run(ArrayType t)
public void run(PrimitiveType t)
public void run(ReferenceType t)
Copyright © 2016. All rights reserved.