From b23cce9938ea6723ed9969473f1c84c668f86bab Mon Sep 17 00:00:00 2001 From: suoto Date: Tue, 26 Jul 2016 23:00:10 -0300 Subject: [PATCH] Adding static check for work library (fixes #20) --- hdlcc/static_check.py | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/hdlcc/static_check.py b/hdlcc/static_check.py index c064a1e..4cdf120 100644 --- a/hdlcc/static_check.py +++ b/hdlcc/static_check.py @@ -19,7 +19,7 @@ import re import logging -__logger__ = logging.getLogger(__name__) +_logger = logging.getLogger(__name__) _GET_SCOPE = re.compile('|'.join([ r"^\s*entity\s+(?P\w+)\s+is\b", @@ -128,8 +128,7 @@ def _getUnusedObjects(vbuffer, objects): yield _object __COMMENT_TAG_SCANNER__ = re.compile('|'.join([ - r"\s*--\s*(?PTODO|FIXME|XXX)\s*:\s*(?P.*)", - ])) + r"\s*--\s*(?PTODO|FIXME|XXX)\s*:\s*(?P.*)"])) def _getCommentTags(vbuffer): result = [] @@ -160,6 +159,28 @@ def _getCommentTags(vbuffer): result += [message] return result +def _getMiscChecks(objects): + """ + Get generic code hints (or it should do that sometime in the future...) + """ + if 'library' not in [x['type'] for x in objects.values()]: + raise StopIteration + + for library, obj in objects.items(): + if obj['type'] != 'library': + continue + if library == 'work': + yield { + 'checker' : 'HDL Code Checker/static', + 'line_number' : obj['lnum'] + 1, + 'column' : obj['start'] + 1, + 'filename' : None, + 'error_number' : '0', + 'error_type' : 'W', + 'error_subtype' : 'Style', + 'error_message' : "Declaration of library '{library}' can " + "be omitted".format(library=library)} + def getStaticMessages(vbuffer=None): "VHDL static checking" objects = _getObjectsFromText(vbuffer) @@ -181,7 +202,7 @@ def getStaticMessages(vbuffer=None): } result.append(message) - return result + _getCommentTags(vbuffer) + return result + _getCommentTags(vbuffer) + list(_getMiscChecks(objects)) def standalone(): # pragma: no cover import sys