Package gnu.expr
Class CaseExp
java.lang.Object
gnu.mapping.PropertySet
gnu.mapping.Procedure
gnu.expr.Expression
gnu.expr.CaseExp
- All Implemented Interfaces:
gnu.kawa.format.Printable
,Named
,SourceLocator
,SourceLocator
,Locator
This class represents a case expression
case case-key case-clause+ case case-key case-clause* case-else-clause case-key ::= expression case-clause ::=((
datum*)
expression+)
|((
datum*) =>
expression)
case-else-clause ::= (else expression+) |(else =>
expression)
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
This class represent a clause of the case expression, of the form ((datum*) expression+) or (else expression+)Nested classes/interfaces inherited from interface gnu.text.SourceLocator
SourceLocator.Simple
-
Field Summary
Fields inherited from class gnu.expr.Expression
applyMethodExpression, flags, NEXT_AVAIL_FLAG, noExpressions, type, VALIDATED
Fields inherited from class gnu.mapping.Procedure
applyMethodType, applyToConsumerDefault, applyToConsumerMethod, applyToObjectDefault, applyToObjectMethod, compilerKey, compilerXKey, inlineIfConstantSymbol, validateApplyKey, validateXApplyKey
Fields inherited from class gnu.mapping.PropertySet
nameKey
-
Constructor Summary
ConstructorsConstructorDescriptionCaseExp
(Expression key, CaseExp.CaseClause[] clauses) Constructor for a case expression with no else clause.CaseExp
(Expression key, CaseExp.CaseClause[] clauses, CaseExp.CaseClause elseClause) Constructor for a case expression with an else clause. -
Method Summary
Modifier and TypeMethodDescriptionvoid
apply
(CallContext ctx) Evaluate the expression.protected Type
Computes the union type of the case expression datums.protected Object
calculateDatumValue
(Expression datum) Given the expression generated from a datum returns the value of the datum as an Object.protected Type
void
compile
(Compilation comp, Target target) protected boolean
void
print
(gnu.kawa.io.OutPort out) boolean
searchValue
(Object keyValue) Search a clause containing the specified key.selectCase
(Object keyValue) Search for a clause containing the specified key.protected <R,
D> R visit
(ExpVisitor<R, D> visitor, D d) protected <R,
D> void visitChildren
(ExpVisitor<R, D> visitor, D d) Methods inherited from class gnu.expr.Expression
applyMethodExpression, checkLiteralKeyword, compile, compile, compileWithPosition, compileWithPosition, deepCopy, deepCopy, deepCopy, deepCopy, eval, eval, getColumnNumber, getEndColumn, getEndLine, getFileName, getFlag, getFlags, getLineNumber, getPublicId, getStartColumn, getStartLine, getSystemId, getType, getTypeRaw, isSingleValue, isStableSourceLocation, makeWhile, maybeSetLine, neverReturns, numArgs, print, printLineColumn, setFile, setFlag, setFlag, setLine, setLine, setLine, setLine, setLine, setLocation, setType, side_effects, toString, validateApply, valueIfConstant
Methods inherited from class gnu.mapping.Procedure
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
Methods inherited from class gnu.mapping.PropertySet
getName, getProperty, getSymbol, removeProperty, setName, setProperty, setProperty, setSymbol
-
Constructor Details
-
CaseExp
Constructor for a case expression with no else clause. Arguments must be non null. clauses parameter must contain at least one CaseClause. -
CaseExp
Constructor for a case expression with an else clause. Arguments must be non null.
-
-
Method Details
-
mustCompile
protected boolean mustCompile()- Specified by:
mustCompile
in classExpression
-
apply
Description copied from class:Expression
Evaluate the expression. This is named apply rather than eval so it is compatible with the full-tail-call calling convention, and we can stash an Expression in CallContext's proc field. FIXME - are we making use of this?- Overrides:
apply
in classExpression
- Throws:
Throwable
-
print
public void print(gnu.kawa.io.OutPort out) - Specified by:
print
in classExpression
-
compile
- Specified by:
compile
in classExpression
-
visit
- Overrides:
visit
in classExpression
-
visitChildren
- Overrides:
visitChildren
in classExpression
-
calculateDatumValue
Given the expression generated from a datum returns the value of the datum as an Object. -
calculateType
- Overrides:
calculateType
in classExpression
-
calculateDatumsType
Computes the union type of the case expression datums. Useful to know if the datums are all integer values. -
searchValue
Search a clause containing the specified key. If the clause is found returns true, false otherwise. -
selectCase
Search for a clause containing the specified key. If the clause is found returns the corresponding expression.
-