addons: Added an addon that locates casts.

This commit is contained in:
Daniel Marjamäki 2015-11-28 09:29:19 +01:00
parent 8689693d6c
commit 5d1307814b
1 changed files with 36 additions and 0 deletions

36
addons/findcasts.py Normal file
View File

@ -0,0 +1,36 @@
#/usr/bin/python
#
# Locate casts in the code
#
import cppcheckdata
import sys
messages = []
for arg in sys.argv[1:]:
print('Checking ' + arg + '...')
data = cppcheckdata.parsedump(arg)
for token in data.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'
if not msg in messages:
messages.append(msg)
sys.stderr.write(msg)