diff options
author | Stephan Bergmann <sbergman@redhat.com> | 2020-01-29 13:26:26 +0100 |
---|---|---|
committer | Stephan Bergmann <sbergman@redhat.com> | 2020-01-29 14:14:04 +0100 |
commit | ce1d8e20a708ed031f2336770a41fbe501fe8225 (patch) | |
tree | 2b9f2ea562a879da8722e5bddb2bac4488624b35 /compilerplugins | |
parent | 3a10338f3cdfe0cb89c3f10425570f260313a689 (diff) |
Adapt to "[ADT] Make StringRef's std::string conversion operator explicit"
...<https://github.com/llvm/llvm-project/commit/
777180a32b61070a10dd330b4f038bf24e916af1>. This is just a quick fix to get
copmilerplugins buiding again with latest LLVM/Clang trunk. Ideally, we should
get rid of as many of those (potentially expensive) conversions from
llvm::StringRef to std::string as possible.
Change-Id: I18e185e0022a06fd8e3b983a3c4f80e1f3b96746
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/87682
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
Diffstat (limited to 'compilerplugins')
-rw-r--r-- | compilerplugins/clang/checkconfigmacros.cxx | 6 | ||||
-rw-r--r-- | compilerplugins/clang/constantparam.cxx | 10 | ||||
-rw-r--r-- | compilerplugins/clang/finalclasses.cxx | 6 | ||||
-rw-r--r-- | compilerplugins/clang/mergeclasses.cxx | 6 | ||||
-rw-r--r-- | compilerplugins/clang/pluginhandler.cxx | 2 | ||||
-rw-r--r-- | compilerplugins/clang/redundantfcast.cxx | 2 | ||||
-rw-r--r-- | compilerplugins/clang/returnconstant.cxx | 2 | ||||
-rw-r--r-- | compilerplugins/clang/sallogareas.cxx | 2 | ||||
-rw-r--r-- | compilerplugins/clang/sharedvisitor/analyzer.cxx | 6 | ||||
-rw-r--r-- | compilerplugins/clang/singlevalfields.cxx | 6 | ||||
-rw-r--r-- | compilerplugins/clang/staticconstfield.cxx | 4 | ||||
-rw-r--r-- | compilerplugins/clang/stringconcatauto.cxx | 2 | ||||
-rw-r--r-- | compilerplugins/clang/useuniqueptr.cxx | 8 | ||||
-rw-r--r-- | compilerplugins/clang/writeonlyvars.cxx | 2 |
14 files changed, 33 insertions, 31 deletions
diff --git a/compilerplugins/clang/checkconfigmacros.cxx b/compilerplugins/clang/checkconfigmacros.cxx index e48cca3fd291..23f6947a3646 100644 --- a/compilerplugins/clang/checkconfigmacros.cxx +++ b/compilerplugins/clang/checkconfigmacros.cxx @@ -67,13 +67,13 @@ void CheckConfigMacros::MacroDefined( const Token& macroToken, const MacroDirect || hasPathnamePrefix(filename, BUILDDIR "/config_build/") )) { // fprintf(stderr,"DEF: %s %s\n", macroToken.getIdentifierInfo()->getName().data(), filename ); - configMacros.insert( macroToken.getIdentifierInfo()->getName()); + configMacros.insert( macroToken.getIdentifierInfo()->getName().str()); } } void CheckConfigMacros::MacroUndefined( const Token& macroToken, MacroDefinition const &, MacroDirective const * ) { - configMacros.erase( macroToken.getIdentifierInfo()->getName()); + configMacros.erase( macroToken.getIdentifierInfo()->getName().str()); } void CheckConfigMacros::Ifdef( SourceLocation location, const Token& macroToken, MacroDefinition const & ) @@ -93,7 +93,7 @@ void CheckConfigMacros::Defined( const Token& macroToken, MacroDefinition const void CheckConfigMacros::checkMacro( const Token& macroToken, SourceLocation location ) { - if( configMacros.find( macroToken.getIdentifierInfo()->getName()) != configMacros.end()) + if( configMacros.find( macroToken.getIdentifierInfo()->getName().str()) != configMacros.end()) { const char* filename = compiler.getSourceManager().getPresumedLoc( location ).getFilename(); if( filename == NULL diff --git a/compilerplugins/clang/constantparam.cxx b/compilerplugins/clang/constantparam.cxx index 175c9d4a42fd..dd9bddd086c5 100644 --- a/compilerplugins/clang/constantparam.cxx +++ b/compilerplugins/clang/constantparam.cxx @@ -148,7 +148,7 @@ void ConstantParam::addToCallSet(const FunctionDecl* functionDecl, int paramInde if (isa<CXXMethodDecl>(functionDecl) && dyn_cast<CXXMethodDecl>(functionDecl)->isConst()) { aInfo.nameAndParams += " const"; } - aInfo.paramName = paramName; + aInfo.paramName = paramName.str(); aInfo.paramIndex = paramIndex; if (paramIndex < (int)functionDecl->getNumParams()) aInfo.paramType = functionDecl->getParamDecl(paramIndex)->getType().getCanonicalType().getAsString(); @@ -274,8 +274,8 @@ bool ConstantParam::VisitCallExpr(const CallExpr * callExpr) { continue; std::string callValue = getCallValue(valExpr); std::string paramName = i < functionDecl->getNumParams() - ? functionDecl->getParamDecl(i)->getName() - : llvm::StringRef("###" + std::to_string(i)); + ? functionDecl->getParamDecl(i)->getName().str() + : llvm::StringRef("###" + std::to_string(i)).str(); addToCallSet(functionDecl, i, paramName, callValue); } return true; @@ -298,8 +298,8 @@ bool ConstantParam::VisitCXXConstructExpr( const CXXConstructExpr* constructExpr continue; std::string callValue = getCallValue(valExpr); std::string paramName = i < constructorDecl->getNumParams() - ? constructorDecl->getParamDecl(i)->getName() - : llvm::StringRef("###" + std::to_string(i)); + ? constructorDecl->getParamDecl(i)->getName().str() + : llvm::StringRef("###" + std::to_string(i)).str(); addToCallSet(constructorDecl, i, paramName, callValue); } return true; diff --git a/compilerplugins/clang/finalclasses.cxx b/compilerplugins/clang/finalclasses.cxx index d906c586d1a0..1c25b50afffe 100644 --- a/compilerplugins/clang/finalclasses.cxx +++ b/compilerplugins/clang/finalclasses.cxx @@ -77,8 +77,8 @@ bool startsWith(const std::string& rStr, const char* pSubStr) { bool ignoreClass(StringRef s) { // ignore stuff in the standard library, and UNO stuff we can't touch. - if (startsWith(s, "rtl::") || startsWith(s, "sal::") || startsWith(s, "com::sun::") - || startsWith(s, "std::") || startsWith(s, "boost::") + if (startsWith(s.str(), "rtl::") || startsWith(s.str(), "sal::") || startsWith(s.str(), "com::sun::") + || startsWith(s.str(), "std::") || startsWith(s.str(), "boost::") || s == "OString" || s == "OUString" || s == "bad_alloc") { return true; @@ -136,7 +136,7 @@ bool FinalClasses::VisitCXXRecordDecl(const CXXRecordDecl* decl) return true; SourceLocation spellingLocation = compiler.getSourceManager().getSpellingLoc(compat::getBeginLoc(decl)); - std::string filename = getFilenameOfLocation(spellingLocation); + std::string filename = getFilenameOfLocation(spellingLocation).str(); auto sourceLocation = filename.substr(strlen(SRCDIR)) + ":" + std::to_string(compiler.getSourceManager().getSpellingLineNumber(spellingLocation)); definitionMap.insert( std::pair<std::string,std::string>(s, sourceLocation) ); diff --git a/compilerplugins/clang/mergeclasses.cxx b/compilerplugins/clang/mergeclasses.cxx index c7f9a6094a14..495cdf7010f1 100644 --- a/compilerplugins/clang/mergeclasses.cxx +++ b/compilerplugins/clang/mergeclasses.cxx @@ -87,8 +87,8 @@ bool startsWith(const std::string& rStr, const char* pSubStr) { bool ignoreClass(StringRef s) { // ignore stuff in the standard library, and UNO stuff we can't touch. - if (startsWith(s, "rtl::") || startsWith(s, "sal::") || startsWith(s, "com::sun::") - || startsWith(s, "std::") || startsWith(s, "boost::") + if (startsWith(s.str(), "rtl::") || startsWith(s.str(), "sal::") || startsWith(s.str(), "com::sun::") + || startsWith(s.str(), "std::") || startsWith(s.str(), "boost::") || s == "OString" || s == "OUString" || s == "bad_alloc") { return true; @@ -149,7 +149,7 @@ bool MergeClasses::VisitCXXRecordDecl(const CXXRecordDecl* decl) if (decl->isThisDeclarationADefinition()) { SourceLocation spellingLocation = compiler.getSourceManager().getSpellingLoc(compat::getBeginLoc(decl)); - std::string filename = getFilenameOfLocation(spellingLocation); + std::string filename = getFilenameOfLocation(spellingLocation).str(); filename = filename.substr(strlen(SRCDIR)); std::string s = decl->getQualifiedNameAsString(); if (ignoreClass(s)) diff --git a/compilerplugins/clang/pluginhandler.cxx b/compilerplugins/clang/pluginhandler.cxx index 6d00cf22a8cf..02150c2b10c5 100644 --- a/compilerplugins/clang/pluginhandler.cxx +++ b/compilerplugins/clang/pluginhandler.cxx @@ -340,7 +340,7 @@ void PluginHandler::HandleTranslationUnit( ASTContext& context ) bSkip = true; } if( modifyFile.empty()) - modifyFile = name; + modifyFile = name.str(); // Check whether the modified file is in the wanted scope if( scope == "mainfile" ) { diff --git a/compilerplugins/clang/redundantfcast.cxx b/compilerplugins/clang/redundantfcast.cxx index 0dca2a1c60cb..d600aa5b79df 100644 --- a/compilerplugins/clang/redundantfcast.cxx +++ b/compilerplugins/clang/redundantfcast.cxx @@ -305,7 +305,7 @@ public: { if (!compiler.getLangOpts().CPlusPlus) return false; - std::string fn = handler.getMainFileName(); + std::string fn = handler.getMainFileName().str(); loplugin::normalizeDotDotInFilePath(fn); // necessary on some other platforms if (fn == SRCDIR "/sal/osl/unx/socket.cxx") diff --git a/compilerplugins/clang/returnconstant.cxx b/compilerplugins/clang/returnconstant.cxx index 70119b07bed7..e33a35664e62 100644 --- a/compilerplugins/clang/returnconstant.cxx +++ b/compilerplugins/clang/returnconstant.cxx @@ -125,7 +125,7 @@ bool ReturnConstant::TraverseCXXMethodDecl(CXXMethodDecl* functionDecl) StringRef name{ Lexer::getImmediateMacroName(compat::getBeginLoc(functionDecl), compiler.getSourceManager(), compiler.getLangOpts()) }; - aImmediateMacro = name; + aImmediateMacro = name.str(); if (name.find("IMPL_LINK") != StringRef::npos || name.find("IMPL_STATIC_LINK") != StringRef::npos || name.find("DECL_LINK") != StringRef::npos diff --git a/compilerplugins/clang/sallogareas.cxx b/compilerplugins/clang/sallogareas.cxx index 02df2793824e..e0d6d160101f 100644 --- a/compilerplugins/clang/sallogareas.cxx +++ b/compilerplugins/clang/sallogareas.cxx @@ -146,7 +146,7 @@ void SalLogAreas::checkArea( StringRef area, SourceLocation location ) { if( logAreas.empty()) readLogAreas(); - if( !logAreas.count( area )) + if( !logAreas.count( area.str() )) { report( DiagnosticsEngine::Warning, "unknown log area '%0' (check or extend include/sal/log-areas.dox)", location ) << area; diff --git a/compilerplugins/clang/sharedvisitor/analyzer.cxx b/compilerplugins/clang/sharedvisitor/analyzer.cxx index 007790facd4d..7c69e4a9381c 100644 --- a/compilerplugins/clang/sharedvisitor/analyzer.cxx +++ b/compilerplugins/clang/sharedvisitor/analyzer.cxx @@ -96,7 +96,7 @@ static bool inheritsPluginClassCheck( const Decl* decl ) static TraverseFunctionInfo findOrCreateTraverseFunctionInfo( StringRef name ) { TraverseFunctionInfo info; - info.name = name; + info.name = name.str(); auto foundInfo = traverseFunctions.find( info ); if( foundInfo != traverseFunctions.end()) { @@ -266,7 +266,9 @@ int main(int argc, char** argv) } SmallVector< StringRef, 20 > clangflags; SplitString( CLANGFLAGS, clangflags ); - args.insert( args.end(), clangflags.begin(), clangflags.end()); + for (auto const & i: clangflags) { + args.push_back(i.str()); + } args.insert( args.end(), { // These must match LO_CLANG_ANALYZER_PCH_CXXFLAGS in Makefile-clang.mk . diff --git a/compilerplugins/clang/singlevalfields.cxx b/compilerplugins/clang/singlevalfields.cxx index 2efb562473ae..ce60eeea7df0 100644 --- a/compilerplugins/clang/singlevalfields.cxx +++ b/compilerplugins/clang/singlevalfields.cxx @@ -146,7 +146,7 @@ void SingleValFields::niceName(const DeclaratorDecl* fieldOrVarDecl, MyFieldInfo else if (auto parentFunctionDecl = dyn_cast<FunctionDecl>(varDecl->getDeclContext())) aInfo.parentClass = parentFunctionDecl->getQualifiedNameAsString(); else if (isa<TranslationUnitDecl>(varDecl->getDeclContext())) - aInfo.parentClass = handler.getMainFileName(); + aInfo.parentClass = handler.getMainFileName().str(); else if (auto parentNamespaceDecl = dyn_cast<NamespaceDecl>(varDecl->getDeclContext())) aInfo.parentClass = parentNamespaceDecl->getQualifiedNameAsString(); else if (isa<LinkageSpecDecl>(varDecl->getDeclContext())) @@ -529,7 +529,7 @@ std::string SingleValFields::getExprValue(const Expr* arg) if (auto stringLiteral = dyn_cast<clang::StringLiteral>(arg)) { if (stringLiteral->getCharByteWidth() == 1) - return stringLiteral->getString(); + return stringLiteral->getString().str(); return "?"; } // ParenListExpr containing a CXXNullPtrLiteralExpr and has a NULL type pointer @@ -546,7 +546,7 @@ std::string SingleValFields::getExprValue(const Expr* arg) { auto stringLiteral = dyn_cast<clang::StringLiteral>(constructExpr->getArg(0)); if (stringLiteral->getCharByteWidth() == 1) - return stringLiteral->getString(); + return stringLiteral->getString().str(); return "?"; } } diff --git a/compilerplugins/clang/staticconstfield.cxx b/compilerplugins/clang/staticconstfield.cxx index 91a798daa5bd..0802c323f810 100644 --- a/compilerplugins/clang/staticconstfield.cxx +++ b/compilerplugins/clang/staticconstfield.cxx @@ -46,7 +46,7 @@ private: void StaticConstField::run() { - std::string fn = handler.getMainFileName(); + std::string fn = handler.getMainFileName().str(); loplugin::normalizeDotDotInFilePath(fn); // unusual case where a user constructor sets a field to one value, and a copy constructor sets it to a different value @@ -107,7 +107,7 @@ bool StaticConstField::TraverseConstructorInitializer(CXXCtorInitializer* init) if (constructExpr->getNumArgs() >= 1 && isa<clang::StringLiteral>(constructExpr->getArg(0))) { - value = dyn_cast<clang::StringLiteral>(constructExpr->getArg(0))->getString(); + value = dyn_cast<clang::StringLiteral>(constructExpr->getArg(0))->getString().str(); found = true; } } diff --git a/compilerplugins/clang/stringconcatauto.cxx b/compilerplugins/clang/stringconcatauto.cxx index 9565225bf45e..c7460cfcc8cd 100644 --- a/compilerplugins/clang/stringconcatauto.cxx +++ b/compilerplugins/clang/stringconcatauto.cxx @@ -71,7 +71,7 @@ bool StringConcatAuto::checkDecl( const DeclaratorDecl* decl, QualType type, con if( isa< ParmVarDecl >( decl )) // parameters should be fine, temporaries should exist during the call return true; std::string fileName = getFilenameOfLocation( - compiler.getSourceManager().getSpellingLoc(compat::getBeginLoc(decl))); + compiler.getSourceManager().getSpellingLoc(compat::getBeginLoc(decl))).str(); loplugin::normalizeDotDotInFilePath(fileName); if (loplugin::isSamePathname(fileName, SRCDIR "/include/rtl/string.hxx") || loplugin::isSamePathname(fileName, SRCDIR "/include/rtl/ustring.hxx") diff --git a/compilerplugins/clang/useuniqueptr.cxx b/compilerplugins/clang/useuniqueptr.cxx index ad8f43132eaa..d0156cac44bb 100644 --- a/compilerplugins/clang/useuniqueptr.cxx +++ b/compilerplugins/clang/useuniqueptr.cxx @@ -32,7 +32,7 @@ public: virtual void run() override { - fn = handler.getMainFileName(); + fn = handler.getMainFileName().str(); loplugin::normalizeDotDotInFilePath(fn); // can't change these because we pass them down to the SfxItemPool stuff if (fn == SRCDIR "/sc/source/core/data/docpool.cxx") @@ -500,16 +500,16 @@ void UseUniquePtr::CheckDeleteLocalVar(const FunctionDecl* functionDecl, const C if (parentName == "ScBroadcastAreaSlot") return; // complicated - if (any_equal(parentName, "SwFormatField", "FontPropertyBox", "SdFontPropertyBox", + if (any_equal(parentName.str(), "SwFormatField", "FontPropertyBox", "SdFontPropertyBox", "SwHTMLParser", "PDFWriterImpl", "SbiParser", "DictionaryList", "SwGlossaryHdl", "SwGlossaryGroupDlg")) return; // ok - if (any_equal(parentName, "SbTreeListBox")) + if (any_equal(parentName.str(), "SbTreeListBox")) return; if (functionDecl->getIdentifier()) { - std::string name = functionDecl->getName(); + std::string name = functionDecl->getName().str(); if (!parentName.empty()) name = std::string(parentName) + "::" + name; diff --git a/compilerplugins/clang/writeonlyvars.cxx b/compilerplugins/clang/writeonlyvars.cxx index eb74f494b59e..6161b428557a 100644 --- a/compilerplugins/clang/writeonlyvars.cxx +++ b/compilerplugins/clang/writeonlyvars.cxx @@ -522,7 +522,7 @@ MyVarInfo WriteOnlyVars::niceName(const VarDecl* varDecl) = std::string(filename.substr(strlen(SRCDIR) + 1)) + ":" + std::to_string(compiler.getSourceManager().getSpellingLineNumber(expansionLoc)); loplugin::normalizeDotDotInFilePath(aInfo.sourceLocation); - aInfo.parent = filename; + aInfo.parent = filename.str(); return aInfo; } |