update unusedfields plugin to use new clang warn_unused attribute support

Change-Id: I7b84de29b672e40cbf3c3d340d235f334d2be8cb
This commit is contained in:
Noel Grandin
2015-11-24 11:04:21 +02:00
parent c18c50cda3
commit f273676325
2 changed files with 11 additions and 24 deletions

View File

@@ -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"

View File

@@ -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]+)')):