Merge: Minor fix to atan2 and triangulate
authorJean Privat <jean@pryen.org>
Thu, 25 Feb 2016 14:02:17 +0000 (09:02 -0500)
committerJean Privat <jean@pryen.org>
Thu, 25 Feb 2016 14:02:17 +0000 (09:02 -0500)
Fix reversed axes in `atan2`, but since it is actually just a change in the name of the variables (and doc) it should not break the clients.

Also sorting points of a polygon in `triangulate` completely invalidated some complex polygons.

Pull-Request: #1958
Reviewed-by: Jean Privat <jean@pryen.org>
Reviewed-by: Romain Chanoir <romain.chanoir@viacesi.fr>

17 files changed:
contrib/jwrapper/src/model.nit
contrib/nitcc/src/grammar.nit
contrib/nitiwiki/src/wiki_links.nit
contrib/nitrpg/src/statistics.nit
contrib/pep8analysis/src/flow_analysis/range_analysis.nit
contrib/pep8analysis/src/flow_analysis/reaching_defs.nit
lib/android/notification/native_notification.nit
lib/android/ui/ui.nit
lib/core/collection/abstract_collection.nit
lib/core/collection/array.nit
lib/core/collection/hash_collection.nit
lib/mongodb/mongodb.nit
lib/neo4j/graph/json_graph_store.nit
lib/nitcorn/http_request.nit
lib/sax/helpers/namespace_support.nit
src/compiler/abstract_compiler.nit
tests/test_regex_check.nit

index e642da4..bfbbdf0 100644 (file)
@@ -261,7 +261,7 @@ class JavaModel
        # All classes, from this pass and from other passes
        var all_classes: HashMap[String, JavaClass] is noserialize, lazy do
                var classes = new HashMap[String, JavaClass]
-               classes.recover_with self.classes
+               classes.add_all self.classes
 
                for model_path in sys.opt_load_models.value do
                        if not model_path.file_exists then
@@ -284,7 +284,7 @@ class JavaModel
                                continue
                        end
 
-                       classes.recover_with model.classes
+                       classes.add_all model.classes
                end
 
                return classes
index 040c6da..3dbd8ce 100644 (file)
@@ -569,7 +569,7 @@ class LRAutomaton
                                res.add "\t\tREDUCE {r}\n"
                        end
                end
-               return res.to_s
+               return res.join
        end
 
        # Generate a graphviz file of the automaton
@@ -894,7 +894,7 @@ class LRState
        var name: String
 
        # Mangled name
-       fun cname: String do return name.to_cmangle
+       var cname: String is lazy do return name.to_cmangle
 
        # Number
        var number: Int = -1
index c1785b2..ac3e171 100644 (file)
@@ -211,7 +211,7 @@ redef class WikiArticle
                super
                if not is_dirty and not wiki.force_render or not has_source then return
                content = md_proc.process(md.as(not null))
-               headlines.recover_with(md_proc.emitter.decorator.headlines)
+               headlines.add_all(md_proc.emitter.decorator.headlines)
        end
 end
 
index 2827ae9..cde6816 100644 (file)
@@ -177,7 +177,7 @@ class GameStats
                obj["period"] = period
                obj["owner"] = owner.key
                var values = new JsonObject
-               values.recover_with(self)
+               values.add_all(self)
                obj["values"] = values
                return obj
        end
index f372ad5..d64d7af 100644 (file)
@@ -153,7 +153,7 @@ class RangeMap
        fun copy: RangeMap
        do
                var c = new RangeMap
-               c.recover_with(self)
+               c.add_all(self)
                return c
        end
 
@@ -171,7 +171,7 @@ redef class AInstruction
        redef fun accept_range_analysis(v, ins, outs)
        do
                visit_all(v)
-               if ins != null then outs.recover_with(ins)
+               if ins != null then outs.add_all(ins)
        end
 end
 
@@ -180,7 +180,7 @@ redef class ALoadInstruction
        do
                visit_all(v)
 
-               if ins != null then outs.recover_with(ins)
+               if ins != null then outs.add_all(ins)
                var variable = def_var
                #var add = new RangeMap[Var, ValRange](variable,
 
@@ -205,7 +205,7 @@ redef class AStoreInstruction
        do
                visit_all(v)
 
-               if ins != null then outs.recover_with(ins)
+               if ins != null then outs.add_all(ins)
                var src = src_var # reg
                var def = def_var # mem
 
@@ -225,7 +225,7 @@ redef class AInputInstruction
        do
                visit_all(v)
 
-               if ins != null then outs.recover_with(ins)
+               if ins != null then outs.add_all(ins)
 
                var def = def_var # mem
 
@@ -244,7 +244,7 @@ redef class AArithmeticInstruction
                v.current_range = null
                visit_all(v)
 
-               if ins != null then outs.recover_with(ins)
+               if ins != null then outs.add_all(ins)
 
                var reg = reg_var
 
@@ -284,7 +284,7 @@ redef class ANegInstruction
                v.current_range = null
                visit_all(v)
 
-               if ins != null then outs.recover_with(ins)
+               if ins != null then outs.add_all(ins)
 
                var reg = reg_var
                if ins.has_key(reg) then
@@ -324,7 +324,7 @@ redef class AMovInstruction
                v.current_range = null
                visit_all(v)
 
-               if ins != null then outs.recover_with(ins)
+               if ins != null then outs.add_all(ins)
 
                var reg = new RegisterVar('A')
                if outs.has_key(reg) then
index 0df593b..0fe04ef 100644 (file)
@@ -48,14 +48,14 @@ end
 redef class AInstruction
        redef fun accept_reaching_defs_analysis(v, ins, outs)
        do
-               if ins != null then outs.recover_with(ins)
+               if ins != null then outs.add_all(ins)
        end
 end
 
 redef class ALoadInstruction
        redef fun accept_reaching_defs_analysis(v, ins, outs)
        do
-               if ins != null then outs.recover_with(ins)
+               if ins != null then outs.add_all(ins)
 
                var variable = def_var
                if variable != null then
@@ -72,7 +72,7 @@ end
 redef class AStoreInstruction
        redef fun accept_reaching_defs_analysis(v, ins, outs)
        do
-               if ins != null then outs.recover_with(ins)
+               if ins != null then outs.add_all(ins)
 
                var variable = def_var
                if variable != null then
index 8de56eb..74e3b4c 100644 (file)
@@ -25,7 +25,7 @@ in "Java" `{
        import android.app.Notification;
 `}
 
-redef class NativeActivity
+redef class NativeContext
        fun notification_manager: NativeNotificationManager in "Java" `{
                return (NotificationManager)self.getSystemService(Context.NOTIFICATION_SERVICE);
        `}
@@ -47,7 +47,7 @@ end
 
 extern class NativeNotificationBuilder in "Java" `{ android.app.Notification$Builder `}
 
-       new (context: NativeActivity) in "Java" `{ return new Notification.Builder(context); `}
+       new (context: NativeContext) in "Java" `{ return new Notification.Builder(context); `}
 
        fun create: NativeNotification in "Java" `{
                // Deprecated since API 16, which introduces `build`,
index 90c513b..476ad82 100644 (file)
@@ -110,7 +110,7 @@ redef class ListLayout
                var adapter = new Android_widget_ArrayAdapter(app.native_activity,
                        android_r_layout_simple_list_item_1, self)
                native.set_adapter adapter
-               return adapter
+               return adapter.new_global_ref
        end
 
        redef fun add(item)
@@ -186,6 +186,7 @@ redef class NativeButton
        private new (context: NativeActivity, sender_object: Button)
        import Button.on_click in "Java" `{
                final int final_sender_object = sender_object;
+               Button_incr_ref(final_sender_object);
 
                return new android.widget.Button(context){
                        @Override
index 5f9af05..ade3bfc 100644 (file)
@@ -149,6 +149,12 @@ interface Collection[E]
        # It is memory-efficient but relies on `has` so may be CPU-inefficient for some kind of collections.
        fun has_all(other: Collection[nullable Object]): Bool
        do
+               if is_same_instance(other) then return true
+               var ol = other.length
+               var  l = length
+               if ol == 0 then return true
+               if l == 0 then return false
+               if ol == 1 then return has(other.first)
                for x in other do if not has(x) then return false
                return true
        end
@@ -680,19 +686,17 @@ interface Map[K, V]
        # Add each (key,value) of `map` into `self`.
        # If a same key exists in `map` and `self`, then the value in self is discarded.
        #
-       # It is the analogous of `SimpleCollection::add_all`
-       #
        #     var x = new HashMap[String, Int]
        #     x["four"] = 4
        #     x["five"] = 5
        #     var y = new HashMap[String, Int]
        #     y["four"] = 40
        #     y["nine"] = 90
-       #     x.recover_with y
+       #     x.add_all y
        #     assert x["four"]  == 40
        #     assert x["five"]  == 5
        #     assert x["nine"]  == 90
-       fun recover_with(map: MapRead[K, V])
+       fun add_all(map: MapRead[K, V])
        do
                var i = map.iterator
                while i.is_ok do
@@ -701,6 +705,9 @@ interface Map[K, V]
                end
        end
 
+       # Alias for `add_all`
+       fun recover_with(map: MapRead[K, V]) is deprecated do add_all(map)
+
        # Remove all items
        #
        #     var x = new HashMap[String, Int]
index 8747c8b..e28e735 100644 (file)
@@ -793,7 +793,7 @@ class ArrayMap[K, E]
        redef fun clone
        do
                var res = new ArrayMap[K,E]
-               res.recover_with self
+               res.add_all self
                return res
        end
 end
index c049332..6546b19 100644 (file)
@@ -273,7 +273,7 @@ class HashMap[K, V]
        # Build a list filled with the items of `coll`.
        init from(coll: Map[K, V]) do
                init
-               recover_with(coll)
+               add_all(coll)
        end
 
        redef var keys: RemovableCollection[K] = new HashMapKeys[K, V](self) is lazy
index 78cd75d..ab4d387 100644 (file)
@@ -121,7 +121,7 @@ end
 
 redef class JsonObject
        # Inits `self` from a BSON object.
-       private init from_bson(bson: BSON) do recover_with(bson.to_json)
+       private init from_bson(bson: BSON) do add_all(bson.to_json)
 
        # Returns a new BSON object from `self`.
        private fun to_bson: BSON do return new BSON.from_json(self)
index 1fdf1ed..8ac55cc 100644 (file)
@@ -186,7 +186,7 @@ redef class NeoGraph
                        var rel_type = json_edge["type"].as(String)
                        var json_properties = json_edge["properties"].as(JsonObject)
                        var edge = new NeoEdge(from, rel_type, to)
-                       edge.properties.recover_with(json_properties)
+                       edge.properties.add_all(json_properties)
                        edges.add edge
                end
        end
@@ -270,7 +270,7 @@ redef class NeoNode
                var labels = o["labels"].as(JsonArray)
                for lab in labels do self.labels.add(lab.as(String))
                var json_properties = o["properties"].as(JsonObject)
-               properties.recover_with(json_properties)
+               properties.add_all(json_properties)
        end
 
        redef fun to_json do return to_json_by_append
index e99237a..9e94493 100644 (file)
@@ -139,7 +139,7 @@ class HttpRequestParser
 
                        var parse_url = parse_url
                        http_request.get_args = parse_url
-                       http_request.all_args.recover_with parse_url
+                       http_request.all_args.add_all parse_url
                else
                        http_request.uri = first_line[1]
                end
index ce8682e..464a2c3 100644 (file)
@@ -650,7 +650,7 @@ private class Context
                if prefix_table != null then
                        var old_prefix_table = prefix_table.as(not null)
                        prefix_table = new HashMap[String, String]
-                       prefix_table.recover_with(old_prefix_table)
+                       prefix_table.add_all(old_prefix_table)
                else
                        prefix_table = new HashMap[String, String]
                end
index 3cba054..347aa11 100644 (file)
@@ -668,7 +668,9 @@ abstract class AbstractCompiler
                self.header.add_decl("  #define be32toh(val) ((be16toh((val) << 16) | (be16toh((val) >> 16))))")
                self.header.add_decl("#endif")
                self.header.add_decl("#ifdef ANDROID")
-               self.header.add_decl("  #define be32toh(val) betoh32(val)")
+               self.header.add_decl("  #ifndef be32toh")
+               self.header.add_decl("          #define be32toh(val) betoh32(val)")
+               self.header.add_decl("  #endif")
                self.header.add_decl("  #include <android/log.h>")
                self.header.add_decl("  #define PRINT_ERROR(...) (void)__android_log_print(ANDROID_LOG_WARN, \"Nit\", __VA_ARGS__)")
                self.header.add_decl("#else")
index 3bd703a..a1f84a8 100644 (file)
@@ -33,7 +33,7 @@ str = "résonnance réseau résultat"
 print str.search_all("rés".to_re).join(", ")
 
 str = "あついあのあほ"
-print str.split("あ(の)?".to_re).join("")
+print str.split("あ(の)?".to_re).join
 
 for i in str.search_all("あ(の)?".to_re) do
        print "Match found : {i}"