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/") ))
{
// 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

View file

@ -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;

View file

@ -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) );

View file

@ -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))

View file

@ -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" )
{

View file

@ -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")

View file

@ -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

View file

@ -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;

View file

@ -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 .

View file

@ -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 "?";
}
}

View file

@ -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;
}
}

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
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")

View file

@ -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;

View file

@ -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;
}