public class TypeChecker extends java.lang.Object implements GoalProver
Some globally defined symbols having multiple types, it is necessary to keep choices of these and backtrack to alternative types upon failure. Therefore, a special goal is used to handle the typing of a Global: a GlobalTypingGoal. Thus, a TypeChecker object maintains all the necessary structures for undoing the effects that happened since the latest choice point. These effects are:
In order to maintain consistency of the effects of type checking, a typechecker object is passed as an argument to all goal proving as well as type unification methods to enable recording of any such effect in the appropriate trail. These effects may then be accordingly undone upon backtracking by unwinding the trails back to where the latest choice point indicates.
To recapitulate, the structures of a TypeChecker object are:
| Modifier and Type | Field and Description |
|---|---|
static boolean |
ALLOWS_POSITIONAL_NAMED_TUPLES
This is a boolean switch to dis/allow unification of position vs. named
tuple types; default is false.
|
static boolean |
ALLOWS_UNIFYING_OPAQUE_TUPLES
This is a boolean switch to dis/allow unification of opaquely defined tuple types
against plain tuple types; default is false.
|
static boolean |
GIVES_DETAILS
This is a static boolean switch to make type clash errors give the actual incompatible
types that it found.
|
| Constructor and Description |
|---|
TypeChecker() |
| Modifier and Type | Method and Description |
|---|---|
void |
allTypes(Expression expression,
java.util.AbstractList types)
Performs an exhaustive type checking of the specifed expression, recording
the types it finds in the specified list.
|
void |
disallowVoid(Type type,
Locatable extent,
java.lang.Object info)
Proves a residuated NoVoidTypeGoal
for the specified type.
|
void |
error(StaticSemanticsErrorException error) |
void |
error(StaticSemanticsErrorException error,
Locatable locatable) |
TypingState |
getTypingState()
Returns the current TypingState
of this typechecker.
|
boolean |
isTracing() |
TypingState |
popCutPoint()
Pops and returns the latest typing state on the cut-point stack.
|
void |
popExitable()
Pops the latest exitable scope.
|
void |
prove(Goal goal)
Proves the specfied goal by pushing it on the goal stack and calling the
_typecheck() method.
|
void |
prune(Global global,
Type filter,
Locatable extent)
Triggers the proving of a PruningGoal
for the specified global an filtering type, and records the specified location
extent into the goal.
|
void |
pushCutPoint()
Pushes the current typing state on the cut-point stack.
|
void |
pushExitable(Scope scope)
Pushes the specified exitable scope onto the exitable scope stack.
|
void |
pushGoal(Goal goal)
Pushes the specified goal on the goal stack.
|
void |
remainingTypes(Expression expression,
java.util.AbstractList types)
Finds all remaining types for the specifed expression starting in the current
typing state of this typechecker, recording the types it finds in the specified
list.
|
void |
reportError() |
TypeChecker |
reset()
Puts this type checker in a "virginal" state (i.e., as if it had
just been constructed).
|
void |
residuate(Type type,
Goal goal)
Constructs and proves a residuation wrapper for the specified goal in the
form of a ResiduatedGoal on
which the specified type is added as a trigger.
|
void |
setTracing(boolean flag) |
void |
toggleTrace() |
void |
trail(Application application,
Expression function,
Expression[] arguments)
Pushes the specified four objects on the application trail (corresponding to
the form of an application before being curryed).
|
void |
trail(Bindable bindable)
Pushes the specified Bindable object on the binding trail.
|
void |
trail(Goal goal)
Pushes the specified goal on the goal trail.
|
void |
typeCheck(Expression expression,
Type type)
Proves a TypingGoal constructed
with the specified expression and type.
|
void |
undoCutPoint() |
void |
unify(Type t1,
Type t2)
Triggers the unification of the two specified types by proving a
UnifyGoal constructed with the
two types.
|
void |
unify(Type t1,
Type t2,
Locatable extent)
Triggers the unification of the two specified types by proving a
UnifyGoal constructed with the
two types and recording the specified location extent.
|
public static boolean GIVES_DETAILS
public static boolean ALLOWS_POSITIONAL_NAMED_TUPLES
public static boolean ALLOWS_UNIFYING_OPAQUE_TUPLES
public final boolean isTracing()
public final void setTracing(boolean flag)
public final void toggleTrace()
public final void pushGoal(Goal goal)
public final void pushExitable(Scope scope)
public final void popExitable()
public final void pushCutPoint()
public final TypingState popCutPoint()
public final void trail(Bindable bindable)
trail in interface GoalProverpublic final void trail(Application application, Expression function, Expression[] arguments)
public final void trail(Goal goal)
trail in interface GoalProverpublic final void unify(Type t1, Type t2) throws TypingErrorException
TypingErrorExceptionpublic final void unify(Type t1, Type t2, Locatable extent) throws TypingErrorException
TypingErrorExceptionpublic final void typeCheck(Expression expression, Type type) throws TypingErrorException
TypingErrorExceptionpublic final void prune(Global global, Type filter, Locatable extent) throws TypingErrorException
TypingErrorExceptionpublic final void residuate(Type type, Goal goal) throws TypingErrorException
TypingErrorExceptionpublic final void disallowVoid(Type type, Locatable extent, java.lang.Object info) throws TypingErrorException
TypingErrorExceptionpublic final void prove(Goal goal) throws TypingErrorException
prove in interface GoalProverTypingErrorExceptionpublic final void allTypes(Expression expression, java.util.AbstractList types)
public final void remainingTypes(Expression expression, java.util.AbstractList types)
public final TypingState getTypingState()
public final TypeChecker reset()
public final void undoCutPoint()
public final void error(StaticSemanticsErrorException error) throws StaticSemanticsErrorException
StaticSemanticsErrorExceptionpublic final void error(StaticSemanticsErrorException error, Locatable locatable) throws StaticSemanticsErrorException
StaticSemanticsErrorExceptionpublic final void reportError()
throws StaticSemanticsErrorException
StaticSemanticsErrorException