Merge: Fix some AST bugs
authorJean Privat <jean@pryen.org>
Sun, 27 Apr 2014 01:01:52 +0000 (21:01 -0400)
committerJean Privat <jean@pryen.org>
Sun, 27 Apr 2014 01:02:02 +0000 (21:02 -0400)
`transform` and `rta` have some issues that lead to inconsistant information on the AST.
This series fixes them.

Note: Most commits extracted (cherry-picked) from #386 and #367

Pull-Request: #404
Reviewed-by: Alexis Laferrière <alexis.laf@xymus.net>

src/abstract_compiler.nit
src/astbuilder.nit
src/platform.nit
src/rapid_type_analysis.nit
src/transform.nit
src/typing.nit
tests/niti.skip
tests/sav/error_needed_method_alt4.res
tests/sav/nitg-e/error_needed_method_alt4.res [new file with mode: 0644]
tests/sav/niti/error_needed_method_alt4.res [new file with mode: 0644]

index d03c1ea..cef1c5b 100644 (file)
@@ -20,7 +20,6 @@ module abstract_compiler
 import literal
 import typing
 import auto_super_init
-import frontend
 import platform
 import c_tools
 
index fa1d188..afcffdf 100644 (file)
@@ -248,7 +248,6 @@ redef class ACallExpr
        do
                self._n_expr = recv
                recv.parent = self
-               self.raw_arguments = args or else new Array[AExpr]
                _n_args = new AListExprs
                _n_id = new TId
                if args != null then
index 4d65c7e..ccb506d 100644 (file)
@@ -18,7 +18,6 @@ module platform
 
 import modelize_property
 import parser_util
-import simple_misc_analysis
 import modelbuilder
 
 redef class ToolContext
index c68d33a..a40ca22 100644 (file)
@@ -161,9 +161,16 @@ class RapidTypeAnalysis
                return tree
        end
 
-       # Methods that are are still candidate to the try_send
+       # Methods that are still candidate to the try_send
        private var totry_methods = new HashSet[MMethod]
 
+       # Methods that are are no more candidate to the try_send
+       private var totry_methods_to_remove = new Array[MMethod]
+
+       # Methods that are or were candidate to the try_send
+       # Used to ensure that try_send is only used once
+       private var try_methods = new HashSet[MMethod]
+
        # The method definitions that remain to visit
        private var todo = new List[MMethodDef]
 
@@ -326,6 +333,10 @@ class RapidTypeAnalysis
                for p in totry_methods do try_send(mtype, p)
                for p in live_super_sends do try_super_send(mtype, p)
 
+               # Remove cleared ones
+               for p in totry_methods_to_remove do totry_methods.remove(p)
+               totry_methods_to_remove.clear
+
                var bound_mtype = mtype.anchor_to(mainmodule, recv)
                for cd in bound_mtype.collect_mclassdefs(mainmodule)
                do
@@ -374,14 +385,15 @@ class RapidTypeAnalysis
                        if not live_methoddefs.has(d) then return
                end
                #print "full property: {mpropdef.mproperty} for {mpropdef.mproperty.mpropdefs.length} definitions"
-               totry_methods.remove(mpropdef.mproperty)
+               totry_methods_to_remove.add(mpropdef.mproperty)
        end
 
        fun add_send(recv: MType, mproperty: MMethod)
        do
-               if live_methods.has(mproperty) then return
+               if try_methods.has(mproperty) then return
                #print "new prop: {mproperty}"
                live_methods.add(mproperty)
+               try_methods.add(mproperty)
                if mproperty.mpropdefs.length == 1 then
                        # If there is only one definition, just add the definition and do not try again the property
                        var d = mproperty.mpropdefs.first
@@ -468,7 +480,11 @@ class RapidTypeVisitor
 
        fun add_type(mtype: MClassType) do analysis.add_new(receiver, mtype)
 
-       fun add_monomorphic_send(mtype: MType, mproperty: MMethod) do analysis.try_send(mtype.as(MClassType), mproperty)
+       fun add_monomorphic_send(mtype: MType, mproperty: MMethod)
+       do
+               analysis.live_methods.add(mproperty)
+               analysis.try_send(mtype.as(MClassType), mproperty)
+       end
 
        fun add_send(mtype: MType, mproperty: MMethod) do analysis.add_send(mtype, mproperty)
 
index bf4b992..06bdcb6 100644 (file)
@@ -88,13 +88,14 @@ redef class AVardeclExpr
        #
        # Declarations are only useful for scope rules
        # Once names are associated with real objects, ther declaration become useless
-       # Therefore, if there is no initial value, then just detach it
+       # Therefore, if there is no initial value, then just ignore it
        # Else, replace it with a simple assignment
        redef fun accept_transform_visitor(v)
        do
                var nexpr = n_expr
                if nexpr == null then
-                       detach
+                       # do nothing
+                       # note: not detached because the collection is currently under iteration
                else
                        var nvar = v.builder.make_var_assign(self.variable.as(not null), nexpr)
                        replace_with(nvar)
@@ -199,6 +200,8 @@ redef class ASuperstringExpr
        #     t.to_s
        redef fun accept_transform_visitor(v)
        do
+               if true then return # FIXME: transformation disabled for the moment
+
                var nblock = v.builder.make_block
 
                var arraytype = v.get_class(self, "Array").get_mtype([v.get_class(self, "Object").mclass_type])
index fbd3f36..9cae36f 100644 (file)
@@ -1221,7 +1221,6 @@ redef class ASendExpr
                var msignature = callsite.msignature
 
                var args = compute_raw_arguments
-               self.raw_arguments = args
 
                callsite.check_signature(v, args)
 
@@ -1245,7 +1244,7 @@ redef class ASendExpr
        private fun property_name: String is abstract
 
        # An array of all arguments (excluding self)
-       var raw_arguments: nullable Array[AExpr]
+       fun raw_arguments: Array[AExpr] do return compute_raw_arguments
 
        private fun compute_raw_arguments: Array[AExpr] is abstract
 end
@@ -1382,7 +1381,6 @@ redef class ASendReassignFormExpr
                self.callsite = callsite
 
                var args = compute_raw_arguments
-               self.raw_arguments = args
 
                callsite.check_signature(v, args)
 
index 906bd9b..7ffd330 100644 (file)
@@ -11,6 +11,7 @@ nitg_args1
 nitg_args3
 nitg_args5
 nitg_args6
+test_markdown_args1
 pep8analysis
 test_android_platform
 android
index 795ca25..6f7a1f9 100644 (file)
@@ -1 +1 @@
-alt/error_needed_method_alt4.nit:49,10--20: Fatal Error: Array must have a property named with_capacity.
+Fatal Error: no primitive class NativeArray
diff --git a/tests/sav/nitg-e/error_needed_method_alt4.res b/tests/sav/nitg-e/error_needed_method_alt4.res
new file mode 100644 (file)
index 0000000..d1e2d76
--- /dev/null
@@ -0,0 +1 @@
+alt/error_needed_method_alt4.nit:49,10--14: Fatal Error: NativeString must have a property named to_s_with_length.
diff --git a/tests/sav/niti/error_needed_method_alt4.res b/tests/sav/niti/error_needed_method_alt4.res
new file mode 100644 (file)
index 0000000..4daa384
--- /dev/null
@@ -0,0 +1 @@
+alt/error_needed_method_alt4.nit:49,10--14: Fatal Error: NativeString must have a property named to_s.