fmrisc.Semantics
Class TypeChecking

java.lang.Object
  extended byfmrisc.Semantics.TypeChecking

public final class TypeChecking
extends java.lang.Object

type checking routines


Constructor Summary
TypeChecking()
           
 
Method Summary
static Type canonical(Type type)
          returns canonical version of type (equality of two types implies the equality of the canonical version of the types).
static TypedIdentifier canonicalTypedIdentifier(TypedIdentifier tid)
          returns canonical version of typed identifier (equality of two types implies the equality of the canonical version of the types).
static TypeExpression clearSubtypes(Type type, Expression exp)
          return version of type where subtypes and subranges are replaced by their base types; the corresponding constraints are returned as a formula which a corresponding expression exp has to fulfill
static boolean hasType(Expression exp, Type etype, Type type, boolean tcc)
          returns true iff expr of type etype matches type.
static boolean isBoolean(Type type)
          checks if type equals BOOLEAN
static java.lang.Integer parseInt(java.lang.String digits)
          get number from digit representation
static void setMatchFunType(boolean match)
          signals whether subtype matching is enabled for function types
static Type subType(Type type0, Type type1)
          return greatest subtype of type0 and type1 (null, if none exists) does not generate tccs.
static Type typeCheck(Expression value)
          type check value
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TypeChecking

public TypeChecking()
Method Detail

setMatchFunType

public static void setMatchFunType(boolean match)
signals whether subtype matching is enabled for function types

Parameters:
match - is true iff subtype matching is to be enabled

isBoolean

public static boolean isBoolean(Type type)
checks if type equals BOOLEAN

Parameters:
type -
Returns:
true iff type equals BOOLEAN

canonical

public static Type canonical(Type type)
returns canonical version of type (equality of two types implies the equality of the canonical version of the types).

Parameters:
type - the type
Returns:
the canonical version of the type

canonicalTypedIdentifier

public static TypedIdentifier canonicalTypedIdentifier(TypedIdentifier tid)
returns canonical version of typed identifier (equality of two types implies the equality of the canonical version of the types).

Parameters:
tid - the typed identifier
Returns:
the canonical version of the typed identifier

parseInt

public static java.lang.Integer parseInt(java.lang.String digits)
get number from digit representation

Parameters:
digits - the representation of the number as a decimal digit sequence
Returns:
the number or null if conversion not possible

typeCheck

public static Type typeCheck(Expression value)
type check value

Parameters:
value - the value to be type checked
Returns:
the type of the value or null if typechecking encountered error

hasType

public static boolean hasType(Expression exp,
                              Type etype,
                              Type type,
                              boolean tcc)
returns true iff expr of type etype matches type. may add as a side effect a type checking condition to the global context. the following general rules succeed without generating TCCs: exp: T matches T exp: SUBTYPE(p:T->BOOL) matches T the following general rule succeeds by generating a TCC: exp: T matches SUBTYPE(T) if p(exp) the following structural rules do not generate TCCs: exp: A->B matches A0->B0, if A0 matches A and B matches B0 exp: ARRAY A OF B matches ARRAY A0 OF B0, if A0 matches A and B matches B0 the following structural rules *may* generate TCCs: exp: [T,...] matches [T0,...], if exp.0: T matches T0, ... exp: [#f:T,...#] matches [#f:T0,...], if exp.f: T matches T0, ... as for arithmetic, the relationship is as follows: [a..b] < INT < REAL REAL0 < REAL (REAL0, i.e. REAL without 0, is only internally used to denote the second argument type of the / operator and thus trigger a TCC) the corresponding conversions from left to right succeed without generating TCCs; conversions are applied transitively. as for the conversion from right to left, we have: exp: REAL matches INT if (EXISTS (x:INT): x=exp) exp: INT matches [a..b] if a <= exp && exp <= b exp: REAL matches REAL0 if exp /= 0 if rules are applied transitively, the conditions are appropriately conjoined, e.g. exp: REAL -> SUBTYPE(p:[a..b]->BOOL) generates the TCC (EXISTS (x:INT): x=exp) && a <= exp && exp <= b && p(exp)

Parameters:
exp - the expression (may be null if tcc is false)
etype - its type
type - the type which expr:etype is expected to match
tcc - true iff a tcc may be generated
Returns:
true iff the matching succeeds

subType

public static Type subType(Type type0,
                           Type type1)
return greatest subtype of type0 and type1 (null, if none exists) does not generate tccs.

Parameters:
type0 - a type
type1 - a type
Returns:
the subtype of type0 and type1 (or null, if none exists)

clearSubtypes

public static TypeExpression clearSubtypes(Type type,
                                           Expression exp)
return version of type where subtypes and subranges are replaced by their base types; the corresponding constraints are returned as a formula which a corresponding expression exp has to fulfill

Parameters:
type - the type to be cleared
exp - an expression of this type
Returns:
a pair of cleared type and formula (may be null if no condition generated) or null (if cleared type is identical to given type)