Commit 7efecf35 authored by jklowden's avatar jklowden
Browse files

support -W additional warning-igore files

parent b9944858
......@@ -218,27 +218,54 @@ def cast_pair(node):
class_name(node.expr) + ':',
string_of(node))
def read_ignores( filename ):
ignoring = []
with open(filename) as f:
for input in f:
elements = input.split(':')
if len(elements) > 2:
output = ':'.join( elements[:2] )
ignoring.append(output)
#rint(output)
return ignoring
# Visitor for Cast nodes, to report where a cast is used.
class CastVisitor(c_ast.NodeVisitor):
ncast = 0
ignoring = ()
def __init__(self, ignoring):
self.ignoring = ignoring
def visit_Cast(self, node):
print( cast_pair(node) )
def show_casts(cpp, filename):
key = '%s:%d' % (node.coord.file, node.coord.line)
if not key in self.ignoring:
print( cast_pair(node) )
self.ncast += 1
else:
pass # print('%s: (ignored)' % key)
def show_casts(cpp, filename, ignoring):
cpp_args = re.split(r'\s{2,}', environ['CSCAN_FLAGS'])
assert( len(cpp_args) > 1 )
ast = parse_file(filename, use_cpp=True,
cpp_path=cpp,
cpp_args=cpp_args)
v = CastVisitor()
try:
ignoring += read_ignores('.cscan-ignore')
print( 'ignoring %d approved casts' % len(ignoring) )
except Exception as oops:
print(oops);
v = CastVisitor(ignoring)
v.visit(ast)
return v.ncast
if __name__ == "__main__":
cpp = 'cpp'
ignoring = []
try:
opts, args = getopt(sys.argv[1:], "E:v")
opts, args = getopt(sys.argv[1:], "E:W:v")
except getopt.GetoptError as err:
print(err)
exit(1)
......@@ -249,6 +276,8 @@ if __name__ == "__main__":
cpp = a
elif o == '-v':
verbose = True
elif o == '-W':
ignoring += read_ignores(a)
else:
assert False, "unhandled option"
......@@ -257,7 +286,9 @@ if __name__ == "__main__":
for filename in sys.argv[narg:]:
print( 'scanning "%s"' % filename )
try:
show_casts(cpp, filename)
exit_status = show_casts(cpp, filename, ignoring)
if exit_status > 0:
break
except CalledProcessError as erc:
print( '%s in %s' % (erc, getcwd()), file=sys.stderr )
exit(1)
......
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