parser: node locations are not nullable
authorJean Privat <jean@pryen.org>
Wed, 29 Jul 2009 13:50:18 +0000 (09:50 -0400)
committerJean Privat <jean@pryen.org>
Thu, 30 Jul 2009 13:17:34 +0000 (09:17 -0400)
Signed-off-by: Jean Privat <jean@pryen.org>

src/parser/parser_abs.nit
src/parser/parser_nodes.nit
src/parser/xss/nodes.xss
src/syntax/control_flow.nit
src/syntax/syntax_base.nit

index 1cc42a7..1918a3d 100644 (file)
@@ -6,7 +6,11 @@ import mmloader
 
 # Root of the AST hierarchy
 abstract class ANode
-       readable var _location: nullable Location
+       var _location: nullable Location
+
+       # Location is set during AST building. Once built, location cannon be null
+       # However, manual instanciated nodes may need mode care
+       fun location: Location do return _location.as(not null)
 end
 
 # Ancestor of all tokens
@@ -17,7 +21,7 @@ end
 # Ancestor of all productions
 abstract class Prod
 special ANode
-       fun location=(loc: nullable Location) do _location = loc
+       fun location=(loc: Location) do _location = loc
 end
 class TEol
 special Token
index c9fde5e..36c5ceb 100644 (file)
@@ -23,7 +23,10 @@ import mmloader
 
 # Root of the AST hierarchy
 abstract class ANode
-       readable var _location: nullable Location
+       var _location: nullable Location
+       # Location is set during AST building. Once built, location cannon be null
+       # However, manual instanciated nodes may need mode care
+       fun location: Location do return _location.as(not null)
 end
 
 # Ancestor of all tokens
@@ -34,7 +37,7 @@ end
 # Ancestor of all productions
 abstract class Prod
 special ANode
-       fun location=(loc: nullable Location) do _location = loc
+       fun location=(l: Location) do _location = l
 end
 class TEol
 special Token
index 9cd1919..d6df697 100644 (file)
@@ -18,7 +18,11 @@ $ // limitations under the License.
 $ template make_abs_nodes()
 # Root of the AST hierarchy
 abstract class PNode
-       readable var _location: nullable Location
+       var _location: nullable Location
+
+       # Location is set during AST building. Once built, location cannon be null
+       # However, manual instanciated nodes may need mode care
+       fun location: Location do return _location.as(not null)
 end
 
 # Ancestor of all tokens
@@ -29,7 +33,7 @@ end
 # Ancestor of all productions
 abstract class Prod
 special PNode
-       fun location=(loc: nullable Location) do _location = loc
+       fun location=(loc: Location) do _location = loc
 end
 $ end template
 
index 7b3baf4..4cd879b 100644 (file)
@@ -49,17 +49,6 @@ abstract class VariableContext
        do
                if v.must_be_set and not is_set(v) then
                        _visitor.error(n, "Error: variable '{v}' is possibly unset.")
-                       var x = self
-                       while true do
-                               var loc = x.node.location
-                               print "  {if loc != null then loc.to_s else "????"}: {x._set_variables.join(", ")} ; {x._dico.join(", ")}"
-                               var x0 = x
-                               if x0 isa SubVariableContext then
-                                       x = x0.prev
-                               else
-                                       break
-                               end
-                       end
                end
        end
 
index 03a25a9..09b7573 100644 (file)
@@ -432,12 +432,7 @@ special Visitor
        do
                if not n.is_typed then
                        if tc.error_count == 0 then
-                               var loc = n.location
-                               if loc == null then
-                                       print("Unknown node not typed but not error")
-                               else
-                                       print("{loc} not typed but not error")
-                               end
+                               print("{n.location} not typed but not error")
                                abort
                        end
                        # An error occured in a sub node,
@@ -488,12 +483,7 @@ special Visitor
                                if node == null then
                                        error(n, "Type error: no most general type. Got {n.stype} and {stype}.")
                                else
-                                       var loc = node.location
-                                       if loc == null then
-                                               error(n, "Type error: no most general type. Got {n.stype} and {stype} at ????.")
-                                       else
-                                               error(n, "Type error: no most general type. Got {n.stype} and {stype} at {loc.relative_to(n.location)}.")
-                                       end
+                                       error(n, "Type error: no most general type. Got {n.stype} and {stype} at {node.location.relative_to(n.location)}.")
                                end
                                return null
                        end