Skip to content

Commit b4af654

Browse files
committed
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.
1 parent 1834f81 commit b4af654

File tree

10 files changed

+20
-23
lines changed

10 files changed

+20
-23
lines changed

src/filesystem.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ void getFilesInFolder(std::string folder, bool recursive, bool dir_prefix,
3131
curr.pop_back();
3232
for (sys::fs::directory_iterator i(folder1, ec, false), e; i != e && !ec;
3333
i.increment(ec)) {
34-
std::string path = i->path(), filename = sys::path::filename(path);
34+
std::string path = i->path();
35+
std::string filename(sys::path::filename(path));
3536
if ((filename[0] == '.' && filename != ".ccls") ||
3637
sys::fs::status(path, status, false))
3738
continue;

src/indexer.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,7 @@ class IndexDataConsumer : public index::IndexDataConsumer {
508508
llvm::raw_svector_ostream os(str);
509509
d->print(os, getDefaultPolicy());
510510

511-
std::string name = os.str();
511+
std::string name(str.data(), str.size());
512512
simplifyAnonymous(name);
513513
// Remove \n in DeclPrinter.cpp "{\n" + if(!TerseOutput)something + "}"
514514
for (std::string::size_type i = 0;;) {

src/main.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ int main(int argc, char **argv) {
140140
if (opt_index.size()) {
141141
SmallString<256> root(opt_index);
142142
sys::fs::make_absolute(root);
143-
pipeline::standalone(root.str());
143+
pipeline::standalone(std::string(root.data(), root.size()));
144144
} else {
145145
// The thread that reads from stdin and dispatchs commands to the main
146146
// thread.

src/pipeline.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ bool cacheInvalid(VFS *vfs, IndexFile *prev, const std::string &path,
113113
}
114114

115115
// For inferred files, allow -o a a.cc -> -o b b.cc
116-
std::string stem = sys::path::stem(path);
116+
StringRef stem = sys::path::stem(path);
117117
int changed = -1, size = std::min(prev->args.size(), args.size());
118118
for (int i = 0; i < size; i++)
119119
if (strcmp(prev->args[i], args[i]) && sys::path::stem(args[i]) != stem) {

src/platform.hh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
// Copyright 2017-2018 ccls Authors
1+
// Copyright 2017-2020 ccls Authors
22
// SPDX-License-Identifier: Apache-2.0
33

44
#pragma once
55

6+
#include <llvm/ADT/StringRef.h>
7+
68
#include <string>
7-
#include <string_view>
8-
#include <vector>
99

1010
namespace ccls {
11-
std::string normalizePath(const std::string &path);
11+
std::string normalizePath(llvm::StringRef path);
1212

1313
// Free any unused memory and return it to the system.
1414
void freeUnusedMemory();

src/platform_posix.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ namespace pipeline {
4040
void threadEnter();
4141
}
4242

43-
std::string normalizePath(const std::string &path) {
43+
std::string normalizePath(llvm::StringRef path) {
4444
llvm::SmallString<256> p(path);
4545
llvm::sys::path::remove_dots(p, true);
4646
return {p.data(), p.size()};

src/platform_win.cc

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,12 @@
1919
#include <thread>
2020

2121
namespace ccls {
22-
std::string normalizePath(const std::string &path) {
23-
DWORD retval = 0;
22+
std::string normalizePath(llvm::StringRef path) {
2423
TCHAR buffer[MAX_PATH] = TEXT("");
2524
TCHAR **lpp_part = {NULL};
2625

27-
std::string result;
28-
retval = GetFullPathName(path.c_str(), MAX_PATH, buffer, lpp_part);
29-
// fail, return original
30-
if (retval == 0)
31-
result = path;
32-
else
26+
std::string result(path);
27+
if (GetFullPathName(result.c_str(), MAX_PATH, buffer, lpp_part) != 0)
3328
result = buffer;
3429

3530
std::replace(result.begin(), result.end(), '\\', '/');

src/project.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ readCompilerArgumentsFromFile(const std::string &path) {
226226
return {};
227227
std::vector<const char *> args;
228228
for (line_iterator i(*mbOrErr.get(), true, '#'), e; i != e; ++i) {
229-
std::string line = *i;
229+
std::string line(*i);
230230
doPathMapping(line);
231231
args.push_back(intern(line));
232232
}
@@ -641,7 +641,7 @@ void Project::index(WorkingFiles *wfiles, const RequestId &id) {
641641
void Project::indexRelated(const std::string &path) {
642642
auto &gi = g_config->index;
643643
GroupMatch match(gi.whitelist, gi.blacklist);
644-
std::string stem = sys::path::stem(path);
644+
StringRef stem = sys::path::stem(path);
645645
std::vector<const char *> args, extra_args;
646646
for (const std::string &arg : g_config->clang.extraArgs)
647647
extra_args.push_back(intern(arg));

src/sema_manager.cc

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -622,9 +622,10 @@ void *diagnosticMain(void *manager_) {
622622
for (const Note &n : d.notes) {
623623
SmallString<256> str(n.file);
624624
llvm::sys::path::remove_dots(str, true);
625-
Location loc{DocumentUri::fromPath(str.str()),
626-
lsRange{{n.range.start.line, n.range.start.column},
627-
{n.range.end.line, n.range.end.column}}};
625+
Location loc{
626+
DocumentUri::fromPath(std::string(str.data(), str.size())),
627+
lsRange{{n.range.start.line, n.range.start.column},
628+
{n.range.end.line, n.range.end.column}}};
628629
ls_diag.relatedInformation.push_back({loc, n.message});
629630
}
630631
} else {

src/serializer.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ void reflect(JsonWriter &vis, IndexInclude &v) {
218218
reflectMemberStart(vis);
219219
REFLECT_MEMBER(line);
220220
if (gTestOutputMode) {
221-
std::string basename = llvm::sys::path::filename(v.resolved_path);
221+
std::string basename(llvm::sys::path::filename(v.resolved_path));
222222
if (v.resolved_path[0] != '&')
223223
basename = "&" + basename;
224224
REFLECT_MEMBER2("resolved_path", basename);

0 commit comments

Comments
 (0)