Browse Source

Fixes to broken references in compilation errors

Yentl Van Tendeloo 5 years ago
parent
commit
a653799899
2 changed files with 32 additions and 58 deletions
  1. 0 1
      bootstrap/modelling.alc
  2. 32 57
      interface/HUTN/hutn_compiler/semantics_visitor.py

+ 0 - 1
bootstrap/modelling.alc

@@ -505,7 +505,6 @@ Element function construct_model_list(model : Element, list : Element):
 
 	while (list_len(list) > 0):
 		command = list_pop_final(list)
-		start = time()
 		if (command == "add_node"):
 			model_add_node(model, list_pop_final(list))
 		elif (command == "add_value"):

+ 32 - 57
interface/HUTN/hutn_compiler/semantics_visitor.py

@@ -39,8 +39,8 @@ class SemanticsVisitor(Visitor):
             raise RuntimeError(
                 "{}:{}:{}: error: invalid operands to binary operator "
                 "(have {} and {})".format(self.inputfiles[0],
-                                          l['startpos']['line'],
-                                          l['startpos']['column'],
+                                          l['startpos'][0],
+                                          l['startpos'][1],
                                           str(l_type),
                                           str(r_type)))
 
@@ -65,8 +65,8 @@ class SemanticsVisitor(Visitor):
             raise RuntimeError(
                 "{}:{}:{}: error: wrong type argument to unary {} "
                 "({})".format(self.inputfiles[0],
-                              l['startpos']['line'],
-                              l['startpos']['column'],
+                              l['startpos'][0],
+                              l['startpos'][1],
                               operator_name,
                               str(l_type)))
 
@@ -95,8 +95,8 @@ class SemanticsVisitor(Visitor):
             raise RuntimeError("{}:{}:{}: error: cannot assign a value of "
                                "type '{}' to a variable of type '{}'"
                 .format(self.inputfiles[0],
-                        l['startpos']['line'],
-                        l['startpos']['column'],
+                        l['startpos'][0],
+                        l['startpos'][1],
                         str(r_type),
                         str(l_type)))
 
@@ -120,8 +120,8 @@ class SemanticsVisitor(Visitor):
             raise RuntimeError(
                 "{}:{}:{}: error: 'return' is used outside of a function"
                 .format(self.inputfiles[0],
-                        tree['startpos']['line'],
-                        tree['startpos']['column']))
+                        tree['startpos'][0],
+                        tree['startpos'][1]))
 
     def check_predicate(self, tree):
         if self.get_type(tree) == "Element":
@@ -130,8 +130,8 @@ class SemanticsVisitor(Visitor):
             raise RuntimeError(
                 "{}:{}:{}: error: predicates of type '{}' are not allowed"
                 .format(self.inputfiles[0],
-                        tree['startpos']['line'],
-                        tree['startpos']['column'],
+                        tree['startpos'][0],
+                        tree['startpos'][1],
                         self.get_type(tree)))
 
     def replace_child_binary_op_with_call(self, tree, i=0):
@@ -151,8 +151,8 @@ class SemanticsVisitor(Visitor):
                 raise RuntimeError(
                     "{}:{}:{}: error: children were not casted".format(
                         self.inputfiles[0],
-                        tree['startpos']['line'],
-                        tree['startpos']['column']
+                        tree['startpos'][0],
+                        tree['startpos'][1]
                     ))
             call_name = SemanticsVisitor.call_name_binary(l_type, op)
             call_tree = self.func_call(call_name, [l, r], tree)
@@ -164,8 +164,8 @@ class SemanticsVisitor(Visitor):
                     "{}:{}:{}: error: cannot perform {}: function '{}' is "
                     "not found".format(
                         self.inputfiles[0],
-                        tree['startpos']['line'],
-                        tree['startpos']['column'],
+                        tree['startpos'][0],
+                        tree['startpos'][1],
                         child['head'],
                         call_signature))
             if i == -1:
@@ -193,8 +193,8 @@ class SemanticsVisitor(Visitor):
                     "{}:{}:{}: error: cannot perform {}: function '{}' is "
                     "not found".format(
                         self.inputfiles[0],
-                        tree['startpos']['line'],
-                        tree['startpos']['column'],
+                        tree['startpos'][0],
+                        tree['startpos'][1],
                         child['head'],
                         call_signature))
             Tree.replace_child(tree, child, call_tree)
@@ -269,8 +269,8 @@ class SemanticsVisitor(Visitor):
             "{}:{}:{}: error: cannot perform implicit cast from '{}'"
             " to '{}': function '{}' is not found".format(
                 self.inputfiles[0],
-                tree['startpos']['line'],
-                tree['startpos']['column'],
+                tree['startpos'][0],
+                tree['startpos'][1],
                 str(to_type), str(from_type),
                 cast_signature))
 
@@ -378,8 +378,8 @@ class SemanticsVisitor(Visitor):
         except Exception:
             raise RuntimeError(
                 "{}:{}:{}: error: redeclaration of '{}'".format(
-                    self.inputfiles[0], tree['startpos']['line'],
-                    tree['startpos']['column'], var_name))
+                    self.inputfiles[0], tree['startpos'][0],
+                    tree['startpos'][1], var_name))
 
         self.set_symbol(tree, symbol)
 
@@ -521,8 +521,8 @@ class SemanticsVisitor(Visitor):
             symbol = self.symbol_table.get(name)
         except KeyError:
             raise RuntimeError("{}:{}:{}: error: '{}' is not declared".format(
-                self.inputfiles[0], tree['startpos']['line'],
-                tree['startpos']['column'], name))
+                self.inputfiles[0], tree['startpos'][0],
+                tree['startpos'][1], name))
         self.set_type(tree, symbol['type'])
         self.set_symbol(tree, symbol)
 
@@ -554,17 +554,12 @@ class SemanticsVisitor(Visitor):
 
         if not st.Symbol.is_func(symbol):
             if symbol['type'] == "Element":
-                #sys.stderr.write("{}:{}:{}: warning: calling a variable of type "
-                #                 "'Element'\n".format(self.inputfiles[0],
-                #                                      tree.startpos['line'],
-                #                                      tree.startpos['column'],
-                #                                      symbol.name))
                 return  # allow the call without knowing the declaration
             raise RuntimeError(
                 "{}:{}:{}: error: '{}' is a variable of type '{}', not a "
                 "function".format(self.inputfiles[0],
-                                  tree['startpos']['line'],
-                                  tree['startpos']['column'],
+                                  tree['startpos'][0],
+                                  tree['startpos'][1],
                                   symbol['name'],
                                   symbol['type']))
 
@@ -573,30 +568,10 @@ class SemanticsVisitor(Visitor):
             raise RuntimeError(
                 "{}:{}:{}: error: wrong number of arguments to "
                 "function '{}'".format(self.inputfiles[0],
-                                       tree['startpos']['line'],
-                                       tree['startpos']['column'],
+                                       tree['startpos'][0],
+                                       tree['startpos'][1],
                                        st.Symbol.signature(symbol)))
 
-        """
-        for i in range(len(expressions)):
-            arg_type = self.get_type(expressions[i])
-            param_type = symbol.params[i]
-            if SemanticsVisitor.incompatible_types(arg_type, param_type):
-                raise RuntimeError(
-                    "{}:{}:{}: error: argument {} has type '{}' instead of "
-                    "'{}', calling function '{}'".format(
-                            self.inputfiles[0],
-                            tree.startpos['line'],
-                            tree.startpos['column'],
-                            i + 1,
-                            str(arg_type),
-                            str(param_type),
-                            symbol.signature()))
-            if type(arg_type) != type(param_type):
-                self.perform_implicit_cast(tree, expressions[i], arg_type,
-                                           param_type)
-        """
-
         if symbol['name'] == "__input":
             tree['head'] = "input"
         elif symbol['name'] == "__output":
@@ -664,8 +639,8 @@ class SemanticsVisitor(Visitor):
         except Exception:
             raise RuntimeError(
                 "{}:{}:{}: error: redeclaration of '{}'".format(
-                    self.inputfiles[0], tree['startpos']['line'],
-                    tree['startpos']['column'], param_name))
+                    self.inputfiles[0], tree['startpos'][0],
+                    tree['startpos'][1], param_name))
 
         self.set_symbol(tree, symbol)
 
@@ -680,12 +655,12 @@ class SemanticsVisitor(Visitor):
         if self.while_counter == 0:
             raise RuntimeError(
                 "{}:{}:{}: error: break outside of while".format(
-                    self.inputfiles[0], tree['startpos']['line'],
-                    tree['startpos']['column']))
+                    self.inputfiles[0], tree['startpos'][0],
+                    tree['startpos'][1]))
 
     def visit_continue(self, tree):
         if self.while_counter == 0:
             raise RuntimeError(
                 "{}:{}:{}: error: continue outside of while".format(
-                    self.inputfiles[0], tree['startpos']['line'],
-                    tree['startpos']['column']))
+                    self.inputfiles[0], tree['startpos'][0],
+                    tree['startpos'][1]))