start removing implicit properties
[nit.git] / src / syntax / mmbuilder.nit
index e9cf796..2032534 100644 (file)
@@ -73,11 +73,7 @@ redef class MMSrcModule
                # Compute class ancestors types
                var mmbv1b = new ClassAncestorBuilder(tc, self)
                for c in classes do
-                       if c isa MMSrcLocalClass then
-                               for n in c.nodes do
-                                       mmbv1b.visit(n)
-                               end
-                       end
+                       c.accept_class_visitor(mmbv1b)
                        c.compute_ancestors
                end
                if tc.error_count > 0 then exit(1)
@@ -85,11 +81,7 @@ redef class MMSrcModule
                # Check class conformity
                var mmbv1b = new ClassVerifierVisitor(tc, self)
                for c in classes do
-                       if c isa MMSrcLocalClass then
-                               for n in c.nodes do
-                                       mmbv1b.visit(n)
-                               end
-                       end
+                       c.accept_class_visitor(mmbv1b)
                end
                if tc.error_count > 0 then exit(1)
 
@@ -100,10 +92,8 @@ redef class MMSrcModule
                        c.inherit_global_properties
 
                        # Global property introduction and redefinition 
+                       c.accept_class_visitor(mmbv2)
                        if c isa MMSrcLocalClass then
-                               for n in c.nodes do
-                                       mmbv2.visit(n)
-                               end
                        end
 
                        # Note that inherited unredefined property are processed on demand latter
@@ -113,11 +103,7 @@ redef class MMSrcModule
                # Property signature analysis and inheritance conformance
                var mmbv3 = new PropertyVerifierVisitor(tc, self)
                for c in classes do
-                       if c isa MMSrcLocalClass then
-                               for n in c.nodes do
-                                       mmbv3.visit(n)
-                               end
-                       end
+                       c.accept_properties_visitor(mmbv3)
                end
 
                # Check inherited local properties
@@ -132,15 +118,45 @@ redef class MMSrcModule
        end
 end
 
+redef class MMLocalClass
+       # Accept a class visitor (on class nodes)
+       private meth accept_class_visitor(v: AbsSyntaxVisitor)
+       do
+       end
+
+       # Accept a class visitor (on class properties)
+       private meth accept_properties_visitor(v: AbsSyntaxVisitor)
+       do
+       end
+end
+
 redef class MMSrcLocalClass
+       redef meth accept_class_visitor(v)
+       do
+               for n in nodes do
+                       v.visit(n)
+               end
+       end
+
+       # Accept a class visitor (on class properties)
+       redef meth accept_properties_visitor(v)
+       do
+               for n in nodes do
+                       v.visit(n)
+               end
+
+               for p in src_local_properties do
+                       p.accept_property_visitor(v)
+               end
+       end
        # Add a source property
        # Register it to the class and attach it to global property
-       private meth add_src_local_property(v: PropertyBuilderVisitor, prop: MMSrcLocalProperty)
+       private meth add_src_local_property(v: PropertyBuilderVisitor, prop: MMConcreteProperty)
        do
                var pname = prop.name
                # Check double definition in the same class
                if src_local_properties.has_key(pname) then
-                       v.error(prop.node, "Error: A property {pname} is already defined in class {name} at line {src_local_properties[pname].node.first_token.line}.")
+                       v.error(prop.node, "Error: A property {pname} is already defined in class {name}.")
                        return
                end
                src_local_properties[pname] = prop
@@ -163,6 +179,11 @@ redef class MMSrcLocalClass
        end
 end
 
+redef class MMConcreteProperty
+       private meth accept_property_visitor(v: AbsSyntaxVisitor)
+       do
+       end
+end
 # Concrete NIT class specialization relation
 class MMSrcAncestor
 special MMAncestor
@@ -268,7 +289,7 @@ redef class AModule
                # Import super-modules
                var module_names_to_import = new Array[Symbol]
                var module_visibility = new HashMap[Symbol, Int]
-               var no_import: PImport
+               var no_import: PImport = null
                for i in n_imports do
                        var n = i.module_name
                        if n != null then
@@ -595,7 +616,7 @@ redef class PPropdef
        # * Check redef errors.
        # * Check forbiden attribute definitions.
        # * Check signature conformance.
-       private meth process_and_check(v: PropertyVerifierVisitor, prop: MMSrcLocalProperty, has_redef: Bool, visibility_level: Int)
+       private meth process_and_check(v: PropertyVerifierVisitor, prop: MMConcreteProperty, has_redef: Bool, visibility_level: Int)
        do
                if prop.global.intro == prop then
                        do_and_check_intro(v, prop, has_redef, visibility_level)
@@ -605,7 +626,7 @@ redef class PPropdef
        end
 
        # The part of process_and_check when prop is an introduction
-       private meth do_and_check_intro(v: PropertyVerifierVisitor, prop: MMSrcLocalProperty, has_redef: Bool, visibility_level: Int)
+       private meth do_and_check_intro(v: PropertyVerifierVisitor, prop: MMConcreteProperty, has_redef: Bool, visibility_level: Int)
        do
                var glob = prop.global
                var gbc = prop.local_class.global
@@ -645,10 +666,11 @@ redef class PPropdef
                end
        end
 
-       private meth inherit_signature(v: PropertyVerifierVisitor, prop: MMSrcLocalProperty, supers: Array[MMLocalProperty])
+       private meth inherit_signature(v: PropertyVerifierVisitor, prop: MMConcreteProperty, supers: Array[MMLocalProperty])
        do
                var s = prop.signature
                for ip in supers do
+                       assert ip isa MMConcreteProperty
                        var isig = ip.signature.adaptation_to(v.local_class.get_type)
 
                        if s == null then
@@ -672,7 +694,7 @@ redef class PPropdef
        end
 
        # The part of process_and_check when prop is a redefinition
-       private meth do_and_check_redef(v: PropertyVerifierVisitor, prop: MMSrcLocalProperty, has_redef: Bool, visibility_level: Int)
+       private meth do_and_check_redef(v: PropertyVerifierVisitor, prop: MMConcreteProperty, has_redef: Bool, visibility_level: Int)
        do
                var is_init = self isa AConcreteInitPropdef
                var glob = prop.global
@@ -940,7 +962,7 @@ end
 
 redef class PSignature
        # Check that visibilities of types in the signature are compatible with the visibility of the property.
-       meth check_visibility(v: AbsSyntaxVisitor, p: MMSrcLocalProperty) is abstract
+       meth check_visibility(v: AbsSyntaxVisitor, p: MMConcreteProperty) is abstract
 end
 
 redef class ASignature
@@ -1020,7 +1042,7 @@ end
 
 redef class PType
        # Check that visibilities of types in the signature are compatible with the visibility of the property.
-       private meth check_visibility(v: AbsSyntaxVisitor, p: MMSrcLocalProperty) is abstract
+       private meth check_visibility(v: AbsSyntaxVisitor, p: MMConcreteProperty) is abstract
 end
 
 redef class AType