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

View File

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

View File

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

View File

@ -7,15 +7,17 @@
import cppcheckdata import cppcheckdata
import sys import sys
def reportError(token, severity, msg): 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): def checkstatic(data):
for var in data.variables: for var in data.variables:
if var.isStatic==True and var.isLocal==True and var.isClass==True: if var.isStatic == True and var.isLocal == True and var.isClass == True:
reportError(var.typeStartToken, 'warning', 'Local static object') reportError(var.typeStartToken, 'warning', 'Local static object')
for arg in sys.argv[1:]: for arg in sys.argv[1:]:
print('Checking ' + arg + '...') print('Checking ' + arg + '...')
data = cppcheckdata.parsedump(arg) data = cppcheckdata.parsedump(arg)
checkstatic(data) checkstatic(data)

View File

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

View File

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

View File

@ -68,4 +68,3 @@ $ make reduce
### * tools/times.sh ### * tools/times.sh
Script to generate a `times.log` file that contains timing information of the last 20 revisions. 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] PASSWORD = sys.argv[1]
# Upload file to sourceforge web server using scp # Upload file to sourceforge web server using scp
def upload(file_to_upload, destination): def upload(file_to_upload, destination):
if not os.path.isfile(file_to_upload): if not os.path.isfile(file_to_upload):
return return
@ -29,6 +31,7 @@ def upload(file_to_upload, destination):
except pexpect.TIMEOUT: except pexpect.TIMEOUT:
pass pass
def daca2(foldernum): def daca2(foldernum):
folders = '0123456789abcdefghijklmnopqrstuvwxyz' folders = '0123456789abcdefghijklmnopqrstuvwxyz'
folder = folders[foldernum % len(folders)] 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(['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]) 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]) 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 foldernum = 0
while True: while True:
daca2(foldernum) daca2(foldernum)
foldernum = foldernum + 1 foldernum = foldernum + 1

View File

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

View File

@ -137,7 +137,8 @@ class MatchCompilerTest(unittest.TestCase):
def test_parseStringComparison(self): def test_parseStringComparison(self):
input = 'str == "abc"' 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(2, len(res))
self.assertEqual('str == MatchCompiler::makeConstString("abc")', input[:res[0]] + "MatchCompiler::makeConstString(" + input[res[0]:res[1]] + ")" + input[res[1]:]) 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 checkout master
git branch -D "$i" git branch -D "$i"
done done