Skip to content

Commit b23cce9

Browse files
committed
Adding static check for work library (fixes #20)
1 parent 6c9834b commit b23cce9

File tree

1 file changed

+25
-4
lines changed

1 file changed

+25
-4
lines changed

hdlcc/static_check.py

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
import re
2020
import logging
2121

22-
__logger__ = logging.getLogger(__name__)
22+
_logger = logging.getLogger(__name__)
2323

2424
_GET_SCOPE = re.compile('|'.join([
2525
r"^\s*entity\s+(?P<entity_name>\w+)\s+is\b",
@@ -128,8 +128,7 @@ def _getUnusedObjects(vbuffer, objects):
128128
yield _object
129129

130130
__COMMENT_TAG_SCANNER__ = re.compile('|'.join([
131-
r"\s*--\s*(?P<tag>TODO|FIXME|XXX)\s*:\s*(?P<text>.*)",
132-
]))
131+
r"\s*--\s*(?P<tag>TODO|FIXME|XXX)\s*:\s*(?P<text>.*)"]))
133132

134133
def _getCommentTags(vbuffer):
135134
result = []
@@ -160,6 +159,28 @@ def _getCommentTags(vbuffer):
160159
result += [message]
161160
return result
162161

162+
def _getMiscChecks(objects):
163+
"""
164+
Get generic code hints (or it should do that sometime in the future...)
165+
"""
166+
if 'library' not in [x['type'] for x in objects.values()]:
167+
raise StopIteration
168+
169+
for library, obj in objects.items():
170+
if obj['type'] != 'library':
171+
continue
172+
if library == 'work':
173+
yield {
174+
'checker' : 'HDL Code Checker/static',
175+
'line_number' : obj['lnum'] + 1,
176+
'column' : obj['start'] + 1,
177+
'filename' : None,
178+
'error_number' : '0',
179+
'error_type' : 'W',
180+
'error_subtype' : 'Style',
181+
'error_message' : "Declaration of library '{library}' can "
182+
"be omitted".format(library=library)}
183+
163184
def getStaticMessages(vbuffer=None):
164185
"VHDL static checking"
165186
objects = _getObjectsFromText(vbuffer)
@@ -181,7 +202,7 @@ def getStaticMessages(vbuffer=None):
181202
}
182203

183204
result.append(message)
184-
return result + _getCommentTags(vbuffer)
205+
return result + _getCommentTags(vbuffer) + list(_getMiscChecks(objects))
185206

186207
def standalone(): # pragma: no cover
187208
import sys

0 commit comments

Comments
 (0)