Merge: typing: Add a mechanism to disable warnings
authorJean Privat <jean@pryen.org>
Sat, 25 Apr 2020 07:12:47 +0000 (03:12 -0400)
committerJean Privat <jean@pryen.org>
Sat, 25 Apr 2020 07:12:47 +0000 (03:12 -0400)
Add a mechanism to suppress warnings during the typing phase. I also took the opportunity to modify a bad indentation in the file :smile: .

Pull-Request: #2818
Reviewed-by: Jean Privat <jean@pryen.org>

src/modelbuilder_base.nit
src/modelize/modelize_property.nit
src/semantize/typing.nit

index 0db4b4b..0d75563 100644 (file)
@@ -60,7 +60,7 @@ class ModelBuilder
        # If no such a class exists, then null is returned.
        # If more than one class exists, then an error on `anode` is displayed and null is returned.
        # FIXME: add a way to handle class name conflict
-       fun try_get_mclass_by_name(anode: ANode, mmodule: MModule, name: String): nullable MClass
+       fun try_get_mclass_by_name(anode: nullable ANode, mmodule: MModule, name: String): nullable MClass
        do
                var classes = model.get_mclasses_by_name(name)
                if classes == null then
@@ -112,7 +112,7 @@ class ModelBuilder
        end
 
        # Like `try_get_mclass_by_name` but display an error message when the class is not found
-       fun get_mclass_by_name(node: ANode, mmodule: MModule, name: String): nullable MClass
+       fun get_mclass_by_name(node: nullable ANode, mmodule: MModule, name: String): nullable MClass
        do
                var mclass = try_get_mclass_by_name(node, mmodule, name)
                if mclass == null then
@@ -127,7 +127,7 @@ class ModelBuilder
        # If no such a property exists, then null is returned.
        # If more than one property exists, then an error on `anode` is displayed and null is returned.
        # FIXME: add a way to handle property name conflict
-       fun try_get_mproperty_by_name2(anode: ANode, mmodule: MModule, mtype: MType, name: String): nullable MProperty
+       fun try_get_mproperty_by_name2(anode: nullable ANode, mmodule: MModule, mtype: MType, name: String): nullable MProperty
        do
                var props = self.model.get_mproperties_by_name(name)
                if props == null then
@@ -209,7 +209,7 @@ class ModelBuilder
 
 
        # Alias for try_get_mproperty_by_name2(anode, mclassdef.mmodule, mclassdef.mtype, name)
-       fun try_get_mproperty_by_name(anode: ANode, mclassdef: MClassDef, name: String): nullable MProperty
+       fun try_get_mproperty_by_name(anode: nullable ANode, mclassdef: MClassDef, name: String): nullable MProperty
        do
                return try_get_mproperty_by_name2(anode, mclassdef.mmodule, mclassdef.bound_mtype, name)
        end
index 7aeffe8..a7acef6 100644 (file)
@@ -53,6 +53,17 @@ redef class ModelBuilder
                mpropdef2npropdef[mpropdef] = npropdef
        end
 
+       # Associate a `nclassdef` with its `mclassdef`
+       #
+       # Be careful, this method is unsafe, no checking is done when it's used.
+       # The safe way to add mclass it's to use the `build_property`
+       #
+       # See `mclassdef2nclassdef`
+       fun unsafe_add_mclassdef2nclassdef(mclassdef: MClassDef, nclassdef: AClassdef)
+       do
+               mclassdef2nclassdef[mclassdef] = nclassdef
+       end
+
        # Retrieve the associated AST node of a mpropertydef.
        # This method is used to associate model entity with syntactic entities.
        #
index 649d564..98aba77 100644 (file)
@@ -1038,6 +1038,18 @@ redef class AExpr
                end
                return res
        end
+
+       # Type the expression as if located in `visited_mpropdef`
+       # `TypeVisitor` and `PostTypingVisitor` will be used to do the typing, see them for more information.
+       #
+       # `visited_mpropdef`: Correspond to the evaluation context in which the expression is located.
+       fun do_typing(modelbuilder: ModelBuilder, visited_mpropdef: MPropDef)
+       do
+               var type_visitor = new TypeVisitor(modelbuilder, visited_mpropdef)
+               type_visitor.visit_stmt(self)
+               var post_visitor = new PostTypingVisitor(type_visitor)
+               post_visitor.enter_visit(self)
+       end
 end
 
 redef class ABlockExpr