summaryrefslogtreecommitdiff
path: root/compilerplugins
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2016-09-15 08:49:53 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2016-09-15 08:51:14 +0200
commitc3c4ae5fdac0341f01eeed8d5c633d203eed8b2a (patch)
tree8fee07cdabdb5fb8e1597a88983c79bd8512ae3c /compilerplugins
parent6df2c90c08b67b943022286e7152b51d52e0ef5e (diff)
use split() to simplify loplugin python code
Change-Id: Ib6d7acf54ca6c12a3b096435f8a621244df88b4f
Diffstat (limited to 'compilerplugins')
-rwxr-xr-xcompilerplugins/clang/countusersofdefaultparams.py7
-rwxr-xr-xcompilerplugins/clang/mergeclasses.py24
-rwxr-xr-xcompilerplugins/clang/singlevalfields.py23
-rwxr-xr-xcompilerplugins/clang/unnecessaryvirtual.py13
-rwxr-xr-xcompilerplugins/clang/unuseddefaultparams.py21
-rwxr-xr-xcompilerplugins/clang/unusedfields.py21
-rwxr-xr-xcompilerplugins/clang/unusedmethods.py35
7 files changed, 60 insertions, 84 deletions
diff --git a/compilerplugins/clang/countusersofdefaultparams.py b/compilerplugins/clang/countusersofdefaultparams.py
index 06db0df837d5..1930eeebf108 100755
--- a/compilerplugins/clang/countusersofdefaultparams.py
+++ b/compilerplugins/clang/countusersofdefaultparams.py
@@ -17,8 +17,8 @@ def normalizeTypeParams( line ):
# I have not yet found a way of suppressing the gbuild output.
with io.open("loplugin.countusersofdefaultparams.log", "rb", buffering=1024*1024) as txt:
for line in txt:
- if line.startswith("defn:\t"):
- tokens = line.strip().split("\t")
+ tokens = line.strip().split("\t")
+ if tokens[0] == "defn:":
access = tokens[1]
returnType = tokens[2]
nameAndParams = tokens[3]
@@ -27,8 +27,7 @@ with io.open("loplugin.countusersofdefaultparams.log", "rb", buffering=1024*1024
definitionToSourceLocationMap[funcInfo] = sourceLocation
if not funcInfo in callDict:
callDict[funcInfo] = set()
- elif line.startswith("call:\t"):
- tokens = line.strip().split("\t")
+ elif tokens[0] == "call:":
returnType = tokens[1]
nameAndParams = tokens[2]
sourceLocationOfCall = tokens[3]
diff --git a/compilerplugins/clang/mergeclasses.py b/compilerplugins/clang/mergeclasses.py
index 23a15f62af66..fc2aaa25beca 100755
--- a/compilerplugins/clang/mergeclasses.py
+++ b/compilerplugins/clang/mergeclasses.py
@@ -9,10 +9,10 @@ definitionToFileDict = {}
with open("loplugin.mergeclasses.log") as txt:
for line in txt:
+ tokens = line.strip().split("\t")
- if line.startswith("instantiated:\t"):
- idx1 = line.find("\t")
- clazzName = line[idx1+1 : len(line)-1]
+ if tokens[0] == "instantiated:":
+ clazzName = tokens[1]
if (clazzName.startswith("const ")):
clazzName = clazzName[6:]
if (clazzName.startswith("class ")):
@@ -21,20 +21,16 @@ with open("loplugin.mergeclasses.log") as txt:
clazzName = clazzName[:len(clazzName)-3]
instantiatedSet.add(clazzName)
- elif line.startswith("definition:\t"):
- idx1 = line.find("\t")
- idx2 = line.find("\t", idx1+1)
- clazzName = line[idx1+1 : idx2]
- # the +2 is so we skip the leading /
- fileName = line[idx2+2 : len(line)-1]
+ elif tokens[0] == "definition:":
+ clazzName = tokens[1]
+ # the 1.. is so we skip the leading /
+ fileName = tokens[1][1..]
definitionSet.add(clazzName)
definitionToFileDict[clazzName] = fileName
- elif line.startswith("has-subclass:\t"):
- idx1 = line.find("\t")
- idx2 = line.find("\t", idx1+1)
- child = line[idx1+1 : idx2]
- parent = line[idx2+1 : len(line)-1]
+ elif tokens[0] == "has-subclass:":
+ child = tokens[1]
+ parent = tokens[2]
if (parent.startswith("class ")):
parent = parent[6:]
elif (parent.startswith("struct ")):
diff --git a/compilerplugins/clang/singlevalfields.py b/compilerplugins/clang/singlevalfields.py
index f3d9c70a77e3..47c4c0d806c1 100755
--- a/compilerplugins/clang/singlevalfields.py
+++ b/compilerplugins/clang/singlevalfields.py
@@ -16,22 +16,17 @@ def normalizeTypeParams( line ):
# reading as binary (since we known it is pure ascii) is much faster than reading as unicode
with io.open("loplugin.singlevalfields.log", "rb", buffering=1024*1024) as txt:
for line in txt:
- if line.startswith("defn:\t"):
- idx1 = line.find("\t")
- idx2 = line.find("\t",idx1+1)
- idx3 = line.find("\t",idx2+1)
- parentClass = normalizeTypeParams(line[idx1+1:idx2])
- fieldName = normalizeTypeParams(line[idx2+1:idx3])
- sourceLocation = line[idx3+1:].strip()
+ tokens = line.strip().split("\t")
+ if tokens[0] == "defn:":
+ parentClass = normalizeTypeParams(tokens[1])
+ fieldName = normalizeTypeParams(tokens[2])
+ sourceLocation = tokens[3]
fieldInfo = (parentClass, fieldName)
definitionToSourceLocationMap[fieldInfo] = sourceLocation
- elif line.startswith("asgn:\t"):
- idx1 = line.find("\t")
- idx2 = line.find("\t",idx1+1)
- idx3 = line.find("\t",idx2+1)
- parentClass = normalizeTypeParams(line[idx1+1:idx2])
- fieldName = normalizeTypeParams(line[idx2+1:idx3])
- assignValue = line[idx3+1:].strip()
+ elif tokens[0] == "asgn:":
+ parentClass = normalizeTypeParams(tokens[1])
+ fieldName = normalizeTypeParams(tokens[2])
+ assignValue = tokens[3]
fieldInfo = (parentClass, fieldName)
if not fieldInfo in fieldAssignDict:
fieldAssignDict[fieldInfo] = set()
diff --git a/compilerplugins/clang/unnecessaryvirtual.py b/compilerplugins/clang/unnecessaryvirtual.py
index cd5613771244..ee7d9ec928af 100755
--- a/compilerplugins/clang/unnecessaryvirtual.py
+++ b/compilerplugins/clang/unnecessaryvirtual.py
@@ -9,15 +9,12 @@ overridingSet = set()
with io.open("loplugin.unnecessaryvirtual.log", "rb", buffering=1024*1024) as txt:
for line in txt:
-
- if line.startswith("definition:\t"):
- idx1 = line.find("\t")
- clazzName = line[idx1+1 : len(line)-1]
+ tokens = line.strip().split("\t")
+ if tokens[0] == "definition:":
+ clazzName = tokens[1]
definitionSet.add(clazzName)
-
- elif line.startswith("overriding:\t"):
- idx1 = line.find("\t")
- clazzName = line[idx1+1 : len(line)-1]
+ elif tokens[0] == "overriding:":
+ clazzName = tokens[1]
overridingSet.add(clazzName)
with open("loplugin.unnecessaryvirtual.report", "wt") as f:
diff --git a/compilerplugins/clang/unuseddefaultparams.py b/compilerplugins/clang/unuseddefaultparams.py
index 45ef27e47669..98d0266a4b57 100755
--- a/compilerplugins/clang/unuseddefaultparams.py
+++ b/compilerplugins/clang/unuseddefaultparams.py
@@ -18,21 +18,18 @@ def normalizeTypeParams( line ):
# I have not yet found a way of suppressing the gbuild output.
with io.open("loplugin.unuseddefaultparams.log", "rb", buffering=1024*1024) as txt:
for line in txt:
- if line.startswith("defn:\t"):
- idx1 = line.find("\t",6)
- idx2 = line.find("\t",idx1+1)
- idx3 = line.find("\t",idx2+1)
- access = line[6:idx1]
- returnType = line[idx1+1:idx2]
- nameAndParams = line[idx2+1:idx3]
- sourceLocation = line[idx3+1:].strip()
+ tokens = line.strip().split("\t")
+ if tokens[0] == "defn:":
+ access = tokens[1]
+ returnType = tokens[2]
+ nameAndParams = tokens[3]
+ sourceLocation = tokens[4]
funcInfo = (normalizeTypeParams(returnType), normalizeTypeParams(nameAndParams))
definitionSet.add(funcInfo)
definitionToSourceLocationMap[funcInfo] = sourceLocation
- elif line.startswith("call:\t"):
- idx1 = line.find("\t",6)
- returnType = line[6:idx1]
- nameAndParams = line[idx1+1:].strip()
+ elif tokens[0] == "call:":
+ returnType = tokens[1]
+ nameAndParams = tokens[2]
callSet.add((normalizeTypeParams(returnType), normalizeTypeParams(nameAndParams)))
# Invert the definitionToSourceLocationMap.
diff --git a/compilerplugins/clang/unusedfields.py b/compilerplugins/clang/unusedfields.py
index 055fd37a085b..c3b51457ff58 100755
--- a/compilerplugins/clang/unusedfields.py
+++ b/compilerplugins/clang/unusedfields.py
@@ -25,21 +25,18 @@ def normalizeTypeParams( line ):
# I have not yet found a way of suppressing the gbuild output.
with io.open("loplugin.unusedfields.log", "rb", buffering=1024*1024) as txt:
for line in txt:
- if line.startswith("definition:\t"):
- idx1 = line.find("\t",12)
- idx2 = line.find("\t",idx1+1)
- idx3 = line.find("\t",idx2+1)
- funcInfo = (normalizeTypeParams(line[12:idx1]), line[idx1+1:idx2])
+ tokens = line.strip().split("\t")
+ if tokens[0] == "definition:":
+ funcInfo = (normalizeTypeParams(tokens[1]), tokens[2])
definitionSet.add(funcInfo)
- definitionToTypeMap[funcInfo] = line[idx2+1:idx3].strip()
- definitionToSourceLocationMap[funcInfo] = line[idx3+1:].strip()
- elif line.startswith("touch:\t"):
- idx1 = line.find("\t",7)
- callInfo = (normalizeTypeParams(line[7:idx1]), line[idx1+1:].strip())
+ definitionToTypeMap[funcInfo] = tokens[3]
+ definitionToSourceLocationMap[funcInfo] = tokens[4]
+ elif tokens[0] == "touch:":
+ callInfo = (normalizeTypeParams(tokens[1]), tokens[2])
callSet.add(callInfo)
- elif line.startswith("read:\t"):
+ elif tokens[0] == "read:":
idx1 = line.find("\t",6)
- readInfo = (normalizeTypeParams(line[6:idx1]), line[idx1+1:].strip())
+ readInfo = (normalizeTypeParams(tokens[1]), tokens[2])
readFromSet.add(readInfo)
# Invert the definitionToSourceLocationMap
diff --git a/compilerplugins/clang/unusedmethods.py b/compilerplugins/clang/unusedmethods.py
index 3d3ffb13003b..6f679449172e 100755
--- a/compilerplugins/clang/unusedmethods.py
+++ b/compilerplugins/clang/unusedmethods.py
@@ -135,33 +135,28 @@ def normalizeTypeParams( line ):
# I have not yet found a way of suppressing the gbuild output.
with io.open("loplugin.unusedmethods.log", "rb", buffering=1024*1024) as txt:
for line in txt:
- if line.startswith("definition:\t"):
- idx1 = line.find("\t",12)
- idx2 = line.find("\t",idx1+1)
- idx3 = line.find("\t",idx2+1)
- access = line[12:idx1]
- returnType = line[idx1+1:idx2]
- nameAndParams = line[idx2+1:idx3]
- sourceLocation = line[idx3+1:].strip()
+ tokens = line.strip().split("\t")
+ if tokens[0] == "definition:":
+ access = tokens[1]
+ returnType = tokens[2]
+ nameAndParams = tokens[3]
+ sourceLocation = tokens[4]
funcInfo = (normalizeTypeParams(returnType), normalizeTypeParams(nameAndParams))
definitionSet.add(funcInfo)
if access == "public":
publicDefinitionSet.add(funcInfo)
definitionToSourceLocationMap[funcInfo] = sourceLocation
- elif line.startswith("call:\t"):
- idx1 = line.find("\t",6)
- returnType = line[6:idx1]
- nameAndParams = line[idx1+1:].strip()
+ elif tokens[0] == "call:":
+ returnType = tokens[1]
+ nameAndParams = tokens[2]
callSet.add((normalizeTypeParams(returnType), normalizeTypeParams(nameAndParams)))
- elif line.startswith("usedReturn:\t"):
- idx1 = line.find("\t",12)
- returnType = line[12:idx1]
- nameAndParams = line[idx1+1:].strip()
+ elif tokens[0] == "usedReturn:":
+ returnType = tokens[1]
+ nameAndParams = tokens[2]
usedReturnSet.add((normalizeTypeParams(returnType), normalizeTypeParams(nameAndParams)))
- elif line.startswith("calledFromOutsideSet:\t"):
- idx1 = line.find("\t",22)
- returnType = line[22:idx1]
- nameAndParams = line[idx1+1:].strip()
+ elif tokens[0] == "calledFromOutsideSet:":
+ returnType = tokens[1]
+ nameAndParams = tokens[2]
calledFromOutsideSet.add((normalizeTypeParams(returnType), normalizeTypeParams(nameAndParams)))
# Invert the definitionToSourceLocationMap.