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

Noel (via logerrit) logerrit at kemper.freedesktop.org
Fri Nov 13 12:44:59 UTC 2020


 compilerplugins/clang/constantparam.py             |   14 +++++++++-----
 compilerplugins/clang/constfields.py               |    6 +++++-
 compilerplugins/clang/countusersofdefaultparams.py |    6 +++++-
 compilerplugins/clang/expandablemethods.py         |    8 ++++++--
 compilerplugins/clang/finalclasses.py              |   10 +++++++---
 compilerplugins/clang/inlinefields.py              |    6 +++++-
 compilerplugins/clang/methodcycles.py              |    8 ++++++--
 compilerplugins/clang/unnecessaryvirtual.py        |    8 ++++++--
 compilerplugins/clang/unusedmethods.py             |    8 ++++++--
 compilerplugins/clang/unusedvarsglobal.py          |   10 +++++++---
 compilerplugins/clang/virtualdead.py               |    8 ++++++--
 compilerplugins/clang/virtualdown.py               |    6 +++++-
 12 files changed, 73 insertions(+), 25 deletions(-)

New commits:
commit 95b2ee0070b1c885f18e620e1204da5fe978ad68
Author:     Noel <noelgrandin at gmail.com>
AuthorDate: Thu Nov 12 10:49:44 2020 +0200
Commit:     Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Fri Nov 13 13:44:12 2020 +0100

    improve sorting in global-analysis plugins
    
    Change-Id: I417f6d9fd6981bb402cd216a08db285cc9adeed0
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/105628
    Tested-by: Noel Grandin <noel.grandin at collabora.co.uk>
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/compilerplugins/clang/constantparam.py b/compilerplugins/clang/constantparam.py
index 1e2cbeee7e4b..9e1c7e74aa9b 100755
--- a/compilerplugins/clang/constantparam.py
+++ b/compilerplugins/clang/constantparam.py
@@ -97,10 +97,14 @@ for callInfo, callValues in iter(callDict.items()):
 def natural_sort_key(s, _nsre=re.compile('([0-9]+)')):
     return [int(text) if text.isdigit() else text.lower()
             for text in re.split(_nsre, s)]
-tmp1list.sort(key=lambda v: natural_sort_key(v[0]))
-tmp2list.sort(key=lambda v: natural_sort_key(v[0]))
-tmp3list.sort(key=lambda v: natural_sort_key(v[0]))
-tmp4list.sort(key=lambda v: natural_sort_key(v[0]))
+# sort by both the source-line and the datatype, so the output file ordering is stable
+# when we have multiple items on the same source line
+def v_sort_key(v):
+    return natural_sort_key(v[0]) + [v[1]]
+tmp1list.sort(key=lambda v: v_sort_key(v))
+tmp2list.sort(key=lambda v: v_sort_key(v))
+tmp3list.sort(key=lambda v: v_sort_key(v))
+tmp4list.sort(key=lambda v: v_sort_key(v))
 
 # print out the results
 with open("compilerplugins/clang/constantparam.booleans.results", "wt") as f:
@@ -184,7 +188,7 @@ for callInfo, callValues in iter(callDict.items()):
 
 
 # sort results by filename:lineno
-tmp2list.sort(key=lambda v: natural_sort_key(v[0]))
+tmp2list.sort(key=lambda v: v_sort_key(v))
 
 # print out the results
 with open("compilerplugins/clang/constantparam.bitmask.results", "wt") as f:
diff --git a/compilerplugins/clang/constfields.py b/compilerplugins/clang/constfields.py
index 980363f78eb9..e81d3f3043f5 100755
--- a/compilerplugins/clang/constfields.py
+++ b/compilerplugins/clang/constfields.py
@@ -70,9 +70,13 @@ for d in definitionSet:
 def natural_sort_key(s, _nsre=re.compile('([0-9]+)')):
     return [int(text) if text.isdigit() else text.lower()
             for text in re.split(_nsre, s)]
+# sort by both the source-line and the datatype, so the output file ordering is stable
+# when we have multiple items on the same source line
+def v_sort_key(v):
+    return natural_sort_key(v[1]) + [v[0]]
 
 # sort results by name and line number
-tmp6list = sorted(canBeConstFieldSet, key=lambda v: natural_sort_key(v[1]))
+tmp6list = sorted(canBeConstFieldSet, key=lambda v: v_sort_key(v))
 
 # print out the results
 with open("compilerplugins/clang/constfields.results", "wt") as f:
diff --git a/compilerplugins/clang/countusersofdefaultparams.py b/compilerplugins/clang/countusersofdefaultparams.py
index eabb7d5ef30e..57af9ea29caa 100755
--- a/compilerplugins/clang/countusersofdefaultparams.py
+++ b/compilerplugins/clang/countusersofdefaultparams.py
@@ -66,9 +66,13 @@ for k,v in callDict.iteritems():
 def natural_sort_key(s, _nsre=re.compile('([0-9]+)')):
     return [int(text) if text.isdigit() else text.lower()
             for text in re.split(_nsre, s)]
+# sort by both the source-line and the datatype, so the output file ordering is stable
+# when we have multiple items on the same source line
+def v_sort_key(v):
+    return natural_sort_key(v[1]) + [v[0]]
 
 # sort results by name and line number
-tmp1list.sort(key=lambda v: natural_sort_key(v[1]))
+tmp1list.sort(key=lambda v: v_sort_key(v))
 
 # print out the results
 with open("loplugin.countusersofdefaultparams.report", "wt") as f:
diff --git a/compilerplugins/clang/expandablemethods.py b/compilerplugins/clang/expandablemethods.py
index 9a7b828a4ad5..0fa61747d368 100755
--- a/compilerplugins/clang/expandablemethods.py
+++ b/compilerplugins/clang/expandablemethods.py
@@ -99,10 +99,14 @@ def isOtherConstness( d, callSet ):
 def natural_sort_key(s, _nsre=re.compile('([0-9]+)')):
     return [int(text) if text.isdigit() else text.lower()
             for text in re.split(_nsre, s)]
+# sort by both the source-line and the datatype, so the output file ordering is stable
+# when we have multiple items on the same source line
+def v_sort_key(v):
+    return natural_sort_key(v[1]) + [v[0]]
 def sort_set_by_natural_key(s):
-    return sorted(s, key=lambda v: natural_sort_key(v[1]))
+    return sorted(s, key=lambda v: v_sort_key(v))
+
 
-    
 # --------------------------------------------------------------------------------------------
 # Methods that are only called from inside their own class, and are only called from one spot
 # --------------------------------------------------------------------------------------------
diff --git a/compilerplugins/clang/finalclasses.py b/compilerplugins/clang/finalclasses.py
index 68c94d6d324b..8b6f505fdd90 100755
--- a/compilerplugins/clang/finalclasses.py
+++ b/compilerplugins/clang/finalclasses.py
@@ -10,7 +10,7 @@ definitionToFileDict = {}
 with open("workdir/loplugin.finalclasses.log") as txt:
     for line in txt:
         tokens = line.strip().split("\t")
-    
+
         if len(tokens) == 1:
             pass
 
@@ -20,7 +20,7 @@ with open("workdir/loplugin.finalclasses.log") as txt:
             fileName  = tokens[2][1:]
             definitionSet.add(clazzName)
             definitionToFileDict[clazzName] = fileName
-            
+
         elif tokens[0] == "inherited-from:":
             parent = tokens[1]
             if (parent.startswith("class ")):
@@ -67,8 +67,12 @@ for clazz in sorted(definitionSet - inheritFromSet):
 def natural_sort_key(s, _nsre=re.compile('([0-9]+)')):
     return [int(text) if text.isdigit() else text.lower()
             for text in re.split(_nsre, s)]
+# sort by both the source-line and the datatype, so the output file ordering is stable
+# when we have multiple items on the same source line
+def v_sort_key(v):
+    return natural_sort_key(v[1]) + [v[0]]
 def sort_set_by_natural_key(s):
-    return sorted(s, key=lambda v: natural_sort_key(v[1]))
+    return sorted(s, key=lambda v: v_sort_key(v))
 
 # print output, sorted by name and line number
 with open("compilerplugins/clang/finalclasses.results", "wt") as f:
diff --git a/compilerplugins/clang/inlinefields.py b/compilerplugins/clang/inlinefields.py
index 4b8211c86a62..1a0dbda34189 100755
--- a/compilerplugins/clang/inlinefields.py
+++ b/compilerplugins/clang/inlinefields.py
@@ -58,7 +58,11 @@ for d in definitionSet:
 def natural_sort_key(s, _nsre=re.compile('([0-9]+)')):
     return [int(text) if text.isdigit() else text.lower()
             for text in re.split(_nsre, s)]
-tmp1list.sort(key=lambda v: natural_sort_key(v[1]))
+# sort by both the source-line and the datatype, so the output file ordering is stable
+# when we have multiple items on the same source line
+def v_sort_key(v):
+    return natural_sort_key(v[1]) + [v[0]]
+tmp1list.sort(key=lambda v: v_sort_key(v))
 
 # print out the results
 with open("loplugin.inlinefields.report", "wt") as f:
diff --git a/compilerplugins/clang/methodcycles.py b/compilerplugins/clang/methodcycles.py
index 77c812d4ab9a..4a153ae1c0e5 100755
--- a/compilerplugins/clang/methodcycles.py
+++ b/compilerplugins/clang/methodcycles.py
@@ -60,10 +60,14 @@ with io.open("workdir/loplugin.methodcycles.log", "rb", buffering=1024*1024) as
 def natural_sort_key(s, _nsre=re.compile('([0-9]+)')):
     return [int(text) if text.isdigit() else text.lower()
             for text in re.split(_nsre, s)]
+# sort by both the source-line and the datatype, so the output file ordering is stable
+# when we have multiple items on the same source line
+def v_sort_key(v):
+    return natural_sort_key(v[1]) + [v[0]]
 def sort_set_by_natural_key(s):
-    return sorted(s, key=lambda v: natural_sort_key(v[1]))
+    return sorted(s, key=lambda v: v_sort_key(v))
+
 
-    
 # --------------------------------------------------------------------------------------------
 #  analysis
 # --------------------------------------------------------------------------------------------
diff --git a/compilerplugins/clang/unnecessaryvirtual.py b/compilerplugins/clang/unnecessaryvirtual.py
index 1e0e1509a810..01a32bfc3df1 100755
--- a/compilerplugins/clang/unnecessaryvirtual.py
+++ b/compilerplugins/clang/unnecessaryvirtual.py
@@ -81,10 +81,14 @@ for clazz in (definitionSet - nonEmptySet):
 def natural_sort_key(s, _nsre=re.compile('([0-9]+)')):
     return [int(text) if text.isdigit() else text.lower()
             for text in re.split(_nsre, s)]
+# sort by both the source-line and the datatype, so the output file ordering is stable
+# when we have multiple items on the same source line
+def v_sort_key(v):
+    return natural_sort_key(v[1]) + [v[0]]
 
 # sort results by name and line number
-tmp1list = sorted(unnecessaryVirtualSet, key=lambda v: natural_sort_key(v[1]))
-tmp2list = sorted(deadSet, key=lambda v: natural_sort_key(v[1]))
+tmp1list = sorted(unnecessaryVirtualSet, key=lambda v: v_sort_key(v))
+tmp2list = sorted(deadSet, key=lambda v: v_sort_key(v))
 
 with open("compilerplugins/clang/unnecessaryvirtual.results", "wt") as f:
     for t in tmp1list:
diff --git a/compilerplugins/clang/unusedmethods.py b/compilerplugins/clang/unusedmethods.py
index da12e2a8ef59..803b0b87733b 100755
--- a/compilerplugins/clang/unusedmethods.py
+++ b/compilerplugins/clang/unusedmethods.py
@@ -101,10 +101,14 @@ def isOtherConstness( d, callSet ):
 def natural_sort_key(s, _nsre=re.compile('([0-9]+)')):
     return [int(text) if text.isdigit() else text.lower()
             for text in re.split(_nsre, s)]
+# sort by both the source-line and the datatype, so the output file ordering is stable
+# when we have multiple items on the same source line
+def v_sort_key(v):
+    return natural_sort_key(v[1]) + [v[0]]
 def sort_set_by_natural_key(s):
-    return sorted(s, key=lambda v: natural_sort_key(v[1]))
+    return sorted(s, key=lambda v: v_sort_key(v))
+
 
-    
 # --------------------------------------------------------------------------------------------
 #  "unused methods" analysis
 # --------------------------------------------------------------------------------------------
diff --git a/compilerplugins/clang/unusedvarsglobal.py b/compilerplugins/clang/unusedvarsglobal.py
index cfc83ad7e8f4..db46b9fee1ca 100755
--- a/compilerplugins/clang/unusedvarsglobal.py
+++ b/compilerplugins/clang/unusedvarsglobal.py
@@ -124,11 +124,15 @@ for d in definitionSet2:
 def natural_sort_key(s, _nsre=re.compile('([0-9]+)')):
     return [int(text) if text.isdigit() else text.lower()
             for text in re.split(_nsre, s)]
+# sort by both the source-line and the datatype, so the output file ordering is stable
+# when we have multiple items on the same source line
+def v_sort_key(v):
+    return natural_sort_key(v[0]) + [v1]]
 
 # sort results by name and line number
-tmp1list = sorted(untouchedSet, key=lambda v: natural_sort_key(v[0]))
-tmp2list = sorted(writeonlySet, key=lambda v: natural_sort_key(v[0]))
-tmp3list = sorted(readonlySet, key=lambda v: natural_sort_key(v[0]))
+tmp1list = sorted(untouchedSet, key=lambda v: v_sort_key(v))
+tmp2list = sorted(writeonlySet, key=lambda v: v_sort_key(v))
+tmp3list = sorted(readonlySet, key=lambda v: v_sort_key(v))
 
 # print out the results
 with open("compilerplugins/clang/unusedvarsglobal.untouched.results", "wt") as f:
diff --git a/compilerplugins/clang/virtualdead.py b/compilerplugins/clang/virtualdead.py
index 2966662ff8fc..e481127af75b 100755
--- a/compilerplugins/clang/virtualdead.py
+++ b/compilerplugins/clang/virtualdead.py
@@ -107,8 +107,12 @@ for name, bitfield in tmp2dict.iteritems():
 def natural_sort_key(s, _nsre=re.compile('([0-9]+)')):
     return [int(text) if text.isdigit() else text.lower()
             for text in re.split(_nsre, s)]
-tmp1list.sort(key=lambda v: natural_sort_key(v[0]))
-tmp2list.sort(key=lambda v: natural_sort_key(v[0]))
+# sort by both the source-line and the datatype, so the output file ordering is stable
+# when we have multiple items on the same source line
+def v_sort_key(v):
+    return natural_sort_key(v[0]) + [v[1]]
+tmp1list.sort(key=lambda v: v_sort_key(v))
+tmp2list.sort(key=lambda v: v_sort_key(v))
 
 # print out the results
 with open("compilerplugins/clang/virtualdead.results", "wt") as f:
diff --git a/compilerplugins/clang/virtualdown.py b/compilerplugins/clang/virtualdown.py
index 9c1346ff2831..35623b5581db 100755
--- a/compilerplugins/clang/virtualdown.py
+++ b/compilerplugins/clang/virtualdown.py
@@ -38,9 +38,13 @@ for clazz in (definitionSet - callSet):
 def natural_sort_key(s, _nsre=re.compile('([0-9]+)')):
     return [int(text) if text.isdigit() else text.lower()
             for text in re.split(_nsre, s)]
+# sort by both the source-line and the datatype, so the output file ordering is stable
+# when we have multiple items on the same source line
+def v_sort_key(v):
+    return natural_sort_key(v[1]) + [v[0]]
 
 # sort results by name and line number
-tmp1list = sorted(unnecessaryVirtualSet, key=lambda v: natural_sort_key(v[1]))
+tmp1list = sorted(unnecessaryVirtualSet, key=lambda v: v_sort_key(v))
 
 with open("compilerplugins/clang/virtualdown.results", "wt") as f:
     for t in tmp1list:


More information about the Libreoffice-commits mailing list