Kaydet (Commit) e3eadc96 authored tarafından Noel Grandin's avatar Noel Grandin

teach constantparam plugin to find always on and always off bitmask values

Change-Id: If56a483494bd3d7feb3fa67c01000dddd0d34421
Reviewed-on: https://gerrit.libreoffice.org/36085Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarNoel Grandin <noel.grandin@collabora.co.uk>
üst ff339c89
......@@ -150,7 +150,7 @@ void basctl_Shell::InitInterface_Impl()
unsigned Shell::nShellCount = 0;
Shell::Shell( SfxViewFrame* pFrame_, SfxViewShell* /* pOldShell */ ) :
SfxViewShell( pFrame_, SfxViewShellFlags::CAN_PRINT | SfxViewShellFlags::NO_NEWWINDOW ),
SfxViewShell( pFrame_, SfxViewShellFlags::NO_NEWWINDOW ),
m_aCurDocument( ScriptDocument::getApplicationScriptDocument() ),
aHScrollBar( VclPtr<ScrollBar>::Create(&GetViewFrame()->GetWindow(), WinBits( WB_HSCROLL | WB_DRAG )) ),
aVScrollBar( VclPtr<ScrollBar>::Create(&GetViewFrame()->GetWindow(), WinBits( WB_VSCROLL | WB_DRAG )) ),
......
......@@ -4,7 +4,7 @@ import sys
import re
import io
callDict = dict()
callDict = dict() # callInfo tuple -> callValue
# clang does not always use exactly the same numbers in the type-parameter vars it generates
# so I need to substitute them to ensure we can match correctly.
......@@ -38,7 +38,7 @@ for callInfo, callValues in callDict.iteritems():
sourceLoc = callInfo[4]
functionSig = callInfo[0] + " " + callInfo[1]
# try and ignore setter methods
# try to ignore setter methods
if ("," not in nameAndParams) and (("::set" in nameAndParams) or ("::Set" in nameAndParams)):
continue
# ignore code that follows a common pattern
......@@ -67,4 +67,67 @@ with open("loplugin.constantparam.report", "wt") as f:
f.write(" " + v[1] + "\n")
f.write(" " + v[2] + "\n")
# -------------------------------------------------------------
# Now a fun set of heuristics to look for methods that
# take bitmask parameters where one or more of the bits in the
# bitmask is always one or always zero
# integer to hext str
def hex(i):
return "0x%x" % i
# I can't use python's ~ operator, because that produces negative numbers
def negate(i):
return (1 << 32) - 1 - i
tmp2list = list()
for callInfo, callValues in callDict.iteritems():
nameAndParams = callInfo[1]
if len(callValues) < 2:
continue
# we are only interested in enum parameters
if not "enum" in callInfo[3]: continue
if not "Flag" in callInfo[3] and not "flag" in callInfo[3] and not "Bit" in callInfo[3] and not "State" in callInfo[3]: continue
# try to ignore setter methods
if ("," not in nameAndParams) and (("::set" in nameAndParams) or ("::Set" in nameAndParams)):
continue
setBits = 0
clearBits = 0
continue_flag = False
first = True
for callValue in callValues:
if "unknown" == callValue or not callValue.isdigit():
continue_flag = True
break
if first:
setBits = int(callValue)
clearBits = negate(int(callValue))
first = False
else:
setBits = setBits & int(callValue)
clearBits = clearBits & negate(int(callValue))
# estimate allBits by using the highest bit we have seen
# TODO dump more precise information about the allBits values of enums
allBits = (1 << setBits.bit_length()) - 1
clearBits = clearBits & allBits
if continue_flag or (setBits == 0 and clearBits == 0): continue
sourceLoc = callInfo[4]
functionSig = callInfo[0] + " " + callInfo[1]
v2 = callInfo[3] + " " + callInfo[2]
if setBits != 0: v2 += " setBits=" + hex(setBits)
if clearBits != 0: v2 += " clearBits=" + hex(clearBits)
tmp2list.append((sourceLoc, functionSig, v2))
# sort results by filename:lineno
tmp2list.sort(key=lambda v: natural_sort_key(v[0]))
# print out the results
with open("loplugin.constantparam.report-bitmask-params", "wt") as f:
for v in tmp2list:
f.write(v[0] + "\n")
f.write(" " + v[1] + "\n")
f.write(" " + v[2] + "\n")
......@@ -119,16 +119,15 @@ namespace com { namespace sun { namespace star {
enum class SfxObjectShellFlags
{
HASOPENDOC = 0x01L,
HASMENU = 0x04L,
DONTCLOSE = 0x10L,
NODOCINFO = 0x20L,
STD_NORMAL = HASOPENDOC,
STD_NORMAL = 0x0000000,
HASMENU = 0x0000004,
DONTCLOSE = 0x0000010,
NODOCINFO = 0x0000020,
UNDEFINED = 0xf000000
};
namespace o3tl
{
template<> struct typed_flags<SfxObjectShellFlags> : is_typed_flags<SfxObjectShellFlags, 0xf000035> {};
template<> struct typed_flags<SfxObjectShellFlags> : is_typed_flags<SfxObjectShellFlags, 0xf000034> {};
}
#define SFX_TITLE_TITLE 0
......
......@@ -96,13 +96,12 @@ enum class SfxViewShellFlags
{
NONE = 0x0000,
HAS_PRINTOPTIONS = 0x0010, /* Options-Button and Options-Dialog in PrintDialog */
CAN_PRINT = 0x0020, /* Printing enabled without having to create a Printer */
NO_SHOW = 0x0040, /* Window of the ViewShell shall not be showed automatically */
NO_NEWWINDOW = 0x0100, /* Allow N View */
};
namespace o3tl
{
template<> struct typed_flags<SfxViewShellFlags> : is_typed_flags<SfxViewShellFlags, 0x0170> {};
template<> struct typed_flags<SfxViewShellFlags> : is_typed_flags<SfxViewShellFlags, 0x0150> {};
}
/* [Description]
......
......@@ -40,14 +40,13 @@ namespace vcl { class Region; }
enum class InitOutDevFlags
{
NONE = 0x0000,
FONT = 0x0001,
COLORS = 0x0002,
RASTEROP = 0x0004,
CLIPREGION = 0x0008,
};
namespace o3tl
{
template<> struct typed_flags<InitOutDevFlags> : is_typed_flags<InitOutDevFlags, 0x0f> {};
template<> struct typed_flags<InitOutDevFlags> : is_typed_flags<InitOutDevFlags, 0x03> {};
}
......@@ -70,7 +69,7 @@ private:
Color maLineColor;
Color maFillColor;
RasterOp meRasterOp;
vcl::Region* mpClipRegion;
vcl::Region* mpClipRegion;
void initAttrs();
......
......@@ -148,7 +148,7 @@ void ScPreviewShell::Construct( vcl::Window* pParent )
ScPreviewShell::ScPreviewShell( SfxViewFrame* pViewFrame,
SfxViewShell* pOldSh ) :
SfxViewShell( pViewFrame, SfxViewShellFlags::CAN_PRINT | SfxViewShellFlags::HAS_PRINTOPTIONS ),
SfxViewShell( pViewFrame, SfxViewShellFlags::HAS_PRINTOPTIONS ),
pDocShell( static_cast<ScDocShell*>(pViewFrame->GetObjectShell()) ),
mpFrameWindow(nullptr),
nSourceDesignMode( TRISTATE_INDET ),
......
......@@ -1634,7 +1634,7 @@ void ScTabViewShell::Construct( TriState nForceDesignMode )
ScTabViewShell::ScTabViewShell( SfxViewFrame* pViewFrame,
SfxViewShell* pOldSh ) :
SfxViewShell( pViewFrame, SfxViewShellFlags::CAN_PRINT | SfxViewShellFlags::HAS_PRINTOPTIONS ),
SfxViewShell( pViewFrame, SfxViewShellFlags::HAS_PRINTOPTIONS ),
ScDBFunc( &pViewFrame->GetWindow(), static_cast<ScDocShell&>(*pViewFrame->GetObjectShell()), this ),
eCurOST(OST_NONE),
nDrawSfxId(0),
......
......@@ -241,9 +241,7 @@ void ViewShellBase::InitInterface_Impl()
ViewShellBase::ViewShellBase (
SfxViewFrame* _pFrame,
SfxViewShell*)
: SfxViewShell (_pFrame,
SfxViewShellFlags::CAN_PRINT
| SfxViewShellFlags::HAS_PRINTOPTIONS),
: SfxViewShell (_pFrame, SfxViewShellFlags::HAS_PRINTOPTIONS),
mpImpl(),
mpDocShell (nullptr),
mpDocument (nullptr)
......
......@@ -928,14 +928,12 @@ void SfxObjectShell::PostActivateEvent_Impl( SfxViewFrame* pFrame )
void SfxObjectShell::SetActivateEvent_Impl(SfxEventHintId nId )
{
if ( GetFactory().GetFlags() & SfxObjectShellFlags::HASOPENDOC )
pImpl->nEventId = nId;
pImpl->nEventId = nId;
}
void SfxObjectShell::PrepareReload( )
/* [Description]
Is called before the Reload and gives the opportunity to clear any caches.
/*
Is called before the Reload and gives the opportunity to clear any caches.
*/
{
}
......
......@@ -371,9 +371,8 @@ void SfxViewFrame::INetState_Impl( SfxItemSet &rItemSet )
// Add/SaveToBookmark at BASIC-IDE, QUERY-EDITOR etc. disable
SfxObjectShell *pDocSh = GetObjectShell();
bool bPseudo = pDocSh && !( pDocSh->GetFactory().GetFlags() & SfxObjectShellFlags::HASOPENDOC );
bool bEmbedded = pDocSh && pDocSh->GetCreateMode() == SfxObjectCreateMode::EMBEDDED;
if ( !pDocSh || bPseudo || bEmbedded || !pDocSh->HasName() )
if ( !pDocSh || bEmbedded || !pDocSh->HasName() )
rItemSet.DisableItem( SID_CREATELINK );
}
......
......@@ -45,7 +45,6 @@ struct SfxViewShell_Impl
bool m_bControllerSet;
SfxShellArr_Impl aArr;
Size aMargin;
bool m_bCanPrint;
bool m_bHasPrintOptions;
bool m_bIsShowView;
bool m_bGotOwnership;
......
......@@ -233,7 +233,6 @@ sal_uInt32 SfxViewShell_Impl::m_nLastViewShellId = 0;
SfxViewShell_Impl::SfxViewShell_Impl(SfxViewShellFlags const nFlags)
: aInterceptorContainer( aMutex )
, m_bControllerSet(false)
, m_bCanPrint(nFlags & SfxViewShellFlags::CAN_PRINT)
, m_bHasPrintOptions(nFlags & SfxViewShellFlags::HAS_PRINTOPTIONS)
, m_bIsShowView(!(nFlags & SfxViewShellFlags::NO_SHOW))
, m_bGotOwnership(false)
......@@ -699,8 +698,7 @@ void SfxViewShell::GetState_Impl( SfxItemSet &rSet )
case SID_SETUPPRINTER:
case SID_PRINTER_NAME:
{
bool bEnabled = pImpl->m_bCanPrint
&& !Application::GetSettings().GetMiscSettings().GetDisablePrinting();
bool bEnabled = !Application::GetSettings().GetMiscSettings().GetDisablePrinting();
if ( bEnabled )
{
SfxPrinter *pPrinter = GetPrinter();
......
......@@ -1921,7 +1921,7 @@ void SmViewShell::GetState(SfxItemSet &rSet)
}
SmViewShell::SmViewShell(SfxViewFrame *pFrame_, SfxViewShell *)
: SfxViewShell(pFrame_, SfxViewShellFlags::HAS_PRINTOPTIONS | SfxViewShellFlags::CAN_PRINT)
: SfxViewShell(pFrame_, SfxViewShellFlags::HAS_PRINTOPTIONS)
, mpImpl(new SmViewShell_Impl)
, mpGraphic(VclPtr<SmGraphicWindow>::Create(this))
, maGraphicController(*mpGraphic.get(), SID_GAPHIC_SM, pFrame_->GetBindings())
......
......@@ -100,7 +100,7 @@ void SwPagePreview::InitInterface_Impl()
}
#define SWVIEWFLAGS ( SfxViewShellFlags::CAN_PRINT | SfxViewShellFlags::HAS_PRINTOPTIONS )
#define SWVIEWFLAGS SfxViewShellFlags::HAS_PRINTOPTIONS
#define MIN_PREVIEW_ZOOM 25
#define MAX_PREVIEW_ZOOM 600
......
......@@ -94,7 +94,7 @@ using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::ui::dialogs;
using namespace ::sfx2;
#define SWSRCVIEWFLAGS ( SfxViewShellFlags::CAN_PRINT | SfxViewShellFlags::NO_NEWWINDOW )
#define SWSRCVIEWFLAGS SfxViewShellFlags::NO_NEWWINDOW
#define SRC_SEARCHOPTIONS (SearchOptionFlags::ALL & ~SearchOptionFlags(SearchOptionFlags::FORMAT|SearchOptionFlags::FAMILIES|SearchOptionFlags::SEARCHALL))
......
......@@ -122,7 +122,7 @@ using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::lang;
using namespace ::com::sun::star::scanner;
#define SWVIEWFLAGS ( SfxViewShellFlags::CAN_PRINT | SfxViewShellFlags::HAS_PRINTOPTIONS)
#define SWVIEWFLAGS SfxViewShellFlags::HAS_PRINTOPTIONS
// Statics. OMG.
......
......@@ -138,18 +138,12 @@ void VCLXGraphics::InitOutputDevice( InitOutDevFlags nFlags )
mpOutputDevice->SetFillColor( maFillColor );
}
if ( nFlags & InitOutDevFlags::RASTEROP )
{
mpOutputDevice->SetRasterOp( meRasterOp );
}
mpOutputDevice->SetRasterOp( meRasterOp );
if ( nFlags & InitOutDevFlags::CLIPREGION )
{
if( mpClipRegion )
mpOutputDevice->SetClipRegion( *mpClipRegion );
else
mpOutputDevice->SetClipRegion();
}
if( mpClipRegion )
mpOutputDevice->SetClipRegion( *mpClipRegion );
else
mpOutputDevice->SetClipRegion();
}
}
......@@ -293,7 +287,7 @@ void VCLXGraphics::copy( const uno::Reference< awt::XDevice >& rxSource, sal_Int
DBG_ASSERT( pFromDev, "VCLXGraphics::copy - invalid device" );
if ( pFromDev )
{
InitOutputDevice( InitOutDevFlags::CLIPREGION|InitOutDevFlags::RASTEROP );
InitOutputDevice( InitOutDevFlags::NONE );
mpOutputDevice->DrawOutDev( Point( nDestX, nDestY ), Size( nDestWidth, nDestHeight ),
Point( nSourceX, nSourceY ), Size( nSourceWidth, nSourceHeight ), *pFromDev->GetOutputDevice() );
}
......@@ -306,7 +300,7 @@ void VCLXGraphics::draw( const uno::Reference< awt::XDisplayBitmap >& rxBitmapHa
if( mpOutputDevice )
{
InitOutputDevice( InitOutDevFlags::CLIPREGION|InitOutDevFlags::RASTEROP);
InitOutputDevice( InitOutDevFlags::NONE);
uno::Reference< awt::XBitmap > xBitmap( rxBitmapHandle, uno::UNO_QUERY );
BitmapEx aBmpEx = VCLUnoHelper::GetBitmap( xBitmap );
......@@ -338,7 +332,7 @@ void VCLXGraphics::drawPixel( sal_Int32 x, sal_Int32 y )
if( mpOutputDevice )
{
InitOutputDevice( InitOutDevFlags::CLIPREGION|InitOutDevFlags::RASTEROP|InitOutDevFlags::COLORS );
InitOutputDevice( InitOutDevFlags::COLORS );
mpOutputDevice->DrawPixel( Point( x, y ) );
}
}
......@@ -349,7 +343,7 @@ void VCLXGraphics::drawLine( sal_Int32 x1, sal_Int32 y1, sal_Int32 x2, sal_Int32
if( mpOutputDevice )
{
InitOutputDevice( InitOutDevFlags::CLIPREGION|InitOutDevFlags::RASTEROP|InitOutDevFlags::COLORS );
InitOutputDevice( InitOutDevFlags::COLORS );
mpOutputDevice->DrawLine( Point( x1, y1 ), Point( x2, y2 ) );
}
}
......@@ -360,7 +354,7 @@ void VCLXGraphics::drawRect( sal_Int32 x, sal_Int32 y, sal_Int32 width, sal_Int3
if( mpOutputDevice )
{
InitOutputDevice( InitOutDevFlags::CLIPREGION|InitOutDevFlags::RASTEROP|InitOutDevFlags::COLORS );
InitOutputDevice( InitOutDevFlags::COLORS );
mpOutputDevice->DrawRect( tools::Rectangle( Point( x, y ), Size( width, height ) ) );
}
}
......@@ -371,7 +365,7 @@ void VCLXGraphics::drawRoundedRect( sal_Int32 x, sal_Int32 y, sal_Int32 width, s
if( mpOutputDevice )
{
InitOutputDevice( InitOutDevFlags::CLIPREGION|InitOutDevFlags::RASTEROP|InitOutDevFlags::COLORS );
InitOutputDevice( InitOutDevFlags::COLORS );
mpOutputDevice->DrawRect( tools::Rectangle( Point( x, y ), Size( width, height ) ), nHorzRound, nVertRound );
}
}
......@@ -382,7 +376,7 @@ void VCLXGraphics::drawPolyLine( const uno::Sequence< sal_Int32 >& DataX, const
if( mpOutputDevice )
{
InitOutputDevice( InitOutDevFlags::CLIPREGION|InitOutDevFlags::RASTEROP|InitOutDevFlags::COLORS );
InitOutputDevice( InitOutDevFlags::COLORS );
mpOutputDevice->DrawPolyLine( VCLUnoHelper::CreatePolygon( DataX, DataY ) );
}
}
......@@ -393,7 +387,7 @@ void VCLXGraphics::drawPolygon( const uno::Sequence< sal_Int32 >& DataX, const u
if( mpOutputDevice )
{
InitOutputDevice( InitOutDevFlags::CLIPREGION|InitOutDevFlags::RASTEROP|InitOutDevFlags::COLORS );
InitOutputDevice( InitOutDevFlags::COLORS );
mpOutputDevice->DrawPolygon( VCLUnoHelper::CreatePolygon( DataX, DataY ) );
}
}
......@@ -404,7 +398,7 @@ void VCLXGraphics::drawPolyPolygon( const uno::Sequence< uno::Sequence< sal_Int3
if( mpOutputDevice )
{
InitOutputDevice( InitOutDevFlags::CLIPREGION|InitOutDevFlags::RASTEROP|InitOutDevFlags::COLORS );
InitOutputDevice( InitOutDevFlags::COLORS );
sal_uInt16 nPolys = (sal_uInt16) DataX.getLength();
tools::PolyPolygon aPolyPoly( nPolys );
for ( sal_uInt16 n = 0; n < nPolys; n++ )
......@@ -420,7 +414,7 @@ void VCLXGraphics::drawEllipse( sal_Int32 x, sal_Int32 y, sal_Int32 width, sal_I
if( mpOutputDevice )
{
InitOutputDevice( InitOutDevFlags::CLIPREGION|InitOutDevFlags::RASTEROP|InitOutDevFlags::COLORS );
InitOutputDevice( InitOutDevFlags::COLORS );
mpOutputDevice->DrawEllipse( tools::Rectangle( Point( x, y ), Size( width, height ) ) );
}
}
......@@ -431,7 +425,7 @@ void VCLXGraphics::drawArc( sal_Int32 x, sal_Int32 y, sal_Int32 width, sal_Int32
if( mpOutputDevice )
{
InitOutputDevice( InitOutDevFlags::CLIPREGION|InitOutDevFlags::RASTEROP|InitOutDevFlags::COLORS );
InitOutputDevice( InitOutDevFlags::COLORS );
mpOutputDevice->DrawArc( tools::Rectangle( Point( x, y ), Size( width, height ) ), Point( x1, y1 ), Point( x2, y2 ) );
}
}
......@@ -442,7 +436,7 @@ void VCLXGraphics::drawPie( sal_Int32 x, sal_Int32 y, sal_Int32 width, sal_Int32
if( mpOutputDevice )
{
InitOutputDevice( InitOutDevFlags::CLIPREGION|InitOutDevFlags::RASTEROP|InitOutDevFlags::COLORS );
InitOutputDevice( InitOutDevFlags::COLORS );
mpOutputDevice->DrawPie( tools::Rectangle( Point( x, y ), Size( width, height ) ), Point( x1, y1 ), Point( x2, y2 ) );
}
}
......@@ -453,7 +447,7 @@ void VCLXGraphics::drawChord( sal_Int32 x, sal_Int32 y, sal_Int32 width, sal_Int
if( mpOutputDevice )
{
InitOutputDevice( InitOutDevFlags::CLIPREGION|InitOutDevFlags::RASTEROP|InitOutDevFlags::COLORS );
InitOutputDevice( InitOutDevFlags::COLORS );
mpOutputDevice->DrawChord( tools::Rectangle( Point( x, y ), Size( width, height ) ), Point( x1, y1 ), Point( x2, y2 ) );
}
}
......@@ -464,7 +458,7 @@ void VCLXGraphics::drawGradient( sal_Int32 x, sal_Int32 y, sal_Int32 width, sal_
if( mpOutputDevice )
{
InitOutputDevice( InitOutDevFlags::CLIPREGION|InitOutDevFlags::RASTEROP|InitOutDevFlags::COLORS );
InitOutputDevice( InitOutDevFlags::COLORS );
Gradient aGradient((GradientStyle)rGradient.Style, rGradient.StartColor, rGradient.EndColor);
aGradient.SetAngle(rGradient.Angle);
aGradient.SetBorder(rGradient.Border);
......@@ -483,7 +477,7 @@ void VCLXGraphics::drawText( sal_Int32 x, sal_Int32 y, const OUString& rText )
if( mpOutputDevice )
{
InitOutputDevice( InitOutDevFlags::CLIPREGION|InitOutDevFlags::RASTEROP|InitOutDevFlags::COLORS |InitOutDevFlags::FONT);
InitOutputDevice( InitOutDevFlags::COLORS |InitOutDevFlags::FONT);
mpOutputDevice->DrawText( Point( x, y ), rText );
}
}
......@@ -494,7 +488,7 @@ void VCLXGraphics::drawTextArray( sal_Int32 x, sal_Int32 y, const OUString& rTex
if( mpOutputDevice )
{
InitOutputDevice( InitOutDevFlags::CLIPREGION|InitOutDevFlags::RASTEROP|InitOutDevFlags::COLORS|InitOutDevFlags::FONT );
InitOutputDevice( InitOutDevFlags::COLORS|InitOutDevFlags::FONT );
std::unique_ptr<long []> pDXA(new long[rText.getLength()]);
for(int i = 0; i < rText.getLength(); i++)
{
......@@ -514,7 +508,7 @@ void VCLXGraphics::drawImage( sal_Int32 x, sal_Int32 y, sal_Int32 width, sal_Int
Image aImage( xGraphic );
if ( !!aImage )
{
InitOutputDevice( InitOutDevFlags::CLIPREGION|InitOutDevFlags::RASTEROP|InitOutDevFlags::COLORS );
InitOutputDevice( InitOutDevFlags::COLORS );
mpOutputDevice->DrawImage( Point( x, y ), Size( width, height ), aImage, static_cast<DrawImageFlags>(nStyle) );
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment