diff options
Diffstat (limited to 'compilerplugins')
-rw-r--r-- | compilerplugins/clang/unusedfields.cxx | 24 | ||||
-rwxr-xr-x | compilerplugins/clang/unusedfields.py | 11 |
2 files changed, 11 insertions, 24 deletions
diff --git a/compilerplugins/clang/unusedfields.cxx b/compilerplugins/clang/unusedfields.cxx index 3d4abe79fa34..d87c40e92a17 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 7325175d5d3d..7fc6d4aeb2e4 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]+)')): |