Commit 5597ca94 authored by Sergio Costas's avatar Sergio Costas

Better error cathegories

parent 16ced69d
......@@ -34,6 +34,7 @@ class crusty(object):
MSG_NORMAL = 0
MSG_WARNING = 1
MSG_ERROR = 2
MSG_CRITICAL = 3
class VarNotFoundException(Exception):
pass
......@@ -185,7 +186,9 @@ class crusty(object):
def print_errors(self):
for err in self.errors:
if (err[1] == self.MSG_ERROR):
if (err[1] == self.MSG_CRITICAL):
print("\033[36m{:s}\033[0m: ".format(_("CRITICAL")),end = "")
elif (err[1] == self.MSG_ERROR):
print("\033[31m{:s}\033[0m: ".format(_("ERROR")),end = "")
elif (err[1] == self.MSG_WARNING):
print("\033[33m{:s}\033[0m: ".format(_("WARNING")),end = "")
......@@ -201,7 +204,7 @@ class crusty(object):
for var_group in var_container:
if var_name in var_group:
return var_group[var_name]
self._add_error(self.MSG_ERROR,_("Unknown variable {:s} at line {:d}").format(str(var_name),line_number))
self._add_error(self.MSG_CRITICAL,_("Unknown variable {:s} at line {:d}").format(str(var_name),line_number))
raise self.VarNotFoundException()
......@@ -210,7 +213,7 @@ class crusty(object):
if (not force) and ((variable["properties"] & self.PROPERTY_CRUST_VARIABLE) != 0):
status = variable["status"]
if (status == crusty.STATUS_NOT_NULL) or (status == crusty.STATUS_NOT_NULL_OR_NULL):
self._add_error(self.MSG_WARNING,_("Initializing {:s} at line {:d}, which was already initialized at line {:d}").format(var_name,line_number,variable["init_line"]))
self._add_error(self.MSG_ERROR,_("Assignment to {:s} at line {:d}, which was already assigned at line {:d}").format(var_name,line_number,variable["init_line"]))
variable["init_line"] = line_number
variable["status"] = value
......@@ -219,10 +222,10 @@ class crusty(object):
if (variable.type != "IDENTIFIER") or (not variable.t_crusty):
return
if variable.status == crusty.STATUS_UNINITIALIZED:
self._add_error(self.MSG_WARNING,_("Using uninitialized variable {:s} at line {:d}").format(variable.name,line_number))
self._add_error(self.MSG_ERROR,_("Using uninitialized variable {:s} at line {:d}").format(variable.name,line_number))
return
if variable.status == crusty.STATUS_FREED:
self._add_error(self.MSG_WARNING,_("Using variable {:s} at line {:d}, after being freed at line {:d}").format(variable.name,line_number,variable.line))
self._add_error(self.MSG_ERROR,_("Using variable {:s} at line {:d}, after being freed at line {:d}").format(variable.name,line_number,variable.line))
return
......@@ -329,21 +332,21 @@ class crusty(object):
if node.pointer == 0:
if is_parameter:
if node.name is None:
self._add_error(self.MSG_ERROR,_("A parameter is defined as __crust_t__ type at line {:d}, but it is not a pointer").format(node.line))
self._add_error(self.MSG_CRITICAL,_("A parameter is defined as __crust_t__ type at line {:d}, but it is not a pointer").format(node.line))
else:
self._add_error(self.MSG_ERROR,_("Parameter {:s} defined as __crust_t__ type at line {:d}, but it is not a pointer").format(node.name,node.line))
self._add_error(self.MSG_CRITICAL,_("Parameter {:s} defined as __crust_t__ type at line {:d}, but it is not a pointer").format(node.name,node.line))
else:
self._add_error(self.MSG_ERROR,_("Variable {:s} is defined as __crust_t__ type at line {:d}, but it is not a pointer").format(node.name,node.line))
self._add_error(self.MSG_CRITICAL,_("Variable {:s} is defined as __crust_t__ type at line {:d}, but it is not a pointer").format(node.name,node.line))
retval += crusty.PROPERTY_CRUST_VARIABLE
if (node.t_crusty_borrow or node.t_crusty_recycle):
if not is_parameter:
self._add_error(self.MSG_ERROR,_("A variable can have only __crust_t__ as modifier (error at line {:d} with variable {:s})").format(node.line,node.name))
self._add_error(self.MSG_CRITICAL,_("A variable can have only __crust_t__ as modifier (error at line {:d} with variable {:s})").format(node.line,node.name))
if (node.t_crusty_borrow and node.t_crusty_recycle):
if is_parameter:
if node.name is None:
self._add_error(self.MSG_ERROR,_("A parameter can be BORROW or RECYCLE, not both. (error at line {:d})").format(node.line))
self._add_error(self.MSG_CRITICAL,_("A parameter can be BORROW or RECYCLE, not both. (error at line {:d})").format(node.line))
else:
self._add_error(self.MSG_ERROR,_("A parameter can be BORROW or RECYCLE, not both. (parameter {:s} at line {:d})").format(node.name,node.line))
self._add_error(self.MSG_CRITICAL,_("A parameter can be BORROW or RECYCLE, not both. (parameter {:s} at line {:d})").format(node.name,node.line))
if node.t_crusty_borrow:
retval += crusty.PROPERTY_BORROWED
if node.t_crusty_recycle:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment