compilerplugins/clang/singlevalfields.could-be-bool.results |   66 ++++++++++++
 compilerplugins/clang/singlevalfields.cxx                   |    4 
 compilerplugins/clang/singlevalfields.py                    |   24 +++-
 include/vcl/split.hxx                                       |    2 
 svl/source/numbers/zforfind.cxx                             |   50 ++++-----
 svl/source/numbers/zforfind.hxx                             |    4 
 vcl/source/window/split.cxx                                 |    6 -
 7 files changed, 121 insertions(+), 35 deletions(-)

New commits:
commit b979e7181ff8c089b7809571791f7f287d01ae83
Author:     Noel Grandin <noel.gran...@collabora.co.uk>
AuthorDate: Sat Oct 20 07:38:42 2018 +0200
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Mon Oct 22 07:55:46 2018 +0200

    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.gran...@collabora.co.uk>

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")
 
 
diff --git a/include/vcl/split.hxx b/include/vcl/split.hxx
index 448894d746ec..b205ffe85edb 100644
--- a/include/vcl/split.hxx
+++ b/include/vcl/split.hxx
@@ -37,7 +37,7 @@ private:
     bool                mbHorzSplit;
     bool                mbDragFull;
     bool                mbKbdSplitting;
-    long                mbInKeyEvent;
+    bool                mbInKeyEvent;
     long                mnKeyboardStepSize;
     Link<Splitter*,void>   maStartSplitHdl;
     Link<Splitter*,void>   maSplitHdl;
diff --git a/svl/source/numbers/zforfind.cxx b/svl/source/numbers/zforfind.cxx
index 590cc0aabb54..59140e770717 100644
--- a/svl/source/numbers/zforfind.cxx
+++ b/svl/source/numbers/zforfind.cxx
@@ -66,7 +66,7 @@ const sal_uInt8 ImpSvNumberInputScan::nMatchedUsedAsReturn = 
0x10;
 
 static const sal_Unicode cNoBreakSpace = 0xA0;
 static const sal_Unicode cNarrowNoBreakSpace = 0x202F;
-static const sal_Int16 kDefaultEra = 1;     // Gregorian CE, positive year
+static const bool kDefaultEra = true;     // Gregorian CE, positive year
 
 ImpSvNumberInputScan::ImpSvNumberInputScan( SvNumberFormatter* pFormatterP )
         :
@@ -99,7 +99,7 @@ void ImpSvNumberInputScan::Reset()
     nSign        = 0;
     nESign       = 0;
     nDecPos      = 0;
-    nNegCheck    = 0;
+    bNegCheck    = false;
     nStringsCnt  = 0;
     nNumericsCnt = 0;
     nThousand    = 0;
@@ -107,7 +107,7 @@ void ImpSvNumberInputScan::Reset()
     nAmPm        = 0;
     nPosThousandString = 0;
     nLogical     = 0;
-    mnEra        = kDefaultEra;
+    mbEraCE        = kDefaultEra;
     nStringScanNumFor = 0;
     nStringScanSign = 0;
     nMatchedAllStrings = nMatchedVirgin;
@@ -871,7 +871,7 @@ inline bool ImpSvNumberInputScan::GetTime100SecSep( const 
OUString& rString, sal
  * Read a sign including brackets
  * '+'   =>  1
  * '-'   => -1
- *  '('   => -1, nNegCheck = 1
+ *  '('   => -1, bNegCheck = 1
  * else =>  0
  */
 int ImpSvNumberInputScan::GetSign( const OUString& rString, sal_Int32& nPos )
@@ -883,7 +883,7 @@ int ImpSvNumberInputScan::GetSign( const OUString& rString, 
sal_Int32& nPos )
             nPos++;
             return 1;
         case '(': // '(' similar to '-' ?!?
-            nNegCheck = 1;
+            bNegCheck = true;
             SAL_FALLTHROUGH;
         case '-':
             nPos++;
@@ -1050,7 +1050,7 @@ sal_uInt16 ImpSvNumberInputScan::ImplGetYear( sal_uInt16 
nIndex )
         // A year in another, not Gregorian CE era is never expanded.
         // A year < 100 entered with at least 3 digits with leading 0 is taken
         // as is without expansion.
-        if (mnEra == kDefaultEra && nYear < 100 && nLen < 3)
+        if (mbEraCE == kDefaultEra && nYear < 100 && nLen < 3)
         {
             nYear = SvNumberFormatter::ExpandTwoDigitYear( nYear, nYear2000 );
         }
@@ -2072,8 +2072,8 @@ input for the following reasons:
             break;
         }   // switch (nNumericsCnt)
 
-        if (mnEra != kDefaultEra)
-            pCal->setValue( CalendarFieldIndex::ERA, mnEra );
+        if (mbEraCE != kDefaultEra)
+            pCal->setValue( CalendarFieldIndex::ERA, mbEraCE ? 1 : 0);
 
         if ( res && pCal->isValid() )
         {
@@ -2523,10 +2523,10 @@ bool ImpSvNumberInputScan::ScanMidString( const 
OUString& rString, sal_uInt16 nS
         }
         if (bSignedYear)
         {
-            if (mnEra != kDefaultEra)               // signed year twice?
+            if (mbEraCE != kDefaultEra)               // signed year twice?
                 return MatchedReturn();
 
-            mnEra = 0;  // BCE
+            mbEraCE = false;  // BCE
         }
     }
 
@@ -2784,7 +2784,7 @@ bool ImpSvNumberInputScan::ScanEndString( const OUString& 
rString )
                                                     //!? catch time too?
     {                                               // not signed yet
         nSign = GetSign(rString, nPos);             // 1- DM
-        if (nNegCheck)                              // '(' as sign
+        if (bNegCheck)                              // '(' as sign
         {
             return MatchedReturn();
         }
@@ -2795,9 +2795,9 @@ bool ImpSvNumberInputScan::ScanEndString( const OUString& 
rString )
     }
 
     SkipBlanks(rString, nPos);
-    if (nNegCheck && SkipChar(')', rString, nPos))  // skip ')' if appropriate
+    if (bNegCheck && SkipChar(')', rString, nPos))  // skip ')' if appropriate
     {
-        nNegCheck = 0;
+        bNegCheck = false;
         SkipBlanks(rString, nPos);
     }
 
@@ -2816,15 +2816,15 @@ bool ImpSvNumberInputScan::ScanEndString( const 
OUString& rString )
         {
             nSign = GetSign(rString, nPos);         // DM -
             SkipBlanks(rString, nPos);
-            if (nNegCheck)                          // 3 DM (
+            if (bNegCheck)                          // 3 DM (
             {
                 return MatchedReturn();
             }
         }
-        if ( nNegCheck && eScannedType == SvNumFormatType::CURRENCY &&
+        if ( bNegCheck && eScannedType == SvNumFormatType::CURRENCY &&
              SkipChar(')', rString, nPos) )
         {
-            nNegCheck = 0;                          // ')' skipped
+            bNegCheck = false;                          // ')' skipped
             SkipBlanks(rString, nPos);              // only if currency
         }
     }
@@ -2967,11 +2967,11 @@ bool ImpSvNumberInputScan::ScanEndString( const 
OUString& rString )
         }
     }
 
-    if ( nNegCheck && SkipChar(')', rString, nPos) )
+    if ( bNegCheck && SkipChar(')', rString, nPos) )
     {
         if (eScannedType == SvNumFormatType::CURRENCY)  // only if currency
         {
-            nNegCheck = 0;                          // skip ')'
+            bNegCheck = false;                          // skip ')'
             SkipBlanks(rString, nPos);
         }
         else
@@ -3216,7 +3216,7 @@ bool ImpSvNumberInputScan::IsNumberFormatMain( const 
OUString& rString,        /
         GetNextNumber(i,j);                 // i=1,2
         if (eSetType == SvNumFormatType::FRACTION)  // Fraction -1 = -1/1
         {
-            if (nSign && !nNegCheck &&      // Sign +, -
+            if (nSign && !bNegCheck &&      // Sign +, -
                 eScannedType == SvNumFormatType::UNDEFINED &&   // not date or 
currency
                 nDecPos == 0 &&             // no previous decimal separator
                 (i >= nStringsCnt ||        // no end string nor decimal 
separator
@@ -3254,7 +3254,7 @@ bool ImpSvNumberInputScan::IsNumberFormatMain( const 
OUString& rString,        /
         }
         if (eSetType == SvNumFormatType::FRACTION)  // -1,200. as fraction
         {
-            if (!nNegCheck  &&                  // no sign '('
+            if (!bNegCheck  &&                  // no sign '('
                 eScannedType == SvNumFormatType::UNDEFINED &&
                 (nDecPos == 0 || nDecPos == 3)  // no decimal separator or at 
end
                 )
@@ -3302,7 +3302,7 @@ bool ImpSvNumberInputScan::IsNumberFormatMain( const 
OUString& rString,        /
         }
         if (eSetType == SvNumFormatType::FRACTION)  // -1,200,100. as fraction
         {
-            if (!nNegCheck  &&                  // no sign '('
+            if (!bNegCheck  &&                  // no sign '('
                 eScannedType == SvNumFormatType::UNDEFINED &&
                 (nDecPos == 0 || nDecPos == 3)  // no decimal separator or at 
end
                 )
@@ -3376,7 +3376,7 @@ bool ImpSvNumberInputScan::IsNumberFormatMain( const 
OUString& rString,        /
         }
         if (eSetType == SvNumFormatType::FRACTION)  // -1,200,100. as fraction
         {
-            if (!nNegCheck  &&                  // no sign '('
+            if (!bNegCheck  &&                  // no sign '('
                 eScannedType == SvNumFormatType::UNDEFINED &&
                 (nDecPos == 0 || nDecPos == 3)  // no decimal separator or at 
end
                 )
@@ -3641,7 +3641,7 @@ bool ImpSvNumberInputScan::IsNumberFormat( const 
OUString& rString,         // s
         // Accept only if the year immediately follows the sign character with
         // no space in between.
         if (nSign && (eScannedType == SvNumFormatType::DATE ||
-                      eScannedType == SvNumFormatType::DATETIME) && mnEra == 
kDefaultEra &&
+                      eScannedType == SvNumFormatType::DATETIME) && mbEraCE == 
kDefaultEra &&
                 (IsDatePatternNumberOfType(0,'Y') || (MayBeIso8601() && 
sStrArray[nNums[0]].getLength() >= 4)))
         {
             const sal_Unicode c = sStrArray[0][sStrArray[0].getLength()-1];
@@ -3649,11 +3649,11 @@ bool ImpSvNumberInputScan::IsNumberFormat( const 
OUString& rString,         // s
             {
                 // A '+' sign doesn't change the era.
                 if (nSign < 0)
-                    mnEra = 0;  // BCE
+                    mbEraCE = false;  // BCE
                 nSign = 0;
             }
         }
-        if ( nNegCheck ||                             // ')' not found for '('
+        if ( bNegCheck ||                             // ')' not found for '('
              (nSign && (eScannedType == SvNumFormatType::DATE ||
                         eScannedType == SvNumFormatType::DATETIME))) // signed 
date/datetime
         {
diff --git a/svl/source/numbers/zforfind.hxx b/svl/source/numbers/zforfind.hxx
index e7ddb7e6f1d9..dfa9b6df4ed7 100644
--- a/svl/source/numbers/zforfind.hxx
+++ b/svl/source/numbers/zforfind.hxx
@@ -108,11 +108,11 @@ private:
     int    nDayOfWeek;                          // Temporary (!) day of week 
(1..7,-1..-7) if date
     sal_uInt16 nTimePos;                        // Index of first time 
separator (+1)
     short  nDecPos;                             // Index of substring 
containing "," (+1)
-    short  nNegCheck;                           // '( )' for negative
+    bool   bNegCheck;                           // '( )' for negative
     short  nESign;                              // Sign of exponent
     short  nAmPm;                               // +1 AM, -1 PM, 0 if none
     short  nLogical;                            // -1 => False, 1 => True
-    sal_Int16 mnEra;                            // Era if date, 0 => BCE, 1 => 
CE (currently only Gregorian)
+    bool   mbEraCE;                            // Era if date, 0 => BCE, 1 => 
CE (currently only Gregorian)
     sal_uInt16 nThousand;                       // Count of group (AKA 
thousand) separators
     sal_uInt16 nPosThousandString;              // Position of concatenated 
000,000,000 string
     SvNumFormatType eScannedType;               // Scanned type
diff --git a/vcl/source/window/split.cxx b/vcl/source/window/split.cxx
index 9b5b1209df8d..bedb5ab01009 100644
--- a/vcl/source/window/split.cxx
+++ b/vcl/source/window/split.cxx
@@ -133,7 +133,7 @@ Splitter::Splitter( vcl::Window* pParent, WinBits nStyle ) :
     mnStartSplitPos( 0 ),
     mbDragFull( false ),
     mbKbdSplitting( false ),
-    mbInKeyEvent( 0 ),
+    mbInKeyEvent( false ),
     mnKeyboardStepSize( SPLITTER_DEFAULTSTEPSIZE )
 {
     ImplGetWindowImpl()->mbSplitter        = true;
@@ -555,7 +555,7 @@ void Splitter::KeyInput( const KeyEvent& rKEvt )
     if( mbInKeyEvent )
         return;
 
-    mbInKeyEvent = 1;
+    mbInKeyEvent = true;
 
     Splitter *pSibling = ImplFindSibling();
     vcl::KeyCode aKeyCode = rKEvt.GetKeyCode();
@@ -644,7 +644,7 @@ void Splitter::KeyInput( const KeyEvent& rKEvt )
             GrabFocusToDocument();
             break;
     }
-    mbInKeyEvent = 0;
+    mbInKeyEvent = false;
 }
 
 void Splitter::DataChanged( const DataChangedEvent& rDCEvt )
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to