com.go.tea.parsetree
Class Expression

java.lang.Object
  |
  +--com.go.tea.parsetree.Node
        |
        +--com.go.tea.parsetree.Expression
All Implemented Interfaces:
java.lang.Cloneable, java.io.Serializable
Direct Known Subclasses:
ArrayLookup, BinaryExpression, CallExpression, Literal, Lookup, NegateExpression, NewArrayExpression, NotExpression, ParenExpression, VariableRef

public class Expression
extends Node

An Expression is a piece of code that, when executed, produces a value. All expressions have a type which represents the type of value is produces.

Version:
36 , 01/01/25
Author:
Brian S O'Neill
See Also:
Serialized Form

Inner Class Summary
static class Expression.Conversion
           
 
Constructor Summary
Expression(SourceInfo info)
           
 
Method Summary
 java.lang.Object accept(NodeVisitor visitor)
          Every subclass of Node must override this method with the following: return visitor.visit(this).
 java.lang.Object clone()
          Returns a clone of this Node and all its children.
 void convertTo(Type toType)
          Applies a type conversion to this expression which is chained to all previous conversions.
 void convertTo(Type toType, boolean preferCast)
          Applies a type conversion to this expression which is chained to all previous conversions.
 java.util.LinkedList getConversionChain()
          Returns a list of Conversion objects representing the all the conversions that have been applied to this Expression.
 Type getInitialType()
          Returns the type of this expression before any conversions were applied, or null if the type isn't set.
 Type getType()
          The type of an expression is not necessarily set by a parser.
 java.lang.Object getValue()
          Most expressions can't generate a value at compile-time, so this method simply returns null.
 boolean isExceptionPossible()
          Returns true if an exception can be thrown while executing this Expression.
 boolean isValueKnown()
          Returns true if the value generated by this expression is known at compile-time.
 void setInitialType(Type type)
          Sets the intial type in the conversion chain, but does not clear the conversions.
 void setType(Type type)
          Sets the type of this expression, clearing the conversion chain.
 
Methods inherited from class com.go.tea.parsetree.Node
getSourceInfo, toString
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Expression

public Expression(SourceInfo info)
Method Detail

accept

public java.lang.Object accept(NodeVisitor visitor)
Description copied from class: Node
Every subclass of Node must override this method with the following: return visitor.visit(this).
Overrides:
accept in class Node
Following copied from class: com.go.tea.parsetree.Node
Parameters:
visitor - A visitor of this Node
Returns:
Node The Node returned by the visitor
See Also:
NodeVisitor

clone

public java.lang.Object clone()
Description copied from class: Node
Returns a clone of this Node and all its children. Immutable child objects are not necessarily cloned
Overrides:
clone in class Node

isExceptionPossible

public boolean isExceptionPossible()
Returns true if an exception can be thrown while executing this Expression. By default, returns true only if a type conversion could cause an exception.

getType

public Type getType()
The type of an expression is not necessarily set by a parser. It is typically set by a type checker. An expression's type may represent its natural type or its coerced type. A code generator is responsible for ensuring that the type it generates correctly matches the type of the expression.
Returns:
null if type is unknown

getInitialType

public Type getInitialType()
Returns the type of this expression before any conversions were applied, or null if the type isn't set.

convertTo

public final void convertTo(Type toType)
Applies a type conversion to this expression which is chained to all previous conversions.
Parameters:
toType - the type to convert to.

convertTo

public void convertTo(Type toType,
                      boolean preferCast)
Applies a type conversion to this expression which is chained to all previous conversions.
Parameters:
toType - the type to convert to.
preferCast - a hint that the conversion should be performed by a type cast operation, by default is true.
Throws:
java.lang.IllegalArgumentException - when the conversion is illegal.

getConversionChain

public java.util.LinkedList getConversionChain()
Returns a list of Conversion objects representing the all the conversions that have been applied to this Expression. Unless the type isn't set, the chain contains at least one element. The conversion chain may be reduced or expanded, so its length doesn't necessarily represent the exact sequence of calls to convertTo(com.go.tea.compiler.Type).

setType

public void setType(Type type)
Sets the type of this expression, clearing the conversion chain.

setInitialType

public void setInitialType(Type type)
Sets the intial type in the conversion chain, but does not clear the conversions.

isValueKnown

public boolean isValueKnown()
Returns true if the value generated by this expression is known at compile-time. For most expressions, false is returned. Literals always return true.
See Also:
Literal

getValue

public java.lang.Object getValue()
Most expressions can't generate a value at compile-time, so this method simply returns null. Call isValueKnown to check if the expression's value is known at compile-time.