Kaydet (Commit) f2736763 authored tarafından Noel Grandin's avatar Noel Grandin

update unusedfields plugin to use new clang warn_unused attribute support

Change-Id: I7b84de29b672e40cbf3c3d340d235f334d2be8cb
üst c18c50cd
...@@ -41,6 +41,7 @@ struct MyFieldInfo ...@@ -41,6 +41,7 @@ struct MyFieldInfo
{ {
std::string parentClass; std::string parentClass;
std::string fieldName; std::string fieldName;
std::string fieldType;
std::string sourceLocation; std::string sourceLocation;
bool operator < (const MyFieldInfo &other) const bool operator < (const MyFieldInfo &other) const
...@@ -77,7 +78,7 @@ public: ...@@ -77,7 +78,7 @@ public:
output += "touch:\t" + s.parentClass + "\t" + s.fieldName + "\n"; output += "touch:\t" + s.parentClass + "\t" + s.fieldName + "\n";
for (const MyFieldInfo & s : definitionSet) 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; ofstream myfile;
myfile.open( SRCDIR "/unusedfields.log", ios::app | ios::out); myfile.open( SRCDIR "/unusedfields.log", ios::app | ios::out);
...@@ -101,6 +102,7 @@ MyFieldInfo UnusedFields::niceName(const FieldDecl* fieldDecl) ...@@ -101,6 +102,7 @@ MyFieldInfo UnusedFields::niceName(const FieldDecl* fieldDecl)
MyFieldInfo aInfo; MyFieldInfo aInfo;
aInfo.parentClass = fieldDecl->getParent()->getQualifiedNameAsString(); aInfo.parentClass = fieldDecl->getParent()->getQualifiedNameAsString();
aInfo.fieldName = fieldDecl->getNameAsString(); aInfo.fieldName = fieldDecl->getNameAsString();
aInfo.fieldType = fieldDecl->getType().getAsString();
SourceLocation expansionLoc = compiler.getSourceManager().getExpansionLoc( fieldDecl->getLocation() ); SourceLocation expansionLoc = compiler.getSourceManager().getExpansionLoc( fieldDecl->getLocation() );
StringRef name = compiler.getSourceManager().getFilename(expansionLoc); StringRef name = compiler.getSourceManager().getFilename(expansionLoc);
...@@ -181,28 +183,10 @@ bool UnusedFields::VisitFieldDecl( const FieldDecl* fieldDecl ) ...@@ -181,28 +183,10 @@ bool UnusedFields::VisitFieldDecl( const FieldDecl* fieldDecl )
if( CXXRecordDecl* recordDecl = type->getAsCXXRecordDecl() ) if( CXXRecordDecl* recordDecl = type->getAsCXXRecordDecl() )
{ {
bool warn_unused = false; bool warn_unused = recordDecl->hasAttr<WarnUnusedAttr>();
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;
}
}
}
if( !warn_unused ) if( !warn_unused )
{ {
string n = recordDecl->getQualifiedNameAsString(); string n = recordDecl->getQualifiedNameAsString();
if( n == "rtl::OUString" )
warn_unused = true;
// Check some common non-LO types. // Check some common non-LO types.
if( n == "std::string" || n == "std::basic_string" if( n == "std::string" || n == "std::basic_string"
|| n == "std::list" || n == "std::__debug::list" || n == "std::list" || n == "std::__debug::list"
......
...@@ -6,6 +6,7 @@ import io ...@@ -6,6 +6,7 @@ import io
definitionSet = set() definitionSet = set()
definitionToSourceLocationMap = dict() definitionToSourceLocationMap = dict()
definitionToTypeMap = dict()
callSet = set() callSet = set()
sourceLocationSet = set() sourceLocationSet = set()
# things we need to exclude for reasons like : # things we need to exclude for reasons like :
...@@ -26,12 +27,14 @@ with io.open(sys.argv[1], "rb", buffering=1024*1024) as txt: ...@@ -26,12 +27,14 @@ with io.open(sys.argv[1], "rb", buffering=1024*1024) as txt:
if line.startswith("definition:\t"): if line.startswith("definition:\t"):
idx1 = line.find("\t",12) idx1 = line.find("\t",12)
idx2 = line.find("\t",idx1+1) 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) 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"): elif line.startswith("touch:\t"):
idx1 = line.find("\t",7) 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) callSet.add(callInfo)
# Invert the definitionToSourceLocationMap # Invert the definitionToSourceLocationMap
...@@ -67,7 +70,7 @@ for d in definitionSet: ...@@ -67,7 +70,7 @@ for d in definitionSet:
or srcLoc.startswith("vcl/inc/unx/gtk/gloactiongroup.h")): or srcLoc.startswith("vcl/inc/unx/gtk/gloactiongroup.h")):
continue 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 # 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]+)')): def natural_sort_key(s, _nsre=re.compile('([0-9]+)')):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment