# May be different from the declaration static type
meth stype(v: Variable): MMType
do
- return v.stype
+ if _stypes.has_key(v) then
+ return _stypes[v]
+ else
+ return v.stype
+ end
+ end
+
+ # Set effective static type of a given variable
+ # May be different from the declaration static type
+ meth stype=(v: Variable, t: MMType)
+ do
+ _stypes[v] = t
end
# Variables by name (in the current context only)
# All variables in all contextes
attr _all_variables: Set[Variable]
+ # Updated static type of variables
+ attr _stypes: Map[Variable, MMType] = new HashMap[Variable, MMType]
+
# Build a new VariableContext
meth sub(node: PNode): SubVariableContext
do
# Build a nested VariableContext with new variable information
meth sub_with(node: PNode, v: Variable, t: MMType): SubVariableContext
do
- return new CastVariableContext.with_prev(self, node, v, t)
+ var ctx = sub(node)
+ ctx.stype(v) = t
+ return ctx
end
# The visitor of the context (used to display error)
redef meth stype(v)
do
- return prev.stype(v)
+ if _stypes.has_key(v) then
+ return _stypes[v]
+ else
+ return prev.stype(v)
+ end
end
init with_prev(p: VariableContext, node: PNode)
end
end
-class CastVariableContext
-special SubVariableContext
- attr _variable: Variable
- attr _var_type: MMType
-
- redef meth stype(v)
- do
- if _variable == v then
- return _var_type
- end
- return prev.stype(v)
- end
-
- init with_prev(p: VariableContext, node: PNode, v: Variable, t: MMType)
- do
- super(p, node)
- _variable = v
- _var_type =t
- end
-end
-
redef class Variable
# Is the variable must be set before being used ?
meth must_be_set: Bool do return false