[Libreoffice-commits] core.git: 2 commits - compilerplugins/clang include/cppuhelper include/tools

Noel Grandin noel at peralex.com
Tue Nov 24 01:05:40 PST 2015


 compilerplugins/clang/unusedfields.cxx |   24 ++++--------------------
 compilerplugins/clang/unusedfields.py  |   11 +++++++----
 include/cppuhelper/weakref.hxx         |    2 +-
 include/tools/ref.hxx                  |    2 +-
 4 files changed, 13 insertions(+), 26 deletions(-)

New commits:
commit f273676325d1865bc08d9617ae2d7c736f6ff8ca
Author: Noel Grandin <noel at peralex.com>
Date:   Tue Nov 24 11:04:21 2015 +0200

    update unusedfields plugin to use new clang warn_unused attribute support
    
    Change-Id: I7b84de29b672e40cbf3c3d340d235f334d2be8cb

diff --git a/compilerplugins/clang/unusedfields.cxx b/compilerplugins/clang/unusedfields.cxx
index 3d4abe7..d87c40e 100644
--- a/compilerplugins/clang/unusedfields.cxx
+++ b/compilerplugins/clang/unusedfields.cxx
@@ -41,6 +41,7 @@ struct MyFieldInfo
 {
     std::string parentClass;
     std::string fieldName;
+    std::string fieldType;
     std::string sourceLocation;
 
     bool operator < (const MyFieldInfo &other) const
@@ -77,7 +78,7 @@ public:
             output += "touch:\t" + s.parentClass + "\t" + s.fieldName + "\n";
         for (const MyFieldInfo & s : definitionSet)
         {
-            output += "definition:\t" + s.parentClass + "\t" + s.fieldName + "\t" + s.sourceLocation + "\n";
+            output += "definition:\t" + s.parentClass + "\t" + s.fieldName + "\t" + s.fieldType + "\t" + s.sourceLocation + "\n";
         }
         ofstream myfile;
         myfile.open( SRCDIR "/unusedfields.log", ios::app | ios::out);
@@ -101,6 +102,7 @@ MyFieldInfo UnusedFields::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);
@@ -181,28 +183,10 @@ bool UnusedFields::VisitFieldDecl( const FieldDecl* fieldDecl )
 
     if( CXXRecordDecl* recordDecl = type->getAsCXXRecordDecl() )
     {
-        bool warn_unused = false;
-        if( recordDecl->hasAttrs())
-        {
-                // Clang currently has no support for custom attributes, but
-                // the annotate attribute comes close, so check for __attribute__((annotate("lo_warn_unused")))
-                for( specific_attr_iterator<AnnotateAttr> i = recordDecl->specific_attr_begin<AnnotateAttr>(),
-                 e = recordDecl->specific_attr_end<AnnotateAttr>();
-                 i != e;
-                 ++i )
-                {
-                    if( (*i)->getAnnotation() == "lo_warn_unused" )
-                    {
-                        warn_unused = true;
-                        break;
-                    }
-                }
-        }
+        bool warn_unused = recordDecl->hasAttr<WarnUnusedAttr>();
         if( !warn_unused )
         {
             string n = recordDecl->getQualifiedNameAsString();
-            if( n == "rtl::OUString" )
-                warn_unused = true;
             // Check some common non-LO types.
             if( n == "std::string" || n == "std::basic_string"
                 || n == "std::list" || n == "std::__debug::list"
diff --git a/compilerplugins/clang/unusedfields.py b/compilerplugins/clang/unusedfields.py
index 7325175..7fc6d4a 100755
--- a/compilerplugins/clang/unusedfields.py
+++ b/compilerplugins/clang/unusedfields.py
@@ -6,6 +6,7 @@ import io
 
 definitionSet = set()
 definitionToSourceLocationMap = dict()
+definitionToTypeMap = dict()
 callSet = set()
 sourceLocationSet = set()
 # things we need to exclude for reasons like :
@@ -26,12 +27,14 @@ with io.open(sys.argv[1], "rb", buffering=1024*1024) as txt:
         if line.startswith("definition:\t"):
             idx1 = line.find("\t",12)
             idx2 = line.find("\t",idx1+1)
-            funcInfo = (normalizeTypeParams(line[12:idx1]), normalizeTypeParams(line[idx1+1:idx2]))
+            idx3 = line.find("\t",idx2+1)
+            funcInfo = (normalizeTypeParams(line[12:idx1]), line[idx1+1:idx2])
             definitionSet.add(funcInfo)
-            definitionToSourceLocationMap[funcInfo] = line[idx2+1:].strip()
+            definitionToTypeMap[funcInfo] = line[idx2+1:idx3].strip()
+            definitionToSourceLocationMap[funcInfo] = line[idx3+1:].strip()
         elif line.startswith("touch:\t"):
             idx1 = line.find("\t",7)
-            callInfo = (normalizeTypeParams(line[7:idx1]), normalizeTypeParams(line[idx1+1:].strip()))
+            callInfo = (normalizeTypeParams(line[7:idx1]), line[idx1+1:].strip())
             callSet.add(callInfo)
 
 # Invert the definitionToSourceLocationMap
@@ -67,7 +70,7 @@ for d in definitionSet:
         or srcLoc.startswith("vcl/inc/unx/gtk/gloactiongroup.h")):
         continue
 
-    tmp1set.add((clazz, srcLoc))
+    tmp1set.add((clazz + " " + definitionToTypeMap[d], srcLoc))
 
 # sort the results using a "natural order" so sequences like [item1,item2,item10] sort nicely
 def natural_sort_key(s, _nsre=re.compile('([0-9]+)')):
commit c18c50cda347e239ed48f2e390f3f6a65533a3b0
Author: Noel Grandin <noel at peralex.com>
Date:   Tue Nov 24 10:56:03 2015 +0200

    add SAL_WARN_UNUSED to css::uno::WeakReference and SvCompatWeakRef
    
    Change-Id: Idb784d398ed22f2291f1beaffb82f68642d68bcd

diff --git a/include/cppuhelper/weakref.hxx b/include/cppuhelper/weakref.hxx
index 8494ddd..458bd93 100644
--- a/include/cppuhelper/weakref.hxx
+++ b/include/cppuhelper/weakref.hxx
@@ -119,7 +119,7 @@ protected:
     @tparam interface_type type of interface
 */
 template< class interface_type >
-class WeakReference : public WeakReferenceHelper
+class SAL_WARN_UNUSED WeakReference : public WeakReferenceHelper
 {
 public:
     /** Default ctor.  Creates an empty weak reference.
diff --git a/include/tools/ref.hxx b/include/tools/ref.hxx
index 45070a2..9cd1bf5 100644
--- a/include/tools/ref.hxx
+++ b/include/tools/ref.hxx
@@ -183,7 +183,7 @@ public:
 /** We only have one weak reference in LO, in include/sfx2/frame.hxx, class SfxFrameWeak.
 */
 template<typename T>
-class SvCompatWeakRef
+class SAL_WARN_UNUSED SvCompatWeakRef
 {
     tools::SvRef< SvCompatWeakHdl<T> > _xHdl;
 public:


More information about the Libreoffice-commits mailing list