public class InnerTranslator extends NodeVisitor
Modifier and Type | Class and Description |
---|---|
protected class |
InnerTranslator.ClassInfo |
protected class |
InnerTranslator.CodeInfo |
Modifier and Type | Field and Description |
---|---|
protected java.util.Stack<InnerTranslator.ClassInfo> |
classContext |
protected java.util.Stack<InnerTranslator.CodeInfo> |
codeContext |
protected java.util.HashMap<java.lang.String,InnerTranslator.ClassInfo> |
innerClassInfoMap |
protected java.util.Stack<java.lang.Boolean> |
insideCode |
protected NodeFactory |
nf |
protected java.util.Stack<java.lang.Boolean> |
staticFieldDecl |
protected TypeSystem |
ts |
Constructor and Description |
---|
InnerTranslator(TypeSystem ts,
NodeFactory nf) |
Modifier and Type | Method and Description |
---|---|
protected ClassDecl |
addAnonymousConstructor(ClassDecl cd,
ParsedClassType ct,
InnerTranslator.ClassInfo cinfo,
New newExpr) |
protected ClassDecl |
addNewMembers(ClassDecl cd,
InnerTranslator.ClassInfo cinfo) |
NodeVisitor |
enter(Node n)
Begin normal traversal of a subtree rooted at
n . |
protected void |
enterClassDecl(ClassDecl cd) |
protected void |
enterCodeDecl(CodeDecl cd) |
protected void |
enterFieldDecl(FieldDecl fd) |
protected void |
enterLocalDecl(LocalDecl ld) |
protected void |
enterNew(New newExpr) |
protected InnerTranslator.ClassInfo |
findClassInfo(ClassType ct)
Find ClassInfo for ClassType ct, from innerClassInfoMap.
|
protected ParsedClassType |
findField(java.lang.String name,
ClassType current)
Find the class type inside which a field with specified name is declared.
|
protected ParsedClassType |
findMethod(MethodInstance mi,
ClassType current)
Find the class type inside which a field with specified name is declared.
|
protected boolean |
isSourceType(ClassType ct)
Check whether ct is a type in source language.
|
Node |
leave(Node old,
Node n,
NodeVisitor v)
This method is called after all of the children of
n
have been visited. |
protected Node |
leaveCall(Node old,
Call c,
NodeVisitor v) |
protected Node |
leaveClassDecl(Node old,
ClassDecl cd,
NodeVisitor v) |
protected Node |
leaveConstructorCall(Node old,
ConstructorCall cc,
NodeVisitor v) |
protected Node |
leaveField(Node old,
Field field,
NodeVisitor v) |
protected Node |
leaveLocal(Node old,
Local local,
NodeVisitor v)
Translate final local variables that should become field accesses of local/anonymous classes.
|
protected Node |
leaveNew(Node old,
New newExpr,
NodeVisitor v) |
protected Node |
leaveSpecial(Node old,
Special s,
NodeVisitor v) |
protected java.lang.String |
namePrefix() |
protected java.lang.String |
newFieldName(java.lang.String name) |
protected java.lang.String |
outerThisName(ClassType ct) |
protected ConstructorDecl |
produceDefaultConstructor(ParsedClassType ct,
InnerTranslator.ClassInfo cinfo) |
protected ConstructorCall |
produceDefaultSuperConstructorCall(ClassType ct) |
protected java.util.List<FieldDecl> |
produceFieldDecls(ClassType ct,
InnerTranslator.ClassInfo cinfo) |
protected java.util.List<Stmt> |
produceFieldInits(InnerTranslator.ClassInfo cinfo) |
protected Field |
produceOuterField(ClassType ct,
Expr rec) |
protected Formal |
produceOuterFormal(ParsedClassType ct,
ParsedClassType oct) |
protected Special |
produceThis(ClassType ct)
Generate a special node "this" with the correct type.
|
protected ClassDecl |
updateClassDecl(ClassDecl cd,
ParsedClassType ct,
InnerTranslator.ClassInfo cinfo) |
protected ConstructorDecl |
updateConstructor(ClassDecl cd,
ClassType ct,
ConstructorDecl cons,
InnerTranslator.ClassInfo cinfo) |
protected ConstructorCall |
updateConstructorCall(ConstructorCall cc,
InnerTranslator.ClassInfo selfInfo) |
protected ConstructorInstance |
updateConstructorInst(ClassType ct,
ConstructorInstance ci,
InnerTranslator.ClassInfo cinfo) |
protected Expr |
updateNewExpr(New newExpr)
Update new expressions to include necessary arguments (for example,
enclosing instances) and eliminate qualifers.
|
protected TypeSystem ts
protected NodeFactory nf
protected java.util.Stack<InnerTranslator.ClassInfo> classContext
protected java.util.Stack<InnerTranslator.CodeInfo> codeContext
protected java.util.HashMap<java.lang.String,InnerTranslator.ClassInfo> innerClassInfoMap
protected java.util.Stack<java.lang.Boolean> insideCode
protected java.util.Stack<java.lang.Boolean> staticFieldDecl
public InnerTranslator(TypeSystem ts, NodeFactory nf)
protected java.lang.String namePrefix()
protected java.lang.String newFieldName(java.lang.String name)
public NodeVisitor enter(Node n)
NodeVisitor
n
. This gives
the visitor the option of changing internal state or returning a new
visitor which will be used to visit the children of n
.
This method is typically called by the method
enter(parent, n)
. If a subclass overrides the
method enter(parent, n)
then this method
may not be called.
enter
in class NodeVisitor
n
- The root of the subtree to be traversed.NodeVisitor
which should be used to visit the
children of n
.protected void enterFieldDecl(FieldDecl fd)
protected void enterClassDecl(ClassDecl cd)
protected void enterNew(New newExpr)
protected void enterCodeDecl(CodeDecl cd)
protected void enterLocalDecl(LocalDecl ld)
public Node leave(Node old, Node n, NodeVisitor v)
NodeVisitor
n
have been visited. In this case, these children were visited by the
visitor v
. This is the last chance for the visitor to
modify the tree rooted at n
. This method will be called
exactly the same number of times as entry
is called.
That is, for each node that is not overridden, enter
and
leave
are each called exactly once.
Note that if old == n
then the visitor should make a copy
of n
before modifying it. It should then return the
modified copy.
This method is typically called by the method
leave(parent, old, n v)
.
If a subclass overrides the method
leave(parent, old, n v)
then this method may not be called.
leave
in class NodeVisitor
old
- The original state of root of the current subtree.n
- The current state of the root of the current subtree.v
- The NodeVisitor
object used to visit the children.n
.protected Node leaveClassDecl(Node old, ClassDecl cd, NodeVisitor v)
protected Node leaveNew(Node old, New newExpr, NodeVisitor v)
protected Node leaveConstructorCall(Node old, ConstructorCall cc, NodeVisitor v)
protected Node leaveSpecial(Node old, Special s, NodeVisitor v)
protected Node leaveField(Node old, Field field, NodeVisitor v)
protected Node leaveCall(Node old, Call c, NodeVisitor v)
protected Node leaveLocal(Node old, Local local, NodeVisitor v)
old
- local
- v
- protected Special produceThis(ClassType ct)
ct
- protected ClassDecl addAnonymousConstructor(ClassDecl cd, ParsedClassType ct, InnerTranslator.ClassInfo cinfo, New newExpr)
protected ParsedClassType findField(java.lang.String name, ClassType current)
protected ParsedClassType findMethod(MethodInstance mi, ClassType current)
protected ConstructorCall updateConstructorCall(ConstructorCall cc, InnerTranslator.ClassInfo selfInfo)
protected ClassDecl addNewMembers(ClassDecl cd, InnerTranslator.ClassInfo cinfo)
protected InnerTranslator.ClassInfo findClassInfo(ClassType ct)
ct
- protected boolean isSourceType(ClassType ct)
ct
- protected Expr updateNewExpr(New newExpr)
newExpr
- protected ConstructorDecl produceDefaultConstructor(ParsedClassType ct, InnerTranslator.ClassInfo cinfo)
protected ClassDecl updateClassDecl(ClassDecl cd, ParsedClassType ct, InnerTranslator.ClassInfo cinfo)
protected java.util.List<FieldDecl> produceFieldDecls(ClassType ct, InnerTranslator.ClassInfo cinfo)
protected java.lang.String outerThisName(ClassType ct)
protected Formal produceOuterFormal(ParsedClassType ct, ParsedClassType oct)
protected ConstructorInstance updateConstructorInst(ClassType ct, ConstructorInstance ci, InnerTranslator.ClassInfo cinfo)
protected ConstructorCall produceDefaultSuperConstructorCall(ClassType ct)
protected ConstructorDecl updateConstructor(ClassDecl cd, ClassType ct, ConstructorDecl cons, InnerTranslator.ClassInfo cinfo)
protected java.util.List<Stmt> produceFieldInits(InnerTranslator.ClassInfo cinfo)