org.erights.e.elang.evm
Class LiteralExpr

java.lang.Object
  |
  +--org.erights.e.elang.evm.ParseNode
        |
        +--org.erights.e.elang.evm.ENode
              |
              +--org.erights.e.elang.evm.EExpr
                    |
                    +--org.erights.e.elang.evm.LiteralExpr
All Implemented Interfaces:
Cloneable, EPrintable, MatchMaker

public class LiteralExpr
extends EExpr

Safe: BNF: LiteralInteger | LiteralFloat64 | LiteralChar | LiteralString
# (perhaps someday): | LiteralTwine

Evaluates to the literal's value, which may be any

Note that not all E scalars are written as literals. In particular, null, false, and true are instead the names of non-shadowable variables in the universal scope holding the corresponding values. These scalars can thereby be written "literally enough" by writing these variable names. The similar cases of Infinity and NaN are explained below.

A LiteralExpr object may be programmatically created to hold any int or float64 value. However, the following ints and float64s cannot be written as literals in the E source language:

Because these literals have the same meaning as the E programs they print as, an optimizer operating on Kernel-E ASTs may, perhaps as part of constant folding, turn such constant expressions into LiteralExprs holding these values.

Author:
Mark S. Miller

Field Summary
private  Object myValue
           
 
Fields inherited from class org.erights.e.elang.evm.ENode
 
Fields inherited from class org.erights.e.elang.evm.ParseNode
NUM_PR, PR_ASSIGN, PR_CALL, PR_COMP, PR_EEXPR, PR_LISTPATT, PR_ORDER, PR_PATTERN, PR_PRIM, PR_START
 
Constructor Summary
LiteralExpr(SourceSpan optSpan, Object value)
          Enabled: Makes an EExpr that will evaluate to 'value'.
 
Method Summary
protected  StaticScope computeStaticScope()
          When staticScope() is first requested on a given node, it calls computeStaticScope() to do the actual computation, which is then remembered.
 boolean matchBind(ConstList args, Object specimen, FlexList bindings)
          Enabled:
 String printRep()
          Enabled:
protected  Object subEval(EvalContext ctx, boolean forValue)
          The recursive part that does the work
 void subPrintOn(TextWriter out, int priority)
          Enabled:
 Object value()
          Enabled:
 Object welcome(ETreeVisitor visitor)
          Enabled:
 
Methods inherited from class org.erights.e.elang.evm.EExpr
__printOn, appendAllTo, appendTo, eval, eval, evalBool, printAsBlockOn, substitute, transform
 
Methods inherited from class org.erights.e.elang.evm.ENode
cleanCopy, copy, getOptPatternMap, getOptScopeMap, getPatternMap, getScopeMap, qbuild, setPatternMap, setScopeMap, staticScope, synEnv
 
Methods inherited from class org.erights.e.elang.evm.ParseNode
asText, getOptSpan, lnPrintOn, lnPrintOn, matchBind, matchBind, matchBind, printListOn, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

myValue

private final Object myValue
Constructor Detail

LiteralExpr

public LiteralExpr(SourceSpan optSpan,
                   Object value)
Enabled: Makes an EExpr that will evaluate to 'value'.

Parameters:
value - If 'value' is a String (though not a Twine), then it is interned during construction. This makes no difference to E's semantics, but 1) may be more efficient, and 2) helps the E language and ELib/Java work together more smootly, since Java also interns all String literals. When compiling E to JVM bytecodes, an E literal will turn into a Java literal anyway, so this anticipates the resulting Java-level semantics.

Currently, 'value' may also be a Character, BigInteger, or Double. We expect to eventually allow 'value' to be a Twine as well, in order to preserve the source position of quasi-strings with Kernel-E code that's still readable.

Method Detail

welcome

public Object welcome(ETreeVisitor visitor)
Enabled:

Specified by:
welcome in class ENode

computeStaticScope

protected StaticScope computeStaticScope()
Description copied from class: ENode
When staticScope() is first requested on a given node, it calls computeStaticScope() to do the actual computation, which is then remembered.

Specified by:
computeStaticScope in class ENode

subEval

protected Object subEval(EvalContext ctx,
                         boolean forValue)
Description copied from class: EExpr
The recursive part that does the work

Specified by:
subEval in class EExpr

matchBind

public boolean matchBind(ConstList args,
                         Object specimen,
                         FlexList bindings)
Enabled:

Specified by:
matchBind in interface MatchMaker
Specified by:
matchBind in class ParseNode

subPrintOn

public void subPrintOn(TextWriter out,
                       int priority)
                throws IOException
Enabled:

Specified by:
subPrintOn in class ParseNode
IOException

printRep

public String printRep()
Enabled:


value

public Object value()
Enabled:



comments?