scale.clef.expr
Class AggregationElements

java.lang.Object
  extended by scale.common.Root
      extended by scale.clef.Node
          extended by scale.clef.expr.Expression
              extended by scale.clef.expr.Literal
                  extended by scale.clef.expr.AggregationElements
All Implemented Interfaces:
AnnotationInterface, DisplayNode

public class AggregationElements
extends Literal

The AggregationElements class represents an aggregation of values used to initialize a variable.

$Id: AggregationElements.java,v 1.67 2007-10-04 19:58:05 burrill Exp $

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

The elements of the aggregation comprize a sequence of Literal instances and PositionOp instances.

See Also:
Literal, PositionOp, PositionFieldOp, PositionIndexOp, PositionOffsetOp, PositionRepeatOp

Constructor Summary
AggregationElements(Type type, Vector<java.lang.Object> elements)
          Create an initialization expression to represent multiple values.
 
Method Summary
 boolean containsAllLiterals()
          Return true if the all elements are instances of the Literal class and none of the literals are AddressLiteral instances that reference constants or variables whose addresses are not constant.
 boolean containsAllZeros()
          Return true if the all the elements are zero.
 boolean equivalent(java.lang.Object exp)
          Return true if the two expressions are equivalent.
 Node getChild(int i)
          Return the specified AST child of this node.
 int getCount()
          Return the number of elements in the aggregation.
 void getDeclList(java.util.AbstractCollection<Declaration> varList)
          Add all declarations referenced in this expression to the collection.
 java.lang.String getDisplayLabel()
          Return short description of current node.
 java.lang.Object getElement(int i)
          Return the specified element of the aggregation.
 Literal getElement(long index)
          Return the specified element of the constant.
 Vector<java.lang.Object> getElementVector()
          Return a vector of the elements of the aggregation.
 java.lang.String getGenericValue()
          Get the string version of the literal using C syntax.
 int numChildren()
          Return the number of AST children of this node.
 int numElements()
          Return the number of elements in the aggregation.
 java.lang.String toStringChildren()
          Convert children of this node to a string representation.
 void visit(Predicate p)
          Process a node by calling its associated routine.
 
Methods inherited from class scale.clef.expr.Literal
executionCostEstimate, findCoefficient, formatRealValue, getConstantValue, isOne, isZero, linearity
 
Methods inherited from class scale.clef.expr.Expression
canonical, containsDeclaration, getCoreType, getDisplayColorHint, getDisplayShapeHint, getPointedToCore, getType, hasTrueFalseResult, isSimpleOp, setType, toStringSpecial
 
Methods inherited from class scale.clef.Node
getDecl, getSourceLineNumber, setAnnotationLevel, setReportLevel, setSourceLineNumber, toString, toString
 
Methods inherited from class scale.common.Root
addAnnotation, allAnnotations, allMatchingAnnotations, getAnnotation, getDisplayName, 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
 

Constructor Detail

AggregationElements

public AggregationElements(Type type,
                           Vector<java.lang.Object> elements)
Create an initialization expression to represent multiple values. Each element of the vector must be a Literal instance or a PositionOp instance.

Parameters:
type - is of no consequence
elements - is a vector of the elements and positioning information
Method Detail

equivalent

public boolean equivalent(java.lang.Object exp)
Return true if the two expressions are equivalent.

Overrides:
equivalent in class Expression

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.

Overrides:
visit in class Literal
See Also:
Predicate

getElement

public final java.lang.Object getElement(int i)
Return the specified element of the aggregation.


getElementVector

public final Vector<java.lang.Object> getElementVector()
Return a vector of the elements of the aggregation.


numElements

public int numElements()
Return the number of elements in the aggregation.


getCount

public int getCount()
Return the number of elements in the aggregation. This is the number of values specified - not the number of elements in the type.

Overrides:
getCount in class Literal

getElement

public Literal getElement(long index)
                   throws InvalidException
Return the specified element of the constant.

Overrides:
getElement in class Literal
Throws:
InvalidException

containsAllZeros

public final boolean containsAllZeros()
Return true if the all the elements are zero.


containsAllLiterals

public boolean containsAllLiterals()
Return true if the all elements are instances of the Literal class and none of the literals are AddressLiteral instances that reference constants or variables whose addresses are not constant.


getGenericValue

public java.lang.String getGenericValue()
Get the string version of the literal using C syntax.

Overrides:
getGenericValue in class Literal
Returns:
a String already converted for display using C syntax.

getDisplayLabel

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

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

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

toStringChildren

public java.lang.String toStringChildren()
Convert children of this node to a string representation.

Overrides:
toStringChildren in class Node

getDeclList

public void getDeclList(java.util.AbstractCollection<Declaration> varList)
Description copied from class: Expression
Add all declarations referenced in this expression to the collection.

Overrides:
getDeclList in class Literal