public class CoercionCheck extends Object implements wybs.lang.Build.Stage<WyilFile>
The point of the coercion check is to check that all convert bytecodes make sense, and are not ambiguous. For example, consider the following code:
define Rec1 as { real x, int y }
define Rec2 as { int x, real y }
define uRec1Rec2 as Rec1 | Rec2
int f(uRec1Rec2 r):
if r is Rec1:
return r.y
else:
return r.x
int g():
rec = { x: 1, y: 1}
return f(rec)
An implicit coercion will be inserted just before the last statement in
g(). This will be:
convert {int x,int y} => {real x,int y}|{int x,real y}
However, this conversion is ambiguous because we could convert the left-hand side to either of the two options in the right-hand side.
| Constructor and Description |
|---|
CoercionCheck(wybs.lang.Build.Task builder) |
| Modifier and Type | Method and Description |
|---|---|
void |
apply(WyilFile module) |
protected void |
check(SyntaxTree tree) |
protected void |
check(Type from,
Type to,
HashSet<wycc.util.Pair<Type,Type>> visited,
wybs.lang.SyntacticElement element)
Recursively check that there is no ambiguity in coercing type from into
type to.
|
public void apply(WyilFile module)
apply in interface wybs.lang.Build.Stage<WyilFile>protected void check(SyntaxTree tree)
protected void check(Type from, Type to, HashSet<wycc.util.Pair<Type,Type>> visited, wybs.lang.SyntacticElement element) throws wybs.util.ResolveError
from - to - visited - - the set of pairs already checked.location - - source location attribute (if applicable).wybs.util.ResolveError - If a named type within this condition cannot be resolved
within the enclosing project.Copyright © 2017. All rights reserved.