public abstract class Expression extends Procedure implements gnu.kawa.format.Printable, SourceLocator
SourceLocator.Simple
Modifier and Type | Field and Description |
---|---|
static java.lang.invoke.MethodHandle |
applyMethodExpression |
protected int |
flags |
protected static int |
NEXT_AVAIL_FLAG |
static Expression[] |
noExpressions |
protected Type |
type |
static int |
VALIDATED |
applyMethodType, applyToConsumerDefault, applyToConsumerMethod, applyToObjectDefault, applyToObjectMethod, compilerKey, compilerXKey, inlineIfConstantSymbol, validateApplyKey, validateXApplyKey
nameKey
Constructor and Description |
---|
Expression() |
Modifier and Type | Method and Description |
---|---|
void |
apply(CallContext ctx)
Evaluate the expression.
|
static java.lang.Object |
applyMethodExpression(Procedure proc,
CallContext ctx) |
protected Type |
calculateType() |
Keyword |
checkLiteralKeyword()
Is this a keyword argument?
In the future this will return non-null only for explicit
literal non-quoted Keywords.
|
void |
compile(Compilation comp,
Declaration lhs)
Compile an expression with checking suitable for a known Declaration.
|
abstract void |
compile(Compilation comp,
Target target) |
void |
compile(Compilation comp,
Type type) |
void |
compileWithPosition(Compilation comp,
Target target)
Same as compile, but emit line number beforehard.
|
void |
compileWithPosition(Compilation comp,
Target target,
Expression position)
Same as 2-argument compileWithPosition,
but use some other Expression's line number.
|
protected static Expression |
deepCopy(Expression exp) |
static Expression[] |
deepCopy(Expression[] exps,
IdentityHashTable mapper) |
static Expression |
deepCopy(Expression exp,
IdentityHashTable mapper)
Make a deep copy of this expression, if possible.
|
protected Expression |
deepCopy(IdentityHashTable mapper) |
java.lang.Object |
eval(CallContext ctx) |
java.lang.Object |
eval(Environment env) |
int |
getColumnNumber()
Return current column number.
|
int |
getEndColumn()
Column (one-origin) of end of range; unknown/unspecified is -1.
|
int |
getEndLine()
Line number (one-origin) of end of range; unknown/unspecified is -1.
|
java.lang.String |
getFileName()
Normally same as getSystemId.
|
boolean |
getFlag(int flag) |
int |
getFlags() |
int |
getLineNumber()
Return current line number.
|
java.lang.String |
getPublicId() |
int |
getStartColumn()
Column (one-origin) of start of range; unknown/unspecified is -1.
|
int |
getStartLine()
Line number (one-origin) of start of range; unknown/unspecified is -1.
|
java.lang.String |
getSystemId() |
Type |
getType()
Return the Type used to represent the values of this Expression.
|
Type |
getTypeRaw() |
boolean |
isSingleValue() |
boolean |
isStableSourceLocation()
True if position is unlikely to change.
|
static Expression |
makeWhile(java.lang.Object cond,
java.lang.Object body,
Compilation parser)
Helper method to create a `while' statement.
|
Expression |
maybeSetLine(Expression old) |
protected abstract boolean |
mustCompile() |
boolean |
neverReturns()
True if the expression provably never returns.
|
int |
numArgs()
Return
minArgs()|(maxArgs<<12) . |
void |
print(Consumer out) |
abstract void |
print(gnu.kawa.io.OutPort ps) |
void |
printLineColumn(gnu.kawa.io.OutPort out)
Print line and column number if specified.
|
void |
setFile(java.lang.String filename) |
void |
setFlag(boolean setting,
int flag) |
void |
setFlag(int flag) |
void |
setLine(Compilation comp)
Set line number from current position in
Compilation . |
Expression |
setLine(Expression old) |
void |
setLine(int lineno) |
void |
setLine(int lineno,
int colno) |
void |
setLine(int startLine,
int startColumn,
int endLine,
int endColumn) |
void |
setLocation(SourceLocator location)
Copies the current location.
|
void |
setType(Type type) |
boolean |
side_effects()
True if evaluating may have side-effects.
|
java.lang.String |
toString() |
Expression |
validateApply(ApplyExp exp,
InlineCalls visitor,
Type required,
Declaration decl)
Apply inlining transformations on a given ApplyExp.
|
java.lang.Object |
valueIfConstant()
Return value if it is constant, or null if non-constant or unknown.
|
protected <R,D> R |
visit(ExpVisitor<R,D> visitor,
D d) |
protected <R,D> void |
visitChildren(ExpVisitor<R,D> visitor,
D d) |
apply0, apply1, apply2, apply3, apply4, applyL, applyN, applyToConsumerDefault, applyToObjectDefault, checkArgCount, checkBadCode, getApplyMethod, getApplyToConsumerMethod, getApplyToObjectMethod, getReturnType, getSetter, getSourceLocation, isSideEffectFree, lookupApplyHandle, maxArgs, maxArgs, minArgs, minArgs, set0, set1, setN, setSetter, setSourceLocation
getName, getProperty, getSymbol, removeProperty, setName, setProperty, setProperty, setSymbol
public static final java.lang.invoke.MethodHandle applyMethodExpression
public static final Expression[] noExpressions
protected Type type
protected int flags
public static final int VALIDATED
protected static final int NEXT_AVAIL_FLAG
public static java.lang.Object applyMethodExpression(Procedure proc, CallContext ctx) throws java.lang.Throwable
java.lang.Throwable
public final java.lang.Object eval(CallContext ctx) throws java.lang.Throwable
java.lang.Throwable
public final java.lang.Object eval(Environment env) throws java.lang.Throwable
java.lang.Throwable
protected abstract boolean mustCompile()
public int numArgs()
Procedure
minArgs()|(maxArgs<<12)
.
We use a single virtual function to reduce the number of methods
in the system, as well as the number of virtual method table entries.
We shift by 12 so the number can normally be represented using a
sipush instruction, without requiring a constant pool entry.public void apply(CallContext ctx) throws java.lang.Throwable
java.lang.Throwable
public final void print(Consumer out)
print
in interface gnu.kawa.format.Printable
public abstract void print(gnu.kawa.io.OutPort ps)
public void printLineColumn(gnu.kawa.io.OutPort out)
public abstract void compile(Compilation comp, Target target)
public final void compileWithPosition(Compilation comp, Target target)
public final void compileWithPosition(Compilation comp, Target target, Expression position)
public final void compile(Compilation comp, Type type)
public final void compile(Compilation comp, Declaration lhs)
public static Expression deepCopy(Expression exp, IdentityHashTable mapper)
mapper
- used to lookup parts (expressions, declarations)
that have been translated in the parent.
Needed for copied Declarations and BlockExps.public static Expression[] deepCopy(Expression[] exps, IdentityHashTable mapper)
protected static Expression deepCopy(Expression exp)
protected Expression deepCopy(IdentityHashTable mapper)
protected <R,D> R visit(ExpVisitor<R,D> visitor, D d)
protected <R,D> void visitChildren(ExpVisitor<R,D> visitor, D d)
public Expression validateApply(ApplyExp exp, InlineCalls visitor, Type required, Declaration decl)
exp
- an application whose function expression can be simplified
to this expression.visitor
- the context for the current inlining passdecl
- if non-null, a Declaration bound to this expression.public static Expression makeWhile(java.lang.Object cond, java.lang.Object body, Compilation parser)
public final void setLocation(SourceLocator location)
public final Expression setLine(Expression old)
public final Expression maybeSetLine(Expression old)
public final void setFile(java.lang.String filename)
public final void setLine(int startLine, int startColumn, int endLine, int endColumn)
public final void setLine(int lineno, int colno)
public final void setLine(int lineno)
public final java.lang.String getFileName()
SourceLocator
public void setLine(Compilation comp)
Compilation
.public java.lang.String getPublicId()
getPublicId
in interface javax.xml.transform.SourceLocator
getPublicId
in interface org.xml.sax.Locator
public java.lang.String getSystemId()
getSystemId
in interface javax.xml.transform.SourceLocator
getSystemId
in interface org.xml.sax.Locator
public final int getLineNumber()
SourceLocator
getStartLine()
.
The "first" line is line 1; unknown is -1.getLineNumber
in interface javax.xml.transform.SourceLocator
getLineNumber
in interface org.xml.sax.Locator
public final int getColumnNumber()
SourceLocator
getStartColumn()
.
The "first" column is column 1; unknown is -1.getColumnNumber
in interface javax.xml.transform.SourceLocator
getColumnNumber
in interface org.xml.sax.Locator
public final int getStartLine()
SourceLocator
public final int getStartColumn()
SourceLocator
public final int getEndLine()
SourceLocator
public final int getEndColumn()
SourceLocator
public boolean isStableSourceLocation()
SourceLocator
public final Type getType()
protected Type calculateType()
public final Type getTypeRaw()
public void setType(Type type)
public boolean neverReturns()
public Keyword checkLiteralKeyword()
public boolean isSingleValue()
public java.lang.Object valueIfConstant()
public void setFlag(boolean setting, int flag)
public void setFlag(int flag)
public int getFlags()
public boolean getFlag(int flag)
public boolean side_effects()