From: Jean Privat Date: Wed, 3 Sep 2014 18:07:32 +0000 (-0400) Subject: parser: _location it no more nullable, so use isset for magic when needed X-Git-Tag: v0.6.9~56^2~6 X-Git-Url: http://nitlanguage.org parser: _location it no more nullable, so use isset for magic when needed Signed-off-by: Jean Privat --- diff --git a/src/astvalidation.nit b/src/astvalidation.nit index 913ee21..a3c4bbc 100644 --- a/src/astvalidation.nit +++ b/src/astvalidation.nit @@ -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 diff --git a/src/parser/lexer_work.nit b/src/parser/lexer_work.nit index 1c626b8..4fc9eda 100644 --- a/src/parser/lexer_work.nit +++ b/src/parser/lexer_work.nit @@ -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 diff --git a/src/parser/parser_nodes.nit b/src/parser/parser_nodes.nit index 5190abd..2e52c08 100644 --- a/src/parser/parser_nodes.nit +++ b/src/parser/parser_nodes.nit @@ -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 diff --git a/src/parser/parser_work.nit b/src/parser/parser_work.nit index 5b217da..e54fc4c 100644 --- a/src/parser/parser_work.nit +++ b/src/parser/parser_work.nit @@ -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