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 ['==', '!=', '>', '>=', '<', '<='])
@ -48,6 +52,8 @@ def exp42(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)):

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

@ -19,6 +19,7 @@ for arg in sys.argv[1:]:
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')

View File

@ -7,9 +7,11 @@
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:

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()

View File

@ -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)]
@ -55,5 +58,3 @@ 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)]
@ -55,4 +58,3 @@ 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