scale.clef.expr
Class TypeConversionOp

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

public class TypeConversionOp
extends MonadicOp

A class which represents a language defined type conversion operation.

$Id: TypeConversionOp.java,v 1.56 2007-10-04 19:58:07 burrill Exp $

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

Type conversion rules vary substantially between languages. Hence, user code is responsible for ensuring that all implicit conversions are made explicit.

Some languages provide a fixed set of type conversions, but C++ allows users to define conversion routines for classes. Hence in the generation interface, a type conversion is a triple consisting of the expression to be converted, the type to which it is to be converted, and a routine for performing the conversion. For language defined conversions, the generation interface provides an enumerated list of recognized conversions. The elements of the following enumeration follow Modula-3 semantics.


Constructor Summary
TypeConversionOp(Type resultType, Expression e, CastMode conversion)
          A constructor which allows either a language-defined conversion routine to be specified.
 
Method Summary
static CastMode determineCast(Type targetType, Type sourceType)
          Return the type of cast required.
 boolean equivalent(java.lang.Object exp)
          Return true if the two expressions are equivalent.
 Literal getConstantValue()
          Return the constant value of the expression.
 CastMode getConversion()
          Return the type of conversion.
protected  void setConversion(CastMode c)
           
 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.expr.MonadicOp
containsDeclaration, getChild, getDeclList, getExpr, isSimpleOp, numChildren, setExpr
 
Methods inherited from class scale.clef.expr.Expression
canonical, getCoreType, getDisplayColorHint, getDisplayLabel, getDisplayShapeHint, getPointedToCore, getType, hasTrueFalseResult, setType
 
Methods inherited from class scale.clef.Node
getDecl, getSourceLineNumber, 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

TypeConversionOp

public TypeConversionOp(Type resultType,
                        Expression e,
                        CastMode conversion)
A constructor which allows either a language-defined conversion routine to be specified.

Parameters:
conversion - specifies the type conversion performed
Method Detail

equivalent

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

Overrides:
equivalent in class MonadicOp

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

getConversion

public final CastMode getConversion()
Return the type of conversion.


setConversion

protected final void setConversion(CastMode c)

getConstantValue

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

Overrides:
getConstantValue in class Expression
See Also:
Lattice

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 Expression

determineCast

public static CastMode determineCast(Type targetType,
                                     Type sourceType)
Return the type of cast required. If no cast is required, cNone is returned. If no valid cast is available, cInvalid is returned.