IntermediateCodeTypeInference

de.uni_luebeck.isp.tessla.tessla_compiler.IntermediateCodeTypeInference$

Class containing code for determining the type of ImpLan expressions and adding casts. Does not perform type checking in any way. Hence this class should only be used for code which is known to be type correct.

Attributes

Graph
Supertypes
class Object
trait Matchable
class Any
Self type

Members list

Concise view

Value members

Concrete methods

def castExpression(exp: ImpLanExpr, target: Option[ImpLanType], varTypes: Map[String, ImpLanType]): ImpLanExpr

Casts an expression to a target type if necessary. Also assures type equality by wrapping sub-expressions into casts where necessary.

Casts an expression to a target type if necessary. Also assures type equality by wrapping sub-expressions into casts where necessary.

Attributes

exp

Expression to be casted

target

Type to which the expression should be casted. Optional. If None only the sub-expressions are casted if necessary.

varTypes

Type environment, mapping every possibly involved variable identifier to its type

Returns:

Expression potentially wrapped into a IntermediateCode.CastingExpression and all sub-expression with non-expected type also wrapped into a cast expression.

def generateCodeWithCasts(listing: SourceListing, varTypes: Map[String, ImpLanType]): SourceListing

Includes casts where necessary in a source listing

Includes casts where necessary in a source listing

Attributes

listing

The source listing to be examined

varTypes

Type environment, mapping every possibly involved variable identifier to its type

Returns:

The source listing with casts added

def generateCodeWithCasts(stmts: Seq[ImpLanStmt], varTypes: Map[String, ImpLanType], retType: Option[ImpLanType]): Seq[ImpLanStmt]

Adds casts to sub-expressions of a statement sequence where necessary

Adds casts to sub-expressions of a statement sequence where necessary

Attributes

retType

Type to which return statements from stmts are casted. Optional. If None, no casting is performed for these return statements (but still for sub-expressions)

stmts

Statements to be examined.

varTypes

Type environment, mapping every possibly involved variable identifier to its type

Returns:

Statement sequence with casts added

def generateFunctionCast(innerExp: ImpLanExpr, from: FunctionType, to: FunctionType, varTypes: Map[String, ImpLanType]): ImpLanExpr

Casts a function expression into a function expression with another signature by wrapping a lambda expression around the original function. The parameters and return value are casted in the usual way when calling the original function.

Casts a function expression into a function expression with another signature by wrapping a lambda expression around the original function. The parameters and return value are casted in the usual way when calling the original function.

Example:

f : LongType x LongType -> LongType casted to Lazy[GeneralType] x Lazy[GeneralType] -> Lazy[GeneralType]

would produce

(tp1: Lazy[GeneralType], tp2: Lazy[GeneralType]) => {(Lazy[GeneralType])(f((LongType)tp1, (LongType)tp2)}

Attributes

from

Type of innerExp

innerExp

Expression to be casted.

to

Type to cast to

varTypes

Type environment, mapping every possibly involved variable identifier to its type

Returns:

Casted expression (wrapped into lambda)

def typeInference(impLanExpr: ImpLanExpr, varTypes: Map[String, ImpLanType]): ImpLanType

Determines the type of an IntermediateCode.ImpLanExpr. This function may return error-prone results if the examined expression is not type-correct.

Determines the type of an IntermediateCode.ImpLanExpr. This function may return error-prone results if the examined expression is not type-correct.

Attributes

impLanExpr

Expression to be examined

varTypes

Type environment, mapping every possibly involved variable identifier to its type

Returns:

Type of the expression