|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.ObjectTranslate.Exp
public abstract class Exp
Translation from abstract syntax to intermediate code trees assumes that every AST node maps to some corresponding IR code tree. Sometimes, the way an AST node should be translated depends on the context in which that node appears. Thus, since translation operates as a depth-first traversal of the AST, we may need to defer how a node is translated until we return back to the context in which that node appears. It has been said that all problems in computer science can be solved using indirection or caching. This is a case where we use indirection to defer how a node is translated by wrapping every translated subtree in one of the following subclasses of Exp. The idea is that every wrapper comes with associated unwrap methods (unEx, unCx, unNx) that perform an appropriate translation of the wrapped code to match a its specific use. Thus we are able to defer translation of a node until we see how it is used.
Nested Class Summary | |
---|---|
static class |
Exp.Cx
A wrapper for tree code that may be used both to compute a Boolean value and to effect transfer of control. |
static class |
Exp.Ex
A wrapper for tree code expressions that produce a value. |
static class |
Exp.Nx
A wrapper for tree code statements that have side-effects. |
Constructor Summary | |
---|---|
Exp()
|
Method Summary | |
---|---|
abstract Tree.Stm |
unCx(Temp.Label t,
Temp.Label f)
Unwrap this expression, to obtain code that causes transfer of control based on the Boolean value of the expression. |
abstract Tree.Exp |
unEx()
Unwrap this expression, to obtain tree code that computes a value. |
abstract Tree.Stm |
unNx()
Unwrap this expression, to obtain tree code that should be executed only for its side-effects. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public Exp()
Method Detail |
---|
public abstract Tree.Exp unEx()
public abstract Tree.Stm unNx()
public abstract Tree.Stm unCx(Temp.Label t, Temp.Label f)
t
- label to branch to on truef
- label to branch to on false
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |