Commit 931b8d94 authored by Vitja Makarov's avatar Vitja Makarov

Move message reporting to MessageCollection

parent 8df60525
...@@ -394,20 +394,24 @@ class GV(object): ...@@ -394,20 +394,24 @@ class GV(object):
fp.write(' }\n') fp.write(' }\n')
class MessageCollection(list): class MessageCollection:
"""Collect error/warnings messages first then sort""" """Collect error/warnings messages first then sort"""
def __init__(self):
self.messages = []
def error(self, pos, message): def error(self, pos, message):
self.append((pos, True, message)) self.messages.append((pos, True, message))
def warning(self, pos, message): def warning(self, pos, message):
self.append((pos, False, message)) self.messages.append((pos, False, message))
def _key(self, item):
return item[0]
def sort(self): def report(self):
list.sort(self, key=self._key) self.messages.sort()
for pos, is_error, message in self.messages:
if is_error:
error(pos, message)
else:
warning(pos, message, 2)
def check_definitions(flow, compiler_directives): def check_definitions(flow, compiler_directives):
...@@ -524,13 +528,7 @@ def check_definitions(flow, compiler_directives): ...@@ -524,13 +528,7 @@ def check_definitions(flow, compiler_directives):
messages.warning(entry.pos, "Unused entry '%s'" % entry.name) messages.warning(entry.pos, "Unused entry '%s'" % entry.name)
entry.cf_used = False entry.cf_used = False
# Sort warnings by position messages.report()
messages.sort()
for pos, is_error, message in messages:
if is_error:
error(pos, message)
else:
warning(pos, message, 2)
class AssignmentCollector(TreeVisitor): class AssignmentCollector(TreeVisitor):
......
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