|
@@ -6,7 +6,6 @@ from hutn_compiler.declare_functions_visitor import DeclareFunctionsVisitor
|
|
|
from hutn_compiler.hutnparser import Tree
|
|
|
from hutn_compiler.visitor import Visitor
|
|
|
|
|
|
-
|
|
|
class SemanticsVisitor(Visitor):
|
|
|
def __init__(self, args):
|
|
|
Visitor.__init__(self, args)
|
|
@@ -360,7 +359,7 @@ class SemanticsVisitor(Visitor):
|
|
|
var_type = types_mv.string_to_type(Tree.get_text(type_spec))
|
|
|
var_name = Tree.get_text(var_id)
|
|
|
|
|
|
- symbol = st.Symbol(var_name, var_type, is_global=self.current_funcdecl is None)
|
|
|
+ symbol = {"name": var_name, "type": var_type, "is_global": self.current_funcdecl is None, "node": None, "params": None}
|
|
|
|
|
|
try:
|
|
|
self.symbol_table.add(symbol)
|
|
@@ -512,7 +511,7 @@ class SemanticsVisitor(Visitor):
|
|
|
raise RuntimeError("{}:{}:{}: error: '{}' is not declared".format(
|
|
|
self.inputfiles[0], tree['startpos']['line'],
|
|
|
tree['startpos']['column'], name))
|
|
|
- self.set_type(tree, symbol.type)
|
|
|
+ self.set_type(tree, symbol['type'])
|
|
|
self.set_symbol(tree, symbol)
|
|
|
|
|
|
def visit_rvalue(self, tree):
|
|
@@ -539,10 +538,10 @@ class SemanticsVisitor(Visitor):
|
|
|
self.visit_children(tree)
|
|
|
|
|
|
symbol = self.get_symbol(Tree.get_tail(tree)[0])
|
|
|
- self.set_type(tree, symbol.type)
|
|
|
+ self.set_type(tree, symbol['type'])
|
|
|
|
|
|
- if not symbol.is_func():
|
|
|
- if isinstance(symbol.type, types_mv.Element):
|
|
|
+ if not st.Symbol.is_func(symbol):
|
|
|
+ if isinstance(symbol['type'], types_mv.Element):
|
|
|
#sys.stderr.write("{}:{}:{}: warning: calling a variable of type "
|
|
|
# "'Element'\n".format(self.inputfiles[0],
|
|
|
# tree.startpos['line'],
|
|
@@ -554,17 +553,17 @@ class SemanticsVisitor(Visitor):
|
|
|
"function".format(self.inputfiles[0],
|
|
|
tree['startpos']['line'],
|
|
|
tree['startpos']['column'],
|
|
|
- symbol.name,
|
|
|
- symbol.type))
|
|
|
+ symbol['name'],
|
|
|
+ symbol['type']))
|
|
|
|
|
|
expressions = Tree.get_children(tree, "expression")
|
|
|
- if len(expressions) != len(symbol.params):
|
|
|
+ if len(expressions) != len(symbol['params']):
|
|
|
raise RuntimeError(
|
|
|
"{}:{}:{}: error: wrong number of arguments to "
|
|
|
"function '{}'".format(self.inputfiles[0],
|
|
|
tree['startpos']['line'],
|
|
|
tree['startpos']['column'],
|
|
|
- symbol.signature()))
|
|
|
+ st.Symbol.signature(symbol)))
|
|
|
|
|
|
"""
|
|
|
for i in range(len(expressions)):
|
|
@@ -586,9 +585,9 @@ class SemanticsVisitor(Visitor):
|
|
|
param_type)
|
|
|
"""
|
|
|
|
|
|
- if symbol.name == "__input":
|
|
|
+ if symbol['name'] == "__input":
|
|
|
tree['head'] = "input"
|
|
|
- elif symbol.name == "__output":
|
|
|
+ elif symbol['name'] == "__output":
|
|
|
tree['head'] = "output"
|
|
|
|
|
|
def visit_input(self, tree):
|
|
@@ -646,7 +645,7 @@ class SemanticsVisitor(Visitor):
|
|
|
param_type = types_mv.string_to_type(Tree.get_text(type_spec))
|
|
|
param_name = Tree.get_text(param_id)
|
|
|
|
|
|
- symbol = st.Symbol(param_name, param_type, is_global=False)
|
|
|
+ symbol = {"name": param_name, "type": param_type, "is_global": False, "node": None, "params": None}
|
|
|
|
|
|
try:
|
|
|
self.symbol_table.add(symbol)
|