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>
This commit is contained in:
Stephan Bergmann
2020-01-29 13:26:26 +01:00
parent 3a10338f3c
commit ce1d8e20a7
14 changed files with 33 additions and 31 deletions

View File

@@ -67,13 +67,13 @@ void CheckConfigMacros::MacroDefined( const Token& macroToken, const MacroDirect
|| hasPathnamePrefix(filename, BUILDDIR "/config_build/") )) || hasPathnamePrefix(filename, BUILDDIR "/config_build/") ))
{ {
// fprintf(stderr,"DEF: %s %s\n", macroToken.getIdentifierInfo()->getName().data(), filename ); // 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 * ) 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 & ) 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 ) 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(); const char* filename = compiler.getSourceManager().getPresumedLoc( location ).getFilename();
if( filename == NULL if( filename == NULL

View File

@@ -148,7 +148,7 @@ void ConstantParam::addToCallSet(const FunctionDecl* functionDecl, int paramInde
if (isa<CXXMethodDecl>(functionDecl) && dyn_cast<CXXMethodDecl>(functionDecl)->isConst()) { if (isa<CXXMethodDecl>(functionDecl) && dyn_cast<CXXMethodDecl>(functionDecl)->isConst()) {
aInfo.nameAndParams += " const"; aInfo.nameAndParams += " const";
} }
aInfo.paramName = paramName; aInfo.paramName = paramName.str();
aInfo.paramIndex = paramIndex; aInfo.paramIndex = paramIndex;
if (paramIndex < (int)functionDecl->getNumParams()) if (paramIndex < (int)functionDecl->getNumParams())
aInfo.paramType = functionDecl->getParamDecl(paramIndex)->getType().getCanonicalType().getAsString(); aInfo.paramType = functionDecl->getParamDecl(paramIndex)->getType().getCanonicalType().getAsString();
@@ -274,8 +274,8 @@ bool ConstantParam::VisitCallExpr(const CallExpr * callExpr) {
continue; continue;
std::string callValue = getCallValue(valExpr); std::string callValue = getCallValue(valExpr);
std::string paramName = i < functionDecl->getNumParams() std::string paramName = i < functionDecl->getNumParams()
? functionDecl->getParamDecl(i)->getName() ? functionDecl->getParamDecl(i)->getName().str()
: llvm::StringRef("###" + std::to_string(i)); : llvm::StringRef("###" + std::to_string(i)).str();
addToCallSet(functionDecl, i, paramName, callValue); addToCallSet(functionDecl, i, paramName, callValue);
} }
return true; return true;
@@ -298,8 +298,8 @@ bool ConstantParam::VisitCXXConstructExpr( const CXXConstructExpr* constructExpr
continue; continue;
std::string callValue = getCallValue(valExpr); std::string callValue = getCallValue(valExpr);
std::string paramName = i < constructorDecl->getNumParams() std::string paramName = i < constructorDecl->getNumParams()
? constructorDecl->getParamDecl(i)->getName() ? constructorDecl->getParamDecl(i)->getName().str()
: llvm::StringRef("###" + std::to_string(i)); : llvm::StringRef("###" + std::to_string(i)).str();
addToCallSet(constructorDecl, i, paramName, callValue); addToCallSet(constructorDecl, i, paramName, callValue);
} }
return true; return true;

View File

@@ -77,8 +77,8 @@ bool startsWith(const std::string& rStr, const char* pSubStr) {
bool ignoreClass(StringRef s) bool ignoreClass(StringRef s)
{ {
// ignore stuff in the standard library, and UNO stuff we can't touch. // ignore stuff in the standard library, and UNO stuff we can't touch.
if (startsWith(s, "rtl::") || startsWith(s, "sal::") || startsWith(s, "com::sun::") if (startsWith(s.str(), "rtl::") || startsWith(s.str(), "sal::") || startsWith(s.str(), "com::sun::")
|| startsWith(s, "std::") || startsWith(s, "boost::") || startsWith(s.str(), "std::") || startsWith(s.str(), "boost::")
|| s == "OString" || s == "OUString" || s == "bad_alloc") || s == "OString" || s == "OUString" || s == "bad_alloc")
{ {
return true; return true;
@@ -136,7 +136,7 @@ bool FinalClasses::VisitCXXRecordDecl(const CXXRecordDecl* decl)
return true; return true;
SourceLocation spellingLocation = compiler.getSourceManager().getSpellingLoc(compat::getBeginLoc(decl)); 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)) + ":" auto sourceLocation = filename.substr(strlen(SRCDIR)) + ":"
+ std::to_string(compiler.getSourceManager().getSpellingLineNumber(spellingLocation)); + std::to_string(compiler.getSourceManager().getSpellingLineNumber(spellingLocation));
definitionMap.insert( std::pair<std::string,std::string>(s, sourceLocation) ); definitionMap.insert( std::pair<std::string,std::string>(s, sourceLocation) );

View File

@@ -87,8 +87,8 @@ bool startsWith(const std::string& rStr, const char* pSubStr) {
bool ignoreClass(StringRef s) bool ignoreClass(StringRef s)
{ {
// ignore stuff in the standard library, and UNO stuff we can't touch. // ignore stuff in the standard library, and UNO stuff we can't touch.
if (startsWith(s, "rtl::") || startsWith(s, "sal::") || startsWith(s, "com::sun::") if (startsWith(s.str(), "rtl::") || startsWith(s.str(), "sal::") || startsWith(s.str(), "com::sun::")
|| startsWith(s, "std::") || startsWith(s, "boost::") || startsWith(s.str(), "std::") || startsWith(s.str(), "boost::")
|| s == "OString" || s == "OUString" || s == "bad_alloc") || s == "OString" || s == "OUString" || s == "bad_alloc")
{ {
return true; return true;
@@ -149,7 +149,7 @@ bool MergeClasses::VisitCXXRecordDecl(const CXXRecordDecl* decl)
if (decl->isThisDeclarationADefinition()) if (decl->isThisDeclarationADefinition())
{ {
SourceLocation spellingLocation = compiler.getSourceManager().getSpellingLoc(compat::getBeginLoc(decl)); SourceLocation spellingLocation = compiler.getSourceManager().getSpellingLoc(compat::getBeginLoc(decl));
std::string filename = getFilenameOfLocation(spellingLocation); std::string filename = getFilenameOfLocation(spellingLocation).str();
filename = filename.substr(strlen(SRCDIR)); filename = filename.substr(strlen(SRCDIR));
std::string s = decl->getQualifiedNameAsString(); std::string s = decl->getQualifiedNameAsString();
if (ignoreClass(s)) if (ignoreClass(s))

View File

@@ -340,7 +340,7 @@ void PluginHandler::HandleTranslationUnit( ASTContext& context )
bSkip = true; bSkip = true;
} }
if( modifyFile.empty()) if( modifyFile.empty())
modifyFile = name; modifyFile = name.str();
// Check whether the modified file is in the wanted scope // Check whether the modified file is in the wanted scope
if( scope == "mainfile" ) if( scope == "mainfile" )
{ {

View File

@@ -305,7 +305,7 @@ public:
{ {
if (!compiler.getLangOpts().CPlusPlus) if (!compiler.getLangOpts().CPlusPlus)
return false; return false;
std::string fn = handler.getMainFileName(); std::string fn = handler.getMainFileName().str();
loplugin::normalizeDotDotInFilePath(fn); loplugin::normalizeDotDotInFilePath(fn);
// necessary on some other platforms // necessary on some other platforms
if (fn == SRCDIR "/sal/osl/unx/socket.cxx") if (fn == SRCDIR "/sal/osl/unx/socket.cxx")

View File

@@ -125,7 +125,7 @@ bool ReturnConstant::TraverseCXXMethodDecl(CXXMethodDecl* functionDecl)
StringRef name{ Lexer::getImmediateMacroName(compat::getBeginLoc(functionDecl), StringRef name{ Lexer::getImmediateMacroName(compat::getBeginLoc(functionDecl),
compiler.getSourceManager(), compiler.getSourceManager(),
compiler.getLangOpts()) }; compiler.getLangOpts()) };
aImmediateMacro = name; aImmediateMacro = name.str();
if (name.find("IMPL_LINK") != StringRef::npos if (name.find("IMPL_LINK") != StringRef::npos
|| name.find("IMPL_STATIC_LINK") != StringRef::npos || name.find("IMPL_STATIC_LINK") != StringRef::npos
|| name.find("DECL_LINK") != StringRef::npos || name.find("DECL_LINK") != StringRef::npos

View File

@@ -146,7 +146,7 @@ void SalLogAreas::checkArea( StringRef area, SourceLocation location )
{ {
if( logAreas.empty()) if( logAreas.empty())
readLogAreas(); 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)", report( DiagnosticsEngine::Warning, "unknown log area '%0' (check or extend include/sal/log-areas.dox)",
location ) << area; location ) << area;

View File

@@ -96,7 +96,7 @@ static bool inheritsPluginClassCheck( const Decl* decl )
static TraverseFunctionInfo findOrCreateTraverseFunctionInfo( StringRef name ) static TraverseFunctionInfo findOrCreateTraverseFunctionInfo( StringRef name )
{ {
TraverseFunctionInfo info; TraverseFunctionInfo info;
info.name = name; info.name = name.str();
auto foundInfo = traverseFunctions.find( info ); auto foundInfo = traverseFunctions.find( info );
if( foundInfo != traverseFunctions.end()) if( foundInfo != traverseFunctions.end())
{ {
@@ -266,7 +266,9 @@ int main(int argc, char** argv)
} }
SmallVector< StringRef, 20 > clangflags; SmallVector< StringRef, 20 > clangflags;
SplitString( CLANGFLAGS, 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.insert(
args.end(), args.end(),
{ // These must match LO_CLANG_ANALYZER_PCH_CXXFLAGS in Makefile-clang.mk . { // These must match LO_CLANG_ANALYZER_PCH_CXXFLAGS in Makefile-clang.mk .

View File

@@ -146,7 +146,7 @@ void SingleValFields::niceName(const DeclaratorDecl* fieldOrVarDecl, MyFieldInfo
else if (auto parentFunctionDecl = dyn_cast<FunctionDecl>(varDecl->getDeclContext())) else if (auto parentFunctionDecl = dyn_cast<FunctionDecl>(varDecl->getDeclContext()))
aInfo.parentClass = parentFunctionDecl->getQualifiedNameAsString(); aInfo.parentClass = parentFunctionDecl->getQualifiedNameAsString();
else if (isa<TranslationUnitDecl>(varDecl->getDeclContext())) else if (isa<TranslationUnitDecl>(varDecl->getDeclContext()))
aInfo.parentClass = handler.getMainFileName(); aInfo.parentClass = handler.getMainFileName().str();
else if (auto parentNamespaceDecl = dyn_cast<NamespaceDecl>(varDecl->getDeclContext())) else if (auto parentNamespaceDecl = dyn_cast<NamespaceDecl>(varDecl->getDeclContext()))
aInfo.parentClass = parentNamespaceDecl->getQualifiedNameAsString(); aInfo.parentClass = parentNamespaceDecl->getQualifiedNameAsString();
else if (isa<LinkageSpecDecl>(varDecl->getDeclContext())) 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 (auto stringLiteral = dyn_cast<clang::StringLiteral>(arg))
{ {
if (stringLiteral->getCharByteWidth() == 1) if (stringLiteral->getCharByteWidth() == 1)
return stringLiteral->getString(); return stringLiteral->getString().str();
return "?"; return "?";
} }
// ParenListExpr containing a CXXNullPtrLiteralExpr and has a NULL type pointer // 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)); auto stringLiteral = dyn_cast<clang::StringLiteral>(constructExpr->getArg(0));
if (stringLiteral->getCharByteWidth() == 1) if (stringLiteral->getCharByteWidth() == 1)
return stringLiteral->getString(); return stringLiteral->getString().str();
return "?"; return "?";
} }
} }

View File

@@ -46,7 +46,7 @@ private:
void StaticConstField::run() void StaticConstField::run()
{ {
std::string fn = handler.getMainFileName(); std::string fn = handler.getMainFileName().str();
loplugin::normalizeDotDotInFilePath(fn); 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 // 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 if (constructExpr->getNumArgs() >= 1
&& isa<clang::StringLiteral>(constructExpr->getArg(0))) && 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; found = true;
} }
} }

View File

@@ -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 if( isa< ParmVarDecl >( decl )) // parameters should be fine, temporaries should exist during the call
return true; return true;
std::string fileName = getFilenameOfLocation( std::string fileName = getFilenameOfLocation(
compiler.getSourceManager().getSpellingLoc(compat::getBeginLoc(decl))); compiler.getSourceManager().getSpellingLoc(compat::getBeginLoc(decl))).str();
loplugin::normalizeDotDotInFilePath(fileName); loplugin::normalizeDotDotInFilePath(fileName);
if (loplugin::isSamePathname(fileName, SRCDIR "/include/rtl/string.hxx") if (loplugin::isSamePathname(fileName, SRCDIR "/include/rtl/string.hxx")
|| loplugin::isSamePathname(fileName, SRCDIR "/include/rtl/ustring.hxx") || loplugin::isSamePathname(fileName, SRCDIR "/include/rtl/ustring.hxx")

View File

@@ -32,7 +32,7 @@ public:
virtual void run() override virtual void run() override
{ {
fn = handler.getMainFileName(); fn = handler.getMainFileName().str();
loplugin::normalizeDotDotInFilePath(fn); loplugin::normalizeDotDotInFilePath(fn);
// can't change these because we pass them down to the SfxItemPool stuff // can't change these because we pass them down to the SfxItemPool stuff
if (fn == SRCDIR "/sc/source/core/data/docpool.cxx") if (fn == SRCDIR "/sc/source/core/data/docpool.cxx")
@@ -500,16 +500,16 @@ void UseUniquePtr::CheckDeleteLocalVar(const FunctionDecl* functionDecl, const C
if (parentName == "ScBroadcastAreaSlot") if (parentName == "ScBroadcastAreaSlot")
return; return;
// complicated // complicated
if (any_equal(parentName, "SwFormatField", "FontPropertyBox", "SdFontPropertyBox", if (any_equal(parentName.str(), "SwFormatField", "FontPropertyBox", "SdFontPropertyBox",
"SwHTMLParser", "PDFWriterImpl", "SbiParser", "DictionaryList", "SwGlossaryHdl", "SwGlossaryGroupDlg")) "SwHTMLParser", "PDFWriterImpl", "SbiParser", "DictionaryList", "SwGlossaryHdl", "SwGlossaryGroupDlg"))
return; return;
// ok // ok
if (any_equal(parentName, "SbTreeListBox")) if (any_equal(parentName.str(), "SbTreeListBox"))
return; return;
if (functionDecl->getIdentifier()) if (functionDecl->getIdentifier())
{ {
std::string name = functionDecl->getName(); std::string name = functionDecl->getName().str();
if (!parentName.empty()) if (!parentName.empty())
name = std::string(parentName) + "::" + name; name = std::string(parentName) + "::" + name;

View File

@@ -522,7 +522,7 @@ MyVarInfo WriteOnlyVars::niceName(const VarDecl* varDecl)
= std::string(filename.substr(strlen(SRCDIR) + 1)) + ":" = std::string(filename.substr(strlen(SRCDIR) + 1)) + ":"
+ std::to_string(compiler.getSourceManager().getSpellingLineNumber(expansionLoc)); + std::to_string(compiler.getSourceManager().getSpellingLineNumber(expansionLoc));
loplugin::normalizeDotDotInFilePath(aInfo.sourceLocation); loplugin::normalizeDotDotInFilePath(aInfo.sourceLocation);
aInfo.parent = filename; aInfo.parent = filename.str();
return aInfo; return aInfo;
} }