From 3bff56e98679a070439ae147bbadfba07ec6a836 Mon Sep 17 00:00:00 2001 From: Jean Privat Date: Fri, 10 Oct 2014 20:41:16 -0400 Subject: [PATCH 1/1] typing: refactor type adaptations in AEqExpr and ANeExpr Signed-off-by: Jean Privat --- src/semantize/typing.nit | 52 ++++++++++++++++++++++++++++------------------ 1 file changed, 32 insertions(+), 20 deletions(-) diff --git a/src/semantize/typing.nit b/src/semantize/typing.nit index cf84e4c..f254292 100644 --- a/src/semantize/typing.nit +++ b/src/semantize/typing.nit @@ -195,6 +195,36 @@ private class TypeVisitor return sup end + # Special verification on != and == for null + # Return true + fun null_test(anode: ABinopExpr) + do + var mtype = anode.n_expr.mtype + var mtype2 = anode.n_expr2.mtype + + if mtype == null or mtype2 == null then return + + if not mtype2 isa MNullType then return + + if not mtype isa MNullableType then + return + end + + # Check for type adaptation + var variable = anode.n_expr.its_variable + if variable == null then return + + if anode isa AEqExpr then + anode.after_flow_context.when_true.set_var(variable, mtype2) + anode.after_flow_context.when_false.set_var(variable, mtype.mtype) + else if anode isa ANeExpr then + anode.after_flow_context.when_false.set_var(variable, mtype2) + anode.after_flow_context.when_true.set_var(variable, mtype.mtype) + else + abort + end + end + fun try_get_mproperty_by_name2(anode: ANode, mtype: MType, name: String): nullable MProperty do return self.modelbuilder.try_get_mproperty_by_name2(anode, mmodule, mtype, name) @@ -1336,16 +1366,7 @@ redef class AEqExpr redef fun accept_typing(v) do super - - var variable = self.n_expr.its_variable - if variable == null then return - var mtype = self.n_expr2.mtype - if not mtype isa MNullType then return - var vartype = v.get_variable(self, variable) - if not vartype isa MNullableType then return - self.after_flow_context.when_true.set_var(variable, mtype) - self.after_flow_context.when_false.set_var(variable, vartype.mtype) - #debug("adapt {variable}:{vartype} ; true->{mtype} false->{vartype.mtype}") + v.null_test(self) end end redef class ANeExpr @@ -1353,16 +1374,7 @@ redef class ANeExpr redef fun accept_typing(v) do super - - var variable = self.n_expr.its_variable - if variable == null then return - var mtype = self.n_expr2.mtype - if not mtype isa MNullType then return - var vartype = v.get_variable(self, variable) - if not vartype isa MNullableType then return - self.after_flow_context.when_false.set_var(variable, mtype) - self.after_flow_context.when_true.set_var(variable, vartype.mtype) - #debug("adapt {variable}:{vartype} ; true->{vartype.mtype} false->{mtype}") + v.null_test(self) end end redef class ALtExpr -- 1.7.9.5