PEP8 fixes.

[ci skip]
This commit is contained in:
XhmikosR 2015-08-21 11:55:19 +03:00
parent 873861df4a
commit 7d0075357e
11 changed files with 93 additions and 78 deletions

View File

@ -11,17 +11,21 @@
import cppcheckdata
import sys
def reportError(token, severity, msg):
sys.stderr.write('[' + token.file + ':' + str(token.linenr) + '] (' + severity + ') cert.py: ' + msg + '\n')
sys.stderr.write('[' + token.file + ':' + str(token.linenr) + '] (' + severity + ') cert.py: ' + msg + '\n')
def isLocalStruct(arg):
if arg and arg.str == '&' and not arg.astOperand2:
arg = arg.astOperand1
return arg and arg.variable and arg.variable.isClass and (arg.variable.isLocal or arg.variable.isArgument)
def isBitwiseOp(token):
return token and (token.str in ['&', '|', '^'])
def isComparisonOp(token):
return token and (token.str in ['==', '!=', '>', '>=', '<', '<='])
@ -42,19 +46,21 @@ def exp42(data):
if token.astOperand1.str == 'memcmp' and (isLocalStruct(arg1) or isLocalStruct(arg2)):
reportError(token, 'style', 'EXP42-C Comparison of struct padding data')
if (token.astOperand1.str in ['memcpy','memmove']) and isLocalStruct(arg2):
if (token.astOperand1.str in ['memcpy', 'memmove']) and isLocalStruct(arg2):
reportError(token, 'style', 'EXP42-C Reading struct padding data')
# EXP46-C
# Do not use a bitwise operator with a Boolean-like operand
# int x = (a == b) & c;
def exp46(data):
for token in data.tokenlist:
if isBitwiseOp(token) and (isComparisonOp(token.astOperand1) or isComparisonOp(token.astOperand2)):
reportError(token, 'style', 'EXP46-C Bitwise operator is used with a Boolean-like operand')
for arg in sys.argv[1:]:
print('Checking ' + arg + '...')
data = cppcheckdata.parsedump(arg)
exp42(data)
exp46(data)
print('Checking ' + arg + '...')
data = cppcheckdata.parsedump(arg)
exp42(data)
exp46(data)

View File

@ -3,72 +3,75 @@
import xml.etree.ElementTree as ET
## Token class. Contains information about each token in the source code.
# Token class. Contains information about each token in the source code.
class Token:
Id = None
## Token string
# Token string
str = None
## Next token in tokenlist. For last token, next is None.
# Next token in tokenlist. For last token, next is None.
next = None
## Previous token in tokenlist. For first token, previous is None,
# Previous token in tokenlist. For first token, previous is None,
previous = None
linkId = None
## Linked token in tokenlist. Each '(', '[' and '{' are linked to the
# Linked token in tokenlist. Each '(', '[' and '{' are linked to the
# corresponding '}', ']' and ')'. For templates, the '<' is linked to
# the corresponding '>'.
link = None
scopeId = None
## Scope information for this token. See the Scope class.
# Scope information for this token. See the Scope class.
scope = None
## Is this token a symbol name
# Is this token a symbol name
isName = False
## Is this token a number, for example 123, 12.34
# Is this token a number, for example 123, 12.34
isNumber = False
## Is this token a int value such as 1234
# Is this token a int value such as 1234
isInt = False
## Is this token a int value such as 12.34
# Is this token a int value such as 12.34
isFloat = False
## Is this token a string literal such as "hello"
# Is this token a string literal such as "hello"
isString = False
## string length for string literal
# string length for string literal
strlen = None
## Is this token a char literal such as 'x'
# Is this token a char literal such as 'x'
isChar = False
## Is this token a operator
# Is this token a operator
isOp = False
## Is this token a arithmetic operator
# Is this token a arithmetic operator
isArithmeticalOp = False
## Is this token a assignment operator
# Is this token a assignment operator
isAssignmentOp = False
## Is this token a comparison operator
# Is this token a comparison operator
isComparisonOp = False
## Is this token a logical operator: && ||
# Is this token a logical operator: && ||
isLogicalOp = False
## varId for token, each variable has a unique non-zero id
# varId for token, each variable has a unique non-zero id
varId = None
variableId = None
## Variable information for this token. See the Variable class.
# Variable information for this token. See the Variable class.
variable = None
functionId = None
## If this token points at a function call, this attribute has the Function information. See the Function class.
# If this token points at a function call, this attribute has the Function
# information. See the Function class.
function = None
valuesId = None
## Possible values of token
# Possible values of token
values = None
astParentId = None
## syntax tree parent
# syntax tree parent
astParent = None
astOperand1Id = None
## syntax tree operand1
# syntax tree operand1
astOperand1 = None
astOperand2Id = None
## syntax tree operand2
# syntax tree operand2
astOperand2 = None
## file name
# file name
file = None
## line number
# line number
linenr = None
def __init__(self, element):
@ -189,6 +192,7 @@ class Function:
self.argument[argnr] = IdMap[argid]
self.tokenDef = IdMap[self.tokenDefId]
class Variable:
Id = None
nameTokenId = None

View File

@ -14,27 +14,28 @@ import re
RE_VARNAME = None
RE_FUNCTIONNAME = None
for arg in sys.argv[1:]:
if arg[:6]=='--var=':
RE_VARNAME = arg[6:]
elif arg[:11]=='--function=':
RE_FUNCTIONNAME = arg[11:]
if arg[:6] == '--var=':
RE_VARNAME = arg[6:]
elif arg[:11] == '--function=':
RE_FUNCTIONNAME = arg[11:]
def reportError(token, severity, msg):
sys.stderr.write('[' + token.file + ':' + str(token.linenr) + '] (' + severity + ') naming.py: ' + msg + '\n')
sys.stderr.write('[' + token.file + ':' + str(token.linenr) + '] (' + severity + ') naming.py: ' + msg + '\n')
for arg in sys.argv[1:]:
if not arg[-5:]=='.dump':
continue
print('Checking ' + arg + '...')
data = cppcheckdata.parsedump(arg)
if RE_VARNAME:
for var in data.variables:
res = re.match(RE_VARNAME, var.nameToken.str)
if not res:
reportError(var.typeStartToken, 'style', 'Variable ' + var.nameToken.str + ' violates naming convention')
if RE_FUNCTIONNAME:
for scope in data.scopes:
if scope.type == 'Function':
res = re.match(RE_FUNCTIONNAME, scope.className)
if not res:
reportError(scope.classStart, 'style', 'Function ' + scope.className + ' violates naming convention')
if not arg[-5:] == '.dump':
continue
print('Checking ' + arg + '...')
data = cppcheckdata.parsedump(arg)
if RE_VARNAME:
for var in data.variables:
res = re.match(RE_VARNAME, var.nameToken.str)
if not res:
reportError(var.typeStartToken, 'style', 'Variable ' + var.nameToken.str + ' violates naming convention')
if RE_FUNCTIONNAME:
for scope in data.scopes:
if scope.type == 'Function':
res = re.match(RE_FUNCTIONNAME, scope.className)
if not res:
reportError(scope.classStart, 'style', 'Function ' + scope.className + ' violates naming convention')

View File

@ -7,15 +7,17 @@
import cppcheckdata
import sys
def reportError(token, severity, msg):
sys.stderr.write('[' + token.file + ':' + str(token.linenr) + '] (' + severity + ') threadsafety.py: ' + msg + '\n')
sys.stderr.write('[' + token.file + ':' + str(token.linenr) + '] (' + severity + ') threadsafety.py: ' + msg + '\n')
def checkstatic(data):
for var in data.variables:
if var.isStatic==True and var.isLocal==True and var.isClass==True:
reportError(var.typeStartToken, 'warning', 'Local static object')
for var in data.variables:
if var.isStatic == True and var.isLocal == True and var.isClass == True:
reportError(var.typeStartToken, 'warning', 'Local static object')
for arg in sys.argv[1:]:
print('Checking ' + arg + '...')
data = cppcheckdata.parsedump(arg)
checkstatic(data)
print('Checking ' + arg + '...')
data = cppcheckdata.parsedump(arg)
checkstatic(data)

View File

@ -120,6 +120,7 @@ def removeLargeFiles(path):
if path.find('/clang/INPUTS/') > 0 or statinfo.st_size > 100000:
os.remove(g)
def dumpfiles(path):
ret = []
for g in glob.glob(path + '*'):
@ -132,6 +133,7 @@ def dumpfiles(path):
ret.append(g)
return ret
def scanarchive(filepath, jobs):
# remove all files/folders except results.txt
removeAllExceptResults()
@ -199,8 +201,8 @@ def scanarchive(filepath, jobs):
'python',
addon,
dumpfile],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
comm = p2.communicate()
results.write(comm[1])
results.close()

View File

@ -274,7 +274,7 @@ class MatchCompiler:
elif line[pos] == '"':
inString = True
pos += 1
return inString
return inString
def _parseStringComparison(self, line, pos1):
startPos = 0
@ -650,7 +650,7 @@ def main():
help='verify compiled matches against on-the-fly parser. Slow!')
parser.add_argument('--show-skipped', action='store_true', default=False,
help='show skipped (non-static) patterns')
parser.add_argument('--read-dir', default="lib",
parser.add_argument('--read-dir', default="lib",
help='directory from which files are read')
parser.add_argument('--write-dir', default="build",
help='directory into which files are written')
@ -683,7 +683,7 @@ def main():
if not files:
# select all *.cpp files in lib_dir
for f in glob.glob(lib_dir + '/*.cpp'):
files.append(f[len(lib_dir)+1:])
files.append(f[len(lib_dir) + 1:])
# convert files
for fi in files:
@ -695,4 +695,3 @@ def main():
if __name__ == '__main__':
main()

View File

@ -68,4 +68,3 @@ $ make reduce
### * tools/times.sh
Script to generate a `times.log` file that contains timing information of the last 20 revisions.

View File

@ -12,6 +12,8 @@ if len(sys.argv) == 2:
PASSWORD = sys.argv[1]
# Upload file to sourceforge web server using scp
def upload(file_to_upload, destination):
if not os.path.isfile(file_to_upload):
return
@ -29,6 +31,7 @@ def upload(file_to_upload, destination):
except pexpect.TIMEOUT:
pass
def daca2(foldernum):
folders = '0123456789abcdefghijklmnopqrstuvwxyz'
folder = folders[foldernum % len(folders)]
@ -47,13 +50,11 @@ def daca2(foldernum):
subprocess.call(['mv', 'cppcheck', os.path.expanduser('~/daca2-addons/cppcheck-O2')])
subprocess.call(['nice', '--adjustment=19', 'python', os.path.expanduser('~/cppcheck/tools/daca2-addons.py'), folder, '--rev=' + rev])
upload(os.path.expanduser('~/daca2-addons/'+folder+'/results.txt'), 'evidente/addons-'+folder+'.txt')
upload(os.path.expanduser('~/daca2-addons/' + folder + '/results.txt'), 'evidente/addons-' + folder + '.txt')
subprocess.call(['nice', '--adjustment=19', 'python', os.path.expanduser('~/cppcheck/tools/daca2-addons.py'), 'lib' + folder, '--rev=' + rev])
upload(os.path.expanduser('~/daca2-addons/lib'+folder+'/results.txt'), 'evidente/addons-lib'+folder+'.txt')
upload(os.path.expanduser('~/daca2-addons/lib' + folder + '/results.txt'), 'evidente/addons-lib' + folder + '.txt')
foldernum = 0
while True:
daca2(foldernum)
foldernum = foldernum + 1

View File

@ -12,6 +12,8 @@ if len(sys.argv) == 2:
PASSWORD = sys.argv[1]
# Upload file to sourceforge web server using scp
def upload(file_to_upload, destination):
if not os.path.isfile(file_to_upload):
return
@ -29,6 +31,7 @@ def upload(file_to_upload, destination):
except pexpect.TIMEOUT:
pass
def daca2(foldernum):
folders = '0123456789abcdefghijklmnopqrstuvwxyz'
folder = folders[foldernum % len(folders)]
@ -47,12 +50,11 @@ def daca2(foldernum):
subprocess.call(['mv', 'cppcheck', os.path.expanduser('~/daca2/cppcheck-O2')])
subprocess.call(['nice', '--adjustment=19', 'python', os.path.expanduser('~/cppcheck/tools/daca2.py'), folder, '--rev=' + rev])
upload(os.path.expanduser('~/daca2/'+folder+'/results.txt'), 'evidente/results-'+folder+'.txt')
upload(os.path.expanduser('~/daca2/' + folder + '/results.txt'), 'evidente/results-' + folder + '.txt')
subprocess.call(['nice', '--adjustment=19', 'python', os.path.expanduser('~/cppcheck/tools/daca2.py'), 'lib' + folder, '--rev=' + rev])
upload(os.path.expanduser('~/daca2/lib'+folder+'/results.txt'), 'evidente/results-lib'+folder+'.txt')
upload(os.path.expanduser('~/daca2/lib' + folder + '/results.txt'), 'evidente/results-lib' + folder + '.txt')
foldernum = 0
while True:
daca2(foldernum)
foldernum = foldernum + 1

View File

@ -137,7 +137,8 @@ class MatchCompilerTest(unittest.TestCase):
def test_parseStringComparison(self):
input = 'str == "abc"'
res = self.mc._parseStringComparison(input, 5) # offset '5' is chosen as an abritary start offset to look for "
# offset '5' is chosen as an abritary start offset to look for
res = self.mc._parseStringComparison(input, 5)
self.assertEqual(2, len(res))
self.assertEqual('str == MatchCompiler::makeConstString("abc")', input[:res[0]] + "MatchCompiler::makeConstString(" + input[res[0]:res[1]] + ")" + input[res[1]:])

View File

@ -21,5 +21,3 @@ do
git checkout master
git branch -D "$i"
done