scale.clef.type
Class Bound

java.lang.Object
  extended by scale.common.Root
      extended by scale.clef.Node
          extended by scale.clef.type.Bound
All Implemented Interfaces:
AnnotationInterface, DisplayNode

public class Bound
extends Node

A Bound class represents a range of allowed integer values.

$Id: Bound.java,v 1.62 2007-10-04 19:58:08 burrill Exp $

Copyright 2008 by the Scale Compiler Group,
Department of Computer Science
University of Massachusetts,
Amherst MA. 01003, USA
All Rights Reserved.


Field Summary
static Bound noBound
          Represents a "no bounds".
static Bound noValues
          Represents a range with no values.
 
Method Summary
 int bitSize()
          Return the number of bits required to represent the maximum.
static void cleanup()
          Remove static lists of types.
static Bound create(Expression min, Expression max)
          Create a representation of a range from min to max.
static Bound create(long min, long max)
          Create a representation of a range from min to max.
 boolean equivalent(Node tc)
          Return true if the types are equivalent.
 Node getChild(int i)
          Return the specified AST child of this node.
 long getConstMax()
          Return the integer value maximum value for the bound.
 long getConstMin()
          Return the integer value minimum value for the bound.
 java.lang.String getDisplayLabel()
          Return short description of current node.
 Expression getMax()
          Return the expression representing the maximum of the bounds.
 Expression getMin()
          Return the expression representing the minimum of the bounds.
 boolean isConstantBounds()
          Check if the bounds represent integer contant expressions.
 long numberOfElements()
          Return the number of elements in a bound (range) if the min and max expressions are integer literals
 int numChildren()
          Return the number of AST children of this node.
protected  void setMax(Expression max)
          Specify the expression representing the maximum of the bounds.
protected  void setMin(Expression min)
          Specify the expression representing the minimum of the bounds.
 java.lang.String toString()
           
 void visit(Predicate p)
          Process a node by calling its associated routine.
 
Methods inherited from class scale.clef.Node
getCoreType, getDecl, getSourceLineNumber, getType, setAnnotationLevel, setReportLevel, setSourceLineNumber, toString, toStringChildren, toStringSpecial
 
Methods inherited from class scale.common.Root
addAnnotation, allAnnotations, allMatchingAnnotations, getAnnotation, getDisplayColorHint, getDisplayName, getDisplayShapeHint, getDisplayString, getNodeCount, getNodeID, hasAnnotation, hasEqualAnnotation, hashCode, removeAnnotation, removeAnnotations, toStringAnnotations, toStringClass, trace, trace, trace
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

noBound

public static final Bound noBound
Represents a "no bounds". In C, this would be represented by [].


noValues

public static final Bound noValues
Represents a range with no values. In C, this would be represented by [0].

Method Detail

create

public static Bound create(Expression min,
                           Expression max)
Create a representation of a range from min to max.

Parameters:
min - is the lower bound
max - is the upper bound

create

public static Bound create(long min,
                           long max)
Create a representation of a range from min to max. If min > max, the bound is considered to be unbounded.

Parameters:
min - the lower bound
max - the upper bound

getMin

public final Expression getMin()
Return the expression representing the minimum of the bounds.


getMax

public final Expression getMax()
Return the expression representing the maximum of the bounds.


getConstMax

public final long getConstMax()
                       throws InvalidException
Return the integer value maximum value for the bound.

Throws:
InvalidException - if the maximum value for the bound is not statically known

getConstMin

public final long getConstMin()
                       throws InvalidException
Return the integer value minimum value for the bound.

Throws:
InvalidException - if the minimum value for the bound is not statically known

numberOfElements

public final long numberOfElements()
                            throws InvalidException
Return the number of elements in a bound (range) if the min and max expressions are integer literals

Returns:
max - min + 1 or null if either max or min aren't literals
Throws:
InvalidException - if the number of elements is not statically known

bitSize

public int bitSize()
Return the number of bits required to represent the maximum.


isConstantBounds

public final boolean isConstantBounds()
Check if the bounds represent integer contant expressions. If so, then return true else return false.

Returns:
true is the bounds are constant expresssions, otherwise false

visit

public void visit(Predicate p)
Description copied from class: Node
Process a node by calling its associated routine. See the "visitor" design pattern in Design Patterns: Elements of Reusable Object-Oriented Software by E. Gamma, et al, Addison Wesley, ISBN 0-201-63361-2.

Each class has a visit(Predicate p) method. For example, in class ABC:

   public void visit(Predicate p)
   {
     p.visitABC(this);
   }
 
and the class that implements Predicate has a method
   public void visitABC(Node n)
   {
     ABC a = (ABC) n;
     ...
   }
 
Thus, the class that implements Predicate can call
   n.visit(this);
 
where n is a Node sub-class without determining which specific sub-class n is. The visit pattern basically avoids implementing a large switch statement or defining different methods in each class for some purpose.

Specified by:
visit in class Node
See Also:
Predicate

setMin

protected final void setMin(Expression min)
Specify the expression representing the minimum of the bounds.


setMax

protected final void setMax(Expression max)
Specify the expression representing the maximum of the bounds.


getChild

public Node getChild(int i)
Return the specified AST child of this node.

Overrides:
getChild in class Node

numChildren

public int numChildren()
Return the number of AST children of this node.

Overrides:
numChildren in class Node

equivalent

public boolean equivalent(Node tc)
Return true if the types are equivalent.


getDisplayLabel

public java.lang.String getDisplayLabel()
Return short description of current node.

Specified by:
getDisplayLabel in interface DisplayNode
Overrides:
getDisplayLabel in class Root

cleanup

public static void cleanup()
Remove static lists of types.


toString

public java.lang.String toString()
Overrides:
toString in class Node