Extract get_signature from process_signature.
authorJean Privat <jean@pryen.org>
Sun, 28 Dec 2008 22:26:08 +0000 (17:26 -0500)
committerJean Privat <jean@pryen.org>
Sun, 28 Dec 2008 22:26:08 +0000 (17:26 -0500)
Rationale: blocs will require processing of a known signature.

src/metamodel/static_type.nit
src/syntax/typing.nit

index 8109d17..7fd2776 100644 (file)
@@ -160,6 +160,42 @@ class MMSignature
                return new MMSignature(p,rv,r)
        end
 
+       attr _not_for_self_cache: MMSignature
+
+       # Return a type approximation if the reveiver is not self
+       # Useful for virtual types
+       meth not_for_self: MMSignature
+       do
+               var res = _not_for_self_cache
+               if res != null then return res
+
+               var need_for_self = false
+               var p = _params
+               if p != null then
+                       p = new Array[MMType]
+                       for i in _params do
+                               var i2 = i.not_for_self
+                               if i != i2 then need_for_self = true
+                               p.add(i.not_for_self)
+                       end
+               end
+               
+               var rv = _return_type
+               if rv != null then
+                       var rv = rv.not_for_self
+                       if rv != _return_type then need_for_self = true
+               end
+
+               if need_for_self then
+                       res = new MMSignature(p, rv, _recv)
+               else
+                       res = self
+               end
+
+               _not_for_self_cache = res
+               return res
+       end
+
        init(params: Array[MMType], return_type: MMType, r: MMType)
        do
                assert params != null
index cea4b10..09d88a3 100644 (file)
@@ -678,7 +678,8 @@ special ASuperInitCall
                        _init_in_superclass = p
                        register_super_init_call(v, p)
                        if n_args.length > 0 then
-                               _arguments = process_signature(v, v.self_type, p, true, n_args.to_a)
+                               var signature = get_signature(v, v.self_type, p, true)
+                               _arguments = process_signature(v, signature, p, n_args.to_a)
                        end
                else
                        v.error(self, "Error: No super method to call for {v.local_property}.")
@@ -776,7 +777,9 @@ special PExpr
        do
                var prop = get_property(v, type_recv, is_implicit_self, name)
                if prop == null then return
-               var args = process_signature(v, type_recv, prop, recv_is_self, raw_args)
+               var sig = get_signature(v, type_recv, prop, recv_is_self)
+               if sig == null then return
+               var args = process_signature(v, sig, prop, raw_args)
                if args == null then return
                _prop = prop
                _arguments = args
@@ -809,10 +812,17 @@ special PExpr
                return prop
        end
 
-       private meth process_signature(v: TypingVisitor, type_recv: MMType, prop: MMMethod, recv_is_self: Bool, raw_args: Array[PExpr]): Array[PExpr]
+       private meth get_signature(v: TypingVisitor, type_recv: MMType, prop: MMMethod, recv_is_self: Bool): MMSignature
        do
                prop.global.check_visibility(v, self, v.module, recv_is_self)
                var psig = prop.signature_for(type_recv)
+               if not recv_is_self then psig = psig.not_for_self
+               return psig
+       end
+       
+       # Check the conformity of a set of arguments `raw_args' to a signature.
+       private meth process_signature(v: TypingVisitor, psig: MMSignature, prop: MMMethod, raw_args: Array[PExpr]): Array[PExpr]
+       do
                var par_vararg = psig.vararg_rank
                var par_arity = psig.arity
                var raw_arity: Int
@@ -826,7 +836,6 @@ special PExpr
                for par_idx in [0..par_arity[ do
                        var a: PExpr
                        var par_type = psig[par_idx]
-                       if not recv_is_self then par_type = par_type.not_for_self
                        if par_idx == par_vararg then
                                var star = new Array[PExpr]
                                for i in [0..(raw_arity-par_arity)] do