orc.type
Class Type

java.lang.Object
  extended by orc.type.Type
Direct Known Subclasses:
ArrowType, BooleanType, Bot, ConstructorType, DatatypeSiteType, DotType, EllipsisArrowType, LetType, Message, MultiType, NumberType, SignalType, StringType, Top, TupleType, Tycon, TypeApplication, TypeInstance, TypeVariable

public abstract class Type
extends java.lang.Object

Abstract superclass of all types for the Orc typechecker. This typechecker is based on the local type inference algorithms described by Benjamin Pierce and David Turner in their paper entitled "Local Type Inference". It extends that inference strategy with tuples, library-defined type constructors, user-defined datatypes, variance annotations, and other small changes.

Author:
dkitchin

Field Summary
static Type BOOLEAN
           
static Type BOT
           
static Type INTEGER
           
static Type LET
           
static Type NUMBER
           
static Type SIGNAL
           
static Type STRING
           
static Type TOP
           
 
Constructor Summary
Type()
           
 
Method Summary
 void addConstraints(Env<java.lang.Boolean> VX, Type T, Constraint[] C)
           
static java.util.Set<java.lang.Integer> allFreeVars(java.util.Collection<Type> collection)
           
 void assertSubtype(Type that)
           
 Tycon asTycon()
           
 Type call(java.util.List<Type> args)
           
 Type call(TypingContext ctx, java.util.List<Argument> args, java.util.List<Type> typeActuals)
           
 boolean closed()
           
 Type demote(Env<java.lang.Boolean> V)
           
 boolean equal(Type that)
           
 Variance findVariance(java.lang.Integer var)
           
 java.util.Set<java.lang.Integer> freeVars()
           
static Type fromJavaClass(java.lang.Class cls)
          Convert a Java class to an Orc type.
static Type fromJavaMethod(java.lang.reflect.Method mth, java.util.Map<java.lang.reflect.TypeVariable,Type> javaCtx)
           
static Type fromJavaMethods(java.util.List<java.lang.reflect.Method> matchingMethods, java.util.Map<java.lang.reflect.TypeVariable,Type> javaCtx)
          From a list of Java Methods, which are assumed to be the declarations of an overloaded method, create an Orc type, either an ArrowType for a singleton method or a MultiType for multiple methods, to typecheck the possible invocations of that method.
static Type fromJavaType(java.lang.reflect.Type genericType)
           
static Type fromJavaType(java.lang.reflect.Type genericType, java.util.Map<java.lang.reflect.TypeVariable,Type> javaCtx)
          From a Java type, possibly a generic type, create an Orc type.
 boolean isBot()
           
 boolean isTop()
           
 java.lang.Class javaCounterpart()
          Determine whether this type has a counterpart as a non-generic class in the Java class hierarchy.
 Type join(Type that)
           
static java.util.Map<java.lang.reflect.TypeVariable,Type> makeJavaCtx()
           
static java.util.Map<java.lang.reflect.TypeVariable,Type> makeJavaCtx(java.lang.Class cls, java.util.List<Type> typeActuals)
          From a class with Java type formals and a list of actual Orc type parameters, create a mapping from those Java variables to their appropriate Orc type bindings.
 Type marshal()
          Convert to a syntactic type.
 Type meet(Type that)
           
 Type promote(Env<java.lang.Boolean> V)
           
 Type resolveSites(Config config)
           
static java.util.Set<java.lang.Integer> shiftFreeVars(java.util.Set<java.lang.Integer> vars, java.lang.Integer distance)
           
 Type subst(Env<Type> ctx)
           
static java.util.List<Type> substAll(java.util.List<Type> ts, Env<Type> ctx)
           
 boolean subtype(Type that)
           
 boolean supertype(Type that)
           
 java.lang.String toString()
           
 Type unwrapAs(Type T)
           
 java.util.List<Variance> variances()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

TOP

public static final Type TOP

BOT

public static final Type BOT

NUMBER

public static final Type NUMBER

STRING

public static final Type STRING

BOOLEAN

public static final Type BOOLEAN

INTEGER

public static final Type INTEGER

LET

public static final Type LET

SIGNAL

public static final Type SIGNAL
Constructor Detail

Type

public Type()
Method Detail

isTop

public boolean isTop()

isBot

public boolean isBot()

subtype

public boolean subtype(Type that)
                throws TypeException
Throws:
TypeException

assertSubtype

public void assertSubtype(Type that)
                   throws TypeException
Throws:
TypeException

supertype

public boolean supertype(Type that)
                  throws TypeException
Throws:
TypeException

equal

public boolean equal(Type that)
              throws TypeException
Throws:
TypeException

join

public Type join(Type that)
          throws TypeException
Throws:
TypeException

meet

public Type meet(Type that)
          throws TypeException
Throws:
TypeException

call

public Type call(TypingContext ctx,
                 java.util.List<Argument> args,
                 java.util.List<Type> typeActuals)
          throws TypeException
Throws:
TypeException

call

public Type call(java.util.List<Type> args)
          throws TypeException
Throws:
TypeException

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

subst

public Type subst(Env<Type> ctx)
           throws TypeException
Throws:
TypeException

substAll

public static java.util.List<Type> substAll(java.util.List<Type> ts,
                                            Env<Type> ctx)
                                     throws TypeException
Throws:
TypeException

variances

public java.util.List<Variance> variances()

unwrapAs

public Type unwrapAs(Type T)
              throws TypeException
Throws:
TypeException

asTycon

public Tycon asTycon()
              throws TypeException
Throws:
TypeException

freeVars

public java.util.Set<java.lang.Integer> freeVars()

allFreeVars

public static java.util.Set<java.lang.Integer> allFreeVars(java.util.Collection<Type> collection)

shiftFreeVars

public static java.util.Set<java.lang.Integer> shiftFreeVars(java.util.Set<java.lang.Integer> vars,
                                                             java.lang.Integer distance)

closed

public boolean closed()

findVariance

public Variance findVariance(java.lang.Integer var)

promote

public Type promote(Env<java.lang.Boolean> V)
             throws TypeException
Throws:
TypeException

demote

public Type demote(Env<java.lang.Boolean> V)
            throws TypeException
Throws:
TypeException

addConstraints

public void addConstraints(Env<java.lang.Boolean> VX,
                           Type T,
                           Constraint[] C)
                    throws TypeException
Throws:
TypeException

fromJavaMethods

public static Type fromJavaMethods(java.util.List<java.lang.reflect.Method> matchingMethods,
                                   java.util.Map<java.lang.reflect.TypeVariable,Type> javaCtx)
                            throws TypeException
From a list of Java Methods, which are assumed to be the declarations of an overloaded method, create an Orc type, either an ArrowType for a singleton method or a MultiType for multiple methods, to typecheck the possible invocations of that method.

Parameters:
matchingMethods -
javaCtx -
Returns:
The Orc arrow type for the methods
Throws:
TypeException

fromJavaMethod

public static Type fromJavaMethod(java.lang.reflect.Method mth,
                                  java.util.Map<java.lang.reflect.TypeVariable,Type> javaCtx)
                           throws TypeException
Throws:
TypeException

fromJavaType

public static Type fromJavaType(java.lang.reflect.Type genericType,
                                java.util.Map<java.lang.reflect.TypeVariable,Type> javaCtx)
                         throws TypeException
From a Java type, possibly a generic type, create an Orc type. This conversion requires a context for all Java type variables that may occur in the type to the appropriate Orc types bound to those variables.

Parameters:
genericType -
javaCtx -
Returns:
The Orc arrow type for the methods
Throws:
TypeException

fromJavaType

public static Type fromJavaType(java.lang.reflect.Type genericType)
                         throws TypeException
Throws:
TypeException

fromJavaClass

public static Type fromJavaClass(java.lang.Class cls)
                          throws TypeException
Convert a Java class to an Orc type. Generic classes are converted to tycons.

Parameters:
cls - Java class to be converted.
Returns:
Resulting Orc type.
Throws:
TypeException

makeJavaCtx

public static java.util.Map<java.lang.reflect.TypeVariable,Type> makeJavaCtx(java.lang.Class cls,
                                                                             java.util.List<Type> typeActuals)
                                                                      throws TypeArityException
From a class with Java type formals and a list of actual Orc type parameters, create a mapping from those Java variables to their appropriate Orc type bindings.

Parameters:
cls -
typeActuals -
Returns:
A new Java context, with the parameter mapping
Throws:
TypeArityException

makeJavaCtx

public static java.util.Map<java.lang.reflect.TypeVariable,Type> makeJavaCtx()

javaCounterpart

public java.lang.Class javaCounterpart()
Determine whether this type has a counterpart as a non-generic class in the Java class hierarchy. If not, return null. This is not a true inverse of fromJavaClass, though it behaves like one in most cases.


resolveSites

public Type resolveSites(Config config)
                  throws MissingTypeException
Throws:
MissingTypeException

marshal

public Type marshal()
             throws UnrepresentableTypeException
Convert to a syntactic type. May return null if the type is not representable.

Returns:
The syntactic type corresponding to this type
Throws:
UnrepresentableTypeException