[Libreoffice-commits] core.git: compilerplugins/clang
Noel (via logerrit)
logerrit at kemper.freedesktop.org
Tue Dec 8 10:27:50 UTC 2020
compilerplugins/clang/singlevalfields.cxx | 13 ++++++++++++-
compilerplugins/clang/singlevalfields.py | 6 +++---
2 files changed, 15 insertions(+), 4 deletions(-)
New commits:
commit e1e4edd4d1aabefb4ef31db3d1478f2165079800
Author: Noel <noelgrandin at gmail.com>
AuthorDate: Tue Dec 8 09:20:05 2020 +0200
Commit: Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Tue Dec 8 11:26:53 2020 +0100
loplugin:singlevalfields update to python3
Change-Id: I1257b7b865caa356c85eeeb45a19a537fc434ac5
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/107368
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>
diff --git a/compilerplugins/clang/singlevalfields.cxx b/compilerplugins/clang/singlevalfields.cxx
index ce60eeea7df0..2731f55c8587 100644
--- a/compilerplugins/clang/singlevalfields.cxx
+++ b/compilerplugins/clang/singlevalfields.cxx
@@ -74,6 +74,17 @@ bool operator < (const MyFieldAssignmentInfo &lhs, const MyFieldAssignmentInfo &
static std::set<MyFieldAssignmentInfo> assignedSet;
static std::set<MyFieldInfo> definitionSet;
+/** escape the value string to make it easier to parse the output file in python */
+std::string escape(std::string s)
+{
+ std::string out;
+ for (size_t i=0; i<s.length(); ++i)
+ if (int(s[i]) >= 32)
+ out += s[i];
+ else
+ out += "\\" + std::to_string((int)s[i]);
+ return out;
+}
class SingleValFields:
public RecursiveASTVisitor<SingleValFields>, public loplugin::Plugin
@@ -92,7 +103,7 @@ public:
// writing to the same logfile
std::string output;
for (const MyFieldAssignmentInfo & s : assignedSet)
- output += "asgn:\t" + s.parentClass + "\t" + s.fieldName + "\t" + s.value + "\n";
+ output += "asgn:\t" + s.parentClass + "\t" + s.fieldName + "\t" + escape(s.value) + "\n";
for (const MyFieldInfo & s : definitionSet)
output += "defn:\t" + s.parentClass + "\t" + s.fieldName + "\t" + s.fieldType + "\t" + s.sourceLocation + "\n";
std::ofstream myfile;
diff --git a/compilerplugins/clang/singlevalfields.py b/compilerplugins/clang/singlevalfields.py
index 3b9577b87263..0830a8cdcc00 100755
--- a/compilerplugins/clang/singlevalfields.py
+++ b/compilerplugins/clang/singlevalfields.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python2
+#!/usr/bin/python3
import sys
import re
@@ -15,7 +15,7 @@ def normalizeTypeParams( line ):
return normalizeTypeParamsRegex.sub("type-parameter-?-?", line)
# reading as binary (since we known it is pure ascii) is much faster than reading as unicode
-with io.open("workdir/loplugin.singlevalfields.log", "rb", buffering=1024*1024) as txt:
+with io.open("workdir/loplugin.singlevalfields.log", "r", buffering=1024*1024) as txt:
for line in txt:
tokens = line.strip().split("\t")
if tokens[0] == "defn:":
@@ -44,7 +44,7 @@ with io.open("workdir/loplugin.singlevalfields.log", "rb", buffering=1024*1024)
tmp1list = list()
# look for things which have two values - zero and one
tmp2list = list()
-for fieldInfo, assignValues in fieldAssignDict.iteritems():
+for fieldInfo, assignValues in fieldAssignDict.items():
v0 = fieldInfo[0] + " " + fieldInfo[1]
v1 = (",".join(assignValues))
v2 = ""
More information about the Libreoffice-commits
mailing list