2017-06-04 22:51:48 +02:00
|
|
|
#!/usr/bin/env python
|
2015-11-28 09:29:19 +01:00
|
|
|
#
|
|
|
|
# Locate casts in the code
|
|
|
|
#
|
|
|
|
|
|
|
|
import cppcheckdata
|
|
|
|
import sys
|
|
|
|
|
2017-06-04 22:51:48 +02:00
|
|
|
messages = set()
|
2015-11-28 09:29:19 +01:00
|
|
|
|
|
|
|
for arg in sys.argv[1:]:
|
|
|
|
print('Checking ' + arg + '...')
|
|
|
|
data = cppcheckdata.parsedump(arg)
|
|
|
|
|
2015-12-14 09:37:26 +01:00
|
|
|
for cfg in data.configurations:
|
|
|
|
if len(data.configurations) > 1:
|
|
|
|
print('Checking ' + arg + ', config "' + cfg.name + '"...')
|
|
|
|
for token in cfg.tokenlist:
|
|
|
|
if token.str != '(' or not token.astOperand1 or token.astOperand2:
|
|
|
|
continue
|
|
|
|
|
|
|
|
# we probably have a cast.. if there is something inside the parentheses
|
|
|
|
# there is a cast. Otherwise this is a function call.
|
|
|
|
typetok = token.next
|
|
|
|
if not typetok.isName:
|
|
|
|
continue
|
|
|
|
|
|
|
|
# cast number => skip output
|
|
|
|
if token.astOperand1.isNumber:
|
|
|
|
continue
|
|
|
|
|
|
|
|
# void cast => often used to suppress compiler warnings
|
|
|
|
if typetok.str == 'void':
|
|
|
|
continue
|
|
|
|
|
|
|
|
msg = '[' + token.file + ':' + str(
|
|
|
|
token.linenr) + '] (information) findcasts.py: found a cast\n'
|
2017-06-04 22:51:48 +02:00
|
|
|
if msg not in messages:
|
|
|
|
messages.add(msg)
|
2015-12-14 09:37:26 +01:00
|
|
|
sys.stderr.write(msg)
|