model: implements lookup_next_definition
authorJean Privat <jean@pryen.org>
Fri, 25 Jan 2013 19:54:26 +0000 (14:54 -0500)
committerJean Privat <jean@pryen.org>
Fri, 25 Jan 2013 19:54:26 +0000 (14:54 -0500)
Still static however.

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

src/model/model.nit
src/naive_interpreter.nit

index b61840a..168de18 100644 (file)
@@ -1580,17 +1580,22 @@ abstract class MPropDef
        fun is_intro: Bool do return mproperty.intro == self
 
        # Return the next definition in linearization of `mtype`.
-       # If there is no next method then null is returned.
        #
        # This method is used to determine what method is called by a super.
        #
-       # FIXME: NOT YET IMPLEMENTED
+       # FIXME: IMPLEMENTED AS A static designation, it is ugly
        #
        # REQUIRE: not mtype.need_anchor
-       fun lookup_next_definition(mmodule: MModule, mtype: MType): nullable MPROPDEF
+       fun lookup_next_definition(mmodule: MModule, mtype: MType): MPROPDEF
        do
                assert not mtype.need_anchor
-               return null
+
+               var mpropdefs = self.mproperty.lookup_super_definitions(self.mclassdef.mmodule, self.mclassdef.bound_mtype)
+               assert not mpropdefs.is_empty
+               if mpropdefs.length > 1 then
+                       print "BADLINEXT chose next {mpropdefs.first} in: {mpropdefs.join(", ")}"
+               end
+               return mpropdefs.first
        end
 end
 
index 4818e57..a420387 100644 (file)
@@ -1554,11 +1554,7 @@ redef class ASuperExpr
                # stantard call-next-method
                var mpropdef = v.frame.mpropdef
                # FIXME: we do not want an ugly static call!
-               var mpropdefs = mpropdef.mproperty.lookup_super_definitions(mpropdef.mclassdef.mmodule, mpropdef.mclassdef.bound_mtype)
-               if mpropdefs.length != 1 then
-                       debug("Warning: NOT YET IMPLEMENTED: multiple MPRODFEFS for super {mpropdef} for {recv}: {mpropdefs.join(", ")}")
-               end
-               mpropdef = mpropdefs.first
+               mpropdef = mpropdef.lookup_next_definition(v.mainmodule, recv.mtype)
                assert mpropdef isa MMethodDef
                var res = v.call(mpropdef, args)
                return res