Kaydet (Commit) 1800862c authored tarafından Stephan Bergmann's avatar Stephan Bergmann

loplugin:stringconstant: look into 'char const * const var = "..."'

Change-Id: I52a97b8ec273509131c2200e47527221cb62d7ee
üst b33b4413
...@@ -929,21 +929,17 @@ bool StringConstant::isStringConstant( ...@@ -929,21 +929,17 @@ bool StringConstant::isStringConstant(
// Look inside RTL_CONSTASCII_STRINGPARAM: // Look inside RTL_CONSTASCII_STRINGPARAM:
if (loplugin::TypeCheck(t).Pointer().Const().Char()) { if (loplugin::TypeCheck(t).Pointer().Const().Char()) {
auto e2 = dyn_cast<UnaryOperator>(expr); auto e2 = dyn_cast<UnaryOperator>(expr);
if (e2 == nullptr || e2->getOpcode() != UO_AddrOf) { if (e2 != nullptr && e2->getOpcode() == UO_AddrOf) {
return false; auto e3 = dyn_cast<ArraySubscriptExpr>(
} e2->getSubExpr()->IgnoreParenImpCasts());
auto e3 = dyn_cast<ArraySubscriptExpr>( if (e3 == nullptr || !isZero(e3->getIdx()->IgnoreParenImpCasts())) {
e2->getSubExpr()->IgnoreParenImpCasts()); return false;
if (e3 == nullptr || !isZero(e3->getIdx()->IgnoreParenImpCasts())) { }
return false; expr = e3->getBase()->IgnoreParenImpCasts();
t = expr->getType();
} }
expr = e3->getBase()->IgnoreParenImpCasts();
t = expr->getType();
} }
if (!(t->isConstantArrayType() && t.isConstQualified() if (!t.isConstQualified()) {
&& (loplugin::TypeCheck(t->getAsArrayTypeUnsafe()->getElementType())
.Char())))
{
return false; return false;
} }
DeclRefExpr const * dre = dyn_cast<DeclRefExpr>(expr); DeclRefExpr const * dre = dyn_cast<DeclRefExpr>(expr);
...@@ -956,6 +952,14 @@ bool StringConstant::isStringConstant( ...@@ -956,6 +952,14 @@ bool StringConstant::isStringConstant(
} }
} }
} }
if (!(loplugin::TypeCheck(t).Pointer().Const().Char()
|| (t->isConstantArrayType()
&& (loplugin::TypeCheck(
t->getAsArrayTypeUnsafe()->getElementType())
.Char()))))
{
return false;
}
StringLiteral const * lit = dyn_cast<StringLiteral>(expr); StringLiteral const * lit = dyn_cast<StringLiteral>(expr);
if (lit != nullptr) { if (lit != nullptr) {
if (!lit->isAscii()) { if (!lit->isAscii()) {
...@@ -986,7 +990,9 @@ bool StringConstant::isStringConstant( ...@@ -986,7 +990,9 @@ bool StringConstant::isStringConstant(
case APValue::LValue: case APValue::LValue:
{ {
Expr const * e = v.getLValueBase().dyn_cast<Expr const *>(); Expr const * e = v.getLValueBase().dyn_cast<Expr const *>();
assert(e != nullptr); //TODO??? if (e == nullptr) {
return false;
}
if (!v.getLValueOffset().isZero()) { if (!v.getLValueOffset().isZero()) {
return false; //TODO return false; //TODO
} }
...@@ -1140,6 +1146,12 @@ void StringConstant::reportChange( ...@@ -1140,6 +1146,12 @@ void StringConstant::reportChange(
<< call->getSourceRange(); << call->getSourceRange();
return; return;
} }
report(
DiagnosticsEngine::Warning,
"TODO call inside %0", getMemberLocation(expr))
<< fdecl->getQualifiedNameAsString()
<< expr->getSourceRange();
return;
} else { } else {
assert(pass == PassThrough::NonEmptyConstantString); assert(pass == PassThrough::NonEmptyConstantString);
if ((dc.Function("equals").Class("OUString") if ((dc.Function("equals").Class("OUString")
...@@ -1160,29 +1172,17 @@ void StringConstant::reportChange( ...@@ -1160,29 +1172,17 @@ void StringConstant::reportChange(
<< expr->getSourceRange(); << expr->getSourceRange();
return; return;
} }
if ((dc.Operator(OO_Plus).Namespace("rtl") report(
.GlobalNamespace()) DiagnosticsEngine::Warning,
|| (dc.Operator(OO_Plus).Class("OUString") ("rewrite call of " + original + " with "
.Namespace("rtl").GlobalNamespace())) + describeChangeKind(kind)
{ + (" in call of %0 as (implicit) construction of"
report( " rtl::OUString")),
DiagnosticsEngine::Warning, getMemberLocation(expr))
("rewrite call of " + original + " with " << fdecl->getQualifiedNameAsString()
+ describeChangeKind(kind) << expr->getSourceRange();
+ (" in call of %0 as (implicit) construction" return;
" of rtl::OUString")),
getMemberLocation(expr))
<< fdecl->getQualifiedNameAsString()
<< expr->getSourceRange();
return;
}
} }
report(
DiagnosticsEngine::Warning,
"TODO call inside %0", getMemberLocation(expr))
<< fdecl->getQualifiedNameAsString()
<< expr->getSourceRange();
return;
} else if (isa<CXXConstructExpr>(call)) { } else if (isa<CXXConstructExpr>(call)) {
auto cdecl = cast<CXXConstructExpr>(call)->getConstructor() auto cdecl = cast<CXXConstructExpr>(call)->getConstructor()
->getParent(); ->getParent();
......
...@@ -32,9 +32,6 @@ namespace oox { ...@@ -32,9 +32,6 @@ namespace oox {
namespace oox { namespace oox {
namespace ole { namespace ole {
const sal_Char* const AX_GUID_CFONT = "{AFC20920-DA4E-11CE-B943-00AA006887B4}";
const sal_uInt32 AX_FONTDATA_BOLD = 0x00000001; const sal_uInt32 AX_FONTDATA_BOLD = 0x00000001;
const sal_uInt32 AX_FONTDATA_ITALIC = 0x00000002; const sal_uInt32 AX_FONTDATA_ITALIC = 0x00000002;
const sal_uInt32 AX_FONTDATA_UNDERLINE = 0x00000004; const sal_uInt32 AX_FONTDATA_UNDERLINE = 0x00000004;
......
...@@ -102,7 +102,7 @@ bool AxFontData::importStdFont( BinaryInputStream& rInStrm ) ...@@ -102,7 +102,7 @@ bool AxFontData::importStdFont( BinaryInputStream& rInStrm )
bool AxFontData::importGuidAndFont( BinaryInputStream& rInStrm ) bool AxFontData::importGuidAndFont( BinaryInputStream& rInStrm )
{ {
OUString aGuid = OleHelper::importGuid( rInStrm ); OUString aGuid = OleHelper::importGuid( rInStrm );
if( aGuid.equalsAscii( AX_GUID_CFONT ) ) if( aGuid == "{AFC20920-DA4E-11CE-B943-00AA006887B4}" )
return importBinaryModel( rInStrm ); return importBinaryModel( rInStrm );
if ( aGuid == OLE_GUID_STDFONT ) if ( aGuid == OLE_GUID_STDFONT )
return importStdFont( rInStrm ); return importStdFont( rInStrm );
......
...@@ -45,9 +45,9 @@ CPPUNIT_TEST_SUITE_REGISTRATION(test::oustring::Compare); ...@@ -45,9 +45,9 @@ CPPUNIT_TEST_SUITE_REGISTRATION(test::oustring::Compare);
void test::oustring::Compare::equalsIgnoreAsciiCaseAscii() void test::oustring::Compare::equalsIgnoreAsciiCaseAscii()
{ {
const char* const abc = "abc"; const char* abc = "abc";
const char* const abcd = "abcd"; const char* abcd = "abcd";
const char* const empty = ""; const char* empty = "";
CPPUNIT_ASSERT(!rtl::OUString().equalsIgnoreAsciiCaseAscii(abc)); CPPUNIT_ASSERT(!rtl::OUString().equalsIgnoreAsciiCaseAscii(abc));
CPPUNIT_ASSERT(!rtl::OUString().equalsIgnoreAsciiCaseAsciiL(abc,3)); CPPUNIT_ASSERT(!rtl::OUString().equalsIgnoreAsciiCaseAsciiL(abc,3));
CPPUNIT_ASSERT(!rtl::OUString("abc"). CPPUNIT_ASSERT(!rtl::OUString("abc").
......
...@@ -59,7 +59,7 @@ const sal_uInt16 BIFF_REFFLAG_ROW1REL = 0x0002; ...@@ -59,7 +59,7 @@ const sal_uInt16 BIFF_REFFLAG_ROW1REL = 0x0002;
const sal_uInt16 BIFF_REFFLAG_COL2REL = 0x0004; const sal_uInt16 BIFF_REFFLAG_COL2REL = 0x0004;
const sal_uInt16 BIFF_REFFLAG_ROW2REL = 0x0008; const sal_uInt16 BIFF_REFFLAG_ROW2REL = 0x0008;
const sal_Char* const spcOoxPrefix = "_xlnm."; const OUStringLiteral spcOoxPrefix("_xlnm.");
const sal_Char* const sppcBaseNames[] = const sal_Char* const sppcBaseNames[] =
{ {
...@@ -92,21 +92,19 @@ OUString lclGetBaseName( sal_Unicode cBuiltinId ) ...@@ -92,21 +92,19 @@ OUString lclGetBaseName( sal_Unicode cBuiltinId )
OUString lclGetPrefixedName( sal_Unicode cBuiltinId ) OUString lclGetPrefixedName( sal_Unicode cBuiltinId )
{ {
return OUStringBuffer().appendAscii( spcOoxPrefix ).append( lclGetBaseName( cBuiltinId ) ).makeStringAndClear(); return OUStringBuffer( spcOoxPrefix ).append( lclGetBaseName( cBuiltinId ) ).makeStringAndClear();
} }
/** returns the built-in name identifier from a prefixed built-in name, e.g. '_xlnm.Print_Area'. */ /** returns the built-in name identifier from a prefixed built-in name, e.g. '_xlnm.Print_Area'. */
sal_Unicode lclGetBuiltinIdFromPrefixedName( const OUString& rModelName ) sal_Unicode lclGetBuiltinIdFromPrefixedName( const OUString& rModelName )
{ {
OUString aPrefix = OUString::createFromAscii( spcOoxPrefix ); if( rModelName.matchIgnoreAsciiCase( spcOoxPrefix ) )
sal_Int32 nPrefixLen = aPrefix.getLength();
if( rModelName.matchIgnoreAsciiCase( aPrefix ) )
{ {
for( sal_Unicode cBuiltinId = 0; cBuiltinId < SAL_N_ELEMENTS( sppcBaseNames ); ++cBuiltinId ) for( sal_Unicode cBuiltinId = 0; cBuiltinId < SAL_N_ELEMENTS( sppcBaseNames ); ++cBuiltinId )
{ {
OUString aBaseName = lclGetBaseName( cBuiltinId ); OUString aBaseName = lclGetBaseName( cBuiltinId );
sal_Int32 nBaseNameLen = aBaseName.getLength(); sal_Int32 nBaseNameLen = aBaseName.getLength();
if( (rModelName.getLength() == nPrefixLen + nBaseNameLen) && rModelName.matchIgnoreAsciiCase( aBaseName, nPrefixLen ) ) if( (rModelName.getLength() == spcOoxPrefix.size + nBaseNameLen) && rModelName.matchIgnoreAsciiCase( aBaseName, spcOoxPrefix.size ) )
return cBuiltinId; return cBuiltinId;
} }
} }
......
...@@ -2326,7 +2326,6 @@ void Dxf::fillToItemSet( SfxItemSet& rSet ) const ...@@ -2326,7 +2326,6 @@ void Dxf::fillToItemSet( SfxItemSet& rSet ) const
namespace { namespace {
const sal_Char* const spcStyleNamePrefix = "Excel Built-in ";
const sal_Char* const sppcStyleNames[] = const sal_Char* const sppcStyleNames[] =
{ {
"Normal", "Normal",
...@@ -2389,8 +2388,7 @@ const sal_Int32 snStyleNamesCount = static_cast< sal_Int32 >( SAL_N_ELEMENTS( sp ...@@ -2389,8 +2388,7 @@ const sal_Int32 snStyleNamesCount = static_cast< sal_Int32 >( SAL_N_ELEMENTS( sp
OUString lclGetBuiltinStyleName( sal_Int32 nBuiltinId, const OUString& rName, sal_Int32 nLevel = 0 ) OUString lclGetBuiltinStyleName( sal_Int32 nBuiltinId, const OUString& rName, sal_Int32 nLevel = 0 )
{ {
OSL_ENSURE( (0 <= nBuiltinId) && (nBuiltinId < snStyleNamesCount), "lclGetBuiltinStyleName - unknown built-in style" ); OSL_ENSURE( (0 <= nBuiltinId) && (nBuiltinId < snStyleNamesCount), "lclGetBuiltinStyleName - unknown built-in style" );
OUStringBuffer aStyleName; OUStringBuffer aStyleName("Excel Built-in ");
aStyleName.appendAscii( spcStyleNamePrefix );
if( (0 <= nBuiltinId) && (nBuiltinId < snStyleNamesCount) && (sppcStyleNames[ nBuiltinId ] != nullptr) ) if( (0 <= nBuiltinId) && (nBuiltinId < snStyleNamesCount) && (sppcStyleNames[ nBuiltinId ] != nullptr) )
aStyleName.appendAscii( sppcStyleNames[ nBuiltinId ] ); aStyleName.appendAscii( sppcStyleNames[ nBuiltinId ] );
else if( !rName.isEmpty() ) else if( !rName.isEmpty() )
......
...@@ -67,9 +67,6 @@ using namespace ::com::sun::star::document; ...@@ -67,9 +67,6 @@ using namespace ::com::sun::star::document;
namespace scripting_protocolhandler namespace scripting_protocolhandler
{ {
const sal_Char * const MYSERVICENAME = "com.sun.star.frame.ProtocolHandler";
const sal_Char * const MYIMPLNAME = "com.sun.star.comp.ScriptProtocolHandler";
void SAL_CALL ScriptProtocolHandler::initialize( void SAL_CALL ScriptProtocolHandler::initialize(
const css::uno::Sequence < css::uno::Any >& aArguments ) const css::uno::Sequence < css::uno::Any >& aArguments )
throw ( css::uno::Exception, std::exception ) throw ( css::uno::Exception, std::exception )
...@@ -468,14 +465,13 @@ throw( RuntimeException, std::exception ) ...@@ -468,14 +465,13 @@ throw( RuntimeException, std::exception )
/* Helper for XServiceInfo */ /* Helper for XServiceInfo */
Sequence< OUString > ScriptProtocolHandler::impl_getStaticSupportedServiceNames() Sequence< OUString > ScriptProtocolHandler::impl_getStaticSupportedServiceNames()
{ {
Sequence< OUString > seqServiceNames { OUString::createFromAscii(::scripting_protocolhandler::MYSERVICENAME) }; return {"com.sun.star.frame.ProtocolHandler"};
return seqServiceNames;
} }
/* Helper for XServiceInfo */ /* Helper for XServiceInfo */
OUString ScriptProtocolHandler::impl_getStaticImplementationName() OUString ScriptProtocolHandler::impl_getStaticImplementationName()
{ {
return OUString::createFromAscii( ::scripting_protocolhandler::MYIMPLNAME ); return OUString("com.sun.star.comp.ScriptProtocolHandler");
} }
/* Helper for registry */ /* Helper for registry */
......
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