Move property selectors from types to local classes
authorJean Privat <jean@pryen.org>
Wed, 24 Dec 2008 00:30:28 +0000 (19:30 -0500)
committerJean Privat <jean@pryen.org>
Wed, 24 Dec 2008 00:30:28 +0000 (19:30 -0500)
src/compiling/compiling_global.nit
src/compiling/compiling_methods.nit
src/metamodel/abstractmetamodel.nit
src/metamodel/genericity.nit
src/metamodel/static_type.nit
src/metamodel/type_formal.nit
src/metamodel/virtualtype.nit
src/syntax/syntax_base.nit
src/syntax/typing.nit

index 84ae7de..b3fd43f 100644 (file)
@@ -473,7 +473,7 @@ redef class MMSrcModule
                if not has_global_class_named(sysname) then
                        print("No main")
                else
-                       var sys = class_by_name(sysname).get_type
+                       var sys = class_by_name(sysname)
                        # var initm = sys.select_method(once "init".to_symbol)
                        var mainm = sys.select_method(once "main".to_symbol)
                        if mainm == null then
index 02d0d68..f4af270 100644 (file)
@@ -218,7 +218,7 @@ redef class MMMethod
                var ee = once "==".to_symbol
                var ne = once "!=".to_symbol
                if name == ne then
-                       var eqp = signature.recv.select_method(ee)
+                       var eqp = signature.recv.local_class.select_method(ee)
                        var eqcall = eqp.compile_call(v, cargs)
                        return "TAG_Bool(!UNTAG_Bool({eqcall}))"
                end
@@ -849,7 +849,7 @@ redef class AForVardeclExpr
        redef meth compile_stmt(v)
        do
                var e = v.compile_expr(n_expr)
-               var prop = n_expr.stype.select_method(once "iterator".to_symbol)
+               var prop = n_expr.stype.local_class.select_method(once "iterator".to_symbol)
                if prop == null then
                        printl("No iterator")
                        return
@@ -858,17 +858,17 @@ redef class AForVardeclExpr
                v.free_var(e)
                var iter = v.get_var
                v.add_assignment(iter, prop.compile_call(v, [e]))
-               var prop2 = ittype.select_method(once "is_ok".to_symbol)
+               var prop2 = ittype.local_class.select_method(once "is_ok".to_symbol)
                if prop2 == null then
                        printl("No is_ok")
                        return
                end
-               var prop3 = ittype.select_method(once "item".to_symbol)
+               var prop3 = ittype.local_class.select_method(once "item".to_symbol)
                if prop3 == null then
                        printl("No item")
                        return
                end
-               var prop4 = ittype.select_method(once "next".to_symbol)
+               var prop4 = ittype.local_class.select_method(once "next".to_symbol)
                if prop4 == null then
                        printl("No next")
                        return
@@ -1042,7 +1042,7 @@ end
 redef class AStringFormExpr
        redef meth compile_expr(v)
        do
-               var prop = stype.select_method(once "with_native".to_symbol)
+               var prop = stype.local_class.select_method(once "with_native".to_symbol)
                compute_string_info
                return prop.compile_constructor_call(v, ["BOX_NativeString(\"{_cstring}\")", "TAG_Int({_cstring_length})"])
        end
@@ -1098,12 +1098,12 @@ end
 redef class ASuperstringExpr
        redef meth compile_expr(v)
        do
-               var prop = stype.select_method(once "init".to_symbol)
+               var prop = stype.local_class.select_method(once "init".to_symbol)
                var recv = prop.compile_constructor_call(v, new Array[String]) 
 
-               var prop2 = stype.select_method(once "append".to_symbol)
+               var prop2 = stype.local_class.select_method(once "append".to_symbol)
 
-               var prop3 = stype.select_method(once "to_s".to_symbol)
+               var prop3 = stype.local_class.select_method(once "to_s".to_symbol)
                for ne in n_exprs do
                        var e = v.ensure_var(v.compile_expr(ne))
                        if ne.stype != stype then
@@ -1126,10 +1126,10 @@ end
 redef class AArrayExpr
        redef meth compile_expr(v)
        do
-               var prop = stype.select_method(once "with_capacity".to_symbol)
+               var prop = stype.local_class.select_method(once "with_capacity".to_symbol)
                var recv = prop.compile_constructor_call(v,["TAG_Int({n_exprs.length})"])
 
-               var prop2 = stype.select_method(once "add".to_symbol)
+               var prop2 = stype.local_class.select_method(once "add".to_symbol)
                for ne in n_exprs do
                        var e = v.compile_expr(ne)
                        prop2.compile_call(v, [recv, e])
@@ -1141,7 +1141,7 @@ end
 redef class ARangeExpr
        redef meth compile_expr(v)
        do
-               var prop = stype.select_method(propname)
+               var prop = stype.local_class.select_method(propname)
                var e = v.compile_expr(n_expr)
                var e2 = v.compile_expr(n_expr2)
                return prop.compile_constructor_call(v, [e, e2])
index 2874b49..878ef46 100644 (file)
@@ -443,6 +443,30 @@ class MMLocalClass
 
                return null
        end
+
+       # Select a method from its name
+       # TODO: Will disapear when qualified names will be available
+       meth select_method(name: Symbol): MMMethod
+       do
+               assert name != null
+               var gp = method(name)
+               if gp == null then return null
+               var res = self[gp]
+               assert res isa MMMethod
+               return res
+       end
+       
+       # Select an attribute from its name
+       # TODO: Will disapear when qualified names will be available
+       meth select_attribute(name: Symbol): MMAttribute
+       do
+               assert name != null
+               var gp = attribute(name)
+               if gp == null then return null
+               var res = self[gp]
+               assert res isa MMAttribute
+               return res
+       end
        
        # Look in super-classes (by specialization) and return properties with name
        # Beware, global property of results is not intended to be the same
index 8a9d14b..6a9d5dd 100644 (file)
@@ -108,7 +108,6 @@ class MMTypeGeneric
 special MMTypeClass
        # Formal arguments
        readable attr _params: Array[MMType] 
-       attr _props: Map[MMGlobalProperty, MMLocalProperty] = new HashMap[MMGlobalProperty, MMLocalProperty]
 
        redef meth is_generic do return true
 
@@ -172,26 +171,6 @@ special MMTypeClass
                return true
        end
 
-       redef meth select_property(g)
-       do
-               if g == null then
-                       return null
-               end
-               if not _props.has_key(g) then
-                       assert _local_class != null
-                       var p = _local_class[g]
-                       if p != null then
-                               #var p2 = p.adapt_property(self)
-                               #_props[g] = p2
-                               #return p2
-                               return p
-                       else
-                               assert false
-                       end
-               end
-               return _props[g]
-       end
-
        redef meth to_s
        do
                return "{super}[{_params.join(", ")}]"
index d6edfde..e7a2c6e 100644 (file)
@@ -216,29 +216,6 @@ abstract class MMType
        # a double dispatch is needed
        meth is_supertype(t: MMType): Bool is abstract
 
-       # Select a method from its name
-       meth select_method(name: Symbol): MMMethod
-       do
-               assert local_class != null
-               assert name != null
-               var res = select_property(local_class.method(name))
-               assert res isa MMMethod
-               return res
-       end
-       
-       # Select an attribute from its name
-       meth select_attribute(name: Symbol): MMAttribute
-       do
-               assert name != null
-               assert local_class != null
-               var res = select_property(local_class.attribute(name))
-               assert res isa MMAttribute
-               return res
-       end
-
-       # Select a local property from its global property
-       meth select_property(t: MMGlobalProperty): MMLocalProperty is abstract
-
        # Adapt self to another module
        meth for_module(mod: MMModule): MMType is abstract
 
@@ -292,15 +269,6 @@ special MMTypeClass
                return  t.local_class.cshe <= _local_class
        end
 
-       redef meth select_property(g)
-       do
-               assert _local_class != null
-               if g == null then
-                       return null
-               end
-               return _local_class[g]
-       end
-
        redef meth for_module(mod)
        do
                var t: MMType = self
index ca506a6..fb24352 100644 (file)
@@ -43,15 +43,6 @@ special MMType
                return _bound.local_class
        end
 
-       redef meth select_property(g)
-       do
-               if g == null then
-                       return null
-               else
-                       return _bound.select_property(g)
-               end
-       end
-
        redef meth to_s do return _name.to_s
 
        protected init(name: Symbol, bound: MMType)
index 7205be8..752d57f 100644 (file)
@@ -31,7 +31,7 @@ special MMLocalProperty
        # The virtual static type associated
        meth stype_for(recv: MMType): MMVirtualType
        do
-               var prop = recv.select_property(global)
+               var prop = recv.local_class[global]
                assert prop isa MMTypeProperty
                return prop.real_stype_for(recv)
        end
@@ -53,18 +53,6 @@ special MMLocalProperty
        end
 end
 
-redef class MMType
-       # Select a virtual type property by its name
-       meth select_virtual_type(name: Symbol): MMTypeProperty
-       do
-               assert local_class != null
-               assert name != null
-               var res = select_property(local_class.virtual_type(name))
-               assert res isa MMTypeProperty
-               return res
-       end
-end
-
 class MMVirtualType
 special MMTypeFormal
        # The property associed
@@ -108,4 +96,15 @@ redef class MMLocalClass
                end
                return null
        end
+
+       # Select a virtual type property by its name
+       meth select_virtual_type(name: Symbol): MMTypeProperty
+       do
+               assert name != null
+               var gp = virtual_type(name)
+               if gp == null then return null
+               var res = self[gp]
+               assert res isa MMTypeProperty
+               return res
+       end
 end
index ee7de59..deefdad 100644 (file)
@@ -437,7 +437,7 @@ redef class AType
                                v.error(self, "Type error: formal type {name} cannot have formal parameters.")
                                return null
                        end
-                       var t = cla.get_type.select_virtual_type(name).stype_for(cla.get_type)
+                       var t = cla.get_type.local_class.select_virtual_type(name).stype_for(cla.get_type)
                        if t == null then
                                v.error(self, "Type error: circular definition in formal type {name}.")
                                return null
index 0920070..afd0da7 100644 (file)
@@ -395,13 +395,13 @@ redef class AForVardeclExpr
                if not v.check_conform(self, expr_type, v.type_collection) then
                        return
                end
-               var prop = expr_type.select_method(once ("iterator".to_symbol))
+               var prop = expr_type.local_class.select_method(once ("iterator".to_symbol))
                if prop == null then
                        v.error(self, "Error: Collection MUST have an iterate method")
                        return
                end
                var iter_type = prop.signature_for(expr_type).return_type
-               var prop2 = iter_type.select_method(once ("item".to_symbol))
+               var prop2 = iter_type.local_class.select_method(once ("item".to_symbol))
                if prop2 == null then
                        v.error(self, "Error: {iter_type} MUST have an item method")
                        return
@@ -445,7 +445,7 @@ redef class AReassignFormExpr
                        return
                end
                var name = n_assign_op.method_name
-               var prop = type_lvalue.select_method(name)
+               var prop = type_lvalue.local_class.select_method(name)
                if prop == null then
                        v.error(self, "Error: Method '{name}' doesn't exists in {type_lvalue}.")
                        return
@@ -663,7 +663,7 @@ special ASuperInitCall
                                if not p.global.is_init then
                                        v.error(self, "Error: {p.local_class}::{p} is not a constructor.")
                                else
-                                       precs.add(v.self_type.select_property(p.global))
+                                       precs.add(v.local_class[p.global])
                                end
                        end
                        if precs.is_empty then
@@ -722,7 +722,7 @@ redef class AAttrFormExpr
                        return
                end
                var name = n_id.to_symbol
-               var prop = type_recv.select_attribute(name)
+               var prop = type_recv.local_class.select_attribute(name)
                if prop == null then
                        v.error(self, "Error: Attribute {name} doesn't exists in {type_recv}.")
                        return
@@ -785,14 +785,14 @@ special PExpr
        private meth get_property(v: TypingVisitor, type_recv: MMType, is_implicit_self: Bool, name: Symbol): MMMethod
        do
                if type_recv == null then return null
-               var prop = type_recv.select_method(name)
+               var prop = type_recv.local_class.select_method(name)
                if prop == null and v.local_property.global.is_init then
                        var props = type_recv.local_class.super_methods_named(name)
                        if props.length > 1 then
                                v.error(self, "Error: Ambigous method name '{name}' for {props.join(", ")}. Use explicit designation.")
                                return null
                        else if props.length == 1 then 
-                               var p = type_recv.select_property(props.first.global)
+                               var p = type_recv.local_class[props.first.global]
                                assert p isa MMMethod
                                prop = p
                        end