[Libreoffice-commits] core.git: compilerplugins/clang

Noel Grandin noel.grandin at collabora.co.uk
Thu Sep 15 06:52:58 UTC 2016


 compilerplugins/clang/countusersofdefaultparams.py |    7 +---
 compilerplugins/clang/mergeclasses.py              |   24 ++++++--------
 compilerplugins/clang/singlevalfields.py           |   23 +++++--------
 compilerplugins/clang/unnecessaryvirtual.py        |   13 +++----
 compilerplugins/clang/unuseddefaultparams.py       |   21 +++++-------
 compilerplugins/clang/unusedfields.py              |   21 +++++-------
 compilerplugins/clang/unusedmethods.py             |   35 +++++++++------------
 7 files changed, 60 insertions(+), 84 deletions(-)

New commits:
commit c3c4ae5fdac0341f01eeed8d5c633d203eed8b2a
Author: Noel Grandin <noel.grandin at collabora.co.uk>
Date:   Thu Sep 15 08:49:53 2016 +0200

    use split() to simplify loplugin python code
    
    Change-Id: Ib6d7acf54ca6c12a3b096435f8a621244df88b4f

diff --git a/compilerplugins/clang/countusersofdefaultparams.py b/compilerplugins/clang/countusersofdefaultparams.py
index 06db0df..1930eee 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 23a15f62..fc2aaa2 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 f3d9c70a..47c4c0d 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 cd56137..ee7d9ec 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 45ef27e..98d0266a 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 055fd37..c3b5145 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 3d3ffb1..6f67944 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.


More information about the Libreoffice-commits mailing list