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();
for (sys::fs::directory_iterator i(folder1, ec, false), e; i != e && !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") ||
sys::fs::status(path, status, false))
continue;

View File

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

View File

@ -134,7 +134,7 @@ int main(int argc, char **argv) {
if (opt_index.size()) {
SmallString<256> root(opt_index);
sys::fs::make_absolute(root);
pipeline::standalone(root.str());
pipeline::standalone(std::string(root.data(), root.size()));
} else {
// The thread that reads from stdin and dispatchs commands to the main
// 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
std::string stem = sys::path::stem(path);
StringRef stem = sys::path::stem(path);
int changed = -1, size = std::min(prev->args.size(), args.size());
for (int i = 0; i < size; i++)
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
#pragma once
#include <llvm/ADT/StringRef.h>
#include <string>
#include <string_view>
#include <vector>
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.
void freeUnusedMemory();

View File

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

View File

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

View File

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

View File

@ -623,7 +623,8 @@ void *diagnosticMain(void *manager_) {
for (const Note &n : d.notes) {
SmallString<256> str(n.file);
llvm::sys::path::remove_dots(str, true);
Location loc{DocumentUri::fromPath(str.str()),
Location loc{
DocumentUri::fromPath(std::string(str.data(), str.size())),
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});

View File

@ -217,7 +217,7 @@ void reflect(JsonWriter &vis, IndexInclude &v) {
reflectMemberStart(vis);
REFLECT_MEMBER(line);
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] != '&')
basename = "&" + basename;
REFLECT_MEMBER2("resolved_path", basename);