mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2024-12-03 19:32:35 +00:00
Revert "Revert "[Tooling/Inclusion] Handle std::get symbol.""
This reverts commit 7c9b15fbae
. Breakage
was in downstream code.
This commit is contained in:
parent
22cd105a66
commit
5a623c2a08
@ -717,7 +717,8 @@ llvm::StringRef CanonicalIncludes::mapSymbol(llvm::StringRef Scope,
|
||||
if (Scope == "std::" && Name == "move")
|
||||
return "<utility>";
|
||||
if (auto StdSym = tooling::stdlib::Symbol::named(Scope, Name, Lang))
|
||||
return StdSym->header().name();
|
||||
if (auto Header = StdSym->header())
|
||||
return Header->name();
|
||||
return "";
|
||||
}
|
||||
|
||||
|
@ -81,7 +81,7 @@ public:
|
||||
llvm::StringRef name() const;
|
||||
llvm::StringRef qualifiedName() const;
|
||||
// The preferred header for this symbol (e.g. the suggested insertion).
|
||||
Header header() const;
|
||||
std::optional<Header> header() const;
|
||||
// Some symbols may be provided by multiple headers.
|
||||
llvm::SmallVector<Header> headers() const;
|
||||
|
||||
|
@ -14,6 +14,7 @@
|
||||
#include "llvm/ADT/STLExtras.h"
|
||||
#include "llvm/ADT/StringRef.h"
|
||||
#include "llvm/Support/Casting.h"
|
||||
#include <optional>
|
||||
|
||||
namespace clang {
|
||||
namespace tooling {
|
||||
@ -120,7 +121,8 @@ static int initialize(Lang Language) {
|
||||
}
|
||||
Mapping->SymbolNames[SymIndex] = {
|
||||
QName.data(), NSLen, static_cast<unsigned int>(QName.size() - NSLen)};
|
||||
Mapping->SymbolHeaderIDs[SymIndex].push_back(AddHeader(HeaderName));
|
||||
if (!HeaderName.empty())
|
||||
Mapping->SymbolHeaderIDs[SymIndex].push_back(AddHeader(HeaderName));
|
||||
|
||||
NSSymbolMap &NSSymbols = AddNS(QName.take_front(NSLen));
|
||||
NSSymbols.try_emplace(QName.drop_front(NSLen), SymIndex);
|
||||
@ -205,8 +207,11 @@ std::optional<Symbol> Symbol::named(llvm::StringRef Scope, llvm::StringRef Name,
|
||||
}
|
||||
return std::nullopt;
|
||||
}
|
||||
Header Symbol::header() const {
|
||||
return Header(getMappingPerLang(Language)->SymbolHeaderIDs[ID][0], Language);
|
||||
std::optional<Header> Symbol::header() const {
|
||||
const auto& Headers = getMappingPerLang(Language)->SymbolHeaderIDs[ID];
|
||||
if (Headers.empty())
|
||||
return std::nullopt;
|
||||
return Header(Headers.front(), Language);
|
||||
}
|
||||
llvm::SmallVector<Header> Symbol::headers() const {
|
||||
llvm::SmallVector<Header> Results;
|
||||
|
@ -218,3 +218,8 @@ SYMBOL(ssize, std::, <string_view>)
|
||||
SYMBOL(ssize, std::, <unordered_map>)
|
||||
SYMBOL(ssize, std::, <unordered_set>)
|
||||
SYMBOL(ssize, std::, <vector>)
|
||||
|
||||
// std::get has a few variants for different types (tuple, array, pair etc)
|
||||
// which is tricky to disambiguate without type information.
|
||||
// Don't set any header for it, as it comes with the type header.
|
||||
SYMBOL(get, std::, /*no headers*/)
|
||||
|
@ -58,6 +58,9 @@ TEST(StdlibTest, All) {
|
||||
EXPECT_EQ(Vector->header(), *VectorH);
|
||||
EXPECT_THAT(Vector->headers(), ElementsAre(*VectorH));
|
||||
|
||||
EXPECT_TRUE(stdlib::Symbol::named("std::", "get"));
|
||||
EXPECT_FALSE(stdlib::Symbol::named("std::", "get")->header());
|
||||
|
||||
EXPECT_THAT(stdlib::Symbol::named("std::", "basic_iostream")->headers(),
|
||||
ElementsAre(stdlib::Header::named("<istream>"),
|
||||
stdlib::Header::named("<iostream>"),
|
||||
|
Loading…
Reference in New Issue
Block a user