From 781c4402f1a8c64f87bc81e866bc444b9ed97948 Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Sat, 2 Nov 2019 07:46:49 +0200 Subject: make some classes module-private improve the script, but it still generates some false positives Change-Id: If8ee1cba8c04ac0be11f73220149e6de15f24f44 Reviewed-on: https://gerrit.libreoffice.org/81929 Tested-by: Jenkins Reviewed-by: Noel Grandin --- bin/find-can-be-private-symbols.py | 38 +++++++++++++++++++--- helpcompiler/inc/BasCodeTagger.hxx | 4 +-- include/basic/basmgr.hxx | 2 +- include/filter/msfilter/msdffimp.hxx | 2 +- include/opencl/platforminfo.hxx | 4 +-- include/sfx2/notebookbar/NotebookbarTabControl.hxx | 2 +- include/svtools/ctrlbox.hxx | 2 +- include/svtools/svmedit2.hxx | 2 +- include/svx/AffineMatrixItem.hxx | 2 +- include/svx/Palette.hxx | 2 +- include/svx/galctrl.hxx | 24 +++++++------- include/vcl/animate/AnimationBitmap.hxx | 2 +- include/vcl/button.hxx | 6 ++-- include/vcl/commandevent.hxx | 6 ++-- include/vcl/debugevent.hxx | 2 +- include/vcl/graph.hxx | 2 +- include/vcl/imapobj.hxx | 2 +- include/vcl/salnativewidgets.hxx | 4 +-- include/vcl/uitest/uiobject.hxx | 14 ++++---- oox/inc/drawingml/presetgeometrynames.hxx | 4 +-- sfx2/source/notebookbar/DropdownBox.hxx | 3 +- sfx2/source/notebookbar/NotebookbarPopup.hxx | 2 +- sfx2/source/notebookbar/PriorityHBox.hxx | 2 +- sfx2/source/notebookbar/PriorityMergedHBox.cxx | 2 +- svx/inc/palettes.hxx | 6 ++-- sw/inc/PageColumnPopup.hxx | 2 +- sw/inc/PageMarginPopup.hxx | 2 +- sw/inc/PageOrientationPopup.hxx | 2 +- sw/inc/PageSizePopup.hxx | 2 +- sw/source/uibase/inc/actctrl.hxx | 2 +- vcl/inc/bitmap/Octree.hxx | 4 +-- vcl/inc/impfontcharmap.hxx | 2 +- vcl/inc/opengl/program.hxx | 2 +- vcl/inc/sallayout.hxx | 4 +-- vcl/inc/unx/freetype_glyphcache.hxx | 2 +- vcl/inc/unx/glyphcache.hxx | 2 +- vcl/inc/unx/gtk/gtkprn.hxx | 2 +- vcl/inc/unx/saldisp.hxx | 2 +- 38 files changed, 100 insertions(+), 71 deletions(-) diff --git a/bin/find-can-be-private-symbols.py b/bin/find-can-be-private-symbols.py index baaba9e924ff..0ff17072361a 100755 --- a/bin/find-can-be-private-symbols.py +++ b/bin/find-can-be-private-symbols.py @@ -1,10 +1,20 @@ #!/usr/bin/python # -# Find exported symbols that can be made private. +# Find exported symbols that can be made non-exported. # # Noting that (a) parsing these commands is a pain, the output is quite irregular and (b) I'm fumbling in the # dark here, trying to guess what exactly constitutes an "import" vs an "export" of a symbol, linux linking # is rather complex. +# +# Takes about 5min to run on a decent machine. +# +# The standalone function analysis is reasonable reliable, but the class/method analysis is less so +# (something to do with destructor thunks not showing up in my results?) +# +# Also, the class/method analysis will not catch problems like +# 'dynamic_cast from 'Foo' with hidden type visibility to 'Bar' with default type visibility' +# but loplugin:dyncastvisibility will do that for you +# import subprocess import sys @@ -74,20 +84,28 @@ classes_with_imported_symbols = set() for sym in exported_symbols: filtered_sym = subprocess.check_output(["c++filt", sym]).strip() if filtered_sym.startswith("non-virtual thunk to "): filtered_sym = filtered_sym[21:] + elif filtered_sym.startswith("virtual thunk to "): filtered_sym = filtered_sym[17:] i = filtered_sym.find("(") i = filtered_sym.rfind("::", 0, i) if i != -1: classname = filtered_sym[:i] - func = filtered_sym[i+2:] # find classes where all of the exported symbols are not imported classes_with_exported_symbols.add(classname) - if sym in imported_symbols: classes_with_imported_symbols.add(classname) else: - package = "" func = filtered_sym # find standalone functions which are exported but not imported if not(sym in imported_symbols): unused_function_exports.add(func) +for sym in imported_symbols: + filtered_sym = subprocess.check_output(["c++filt", sym]).strip() + if filtered_sym.startswith("non-virtual thunk to "): filtered_sym = filtered_sym[21:] + elif filtered_sym.startswith("virtual thunk to "): filtered_sym = filtered_sym[17:] + i = filtered_sym.find("(") + i = filtered_sym.rfind("::", 0, i) + if i != -1: + classname = filtered_sym[:i] + classes_with_imported_symbols.add(classname) + with open("bin/find-can-be-private-symbols.functions.results", "wt") as f: for sym in sorted(unused_function_exports): # Filter out most of the noise. @@ -175,4 +193,16 @@ with open("bin/find-can-be-private-symbols.functions.results", "wt") as f: with open("bin/find-can-be-private-symbols.classes.results", "wt") as f: for sym in sorted(classes_with_exported_symbols - classes_with_imported_symbols): + # externals + if sym.startswith("libcdr"): continue + elif sym.startswith("libabw"): continue + elif sym.startswith("libebook"): continue + elif sym.startswith("libepubgen"): continue + elif sym.startswith("libfreehand"): continue + elif sym.startswith("libmspub"): continue + elif sym.startswith("libpagemaker"): continue + elif sym.startswith("libqxp"): continue + elif sym.startswith("libvisio"): continue + elif sym.startswith("libzmf"): continue + elif sym.startswith("lucene::"): continue f.write(sym + "\n") diff --git a/helpcompiler/inc/BasCodeTagger.hxx b/helpcompiler/inc/BasCodeTagger.hxx index 93dfd70f137b..d897afb4fe1d 100644 --- a/helpcompiler/inc/BasCodeTagger.hxx +++ b/helpcompiler/inc/BasCodeTagger.hxx @@ -20,7 +20,7 @@ class LibXmlTreeWalker; //!Tagger class. -class L10N_DLLPUBLIC BasicCodeTagger +class BasicCodeTagger { private: xmlDocPtr m_pDocument; @@ -42,7 +42,7 @@ class L10N_DLLPUBLIC BasicCodeTagger //================LibXmlTreeWalker=========================================================== -class L10N_DLLPUBLIC LibXmlTreeWalker +class LibXmlTreeWalker { private: xmlNodePtr m_pCurrentNode; diff --git a/include/basic/basmgr.hxx b/include/basic/basmgr.hxx index 95e5a7c11d22..64e4ac597df7 100644 --- a/include/basic/basmgr.hxx +++ b/include/basic/basmgr.hxx @@ -49,7 +49,7 @@ enum class BasicErrorReason STDLIB = 0x0100 }; -class BASIC_DLLPUBLIC BasicError +class BasicError { private: ErrCode nErrorId; diff --git a/include/filter/msfilter/msdffimp.hxx b/include/filter/msfilter/msdffimp.hxx index 981ab4dd49db..4defc7f0b8bb 100644 --- a/include/filter/msfilter/msdffimp.hxx +++ b/include/filter/msfilter/msdffimp.hxx @@ -130,7 +130,7 @@ struct MSFILTER_DLLPUBLIC CompareSvxMSDffShapeInfoById bool operator()(std::shared_ptr const& lhs, std::shared_ptr const& rhs) const; }; -struct MSFILTER_DLLPUBLIC CompareSvxMSDffShapeInfoByTxBxComp +struct CompareSvxMSDffShapeInfoByTxBxComp { bool operator()(std::shared_ptr const& lhs, std::shared_ptr const& rhs) const; diff --git a/include/opencl/platforminfo.hxx b/include/opencl/platforminfo.hxx index ac3f144f9d9f..5e54c052fc51 100644 --- a/include/opencl/platforminfo.hxx +++ b/include/opencl/platforminfo.hxx @@ -20,7 +20,7 @@ // Struct that describs an actual instance of an OpenCL device -struct OPENCL_DLLPUBLIC OpenCLDeviceInfo +struct OpenCLDeviceInfo { cl_device_id device; OUString maName; @@ -35,7 +35,7 @@ struct OPENCL_DLLPUBLIC OpenCLDeviceInfo // Struct that describs an actual instance of an OpenCL platform implementation -struct OPENCL_DLLPUBLIC OpenCLPlatformInfo +struct OpenCLPlatformInfo { cl_platform_id platform; OUString maVendor; diff --git a/include/sfx2/notebookbar/NotebookbarTabControl.hxx b/include/sfx2/notebookbar/NotebookbarTabControl.hxx index 68d7b4ef252d..440148beff0d 100644 --- a/include/sfx2/notebookbar/NotebookbarTabControl.hxx +++ b/include/sfx2/notebookbar/NotebookbarTabControl.hxx @@ -18,7 +18,7 @@ namespace com { namespace sun { namespace star { namespace ui { } } } } namespace com::sun::star::uno { class XComponentContext; } -class SFX2_DLLPUBLIC NotebookbarTabControl final : public NotebookbarTabControlBase +class NotebookbarTabControl final : public NotebookbarTabControlBase { friend class ChangedUIEventListener; diff --git a/include/svtools/ctrlbox.hxx b/include/svtools/ctrlbox.hxx index fbde3fc5dacc..1805778aa3d2 100644 --- a/include/svtools/ctrlbox.hxx +++ b/include/svtools/ctrlbox.hxx @@ -356,7 +356,7 @@ private: FontNameBox& operator =( const FontNameBox& ) = delete; }; -class SVT_DLLPUBLIC FontStyleBox final : public ComboBox +class FontStyleBox final : public ComboBox { Size aOptimalSize; diff --git a/include/svtools/svmedit2.hxx b/include/svtools/svmedit2.hxx index e2b7b1f5a238..6387bbd42921 100644 --- a/include/svtools/svmedit2.hxx +++ b/include/svtools/svmedit2.hxx @@ -24,7 +24,7 @@ class TextAttrib; -class SVT_DLLPUBLIC ExtMultiLineEdit final : public MultiLineEdit +class ExtMultiLineEdit final : public MultiLineEdit { public: ExtMultiLineEdit( vcl::Window* pParent, WinBits nWinStyle ); diff --git a/include/svx/AffineMatrixItem.hxx b/include/svx/AffineMatrixItem.hxx index b9559147c58e..6b3cbebf872f 100644 --- a/include/svx/AffineMatrixItem.hxx +++ b/include/svx/AffineMatrixItem.hxx @@ -26,7 +26,7 @@ class SfxItemPool; -class SVX_DLLPUBLIC AffineMatrixItem final : public SfxPoolItem +class AffineMatrixItem final : public SfxPoolItem { private: css::geometry::AffineMatrix2D maMatrix; diff --git a/include/svx/Palette.hxx b/include/svx/Palette.hxx index f66d06b30b05..0ce1722ff130 100644 --- a/include/svx/Palette.hxx +++ b/include/svx/Palette.hxx @@ -28,7 +28,7 @@ class SvxColorValueSet; typedef std::pair NamedColor; -class SVX_DLLPUBLIC Palette +class Palette { public: virtual ~Palette(); diff --git a/include/svx/galctrl.hxx b/include/svx/galctrl.hxx index e43453c5b2de..ddbcbb3a60cf 100644 --- a/include/svx/galctrl.hxx +++ b/include/svx/galctrl.hxx @@ -32,7 +32,7 @@ class GalleryTheme; class GalleryBrowser2; class INetURLObject; -class SVX_DLLPUBLIC GalleryPreview final : public vcl::Window, public DropTargetHelper, public DragSourceHelper +class GalleryPreview final : public vcl::Window, public DropTargetHelper, public DragSourceHelper { private: @@ -40,24 +40,24 @@ private: tools::Rectangle aPreviewRect; GalleryTheme* const mpTheme; - SVX_DLLPRIVATE bool ImplGetGraphicCenterRect( const Graphic& rGraphic, tools::Rectangle& rResultRect ) const; - SVX_DLLPRIVATE void InitSettings(); + bool ImplGetGraphicCenterRect( const Graphic& rGraphic, tools::Rectangle& rResultRect ) const; + void InitSettings(); // Window - SVX_DLLPRIVATE virtual void Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect) override; - SVX_DLLPRIVATE virtual Size GetOptimalSize() const override; - SVX_DLLPRIVATE virtual void MouseButtonDown(const MouseEvent& rMEvt) override; - SVX_DLLPRIVATE virtual void Command(const CommandEvent& rCEvt) override; - SVX_DLLPRIVATE virtual void KeyInput( const KeyEvent& rKEvt ) override; - SVX_DLLPRIVATE virtual void DataChanged( const DataChangedEvent& rDCEvt ) override; + virtual void Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect) override; + virtual Size GetOptimalSize() const override; + virtual void MouseButtonDown(const MouseEvent& rMEvt) override; + virtual void Command(const CommandEvent& rCEvt) override; + virtual void KeyInput( const KeyEvent& rKEvt ) override; + virtual void DataChanged( const DataChangedEvent& rDCEvt ) override; // DropTargetHelper - SVX_DLLPRIVATE virtual sal_Int8 AcceptDrop( const AcceptDropEvent& rEvt ) override; - SVX_DLLPRIVATE virtual sal_Int8 ExecuteDrop( const ExecuteDropEvent& rEvt ) override; + virtual sal_Int8 AcceptDrop( const AcceptDropEvent& rEvt ) override; + virtual sal_Int8 ExecuteDrop( const ExecuteDropEvent& rEvt ) override; // DragSourceHelper - SVX_DLLPRIVATE virtual void StartDrag( sal_Int8 nAction, const Point& rPosPixel ) override; + virtual void StartDrag( sal_Int8 nAction, const Point& rPosPixel ) override; public: diff --git a/include/vcl/animate/AnimationBitmap.hxx b/include/vcl/animate/AnimationBitmap.hxx index ae8aaab1634f..5b438f8c4d6a 100644 --- a/include/vcl/animate/AnimationBitmap.hxx +++ b/include/vcl/animate/AnimationBitmap.hxx @@ -30,7 +30,7 @@ enum class Disposal Previous }; -struct VCL_DLLPUBLIC AnimationBitmap +struct AnimationBitmap { BitmapEx maBitmapEx; Point maPositionPixel; diff --git a/include/vcl/button.hxx b/include/vcl/button.hxx index 0b32b85f341c..c39c466d1afe 100644 --- a/include/vcl/button.hxx +++ b/include/vcl/button.hxx @@ -247,7 +247,7 @@ public: virtual void Click() override; }; -class VCL_DLLPUBLIC CloseButton final : public CancelButton +class CloseButton final : public CancelButton { public: explicit CloseButton(vcl::Window* pParent, WinBits nStyle = 0); @@ -517,9 +517,9 @@ public: explicit TriStateBox( vcl::Window* pParent, WinBits nStyle ); }; -class VCL_DLLPUBLIC DisclosureButton final : public CheckBox +class DisclosureButton final : public CheckBox { - SAL_DLLPRIVATE virtual void ImplDrawCheckBoxState(vcl::RenderContext& rRenderContext) override; + virtual void ImplDrawCheckBoxState(vcl::RenderContext& rRenderContext) override; public: explicit DisclosureButton( vcl::Window* pParent ); diff --git a/include/vcl/commandevent.hxx b/include/vcl/commandevent.hxx index a3ee2fb73c99..bf446e7f4f83 100644 --- a/include/vcl/commandevent.hxx +++ b/include/vcl/commandevent.hxx @@ -170,7 +170,7 @@ public: { return ((mnCode & KEY_MOD2) != 0); } }; -class VCL_DLLPUBLIC CommandScrollData +class CommandScrollData { private: long mnDeltaX; @@ -183,7 +183,7 @@ public: long GetDeltaY() const { return mnDeltaY; } }; -class VCL_DLLPUBLIC CommandModKeyData +class CommandModKeyData { private: bool mbDown; @@ -256,7 +256,7 @@ public: bool GetPassThroughToOS() const { return m_bPassThroughToOS; } }; -class VCL_DLLPUBLIC CommandSelectionChangeData +class CommandSelectionChangeData { private: sal_uLong mnStart; diff --git a/include/vcl/debugevent.hxx b/include/vcl/debugevent.hxx index e0d498761d29..a6f458265cbb 100644 --- a/include/vcl/debugevent.hxx +++ b/include/vcl/debugevent.hxx @@ -16,7 +16,7 @@ namespace vcl { class Window; } -class VCL_DLLPUBLIC DebugEventInjector final : private Timer { +class DebugEventInjector final : private Timer { sal_uInt32 mnEventsLeft; DebugEventInjector( sal_uInt32 nMaxEvents ); diff --git a/include/vcl/graph.hxx b/include/vcl/graph.hxx index bc2e6cc03a75..a30b3909e899 100644 --- a/include/vcl/graph.hxx +++ b/include/vcl/graph.hxx @@ -51,7 +51,7 @@ class ImpGraphic; class OutputDevice; class ReaderData; -class VCL_DLLPUBLIC GraphicReader +class GraphicReader { public: virtual ~GraphicReader(); diff --git a/include/vcl/imapobj.hxx b/include/vcl/imapobj.hxx index a9bf0ce7bc8f..2310328904e9 100644 --- a/include/vcl/imapobj.hxx +++ b/include/vcl/imapobj.hxx @@ -47,7 +47,7 @@ class SvStream; #define IMAP_ERR_OK 0x00000000L #define IMAP_ERR_FORMAT 0x00000001L -class VCL_DLLPUBLIC IMapObject +class IMapObject { friend class ImageMap; diff --git a/include/vcl/salnativewidgets.hxx b/include/vcl/salnativewidgets.hxx index 5e7ebc47de73..8108abe046dc 100644 --- a/include/vcl/salnativewidgets.hxx +++ b/include/vcl/salnativewidgets.hxx @@ -472,7 +472,7 @@ public: * * Value container for menubars specifying height of adjacent docking area */ -class VCL_DLLPUBLIC MenubarValue final : public ImplControlValue +class MenubarValue final : public ImplControlValue { public: MenubarValue() : ImplControlValue( ControlType::Menubar, 0 ) @@ -491,7 +491,7 @@ public: * Value container for menu items; specifies the rectangle for the whole item which * may be useful when drawing parts with a smaller rectangle. */ -class VCL_DLLPUBLIC MenupopupValue final : public ImplControlValue +class MenupopupValue final : public ImplControlValue { public: MenupopupValue( long i_nGutterWidth, const tools::Rectangle& i_rItemRect ) diff --git a/include/vcl/uitest/uiobject.hxx b/include/vcl/uitest/uiobject.hxx index a8722c46fed4..34aa048e5abd 100644 --- a/include/vcl/uitest/uiobject.hxx +++ b/include/vcl/uitest/uiobject.hxx @@ -135,7 +135,7 @@ protected: }; // TODO: moggi: what about push buttons? -class UITEST_DLLPUBLIC ButtonUIObject final : public WindowUIObject +class ButtonUIObject final : public WindowUIObject { VclPtr