From bd89dff26155800be457735a0252476b670ddbd2 Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Tue, 4 Oct 2016 09:29:36 +0200 Subject: loplugin:mergeclasses various fixes better tracking of templates, ignore more noise in the plugin so the python has less log to process Change-Id: I62874236d362529bd566140ac3fcc65e734fd62c --- compilerplugins/clang/mergeclasses.cxx | 74 ++++++++++-------------------- compilerplugins/clang/mergeclasses.py | 48 ++++++++++--------- compilerplugins/clang/mergeclasses.results | 32 ++++--------- 3 files changed, 58 insertions(+), 96 deletions(-) (limited to 'compilerplugins') diff --git a/compilerplugins/clang/mergeclasses.cxx b/compilerplugins/clang/mergeclasses.cxx index 20f3dc288ec3..fa4eb3c99a3b 100644 --- a/compilerplugins/clang/mergeclasses.cxx +++ b/compilerplugins/clang/mergeclasses.cxx @@ -70,28 +70,32 @@ public: myfile.close(); } + bool shouldVisitTemplateInstantiations () const { return true; } + bool VisitVarDecl(const VarDecl *); bool VisitFieldDecl(const FieldDecl *); bool VisitCXXConstructExpr( const CXXConstructExpr* var ); bool VisitCXXRecordDecl( const CXXRecordDecl* decl); - bool VisitFunctionDecl( const FunctionDecl* decl); - bool VisitCallExpr(const CallExpr* decl); }; bool startsWith(const std::string& rStr, const char* pSubStr) { return rStr.compare(0, strlen(pSubStr), pSubStr) == 0; } -void addToInstantiatedSet(const std::string& s) +bool ignoreClass(StringRef s) { // ignore stuff in the standard library, and UNO stuff we can't touch. if (startsWith(s, "rtl::") || startsWith(s, "sal::") || startsWith(s, "com::sun::") || startsWith(s, "std::") || startsWith(s, "boost::") || s == "OString" || s == "OUString" || s == "bad_alloc") { - return; + return true; + } + // ignore instantiations of pointers and arrays + if (s.endswith("*") || s.endswith("]")) { + return true; } - instantiatedSet.insert(s); + return false; } // check for implicit construction @@ -100,7 +104,9 @@ bool MergeClasses::VisitVarDecl( const VarDecl* pVarDecl ) if (ignoreLocation(pVarDecl)) { return true; } - addToInstantiatedSet(pVarDecl->getType().getAsString()); + std::string s = pVarDecl->getType().getAsString(); + if (!ignoreClass(s)) + instantiatedSet.insert(s); return true; } @@ -110,7 +116,9 @@ bool MergeClasses::VisitFieldDecl( const FieldDecl* pFieldDecl ) if (ignoreLocation(pFieldDecl)) { return true; } - addToInstantiatedSet(pFieldDecl->getType().getAsString()); + std::string s = pFieldDecl->getType().getAsString(); + if (!ignoreClass(s)) + instantiatedSet.insert(s); return true; } @@ -126,7 +134,8 @@ bool MergeClasses::VisitCXXConstructExpr( const CXXConstructExpr* pCXXConstructE const CXXConstructorDecl* pCXXConstructorDecl = pCXXConstructExpr->getConstructor(); const CXXRecordDecl* pParentCXXRecordDecl = pCXXConstructorDecl->getParent(); std::string s = pParentCXXRecordDecl->getQualifiedNameAsString(); - addToInstantiatedSet(s); + if (!ignoreClass(s)) + instantiatedSet.insert(s); return true; } @@ -135,63 +144,26 @@ bool MergeClasses::VisitCXXRecordDecl(const CXXRecordDecl* decl) if (ignoreLocation(decl)) { return true; } - if (decl->hasDefinition()) + if (decl->isThisDeclarationADefinition()) { SourceLocation spellingLocation = compiler.getSourceManager().getSpellingLoc(decl->getCanonicalDecl()->getLocStart()); std::string filename = compiler.getSourceManager().getFilename(spellingLocation); filename = filename.substr(strlen(SRCDIR)); - definitionMap.insert( std::pair(decl->getQualifiedNameAsString(), filename) ); + std::string s = decl->getQualifiedNameAsString(); + if (ignoreClass(s)) + return true; + definitionMap.insert( std::pair(s, filename) ); for (auto it = decl->bases_begin(); it != decl->bases_end(); ++it) { const CXXBaseSpecifier spec = *it; // need to look through typedefs, hence the getUnqualifiedDesugaredType QualType baseType = spec.getType().getDesugaredType(compiler.getASTContext()); - childToParentClassSet.insert( std::pair(decl->getQualifiedNameAsString(), baseType.getAsString()) ); + childToParentClassSet.insert( std::pair(s, baseType.getAsString()) ); } } return true; } -bool MergeClasses::VisitFunctionDecl(const FunctionDecl* decl) -{ - if (ignoreLocation(decl)) { - return true; - } - return true; -} - -bool startswith(const std::string& s, const std::string& prefix) -{ - return s.rfind(prefix,0) == 0; -} - -bool endswith(const std::string& s, const std::string& suffix) -{ - return s.rfind(suffix) == (s.size()-suffix.size()); -} - -bool MergeClasses::VisitCallExpr(const CallExpr* decl) -{ - if (ignoreLocation(decl)) { - return true; - } - // VclPtr::Create using a forwarding constructor, so we need to handle it differently in order - // to pick up the instantiation via it. - if (decl->getCalleeDecl() && isa(decl->getCalleeDecl())) - { - const CXXMethodDecl * pMethod = dyn_cast(decl->getCalleeDecl()); - std::string s = pMethod->getQualifiedNameAsString(); - if (startswith(s, "VclPtr<") && endswith(s, ">::Create")) - { - const ClassTemplateSpecializationDecl *pTemplateDecl = dyn_cast(pMethod->getParent()); - QualType windowType = pTemplateDecl->getTemplateArgs()[0].getAsType(); - instantiatedSet.insert(windowType.getAsString()); - } - } - return true; -} - - loplugin::Plugin::Registration< MergeClasses > X("mergeclasses", false); } diff --git a/compilerplugins/clang/mergeclasses.py b/compilerplugins/clang/mergeclasses.py index fc2aaa25beca..2af07ee3161d 100755 --- a/compilerplugins/clang/mergeclasses.py +++ b/compilerplugins/clang/mergeclasses.py @@ -11,20 +11,23 @@ with open("loplugin.mergeclasses.log") as txt: for line in txt: tokens = line.strip().split("\t") - if tokens[0] == "instantiated:": + if len(tokens) == 1: + pass + + elif tokens[0] == "instantiated:": clazzName = tokens[1] if (clazzName.startswith("const ")): clazzName = clazzName[6:] if (clazzName.startswith("class ")): clazzName = clazzName[6:] - if (clazzName.endswith(" &")): - clazzName = clazzName[:len(clazzName)-3] + if (clazzName.startswith("::")): + clazzName = clazzName[2:] instantiatedSet.add(clazzName) elif tokens[0] == "definition:": clazzName = tokens[1] # the 1.. is so we skip the leading / - fileName = tokens[1][1..] + fileName = tokens[2][1:] definitionSet.add(clazzName) definitionToFileDict[clazzName] = fileName @@ -42,7 +45,7 @@ with open("loplugin.mergeclasses.log") as txt: if (parent not in parentChildDict): parentChildDict[parent] = set() parentChildDict[parent].add(child) - + def extractModuleName(clazz): filename = definitionToFileDict[clazz] if filename.startswith("include/"): @@ -51,21 +54,22 @@ def extractModuleName(clazz): return filename[:idx] with open("loplugin.mergeclasses.report", "wt") as f: -for clazz in sorted(definitionSet - instantiatedSet): - # find uninstantiated classes without any subclasses - if (not(clazz in parentChildDict)) or (len(parentChildDict[clazz]) != 1): - continue - # exclude some common false positives - a = ['Dialog', 'Dlg', 'com::sun', 'Base'] - if any(x in clazz for x in a): - continue - # ignore base class that contain the word "mutex", they are normally there to - # help with the WeakComponentImpl template magic - if ("mutex" in clazz) or ("Mutex" in clazz): - continue - otherclazz = next(iter(parentChildDict[clazz])) - # exclude combinations that span modules because we often use those to make cross-module dependencies more manageable. - if extractModuleName(clazz) != extractModuleName(otherclazz): - continue - f.write( "merge" + clazz + "with" + otherclazz + "\n" ) + # loop over defined, but not instantiated classes + for clazz in sorted(definitionSet - instantiatedSet): + # ignore classes without any children, and classes with more than one child + if (clazz not in parentChildDict) or (len(parentChildDict[clazz]) != 1): + continue + # exclude some common false positives + a = ['Dialog', 'Dlg', 'com::sun', 'Base'] + if any(x in clazz for x in a): + continue + # ignore base class that contain the word "mutex", they are normally there to + # help with the WeakComponentImpl template magic + if ("mutex" in clazz) or ("Mutex" in clazz): + continue + otherclazz = next(iter(parentChildDict[clazz])) + # exclude combinations that span modules because we often use those to make cross-module dependencies more manageable. + if extractModuleName(clazz) != extractModuleName(otherclazz): + continue + f.write( "merge " + clazz + " with " + otherclazz + "\n" ) diff --git a/compilerplugins/clang/mergeclasses.results b/compilerplugins/clang/mergeclasses.results index f62a55cd9dd1..254d14e8127d 100644 --- a/compilerplugins/clang/mergeclasses.results +++ b/compilerplugins/clang/mergeclasses.results @@ -8,6 +8,7 @@ merge (anonymous namespace)::Data with cppu::PropertySetMixinImpl::Impl merge (anonymous namespace)::N with (anonymous namespace)::P merge (anonymous namespace)::O with (anonymous namespace)::O2 merge (anonymous namespace)::ParserData with (anonymous namespace)::Entity +merge (anonymous namespace)::PublishableDescription with cppu::ImplInheritanceHelper1 merge (anonymous namespace)::RecursiveTest with (anonymous namespace)::SimpleRecursiveTest merge (anonymous namespace)::ReflectionTransition with (anonymous namespace)::RochadeTransition merge (anonymous namespace)::SimpleTransition with (anonymous namespace)::DiamondTransition @@ -24,7 +25,6 @@ merge DbGridControl with FmGridControl merge DdeItem with DdeGetPutItem merge DdeLink with DdeHotLink merge DomVisitor with DomExport -merge DownloadInteractionHandler with UpdateCheck merge E3dScene with E3dPolyScene merge E3dUndoAction with E3dRotateUndoAction merge EscherPersistTable with EscherEx @@ -40,7 +40,6 @@ merge GLWindow with GLX11Window merge GraphiteLayout with GraphiteLayoutImpl merge GroupTable with PPTWriterBase merge HostDetailsContainer with DavDetailsContainer -merge IActionListener with UpdateCheck merge IDocumentChartDataProviderAccess with sw::DocumentChartDataProviderManager merge IDocumentContentOperations with sw::DocumentContentOperationsManager merge IDocumentDeviceAccess with sw::DocumentDeviceManager @@ -75,7 +74,6 @@ merge IconChoicePage with SvxHyperlinkTabPageBase merge ImplEESdrWriter with ImplEscherExSdr merge ImplGlyphFallbackFontSubstitution with FcGlyphFallbackSubstitution merge ImplPreMatchFontSubstitution with FcPreMatchSubstitution -merge LineLB with SvxLineBox merge LwpDLList with LwpParaProperty merge LwpDLVListHead with LwpPropList merge LwpMarker with LwpStoryMarker @@ -136,7 +134,6 @@ merge SfxMultiFixRecordWriter with SfxMultiVarRecordWriter merge SfxSingleRecordReader with SfxMultiRecordReader merge SfxSingleRecordWriter with SfxMultiFixRecordWriter merge SfxWorkWindow with SfxFrameWorkWin_Impl -merge SmElement with SmElementSeparator merge SmFontPickList with SmFontPickListBox merge StarSymbolToMSMultiFont with StarSymbolToMSMultiFontImpl merge StgAvlIterator with StgIterator @@ -153,7 +150,6 @@ merge SvxCSS1Parser with SwCSS1Parser merge SvxListBoxControl with SvxUndoRedoControl merge SvxRTFParser with EditRTFParser merge SvxShapeMaster with SdXShape -merge SvxUnoDrawMSFactory with SvxFmMSFactory merge SwAccessibleFrame with SwAccessibleContext merge SwComboBox with CaptionComboBox merge SwCursorShell with SwEditShell @@ -174,7 +170,6 @@ merge TextObj with TextObjBinary merge TextRenderImpl with CairoTextRender merge TextView with ExtTextView merge UniqueIndexImpl with UniqueIndex -merge UpdateCheckConfigListener with UpdateCheck merge ValueGetter with CellValueGetter merge ValueSetter with CellValueSetter merge VariableTextField with VariableDateTimeField @@ -189,7 +184,6 @@ merge XMLTransformer with XMLTransformerBase merge XclDebugObjCounter with XclRootData merge XclExpFutureRecord with XclExpChFutureRecordBase merge XclExpSubStream with XclExpChart -merge XclImpCachedValue with XclImpCrn merge XclNumFmtBuffer with XclImpNumFmtBuffer merge abp::OModuleResourceClient with abp::OABSPilotUno merge accessibility::GridControlAccessibleElement with accessibility::AccessibleGridControlTableBase @@ -198,8 +192,6 @@ merge basctl::docs::IDocumentDescriptorFilter with basctl::(anonymous namespace) merge basegfx::InterpolatorProvider3D with basegfx::RasterConverter3D merge bib::OComponentListener with bib::OLoadListener merge bib::OLoadListener with bib::FormControlContainer -merge cairocanvas::CanvasHelper with cairocanvas::SpriteCanvasHelper -merge cairocanvas::DeviceHelper with cairocanvas::SpriteDeviceHelper merge cairocanvas::Sprite with cairocanvas::CanvasCustomSpriteSpriteBase_Base merge canvas::ISurfaceProxy with canvas::SurfaceProxy merge canvas::ISurfaceProxyManager with canvas::SurfaceProxyManager @@ -236,11 +228,8 @@ merge dbaccess::IPropertyContainer with dbaccess::OColumn merge dbaccess::IRefreshListener with dbaccess::OConnection merge dbaccess::OColumnWrapper with dbaccess::OTableColumnDescriptorWrapper merge dbaccess::StorageInputStream with dbaccess::StorageXMLInputStream -merge dbaui::DBSubComponentController with rptui::OReportController merge dbaui::IEntryFilter with dbaui::(anonymous namespace)::FilterByEntryDataId merge dbaui::IUpdateHelper with dbaui::OParameterUpdateHelper -merge dbaui::OGenericUnoController with dbaui::OApplicationController -merge dbaui::OQueryView with dbaui::OQueryDesignView merge dbaui::OSplitterView with dbaui::OApplicationDetailView merge dbaui::OTableRowView with dbaui::OTableEditorCtrl merge dbaui::SbaGridListener with dbaui::SbaXDataBrowserController @@ -265,18 +254,14 @@ merge frm::OFormComponents with frm::ODatabaseForm merge ftp::CurlInput with InsertData merge gio::Seekable with gio::OutputStream merge i_xml_parser_event_handler with (anonymous namespace)::recently_used_file_filter -merge oglcanvas::CanvasHelper with oglcanvas::BitmapCanvasHelper merge oglcanvas::IBufferContext with oglcanvas::(anonymous namespace)::BufferContextImpl merge old_SdrDownCompat with SdIOCompat -merge oox::dump::ConstList with oox::dump::MultiList -merge oox::dump::FlagsList with oox::dump::CombiList merge oox::dump::ItemFormat with oox::dump::CombiList::ExtItemFormat merge oox::dump::OleStreamObject with oox::dump::OleCompObjObject merge oox::formulaimport::XmlStream with oox::formulaimport::XmlStreamBuilder -merge oox::ole::OleObjectInfo with oox::vml::OleObjectInfo merge oox::ole::VbaFilterConfig with oox::ole::VbaProject merge oox::vml::CustomShape with oox::vml::ComplexShape -merge oox::xls::BiffFragmentHandler with oox::xls::BiffWorkbookFragmentBase +merge oox::xls::FormulaParserImpl with oox::xls::OoxFormulaParserImpl merge oox::xls::FunctionProvider with oox::xls::OpCodeProvider merge oox::xls::IWorksheetProgress with oox::xls::WorksheetGlobals merge pcr::(anonymous namespace)::ISQLCommandPropertyUI with pcr::(anonymous namespace)::SQLCommandPropertyUI @@ -288,6 +273,7 @@ merge pcr::IPropertyLineListener with pcr::OPropertyBrowserController merge pcr::ISQLCommandAdapter with pcr::(anonymous namespace)::ISQLCommandPropertyUI merge pcr::PropertyHandler with pcr::PropertyHandlerComponent merge pcr::PropertyHandlerComponent with pcr::HandlerComponentBase +merge psp::Ascii85Encoder with psp::LZWEncoder merge psp::PrinterBmp with SalPrinterBmp merge registry::tools::Options with Options_Impl merge reportdesign::ITraverseReport with rptui::NavigatorTree @@ -329,8 +315,10 @@ merge slideshow::internal::AnimatableShape with slideshow::internal::Attributabl merge slideshow::internal::AnimationFunction with slideshow::internal::ExpressionNode merge slideshow::internal::AnimationNode with slideshow::internal::BaseNode merge slideshow::internal::AttributableShape with slideshow::internal::DrawShape -merge slideshow::internal::ClickEventHandler with slideshow::internal::SkipEffectEventHandler +merge slideshow::internal::BoolAnimation with slideshow::internal::(anonymous namespace)::GenericAnimation +merge slideshow::internal::ColorAnimation with slideshow::internal::(anonymous namespace)::GenericAnimation merge slideshow::internal::DocTreeNodeSupplier with slideshow::internal::DrawShape +merge slideshow::internal::EnumAnimation with slideshow::internal::(anonymous namespace)::GenericAnimation merge slideshow::internal::HSLColorAnimation with slideshow::internal::(anonymous namespace)::HSLWrapper merge slideshow::internal::HyperlinkArea with slideshow::internal::DrawShape merge slideshow::internal::HyperlinkHandler with (anonymous namespace)::SlideShowImpl::SeparateListenerImpl @@ -340,6 +328,7 @@ merge slideshow::internal::ScreenUpdater::UpdateLock with (anonymous namespace): merge slideshow::internal::ShapeListenerEventHandler with slideshow::internal::ShapeManagerImpl merge slideshow::internal::ShapeManager with slideshow::internal::SubsettableShapeManager merge slideshow::internal::Slide with slideshow::internal::(anonymous namespace)::SlideImpl +merge slideshow::internal::StringAnimation with slideshow::internal::(anonymous namespace)::GenericAnimation merge slideshow::internal::SubsettableShapeManager with slideshow::internal::ShapeManagerImpl merge slideshow::internal::UnoView with slideshow::internal::(anonymous namespace)::SlideView merge slideshow::internal::UserPaintEventHandler with slideshow::internal::PaintOverlayHandler @@ -355,7 +344,6 @@ merge svt::IEditImplementation with svt::GenericEditImplementation merge svt::IEnumerationResultHandler with SvtFileView_Impl merge svt::IFilePickerController with SvtFileDialog_Base merge svt::IFilePickerListener with SvtFilePicker -merge svt::OCommonPicker with SvtFilePicker merge svt::table::IAccessibleTable with svt::table::TableControl merge svt::table::IColumnModel with svt::table::UnoGridColumnFacade merge svt::table::ITableControl with svt::table::TableControl_Impl @@ -369,6 +357,7 @@ merge svx::IFocusObserver with svx::FmTextControlShell merge svx::IPropertyValueProvider with svx::PropertyValueProvider merge svx::ISlotInvalidator with svx::FmTextControlShell merge svx::RegistrationItemSetHolder with svx::DatabaseRegistrationDialog +merge svx::sidebar::SvxShapeCommandsMap with svx::sidebar::DefaultShapesPanel merge svxform::(anonymous namespace)::IScript with svxform::(anonymous namespace)::NewStyleUNOScript merge svxform::DispatchInterceptor with svxform::FormController merge svxform::IFormScriptingEnvironment with svxform::FormScriptingEnvironment @@ -384,8 +373,8 @@ merge toolkit::ScrollableInterface with toolkit::ScrollableWrapper merge unographic::GraphicTransformer with unographic::Graphic merge vcl::DeletionNotifier with SalFrame merge vcl::ExtOutDevData with vcl::PDFExtOutDevData +merge vcl::IPrioritable with VclContainer merge vcl::SolarThreadExecutor with vcl::solarthread::detail::GenericSolarThreadExecutor -merge vclcanvas::DeviceHelper with vclcanvas::SpriteDeviceHelper merge vclcanvas::Sprite with vclcanvas::CanvasCustomSpriteSpriteBase_Base merge webdav_ucp::DAVAuthListener with webdav_ucp::DAVAuthListener_Impl merge webdav_ucp::DAVSession with webdav_ucp::NeonSession @@ -396,12 +385,9 @@ merge writerfilter::ooxml::OOXMLDocument with writerfilter::ooxml::OOXMLDocument merge writerfilter::ooxml::OOXMLFastContextHandlerLinear with writerfilter::ooxml::OOXMLFastContextHandlerMath merge writerfilter::ooxml::OOXMLStream with writerfilter::ooxml::OOXMLStreamImpl merge writerfilter::rtftok::RTFDocument with writerfilter::rtftok::RTFDocumentImpl -merge ww8::WW8Struct with ww8::WW8Sttb -merge xforms::OXSDDataType with xforms::OValueLimitedType_Base merge xmloff::IEventAttacher with xmloff::OElementImport merge xmloff::IEventAttacherManager with xmloff::ODefaultEventAttacherManager merge xmloff::IFormsExportContext with xmloff::OFormLayerXMLExport_Impl -merge xmloff::OElementImport with xmloff::OControlImport merge xmloff::OPropertyExport with xmloff::OElementExport merge xmloff::OPropertyImport with xmloff::OElementImport merge xmloff::OURLReferenceImport with xmloff::OButtonImport -- cgit