Signed-off-by: Jean Privat <jean@pryen.org>
# Root of the AST hierarchy
abstract class ANode
# 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
end
# Ancestor of all tokens
# Ancestor of all productions
abstract class Prod
special ANode
# 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
end
class TEol
special Token
# Root of the AST hierarchy
abstract class ANode
# 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
end
# Ancestor of all tokens
# Ancestor of all productions
abstract class Prod
special ANode
# 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
end
class TEol
special Token
$ template make_abs_nodes()
# Root of the AST hierarchy
abstract class PNode
$ 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
end
# Ancestor of all tokens
# Ancestor of all productions
abstract class Prod
special PNode
# Ancestor of all productions
abstract class Prod
special PNode
- fun location=(loc: nullable Location) do _location = loc
+ fun location=(loc: Location) do _location = loc
do
if v.must_be_set and not is_set(v) then
_visitor.error(n, "Error: variable '{v}' is possibly unset.")
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
do
if not n.is_typed then
if tc.error_count == 0 then
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,
abort
end
# An error occured in a sub node,
if node == null then
error(n, "Type error: no most general type. Got {n.stype} and {stype}.")
else
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)}.")