public class TypeSystem extends Object
| Modifier and Type | Field and Description |
|---|---|
static TypeInferer.Environment |
NULL_ENVIRONMENT
The "null" environment provides a simple environment which simply falls
back to using the declared type for a given variable.
|
| Constructor and Description |
|---|
TypeSystem(wybs.lang.Build.Project project) |
| Modifier and Type | Method and Description |
|---|---|
Formula |
extractInvariant(WyalFile.Type type,
WyalFile.Expr root)
Extracting the invariant (if any) from a given type.
|
WyalFile.Type.Array |
extractReadableArray(WyalFile.Type type)
Extract the readable array type from a given type.
|
WyalFile.Type.Record |
extractReadableRecord(WyalFile.Type type)
For a given type, extract its effective record type.
|
WyalFile.Type.Reference |
extractReadableReference(WyalFile.Type type)
Extract the readable reference type from a given type.
|
WyalFile.Type |
inferType(TypeInferer.Environment environment,
WyalFile.Expr expression)
Get the type inferred for a given expression in a given environment.
|
boolean |
isRawSubtype(WyalFile.Type lhs,
WyalFile.Type rhs)
Determine whether one type is a raw subtype of another.
|
<T extends WyalFile.Declaration.Named> |
resolveAll(wybs.util.AbstractCompilationUnit.Name name,
Class<T> kind) |
<T extends WyalFile.Declaration.Named> |
resolveExactly(wybs.util.AbstractCompilationUnit.Name name,
Class<T> kind) |
WyalFile.Type |
simplify(WyalFile.Type type) |
public static final TypeInferer.Environment NULL_ENVIRONMENT
public boolean isRawSubtype(WyalFile.Type lhs, WyalFile.Type rhs) throws wybs.lang.NameResolver.ResolutionError
Determine whether one type is a raw subtype of another.
Specifically, whether the raw type of rhs is a subtype of
lhs's raw type (i.e.
"⌊lhs⌋ :> ⌊rhs⌋"). The raw type
is that which ignores any type invariants involved. Thus, one must be
careful when interpreting the meaning of this operation. Specifically,
"⌊lhs⌋ :> ⌊rhs⌋" does not
imply that "lhs :> rhs" holds. However, if
"⌊lhs⌋ :> ⌊rhs⌋" does not hold,
then it does follow that "lhs :> rhs" also does not
hold.
Depending on the exact language of types involved, this can be a surprisingly complex operation. For example, in the presence of union, intersection and negation types, the subtype algorithm is surprisingly intricate.
lhs - The candidate "supertype". That is, lhs's raw type may be a
supertype of rhs's raw type.rhs - The candidate "subtype". That is, rhs's raw type may be a
subtype of lhs's raw type.wybs.lang.NameResolver.ResolutionError - Occurs when a nominal type is encountered whose name cannot
be resolved properly. For example, it resolves to more than
one possible matching declaration, or it cannot be resolved
to a corresponding type declaration.public WyalFile.Type.Record extractReadableRecord(WyalFile.Type type) throws wybs.lang.NameResolver.ResolutionError
({int x, int y}|{int x, int z}) has effective record
type {int x, ...}. The following illustrates some more
cases:
{int x, int y} | null ==> null
{int x, int y} | {int x} ==> null
{int x, int y} | {int x, bool y} ==> {int x, int|bool y}
{int x, int y} & null ==> null
{int x, int y} & {int x} ==> null
{int x, int y} & {int x, int|bool y} ==> {int x, int y}
type - wybs.lang.NameResolver.ResolutionErrorpublic WyalFile.Type.Array extractReadableArray(WyalFile.Type type) throws wybs.lang.NameResolver.ResolutionError
(int[])|(bool[]) has a readable array type of
(int|bool)[].type - wybs.lang.NameResolver.ResolutionErrorpublic WyalFile.Type.Reference extractReadableReference(WyalFile.Type type) throws wybs.lang.NameResolver.ResolutionError
&int is extracted as
&int. However, (&int)|(&bool) is not extracted
as as &(int|bool).type - wybs.lang.NameResolver.ResolutionErrorpublic Formula extractInvariant(WyalFile.Type type, WyalFile.Expr root) throws wybs.lang.NameResolver.ResolutionError
type nat is (int x) where x >= 0Then, extracting the invariant from type
nat gives
x >= 0. Likewise, extracting the invariant from the type
bool|int gives the invariant
(x is int) ==> (x >= 0). Finally, extracting the invariant
from the type nat[] gives the invariant
forall(int i).(0 <= i
&& i < |xs| ==> xs[i] >= 0).wybs.lang.NameResolver.ResolutionErrorpublic WyalFile.Type inferType(TypeInferer.Environment environment, WyalFile.Expr expression) throws wybs.lang.NameResolver.ResolutionError
environment - expression - wybs.lang.NameResolver.ResolutionError - Occurs when a particular named type cannot be resolved.public <T extends WyalFile.Declaration.Named> T resolveExactly(wybs.util.AbstractCompilationUnit.Name name, Class<T> kind) throws wybs.lang.NameResolver.ResolutionError
wybs.lang.NameResolver.ResolutionErrorpublic <T extends WyalFile.Declaration.Named> List<T> resolveAll(wybs.util.AbstractCompilationUnit.Name name, Class<T> kind) throws wybs.lang.NameResolver.ResolutionError
wybs.lang.NameResolver.ResolutionErrorpublic WyalFile.Type simplify(WyalFile.Type type)
Copyright © 2017. All rights reserved.