harpoon.IR.Quads
Class TYPESWITCH

java.lang.Object
  extended by harpoon.IR.Quads.Quad
      extended by harpoon.IR.Quads.SIGMA
          extended by harpoon.IR.Quads.TYPESWITCH
All Implemented Interfaces:
HCodeElement, CFGraphable<Quad,Edge>, UseDefable, Graph.Node<Quad,Edge>, Serializable, Cloneable, Comparable<Quad>

public class TYPESWITCH
extends SIGMA

TYPESWITCH represents a multiple-way branch dependent on the class type of the argument. It may optionally omit the default case, in which case it is read as an assertion on the type of the argument, in addition to its usual semantics.

Version:
$Id: TYPESWITCH.java,v 1.5 2002/04/11 04:00:35 cananian Exp $
Author:
C. Scott Ananian <cananian@alumni.princeton.edu>
See Also:
Serialized Form

Field Summary
protected  boolean hasDefault
          True if this TYPESWITCH has a default case.
protected  Temp index
          The discriminant, of Object type, whose class is compared against each class type in keys[].
protected  HClass[] keys
          Class type keys for typeswitch cases.
 
Fields inherited from class harpoon.IR.Quads.SIGMA
dst, src
 
Fields inherited from class harpoon.IR.Quads.Quad
arrayFactory
 
Constructor Summary
TYPESWITCH(QuadFactory qf, HCodeElement source, Temp index, HClass[] keys, Temp[][] dst, Temp[] src, boolean hasDefault)
          Creates a TYPESWITCH operation.
TYPESWITCH(QuadFactory qf, HCodeElement source, Temp index, HClass[] keys, Temp[] src, boolean hasDefault)
          Creates a typeswitch with arity defined by the keys array.
 
Method Summary
<T> T
accept(QuadValueVisitor<T> v)
           
 void accept(QuadVisitor v)
          Accept a visitor.
 boolean hasDefault()
          Returns true if this TYPESWITCH has a default case.
 Temp index()
          Returns the Temp holding the discriminant.
 HClass[] keys()
          Returns the array of class type keys for the typeswitch cases.
 HClass keys(int i)
          Returns a given element in the keys array.
 int keysLength()
          Returns the length of the keys array.
 int kind()
          Return an integer enumeration of the kind of this Quad.
 Quad rename(QuadFactory qqf, TempMap defMap, TempMap useMap)
          Create a new Quad identical to the receiver, but with all Temps renamed according to a mapping.
 String toString()
          Returns human-readable representation of this quad.
 Temp[] use()
          Returns the Temp used by this quad.
 
Methods inherited from class harpoon.IR.Quads.SIGMA
arity, assign, def, dst, dst, dst, numSigmas, removeSigma, src, src
 
Methods inherited from class harpoon.IR.Quads.Quad
addEdge, addEdges, addHandlers, clone, clone, clone, compareTo, defC, edgeC, edges, getFactory, getID, getLineNumber, getSourceFile, handlers, hashCode, isPred, isSucc, map, map, map, next, next, nextEdge, nextEdge, nextLength, pred, predC, prev, prev, prevEdge, prevEdge, prevLength, remove, removeHandlers, rename, replace, succ, succC, toLongString, transferHandlers, useC
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

index

protected Temp index
The discriminant, of Object type, whose class is compared against each class type in keys[].


keys

protected HClass[] keys
Class type keys for typeswitch cases.

next(n) is the jump target corresponding to keys[n] for 0 <= n < keys.length.

next(keys.length) is the default target.


hasDefault

protected boolean hasDefault
True if this TYPESWITCH has a default case.

Constructor Detail

TYPESWITCH

public TYPESWITCH(QuadFactory qf,
                  HCodeElement source,
                  Temp index,
                  HClass[] keys,
                  Temp[][] dst,
                  Temp[] src,
                  boolean hasDefault)
Creates a TYPESWITCH operation.

next[n] is the jump target corresponding to keys[n] for 0 <= n < keys.length.

next[keys.length] is the default target.

Order among the keys is important; the destination corresponds to the *first* class type matching the argument. We differ from the modula-3 TYPECASE statement by disallowing null as a valid key value. The discriminant is also not permitted to be null (except in quad-with-try form, in which case a null discriminant causes the default branch to be taken). If withDefault is true, a default edge will be taken if none of the keys match the type of the argument; otherwise we assert that at least one key will always match the argument.

Parameters:
index - the discriminant.
keys - class type keys for switch cases.
dst - sigma function left-hand sides.
src - sigma function arguments.
hasDefault - true if this TYPESWITCH should have a default case.

TYPESWITCH

public TYPESWITCH(QuadFactory qf,
                  HCodeElement source,
                  Temp index,
                  HClass[] keys,
                  Temp[] src,
                  boolean hasDefault)
Creates a typeswitch with arity defined by the keys array.

Method Detail

index

public Temp index()
Returns the Temp holding the discriminant.


keys

public HClass[] keys()
Returns the array of class type keys for the typeswitch cases.


keys

public HClass keys(int i)
Returns a given element in the keys array.


keysLength

public int keysLength()
Returns the length of the keys array.


hasDefault

public boolean hasDefault()
Returns true if this TYPESWITCH has a default case.


use

public Temp[] use()
Returns the Temp used by this quad.

Specified by:
use in interface UseDefable
Overrides:
use in class SIGMA
Returns:
the index field.

kind

public int kind()
Description copied from class: Quad
Return an integer enumeration of the kind of this Quad. The enumerated values are defined in QuadKind.

Specified by:
kind in class Quad

rename

public Quad rename(QuadFactory qqf,
                   TempMap defMap,
                   TempMap useMap)
Description copied from class: Quad
Create a new Quad identical to the receiver, but with all Temps renamed according to a mapping. The new Quad will have no edges.

The new Quad will come from the specified QuadFactory.

Specified by:
rename in class Quad

accept

public void accept(QuadVisitor v)
Description copied from class: Quad
Accept a visitor.

Overrides:
accept in class SIGMA

accept

public <T> T accept(QuadValueVisitor<T> v)
Overrides:
accept in class SIGMA

toString

public String toString()
Returns human-readable representation of this quad.

Overrides:
toString in class SIGMA