public class TypeAnalyzer extends Object implements Analyzer
Type checks and creates explicit upcast nodes in the AST. When the expressions are rewritten, the types need to be reanalyzed.
abstract A a abstract B : A b C : B c D : B d
A lowest common supertype in this solver directly corresponds to how the
expression is stored as a set. For example, suppose there is an expression
that evaluates to {C0, D0}. Unfortunately, C0 is stored as 0 for the type C
and D0 is also stored as 0 for the type D. The way the solver does it is to
upcast both C0 and D0 to the type B, where C0 = B0 and D0 = B1 so the set
{C0, D0} can be stored as {B0, B1}, ie. {0, 1} in Choco.
Type.getCommonSuperType()
of each expression is the type used for
representing the set in Choco.
Even though the expressions are stored as the common supertype, it is
sometimes necessary to reconvert it back to the subtype. For example,
consider the expression (C ++ D).d
. (C ++ D)
has the union
type {C, D} but is stored as the supertype B. The join .d
is allowed
because D is in the union type of (C ++ D)
, but since it is stored as
a set of B's, the set first needs to be downcasted to a set of D's before the
join can be performed. If the expression were (C ++ D).a
, then the
set of B's would need to be upcasted to a set of A's. If the expression were
(C ++ D).b
then no casting is required.
Constructor and Description |
---|
TypeAnalyzer() |
Copyright © 2013. All Rights Reserved.