From 7041b45d15044d4ae649423e68fe2dee36a72e02 Mon Sep 17 00:00:00 2001 From: Jean Privat Date: Wed, 29 Jul 2009 09:50:18 -0400 Subject: [PATCH] parser: node locations are not nullable Signed-off-by: Jean Privat --- src/parser/parser_abs.nit | 8 ++++++-- src/parser/parser_nodes.nit | 7 +++++-- src/parser/xss/nodes.xss | 8 ++++++-- src/syntax/control_flow.nit | 11 ----------- src/syntax/syntax_base.nit | 14 ++------------ 5 files changed, 19 insertions(+), 29 deletions(-) diff --git a/src/parser/parser_abs.nit b/src/parser/parser_abs.nit index 1cc42a7..1918a3d 100644 --- a/src/parser/parser_abs.nit +++ b/src/parser/parser_abs.nit @@ -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 diff --git a/src/parser/parser_nodes.nit b/src/parser/parser_nodes.nit index c9fde5e..36c5ceb 100644 --- a/src/parser/parser_nodes.nit +++ b/src/parser/parser_nodes.nit @@ -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 diff --git a/src/parser/xss/nodes.xss b/src/parser/xss/nodes.xss index 9cd1919..d6df697 100644 --- a/src/parser/xss/nodes.xss +++ b/src/parser/xss/nodes.xss @@ -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 diff --git a/src/syntax/control_flow.nit b/src/syntax/control_flow.nit index 7b3baf4..4cd879b 100644 --- a/src/syntax/control_flow.nit +++ b/src/syntax/control_flow.nit @@ -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 diff --git a/src/syntax/syntax_base.nit b/src/syntax/syntax_base.nit index 03a25a9..09b7573 100644 --- a/src/syntax/syntax_base.nit +++ b/src/syntax/syntax_base.nit @@ -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 -- 1.7.9.5