compilerplugins/clang/stringconstant.cxx | 63 +++++++++++++++++++---- connectivity/source/drivers/kab/KDriver.cxx | 20 +++---- shell/source/backends/localebe/localebackend.cxx | 2 vcl/generic/fontmanager/helper.cxx | 14 ++--- vcl/generic/print/genprnpsp.cxx | 2 vcl/generic/print/printerjob.cxx | 2 vcl/unx/generic/printer/cupsmgr.cxx | 2 vcl/unx/kde/UnxCommandThread.cxx | 2 vcl/unx/kde/UnxFilePicker.cxx | 58 ++++++++++----------- vcl/unx/x11/x11sys.cxx | 2 10 files changed, 106 insertions(+), 61 deletions(-)
New commits: commit 3286c6c854cf7dfa71c24ff98cd47bdddf6b0c27 Author: Stephan Bergmann <sberg...@redhat.com> Date: Mon Aug 31 08:07:39 2015 +0200 loplugin:stringconstant: OUStringBuffer: appendAscii -> append Change-Id: I0d1c988aad308435542dbd381fcf6bf7e1af6290 diff --git a/compilerplugins/clang/stringconstant.cxx b/compilerplugins/clang/stringconstant.cxx index 7cc6d9a..5c675a8 100644 --- a/compilerplugins/clang/stringconstant.cxx +++ b/compilerplugins/clang/stringconstant.cxx @@ -12,6 +12,7 @@ #include <stack> #include <string> +#include "compat.hxx" #include "plugin.hxx" // Define a "string constant" to be a constant expression either of type "array @@ -47,10 +48,11 @@ SourceLocation getMemberLocation(Expr const * expr) { } class StringConstant: - public RecursiveASTVisitor<StringConstant>, public loplugin::Plugin + public RecursiveASTVisitor<StringConstant>, public loplugin::RewritePlugin { public: - explicit StringConstant(InstantiationData const & data): Plugin(data) {} + explicit StringConstant(InstantiationData const & data): RewritePlugin(data) + {} void run() override; @@ -83,7 +85,8 @@ private: void reportChange( Expr const * expr, ChangeKind kind, std::string const & original, - std::string const & replacement, PassThrough pass); + std::string const & replacement, PassThrough pass, + char const * rewriteFrom, char const * rewriteTo); void checkEmpty( CallExpr const * expr, std::string const & qname, TreatEmpty treatEmpty, @@ -91,7 +94,8 @@ private: void handleChar( CallExpr const * expr, unsigned arg, std::string const & qname, - std::string const & replacement, TreatEmpty treatEmpty, bool literal); + std::string const & replacement, TreatEmpty treatEmpty, bool literal, + char const * rewriteFrom = nullptr, char const * rewriteTo = nullptr); void handleCharLen( CallExpr const * expr, unsigned arg1, unsigned arg2, @@ -524,6 +528,24 @@ bool StringConstant::VisitCallExpr(CallExpr const * expr) { } return true; } + if (qname == "rtl::OUStringBuffer::appendAscii" + && fdecl->getNumParams() == 1) + { + // u.appendAscii("foo") -> u.append("foo") + handleChar( + expr, 0, qname, "rtl::OUStringBuffer::append", TreatEmpty::Error, + true, "appendAscii", "append"); + return true; + } + if (qname == "rtl::OUStringBuffer::appendAscii" + && fdecl->getNumParams() == 2) + { + // u.appendAscii("foo", 3) -> u.append("foo"): + handleCharLen( + expr, 0, 1, qname, "rtl::OUStringBuffer::append", + TreatEmpty::Error); + return true; + } return true; } @@ -856,8 +878,10 @@ bool StringConstant::isZero(Expr const * expr) { void StringConstant::reportChange( Expr const * expr, ChangeKind kind, std::string const & original, - std::string const & replacement, PassThrough pass) + std::string const & replacement, PassThrough pass, char const * rewriteFrom, + char const * rewriteTo) { + assert((rewriteFrom == nullptr) == (rewriteTo == nullptr)); if (pass != PassThrough::No && !calls_.empty()) { Expr const * call = calls_.top(); CallExpr::const_arg_iterator argsBeg; @@ -1005,6 +1029,23 @@ void StringConstant::reportChange( } } } + if (rewriter != nullptr && rewriteFrom != nullptr) { + SourceLocation loc = getMemberLocation(expr); + while (compiler.getSourceManager().isMacroArgExpansion(loc)) { + loc = compiler.getSourceManager().getImmediateMacroCallerLoc(loc); + } + if (compat::isMacroBodyExpansion(compiler, loc)) { + loc = compiler.getSourceManager().getSpellingLoc(loc); + } + unsigned n = Lexer::MeasureTokenLength( + loc, compiler.getSourceManager(), compiler.getLangOpts()); + if ((std::string(compiler.getSourceManager().getCharacterData(loc), n) + == rewriteFrom) + && replaceText(loc, n, rewriteTo)) + { + return; + } + } report( DiagnosticsEngine::Warning, ("rewrite call of " + original + " with " + describeChangeKind(kind) @@ -1040,7 +1081,8 @@ void StringConstant::checkEmpty( void StringConstant::handleChar( CallExpr const * expr, unsigned arg, std::string const & qname, - std::string const & replacement, TreatEmpty treatEmpty, bool literal) + std::string const & replacement, TreatEmpty treatEmpty, bool literal, + char const * rewriteFrom, char const * rewriteTo) { unsigned n; bool non; @@ -1087,7 +1129,8 @@ void StringConstant::handleChar( ? (n == 0 ? PassThrough::EmptyConstantString : PassThrough::NonEmptyConstantString) - : PassThrough::No)); + : PassThrough::No), + rewriteFrom, rewriteTo); } void StringConstant::handleCharLen( @@ -1158,7 +1201,9 @@ void StringConstant::handleCharLen( } std::string repl(replacement); checkEmpty(expr, qname, treatEmpty, n, &repl); - reportChange(expr, ChangeKind::CharLen, qname, repl, PassThrough::No); + reportChange( + expr, ChangeKind::CharLen, qname, repl, PassThrough::No, nullptr, + nullptr); } void StringConstant::handleOUStringCtor( @@ -1228,7 +1273,7 @@ void StringConstant::handleOUStringCtor( << qname << expr->getSourceRange(); } -loplugin::Plugin::Registration< StringConstant > X("stringconstant"); +loplugin::Plugin::Registration< StringConstant > X("stringconstant", true); } commit 0f3ccde7fef8550837f0db52d706281975bc2523 Author: Stephan Bergmann <sberg...@redhat.com> Date: Mon Aug 31 14:37:41 2015 +0200 loplugin:stringconstant: OUStringBuffer: appendAscii -> append Change-Id: I83f45260158f5282b857458046d2e324be85a7b5 diff --git a/vcl/generic/fontmanager/helper.cxx b/vcl/generic/fontmanager/helper.cxx index 4517c6d..2dca718 100644 --- a/vcl/generic/fontmanager/helper.cxx +++ b/vcl/generic/fontmanager/helper.cxx @@ -119,7 +119,7 @@ void psp::getPrinterPathList( std::list< OUString >& rPathList, const char* pSub aPathBuffer.append( getOfficePath( psp::InstallationRootPath ) ); if( !aPathBuffer.isEmpty() ) { - aPathBuffer.appendAscii( "/" LIBO_SHARE_FOLDER "/psprint" ); + aPathBuffer.append( "/" LIBO_SHARE_FOLDER "/psprint" ); if( pSubDir ) { aPathBuffer.append( '/' ); @@ -131,7 +131,7 @@ void psp::getPrinterPathList( std::list< OUString >& rPathList, const char* pSub aPathBuffer.append( getOfficePath( psp::UserPath ) ); if( !aPathBuffer.isEmpty() ) { - aPathBuffer.appendAscii( "/user/psprint" ); + aPathBuffer.append( "/user/psprint" ); if( pSubDir ) { aPathBuffer.append( '/' ); @@ -201,7 +201,7 @@ OUString psp::getFontPath() // #i53530# Path from CustomDataUrl will completely // replace net and user paths if the path exists aPathBuffer.append(aConfigPath); - aPathBuffer.appendAscii("/" LIBO_SHARE_FOLDER "/fonts"); + aPathBuffer.append("/" LIBO_SHARE_FOLDER "/fonts"); // check existence of config path struct stat aStat; if( 0 != stat( OUStringToOString( aPathBuffer.makeStringAndClear(), osl_getThreadTextEncoding() ).getStr(), &aStat ) @@ -210,7 +210,7 @@ OUString psp::getFontPath() else { aPathBuffer.append(aConfigPath); - aPathBuffer.appendAscii("/" LIBO_SHARE_FOLDER "/fonts"); + aPathBuffer.append("/" LIBO_SHARE_FOLDER "/fonts"); } } if( aConfigPath.isEmpty() ) @@ -218,14 +218,14 @@ OUString psp::getFontPath() if( !aInstallationRootPath.isEmpty() ) { aPathBuffer.append( aInstallationRootPath ); - aPathBuffer.appendAscii( "/" LIBO_SHARE_FOLDER "/fonts/truetype;"); + aPathBuffer.append( "/" LIBO_SHARE_FOLDER "/fonts/truetype;"); aPathBuffer.append( aInstallationRootPath ); - aPathBuffer.appendAscii( "/" LIBO_SHARE_FOLDER "/fonts/type1;" ); + aPathBuffer.append( "/" LIBO_SHARE_FOLDER "/fonts/type1;" ); } if( !aUserPath.isEmpty() ) { aPathBuffer.append( aUserPath ); - aPathBuffer.appendAscii( "/user/fonts" ); + aPathBuffer.append( "/user/fonts" ); } } diff --git a/vcl/generic/print/genprnpsp.cxx b/vcl/generic/print/genprnpsp.cxx index 576a24f..0602636 100644 --- a/vcl/generic/print/genprnpsp.cxx +++ b/vcl/generic/print/genprnpsp.cxx @@ -919,7 +919,7 @@ bool PspSalPrinter::StartJob( OUStringBuffer aFileName( getPdfDir( rInfo ) ); aFileName.append( '/' ); aFileName.append( rJobName ); - aFileName.appendAscii( ".pdf" ); + aFileName.append( ".pdf" ); m_aFileName = aFileName.makeStringAndClear(); } break; diff --git a/vcl/generic/print/printerjob.cxx b/vcl/generic/print/printerjob.cxx index 30b51f3..2034bed 100644 --- a/vcl/generic/print/printerjob.cxx +++ b/vcl/generic/print/printerjob.cxx @@ -238,7 +238,7 @@ createSpoolDir () { OUStringBuffer aDir( aTmpDir.getLength() + 16 ); aDir.append( aTmpDir ); - aDir.appendAscii( "/psp" ); + aDir.append( "/psp" ); aDir.append(nRand); OUString aResult = aDir.makeStringAndClear(); if( osl::Directory::create( aResult ) == osl::FileBase::E_None ) diff --git a/vcl/unx/generic/printer/cupsmgr.cxx b/vcl/unx/generic/printer/cupsmgr.cxx index 20a27c2..17d2cf2 100644 --- a/vcl/unx/generic/printer/cupsmgr.cxx +++ b/vcl/unx/generic/printer/cupsmgr.cxx @@ -324,7 +324,7 @@ void CUPSManager::initialize() } OUStringBuffer aBuf( 256 ); - aBuf.appendAscii( "CUPS:" ); + aBuf.append( "CUPS:" ); aBuf.append( aPrinterName ); // note: the parser that goes with the PrinterInfo // is created implicitly by the JobData::operator=() diff --git a/vcl/unx/kde/UnxCommandThread.cxx b/vcl/unx/kde/UnxCommandThread.cxx index 46ff51c..b7c4a86 100644 --- a/vcl/unx/kde/UnxCommandThread.cxx +++ b/vcl/unx/kde/UnxCommandThread.cxx @@ -48,7 +48,7 @@ namespace { if ( pUnicode != pEnd ) { if ( *pUnicode == 'n' ) - aBuffer.appendAscii( "\n", 1 ); + aBuffer.append( "\n" ); else aBuffer.append( *pUnicode ); } diff --git a/vcl/unx/kde/UnxFilePicker.cxx b/vcl/unx/kde/UnxFilePicker.cxx index faeb4e0..a3bf19c 100644 --- a/vcl/unx/kde/UnxFilePicker.cxx +++ b/vcl/unx/kde/UnxFilePicker.cxx @@ -82,21 +82,21 @@ void appendEscaped( OUStringBuffer &rBuffer, const OUString &rString ) const sal_Unicode *pUnicode = rString.getStr(); const sal_Unicode *pEnd = pUnicode + rString.getLength(); - rBuffer.appendAscii( "\"" , 1 ); + rBuffer.append( "\"" ); for ( ; pUnicode != pEnd; ++pUnicode ) { if ( *pUnicode == '\\' ) - rBuffer.appendAscii( "\\\\", 2 ); + rBuffer.append( "\\\\" ); else if ( *pUnicode == '"' ) - rBuffer.appendAscii( "\\\"", 2 ); + rBuffer.append( "\\\"" ); else if ( *pUnicode == '\n' ) - rBuffer.appendAscii( "\\n", 2 ); + rBuffer.append( "\\n" ); else rBuffer.append( *pUnicode ); } - rBuffer.appendAscii( "\"", 1 ); + rBuffer.append( "\"" ); } bool controlIdInfo( sal_Int16 nControlId, OUString &rType, sal_Int32 &rTitleId ) @@ -258,7 +258,7 @@ void SAL_CALL UnxFilePicker::setTitle( const OUString &rTitle ) OUStringBuffer aBuffer( 1024 ); - aBuffer.appendAscii( "setTitle " ); + aBuffer.append( "setTitle " ); appendEscaped( aBuffer, rTitle ); sendCommand( aBuffer.makeStringAndClear() ); @@ -302,7 +302,7 @@ void SAL_CALL UnxFilePicker::setDefaultName( const OUString &rName ) OUStringBuffer aBuffer( 1024 ); - aBuffer.appendAscii( "setDefaultName " ); + aBuffer.append( "setDefaultName " ); appendEscaped( aBuffer, rName ); sendCommand( aBuffer.makeStringAndClear() ); @@ -316,7 +316,7 @@ void SAL_CALL UnxFilePicker::setDisplayDirectory( const OUString &rDirectory ) OUStringBuffer aBuffer( 1024 ); - aBuffer.appendAscii( "setDirectory " ); + aBuffer.append( "setDirectory " ); appendEscaped( aBuffer, rDirectory ); sendCommand( aBuffer.makeStringAndClear() ); @@ -354,9 +354,9 @@ void SAL_CALL UnxFilePicker::appendFilter( const OUString &rTitle, const OUStrin OUStringBuffer aBuffer( 1024 ); - aBuffer.appendAscii( "appendFilter " ); + aBuffer.append( "appendFilter " ); appendEscaped( aBuffer, rTitle ); - aBuffer.appendAscii( " ", 1 ); + aBuffer.append( " " ); appendEscaped( aBuffer, rFilter ); sendCommand( aBuffer.makeStringAndClear() ); @@ -370,7 +370,7 @@ void SAL_CALL UnxFilePicker::setCurrentFilter( const OUString &rTitle ) OUStringBuffer aBuffer( 1024 ); - aBuffer.appendAscii( "setCurrentFilter " ); + aBuffer.append( "setCurrentFilter " ); appendEscaped( aBuffer, rTitle ); sendCommand( aBuffer.makeStringAndClear() ); @@ -396,16 +396,16 @@ void SAL_CALL UnxFilePicker::appendFilterGroup( const OUString &rGroupTitle, con OUStringBuffer aBuffer( 1024 ); - aBuffer.appendAscii( "appendFilterGroup " ); + aBuffer.append( "appendFilterGroup " ); appendEscaped( aBuffer, rGroupTitle ); for ( sal_Int32 i = 0; i < rFilters.getLength(); ++i ) { beans::StringPair aPair = rFilters[i]; - aBuffer.appendAscii( " ", 1 ); + aBuffer.append( " " ); appendEscaped( aBuffer, aPair.First ); - aBuffer.appendAscii( " ", 1 ); + aBuffer.append( " " ); appendEscaped( aBuffer, aPair.Second ); } @@ -426,18 +426,18 @@ void SAL_CALL UnxFilePicker::setValue( sal_Int16 nControlId, sal_Int16 nControlA { OUStringBuffer aBuffer( 1024 ); - aBuffer.appendAscii( "setValue " ); + aBuffer.append( "setValue " ); aBuffer.append( static_cast< sal_Int32 >( nControlId ) ); - aBuffer.appendAscii( " ", 1 ); + aBuffer.append( " " ); aBuffer.append( aAction ); if ( aType == "checkbox" ) { bool bControlValue; if ( ( rValue >>= bControlValue ) && bControlValue ) - aBuffer.appendAscii( " true" ); + aBuffer.append( " true" ); else - aBuffer.appendAscii( " false" ); + aBuffer.append( " false" ); } else if ( aType == "listbox" ) { @@ -449,7 +449,7 @@ void SAL_CALL UnxFilePicker::setValue( sal_Int16 nControlId, sal_Int16 nControlA OUString aString; if ( rValue >>= aString ) { - aBuffer.appendAscii( " ", 1 ); + aBuffer.append( " " ); appendEscaped( aBuffer, aString ); } } @@ -462,7 +462,7 @@ void SAL_CALL UnxFilePicker::setValue( sal_Int16 nControlId, sal_Int16 nControlA { for ( sal_Int32 nIdx = 0; nIdx < aSequence.getLength(); ++nIdx ) { - aBuffer.appendAscii( " ", 1 ); + aBuffer.append( " " ); appendEscaped( aBuffer, aSequence[nIdx] ); } @@ -476,7 +476,7 @@ void SAL_CALL UnxFilePicker::setValue( sal_Int16 nControlId, sal_Int16 nControlA sal_Int32 nInt; if ( rValue >>= nInt ) { - aBuffer.appendAscii( " ", 1 ); + aBuffer.append( " " ); aBuffer.append( nInt ); } } @@ -505,9 +505,9 @@ uno::Any SAL_CALL UnxFilePicker::getValue( sal_Int16 nControlId, sal_Int16 nCont { OUStringBuffer aBuffer( 1024 ); - aBuffer.appendAscii( "getValue " ); + aBuffer.append( "getValue " ); aBuffer.append( static_cast< sal_Int32 >( nControlId ) ); - aBuffer.appendAscii( " ", 1 ); + aBuffer.append( " " ); aBuffer.append( aAction ); sendCommand( aBuffer.makeStringAndClear(), @@ -527,7 +527,7 @@ void SAL_CALL UnxFilePicker::enableControl( sal_Int16 nControlId, sal_Bool bEnab OUStringBuffer aBuffer( 1024 ); - aBuffer.appendAscii( "enableControl " ); + aBuffer.append( "enableControl " ); aBuffer.append( static_cast< sal_Int32 >( nControlId ) ); aBuffer.appendAscii( bEnable? " true": " false" ); @@ -542,9 +542,9 @@ void SAL_CALL UnxFilePicker::setLabel( sal_Int16 nControlId, const OUString &rLa OUStringBuffer aBuffer( 1024 ); - aBuffer.appendAscii( "setLabel " ); + aBuffer.append( "setLabel " ); aBuffer.append( static_cast< sal_Int32 >( nControlId ) ); - aBuffer.appendAscii( " ", 1 ); + aBuffer.append( " " ); appendEscaped( aBuffer, rLabel ); sendCommand( aBuffer.makeStringAndClear() ); @@ -902,11 +902,11 @@ void UnxFilePicker::sendAppendControlCommand( sal_Int16 nControlId ) { OUStringBuffer aBuffer( 1024 ); - aBuffer.appendAscii( "appendControl " ); + aBuffer.append( "appendControl " ); aBuffer.append( static_cast< sal_Int32 >( nControlId ) ); - aBuffer.appendAscii( " ", 1 ); + aBuffer.append( " " ); appendEscaped( aBuffer, aType ); - aBuffer.appendAscii( " ", 1 ); + aBuffer.append( " " ); appendEscaped( aBuffer, m_pResMgr? ResId(nTitleId, *m_pResMgr).toString(): OUString() ); sendCommand( aBuffer.makeStringAndClear() ); diff --git a/vcl/unx/x11/x11sys.cxx b/vcl/unx/x11/x11sys.cxx index e3eb453..fbb625a 100644 --- a/vcl/unx/x11/x11sys.cxx +++ b/vcl/unx/x11/x11sys.cxx @@ -96,7 +96,7 @@ OUString X11SalSystem::GetDisplayScreenName( unsigned int nScreen ) nScreen = 0; OUStringBuffer aBuf( 256 ); aBuf.append( OStringToOUString( OString( DisplayString( pSalDisp->GetDisplay() ) ), osl_getThreadTextEncoding() ) ); - aBuf.appendAscii( " [" ); + aBuf.append( " [" ); aBuf.append( static_cast<sal_Int32>(nScreen) ); aBuf.append( ']' ); aScreenName = aBuf.makeStringAndClear(); commit 330680784a9f30926142986a44ac187e86e4fc02 Author: Stephan Bergmann <sberg...@redhat.com> Date: Mon Aug 31 14:37:36 2015 +0200 loplugin:stringconstant: OUStringBuffer: appendAscii -> append Change-Id: Idc3c74505d84a96bb5cc6713a95ef2fadc267ea8 diff --git a/shell/source/backends/localebe/localebackend.cxx b/shell/source/backends/localebe/localebackend.cxx index 6961116..ac97167 100644 --- a/shell/source/backends/localebe/localebackend.cxx +++ b/shell/source/backends/localebe/localebackend.cxx @@ -190,7 +190,7 @@ static OUString ImplGetLocale(int category) if( uscore != NULL ) { aLocaleBuffer.appendAscii(locale, uscore++ - locale); - aLocaleBuffer.appendAscii("-"); + aLocaleBuffer.append("-"); aLocaleBuffer.appendAscii(uscore, cp - uscore); } else commit 78970193945e978bf5f41f41a116c4d6e1016085 Author: Stephan Bergmann <sberg...@redhat.com> Date: Mon Aug 31 14:37:31 2015 +0200 loplugin:stringconstant: OUStringBuffer: appendAscii -> append Change-Id: I358fe0f3dc11939269f58b345489621b0ad25797 diff --git a/connectivity/source/drivers/kab/KDriver.cxx b/connectivity/source/drivers/kab/KDriver.cxx index 43e2542..2a00ed4 100644 --- a/connectivity/source/drivers/kab/KDriver.cxx +++ b/connectivity/source/drivers/kab/KDriver.cxx @@ -112,17 +112,17 @@ void throwKdeTooNewException() OUStringBuffer aMessage; aMessage.append( aResources.getResourceString(STR_KDE_VERSION_TOO_NEW_WORK_AROUND) ); - aMessage.appendAscii( "Sub disableKDEMaxVersionCheck\n" ); - aMessage.appendAscii( " BasicLibraries.LoadLibrary( \"Tools\" )\n" ); + aMessage.append( "Sub disableKDEMaxVersionCheck\n" ); + aMessage.append( " BasicLibraries.LoadLibrary( \"Tools\" )\n" ); - aMessage.appendAscii( " Dim configNode as Object\n" ); - aMessage.appendAscii( " configNode = GetRegistryKeyContent( \"" ); + aMessage.append( " Dim configNode as Object\n" ); + aMessage.append( " configNode = GetRegistryKeyContent( \"" ); aMessage.append( KabDriver::impl_getConfigurationSettingsPath() ); - aMessage.appendAscii( "\", true )\n" ); + aMessage.append( "\", true )\n" ); - aMessage.appendAscii( " configNode.DisableKDEMaximumVersionCheck = TRUE\n" ); - aMessage.appendAscii( " configNode.commitChanges\n" ); - aMessage.appendAscii( "End Sub\n" ); + aMessage.append( " configNode.DisableKDEMaximumVersionCheck = TRUE\n" ); + aMessage.append( " configNode.commitChanges\n" ); + aMessage.append( "End Sub\n" ); aDetails.Message = aMessage.makeStringAndClear(); @@ -454,8 +454,8 @@ void SAL_CALL KabDriver::disposing( const EventObject& ) throw (RuntimeException OUString KabDriver::impl_getConfigurationSettingsPath() { OUStringBuffer aPath; - aPath.appendAscii( "/org.openoffice.Office.DataAccess/DriverSettings/" ); - aPath.appendAscii( "com.sun.star.comp.sdbc." KAB_SERVICE_NAME ".Driver" ); + aPath.append( "/org.openoffice.Office.DataAccess/DriverSettings/" ); + aPath.append( "com.sun.star.comp.sdbc." KAB_SERVICE_NAME ".Driver" ); return aPath.makeStringAndClear(); } _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits