modelbuilder: add `ANode::is_broken`
authorJean Privat <jean@pryen.org>
Tue, 6 Oct 2015 15:53:32 +0000 (11:53 -0400)
committerJean Privat <jean@pryen.org>
Tue, 6 Oct 2015 15:53:32 +0000 (11:53 -0400)
Signed-off-by: Jean Privat <jean@pryen.org>

src/modelbuilder_base.nit

index 8e1e7c6..4edd46d 100644 (file)
@@ -186,10 +186,15 @@ class ModelBuilder
 
        # Helper function to display an error on a node.
        # Alias for `self.toolcontext.error(n.hot_location, text)`
+       #
+       # This automatically sets `n.is_broken` to true.
        fun error(n: nullable ANode, text: String)
        do
                var l = null
-               if n != null then l = n.hot_location
+               if n != null then
+                       l = n.hot_location
+                       n.is_broken = true
+               end
                self.toolcontext.error(l, text)
        end
 
@@ -354,6 +359,22 @@ class ModelBuilder
        end
 end
 
+redef class ANode
+       # The indication that the node did not pass some semantic verifications.
+       #
+       # This simple flag is set by a given analysis to say that the node is broken and unusable in
+       # an execution.
+       # When a node status is set to broken, it is usually associated with a error message.
+       #
+       # If it is safe to do so, clients of the AST SHOULD just skip broken nodes in their processing.
+       # Clients that do not care about the executability (e.g. metrics) MAY still process the node or
+       # perform specific checks to determinate the validity of the node.
+       #
+       # Note that the broken status is not propagated to parent or children nodes.
+       # e.g. a broken expression used as argument does not make the whole call broken.
+       var is_broken = false is writable
+end
+
 redef class AType
        # The mtype associated to the node
        var mtype: nullable MType = null