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
|
|
|
|
#
|
|
|
|
|
2021-08-12 20:17:51 +02:00
|
|
|
import cppcheck
|
2015-11-28 09:29:19 +01:00
|
|
|
|
2021-08-12 20:17:51 +02:00
|
|
|
@cppcheck.checker
|
|
|
|
def cast(cfg, data):
|
|
|
|
for token in cfg.tokenlist:
|
|
|
|
if token.str != '(' or not token.astOperand1 or token.astOperand2:
|
|
|
|
continue
|
2019-04-10 18:29:46 +02:00
|
|
|
|
2021-08-12 20:17:51 +02:00
|
|
|
# Is it a lambda?
|
|
|
|
if token.astOperand1.str == '{':
|
|
|
|
continue
|
2015-11-28 09:29:19 +01:00
|
|
|
|
2021-08-12 20:17:51 +02: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
|
2015-12-14 09:37:26 +01:00
|
|
|
|
2021-08-12 20:17:51 +02:00
|
|
|
# cast number => skip output
|
|
|
|
if token.astOperand1.isNumber:
|
|
|
|
continue
|
2019-04-10 18:29:46 +02:00
|
|
|
|
2021-08-12 20:17:51 +02:00
|
|
|
# void cast => often used to suppress compiler warnings
|
|
|
|
if typetok.str == 'void':
|
|
|
|
continue
|
2015-12-14 09:37:26 +01:00
|
|
|
|
2021-08-12 20:17:51 +02:00
|
|
|
cppcheck.reportError(token, 'information', 'found a cast')
|