orc.ast.simple.expression
Class Expression

java.lang.Object
  extended by orc.ast.simple.expression.Expression
Direct Known Subclasses:
Call, Catch, DeclareDefs, DeclareType, HasType, Let, Otherwise, Parallel, Pruning, Sequential, Stop, Throw, WithLocation

public abstract class Expression
extends java.lang.Object

Base class for the simplified abstract syntax tree.

Author:
dkitchin, wcook

Constructor Summary
Expression()
           
 
Method Summary
abstract  Expression convert(Env<Variable> vars, Env<TypeVariable> typevars)
          Converts abstract syntax tree into a serializable form, used to generate portable .oil (Orc Intermediate Language) files.
static java.util.List<Expression> convertAll(java.util.List<Expression> es, Env<Variable> vars, Env<TypeVariable> typevars)
          Convenience method, to apply convert to a list of expressions.
 Expression subMap(java.util.Map<FreeVariable,? extends Argument> m)
          Perform a set of substitutions defined by a map.
abstract  Expression subst(Argument a, FreeVariable x)
          Performs the substitution [a/x], replacing occurrences of the free variable x with the new argument a (which could be any argument, including another variable).
abstract  Expression subst(Type T, FreeTypeVariable X)
          Performs the substitution [T/X], replacing occurrences of the free type variable X with the type T (which could be any type, including another variable).
static java.util.List<Expression> substAll(java.util.List<Expression> es, Argument a, FreeVariable x)
          Convenience method, to apply a substitution to a list of expressions.
 Expression subvar(TypeVariable U, FreeTypeVariable X)
          Performs the substitution [U/X], replacing occurrences of the free type variable X with the nameless type variable U.
 Expression subvar(Variable v, FreeVariable x)
          Performs the substitution [v/x], replacing occurrences of the free variable x with the nameless variable v.
abstract  java.util.Set<Variable> vars()
          Find the set of all Variables (note: not FreeVariables) that are not bound within this expression.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Expression

public Expression()
Method Detail

convert

public abstract Expression convert(Env<Variable> vars,
                                   Env<TypeVariable> typevars)
                            throws CompilationException
Converts abstract syntax tree into a serializable form, used to generate portable .oil (Orc Intermediate Language) files.

Parameters:
vars - The vars environment, used in content addressable mode to find the appropriate deBruijn index of a var.
typevars - The type vars environment, used in content addressable mode to find the appropriate deBruijn index of a type var.
Returns:
A new node.
Throws:
CompilationException

convertAll

public static java.util.List<Expression> convertAll(java.util.List<Expression> es,
                                                    Env<Variable> vars,
                                                    Env<TypeVariable> typevars)
                                             throws CompilationException
Convenience method, to apply convert to a list of expressions.

Parameters:
es - A list of expressions.
vars -
typevars -
Returns:
The list of expressions, after conversion
Throws:
CompilationException

subst

public abstract Expression subst(Argument a,
                                 FreeVariable x)
Performs the substitution [a/x], replacing occurrences of the free variable x with the new argument a (which could be any argument, including another variable).

Parameters:
a - The replacing variable or value
x - The free variable whose occurrences will be replaced
Returns:
A new copy of the expression with the substitution performed

substAll

public static java.util.List<Expression> substAll(java.util.List<Expression> es,
                                                  Argument a,
                                                  FreeVariable x)
Convenience method, to apply a substitution to a list of expressions.


subvar

public Expression subvar(Variable v,
                         FreeVariable x)
Performs the substitution [v/x], replacing occurrences of the free variable x with the nameless variable v. Additionally, attach the name of x as documentation on the variable v so that it can be used later for debugging or other purposes. This method delegates to the subst method after attaching the name.

Parameters:
v - The replacing variable
x - The free variable whose occurrences will be replaced
Returns:
A new copy of the expression with the substitution performed

subMap

public Expression subMap(java.util.Map<FreeVariable,? extends Argument> m)
Perform a set of substitutions defined by a map. For each x |-> a in the map, the substitution [a/x] occurs. If a is a nameless variable v, the name of the corresponding x will be attached to it.

Parameters:
m -

subst

public abstract Expression subst(Type T,
                                 FreeTypeVariable X)
Performs the substitution [T/X], replacing occurrences of the free type variable X with the type T (which could be any type, including another variable).

Parameters:
T - The replacing type
X - The free type variable whose occurrences will be replaced
Returns:
A new copy of the expression with the substitution performed

subvar

public Expression subvar(TypeVariable U,
                         FreeTypeVariable X)
Performs the substitution [U/X], replacing occurrences of the free type variable X with the nameless type variable U. Additionally, attach the name of X as documentation on U so that it can be used later for debugging or other purposes. This method delegates to the subst method after attaching the name.

Parameters:
U - The replacing type variable
X - The free type variable whose occurrences will be replaced
Returns:
A new copy of the type with the substitution performed

vars

public abstract java.util.Set<Variable> vars()
Find the set of all Variables (note: not FreeVariables) that are not bound within this expression.