public class UndecidedExpression extends ProtoExpression
If more than two options are to be considered, this expression may be nested within similar expressions. The typechecker maintains a stack of cut-point states to ensure that the correct typing context is recovered for each such undecided expression choice.
VOID_ASSIGNMENTS| Constructor and Description |
|---|
UndecidedExpression(Expression first,
Expression second) |
| Modifier and Type | Method and Description |
|---|---|
void |
compile(Compiler compiler)
This method compiles this expression in the context of the specified
Compiler.
|
Expression |
copy()
Returns a deep copy of this expression.
|
Expression |
getActualChoice()
Returns the selected option.
|
int |
getActualChoiceIndicator()
Returns an indicator of the subexpression selected:
0 if this is the first option expression,
1 if this is the second option expression,
-1 otherwise (no choice yet)
|
int |
numberOfSubexpressions()
Returns the number of subexpressions
|
void |
sanitizeSorts(Enclosure enclosure)
|
void |
setCheckedType()
This method sets the final unambiguously checked type of this expression, possibly
along with other final information that may be needed by the compiler for
generating code.
|
Expression |
setSubexpression(int n,
Expression expression)
Returns this expression after setting its n-th subexpression to the specified
expression; if there is no subexpression at the given position, this throws a
NoSuchSubexpressionException
|
Expression |
shiftOffsets(int intShift,
int realShift,
int objectShift,
int intDepth,
int realDepth,
int objectDepth)
This methods visits this expression shifting the offset of all the Locals it encounters by the specified amount (per
sort) as long as the offset it sees is referencing a parameter within the specified
scope depth (per sort); This method is used when the compiler needs to
synthesize an scope from an already typechecked expression (i.e., for
currying or un/boxing - e.g., see the pad method below).
|
Expression |
subexpression(int n)
Returns the n-th subexpression of this expression; if there is no subexpression
at the given position, this throws a NoSuchSubexpressionException
|
java.lang.String |
toString() |
void |
typeCheck(TypeChecker typeChecker)
Type-checking an UndecidedExpression works as follows:
a TypingState is pushed on
the typechecker's cut-point stack in order to inhibit backtracking before
this point;
the first option expression is typechecked;
if type-checking succeeds, the typechecker's cut-point stack is popped;
if it fails:
all the typechecker's goals trailed after the latest cut-point
are thrown away;
all the other typechecker's trails are unwound up to the points
indicated by the latest cut-point;
the cut-point stack is popped;
the second option is typechecked as the actual expression.
|
Expression |
typedCopy()
Returns a deep copy of this expression this and all its subexpressions share the
same type as their copy's counterparts.
|
checkedType, setCheckedType, setType, type, typeRefaddType, addTypes, boxSort, containsFreeName, enclosingScope, extent, getEnd, getStart, isConstant, isEquality, isFalse, isHiddenSlicing, isNull, isSelector, isSlicing, isTrue, isVoid, locationString, otherTypes, parameters, sanitizeNames, setCheckedTypeLocked, setEnd, setExtent, setOtherTypes, setStart, shiftOffsets, sort, substitute, typeCheck, typeCheck, typeCheckLockedpublic UndecidedExpression(Expression first, Expression second)
public final Expression copy()
Expressioncopy in class Expressionpublic final Expression typedCopy()
ExpressiontypedCopy in class Expressionpublic final int numberOfSubexpressions()
ExpressionnumberOfSubexpressions in class Expressionpublic final Expression subexpression(int n) throws NoSuchSubexpressionException
Expressionsubexpression in class ExpressionNoSuchSubexpressionExceptionpublic final Expression setSubexpression(int n, Expression expression) throws NoSuchSubexpressionException
ExpressionsetSubexpression in class ExpressionNoSuchSubexpressionExceptionpublic final int getActualChoiceIndicator()
public final Expression getActualChoice()
public final void setCheckedType()
ExpressionsetCheckedType in class Expressionpublic final void sanitizeSorts(Enclosure enclosure)
ExpressionsanitizeSorts in class Expressionpublic final Expression shiftOffsets(int intShift, int realShift, int objectShift, int intDepth, int realDepth, int objectDepth)
ExpressionshiftOffsets in class Expressionpublic final void typeCheck(TypeChecker typeChecker) throws TypingErrorException
typeCheck in class ExpressionTypingErrorExceptionpublic final void compile(Compiler compiler)
Expressioncompile in class Expressionpublic final java.lang.String toString()
toString in class java.lang.Object