step10
Class type

java.lang.Object
  extended by step10.type
All Implemented Interfaces:
Visitor

public class type
extends Object
implements Visitor

strongly type-checks and rewrites mini. The architecture is self-contained but is heavily borrowed from step9.


Nested Class Summary
static class type.BAnd
          and of two type.BooleanT trees.
static class type.BAndIf
          and-if of two type.BooleanT trees.
static class type.BBegin
          block ending in type.BooleanT tree.
static class type.BCall
          call with Boolean result.
static class type.BDeref
          deref String to Boolean.
static class type.BEq
          equal of two type.BooleanT trees.
static class type.BIf
          if with type.BooleanT alternatives.
static class type.BLet
          let with type.BooleanT body.
static class type.BLetrec
          letrec with type.BooleanT body.
static class type.BNe
          not-equal of two type.BooleanT trees.
static class type.BNot
          negate a type.BooleanT tree.
static class type.BooleanT
          base class for boolean operations, itself used to type an Boolean leaf.
static class type.BOr
          or of two type.BooleanT trees.
static class type.BOrIf
          or-if of two type.BooleanT trees.
static class type.BVar
          var with type.BooleanT initializer.
static class type.BXor
          xor of two type.BooleanT trees.
static class type.DAdd
          add two type.DoubleT trees.
static class type.DBegin
          block ending in type.DoubleT tree.
static class type.DCall
          call with Double result.
static class type.DDeref
          deref String to Double.
static class type.DDiv
          divide two type.DoubleT trees.
static class type.DEq
          equal of two type.DoubleT trees.
static class type.DGe
          greater-equal of two type.DoubleT trees.
static class type.DGt
          greater-then of two type.DoubleT trees.
static class type.DIf
          if with type.DoubleT alternatives.
static class type.DLe
          less-equal of two type.DoubleT trees.
static class type.DLet
          let with type.DoubleT body.
static class type.DLetrec
          letrec with type.DoubleT body.
static class type.DLt
          less-then of two type.DoubleT trees.
static class type.DMinus
          sign-change an type.DoubleT tree.
static class type.DMul
          multiply two type.DoubleT trees.
static class type.DNe
          not-equal of two type.DoubleT trees.
static class type.DoubleT
          base class for double operations, itself used to type a Double leaf.
static class type.DSub
          subtract two type.DoubleT trees.
static class type.DVar
          var with type.DoubleT initializer.
static class type.Env
          environment: block-structured map of keys to values.
static class type.I2D
          convert type.IntegerT to type.DoubleT.
static class type.IAdd
          add two type.IntegerT trees.
static class type.IAnd
          bit-and two type.IntegerT trees.
static class type.IBegin
          block ending in type.IntegerT tree.
static class type.ICall
          call with Integer result.
static class type.IDeref
          deref String to Integer.
static class type.IDiv
          divide two type.IntegerT trees.
static class type.IEq
          equal of two type.IntegerT trees.
static class type.IGe
          greater-equal of two type.IntegerT trees.
static class type.IGt
          greater-then of two type.IntegerT trees.
static class type.IIf
          if with type.IntegerT alternatives.
static class type.ILe
          less-equal of two type.IntegerT trees.
static class type.ILet
          let with type.IntegerT body.
static class type.ILetrec
          letrec with type.IntegerT body.
static class type.ILsh
          left shift two type.IntegerT trees.
static class type.ILt
          less-then of two type.IntegerT trees.
static class type.IMinus
          sign-change an type.IntegerT tree.
static class type.IMod
          remainder of two type.IntegerT trees.
static class type.IMul
          multiply two type.IntegerT trees.
static class type.INe
          not-equal of two type.IntegerT trees.
static class type.INeg
          bit-complement an type.IntegerT tree.
static class type.IntegerT
          base class for integer operations, itself used to type an Integer leaf.
static class type.IOr
          bit-or two type.IntegerT trees.
static class type.IRsh
          right shift two type.IntegerT trees.
static class type.ISub
          subtract two type.IntegerT trees.
static class type.IVar
          var with type.IntegerT initializer.
static class type.IXor
          bit-xor two type.IntegerT trees.
static class type.PBegin
          block ending in type.ProcT tree.
static class type.PCall
          call with type.ProcT result.
static class type.PDeref
          deref String to type.ProcT.
static class type.PIf
          if with type.ProcT alternatives.
static class type.PLet
          let with type.ProcT body.
static class type.PLetrec
          letrec with type.ProcT body.
static class type.ProcT
          base class for procedures, itself used to represent a mini.yyTree.Proc.
static class type.PVar
          var with type.ProcT initializer.
static class type.SAdd
          concatenate two type.StringT trees.
static class type.SBegin
          block ending in type.StringT tree.
static class type.SCall
          call with String result.
static class type.SDeref
          deref String to String.
static class type.SEq
          equal of two type.StringT trees.
static class type.SGe
          greater-equal of two type.StringT trees.
static class type.SGt
          greater-then of two type.StringT trees.
static class type.SIf
          if with type.StringT alternatives.
static class type.SLe
          less-equal of two type.StringT trees.
static class type.SLet
          let with type.StringT body.
static class type.SLetrec
          letrec with type.StringT body.
static class type.SLt
          less-then of two type.StringT trees.
static class type.SNe
          not-equal of two type.StringT trees.
static class type.StringT
          base class for string operations, itself used to type a String leaf.
static class type.SVar
          var with type.StringT initializer.
static class type.T
          base class for typed branch nodes.
 
Field Summary
protected  HashMap _rules
          maps class to array of Rule.
protected  type.Env env
          maps identifiers to types.
protected  PrintStream out
          print action stream.
 
Constructor Summary
type()
           
 
Method Summary
 Object BAnd(List sub)
          factory method: and of two type.BooleanT trees.
 Object BAndIf(List sub)
          factory method: and-if of two type.BooleanT trees.
 Object BBegin(Object type, List sub)
          factory method: block ending in type.BooleanT tree.
 Object BCall(Object type, List sub)
          factory method: call with Boolean result.
 Object BDeref(Object type, List sub)
          factory method: deref String to Boolean.
 Object BEq(List sub)
          factory method: equal of two type.BooleanT trees.
 Object BIf(Object type, List sub)
          factory method: if with type.BooleanT alternatives.
 Object BLet(Object type, List sub)
          factory method: let with type.BooleanT body.
 Object BLetrec(Object type, List sub)
          factory method: letrec with type.BooleanT body.
 Object BNe(List sub)
          factory method: not-equal of two type.BooleanT trees.
 Object BNot(List sub)
          factory method: negate a type.BooleanT tree.
 type.BooleanT BooleanT(Boolean b)
          factory method: type a Boolean leaf.
 Object BOr(List sub)
          factory method: or of two type.BooleanT trees.
 Object BOrIf(List sub)
          factory method: or-if of two type.BooleanT trees.
 Object BVar(Object type, List sub)
          factory method: var with type.BooleanT initializer.
 Object BXor(List sub)
          factory method: xor of two type.BooleanT trees.
static String classname(Object o)
          returns simplified classname.
 Object create(String name, Object type, List sub)
          factory method, based on reflection: create typed operator node.
 Object DAdd(List sub)
          factory method: add two type.DoubleT trees.
 Object DBegin(Object type, List sub)
          factory method: block ending in type.DoubleT tree.
 Object DCall(Object type, List sub)
          factory method: call with Double result.
 Object DDeref(Object type, List sub)
          factory method: deref String to Double.
 Object DDiv(List sub)
          factory method: divide two type.DoubleT trees.
 Object DEq(List sub)
          factory method: equal of two type.DoubleT trees.
 Object DGe(List sub)
          factory method: greater-equal of two type.DoubleT trees.
 Object DGt(List sub)
          factory method: greater-then of two type.DoubleT trees.
 Object DIf(Object type, List sub)
          factory method: if with type.DoubleT alternatives.
 Object DLe(List sub)
          factory method: less-equal of two type.DoubleT trees.
 Object DLet(Object type, List sub)
          factory method: let with type.DoubleT body.
 Object DLetrec(Object type, List sub)
          factory method: letrec with type.DoubleT body.
 Object DLt(List sub)
          factory method: less-then of two type.DoubleT trees.
 Object DMinus(List sub)
          factory method: sign-change an type.DoubleT tree.
 Object DMul(List sub)
          factory method: multiply two type.DoubleT trees.
 Object DNe(List sub)
          factory method: not-equal of two type.DoubleT trees.
 type.DoubleT DoubleT(Double d)
          factory method: type a Double leaf.
 Object DSub(List sub)
          factory method: subtract two type.DoubleT trees.
static void dump(PrintStream out, Object o, String indent)
          indented symbolic dump.
 Object DVar(Object type, List sub)
          factory method: var with type.DoubleT initializer.
 type.Env Env()
          factory method: empty environment.
 type.Env Env(String[] keys, Object[] values, type.Env prev)
          factory method: extend environment.
 Object I2D(type.IntegerT sub)
          factory method: convert type.IntegerT to type.DoubleT.
 Object IAdd(List sub)
          factory method: add two type.IntegerT trees.
 Object IAnd(List sub)
          factory method: bit-and two type.IntegerT trees.
 Object IBegin(Object type, List sub)
          factory method: block ending in type.IntegerT tree.
 Object ICall(Object type, List sub)
          factory method: call with Integer result.
 Object IDeref(Object type, List sub)
          factory method: deref String to Integer.
 Object IDiv(List sub)
          factory method: divide two type.IntegerT trees.
 Object IEq(List sub)
          factory method: equal of two type.IntegerT trees.
 Object IGe(List sub)
          factory method: greater-equal of two type.IntegerT trees.
 Object IGt(List sub)
          factory method: greater-then of two type.IntegerT trees.
 Object IIf(Object type, List sub)
          factory method: if with type.IntegerT alternatives.
 Object ILe(List sub)
          factory method: less-equal of two type.IntegerT trees.
 Object ILet(Object type, List sub)
          factory method: let with type.IntegerT body.
 Object ILetrec(Object type, List sub)
          factory method: letrec with type.IntegerT body.
 Object ILsh(List sub)
          factory method: left shift two type.IntegerT trees.
 Object ILt(List sub)
          factory method: less-then of two type.IntegerT trees.
 Object IMinus(List sub)
          factory method: sign-change an type.IntegerT tree.
 Object IMod(List sub)
          factory method: remainder of two type.IntegerT trees.
 Object IMul(List sub)
          factory method: multiply two type.IntegerT trees.
 Object INe(List sub)
          factory method: not-equal of two type.IntegerT trees.
 Object INeg(List sub)
          factory method: bit-complement an type.IntegerT tree.
 type.IntegerT IntegerT(Integer i)
          factory method: type an Integer leaf.
 Object IOr(List sub)
          factory method: bit-or two type.IntegerT trees.
 Object IRsh(List sub)
          factory method: right shift two type.IntegerT trees.
 Object ISub(List sub)
          factory method: subtract two type.IntegerT trees.
 Object IVar(Object type, List sub)
          factory method: var with type.IntegerT initializer.
 Object IXor(List sub)
          factory method: bit-xor two type.IntegerT trees.
static void main(String[] args)
          type lines with mixed mode expressions.
protected  PrintStream out()
          returns print action stream.
 Object PBegin(Object type, List sub)
          factory method: block ending in type.ProcT tree.
 Object PCall(Object type, List sub)
          factory method: call with type.ProcT result.
 Object PDeref(Object type, List sub)
          factory method: deref String to type.ProcT.
 Object PIf(Object type, List sub)
          factory method: if with type.ProcT alternatives.
 Object PLet(Object type, List sub)
          factory method: let with type.ProcT body.
 Object PLetrec(Object type, List sub)
          factory method: letrec with type.ProcT body.
 Object prefix(String name, List op)
          factory method, based on reflection: create typed operator node of same name.
 Object prefix(type.T type, List op)
          factory method, based on reflection: create typed operator node of same name.
 type.ProcT ProcT(type.T result, String name, type.T[] params, String[] names, List body)
          factory method: represent a procedure.
 type.ProcT ProcT(type.T result, type.T[] params)
          factory method: represent a procedure type.
 Object PVar(Object type, List sub)
          factory method: var with type.ProcT initializer.
 Object SAdd(List sub)
          factory method: concatenate two type.StringT trees.
 Object SBegin(Object type, List sub)
          factory method: block ending in type.StringT tree.
 Object SCall(Object type, List sub)
          factory method: call with String result.
 Object SDeref(Object type, List sub)
          factory method: deref String to String.
 Object SEq(List sub)
          factory method: equal of two type.StringT trees.
 Object SGe(List sub)
          factory method: greater-equal of two type.StringT trees.
 Object SGt(List sub)
          factory method: greater-then of two type.StringT trees.
 Object SIf(Object type, List sub)
          factory method: if with type.StringT alternatives.
 Object SLe(List sub)
          factory method: less-equal of two type.StringT trees.
 Object SLet(Object type, List sub)
          factory method: let with type.StringT body.
 Object SLetrec(Object type, List sub)
          factory method: letrec with type.StringT body.
 Object SLt(List sub)
          factory method: less-then of two type.StringT trees.
 Object SNe(List sub)
          factory method: not-equal of two type.StringT trees.
 type.StringT StringT(String s)
          factory method: type a String leaf.
 Object SVar(Object type, List sub)
          factory method: var with type.StringT initializer.
 type.T T(String typeId)
          factory method: represent a simple type.
 Object visit(int _action, Object _object)
          visits an object.
 Object visit(Object object)
          visits an object.
 Object visit0(Object object)
          visits an object, ignoring possible descendants.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

env

protected type.Env env
maps identifiers to types.


out

protected transient PrintStream out
print action stream. Can be replaced to reroute output. BUG: should be a self-flushing PrintWriter.


_rules

protected final HashMap _rules
maps class to array of Rule.

Constructor Detail

type

public type()
Method Detail

out

protected PrintStream out()
returns print action stream. Defaults to System.out.


visit

public Object visit(Object object)
             throws Exception
visits an object. This is a facade for the class search.

Specified by:
visit in interface Visitor
Parameters:
object - to be visited, not null.
Returns:
result of action.
Throws:
NoRuleException - if no rule can be found.
Exception
See Also:
Rule.visit(jag.Visitor, java.util.HashMap, java.lang.Object, int, java.util.List)

visit0

public Object visit0(Object object)
              throws Exception
visits an object, ignoring possible descendants. This is a facade for the class search with degree zero.

Specified by:
visit0 in interface Visitor
Parameters:
object - to be visited, not null.
Returns:
result of action.
Throws:
NoRuleException - if no rule can be found.
Exception
See Also:
Rule.visit(jag.Visitor, java.util.HashMap, java.lang.Object, int, java.util.List)

visit

public Object visit(int _action,
                    Object _object)
             throws Exception
visits an object.

Specified by:
visit in interface Visitor
Parameters:
_action - index.
_object - to be visited, not null.
Returns:
result of action.
Throws:
NoRuleException - if no rule can be found.
Exception

prefix

public Object prefix(String name,
                     List op)
factory method, based on reflection: create typed operator node of same name.

Parameters:
name - to prepend.
op - tree, contains the typed subtrees.

prefix

public Object prefix(type.T type,
                     List op)
factory method, based on reflection: create typed operator node of same name.

Parameters:
type - propagated through type.T.toPrefix() and type.T.type().
op - tree, contains the typed subtrees.

create

public Object create(String name,
                     Object type,
                     List sub)
factory method, based on reflection: create typed operator node.

Parameters:
name - to create.
type - describes type for Object.equals(java.lang.Object), propagate.
sub - contains the typed subtrees.

T

public type.T T(String typeId)
factory method: represent a simple type.


BooleanT

public type.BooleanT BooleanT(Boolean b)
factory method: type a Boolean leaf.


DoubleT

public type.DoubleT DoubleT(Double d)
factory method: type a Double leaf.


IntegerT

public type.IntegerT IntegerT(Integer i)
factory method: type an Integer leaf.


StringT

public type.StringT StringT(String s)
factory method: type a String leaf.


ProcT

public type.ProcT ProcT(type.T result,
                        type.T[] params)
factory method: represent a procedure type.


ProcT

public type.ProcT ProcT(type.T result,
                        String name,
                        type.T[] params,
                        String[] names,
                        List body)
factory method: represent a procedure.


Env

public type.Env Env()
factory method: empty environment.


Env

public type.Env Env(String[] keys,
                    Object[] values,
                    type.Env prev)
factory method: extend environment.


main

public static void main(String[] args)
                 throws Exception
type lines with mixed mode expressions.

Throws:
Exception

dump

public static void dump(PrintStream out,
                        Object o,
                        String indent)
indented symbolic dump.


classname

public static String classname(Object o)
returns simplified classname.


BBegin

public Object BBegin(Object type,
                     List sub)
factory method: block ending in type.BooleanT tree.


BIf

public Object BIf(Object type,
                  List sub)
factory method: if with type.BooleanT alternatives.


BLet

public Object BLet(Object type,
                   List sub)
factory method: let with type.BooleanT body.


BVar

public Object BVar(Object type,
                   List sub)
factory method: var with type.BooleanT initializer.


BDeref

public Object BDeref(Object type,
                     List sub)
factory method: deref String to Boolean.


BLetrec

public Object BLetrec(Object type,
                      List sub)
factory method: letrec with type.BooleanT body.


BCall

public Object BCall(Object type,
                    List sub)
factory method: call with Boolean result.


BOrIf

public Object BOrIf(List sub)
factory method: or-if of two type.BooleanT trees.


BAndIf

public Object BAndIf(List sub)
factory method: and-if of two type.BooleanT trees.


BOr

public Object BOr(List sub)
factory method: or of two type.BooleanT trees.


BXor

public Object BXor(List sub)
factory method: xor of two type.BooleanT trees.


BAnd

public Object BAnd(List sub)
factory method: and of two type.BooleanT trees.


BEq

public Object BEq(List sub)
factory method: equal of two type.BooleanT trees.


BNe

public Object BNe(List sub)
factory method: not-equal of two type.BooleanT trees.


BNot

public Object BNot(List sub)
factory method: negate a type.BooleanT tree.


DBegin

public Object DBegin(Object type,
                     List sub)
factory method: block ending in type.DoubleT tree.


DIf

public Object DIf(Object type,
                  List sub)
factory method: if with type.DoubleT alternatives.


DLet

public Object DLet(Object type,
                   List sub)
factory method: let with type.DoubleT body.


DVar

public Object DVar(Object type,
                   List sub)
factory method: var with type.DoubleT initializer.


DDeref

public Object DDeref(Object type,
                     List sub)
factory method: deref String to Double.


DLetrec

public Object DLetrec(Object type,
                      List sub)
factory method: letrec with type.DoubleT body.


DCall

public Object DCall(Object type,
                    List sub)
factory method: call with Double result.


DAdd

public Object DAdd(List sub)
factory method: add two type.DoubleT trees.


DSub

public Object DSub(List sub)
factory method: subtract two type.DoubleT trees.


DMul

public Object DMul(List sub)
factory method: multiply two type.DoubleT trees.


DDiv

public Object DDiv(List sub)
factory method: divide two type.DoubleT trees.


DMinus

public Object DMinus(List sub)
factory method: sign-change an type.DoubleT tree.


I2D

public Object I2D(type.IntegerT sub)
factory method: convert type.IntegerT to type.DoubleT.


DLt

public Object DLt(List sub)
factory method: less-then of two type.DoubleT trees.


DLe

public Object DLe(List sub)
factory method: less-equal of two type.DoubleT trees.


DGt

public Object DGt(List sub)
factory method: greater-then of two type.DoubleT trees.


DGe

public Object DGe(List sub)
factory method: greater-equal of two type.DoubleT trees.


DEq

public Object DEq(List sub)
factory method: equal of two type.DoubleT trees.


DNe

public Object DNe(List sub)
factory method: not-equal of two type.DoubleT trees.


IBegin

public Object IBegin(Object type,
                     List sub)
factory method: block ending in type.IntegerT tree.


IIf

public Object IIf(Object type,
                  List sub)
factory method: if with type.IntegerT alternatives.


ILet

public Object ILet(Object type,
                   List sub)
factory method: let with type.IntegerT body.


IVar

public Object IVar(Object type,
                   List sub)
factory method: var with type.IntegerT initializer.


IDeref

public Object IDeref(Object type,
                     List sub)
factory method: deref String to Integer.


ILetrec

public Object ILetrec(Object type,
                      List sub)
factory method: letrec with type.IntegerT body.


ICall

public Object ICall(Object type,
                    List sub)
factory method: call with Integer result.


IOr

public Object IOr(List sub)
factory method: bit-or two type.IntegerT trees.


IXor

public Object IXor(List sub)
factory method: bit-xor two type.IntegerT trees.


IAnd

public Object IAnd(List sub)
factory method: bit-and two type.IntegerT trees.


ILsh

public Object ILsh(List sub)
factory method: left shift two type.IntegerT trees.


IRsh

public Object IRsh(List sub)
factory method: right shift two type.IntegerT trees.


IAdd

public Object IAdd(List sub)
factory method: add two type.IntegerT trees.


ISub

public Object ISub(List sub)
factory method: subtract two type.IntegerT trees.


IMul

public Object IMul(List sub)
factory method: multiply two type.IntegerT trees.


IDiv

public Object IDiv(List sub)
factory method: divide two type.IntegerT trees.


IMod

public Object IMod(List sub)
factory method: remainder of two type.IntegerT trees.


IMinus

public Object IMinus(List sub)
factory method: sign-change an type.IntegerT tree.


INeg

public Object INeg(List sub)
factory method: bit-complement an type.IntegerT tree.


ILt

public Object ILt(List sub)
factory method: less-then of two type.IntegerT trees.


ILe

public Object ILe(List sub)
factory method: less-equal of two type.IntegerT trees.


IGt

public Object IGt(List sub)
factory method: greater-then of two type.IntegerT trees.


IGe

public Object IGe(List sub)
factory method: greater-equal of two type.IntegerT trees.


IEq

public Object IEq(List sub)
factory method: equal of two type.IntegerT trees.


INe

public Object INe(List sub)
factory method: not-equal of two type.IntegerT trees.


SBegin

public Object SBegin(Object type,
                     List sub)
factory method: block ending in type.StringT tree.


SIf

public Object SIf(Object type,
                  List sub)
factory method: if with type.StringT alternatives.


SLet

public Object SLet(Object type,
                   List sub)
factory method: let with type.StringT body.


SVar

public Object SVar(Object type,
                   List sub)
factory method: var with type.StringT initializer.


SDeref

public Object SDeref(Object type,
                     List sub)
factory method: deref String to String.


SLetrec

public Object SLetrec(Object type,
                      List sub)
factory method: letrec with type.StringT body.


SCall

public Object SCall(Object type,
                    List sub)
factory method: call with String result.


SAdd

public Object SAdd(List sub)
factory method: concatenate two type.StringT trees.


SLt

public Object SLt(List sub)
factory method: less-then of two type.StringT trees.


SLe

public Object SLe(List sub)
factory method: less-equal of two type.StringT trees.


SGt

public Object SGt(List sub)
factory method: greater-then of two type.StringT trees.


SGe

public Object SGe(List sub)
factory method: greater-equal of two type.StringT trees.


SEq

public Object SEq(List sub)
factory method: equal of two type.StringT trees.


SNe

public Object SNe(List sub)
factory method: not-equal of two type.StringT trees.


PBegin

public Object PBegin(Object type,
                     List sub)
factory method: block ending in type.ProcT tree.


PIf

public Object PIf(Object type,
                  List sub)
factory method: if with type.ProcT alternatives.


PLet

public Object PLet(Object type,
                   List sub)
factory method: let with type.ProcT body.


PVar

public Object PVar(Object type,
                   List sub)
factory method: var with type.ProcT initializer.


PDeref

public Object PDeref(Object type,
                     List sub)
factory method: deref String to type.ProcT.


PLetrec

public Object PLetrec(Object type,
                      List sub)
factory method: letrec with type.ProcT body.


PCall

public Object PCall(Object type,
                    List sub)
factory method: call with type.ProcT result.