syntax: remove local variable masking
authorJean Privat <jean@pryen.org>
Tue, 4 Aug 2009 14:02:43 +0000 (10:02 -0400)
committerJean Privat <jean@pryen.org>
Thu, 6 Aug 2009 15:29:30 +0000 (11:29 -0400)
Signed-off-by: Jean Privat <jean@pryen.org>

23 files changed:
lib/standard/collection/hash_collection.nit
src/compiling/compiling.nit
src/compiling/compiling_global.nit
src/compiling/compiling_icode.nit
src/mmloader.nit
src/nitc.nit
src/nitdoc.nit
src/syntax/icode_generation.nit
src/syntax/mmbuilder.nit
tests/base_array.nit
tests/base_closure6.nit
tests/base_closure_forms.nit
tests/base_combined_assignment.nit
tests/base_nullable.nit
tests/base_var.nit
tests/error_expr_not_ok.nit
tests/error_needed_types.nit
tests/sav/base_closure6_alt1.sav
tests/sav/base_combined_assignment_alt1.sav
tests/sav/test_let.sav [deleted file]
tests/test_break.nit
tests/test_let.nit [deleted file]
tests/test_list2.nit

index 5bb6ff7..7fb541d 100644 (file)
@@ -160,7 +160,6 @@ special ArrayCapable[nullable N]
 
                if _capacity <= old_cap then return
 
-               var new_array = _array
                # Reput items in the array
                var node = _first_item
                while node != null do
index 8dfd072..0fa87b9 100644 (file)
@@ -124,7 +124,8 @@ redef class MMModule
                end
                f.write("#endif\n")
                f.close
-               var f = new OFStream.open("{tc.compdir}/{name}._sep.c")
+
+               f = new OFStream.open("{tc.compdir}/{name}._sep.c")
                f.write("/* This C file is generated by NIT to compile module {name}. */\n")
                f.write("#include \"{name}._sep.h\"\n")
                for s in v.ctx.instrs do
index b66c57a..9314b9a 100644 (file)
@@ -497,8 +497,8 @@ redef class MMModule
                                if pg.is_init_for(c) then
                                        # Declare constructors
                                        var params = new Array[String]
-                                       for i in [0..p.signature.arity[ do
-                                               params.add("val_t p{i}")
+                                       for j in [0..p.signature.arity[ do
+                                               params.add("val_t p{j}")
                                        end
                                        v.add_decl("val_t NEW_{c}_{p.global.intro.cname}({params.join(", ")});")
                                end
@@ -865,61 +865,65 @@ redef class MMLocalClass
 
                var pi = primitive_info
                if pi == null then
-                       var iself = new IRegister(get_type)
-                       var iselfa = [iself]
-                       var iroutine = new IRoutine(new Array[IRegister], iself)
-                       var icb = new ICodeBuilder(module, iroutine, null)
-                       var obj = new INative("OBJ2VAL(obj)", null)
-                       obj.result = iself
-                       icb.stmt(obj)
-
-                       for g in global_properties do
-                               var p = self[g]
-                               var t = p.signature.return_type
-                               if p isa MMAttribute and t != null then
-                                       var ir = p.iroutine
-                                       if ir == null then continue
-                                       # FIXME: Not compatible with sep compilation
-                                       var e = ir.inline_in_seq(icb.seq, iselfa).as(not null)
-                                       icb.stmt(new IAttrWrite(p, iself, e))
+                       do
+                               var iself = new IRegister(get_type)
+                               var iselfa = [iself]
+                               var iroutine = new IRoutine(new Array[IRegister], iself)
+                               var icb = new ICodeBuilder(module, iroutine, null)
+                               var obj = new INative("OBJ2VAL(obj)", null)
+                               obj.result = iself
+                               icb.stmt(obj)
+
+                               for g in global_properties do
+                                       var p = self[g]
+                                       var t = p.signature.return_type
+                                       if p isa MMAttribute and t != null then
+                                               var ir = p.iroutine
+                                               if ir == null then continue
+                                               # FIXME: Not compatible with sep compilation
+                                               var e = ir.inline_in_seq(icb.seq, iselfa).as(not null)
+                                               icb.stmt(new IAttrWrite(p, iself, e))
+                                       end
                                end
-                       end
 
-                       var cname = "NEW_{name}"
-                       var args = iroutine.compile_signature_to_c(v, cname, "new {name}", null, null)
-                       var ctx_old = v.ctx
-                       v.ctx = new CContext
-                       v.add_decl("obj_t obj;")
-                       v.add_instr("obj = alloc(sizeof(val_t) * {itab.length});")
-                       v.add_instr("obj->vft = (classtable_elt_t*)VFT_{name};")
-                       var r = iroutine.compile_to_c(v, cname, args).as(not null)
-                       v.add_instr("return {r};")
-                       ctx_old.append(v.ctx)
-                       v.ctx = ctx_old
-                       v.unindent
-                       v.add_instr("}")
+                               var cname = "NEW_{name}"
+                               var args = iroutine.compile_signature_to_c(v, cname, "new {name}", null, null)
+                               var ctx_old = v.ctx
+                               v.ctx = new CContext
+                               v.add_decl("obj_t obj;")
+                               v.add_instr("obj = alloc(sizeof(val_t) * {itab.length});")
+                               v.add_instr("obj->vft = (classtable_elt_t*)VFT_{name};")
+                               var r = iroutine.compile_to_c(v, cname, args).as(not null)
+                               v.add_instr("return {r};")
+                               ctx_old.append(v.ctx)
+                               v.ctx = ctx_old
+                               v.unindent
+                               v.add_instr("}")
+                       end
 
-                       # Compile CHECKNAME
-                       var iself = new IRegister(get_type)
-                       var iselfa = [iself]
-                       var iroutine = new IRoutine(iselfa, null)
-                       var icb = new ICodeBuilder(module, iroutine, null)
-                       for g in global_properties do
-                               var p = self[g]
-                               var t = p.signature.return_type
-                               if p isa MMAttribute and t != null and not t.is_nullable then
-                                       icb.add_attr_check(p, iself)
+                       do
+                               # Compile CHECKNAME
+                               var iself = new IRegister(get_type)
+                               var iselfa = [iself]
+                               var iroutine = new IRoutine(iselfa, null)
+                               var icb = new ICodeBuilder(module, iroutine, null)
+                               for g in global_properties do
+                                       var p = self[g]
+                                       var t = p.signature.return_type
+                                       if p isa MMAttribute and t != null and not t.is_nullable then
+                                               icb.add_attr_check(p, iself)
+                                       end
                                end
+                               var cname = "CHECKNEW_{name}"
+                               var args = iroutine.compile_signature_to_c(v, cname, "check new {name}", null, null)
+                               var ctx_old = v.ctx
+                               v.ctx = new CContext
+                               iroutine.compile_to_c(v, cname, args)
+                               ctx_old.append(v.ctx)
+                               v.ctx = ctx_old
+                               v.unindent
+                               v.add_instr("}")
                        end
-                       var cname = "CHECKNEW_{name}"
-                       var args = iroutine.compile_signature_to_c(v, cname, "check new {name}", null, null)
-                       var ctx_old = v.ctx
-                       v.ctx = new CContext
-                       iroutine.compile_to_c(v, cname, args)
-                       ctx_old.append(v.ctx)
-                       v.ctx = ctx_old
-                       v.unindent
-                       v.add_instr("}")
 
                        var init_table_size = cshe.greaters.length + 1
                        var init_table_decl = "int init_table[{init_table_size}] = \{0{", 0" * (init_table_size-1)}};"
index 97514ac..d355bb1 100644 (file)
@@ -283,12 +283,11 @@ redef class IRoutine
                else
                        v.add_decl("struct WBT_ **CREG = NULL;")
                end
-               var i = 0
+               var k = 0
                for r in params do
-                       if r.slot_index != null then v.add_assignment(v.register(r), args[i])
-                       i += 1
+                       if r.slot_index != null then v.add_assignment(v.register(r), args[k])
+                       k += 1
                end
-               var iclosdecls = closure_decls
                if iclosdecls != null then
                        for i in [0..iclosdecls.length[ do
                                var iclosdecl = iclosdecls[i]
index 709de5a..60e84f1 100644 (file)
@@ -258,7 +258,6 @@ special MMContext
        # If the module is already loaded, just return it without further processing.
        fun get_module(module_name: Symbol, from: nullable MMModule): MMModule
        do
-               var m: MMModule
                if from != null then
                        var dir: nullable MMDirectory = from.directory
                        while dir != null do
index eef3c56..29a4ab4 100644 (file)
@@ -66,7 +66,7 @@ special AbstractCompiler
                if clibdir == null then
                        var dir = once ("NIT_DIR".to_symbol).environ
                        if dir.is_empty then 
-                               var dir = "{sys.program_name.dirname}/../lib"
+                               dir = "{sys.program_name.dirname}/../lib"
                                if dir.file_exists then clibdir = dir
                        else
                                dir = "{dir}/lib"
@@ -81,7 +81,7 @@ special AbstractCompiler
                if bindir == null then
                        var dir = once ("NIT_DIR".to_symbol).environ
                        if dir.is_empty then 
-                               var dir = "{sys.program_name.dirname}/../bin"
+                               dir = "{sys.program_name.dirname}/../bin"
                                if dir.file_exists then bindir = dir
                        else
                                dir = "{dir}/bin"
index 7de4d4f..dfd5ec8 100644 (file)
@@ -403,7 +403,7 @@ special MMEntity
        do
                var m = module
                if not need_doc(dctx) then m = global.intro.module
-               var m = dctx.known_owner_of(m)
+               m = dctx.known_owner_of(m)
                if m == dctx.module then
                        return "<a href=\"#{html_anchor}\">{self}</a>"
                else
@@ -697,7 +697,7 @@ special MMEntity
        do
                var m = module
                if not need_doc(dctx) then m = global.module
-               var m = dctx.known_owner_of(m)
+               m = dctx.known_owner_of(m)
                if m == dctx.module then
                        return "<a href=\"#{html_anchor}\">{self}</a>"
                else
@@ -904,7 +904,6 @@ special MMEntity
                        # skip pass 1 because constructors are not inherited
                        var cmap = new HashMap[MMLocalClass, Array[MMLocalProperty]]
                        var mmap = new HashMap[MMModule, Array[MMLocalProperty]]
-                       var props = new Array[MMLocalClass]
                        for c in che.greaters do
                                if c isa MMSrcLocalClass then
                                        var km = dctx.known_owner_of(c.module)
@@ -962,7 +961,6 @@ special MMEntity
                end
 
                var mmap = new HashMap[MMModule, Array[MMLocalProperty]]
-               var props = new Array[MMLocalClass]
                for c in crhe.order do
                        if module.mhe <= c.module or dctx.owned_modules.has(c.module) or not c isa MMSrcLocalClass then continue
                        var km = dctx.known_owner_of(c.module)
index 25f6bdd..b48ede4 100644 (file)
@@ -115,17 +115,17 @@ special ICodeBuilder
                end
                var l = n.super_init_calls.length
                while i < l do
-                       var p = n.super_init_calls[i]
-                       if p == stop_prop then break
+                       var sp = n.super_init_calls[i]
+                       if sp == stop_prop then break
                        var cargs = new Array[IRegister]
-                       if p.signature.arity == 0 then
+                       if sp.signature.arity == 0 then
                                cargs.add(iroutine.params.first)
                        else
                                for va in iroutine.params do
                                        cargs.add(va)
                                end
                        end
-                       stmt(new ICall(p, cargs))
+                       stmt(new ICall(sp, cargs))
                        i += 1
                end
        end
@@ -1160,7 +1160,7 @@ redef class ASuperExpr
                                return null
                        end
                else
-                       var p = prop
+                       p = prop
                        var rtype = p.signature.return_type
                        if rtype == null then
                                v.stmt(new ISuper(p, args))
index 52855c8..c079443 100644 (file)
@@ -84,9 +84,9 @@ redef class MMSrcModule
                end
 
                # Check class conformity
-               var mmbv1b = new ClassVerifierVisitor(tc, self)
+               var mmbv1c = new ClassVerifierVisitor(tc, self)
                for c in classes do
-                       c.accept_class_visitor(mmbv1b)
+                       c.accept_class_visitor(mmbv1c)
                end
                tc.check_errors
 
@@ -892,9 +892,9 @@ redef class APropdef
                        if s.arity != isig.arity then
                                v.error(self, "Redef error: {prop.local_class}::{prop} redefines {ip.local_class}::{ip} with {isig.arity} parameter(s).")
                        else
-                               for i in [0..s.arity[ do
-                                       if s[i] != isig[i] then
-                                               v.error(self, "Redef error: Expected {isig[i]} (as in {ip.local_class}::{ip}), got {s[i]} in {prop.local_class}::{prop}.")
+                               for j in [0..s.arity[ do
+                                       if s[j] != isig[j] then
+                                               v.error(self, "Redef error: Expected {isig[j]} (as in {ip.local_class}::{ip}), got {s[j]} in {prop.local_class}::{prop}.")
                                        end
                                end
                        end
index 9b793e6..f37dd3a 100644 (file)
@@ -24,4 +24,4 @@ for i in a do
        (i*10).output
 end
 
-#alt1# var a = [10, true]
+#alt1# var b = [10, true]
index b7b6a7a..5dd96dd 100644 (file)
@@ -47,7 +47,7 @@ var u: U = new U
 var v: V = new V
 var w: W = new W
 
-var y: Object
+var y: Object#!alt1#
 #alt1#var y: U
 y = a.foo !bar do 0.output
 y = a.foo !bar do break t
index 3be20e9..d5457a7 100644 (file)
@@ -129,7 +129,7 @@ end
 
 fun file_open(i: Int)
        !work(f: File)
-       break !error(i: Int) do abort
+       break !error(j: Int) do abort
 do
        var f = new File(i)
        if not f.is_open then error(404)
index 756d60d..0548c19 100644 (file)
@@ -16,7 +16,7 @@
 
 import kernel
 
-var i = 1
+var i = 1#!alt1#
 #alt1#var i: Object = 1
 i += 2
 i.output
index d4cdefe..fe19a24 100644 (file)
@@ -22,10 +22,10 @@ class A
        redef fun output do _i.output
 end
 
-var a: A
-var na: nullable A
-var o: Object
-var no: nullable Object
+
+
+
+
 
 var a: A = new A(1)
 var na: nullable A = new A(2)
index e37284b..5303286 100644 (file)
@@ -50,5 +50,5 @@ var a4: Int = foo
 a4.output
 var a5 = foo
 a5.output
-#alt7#var a4: Int = bar
-#alt8#var a5 = bar
+#alt7#var a6: Int = bar
+#alt8#var a7 = bar
index 82c0d5a..edeb2ae 100644 (file)
@@ -67,7 +67,7 @@ while fail do trash(0)
 while true do fail
 
 for i in fail do trash(0) # no rtype (hum...)
-for i in [0..1] do fail
+for j in [0..1] do fail
 assert fail
 trash(once fail) # no rtype
 trash(fail or true)
index dea2941..6d41036 100644 (file)
@@ -20,5 +20,5 @@ fun some_fun do
 #alt7# var v = [1..10]
 #alt8#  for i in new L do
 #alt8#  end
-       var v: Object
+       var y: Object
 end
index 6621084..9b6b499 100644 (file)
@@ -1,4 +1,4 @@
-alt/base_closure6_alt1.nit:53,5--25: Type error: expected U, got T
-alt/base_closure6_alt1.nit:55,25: Type error: no most general type. Got V and U.
-alt/base_closure6_alt1.nit:57,5--61,8: Type error: expected U, got T
-alt/base_closure6_alt1.nit:65,8: Type error: no most general type. Got V and U at 64,8.
+alt/base_closure6_alt1.nit:52,5--25: Type error: expected U, got T
+alt/base_closure6_alt1.nit:54,25: Type error: no most general type. Got V and U.
+alt/base_closure6_alt1.nit:56,5--60,8: Type error: expected U, got T
+alt/base_closure6_alt1.nit:64,8: Type error: no most general type. Got V and U at 63,8.
index 130e589..005e4ac 100644 (file)
@@ -1 +1 @@
-alt/base_combined_assignment_alt1.nit:21,1--6: Error: Method '+' doesn't exists in Object.
+alt/base_combined_assignment_alt1.nit:20,1--6: Error: Method '+' doesn't exists in Object.
diff --git a/tests/sav/test_let.sav b/tests/sav/test_let.sav
deleted file mode 100644 (file)
index c79bf12..0000000
+++ /dev/null
@@ -1,9 +0,0 @@
-5
-0
-a
-6
-a
-a
-5
-0
-a
index 986b6af..981afa7 100644 (file)
@@ -23,16 +23,18 @@ for i in [0..10[ do
        print(i)
 end
 
-var i = 0
-while i < 10 do
-       if i == 3 then
-               i = i + 2
-               continue
-       else if i == 7 then
-               break
+do
+       var i = 0
+       while i < 10 do
+               if i == 3 then
+                       i = i + 2
+                       continue
+               else if i == 7 then
+                       break
+               end
+               print(i)
+               i = i + 1
        end
-       print(i)
-       i = i + 1
 end
 
 for i in [0..10[ do
diff --git a/tests/test_let.nit b/tests/test_let.nit
deleted file mode 100644 (file)
index 70dbe4b..0000000
+++ /dev/null
@@ -1,39 +0,0 @@
-# This file is part of NIT ( http://www.nitlanguage.org ).
-#
-# Copyright 2004-2008 Jean Privat <jean@pryen.org>
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-#     http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-var i = 0
-var j: Object = i
-var k: Object
-
-i = 5
-k = 'a'
-print(i)
-print(j)
-print(k)
-
-do
-       var i = i + 1
-       var j = k
-       var k = j
-
-       print(i)
-       print(j)
-       print(k)
-end
-
-print(i)
-print(j)
-print(k)
index ab0290b..cec0b00 100644 (file)
 var l = new List[Int]
 l.add_all([1, 2, 3, 4, 5, 6])
 print l.join(", ")
-var it = l.iterator
-while it.is_ok do
-       it.item += 10
-       it.next
+do
+       var it = l.iterator
+       while it.is_ok do
+               it.item += 10
+               it.next
+       end
 end
 print l.join(", ")
-var it = l.iterator
-while it.is_ok do
-       it.insert_before(it.item-10)
-       it.insert_before(it.item+10)
-       it.delete
-       it.next
+do
+       var it = l.iterator
+       while it.is_ok do
+               it.insert_before(it.item-10)
+               it.insert_before(it.item+10)
+               it.delete
+               it.next
+       end
 end
 print l.join(", ")