[PATCH] D46065: [clangd] Add "str()" method to SymbolID.
Haojian Wu via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Apr 25 08:14:26 PDT 2018
hokein created this revision.
hokein added a reviewer: ioeric.
Herald added subscribers: jkorous, MaskRay, ilya-biryukov, klimek.
This is a convenient function when we try to get std::string of
SymbolID.
Repository:
rCTE Clang Tools Extra
https://reviews.llvm.org/D46065
Files:
clangd/global-symbol-builder/GlobalSymbolBuilderMain.cpp
clangd/index/Index.cpp
clangd/index/Index.h
Index: clangd/index/Index.h
===================================================================
--- clangd/index/Index.h
+++ clangd/index/Index.h
@@ -69,6 +69,9 @@
return HashValue < Sym.HashValue;
}
+ // Returns a 40-bytes hex encoded string.
+ std::string str() const;
+
private:
static constexpr unsigned HashByteLength = 20;
Index: clangd/index/Index.cpp
===================================================================
--- clangd/index/Index.cpp
+++ clangd/index/Index.cpp
@@ -31,6 +31,13 @@
return OS;
}
+std::string SymbolID::str() const {
+ std::string ID;
+ llvm::raw_string_ostream OS(ID);
+ OS << *this;
+ return OS.str();
+}
+
void operator>>(StringRef Str, SymbolID &ID) {
std::string HexString = fromHex(Str);
assert(HexString.size() == ID.HashValue.size());
Index: clangd/global-symbol-builder/GlobalSymbolBuilderMain.cpp
===================================================================
--- clangd/global-symbol-builder/GlobalSymbolBuilderMain.cpp
+++ clangd/global-symbol-builder/GlobalSymbolBuilderMain.cpp
@@ -78,10 +78,7 @@
auto Symbols = Collector->takeSymbols();
for (const auto &Sym : Symbols) {
- std::string IDStr;
- llvm::raw_string_ostream OS(IDStr);
- OS << Sym.ID;
- Ctx->reportResult(OS.str(), SymbolToYAML(Sym));
+ Ctx->reportResult(Sym.ID.str(), SymbolToYAML(Sym));
}
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D46065.143940.patch
Type: text/x-patch
Size: 1425 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180425/29d19b86/attachment.bin>
More information about the cfe-commits
mailing list