Kaydet (Commit) 508c95f1 authored tarafından Noel Grandin's avatar Noel Grandin Kaydeden (comit) Noel Grandin

improve passstuffbyref return analysis

Change-Id: I4258bcc97273d8bb7a8c4879fac02a427f76e18c
Reviewed-on: https://gerrit.libreoffice.org/27317Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarNoel Grandin <noelgrandin@gmail.com>
üst 9f4af777
......@@ -491,7 +491,7 @@ void FrameControl::impl_deleteFrame()
// private method
const Sequence< Property > FrameControl::impl_getStaticPropertyDescriptor()
const Sequence< Property >& FrameControl::impl_getStaticPropertyDescriptor()
{
// All Properties of this implementation. The array must be sorted!
static const Property pPropertys[PROPERTY_COUNT] =
......
......@@ -205,7 +205,7 @@ private:
void impl_deleteFrame();
static const css::uno::Sequence< css::beans::Property > impl_getStaticPropertyDescriptor();
static const css::uno::Sequence< css::beans::Property >& impl_getStaticPropertyDescriptor();
// private variables
......
......@@ -190,7 +190,7 @@ ModulWindow::ModulWindow (ModulWindowLayout* pParent, ScriptDocument const& rDoc
SetBackground();
}
SbModuleRef ModulWindow::XModule()
SbModuleRef const & ModulWindow::XModule()
{
// ModuleWindows can now be created as a result of the
// modules getting created via the api. This is a result of an
......
......@@ -314,7 +314,7 @@ private:
static void GoOnTop();
sal_Int32 FormatAndPrint( Printer* pPrinter, sal_Int32 nPage = -1 );
SbModuleRef XModule();
SbModuleRef const & XModule();
protected:
virtual void Resize() override;
virtual void GetFocus() override;
......
......@@ -251,7 +251,7 @@ DlgEditor::~DlgEditor()
}
Reference< awt::XControlContainer > DlgEditor::GetWindowControlContainer()
Reference< awt::XControlContainer > const & DlgEditor::GetWindowControlContainer()
{
if (!m_xControlContainer.is())
m_xControlContainer = VCLUnoHelper::CreateControlContainer(&rWindow);
......
......@@ -147,7 +147,7 @@ public:
@see GetWindow
@see SetWindow
*/
css::uno::Reference< css::awt::XControlContainer >
css::uno::Reference< css::awt::XControlContainer > const &
GetWindowControlContainer();
void SetScrollBars( ScrollBar* pHScroll, ScrollBar* pVScroll );
......
......@@ -173,7 +173,7 @@ namespace tools
addPolyPolygon(rPolyPoly,XOR);
}
B2DPolyPolygon getClipPoly() const
B2DPolyPolygon const & getClipPoly() const
{
commitPendingRanges();
commitPendingPolygons();
......
......@@ -189,7 +189,7 @@ SbxErrObject::~SbxErrObject()
OSL_TRACE("SbxErrObject::~SbxErrObject dtor");
}
uno::Reference< vba::XErrObject >
uno::Reference< vba::XErrObject > const &
SbxErrObject::getUnoErrObject()
{
SbxVariable* pVar = getErrObject();
......@@ -197,7 +197,7 @@ SbxErrObject::getUnoErrObject()
return pGlobErr->m_xErr;
}
SbxVariableRef
SbxVariableRef const &
SbxErrObject::getErrObject()
{
static SbxVariableRef pGlobErr = new SbxErrObject( OUString("Err"), uno::makeAny( uno::Reference< vba::XErrObject >( new ErrObject() ) ) );
......
......@@ -1815,7 +1815,7 @@ void StarBASIC::SetGlobalBreakHdl( const Link<StarBASIC*,sal_uInt16>& rLink )
GetSbData()->aBreakHdl = rLink;
}
SbxArrayRef StarBASIC::getUnoListeners()
SbxArrayRef const & StarBASIC::getUnoListeners()
{
if( !xUnoListeners.Is() )
{
......
......@@ -167,7 +167,7 @@ Reference< XIdlReflection > getCoreReflection_Impl()
}
// save CoreReflection statically
Reference< XHierarchicalNameAccess > getCoreReflection_HierarchicalNameAccess_Impl()
Reference< XHierarchicalNameAccess > const & getCoreReflection_HierarchicalNameAccess_Impl()
{
static Reference< XHierarchicalNameAccess > xCoreReflection_HierarchicalNameAccess;
......@@ -184,7 +184,7 @@ Reference< XHierarchicalNameAccess > getCoreReflection_HierarchicalNameAccess_Im
}
// Hold TypeProvider statically
Reference< XHierarchicalNameAccess > getTypeProvider_Impl()
Reference< XHierarchicalNameAccess > const & getTypeProvider_Impl()
{
static Reference< XHierarchicalNameAccess > xAccess;
......@@ -210,7 +210,7 @@ Reference< XHierarchicalNameAccess > getTypeProvider_Impl()
}
// Hold TypeConverter statically
Reference< XTypeConverter > getTypeConverter_Impl()
Reference< XTypeConverter > const & getTypeConverter_Impl()
{
static Reference< XTypeConverter > xTypeConverter;
......
......@@ -492,7 +492,7 @@ SbModule::~SbModule()
mxWrapper = nullptr;
}
uno::Reference< script::XInvocation >
uno::Reference< script::XInvocation > const &
SbModule::GetUnoModule()
{
if ( !mxWrapper.is() )
......
......@@ -32,8 +32,8 @@ class SbxErrObject : public SbUnoObject
virtual ~SbxErrObject();
public:
static SbxVariableRef getErrObject();
static css::uno::Reference< ooo::vba::XErrObject > getUnoErrObject();
static SbxVariableRef const & getErrObject();
static css::uno::Reference< ooo::vba::XErrObject > const & getUnoErrObject();
void setNumberAndDescription( ::sal_Int32 _number, const OUString& _description )
throw (css::uno::RuntimeException);
......
......@@ -160,7 +160,7 @@ OUString getFullPath( const OUString& aRelPath )
}
// TODO: -> SbiGlobals
static uno::Reference< ucb::XSimpleFileAccess3 > getFileAccess()
static uno::Reference< ucb::XSimpleFileAccess3 > const & getFileAccess()
{
static uno::Reference< ucb::XSimpleFileAccess3 > xSFI;
if( !xSFI.is() )
......
......@@ -67,7 +67,7 @@ using namespace com::sun::star::lang;
using namespace com::sun::star::sheet;
using namespace com::sun::star::uno;
static Reference< XCalendar4 > getLocaleCalendar()
static Reference< XCalendar4 > const & getLocaleCalendar()
{
static Reference< XCalendar4 > xCalendar;
if( !xCalendar.is() )
......
......@@ -481,7 +481,7 @@ namespace cairocanvas
cairo_paint( pWindowCairo.get() );
}
::cairo::SurfaceSharedPtr SpriteCanvasHelper::getCompositingSurface( const ::basegfx::B2ISize& rNeededSize )
::cairo::SurfaceSharedPtr const & SpriteCanvasHelper::getCompositingSurface( const ::basegfx::B2ISize& rNeededSize )
{
if( rNeededSize.getX() > maCompositingSurfaceSize.getX() ||
rNeededSize.getY() > maCompositingSurfaceSize.getY() )
......@@ -501,7 +501,7 @@ namespace cairocanvas
return mpCompositingSurface;
}
::cairo::SurfaceSharedPtr SpriteCanvasHelper::getTemporarySurface()
::cairo::SurfaceSharedPtr const & SpriteCanvasHelper::getTemporarySurface()
{
if ( !mpTemporarySurface )
mpTemporarySurface = createSurface( maCompositingSurfaceSize );
......
......@@ -117,8 +117,8 @@ namespace cairocanvas
const ::std::vector< ::canvas::Sprite::Reference >& rSortedUpdateSprites );
private:
::cairo::SurfaceSharedPtr getCompositingSurface( const ::basegfx::B2ISize& rNeededSize );
::cairo::SurfaceSharedPtr getTemporarySurface();
::cairo::SurfaceSharedPtr const & getCompositingSurface( const ::basegfx::B2ISize& rNeededSize );
::cairo::SurfaceSharedPtr const & getTemporarySurface();
::cairo::SurfaceSharedPtr createSurface( const ::basegfx::B2ISize& rNeededSize ) const;
/// Set from the SpriteCanvas: instance coordinating sprite redraw
......
......@@ -568,7 +568,7 @@ public:
throw (css::uno::RuntimeException, std::exception) override;
// normal methods
css::uno::Reference< css::util::XNumberFormatsSupplier >
css::uno::Reference< css::util::XNumberFormatsSupplier > const &
getNumberFormatsSupplier();
const css::uno::Reference< css::uno::XInterface >& getChartView() { return xChartView;}
......
......@@ -200,7 +200,7 @@ public:
}
};
OUString findChartFile(const OUString& rDir, uno::Reference< container::XNameAccess > const & xNames )
OUString const & findChartFile(const OUString& rDir, uno::Reference< container::XNameAccess > const & xNames )
{
uno::Sequence<OUString> rNames = xNames->getElementNames();
OUString* pElement = std::find_if(rNames.begin(), rNames.end(), CheckForChartName(rDir));
......
......@@ -98,7 +98,7 @@ Reference< chart2::XDiagram > Chart2ModelContact::getChart2Diagram() const
return ChartModelHelper::findDiagram( this->getChartModel() );
}
uno::Reference< lang::XUnoTunnel > Chart2ModelContact::getChartView() const
uno::Reference< lang::XUnoTunnel > const & Chart2ModelContact::getChartView() const
{
if(!m_xChartView.is())
{
......
......@@ -126,7 +126,7 @@ public:
private: //methods
ExplicitValueProvider* getExplicitValueProvider() const;
css::uno::Reference< css::lang::XUnoTunnel > getChartView() const;
css::uno::Reference< css::lang::XUnoTunnel > const & getChartView() const;
public: //member
css::uno::Reference< css::uno::XComponentContext > m_xContext;
......
......@@ -396,7 +396,7 @@ void DialogModel::setTemplate(
m_xTemplate = xTemplate;
}
::std::shared_ptr< RangeSelectionHelper >
::std::shared_ptr< RangeSelectionHelper > const &
DialogModel::getRangeSelectionHelper() const
{
if( ! m_spRangeSelectionHelper.get())
......
......@@ -76,7 +76,7 @@ public:
void setTemplate(
const css::uno::Reference< css::chart2::XChartTypeTemplate > & xTemplate );
std::shared_ptr< RangeSelectionHelper >
std::shared_ptr< RangeSelectionHelper > const &
getRangeSelectionHelper() const;
css::uno::Reference< css::frame::XModel >
......
......@@ -54,7 +54,7 @@ bool RangeSelectionHelper::hasRangeSelection()
return getRangeSelection().is();
}
Reference< sheet::XRangeSelection > RangeSelectionHelper::getRangeSelection()
Reference< sheet::XRangeSelection > const & RangeSelectionHelper::getRangeSelection()
{
if( !m_xRangeSelection.is() &&
m_xChartDocument.is() )
......
......@@ -43,7 +43,7 @@ public:
~RangeSelectionHelper();
bool hasRangeSelection();
css::uno::Reference< css::sheet::XRangeSelection > getRangeSelection();
css::uno::Reference< css::sheet::XRangeSelection > const & getRangeSelection();
void raiseRangeSelectionDocument();
bool chooseRange(
const OUString & aCurrentRange,
......
......@@ -59,7 +59,7 @@ public:
css::uno::Reference< css::chart2::data::XDataSequence > getOriginalCategories();
css::uno::Sequence< OUString > getSimpleCategories();
css::uno::Sequence< OUString > const & getSimpleCategories();
const std::vector<ComplexCategory>* getCategoriesByLevel( sal_Int32 nLevel );
static OUString getCategoryByIndex(
......
......@@ -51,11 +51,11 @@ public:
css::uno::Reference< css::lang::XMultiServiceFactory > getShapeFactory();
// the main page will contain the normal view objects
css::uno::Reference< css::drawing::XDrawPage > getMainDrawPage();
css::uno::Reference< css::drawing::XDrawPage > const & getMainDrawPage();
SAL_DLLPRIVATE void clearMainDrawPage();
// the extra page is not visible, but contains some extras like the symbols for data points
css::uno::Reference< css::drawing::XDrawPage > getHiddenDrawPage();
css::uno::Reference< css::drawing::XDrawPage > const & getHiddenDrawPage();
static css::uno::Reference< css::drawing::XShapes >
getChartRootShape( const css::uno::Reference< css::drawing::XDrawPage>& xPage );
......
......@@ -1301,7 +1301,7 @@ Sequence< OUString > SAL_CALL ChartModel::getAvailableServiceNames()
return aResult;
}
Reference< util::XNumberFormatsSupplier > ChartModel::getNumberFormatsSupplier()
Reference< util::XNumberFormatsSupplier > const & ChartModel::getNumberFormatsSupplier()
{
if( !m_xNumberFormatsSupplier.is() )
{
......
......@@ -504,7 +504,7 @@ void ExplicitCategoriesProvider::init()
}
}
Sequence< OUString > ExplicitCategoriesProvider::getSimpleCategories()
Sequence< OUString > const & ExplicitCategoriesProvider::getSimpleCategories()
{
if( !m_bIsExplicitCategoriesInited )
{
......
......@@ -94,8 +94,8 @@ public:
bool hasPropertyMapping( const OUString& rPropName ) const;
css::uno::Sequence< double > getAllX() const;
css::uno::Sequence< double > getAllY() const;
css::uno::Sequence< double > const & getAllX() const;
css::uno::Sequence< double > const & getAllY() const;
double getXMeanValue() const;
double getYMeanValue() const;
......
......@@ -163,7 +163,7 @@ uno::Reference< lang::XMultiServiceFactory > DrawModelWrapper::getShapeFactory()
return xShapeFactory;
}
uno::Reference< drawing::XDrawPage > DrawModelWrapper::getMainDrawPage()
uno::Reference< drawing::XDrawPage > const & DrawModelWrapper::getMainDrawPage()
{
if (m_xMainDrawPage.is())
return m_xMainDrawPage;
......@@ -192,7 +192,7 @@ uno::Reference< drawing::XDrawPage > DrawModelWrapper::getMainDrawPage()
// AbstractShapeFactory::getOrCreateShapeFactory(this->getShapeFactory())->getOrCreateChartRootShape( m_xMainDrawPage );
return m_xMainDrawPage;
}
uno::Reference< drawing::XDrawPage > DrawModelWrapper::getHiddenDrawPage()
uno::Reference< drawing::XDrawPage > const & DrawModelWrapper::getHiddenDrawPage()
{
if( !m_xHiddenDrawPage.is() )
{
......
......@@ -304,7 +304,7 @@ OUString SAL_CALL DummyXShape::getImplementationName()
namespace {
uno::Sequence< OUString > listSupportedServices()
uno::Sequence< OUString > const & listSupportedServices()
{
static const uno::Sequence< OUString > aSupportedServices{
"com.sun.star.drawing.Shape",
......
......@@ -725,7 +725,7 @@ double VDataSeries::getMaximumofAllDifferentYValues( sal_Int32 index ) const
return fMax;
}
uno::Sequence< double > VDataSeries::getAllX() const
uno::Sequence< double > const & VDataSeries::getAllX() const
{
if(!m_aValues_X.is() && !m_aValues_X.getLength() && m_nPointCount)
{
......@@ -738,7 +738,7 @@ uno::Sequence< double > VDataSeries::getAllX() const
return m_aValues_X.Doubles;
}
uno::Sequence< double > VDataSeries::getAllY() const
uno::Sequence< double > const & VDataSeries::getAllY() const
{
if(!m_aValues_Y.is() && !m_aValues_Y.getLength() && m_nPointCount)
{
......
......@@ -37,7 +37,7 @@ bool Options::isValid(const OString& option) const
return m_options.find(option) != m_options.end();
}
const OString Options::getOption(const OString& option) const
const OString& Options::getOption(const OString& option) const
throw( IllegalArgument )
{
OptionMap::const_iterator i(m_options.find(option));
......
......@@ -39,7 +39,7 @@ IndexAccessIterator::IndexAccessIterator(css::uno::Reference< css::uno::XInterfa
IndexAccessIterator::~IndexAccessIterator() {}
css::uno::Reference< css::uno::XInterface> IndexAccessIterator::Next()
css::uno::Reference< css::uno::XInterface> const & IndexAccessIterator::Next()
{
bool bCheckingStartingPoint = !m_xCurrentObject.is();
// Is the current node the starting point?
......
......@@ -54,7 +54,7 @@ namespace comphelper
}
Reference < i18n::XBreakIterator > OCommonAccessibleText::implGetBreakIterator()
Reference < i18n::XBreakIterator > const & OCommonAccessibleText::implGetBreakIterator()
{
if ( !m_xBreakIter.is() )
{
......@@ -66,7 +66,7 @@ namespace comphelper
}
Reference < i18n::XCharacterClassification > OCommonAccessibleText::implGetCharacterClassification()
Reference < i18n::XCharacterClassification > const & OCommonAccessibleText::implGetCharacterClassification()
{
if ( !m_xCharClass.is() )
{
......
......@@ -40,7 +40,7 @@ public:
void add(PropertyMapEntry const * pMap) throw();
void remove( const OUString& aName ) throw();
std::vector< Property > getProperties() throw();
std::vector< Property > const & getProperties() throw();
const PropertyMap& getPropertyMap() const throw() { return maPropertyMap;}
......@@ -83,7 +83,7 @@ void PropertyMapImpl::remove( const OUString& aName ) throw()
maProperties.clear();
}
std::vector< Property > PropertyMapImpl::getProperties() throw()
std::vector< Property > const & PropertyMapImpl::getProperties() throw()
{
// maybe we have to generate the properties after
// a change in the property map or at first call
......
......@@ -67,7 +67,7 @@ class OFOPXMLHelper_Impl
public:
css::uno::Sequence< css::uno::Sequence< css::beans::StringPair > > GetParsingResult();
css::uno::Sequence< css::uno::Sequence< css::beans::StringPair > > const & GetParsingResult();
explicit OFOPXMLHelper_Impl( sal_uInt16 nFormat ); // must not be created directly
virtual ~OFOPXMLHelper_Impl();
......@@ -284,7 +284,7 @@ OFOPXMLHelper_Impl::~OFOPXMLHelper_Impl()
}
uno::Sequence< uno::Sequence< beans::StringPair > > OFOPXMLHelper_Impl::GetParsingResult()
uno::Sequence< uno::Sequence< beans::StringPair > > const & OFOPXMLHelper_Impl::GetParsingResult()
{
if ( m_aElementsSeq.size() )
throw uno::RuntimeException(); // the parsing has still not finished!
......
......@@ -36,7 +36,7 @@ public:
virtual void run() override { TraverseDecl(compiler.getASTContext().getTranslationUnitDecl()); }
// When warning about function params of primitive type that could be passed
// by value instead of by reference, make sure not to warn if the paremeter
// by value instead of by reference, make sure not to warn if the parameter
// is ever bound to a reference; on the one hand, this needs scaffolding in
// all Traverse*Decl functions (indirectly) derived from FunctionDecl; and
// on the other hand, use a hack of ignoring just the DeclRefExprs nested in
......@@ -51,9 +51,8 @@ public:
bool TraverseImplicitCastExpr(ImplicitCastExpr * expr);
bool VisitDeclRefExpr(const DeclRefExpr * expr);
bool VisitCallExpr(const CallExpr * ) { if (mbInsideFunctionDecl) mbFoundDisqualifier = true; return true; }
bool VisitMaterializeTemporaryExpr(const MaterializeTemporaryExpr * ) { if (mbInsideFunctionDecl) mbFoundDisqualifier = true; return true; }
bool VisitDeclStmt(const DeclStmt * ) { if (mbInsideFunctionDecl) mbFoundDisqualifier = true; return true; }
bool VisitReturnStmt(const ReturnStmt * );
bool VisitVarDecl(const VarDecl * );
private:
template<typename T> bool traverseAnyFunctionDecl(
......@@ -62,6 +61,8 @@ private:
void checkReturnValue(const FunctionDecl * functionDecl, const CXXMethodDecl * methodDecl);
bool isFat(QualType type);
bool isPrimitiveConstRef(QualType type);
bool isReturnExprDisqualified(const Expr* expr);
bool mbInsideFunctionDecl;
bool mbFoundDisqualifier;
......@@ -228,10 +229,10 @@ void PassStuffByRef::checkParams(const FunctionDecl * functionDecl) {
void PassStuffByRef::checkReturnValue(const FunctionDecl * functionDecl, const CXXMethodDecl * methodDecl) {
if (methodDecl && methodDecl->isVirtual()) {
if (methodDecl && (methodDecl->isVirtual() || methodDecl->hasAttr<OverrideAttr>())) {
return;
}
if( !functionDecl->hasBody()) {
if( !functionDecl->doesThisDeclarationHaveABody()) {
return;
}
......@@ -258,7 +259,8 @@ void PassStuffByRef::checkReturnValue(const FunctionDecl * functionDecl, const C
|| (dc.MemberFunction().Class("Model").Namespace("xforms")
.GlobalNamespace())
|| (dc.MemberFunction().Class("Submission").Namespace("xforms")
.GlobalNamespace()))
.GlobalNamespace())
|| (dc.Function("TopLeft").Class("SwRect").GlobalNamespace()))
{
return;
}
......@@ -274,8 +276,7 @@ void PassStuffByRef::checkReturnValue(const FunctionDecl * functionDecl, const C
return;
// depends on a define
if (dc.Function("GetSharedFileURL").Class("SfxObjectShell")
.GlobalNamespace())
{
.GlobalNamespace()) {
return;
}
mbInsideFunctionDecl = true;
......@@ -297,12 +298,85 @@ void PassStuffByRef::checkReturnValue(const FunctionDecl * functionDecl, const C
{
report(
DiagnosticsEngine::Note,
"rather return by const& than by value",
"decl here",
functionDecl->getCanonicalDecl()->getSourceRange().getBegin())
<< functionDecl->getCanonicalDecl()->getSourceRange();
}
}
bool PassStuffByRef::VisitReturnStmt(const ReturnStmt * returnStmt)
{
if (!mbInsideFunctionDecl)
return true;
const Expr* expr = dyn_cast<Expr>(*returnStmt->child_begin())->IgnoreParenCasts();
if (isReturnExprDisqualified(expr)) {
mbFoundDisqualifier = true;
return true;
}
return true;
}
bool PassStuffByRef::isReturnExprDisqualified(const Expr* expr)