summaryrefslogtreecommitdiff
path: root/compilerplugins
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2018-10-20 07:38:42 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2018-10-22 07:55:46 +0200
commitb979e7181ff8c089b7809571791f7f287d01ae83 (patch)
tree659b9e39cde19d3e5fa418187893df93aeb89ac4 /compilerplugins
parent7ea01578eed8459678369d0256de016930b3af40 (diff)
loplugin:singlevalfields look for fields that can be bool
Change-Id: Ief773b661a8378a10db56943b32127c7a2c86d11 Reviewed-on: https://gerrit.libreoffice.org/62037 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'compilerplugins')
-rw-r--r--compilerplugins/clang/singlevalfields.could-be-bool.results66
-rw-r--r--compilerplugins/clang/singlevalfields.cxx4
-rwxr-xr-xcompilerplugins/clang/singlevalfields.py24
3 files changed, 90 insertions, 4 deletions
diff --git a/compilerplugins/clang/singlevalfields.could-be-bool.results b/compilerplugins/clang/singlevalfields.could-be-bool.results
new file mode 100644
index 000000000000..d8d1b4787d89
--- /dev/null
+++ b/compilerplugins/clang/singlevalfields.could-be-bool.results
@@ -0,0 +1,66 @@
+chart2/source/view/inc/PlottingPositionHelper.hxx:206
+ chart::PolarPlottingPositionHelper m_fRadiusOffset
+ double
+connectivity/source/inc/dbase/dindexnode.hxx:125
+ connectivity::dbase::ONDXPage bNoDelete
+ unsigned int
+filter/source/graphicfilter/eps/eps.cxx:139
+ PSWriter nNextChrSetId
+ sal_uInt8
+include/vcl/split.hxx:40
+ Splitter mbInKeyEvent
+ long
+sal/rtl/cipher.cxx:110
+ Cipher_Impl m_algorithm
+ rtlCipherAlgorithm
+sc/source/filter/inc/stylesbuffer.hxx:290
+ oox::xls::ApiAlignmentData mnHorJustifyMethod
+ sal_Int32
+sc/source/filter/inc/stylesbuffer.hxx:292
+ oox::xls::ApiAlignmentData mnVerJustifyMethod
+ sal_Int32
+sc/source/ui/Accessibility/AccessibleDocumentPagePreview.cxx:1099
+ ScPagePreviewCountData nHeaders
+ long
+sc/source/ui/Accessibility/AccessibleDocumentPagePreview.cxx:1100
+ ScPagePreviewCountData nTables
+ long
+sc/source/ui/Accessibility/AccessibleDocumentPagePreview.cxx:1102
+ ScPagePreviewCountData nFooters
+ long
+sc/source/ui/vba/vbahyperlink.hxx:82
+ ScVbaHyperlink mnType
+ long
+soltools/cpp/cpp.h:121
+ includelist always
+ char
+svl/source/numbers/zforfind.hxx:111
+ ImpSvNumberInputScan nNegCheck
+ short
+svl/source/numbers/zforfind.hxx:115
+ ImpSvNumberInputScan mnEra
+ sal_Int16
+svx/source/inc/cell.hxx:205
+ sdr::table::Cell mnCellContentType
+ css::table::CellContentType
+svx/source/table/tablertfimporter.cxx:55
+ sdr::table::RTFCellDefault mnRowSpan
+ sal_Int32
+sw/source/filter/ww8/docxexport.hxx:100
+ DocxExport m_nHeadersFootersInSection
+ sal_Int32
+sw/source/filter/ww8/ww8scan.hxx:65
+ SprmInfo nVari
+ unsigned int
+vcl/inc/canvasbitmap.hxx:57
+ vcl::unotools::VclCanvasBitmap m_nEndianness
+ sal_Int8
+vcl/inc/unx/i18n_ic.hxx:33
+ SalI18N_InputContext mbUseable
+ int
+vcl/workben/icontest.cxx:144
+ IconTestApp nRet
+ int
+writerfilter/source/dmapper/PageBordersHandler.hxx:54
+ writerfilter::dmapper::PageBordersHandler m_eOffsetFrom
+ class SectionPropertyMap::BorderOffsetFrom
diff --git a/compilerplugins/clang/singlevalfields.cxx b/compilerplugins/clang/singlevalfields.cxx
index 9c3a8b8d71b7..68b4df06af2d 100644
--- a/compilerplugins/clang/singlevalfields.cxx
+++ b/compilerplugins/clang/singlevalfields.cxx
@@ -41,6 +41,7 @@ struct MyFieldInfo
{
std::string parentClass;
std::string fieldName;
+ std::string fieldType;
std::string sourceLocation;
};
bool operator < (const MyFieldInfo &lhs, const MyFieldInfo &rhs)
@@ -83,7 +84,7 @@ public:
for (const MyFieldAssignmentInfo & s : assignedSet)
output += "asgn:\t" + s.parentClass + "\t" + s.fieldName + "\t" + s.value + "\n";
for (const MyFieldInfo & s : definitionSet)
- output += "defn:\t" + s.parentClass + "\t" + s.fieldName + "\t" + s.sourceLocation + "\n";
+ output += "defn:\t" + s.parentClass + "\t" + s.fieldName + "\t" + s.fieldType + "\t" + s.sourceLocation + "\n";
std::ofstream myfile;
myfile.open( WORKDIR "/loplugin.singlevalfields.log", std::ios::app | std::ios::out);
myfile << output;
@@ -112,6 +113,7 @@ void SingleValFields::niceName(const FieldDecl* fieldDecl, MyFieldInfo& aInfo)
{
aInfo.parentClass = fieldDecl->getParent()->getQualifiedNameAsString();
aInfo.fieldName = fieldDecl->getNameAsString();
+ aInfo.fieldType = fieldDecl->getType().getAsString();
SourceLocation expansionLoc = compiler.getSourceManager().getExpansionLoc( fieldDecl->getLocation() );
StringRef name = compiler.getSourceManager().getFilename(expansionLoc);
diff --git a/compilerplugins/clang/singlevalfields.py b/compilerplugins/clang/singlevalfields.py
index b842929011b1..7d42a0f6bbc6 100755
--- a/compilerplugins/clang/singlevalfields.py
+++ b/compilerplugins/clang/singlevalfields.py
@@ -5,6 +5,7 @@ import re
import io
definitionToSourceLocationMap = dict() # dict of tuple(parentClass, fieldName) to sourceLocation
+definitionToTypeMap = dict() # dict of tuple(parentClass, fieldName) to field type
fieldAssignDict = dict() # dict of tuple(parentClass, fieldName) to (set of values)
# clang does not always use exactly the same numbers in the type-parameter vars it generates
@@ -20,9 +21,11 @@ with io.open("workdir/loplugin.singlevalfields.log", "rb", buffering=1024*1024)
if tokens[0] == "defn:":
parentClass = normalizeTypeParams(tokens[1])
fieldName = normalizeTypeParams(tokens[2])
- sourceLocation = tokens[3]
+ fieldType = normalizeTypeParams(tokens[3])
+ sourceLocation = tokens[4]
fieldInfo = (parentClass, fieldName)
definitionToSourceLocationMap[fieldInfo] = sourceLocation
+ definitionToTypeMap[fieldInfo] = fieldType
elif tokens[0] == "asgn:":
parentClass = normalizeTypeParams(tokens[1])
fieldName = normalizeTypeParams(tokens[2])
@@ -37,7 +40,10 @@ with io.open("workdir/loplugin.singlevalfields.log", "rb", buffering=1024*1024)
else:
print( "unknown line: " + line)
+# look for stuff also has a single value
tmp1list = list()
+# look for things which have two values - zero and one
+tmp2list = list()
for fieldInfo, assignValues in fieldAssignDict.iteritems():
v0 = fieldInfo[0] + " " + fieldInfo[1]
v1 = (",".join(assignValues))
@@ -45,7 +51,7 @@ for fieldInfo, assignValues in fieldAssignDict.iteritems():
if fieldInfo not in definitionToSourceLocationMap:
continue
v2 = definitionToSourceLocationMap[fieldInfo]
- if len(assignValues) != 1:
+ if len(assignValues) > 2:
continue
if "?" in assignValues:
continue
@@ -75,13 +81,20 @@ for fieldInfo, assignValues in fieldAssignDict.iteritems():
# Some of our supported compilers don't do constexpr, which means o3tl::typed_flags can't be 'static const'
if containingClass in ["WaitWindow_Impl"]:
continue
- tmp1list.append((v0,v1,v2))
+ if len(assignValues) == 2:
+ if "0" in assignValues and "1" in assignValues:
+ fieldType = definitionToTypeMap[fieldInfo]
+ if not "_Bool" in fieldType and not "enum " in fieldType and not "boolean" in fieldType:
+ tmp2list.append((v0,v1,v2,fieldType))
+ else:
+ tmp1list.append((v0,v1,v2))
# sort results by filename:lineno
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[2]))
+tmp2list.sort(key=lambda v: natural_sort_key(v[2]))
# print out the results
with open("compilerplugins/clang/singlevalfields.results", "wt") as f:
@@ -89,5 +102,10 @@ with open("compilerplugins/clang/singlevalfields.results", "wt") as f:
f.write(v[2] + "\n")
f.write(" " + v[0] + "\n")
f.write(" " + v[1] + "\n")
+with open("compilerplugins/clang/singlevalfields.could-be-bool.results", "wt") as f:
+ for v in tmp2list:
+ f.write(v[2] + "\n")
+ f.write(" " + v[0] + "\n")
+ f.write(" " + v[3] + "\n")