[Libreoffice-commits] core.git: compilerplugins/clang include/basic include/vcl vcl/source xmlsecurity/inc xmlsecurity/source

Noel Grandin noel.grandin at collabora.co.uk
Fri Mar 24 08:57:25 UTC 2017


 compilerplugins/clang/unusedfields.cxx                     |   30 +++++++------
 compilerplugins/clang/unusedfields.py                      |   20 ++++----
 include/basic/sbxvar.hxx                                   |    1 
 include/vcl/outdev.hxx                                     |    1 
 vcl/source/app/svapp.cxx                                   |   12 -----
 xmlsecurity/inc/macrosecurity.hxx                          |    2 
 xmlsecurity/source/component/documentdigitalsignatures.cxx |    2 
 xmlsecurity/source/dialogs/macrosecurity.cxx               |    2 
 8 files changed, 32 insertions(+), 38 deletions(-)

New commits:
commit f0593478571009139cd12bac11a9b38e51c42f96
Author: Noel Grandin <noel.grandin at collabora.co.uk>
Date:   Fri Mar 24 08:31:25 2017 +0200

    loplugin:unusedfields
    
    improve the plugin to find fields which are only assigned to in the
    constructor
    
    Change-Id: I95b5be238ebba83d950ca15093abdd1849740359
    Reviewed-on: https://gerrit.libreoffice.org/35613
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/compilerplugins/clang/unusedfields.cxx b/compilerplugins/clang/unusedfields.cxx
index 94a1cb6300d9..04c51195eaf3 100644
--- a/compilerplugins/clang/unusedfields.cxx
+++ b/compilerplugins/clang/unusedfields.cxx
@@ -57,7 +57,8 @@ bool operator < (const MyFieldInfo &lhs, const MyFieldInfo &rhs)
 
 
 // try to limit the voluminous output a little
-static std::set<MyFieldInfo> touchedSet;
+static std::set<MyFieldInfo> touchedFromInsideSet;
+static std::set<MyFieldInfo> touchedFromConstructorSet;
 static std::set<MyFieldInfo> touchedFromOutsideSet;
 static std::set<MyFieldInfo> readFromSet;
 static std::set<MyFieldInfo> definitionSet;
@@ -76,8 +77,10 @@ public:
         // dump all our output in one write call - this is to try and limit IO "crosstalk" between multiple processes
         // writing to the same logfile
         std::string output;
-        for (const MyFieldInfo & s : touchedSet)
-            output += "touch:\t" + s.parentClass + "\t" + s.fieldName + "\n";
+        for (const MyFieldInfo & s : touchedFromInsideSet)
+            output += "inside:\t" + s.parentClass + "\t" + s.fieldName + "\n";
+        for (const MyFieldInfo & s : touchedFromConstructorSet)
+            output += "constructor:\t" + s.parentClass + "\t" + s.fieldName + "\n";
         for (const MyFieldInfo & s : touchedFromOutsideSet)
             output += "outside:\t" + s.parentClass + "\t" + s.fieldName + "\n";
         for (const MyFieldInfo & s : readFromSet)
@@ -100,7 +103,7 @@ public:
     bool VisitDeclRefExpr( const DeclRefExpr* );
 private:
     MyFieldInfo niceName(const FieldDecl*);
-    void checkForTouchedFromOutside(const FieldDecl* fieldDecl, const Expr* memberExpr, const MyFieldInfo& fieldInfo);
+    void checkTouched(const FieldDecl* fieldDecl, const Expr* memberExpr);
 };
 
 MyFieldInfo UnusedFields::niceName(const FieldDecl* fieldDecl)
@@ -193,7 +196,7 @@ bool UnusedFields::VisitMemberExpr( const MemberExpr* memberExpr )
 
   // for the touched-from-outside analysis
 
-    checkForTouchedFromOutside(fieldDecl, memberExpr, fieldInfo);
+    checkTouched(fieldDecl, memberExpr);
 
   // for the write-only analysis
 
@@ -281,19 +284,18 @@ bool UnusedFields::VisitDeclRefExpr( const DeclRefExpr* declRefExpr )
     if (isInUnoIncludeFile(compiler.getSourceManager().getSpellingLoc(fieldDecl->getLocation()))) {
         return true;
     }
-    MyFieldInfo fieldInfo = niceName(fieldDecl);
-    touchedSet.insert(fieldInfo);
-    checkForTouchedFromOutside(fieldDecl, declRefExpr, fieldInfo);
+    checkTouched(fieldDecl, declRefExpr);
     return true;
 }
 
-void UnusedFields::checkForTouchedFromOutside(const FieldDecl* fieldDecl, const Expr* memberExpr, const MyFieldInfo& fieldInfo) {
+void UnusedFields::checkTouched(const FieldDecl* fieldDecl, const Expr* memberExpr) {
     const FunctionDecl* memberExprParentFunction = parentFunctionDecl(memberExpr);
     const CXXMethodDecl* methodDecl = dyn_cast_or_null<CXXMethodDecl>(memberExprParentFunction);
 
+    MyFieldInfo fieldInfo = niceName(fieldDecl);
+
     // it's touched from somewhere outside a class
     if (!methodDecl) {
-        touchedSet.insert(fieldInfo);
         touchedFromOutsideSet.insert(fieldInfo);
         return;
     }
@@ -303,9 +305,13 @@ void UnusedFields::checkForTouchedFromOutside(const FieldDecl* fieldDecl, const
         // ignore move/copy operator, it's self->self
     } else if (constructorDecl && (constructorDecl->isCopyConstructor() || constructorDecl->isMoveConstructor())) {
         // ignore move/copy constructor, it's self->self
+    } else if (constructorDecl && memberExprParentFunction->getParent() == fieldDecl->getParent()) {
+        // if the field is touched from inside it's parent class constructor
+        touchedFromConstructorSet.insert(fieldInfo);
     } else {
-        touchedSet.insert(fieldInfo);
-        if (memberExprParentFunction->getParent() != fieldDecl->getParent()) {
+        if (memberExprParentFunction->getParent() == fieldDecl->getParent()) {
+            touchedFromInsideSet.insert(fieldInfo);
+        } else {
            touchedFromOutsideSet.insert(fieldInfo);
         }
     }
diff --git a/compilerplugins/clang/unusedfields.py b/compilerplugins/clang/unusedfields.py
index 7bf910f62d80..77e6446e18e3 100755
--- a/compilerplugins/clang/unusedfields.py
+++ b/compilerplugins/clang/unusedfields.py
@@ -8,7 +8,8 @@ definitionSet = set()
 protectedAndPublicDefinitionSet = set() # set of tuple(type, name)
 definitionToSourceLocationMap = dict()
 definitionToTypeMap = dict()
-callSet = set()
+touchedFromInsideSet = set()
+touchedFromConstructorSet = set()
 readFromSet = set()
 sourceLocationSet = set()
 touchedFromOutsideSet = set()
@@ -45,20 +46,20 @@ with io.open("loplugin.unusedfields.log", "rb", buffering=1024*1024) as txt:
             if access == "protected" or access == "public":
                 protectedAndPublicDefinitionSet.add(fieldInfo)
             definitionToSourceLocationMap[fieldInfo] = tokens[5]
-        elif tokens[0] == "touch:":
-            callSet.add(parseFieldInfo(tokens))
-        elif tokens[0] == "read:":
-            readFromSet.add(parseFieldInfo(tokens))
-        elif tokens[0] == "read:":
-            readFromSet.add(parseFieldInfo(tokens))
+        elif tokens[0] == "inside:":
+            touchedFromInsideSet.add(parseFieldInfo(tokens))
+        elif tokens[0] == "constructor:":
+            touchedFromConstructorSet.add(parseFieldInfo(tokens))
         elif tokens[0] == "outside:":
             touchedFromOutsideSet.add(parseFieldInfo(tokens))
+        elif tokens[0] == "read:":
+            readFromSet.add(parseFieldInfo(tokens))
         else:
             print( "unknown line: " + line)
 
 # Invert the definitionToSourceLocationMap
 # If we see more than one method at the same sourceLocation, it's being autogenerated as part of a template
-# and we should just ignore
+# and we should just ignore it
 sourceLocationToDefinitionMap = {}
 for k, v in definitionToSourceLocationMap.iteritems():
     sourceLocationToDefinitionMap[v] = sourceLocationToDefinitionMap.get(v, [])
@@ -68,9 +69,10 @@ for k, definitions in sourceLocationToDefinitionMap.iteritems():
         for d in definitions:
             definitionSet.remove(d)
 
+# Calculate untouched or untouched-except-for-in-constructor
 untouchedSet = set()
 for d in definitionSet:
-    if d in callSet:
+    if d in touchedFromOutsideSet or d in touchedFromInsideSet:
         continue
     srcLoc = definitionToSourceLocationMap[d];
     # this is all representations of on-disk data structures
diff --git a/include/basic/sbxvar.hxx b/include/basic/sbxvar.hxx
index 90127f28a1e9..5645a6cb409f 100644
--- a/include/basic/sbxvar.hxx
+++ b/include/basic/sbxvar.hxx
@@ -58,7 +58,6 @@ struct SbxValues
         sal_Int16*      pInteger;
         sal_uInt32*     pULong;
         sal_Int32*      pLong;
-        int*            pInt;
         sal_uInt64*     puInt64;
         sal_Int64*      pnInt64;
 
diff --git a/include/vcl/outdev.hxx b/include/vcl/outdev.hxx
index f3a407eae2e4..90591a9c00a0 100644
--- a/include/vcl/outdev.hxx
+++ b/include/vcl/outdev.hxx
@@ -403,7 +403,6 @@ private:
     mutable bool                    mbInitTextColor : 1;
     mutable bool                    mbInitClipRegion : 1;
     mutable bool                    mbClipRegionSet : 1;
-    mutable bool                    mbKerning : 1;
     mutable bool                    mbNewFont : 1;
     mutable bool                    mbTextLines : 1;
     mutable bool                    mbTextSpecial : 1;
diff --git a/vcl/source/app/svapp.cxx b/vcl/source/app/svapp.cxx
index 6184596f8ad5..ecd87c90637a 100644
--- a/vcl/source/app/svapp.cxx
+++ b/vcl/source/app/svapp.cxx
@@ -170,19 +170,11 @@ struct ImplPostEventData
     ImplSVEvent *   mnEventId;
     KeyEvent        maKeyEvent;
     MouseEvent      maMouseEvent;
-    ZoomEvent       maZoomEvent;
-    ScrollEvent     maScrollEvent;
 
-       ImplPostEventData( VclEventId nEvent, vcl::Window* pWin, const KeyEvent& rKeyEvent ) :
+    ImplPostEventData( VclEventId nEvent, vcl::Window* pWin, const KeyEvent& rKeyEvent ) :
         mnEvent( nEvent ), mpWin( pWin ), mnEventId( nullptr ), maKeyEvent( rKeyEvent ) {}
-       ImplPostEventData( VclEventId nEvent, vcl::Window* pWin, const MouseEvent& rMouseEvent ) :
+    ImplPostEventData( VclEventId nEvent, vcl::Window* pWin, const MouseEvent& rMouseEvent ) :
         mnEvent( nEvent ), mpWin( pWin ), mnEventId( nullptr ), maMouseEvent( rMouseEvent ) {}
-#if !HAVE_FEATURE_DESKTOP
-       ImplPostEventData( VclEventId nEvent, vcl::Window* pWin, const ZoomEvent& rZoomEvent ) :
-        mnEvent( nEvent ), mpWin( pWin ), mnEventId( 0 ), maZoomEvent( rZoomEvent ) {}
-       ImplPostEventData( VclEventId nEvent, vcl::Window* pWin, const ScrollEvent& rScrollEvent ) :
-        mnEvent( nEvent ), mpWin( pWin ), mnEventId( 0 ), maScrollEvent( rScrollEvent ) {}
-#endif
 };
 
 Application* GetpApp()
diff --git a/xmlsecurity/inc/macrosecurity.hxx b/xmlsecurity/inc/macrosecurity.hxx
index b5bd77f61030..e02537c07c44 100644
--- a/xmlsecurity/inc/macrosecurity.hxx
+++ b/xmlsecurity/inc/macrosecurity.hxx
@@ -50,7 +50,6 @@ private:
     VclPtr<OKButton>           m_pOkBtn;
     VclPtr<PushButton>         m_pResetBtn;
 
-    css::uno::Reference< css::uno::XComponentContext >  mxCtx;
     css::uno::Reference< css::xml::crypto::XSecurityEnvironment >  mxSecurityEnvironment;
     SvtSecurityOptions                                          maSecOptions;
 
@@ -63,7 +62,6 @@ private:
     DECL_LINK(          OkBtnHdl, Button*, void );
 public:
     MacroSecurity(vcl::Window* pParent,
-        const css::uno::Reference< css::uno::XComponentContext>& rxCtx,
         const css::uno::Reference< css::xml::crypto::XSecurityEnvironment >& rxSecurityEnvironment);
     virtual ~MacroSecurity() override;
     virtual void dispose() override;
diff --git a/xmlsecurity/source/component/documentdigitalsignatures.cxx b/xmlsecurity/source/component/documentdigitalsignatures.cxx
index 34bce199d2fb..95f249af12b6 100644
--- a/xmlsecurity/source/component/documentdigitalsignatures.cxx
+++ b/xmlsecurity/source/component/documentdigitalsignatures.cxx
@@ -400,7 +400,7 @@ void DocumentDigitalSignatures::manageTrustedSources(  )
     if (aSignatureManager.init())
         xSecEnv = aSignatureManager.getSecurityEnvironment();
 
-    ScopedVclPtrInstance< MacroSecurity > aDlg( nullptr, mxCtx, xSecEnv );
+    ScopedVclPtrInstance< MacroSecurity > aDlg( nullptr, xSecEnv );
     aDlg->Execute();
 }
 
diff --git a/xmlsecurity/source/dialogs/macrosecurity.cxx b/xmlsecurity/source/dialogs/macrosecurity.cxx
index ac06fabfaac3..63a112361280 100644
--- a/xmlsecurity/source/dialogs/macrosecurity.cxx
+++ b/xmlsecurity/source/dialogs/macrosecurity.cxx
@@ -56,10 +56,8 @@ IMPL_LINK_NOARG(MacroSecurity, OkBtnHdl, Button*, void)
 }
 
 MacroSecurity::MacroSecurity( vcl::Window* _pParent,
-    const css::uno::Reference< css::uno::XComponentContext> &_rxCtx,
     const css::uno::Reference< css::xml::crypto::XSecurityEnvironment >& _rxSecurityEnvironment)
     : TabDialog(_pParent, "MacroSecurityDialog", "xmlsec/ui/macrosecuritydialog.ui")
-    , mxCtx(_rxCtx)
     , mxSecurityEnvironment(_rxSecurityEnvironment)
 {
     get(m_pTabCtrl, "tabcontrol");


More information about the Libreoffice-commits mailing list