diff options
author | Noel <noelgrandin@gmail.com> | 2020-12-08 09:20:05 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2020-12-08 11:26:53 +0100 |
commit | e1e4edd4d1aabefb4ef31db3d1478f2165079800 (patch) | |
tree | 48bc4182cde3aff2981522f33874fe74f58aea48 /compilerplugins | |
parent | 085468767e04db71b7f458b8f5dc1f03d2e4ad17 (diff) |
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@collabora.co.uk>
Diffstat (limited to 'compilerplugins')
-rw-r--r-- | compilerplugins/clang/singlevalfields.cxx | 13 | ||||
-rwxr-xr-x | compilerplugins/clang/singlevalfields.py | 6 |
2 files changed, 15 insertions, 4 deletions
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 = "" |