parser: _location it no more nullable, so use isset for magic when needed
authorJean Privat <jean@pryen.org>
Wed, 3 Sep 2014 18:07:32 +0000 (14:07 -0400)
committerJean Privat <jean@pryen.org>
Wed, 3 Sep 2014 23:09:08 +0000 (19:09 -0400)
Signed-off-by: Jean Privat <jean@pryen.org>

src/astvalidation.nit
src/parser/lexer_work.nit
src/parser/parser_nodes.nit
src/parser/parser_work.nit

index 913ee21..a3c4bbc 100644 (file)
@@ -52,7 +52,7 @@ redef class ANode
                end
                v.seen.add(self)
 
-               if _location == null then
+               if not isset _location then
                        #debug "LOCATION: unlocated node {v.path.join(", ")}"
                        _location = self.parent.location
                end
index 1c626b8..4fc9eda 100644 (file)
@@ -127,7 +127,7 @@ class Lexer
                t = get_token
                while t == null do t = get_token
 
-               if t._location != null then
+               if isset t._location then
                        var l = last_token
                        if l != null then
                                l.next_token = t
index 5190abd..2e52c08 100644 (file)
@@ -20,11 +20,9 @@ import location
 
 # Root of the AST class-hierarchy
 abstract class ANode
-       var _location: nullable Location = null
-
        # Location is set during AST building. Once built, location cannon be null.
        # However, manual instantiated nodes may need more care.
-       fun location: Location do return _location.as(not null)
+       var location: Location is writable, noinit
 
        # The location of the important part of the node (identifier or whatever)
        fun hot_location: Location do return location
@@ -269,8 +267,6 @@ end
 abstract class Prod
        super ANode
 
-       fun location=(l: Location) do _location = l
-
        # All the annotations attached directly to the node
        var _n_annotations: nullable AAnnotations = null
        fun n_annotations: nullable AAnnotations do return _n_annotations
@@ -280,7 +276,7 @@ abstract class Prod
        do
                super
                assert n isa Prod
-               if n._location == null then n._location = _location
+               if not isset n._location and isset _location then n._location = _location
        end
 end
 
index 5b217da..e54fc4c 100644 (file)
@@ -154,7 +154,7 @@ class Parser
                                return node
                        else if action_type == 3 then # ERROR
                                # skip injected tokens
-                               while token._location == null do token = lexer.next
+                               while not isset token._location do token = lexer.next
                                var node2 = new AParserError.init_parser_error("Syntax error: unexpected {token}.", token.location, token)
                                var node = new Start(null, node2)
                                return node
@@ -188,8 +188,8 @@ private class ComputeProdLocationVisitor
        redef fun visit(n: ANode)
        do
                if n isa Token then
+                       if not isset n._location then return
                        var loc = n._location
-                       if loc == null then return
                        _last_location = loc
 
                        # Add a first token to productions that need one