Adapt llvmorg-11-init-1314-g777180a32b6: StringRef's conversion to std::string is now explicit

For compatibility with LLVM 7, the call sites have to be a bit verbose.
This commit is contained in:
Fangrui Song 2020-01-29 00:29:06 -08:00
parent 61a1071634
commit 6717986541
10 changed files with 20 additions and 23 deletions

View File

@ -31,7 +31,8 @@ void getFilesInFolder(std::string folder, bool recursive, bool dir_prefix,
curr.pop_back(); curr.pop_back();
for (sys::fs::directory_iterator i(folder1, ec, false), e; i != e && !ec; for (sys::fs::directory_iterator i(folder1, ec, false), e; i != e && !ec;
i.increment(ec)) { i.increment(ec)) {
std::string path = i->path(), filename = sys::path::filename(path); std::string path = i->path();
std::string filename(sys::path::filename(path));
if ((filename[0] == '.' && filename != ".ccls") || if ((filename[0] == '.' && filename != ".ccls") ||
sys::fs::status(path, status, false)) sys::fs::status(path, status, false))
continue; continue;

View File

@ -504,7 +504,7 @@ public:
llvm::raw_svector_ostream os(str); llvm::raw_svector_ostream os(str);
d->print(os, getDefaultPolicy()); d->print(os, getDefaultPolicy());
std::string name = os.str(); std::string name(str.data(), str.size());
simplifyAnonymous(name); simplifyAnonymous(name);
// Remove \n in DeclPrinter.cpp "{\n" + if(!TerseOutput)something + "}" // Remove \n in DeclPrinter.cpp "{\n" + if(!TerseOutput)something + "}"
for (std::string::size_type i = 0;;) { for (std::string::size_type i = 0;;) {

View File

@ -134,7 +134,7 @@ int main(int argc, char **argv) {
if (opt_index.size()) { if (opt_index.size()) {
SmallString<256> root(opt_index); SmallString<256> root(opt_index);
sys::fs::make_absolute(root); sys::fs::make_absolute(root);
pipeline::standalone(root.str()); pipeline::standalone(std::string(root.data(), root.size()));
} else { } else {
// The thread that reads from stdin and dispatchs commands to the main // The thread that reads from stdin and dispatchs commands to the main
// thread. // thread.

View File

@ -113,7 +113,7 @@ bool cacheInvalid(VFS *vfs, IndexFile *prev, const std::string &path,
} }
// For inferred files, allow -o a a.cc -> -o b b.cc // For inferred files, allow -o a a.cc -> -o b b.cc
std::string stem = sys::path::stem(path); StringRef stem = sys::path::stem(path);
int changed = -1, size = std::min(prev->args.size(), args.size()); int changed = -1, size = std::min(prev->args.size(), args.size());
for (int i = 0; i < size; i++) for (int i = 0; i < size; i++)
if (strcmp(prev->args[i], args[i]) && sys::path::stem(args[i]) != stem) { if (strcmp(prev->args[i], args[i]) && sys::path::stem(args[i]) != stem) {

View File

@ -1,14 +1,14 @@
// Copyright 2017-2018 ccls Authors // Copyright 2017-2020 ccls Authors
// SPDX-License-Identifier: Apache-2.0 // SPDX-License-Identifier: Apache-2.0
#pragma once #pragma once
#include <llvm/ADT/StringRef.h>
#include <string> #include <string>
#include <string_view>
#include <vector>
namespace ccls { namespace ccls {
std::string normalizePath(const std::string &path); std::string normalizePath(llvm::StringRef path);
// Free any unused memory and return it to the system. // Free any unused memory and return it to the system.
void freeUnusedMemory(); void freeUnusedMemory();

View File

@ -40,7 +40,7 @@ namespace pipeline {
void threadEnter(); void threadEnter();
} }
std::string normalizePath(const std::string &path) { std::string normalizePath(llvm::StringRef path) {
llvm::SmallString<256> p(path); llvm::SmallString<256> p(path);
llvm::sys::path::remove_dots(p, true); llvm::sys::path::remove_dots(p, true);
return {p.data(), p.size()}; return {p.data(), p.size()};

View File

@ -19,17 +19,12 @@
#include <thread> #include <thread>
namespace ccls { namespace ccls {
std::string normalizePath(const std::string &path) { std::string normalizePath(llvm::StringRef path) {
DWORD retval = 0;
TCHAR buffer[MAX_PATH] = TEXT(""); TCHAR buffer[MAX_PATH] = TEXT("");
TCHAR **lpp_part = {NULL}; TCHAR **lpp_part = {NULL};
std::string result; std::string result(path);
retval = GetFullPathName(path.c_str(), MAX_PATH, buffer, lpp_part); if (GetFullPathName(result.c_str(), MAX_PATH, buffer, lpp_part) != 0)
// fail, return original
if (retval == 0)
result = path;
else
result = buffer; result = buffer;
std::replace(result.begin(), result.end(), '\\', '/'); std::replace(result.begin(), result.end(), '\\', '/');

View File

@ -222,7 +222,7 @@ readCompilerArgumentsFromFile(const std::string &path) {
return {}; return {};
std::vector<const char *> args; std::vector<const char *> args;
for (line_iterator i(*mbOrErr.get(), true, '#'), e; i != e; ++i) { for (line_iterator i(*mbOrErr.get(), true, '#'), e; i != e; ++i) {
std::string line = *i; std::string line(*i);
doPathMapping(line); doPathMapping(line);
args.push_back(intern(line)); args.push_back(intern(line));
} }
@ -632,7 +632,7 @@ void Project::index(WorkingFiles *wfiles, RequestId id) {
void Project::indexRelated(const std::string &path) { void Project::indexRelated(const std::string &path) {
auto &gi = g_config->index; auto &gi = g_config->index;
GroupMatch match(gi.whitelist, gi.blacklist); GroupMatch match(gi.whitelist, gi.blacklist);
std::string stem = sys::path::stem(path); StringRef stem = sys::path::stem(path);
std::vector<const char *> args, extra_args; std::vector<const char *> args, extra_args;
for (const std::string &arg : g_config->clang.extraArgs) for (const std::string &arg : g_config->clang.extraArgs)
extra_args.push_back(intern(arg)); extra_args.push_back(intern(arg));

View File

@ -623,9 +623,10 @@ void *diagnosticMain(void *manager_) {
for (const Note &n : d.notes) { for (const Note &n : d.notes) {
SmallString<256> str(n.file); SmallString<256> str(n.file);
llvm::sys::path::remove_dots(str, true); llvm::sys::path::remove_dots(str, true);
Location loc{DocumentUri::fromPath(str.str()), Location loc{
lsRange{{n.range.start.line, n.range.start.column}, DocumentUri::fromPath(std::string(str.data(), str.size())),
{n.range.end.line, n.range.end.column}}}; lsRange{{n.range.start.line, n.range.start.column},
{n.range.end.line, n.range.end.column}}};
ls_diag.relatedInformation.push_back({loc, n.message}); ls_diag.relatedInformation.push_back({loc, n.message});
} }
} else { } else {

View File

@ -217,7 +217,7 @@ void reflect(JsonWriter &vis, IndexInclude &v) {
reflectMemberStart(vis); reflectMemberStart(vis);
REFLECT_MEMBER(line); REFLECT_MEMBER(line);
if (gTestOutputMode) { if (gTestOutputMode) {
std::string basename = llvm::sys::path::filename(v.resolved_path); std::string basename(llvm::sys::path::filename(v.resolved_path));
if (v.resolved_path[0] != '&') if (v.resolved_path[0] != '&')
basename = "&" + basename; basename = "&" + basename;
REFLECT_MEMBER2("resolved_path", basename); REFLECT_MEMBER2("resolved_path", basename);