scale.clef.expr
Class Literal

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
All Implemented Interfaces:
AnnotationInterface, DisplayNode
Direct Known Subclasses:
AddressLiteral, AggregationElements, BooleanLiteral, CharLiteral, ComplexLiteral, FloatArrayLiteral, FloatLiteral, IntArrayLiteral, IntLiteral, NilOp, SizeofLiteral, StringLiteral

public class Literal
extends Expression

The base class for classes which represent a literal, or constant, value.

$Id: Literal.java,v 1.61 2007-08-28 17:58:21 burrill Exp $

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

This class is also used to provide special literal values such as needed by the Lattice class.


Constructor Summary
Literal(Type type)
           
 
Method Summary
 int executionCostEstimate()
          Return a relative cost estimate for executing the expression.
 int findCoefficient()
          Return the coefficient value.
static java.lang.String formatRealValue(double value)
          Return a string representing the floating point value.
 Literal getConstantValue()
          Return the constant value of the expression.
 int getCount()
          Return the number of elements in the Literal.
 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.
 Literal getElement(long index)
          Return the specified element of the constant.
 java.lang.String getGenericValue()
          Get the string version of the literal using C syntax.
 boolean isOne()
          Return true if the value of this literal is known to be one.
 boolean isZero()
          Return true if the value of this literal is known to be zero.
 int linearity()
          Return linearity of literal.
 void visit(Predicate p)
          Process a node by calling its associated routine.
 
Methods inherited from class scale.clef.expr.Expression
canonical, containsDeclaration, equivalent, getCoreType, getDisplayColorHint, getDisplayShapeHint, getPointedToCore, getType, hasTrueFalseResult, isSimpleOp, setType, toStringSpecial
 
Methods inherited from class scale.clef.Node
getChild, getDecl, getSourceLineNumber, numChildren, setAnnotationLevel, setReportLevel, setSourceLineNumber, toString, toString, toStringChildren
 
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

Literal

public Literal(Type type)
Method Detail

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 Expression
See Also:
Predicate

getGenericValue

public java.lang.String getGenericValue()
Get the string version of the literal using C syntax. For another language, use getValue which returns an object that can then be displayed using logic specific to the target language.

Returns:
a String representing the literal value and uses C syntax

getCount

public int getCount()
Return the number of elements in the Literal.


getElement

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

Throws:
InvalidException

getConstantValue

public Literal getConstantValue()
Return the constant value of the expression.

Overrides:
getConstantValue in class Expression
See Also:
Lattice

getDisplayLabel

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

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

linearity

public int linearity()
Return linearity of literal. Integer literals have linearity of 0. All other literals have linearity of 2.


findCoefficient

public int findCoefficient()
Return the coefficient value.


executionCostEstimate

public int executionCostEstimate()
Return a relative cost estimate for executing the expression.


isZero

public boolean isZero()
Return true if the value of this literal is known to be zero.


isOne

public boolean isOne()
Return true if the value of this literal is known to be one.


formatRealValue

public static java.lang.String formatRealValue(double value)
Return a string representing the floating point value.


getDeclList

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

Specified by:
getDeclList in class Expression