2019-11-15 21:38:20 +01:00
|
|
|
#!/usr/bin/env python3
|
2015-11-28 09:29:19 +01:00
|
|
|
#
|
|
|
|
# Locate casts in the code
|
|
|
|
#
|
|
|
|
|
2019-12-30 17:30:17 +01:00
|
|
|
import cppcheckdata
|
2015-11-28 09:29:19 +01:00
|
|
|
import sys
|
|
|
|
|
|
|
|
for arg in sys.argv[1:]:
|
2019-04-10 18:29:46 +02:00
|
|
|
if arg.startswith('-'):
|
|
|
|
continue
|
|
|
|
|
2019-12-27 08:50:56 +01:00
|
|
|
print('Checking %s...' % arg)
|
|
|
|
data = cppcheckdata.CppcheckData(arg)
|
2015-11-28 09:29:19 +01:00
|
|
|
|
2019-12-27 08:50:56 +01:00
|
|
|
for cfg in data.iterconfigurations():
|
|
|
|
print('Checking %s, config %s...' % (arg, cfg.name))
|
2015-12-14 09:37:26 +01:00
|
|
|
for token in cfg.tokenlist:
|
|
|
|
if token.str != '(' or not token.astOperand1 or token.astOperand2:
|
|
|
|
continue
|
|
|
|
|
2019-04-10 18:29:46 +02:00
|
|
|
# Is it a lambda?
|
|
|
|
if token.astOperand1.str == '{':
|
|
|
|
continue
|
|
|
|
|
2015-12-14 09:37:26 +01:00
|
|
|
# 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
|
|
|
|
|
2019-04-14 08:54:53 +02:00
|
|
|
cppcheckdata.reportError(token, 'information', 'found a cast', 'findcasts', 'cast')
|
2020-08-29 07:44:13 +02:00
|
|
|
|
|
|
|
sys.exit(cppcheckdata.EXIT_CODE)
|