diff options
author | Noel Grandin <noel@peralex.com> | 2015-09-30 10:29:19 +0200 |
---|---|---|
committer | Noel Grandin <noelgrandin@gmail.com> | 2015-10-01 10:43:24 +0000 |
commit | 58aea3f36c14414f95668e229a7350598f6c53a8 (patch) | |
tree | 70c115dffd44576313cefd49e4164d293895e4bd /compilerplugins | |
parent | 3fcbfe10857631212d8b8db9a079bb9692ed78bc (diff) |
loplugin:unusedmethods
- improvements to the plugin to find more method calls
- improvements to python script to remove more false+
- fix the FORCE_COMPILE_ALL build flag to include code in
the $WORKDIR
Change-Id: I4d6015dcb9b9d60c26f0bcee8abad807177a7836
Reviewed-on: https://gerrit.libreoffice.org/19064
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Noel Grandin <noelgrandin@gmail.com>
Diffstat (limited to 'compilerplugins')
-rw-r--r-- | compilerplugins/clang/unusedmethods.cxx | 95 | ||||
-rwxr-xr-x | compilerplugins/clang/unusedmethods.py | 274 |
2 files changed, 158 insertions, 211 deletions
diff --git a/compilerplugins/clang/unusedmethods.cxx b/compilerplugins/clang/unusedmethods.cxx index fa62ce58e0d1..31ff68da6093 100644 --- a/compilerplugins/clang/unusedmethods.cxx +++ b/compilerplugins/clang/unusedmethods.cxx @@ -39,9 +39,27 @@ TODO deal with calls to superclass/member constructors from other constructors, namespace { +struct MyFuncInfo +{ + std::string returnType; + std::string nameAndParams; + std::string sourceLocation; + + bool operator < (const MyFuncInfo &other) const + { + if (returnType < other.returnType) + return true; + else if (returnType == other.returnType) + return nameAndParams < other.nameAndParams; + else + return false; + } +}; + + // try to limit the voluminous output a little -static std::set<std::string> callSet; -static std::set<std::string> definitionSet; +static std::set<MyFuncInfo> callSet; +static std::set<MyFuncInfo> definitionSet; class UnusedMethods: @@ -57,10 +75,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 std::string & s : callSet) - output += "call:\t" + s + "\t\n"; - for (const std::string & s : definitionSet) - output += "definition:\t" + s + "\t\n"; + for (const MyFuncInfo & s : callSet) + output += "call:\t" + s.returnType + "\t" + s.nameAndParams + "\n"; + for (const MyFuncInfo & s : definitionSet) + output += "definition:\t" + s.returnType + "\t" + s.nameAndParams + "\t" + s.sourceLocation + "\n"; ofstream myfile; myfile.open( SRCDIR "/unusedmethods.log", ios::app | ios::out); myfile << output; @@ -72,9 +90,12 @@ public: bool VisitDeclRefExpr( const DeclRefExpr* ); bool VisitCXXConstructExpr( const CXXConstructExpr* ); bool VisitVarDecl( const VarDecl* ); +private: + void logCallToRootMethods(const FunctionDecl* functionDecl); + MyFuncInfo niceName(const FunctionDecl* functionDecl); }; -static std::string niceName(const FunctionDecl* functionDecl) +MyFuncInfo UnusedMethods::niceName(const FunctionDecl* functionDecl) { if (functionDecl->getInstantiatedFromMemberFunction()) functionDecl = functionDecl->getInstantiatedFromMemberFunction(); @@ -86,31 +107,36 @@ static std::string niceName(const FunctionDecl* functionDecl) functionDecl = functionDecl->getTemplateInstantiationPattern(); #endif - std::string s = - compat::getReturnType(*functionDecl).getCanonicalType().getAsString() - + " "; + MyFuncInfo aInfo; + aInfo.returnType = compat::getReturnType(*functionDecl).getCanonicalType().getAsString(); + if (isa<CXXMethodDecl>(functionDecl)) { const CXXRecordDecl* recordDecl = dyn_cast<CXXMethodDecl>(functionDecl)->getParent(); - s += recordDecl->getQualifiedNameAsString(); - s += "::"; + aInfo.nameAndParams += recordDecl->getQualifiedNameAsString(); + aInfo.nameAndParams += "::"; } - s += functionDecl->getNameAsString() + "("; + aInfo.nameAndParams += functionDecl->getNameAsString() + "("; bool bFirst = true; for (const ParmVarDecl *pParmVarDecl : functionDecl->params()) { if (bFirst) bFirst = false; else - s += ","; - s += pParmVarDecl->getType().getCanonicalType().getAsString(); + aInfo.nameAndParams += ","; + aInfo.nameAndParams += pParmVarDecl->getType().getCanonicalType().getAsString(); } - s += ")"; + aInfo.nameAndParams += ")"; if (isa<CXXMethodDecl>(functionDecl) && dyn_cast<CXXMethodDecl>(functionDecl)->isConst()) { - s += " const"; + aInfo.nameAndParams += " const"; } - return s; + + SourceLocation expansionLoc = compiler.getSourceManager().getExpansionLoc( functionDecl->getLocation() ); + StringRef name = compiler.getSourceManager().getFilename(expansionLoc); + aInfo.sourceLocation = std::string(name.substr(strlen(SRCDIR)+1)) + ":" + std::to_string(compiler.getSourceManager().getSpellingLineNumber(expansionLoc)); + + return aInfo; } -static void logCallToRootMethods(const FunctionDecl* functionDecl) +void UnusedMethods::logCallToRootMethods(const FunctionDecl* functionDecl) { functionDecl = functionDecl->getCanonicalDecl(); bool bPrinted = false; @@ -127,8 +153,7 @@ static void logCallToRootMethods(const FunctionDecl* functionDecl) } if (!bPrinted) { - std::string s = niceName(functionDecl); - callSet.insert(s); + callSet.insert(niceName(functionDecl)); } } @@ -170,8 +195,36 @@ bool UnusedMethods::VisitCallExpr(CallExpr* expr) FunctionDecl* calleeFunctionDecl = expr->getDirectCallee(); if (calleeFunctionDecl == nullptr) { + Expr* callee = expr->getCallee()->IgnoreParenImpCasts(); + DeclRefExpr* dr = dyn_cast<DeclRefExpr>(callee); + if (dr) { + calleeFunctionDecl = dyn_cast<FunctionDecl>(dr->getDecl()); + if (calleeFunctionDecl) + goto gotfunc; + } + /* + // ignore case where we can't determine the target of the call because we're inside a template + if (isa<CXXDependentScopeMemberExpr>(callee)) + return true; + if (isa<UnresolvedLookupExpr>(callee)) + return true; + if (isa<UnresolvedMemberExpr>(callee)) + return true; + if (isa<DependentScopeDeclRefExpr>(callee)) + return true; + // ignore this, doesn't really exist (side-effect of template expansion on scalar types) + if (isa<CXXPseudoDestructorExpr>(callee)) + return true; + expr->dump(); + std::string name = compiler.getSourceManager().getFilename(expansionLoc); + std::string sourceLocation = name + ":" + std::to_string(compiler.getSourceManager().getSpellingLineNumber(expansionLoc)); + cout << sourceLocation << endl; + throw "Cant touch this"; + */ return true; } + +gotfunc: // if we see a call to a function, it may effectively create new code, // if the function is templated. However, if we are inside a template function, // calling another function on the same template, the same problem occurs. diff --git a/compilerplugins/clang/unusedmethods.py b/compilerplugins/clang/unusedmethods.py index 3bc61b8b673c..f2b9e5c4cf54 100755 --- a/compilerplugins/clang/unusedmethods.py +++ b/compilerplugins/clang/unusedmethods.py @@ -1,8 +1,10 @@ #!/usr/bin/python import sys +import re definitionSet = set() +definitionToSourceLocationMap = dict() callSet = set() # things we need to exclude for reasons like : # - it's a weird template thingy that confuses the plugin @@ -18,91 +20,6 @@ exclusionSet = set([ "class XMLPropertyBackpatcher<short> & XMLTextImportHelper::GetSequenceIdBP()", "void XclExpPivotCache::SaveXml(class XclExpXmlStream &)", - # used from a yacc lexer - "struct unoidl::detail::SourceProviderExpr unoidl::detail::SourceProviderExpr::Float(double)", - "struct unoidl::detail::SourceProviderExpr unoidl::detail::SourceProviderExpr::Int(long)", - "struct unoidl::detail::SourceProviderExpr unoidl::detail::SourceProviderExpr::Uint(unsigned long)", - "struct unoidl::detail::SourceProviderExpr unoidl::detail::SourceProviderExpr::Bool(_Bool)", - "class rtl::OUString unoidl::detail::SourceProviderType::getName() const", - "_Bool unoidl::detail::SourceProviderType::equals(const struct unoidl::detail::SourceProviderType &) const", - "_Bool unoidl::detail::SourceProviderEntityPad::isPublished() const", - "_Bool unoidl::detail::SourceProviderInterfaceTypeEntityPad::checkMemberClashes(int,void *,struct unoidl::detail::SourceProviderScannerData *,const class rtl::OUString &,const class rtl::OUString &,_Bool) const", - "_Bool unoidl::detail::SourceProviderInterfaceTypeEntityPad::checkBaseClashes(int,void *,struct unoidl::detail::SourceProviderScannerData *,const class rtl::OUString &,const class rtl::Reference<class unoidl::InterfaceTypeEntity> &,_Bool,_Bool,_Bool,class std::__debug::set<class rtl::OUString, struct std::less<class rtl::OUString>, class std::allocator<class rtl::OUString> > *) const", - "_Bool unoidl::detail::SourceProviderInterfaceTypeEntityPad::addDirectBase(int,void *,struct unoidl::detail::SourceProviderScannerData *,const struct unoidl::detail::SourceProviderInterfaceTypeEntityPad::DirectBase &,_Bool)", - "_Bool unoidl::detail::SourceProviderInterfaceTypeEntityPad::addBase(int,void *,struct unoidl::detail::SourceProviderScannerData *,const class rtl::OUString &,const class rtl::OUString &,const class rtl::Reference<class unoidl::InterfaceTypeEntity> &,_Bool,_Bool)", - "_Bool unoidl::detail::SourceProviderInterfaceTypeEntityPad::addDirectMember(int,void *,struct unoidl::detail::SourceProviderScannerData *,const class rtl::OUString &)", - "_Bool unoidl::detail::SourceProviderInterfaceTypeEntityPad::addOptionalBaseMembers(int,void *,struct unoidl::detail::SourceProviderScannerData *,const class rtl::OUString &,const class rtl::Reference<class unoidl::InterfaceTypeEntity> &)", - "void unoidl::detail::SourceProviderScannerData::setSource(const void *,unsigned long)", - "void Idlc::setParseState(enum ParseState)", - "_Bool AstDeclaration::isPredefined()", - "void Idlc::setOffset(unsigned int,unsigned int)", - "_Bool Idlc::isInMainFile()", - "void Idlc::setPublished(_Bool)", - "enum ParseState Idlc::getParseState()", - "void Idlc::setLineNumber(unsigned int)", - "void Idlc::incLineNumber()", - "void Idlc::setDocumentation(const class rtl::OString &)", - "void Idlc::setInMainfile(_Bool)", - "void AstInterface::forwardDefined(const class AstInterface &)", - "_Bool AstInterface::hasMandatoryInheritedInterfaces() const", - "_Bool AstInterface::usesSingleInheritance() const", - "struct AstInterface::DoubleDeclarations AstInterface::checkInheritedInterfaceClashes(const class AstInterface *,_Bool) const", - "class std::__debug::vector<struct AstInterface::DoubleMemberDeclaration, class std::allocator<struct AstInterface::DoubleMemberDeclaration> > AstInterface::checkMemberClashes(const class AstDeclaration *) const", - "void AstOperation::setExceptions(const class std::__debug::list<class AstDeclaration *, class std::allocator<class AstDeclaration *> > *)", - "_Bool AstOperation::isConstructor() const", - "_Bool AstService::isSingleInterfaceBasedService() const", - "void AstService::setSingleInterfaceBasedService()", - "void AstService::setDefaultConstructor(_Bool)", - "_Bool AstService::checkLastConstructor() const", - "class AstScope * AstStack::nextToTop()", - "class AstScope * AstStack::bottom()", - "const class AstDeclaration * AstStruct::findTypeParameter(const class rtl::OString &) const", - "int AstEnum::getEnumValueCount()", - "class AstConstant * AstEnum::checkValue(class AstExpression *)", - "void ErrorHandler::flagError(enum ErrorCode,unsigned int)", - "void ErrorHandler::error0(enum ErrorCode)", - "void ErrorHandler::syntaxError(enum ParseState,int,const char *)", - "void ErrorHandler::lookupError(enum ErrorCode,const class rtl::OString &,class AstDeclaration *)", - "void ErrorHandler::error3(enum ErrorCode,class AstDeclaration *,class AstDeclaration *,class AstDeclaration *)", - "void ErrorHandler::warning0(enum WarningCode,const char *)", - "void ErrorHandler::coercionError(class AstExpression *,enum ExprType)", - "class AstDeclaration * FeInheritanceHeader::getInherits()", - "const class std::__debug::vector<class rtl::OString, class std::allocator<class rtl::OString> > & FeInheritanceHeader::getTypeParameters() const", - "const class AstType * FeDeclarator::compose(const class AstDeclaration *)", - "const class AstType * AstStructInstance::getTypeTemplate() const", - "class __gnu_debug::_Safe_iterator<struct std::__cxx1998::_List_const_iterator<class AstDeclaration *>, class std::__debug::list<class AstDeclaration *, class std::allocator<class AstDeclaration *> > > AstStructInstance::getTypeArgumentsBegin() const", - "class __gnu_debug::_Safe_iterator<struct std::__cxx1998::_List_const_iterator<class AstDeclaration *>, class std::__debug::list<class AstDeclaration *, class std::allocator<class AstDeclaration *> > > AstStructInstance::getTypeArgumentsEnd() const", - "void AstAttribute::setExceptions(const class rtl::OUString *,const class std::__debug::list<class AstDeclaration *, class std::allocator<class AstDeclaration *> > *,const class rtl::OUString *,const class std::__debug::list<class AstDeclaration *, class std::allocator<class AstDeclaration *> > *)", - - "const class rtl::OString & FeDeclarator::getName()", - "_Bool FeDeclarator::checkType(const class AstDeclaration *)", - "enum connectivity::IParseContext::InternationalKeyCode connectivity::IParseContext::getIntlKeyCode(const class rtl::OString &) const", - "void connectivity::OSQLParser::error(const char *)", - "int connectivity::OSQLParser::SQLlex()", - "void connectivity::OSQLParseNode::insert(unsigned int,class connectivity::OSQLParseNode *)", - "const class rtl::OUString & connectivity::OSQLParser::getFieldName() const", - "short connectivity::OSQLParser::buildLikeRule(class connectivity::OSQLParseNode *,class connectivity::OSQLParseNode *&,const class connectivity::OSQLParseNode *)", - "void connectivity::OSQLParser::reduceLiteral(class connectivity::OSQLParseNode *&,_Bool)", - "short connectivity::OSQLParser::buildComparsionRule(class connectivity::OSQLParseNode *&,class connectivity::OSQLParseNode *)", - "enum connectivity::IParseContext::InternationalKeyCode connectivity::OSQLScanner::getInternationalTokenID(const char *) const", - "class rtl::OString connectivity::OSQLScanner::getStatement() const", - "void connectivity::OSQLScanner::SQLyyerror(const char *)", - "int connectivity::OSQLScanner::GetCurrentPos() const", - "int connectivity::OSQLScanner::SQLyygetc()", - "void connectivity::OSQLParser::setParseTree(class connectivity::OSQLParseNode *)", - "short connectivity::OSQLParser::buildPredicateRule(class connectivity::OSQLParseNode *&,class connectivity::OSQLParseNode *const,class connectivity::OSQLParseNode *,class connectivity::OSQLParseNode *)", - "int connectivity::OSQLScanner::SQLlex()", - - "const struct RSCINST & ObjectStack::Top()", - "void ObjectStack::Push(struct RSCINST)", - "_Bool RefNode::PutObjNode(class ObjNode *)", - "void RscFileInst::SetFileIndex(unsigned long)", - "void RscFileInst::SetLineNo(unsigned int)", - "class RscDefine * RscFileTab::NewDef(unsigned long,const class rtl::OString &,class RscExpression *,unsigned long)", - "class RscDefine * RscFileTab::NewDef(unsigned long,const class rtl::OString &,int,unsigned long)", - "class RscTop * RscTypCont::GetRoot()", - "class RscTop * RscTypCont::SearchType(unsigned int)", - "void RscTypCont::InsertType(class RscTop *)", # TODO track instantiations of template class constructors "void comphelper::IEventProcessor::release()", @@ -149,68 +66,6 @@ exclusionSet = set([ "void oox::PropertyMap::dumpCode(class com::sun::star::uno::Reference<class com::sun::star::beans::XPropertySet>)", "void oox::PropertyMap::dumpData(class com::sun::star::uno::Reference<class com::sun::star::beans::XPropertySet>)", "class std::basic_string<char, struct std::char_traits<char>, class std::allocator<char> > writerfilter::ooxml::OOXMLPropertySet::toString()", - # called from the writerfilter generated code in $WORKDIR, not sure why it is not being picked up - "_Bool writerfilter::ooxml::OOXMLFactory_ns::getElementId(unsigned int,unsigned int,enum writerfilter::ooxml::ResourceType_t &,unsigned int &)", - "void writerfilter::ooxml::OOXMLFastContextHandler::setDefaultIntegerValue()", - "void writerfilter::ooxml::OOXMLFastContextHandler::positivePercentage(const class rtl::OUString &)", - "void writerfilter::ooxml::OOXMLFastContextHandler::positionOffset(const class rtl::OUString &)", - "void writerfilter::ooxml::OOXMLFastContextHandler::alignH(const class rtl::OUString &)", - "void writerfilter::ooxml::OOXMLFastContextHandler::alignV(const class rtl::OUString &)", - "void writerfilter::ooxml::OOXMLFastContextHandler::setDefaultStringValue()", - "void writerfilter::ooxml::OOXMLFastContextHandler::clearProps()", - "void writerfilter::ooxml::OOXMLFastContextHandler::sendPropertiesWithId(const unsigned int &)", - "void writerfilter::ooxml::OOXMLFastContextHandler::cr()", - "void writerfilter::ooxml::OOXMLFastContextHandler::softHyphen()", - "void writerfilter::ooxml::OOXMLFastContextHandler::noBreakHyphen()", - "void writerfilter::ooxml::OOXMLFastContextHandler::setDefaultBooleanValue()", - "void writerfilter::ooxml::OOXMLFastContextHandler::endField()", - "void writerfilter::ooxml::OOXMLFastContextHandler::propagateCharacterPropertiesAsSet(const unsigned int &)", - "void writerfilter::ooxml::OOXMLFastContextHandler::tab()", - "void writerfilter::ooxml::OOXMLFastContextHandler::ftnednref()", - "void writerfilter::ooxml::OOXMLFastContextHandler::ftnednsep()", - "void writerfilter::ooxml::OOXMLFastContextHandler::ftnedncont()", - "void writerfilter::ooxml::OOXMLFastContextHandler::pgNum()", - "void writerfilter::ooxml::OOXMLFastContextHandler::sendRowProperties()", - "void writerfilter::ooxml::OOXMLFastContextHandler::setLastSectionGroup()", - "void writerfilter::ooxml::OOXMLFastContextHandler::endTxbxContent()", - "void writerfilter::ooxml::OOXMLFastContextHandler::setDefaultHexValue()", - "void writerfilter::ooxml::OOXMLFastContextHandlerProperties::handleComment()", - "void writerfilter::ooxml::OOXMLFastContextHandlerProperties::handleOLE()", - "void writerfilter::ooxml::OOXMLFastContextHandlerProperties::handlePicture()", - "void writerfilter::ooxml::OOXMLFastContextHandlerProperties::handleHdrFtr()", - "void writerfilter::ooxml::OOXMLFastContextHandlerProperties::handleBreak()", - "int writerfilter::ooxml::OOXMLPropertySetEntryToInteger::getValue() const", - "void writerfilter::ooxml::OOXMLFastContextHandler::fieldSeparator()", - "void writerfilter::ooxml::OOXMLFastContextHandler::startField()", - "void writerfilter::ooxml::OOXMLFastContextHandlerStream::sendProperty(unsigned int)", - "void writerfilter::ooxml::OOXMLFastContextHandlerProperties::handleXNotes()", - "void writerfilter::ooxml::OOXMLFastContextHandler::propagateTableProperties()", - "void writerfilter::ooxml::OOXMLFastContextHandlerTextTableRow::endRow()", - "void writerfilter::ooxml::OOXMLFastContextHandler::propagateCellProperties()", - "void writerfilter::ooxml::OOXMLFastContextHandler::endSdt()", - "void writerfilter::ooxml::OOXMLFastContextHandlerTextTableCell::endCell()", - "void writerfilter::ooxml::OOXMLFastContextHandler::propagateRowProperties()", - "void writerfilter::ooxml::OOXMLFastContextHandler::sendTableProperties()", - "_Bool writerfilter::ooxml::OOXMLPropertySetEntryToBool::getValue() const", - "void writerfilter::ooxml::OOXMLFastContextHandler::lockField()", - "void writerfilter::ooxml::OOXMLFastContextHandlerStream::handleHyperlink()", - "void writerfilter::ooxml::OOXMLFastContextHandler::setLastParagraphInSection()", - "void writerfilter::ooxml::OOXMLFastContextHandler::startSdt()", - "void writerfilter::ooxml::OOXMLFastContextHandler::setHandle()", - "void writerfilter::ooxml::OOXMLFastContextHandler::sendTableDepth() const", - "void writerfilter::ooxml::OOXMLFastContextHandler::startTxbxContent()", - "void writerfilter::ooxml::OOXMLFastContextHandler::handleLastParagraphInSection()", - "void writerfilter::ooxml::OOXMLFastContextHandlerTextTableCell::startCell()", - "void writerfilter::ooxml::OOXMLFastContextHandlerTextTableRow::startRow()", - "void writerfilter::ooxml::OOXMLFastContextHandler::propagateCharacterProperties()", - "void writerfilter::ooxml::OOXMLFastContextHandlerProperties::handleFontRel()", - "void writerfilter::ooxml::OOXMLFastContextHandler::ignore()", - "void writerfilter::ooxml::OOXMLFastContextHandler::resolvePropertySetAttrs()", - "void writerfilter::ooxml::OOXMLFastContextHandlerXNote::checkId(class std::shared_ptr<class writerfilter::ooxml::OOXMLValue>)", - "void writerfilter::ooxml::OOXMLFastContextHandlerTextTableRow::handleGridBefore(class std::shared_ptr<class writerfilter::ooxml::OOXMLValue>)", - "void writerfilter::ooxml::OOXMLFastContextHandlerXNote::checkType(class std::shared_ptr<class writerfilter::ooxml::OOXMLValue>)", - "void writerfilter::ooxml::OOXMLFastContextHandler::setXNoteId(class std::shared_ptr<class writerfilter::ooxml::OOXMLValue>)", - # deep template magic in SW "Ring<value_type> * sw::Ring::Ring_node_traits::get_next(const Ring<value_type> *)", "Ring<value_type> * sw::Ring::Ring_node_traits::get_previous(const Ring<value_type> *)", @@ -219,79 +74,118 @@ exclusionSet = set([ # I need to teach the plugin that for loops with range expressions call begin() and end() "class __gnu_debug::_Safe_iterator<class __gnu_cxx::__normal_iterator<class SwAnchoredObject *const *, class std::__cxx1998::vector<class SwAnchoredObject *, class std::allocator<class SwAnchoredObject *> > >, class std::__debug::vector<class SwAnchoredObject *, class std::allocator<class SwAnchoredObject *> > > SwSortedObjs::begin() const", "class __gnu_debug::_Safe_iterator<class __gnu_cxx::__normal_iterator<class SwAnchoredObject *const *, class std::__cxx1998::vector<class SwAnchoredObject *, class std::allocator<class SwAnchoredObject *> > >, class std::__debug::vector<class SwAnchoredObject *, class std::allocator<class SwAnchoredObject *> > > SwSortedObjs::end() const", + # loaded by dlopen() + "void * getStandardAccessibleFactory()", + "void * getSvtAccessibilityComponentFactory()", + "struct _rtl_uString * basicide_choose_macro(void *,unsigned char,struct _rtl_uString *)", + "void basicide_macro_organizer(short)", + "long basicide_handle_basic_error(void *)", + "class com::sun::star::uno::XInterface * org_libreoffice_chart2_Chart2ToolboxController(class com::sun::star::uno::XComponentContext *,const class com::sun::star::uno::Sequence<class com::sun::star::uno::Any> &)", + "class com::sun::star::uno::XInterface * org_libreoffice_comp_chart2_sidebar_ChartPanelFactory(class com::sun::star::uno::XComponentContext *,const class com::sun::star::uno::Sequence<class com::sun::star::uno::Any> &)", + "class chart::opengl::OpenglShapeFactory * getOpenglShapeFactory()", + "class VclAbstractDialogFactory * CreateDialogFactory()", + "_Bool GetSpecialCharsForEdit(class vcl::Window *,const class vcl::Font &,class rtl::OUString &)", + "const struct ImplTextEncodingData * sal_getFullTextEncodingData(unsigned short)" ]) -# The parsing here is designed to also grab output which is mixed into the output from gbuild. +# The parsing here is designed to avoid grabbing stuff which is mixed in from gbuild. # I have not yet found a way of suppressing the gbuild output. with open(sys.argv[1]) as txt: for line in txt: - if line.find("definition:\t") != -1: - idx1 = line.find("definition:\t") - idx2 = line.find("\t", idx1+12) - clazzName = line[idx1+12 : idx2] - definitionSet.add(clazzName) - elif line.find("call:\t") != -1: - idx1 = line.find("call:\t") - idx2 = line.find("\t", idx1+6) - clazzName = line[idx1+6 : idx2] - callSet.add(clazzName) + if line.startswith("definition:\t"): + tokens = line.split("\t") + funcInfo = (tokens[1], tokens[2]) + definitionSet.add(funcInfo) + definitionToSourceLocationMap[funcInfo] = tokens[3].strip() + elif line.startswith("call:\t"): + tokens = line.split("\t") + callSet.add((tokens[1], tokens[2].strip())) -for clazz in sorted(definitionSet - callSet - exclusionSet): +tmp1set = set() +for d in definitionSet: + clazz = d[0] + " " + d[1] + if clazz in exclusionSet: + continue + if d in callSet: + continue # ignore operators, they are normally called from inside STL code - if (clazz.find("::operator") != -1): + if "::operator" in d[1]: continue # ignore the custom RTTI stuff - if ( (clazz.find("::CreateType()") != -1) - or (clazz.find("::IsA(") != -1) - or (clazz.find("::Type()") != -1)): + if ( ("::CreateType()" in d[1]) + or ("::IsA(" in d[1]) + or ("::Type()" in d[1])): continue # if this method is const, and there is a non-const variant of it, and the non-const variant is in use, then leave it alone - if (clazz.startswith("const ") and clazz.endswith(" const")): - clazz2 = clazz[6:len(clazz)-6] - if (clazz2 in callSet): + if d[0].startswith("const ") and d[1].endswith(" const"): + if ((d[0][6:],d[1][:-6]) in callSet): continue - elif (clazz.endswith(" const")): + elif clazz.endswith(" const"): clazz2 = clazz[:len(clazz)-6] # strip off " const" - if (clazz2 in callSet): + if ((d[0],clazz2) in callSet): continue - if (clazz.endswith(" const") and clazz.find("::iterator") != -1): + if clazz.endswith(" const") and ("::iterator" in clazz): clazz2 = clazz[:len(clazz)-6] # strip off " const" clazz2 = clazz2.replace("::const_iterator", "::iterator") - if (clazz2 in callSet): + if ((d[0],clazz2) in callSet): continue # if this method is non-const, and there is a const variant of it, and the const variant is in use, then leave it alone - if ((not clazz.endswith(" const")) and ("const " + clazz + " const") in callSet): + if (not clazz.endswith(" const")) and ((d[0],"const " + clazz + " const") in callSet): continue - if ((not clazz.endswith(" const")) and clazz.find("::iterator") != -1): + if (not clazz.endswith(" const")) and ("::iterator" in clazz): clazz2 = clazz.replace("::iterator", "::const_iterator") + " const" - if (clazz2 in callSet): + if ((d[0],clazz2) in callSet): continue # There is lots of macro magic going on in SRCDIR/include/sax/fshelper.hxx that should be using C++11 varag templates - if clazz.startswith("void sax_fastparser::FastSerializerHelper::"): + if d[1].startswith("sax_fastparser::FastSerializerHelper::"): continue # used by Windows build - if (clazz.find("DdeTopic::") != -1 - or clazz.find("DdeData::") != -1 - or clazz.find("DdeService::") != -1 - or clazz.find("DdeTransaction::") != -1 - or clazz.find("DdeConnection::") != -1 - or clazz.find("DdeLink::") != -1 - or clazz.find("DdeItem::") != -1 - or clazz.find("DdeGetPutItem::") != -1): + if any(x in d[1] for x in ["DdeTopic::", "DdeData::", "DdeService::", "DdeTransaction::", "DdeConnection::", "DdeLink::", "DdeItem::", "DdeGetPutItem::"]): continue # the include/tools/rtti.hxx stuff - if (clazz.find("::StaticType()") != -1 - or clazz.find("::IsOf(void *(*)(void))") != -1): + if ("::StaticType()" in d[1]) or ("::IsOf(void *(*)(void))" in d[1]): continue # too much template magic here for my plugin - if (clazz.find(" cairocanvas::") != -1 - or clazz.find(" canvas::") != -1 - or clazz.find(" oglcanvas::") != -1 - or clazz.find(" vclcanvas::") != -1): + if ( ("cairocanvas::" in d[1]) + or ("canvas::" in d[1]) + or ("oglcanvas::" in d[1]) + or ("vclcanvas::" in d[1])): continue - print clazz - + # these are loaded by dlopen() from somewhere + if "get_implementation" in d[1]: + continue + if "component_getFactory" in d[1]: + continue + if d[0]=="_Bool" and "_supportsService(const class rtl::OUString &)" in d[1]: + continue + if (d[0]=="class com::sun::star::uno::Reference<class com::sun::star::uno::XInterface>" + and "Instance(const class com::sun::star::uno::Reference<class com::sun::star::lang::XMultiServiceFactory> &)" in d[1]): + continue + # ignore the Java symbols, loaded from the JavaVM + if d[1].startswith("Java_"): + continue + # ignore external code + if definitionToSourceLocationMap[d].startswith("external/"): + continue + # ignore the VCL_BUILDER_DECL_FACTORY stuff + if d[0]=="void" and d[1].startswith("make") and ("(class VclPtr<class vcl::Window> &" in d[1]): + continue + + tmp1set.add((clazz, definitionToSourceLocationMap[d])) + +def natural_sort_key(s, _nsre=re.compile('([0-9]+)')): + return [int(text) if text.isdigit() else text.lower() + for text in re.split(_nsre, s)] + +# sort results by name and line number +tmp1list = sorted(tmp1set, key=lambda v: natural_sort_key(v[1])) + +# print out the results +for t in tmp1list: + print t[1] + print " ", t[0] + # add an empty line at the end to make it easier for the unusedmethodsremove plugin to mmap() the output file |