scale.clef.expr
Class Expression

java.lang.Object
  extended by scale.common.Root
      extended by scale.clef.Node
          extended by scale.clef.expr.Expression
All Implemented Interfaces:
AnnotationInterface, DisplayNode
Direct Known Subclasses:
CallOp, DyadicOp, HeapOp, IdReferenceOp, Literal, MonadicOp, SubscriptOp, TernaryOp, ThisOp, VarArgOp

public abstract class Expression
extends Node

This is the base class for expressions such as add, subscript, etc.

$Id: Expression.java,v 1.74 2007-08-28 21:10:10 burrill Exp $

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


Constructor Summary
Expression(Type type)
           
 
Method Summary
 long canonical()
          Return a unique value representing this particular expression.
 boolean containsDeclaration(Declaration decl)
          Return true if this expression contains a reference to the variable.
 boolean equivalent(java.lang.Object exp)
          Return true if the two expressions are equivalent.
 Literal getConstantValue()
          Return the constant value of the expression.
 Type getCoreType()
          Get the actual Type in cases where getting a RefType will be a problem.
abstract  void getDeclList(java.util.AbstractCollection<Declaration> varList)
          Add all declarations referenced in this expression to the collection.
 DColor getDisplayColorHint()
          Return a String specifying the color to use for coloring this node in a graphical display.
 java.lang.String getDisplayLabel()
          Return a String suitable for labeling this node in a graphical display.
 DShape getDisplayShapeHint()
          Return a String specifying a shape to use when drawing this node in a graphical display.
 Type getPointedToCore()
          Return the type of the thing pointed to by the type of the expression.
 Type getType()
          Return the Type associated with this Node.
 boolean hasTrueFalseResult()
          Return true if the result of the expression is either true (1) or false (0).
 boolean isSimpleOp()
          Return true if compilation of this expression will not result in the generation of a CFG node.
 void setType(Type type)
          Specify the type associated with this expression.
 java.lang.String toStringSpecial()
          This method allows sub-classes to provide class specific stuff to the string.
 void visit(Predicate p)
          Process a node by calling its associated routine.
 
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

Expression

public Expression(Type type)
Method Detail

getDeclList

public abstract void getDeclList(java.util.AbstractCollection<Declaration> varList)
Add all declarations referenced in this expression to the collection.


equivalent

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


toStringSpecial

public java.lang.String toStringSpecial()
Description copied from class: Node
This method allows sub-classes to provide class specific stuff to the string.

Overrides:
toStringSpecial in class Node

getDisplayLabel

public java.lang.String getDisplayLabel()
Return a String suitable for labeling this node in a graphical display. This method should be over-ridden as it simplay returns the class name.

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

getDisplayColorHint

public DColor getDisplayColorHint()
Return a String specifying the color to use for coloring this node in a graphical display. This method should be over-ridden as it simplay returns the color red.

Specified by:
getDisplayColorHint in interface DisplayNode
Overrides:
getDisplayColorHint in class Root
See Also:
DColor

getDisplayShapeHint

public DShape getDisplayShapeHint()
Return a String specifying a shape to use when drawing this node in a graphical display. This method should be over-ridden as it simplay returns the shape "box".

Specified by:
getDisplayShapeHint in interface DisplayNode
Overrides:
getDisplayShapeHint in class Root
See Also:
DShape

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

getType

public final Type getType()
Description copied from class: Node
Return the Type associated with this Node.

Overrides:
getType in class Node

setType

public void setType(Type type)
Specify the type associated with this expression.


getCoreType

public final Type getCoreType()
Get the actual Type in cases where getting a RefType will be a problem. For example, if the expression should be of type PointerType, a cast of a RefType to PointerType will cause an exception eventhough the RefType contains the PointerType. Note - getType() should always be used when the Type is not examined or when the attributes are needed.

Overrides:
getCoreType in class Node
See Also:
getType(), RefType

getPointedToCore

public final Type getPointedToCore()
Return the type of the thing pointed to by the type of the expression. Equivalent to
   getCoreType().getPointedTo().getCoreType()
 


getConstantValue

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

See Also:
Lattice

canonical

public long canonical()
Return a unique value representing this particular expression.


isSimpleOp

public boolean isSimpleOp()
Return true if compilation of this expression will not result in the generation of a CFG node. For example, (a && b) may require a branch to represent and i++ requires a store.


hasTrueFalseResult

public boolean hasTrueFalseResult()
Return true if the result of the expression is either true (1) or false (0).


containsDeclaration

public boolean containsDeclaration(Declaration decl)
Return true if this expression contains a reference to the variable.