Prepare unset variable control flow
authorJean Privat <jean@pryen.org>
Tue, 25 Nov 2008 18:58:56 +0000 (13:58 -0500)
committerJean Privat <jean@pryen.org>
Tue, 25 Nov 2008 18:58:56 +0000 (13:58 -0500)
lib/standard/string_search.nit
src/compiling/compiling_methods.nit
src/syntax/mmbuilder.nit
src/syntax/syntax.nit
src/syntax/syntax_base.nit
src/syntax/typing.nit

index 9e22e48..94282aa 100644 (file)
@@ -153,7 +153,7 @@ special Pattern
                var m = _length
                var suff = new Array[Int].filled_with(m, m)
 
-               var f: Int
+               var f = 0
                var g = m - 1
                var i = m - 2
                while i >= 0 do
index 23ba504..bc1bf98 100644 (file)
@@ -171,7 +171,7 @@ redef class CompilerVisitor
                        end
                        j += 1
                end
-               var stop_prop: MMMethod
+               var stop_prop: MMMethod = null
                if j < n.explicit_super_init_calls.length then
                        stop_prop = n.explicit_super_init_calls[j]
                end
@@ -282,7 +282,7 @@ redef class MMSrcMethod
        protected meth decl_csignature(v: CompilerVisitor, args: Array[String]): String
        do
                var params = new Array[String]
-               var params_new: Array[String]
+               var params_new: Array[String] = null
                if global.is_init then
                        params_new = new Array[String]
                end
@@ -421,7 +421,7 @@ redef class AConcreteMethPropdef
                var old_return_value = v.return_value
                var old_has_return = v.has_return
 
-               var itpos: String
+               var itpos: String = null
                if self isa AConcreteInitPropdef then
                        itpos = "VAL2OBJ({params[0]})->vft[{method.local_class.global.init_table_pos_id}].i"
                        # v.add_instr("printf(\"{method.full_name}: inittable[%d] = %d\\n\", {itpos}, init_table[{itpos}]);")
@@ -505,7 +505,7 @@ redef class AInternMethPropdef
        do
                var c = method.local_class.name
                var n = method.name
-               var s: String
+               var s: String = null
                if c == once "Int".to_symbol then
                        if n == once "object_id".to_symbol then
                                s = "{p[0]}"
index 51ea48c..d934fce 100644 (file)
@@ -289,7 +289,7 @@ redef class AModule
                # Import super-modules
                var module_names_to_import = new Array[Symbol]
                var module_visibility = new HashMap[Symbol, Int]
-               var no_import: PImport
+               var no_import: PImport = null
                for i in n_imports do
                        var n = i.module_name
                        if n != null then
index c52625c..1bc71de 100644 (file)
@@ -78,11 +78,12 @@ redef class MMSrcModule
                do_mmbuilder(tc)
                if tc.error_count > 0 then exit(1)
 
-               do_control_flow(tc)
+               do_typing(tc)
                if tc.error_count > 0 then exit(1)
 
-               do_typing(tc)
+               do_control_flow(tc)
                if tc.error_count > 0 then exit(1)
+
        end
 
 end
index e35b117..8a48e25 100644 (file)
@@ -185,6 +185,8 @@ class Variable
        # Static type
        readable writable attr _stype: MMType 
 
+       redef meth to_s do return _name.to_s
+
        init(n: Symbol, d: PNode)
        do
                assert n != null
@@ -497,3 +499,19 @@ redef class PExpr
        # Is null for statement and for erronus expression
        meth stype: MMType is abstract
 end
+
+redef class AVardeclExpr
+       # Assiociated local variable
+       readable writable attr _variable: Variable
+end
+
+redef class AForVardeclExpr
+       # Associated automatic local variable
+       readable writable attr _variable: Variable
+end
+
+redef class AVarFormExpr
+       # Associated local variable
+       readable writable attr _variable: Variable 
+end
+
index 4e8348a..932e6c1 100644 (file)
@@ -132,13 +132,13 @@ private class VariableContext
        attr _dico: Map[Symbol, Variable]
 
        # Build a new VariableContext
-       meth sub: VariableContext
+       meth sub: SubVariableContext
        do
                return new SubVariableContext.with(self, null, null)
        end
 
        # Build a nested VariableContext with new variable information
-       meth sub_with(v: Variable, t: MMType): VariableContext
+       meth sub_with(v: Variable, t: MMType): SubVariableContext
        do
                return new SubVariableContext.with(self, v, t)
        end
@@ -233,8 +233,8 @@ redef class AConcreteInitPropdef
                else 
                        var i = 0
                        var l = explicit_super_init_calls.length
-                       var cur_m: MMMethod
-                       var cur_c: MMLocalClass
+                       var cur_m: MMMethod = null
+                       var cur_c: MMLocalClass = null
                        if i < l then
                                cur_m = explicit_super_init_calls[i]
                                cur_c = cur_m.global.intro.local_class
@@ -301,13 +301,10 @@ redef class PExpr
 end
 
 redef class AVardeclExpr
-       # Assiociated local variable
-        readable attr _variable: Variable
-
        redef meth after_typing(v)
        do
                var va = new Variable(n_id.to_symbol, self)
-               _variable = va
+               variable = va
                v.variable_ctx.add(va)
 
                if n_type != null then
@@ -387,15 +384,12 @@ redef class AForExpr
 end
 
 redef class AForVardeclExpr
-       # Associated automatic local variable
-       readable attr _variable: Variable
-
        redef meth after_typing(v)
        do
                v.variable_ctx = v.variable_ctx.sub
-               var variable = new Variable(n_id.to_symbol, self)
-               _variable = variable
-               v.variable_ctx.add(variable)
+               var va = new Variable(n_id.to_symbol, self)
+               variable = va
+               v.variable_ctx.add(va)
 
                var expr_type = n_expr.stype
                if not v.check_conform(self, expr_type, v.type_collection) then
@@ -414,7 +408,7 @@ redef class AForVardeclExpr
                end
                var t = prop2.signature.return_type
                if not n_expr.is_self then t = t.not_for_self
-               variable.stype = t
+               va.stype = t
        end
 end
 
@@ -426,11 +420,6 @@ redef class AAssertExpr
        end
 end
 
-redef class AVarFormExpr
-       # Associated local variable
-        readable writable attr _variable: Variable 
-end
-
 redef class AVarExpr
        redef meth is_variable do return true
 
@@ -472,6 +461,14 @@ redef class AReassignFormExpr
        readable attr _assign_method: MMMethod
 end
 
+redef class AVarReassignExpr
+       redef meth after_typing(v)
+       do
+               var t = v.variable_ctx.stype(variable)
+               do_lvalue_typing(v, t)
+       end
+end
+
 redef class PAssignOp
        meth method_name: Symbol is abstract
 end
@@ -482,14 +479,6 @@ redef class AMinusAssignOp
        redef meth method_name do return once "-".to_symbol
 end
 
-redef class AVarReassignExpr
-       redef meth after_typing(v)
-       do
-               var t = v.variable_ctx.stype(variable)
-               do_lvalue_typing(v, t)
-       end
-end
-
 redef class ASelfExpr
        redef meth after_typing(v)
        do
@@ -625,7 +614,7 @@ redef class AArrayExpr
 
        redef meth after_typing(v)
        do
-               var stype: MMType
+               var stype: MMType = null
                for n in n_exprs do
                        var ntype = n.stype
                        if stype == null or (ntype != null and stype < ntype) then
@@ -698,7 +687,7 @@ special ASuperInitCall
 
                if precs.first.signature.return_type != null then
                        var stypes = new Array[MMType]
-                       var stype: MMType
+                       var stype: MMType = null
                        for prop in precs do
                                assert prop isa MMMethod
                                var t = prop.signature.return_type.for_module(v.module).adapt_to(v.local_property.signature.recv)
@@ -876,7 +865,7 @@ special AAbsSendExpr
                        v.error(self, "Error: Constructor invocation {property} must not be in nested block.")
                end
                var cla = v.module[property.global.intro.local_class.global]
-               var prev_class: MMLocalClass
+               var prev_class: MMLocalClass = null
                if not v.explicit_super_init_calls.is_empty then
                        prev_class = v.explicit_super_init_calls.last.global.intro.local_class
                end