Translate
Class Exp

java.lang.Object
  extended by Translate.Exp
Direct Known Subclasses:
Exp.Cx, Exp.Ex, Exp.Nx

public abstract class Exp
extends java.lang.Object

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

Exp

public Exp()
Method Detail

unEx

public abstract Tree.Exp unEx()
Unwrap this expression, to obtain tree code that computes a value.

Returns:
the tree code that computes the value

unNx

public abstract Tree.Stm unNx()
Unwrap this expression, to obtain tree code that should be executed only for its side-effects.

Returns:
the tree code to be executed for its side-effects

unCx

public 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.

Parameters:
t - label to branch to on true
f - label to branch to on false
Returns:
the tree code to evaluate the expression and effect the transfer of control.