lib: for on maps require two parameters
authorJean Privat <jean@pryen.org>
Mon, 13 Feb 2012 19:01:25 +0000 (14:01 -0500)
committerJean Privat <jean@pryen.org>
Mon, 13 Feb 2012 19:04:52 +0000 (14:04 -0500)
Existing clients require to adapts existing loops on map:

    for v in my_map do

has to be rewrite to

    for k, v in my_map do

or

    for v in my_map.values do

Signed-off-by: Jean Privat <jean@pryen.org>

lib/standard/collection/abstract_collection.nit
lib/standard/collection/hash_collection.nit
src/metamodel/inheritance.nit
src/metamodel/partial_order.nit
src/mmloader.nit
src/nitdoc.nit
src/program.nit
src/syntax/icode_generation.nit
src/syntax/mmbuilder.nit
tests/test_map.nit

index 12a5598..64fdac4 100644 (file)
@@ -250,11 +250,11 @@ interface MapRead[K: Object, E]
 
        # Iterate over each element of the collection
        fun iterate
-               !each(e: E)
+               !each(k: K, v: E)
        do
                var i = iterator
                while i.is_ok do
-                       each(i.item)
+                       each(i.key, i.item)
                        i.next
                end
        end
index d1b4bb7..11dfa61 100644 (file)
@@ -213,11 +213,11 @@ class HashMap[K: Object, V]
        redef fun iterator: HashMapIterator[K, V] do return new HashMapIterator[K,V](self)
 
        redef fun iterate
-               !each(e: V)
+               !each(k: K, v: V)
        do
                var c = _first_item
                while c != null do
-                       each(c._value)
+                       each(c._key, c._value)
                        c = c._next_item
                end
        end
index 46e6e88..06e1c08 100644 (file)
@@ -96,7 +96,7 @@ redef class MMLocalClass
                var ancestors = group_ancestors(build_ancestors)
                _ancestors = new HashMap[MMLocalClass, MMAncestor]
 
-               for set in ancestors do
+               for set in ancestors.values do
                        if set.length == 1 then
                                add_ancestor(set.first)
                        else
@@ -447,7 +447,7 @@ redef class MMAncestor
        do
                tab.add(self)
                stype.local_class.compute_ancestors
-               for anc in stype.local_class.ancestors.as(not null) do
+               for anc in stype.local_class.ancestors.values do
                        var aaa = anc.stype.for_module(stype.mmmodule)
                        var a = aaa.adapt_to(stype).for_module(inheriter.mmmodule)
                        if a.local_class != inheriter.local_class then
index 435e3d9..91b8f43 100644 (file)
@@ -66,7 +66,7 @@ class PartialOrder[E: Object]
        do
                var s = new Buffer
                s.append(to_dot_header)
-               for e in _elements do
+               for e in _elements.values do
                        s.append(to_dot_node(e.value))
                        for d in e.direct_greaters do
                                s.append(to_dot_edge(e.value, d))
@@ -171,7 +171,7 @@ class PartialOrder[E: Object]
        protected fun compute_smallers_for(poe: PartialOrderElement[E], set: Set[E])
        do
                var e = poe.value
-               for s in _elements do
+               for s in _elements.values do
                        if s < e then
                                set.add(s.value)
                        end
index 9d28ff2..4f54478 100644 (file)
@@ -252,7 +252,7 @@ class ToolContext
        private fun try_to_load(module_name: Symbol, dir: MMDirectory): nullable MMModule
        do
                # Look in the module directory
-               for m in dir.modules do
+               for m in dir.modules.values do
                        if m.name == module_name then return m
                end
 
index 5e69d6b..2aff604 100644 (file)
@@ -1134,7 +1134,7 @@ redef class MMSrcLocalClass
                if global.intro == self then
                        return true
                end
-               for p in src_local_properties do
+               for p in src_local_properties.values do
                        if p.need_doc(dctx) then
                                return true
                        end
index 217031a..5b32b2f 100644 (file)
@@ -182,7 +182,7 @@ class Program
                                if iroutine != null then
                                        action(iroutine, m)
                                end
-                               for i in c.new_instance_iroutine do
+                               for i in c.new_instance_iroutine.values do
                                        action(i, m)
                                end
                        end
index 260d1e5..b388114 100644 (file)
@@ -180,8 +180,8 @@ redef class MMSrcModule
        fun generate_icode(tc: ToolContext)
        do
                var v = new A2IVisitor(tc, self)
-               for c in src_local_classes do
-                       for p in c.src_local_properties do
+               for c in src_local_classes.values do
+                       for p in c.src_local_properties.values do
                                if p isa MMSrcMethod then
                                        p.generate_iroutine(v)
                                else if p isa MMSrcAttribute then
index 510f0fc..2a52a9a 100644 (file)
@@ -163,7 +163,7 @@ redef class MMSrcLocalClass
                        n = n.next_node
                end
 
-               for p in src_local_properties do
+               for p in src_local_properties.values do
                        p.accept_property_visitor(v)
                end
        end
@@ -197,7 +197,7 @@ redef class MMSrcLocalClass
 
                # Collect unassigned attributes
                var unassigned_attributes = new Array[MMSrcAttribute]
-               for a in src_local_properties do
+               for a in src_local_properties.values do
                        if a isa MMSrcAttribute then
                                var n = a.node
                                if n.n_expr == null then unassigned_attributes.add(a)
index 58e8ea0..fd9e1b3 100644 (file)
@@ -31,7 +31,7 @@ do
        print(h.has(20))
        print(h.length)
        var s = 24
-       for x in h do
+       for x in h.values do
                s = s - x
        end
        print(s)