[include-fixer] Remove line number from Symbol identity

Summary:
Remove line number from Symbol identity.

For our purposes (include-fixer and clangd autocomplete), function overloads
within the same header should mostly be treated as a single combined symbol.

We may want to track individual occurrences (line number, full type info)
and aggregate this during mapreduce, but that's not done here.

Reviewers: hokein, bkramer

Subscribers: cfe-commits

Differential Revision: https://reviews.llvm.org/D30685

llvm-svn: 297371
This commit is contained in:
Sam McCall 2017-03-09 10:47:44 +00:00
parent 76630d43f6
commit 573050e703
12 changed files with 178 additions and 208 deletions

View File

@ -333,8 +333,7 @@ IncludeFixerContext IncludeFixerSemaSource::getIncludeFixerContext(
: "\"" + FilePath + "\""),
SourceManager, HeaderSearch);
SymbolCandidates.emplace_back(Symbol.getName(), Symbol.getSymbolKind(),
MinimizedFilePath, Symbol.getLineNumber(),
Symbol.getContexts());
MinimizedFilePath, Symbol.getContexts());
}
return IncludeFixerContext(FilePath, QuerySymbolInfos, SymbolCandidates);
}

View File

@ -28,8 +28,7 @@ FindAllMacros::CreateMacroSymbol(const Token &MacroNameTok,
if (FilePath.empty())
return llvm::None;
return SymbolInfo(MacroNameTok.getIdentifierInfo()->getName(),
SymbolInfo::SymbolKind::Macro, FilePath,
SM->getSpellingLineNumber(info->getDefinitionLoc()), {});
SymbolInfo::SymbolKind::Macro, FilePath, {});
}
void FindAllMacros::MacroDefined(const Token &MacroNameTok,

View File

@ -109,8 +109,7 @@ CreateSymbolInfo(const NamedDecl *ND, const SourceManager &SM,
std::string FilePath = getIncludePath(SM, Loc, Collector);
if (FilePath.empty()) return llvm::None;
return SymbolInfo(ND->getNameAsString(), Type, FilePath,
SM.getExpansionLineNumber(Loc), GetContexts(ND));
return SymbolInfo(ND->getNameAsString(), Type, FilePath, GetContexts(ND));
}
} // namespace
@ -196,7 +195,7 @@ void FindAllSymbols::registerMatchers(MatchFinder *MatchFinder) {
anyOf(hasDeclContext(enumDecl(HasNSOrTUCtxMatcher)), ExternCMatcher));
// Most of the time we care about all matchable decls, or all types.
auto Types = namedDecl(anyOf(CRecords, CXXRecords, Enums, Typedefs));
auto Types = namedDecl(anyOf(CRecords, CXXRecords, Enums));
auto Decls = namedDecl(anyOf(CRecords, CXXRecords, Enums, Typedefs, Vars,
EnumConstants, Functions));
@ -219,8 +218,8 @@ void FindAllSymbols::registerMatchers(MatchFinder *MatchFinder) {
typeLoc(isExpansionInMainFile(),
loc(qualType(hasDeclaration(Types.bind("use"))))),
this);
// Uses of typedefs: these are transparent to hasDeclaration, so we need to
// handle them explicitly.
// Uses of typedefs: these are often transparent to hasDeclaration, so we need
// to handle them explicitly.
MatchFinder->addMatcher(
typeLoc(isExpansionInMainFile(),
loc(typedefType(hasDeclaration(Typedefs.bind("use"))))),

View File

@ -32,7 +32,6 @@ template <> struct MappingTraits<SymbolAndSignals> {
io.mapRequired("Name", Symbol.Symbol.Name);
io.mapRequired("Contexts", Symbol.Symbol.Contexts);
io.mapRequired("FilePath", Symbol.Symbol.FilePath);
io.mapRequired("LineNumber", Symbol.Symbol.LineNumber);
io.mapRequired("Type", Symbol.Symbol.Type);
io.mapRequired("Seen", Symbol.Signals.Seen);
io.mapRequired("Used", Symbol.Signals.Used);
@ -74,21 +73,18 @@ namespace clang {
namespace find_all_symbols {
SymbolInfo::SymbolInfo(llvm::StringRef Name, SymbolKind Type,
llvm::StringRef FilePath, int LineNumber,
llvm::StringRef FilePath,
const std::vector<Context> &Contexts)
: Name(Name), Type(Type), FilePath(FilePath), Contexts(Contexts),
LineNumber(LineNumber) {}
: Name(Name), Type(Type), FilePath(FilePath), Contexts(Contexts) {}
bool SymbolInfo::operator==(const SymbolInfo &Symbol) const {
return std::tie(Name, Type, FilePath, LineNumber, Contexts) ==
std::tie(Symbol.Name, Symbol.Type, Symbol.FilePath, Symbol.LineNumber,
Symbol.Contexts);
return std::tie(Name, Type, FilePath, Contexts) ==
std::tie(Symbol.Name, Symbol.Type, Symbol.FilePath, Symbol.Contexts);
}
bool SymbolInfo::operator<(const SymbolInfo &Symbol) const {
return std::tie(Name, Type, FilePath, LineNumber, Contexts) <
std::tie(Symbol.Name, Symbol.Type, Symbol.FilePath, Symbol.LineNumber,
Symbol.Contexts);
return std::tie(Name, Type, FilePath, Contexts) <
std::tie(Symbol.Name, Symbol.Type, Symbol.FilePath, Symbol.Contexts);
}
std::string SymbolInfo::getQualifiedName() const {

View File

@ -20,7 +20,11 @@
namespace clang {
namespace find_all_symbols {
/// \brief Contains all information for a Symbol.
/// \brief Describes a named symbol from a header.
/// Symbols with the same qualified name and type (e.g. function overloads)
/// that appear in the same header are represented by a single SymbolInfo.
///
/// TODO: keep track of instances, e.g. overload locations and signatures.
class SymbolInfo {
public:
/// \brief The SymbolInfo Type.
@ -66,10 +70,10 @@ public:
// The default constructor is required by YAML traits in
// LLVM_YAML_IS_DOCUMENT_LIST_VECTOR.
SymbolInfo() : Type(SymbolKind::Unknown), LineNumber(-1) {}
SymbolInfo() : Type(SymbolKind::Unknown) {}
SymbolInfo(llvm::StringRef Name, SymbolKind Type, llvm::StringRef FilePath,
int LineNumber, const std::vector<Context> &Contexts);
const std::vector<Context> &Contexts);
void SetFilePath(llvm::StringRef Path) { FilePath = Path; }
@ -90,9 +94,6 @@ public:
return Contexts;
}
/// \brief Get a 1-based line number of the symbol's declaration.
int getLineNumber() const { return LineNumber; }
bool operator<(const SymbolInfo &Symbol) const;
bool operator==(const SymbolInfo &Symbol) const;
@ -121,9 +122,6 @@ private:
///
/// If the symbol is declared in `TranslationUnitDecl`, it has no context.
std::vector<Context> Contexts;
/// \brief The 1-based line number of of the symbol's declaration.
int LineNumber;
};
struct SymbolAndSignals {

View File

@ -178,7 +178,7 @@ createSymbolIndexManager(StringRef FilePath) {
for (size_t I = 0, E = CommaSplits.size(); I != E; ++I)
Symbols.push_back(
{SymbolInfo(Split.first.trim(), SymbolInfo::SymbolKind::Unknown,
CommaSplits[I].trim(), 1, {}),
CommaSplits[I].trim(), {}),
// Use fake "seen" signal for tests, so first header wins.
SymbolInfo::Signals(/*Seen=*/static_cast<unsigned>(E - I),
/*Used=*/0)});

View File

@ -6,7 +6,6 @@ Contexts:
- ContextType: Namespace
ContextName: b
FilePath: foo.h
LineNumber: 1
Type: Class
Seen: 1
Used: 0
@ -18,7 +17,6 @@ Contexts:
- ContextType: Namespace
ContextName: b
FilePath: ../include/bar.h
LineNumber: 1
Type: Class
Seen: 1
Used: 0
@ -30,7 +28,6 @@ Contexts:
- ContextType: Namespace
ContextName: b
FilePath: ../include/bar.h
LineNumber: 2
Type: Class
Seen: 3
Used: 0
@ -42,7 +39,6 @@ Contexts:
- ContextType: Namespace
ContextName: b
FilePath: ../include/zbar.h
LineNumber: 1
Type: Class
Seen: 3
Used: 0
@ -50,7 +46,6 @@ Used: 0
Name: b
Contexts:
FilePath: var.h
LineNumber: 1
Type: Variable
Seen: 1
Used: 0
@ -60,7 +55,6 @@ Contexts:
- ContextType: Namespace
ContextName: c
FilePath: test/include-fixer/baz.h
LineNumber: 1
Type: Class
Seen: 1
Used: 0

View File

@ -4,7 +4,6 @@ Contexts:
- ContextType: Namespace
ContextName: a
FilePath: foo.h
LineNumber: 1
Type: Class
Seen: 1
Used: 1
@ -15,7 +14,6 @@ Contexts:
- ContextType: Namespace
ContextName: a
FilePath: ../include/bar.h
LineNumber: 1
Type: Class
Seen: 1
Used: 2

View File

@ -4,7 +4,6 @@ Contexts:
- ContextType: Namespace
ContextName: a
FilePath: foo.h
LineNumber: 1
Type: Class
Seen: 1
Used: 2
@ -15,7 +14,6 @@ Contexts:
- ContextType: Namespace
ContextName: a
FilePath: ../include/barbar.h
LineNumber: 1
Type: Class
Seen: 1
Used: 0

View File

@ -7,7 +7,6 @@ Contexts:
- ContextType: Namespace
ContextName: a
FilePath: ../include/bar.h
LineNumber: 1
Type: Class
Seen: 1
Used: 1
@ -18,7 +17,6 @@ Contexts:
- ContextType: Namespace
ContextName: a
FilePath: ../include/barbar.h
LineNumber: 1
Type: Class
Seen: 1
Used: 0
@ -29,7 +27,6 @@ Contexts:
- ContextType: Namespace
ContextName: a
FilePath: foo.h
LineNumber: 1
Type: Class
Seen: 2
Used: 2

View File

@ -54,43 +54,43 @@ static std::string runIncludeFixer(
StringRef Code,
const std::vector<std::string> &ExtraArgs = std::vector<std::string>()) {
std::vector<SymbolAndSignals> Symbols = {
{SymbolInfo("string", SymbolInfo::SymbolKind::Class, "<string>", 1,
{SymbolInfo("string", SymbolInfo::SymbolKind::Class, "<string>",
{{SymbolInfo::ContextType::Namespace, "std"}}),
SymbolInfo::Signals{}},
{SymbolInfo("sting", SymbolInfo::SymbolKind::Class, "\"sting\"", 1,
{SymbolInfo("sting", SymbolInfo::SymbolKind::Class, "\"sting\"",
{{SymbolInfo::ContextType::Namespace, "std"}}),
SymbolInfo::Signals{}},
{SymbolInfo("foo", SymbolInfo::SymbolKind::Class,
"\"dir/otherdir/qux.h\"", 1,
"\"dir/otherdir/qux.h\"",
{{SymbolInfo::ContextType::Namespace, "b"},
{SymbolInfo::ContextType::Namespace, "a"}}),
SymbolInfo::Signals{}},
{SymbolInfo("bar", SymbolInfo::SymbolKind::Class, "\"bar.h\"", 1,
{SymbolInfo("bar", SymbolInfo::SymbolKind::Class, "\"bar.h\"",
{{SymbolInfo::ContextType::Namespace, "b"},
{SymbolInfo::ContextType::Namespace, "a"}}),
SymbolInfo::Signals{}},
{SymbolInfo("bar", SymbolInfo::SymbolKind::Class, "\"bar2.h\"", 1,
{SymbolInfo("bar", SymbolInfo::SymbolKind::Class, "\"bar2.h\"",
{{SymbolInfo::ContextType::Namespace, "c"},
{SymbolInfo::ContextType::Namespace, "a"}}),
SymbolInfo::Signals{}},
{SymbolInfo("Green", SymbolInfo::SymbolKind::Class, "\"color.h\"", 1,
{SymbolInfo("Green", SymbolInfo::SymbolKind::Class, "\"color.h\"",
{{SymbolInfo::ContextType::EnumDecl, "Color"},
{SymbolInfo::ContextType::Namespace, "b"},
{SymbolInfo::ContextType::Namespace, "a"}}),
SymbolInfo::Signals{}},
{SymbolInfo("Vector", SymbolInfo::SymbolKind::Class, "\"Vector.h\"", 1,
{SymbolInfo("Vector", SymbolInfo::SymbolKind::Class, "\"Vector.h\"",
{{SymbolInfo::ContextType::Namespace, "__a"},
{SymbolInfo::ContextType::Namespace, "a"}}),
SymbolInfo::Signals{/*Seen=*/2, 0}},
{SymbolInfo("Vector", SymbolInfo::SymbolKind::Class, "\"Vector.h\"", 2,
{SymbolInfo("Vector", SymbolInfo::SymbolKind::Class, "\"Vector.h\"",
{{SymbolInfo::ContextType::Namespace, "a"}}),
SymbolInfo::Signals{/*Seen=*/2, 0}},
{SymbolInfo("StrCat", SymbolInfo::SymbolKind::Class, "\"strcat.h\"", 1,
{SymbolInfo("StrCat", SymbolInfo::SymbolKind::Class, "\"strcat.h\"",
{{SymbolInfo::ContextType::Namespace, "str"}}),
SymbolInfo::Signals{}},
{SymbolInfo("str", SymbolInfo::SymbolKind::Class, "\"str.h\"", 1, {}),
{SymbolInfo("str", SymbolInfo::SymbolKind::Class, "\"str.h\"", {}),
SymbolInfo::Signals{}},
{SymbolInfo("foo2", SymbolInfo::SymbolKind::Class, "\"foo2.h\"", 1, {}),
{SymbolInfo("foo2", SymbolInfo::SymbolKind::Class, "\"foo2.h\"", {}),
SymbolInfo::Signals{}},
};
auto SymbolIndexMgr = llvm::make_unique<SymbolIndexManager>();

View File

@ -42,14 +42,14 @@ public:
Symbols[Entry.first] += Entry.second;
}
bool hasSymbol(const SymbolInfo &Symbol) const {
int seen(const SymbolInfo &Symbol) const {
auto it = Symbols.find(Symbol);
return it != Symbols.end() && it->second.Seen > 0;
return it == Symbols.end() ? 0 : it->second.Seen;
}
bool hasUse(const SymbolInfo &Symbol) const {
int used(const SymbolInfo &Symbol) const {
auto it = Symbols.find(Symbol);
return it != Symbols.end() && it->second.Used > 0;
return it == Symbols.end() ? 0 : it->second.Used;
}
private:
@ -58,11 +58,9 @@ private:
class FindAllSymbolsTest : public ::testing::Test {
public:
bool hasSymbol(const SymbolInfo &Symbol) {
return Reporter.hasSymbol(Symbol);
}
int seen(const SymbolInfo &Symbol) { return Reporter.seen(Symbol); }
bool hasUse(const SymbolInfo &Symbol) { return Reporter.hasUse(Symbol); }
int used(const SymbolInfo &Symbol) { return Reporter.used(Symbol); }
bool runFindAllSymbols(StringRef HeaderCode, StringRef MainCode) {
llvm::IntrusiveRefCntPtr<vfs::InMemoryFileSystem> InMemoryFileSystem(
@ -86,9 +84,9 @@ public:
std::string InternalCode =
"#include \"private.inc\"\nclass Internal {};";
SymbolInfo InternalSymbol("Internal", SymbolInfo::SymbolKind::Class,
TopHeader, 2, {});
TopHeader, {});
SymbolInfo IncSymbol("IncHeaderClass", SymbolInfo::SymbolKind::Class,
TopHeader, 1, {});
TopHeader, {});
InMemoryFileSystem->addFile(
IncHeader, 0, llvm::MemoryBuffer::getMemBuffer(IncHeaderCode));
InMemoryFileSystem->addFile(InternalHeader, 0,
@ -120,19 +118,19 @@ public:
InMemoryFileSystem->addFile(
DirtyHeader, 0, llvm::MemoryBuffer::getMemBuffer(DirtyHeaderContent));
SymbolInfo DirtyMacro("INTERNAL", SymbolInfo::SymbolKind::Macro,
CleanHeader, 1, {});
CleanHeader, {});
SymbolInfo DirtySymbol("ExtraInternal", SymbolInfo::SymbolKind::Class,
CleanHeader, 2, {});
CleanHeader, {});
#endif // _MSC_VER && __MINGW32__
Content += "\n" + MainCode.str();
InMemoryFileSystem->addFile(FileName, 0,
llvm::MemoryBuffer::getMemBuffer(Content));
Invocation.run();
EXPECT_TRUE(hasSymbol(InternalSymbol));
EXPECT_TRUE(hasSymbol(IncSymbol));
EXPECT_EQ(1, seen(InternalSymbol));
EXPECT_EQ(1, seen(IncSymbol));
#if !defined(_MSC_VER) && !defined(__MINGW32__)
EXPECT_TRUE(hasSymbol(DirtySymbol));
EXPECT_TRUE(hasSymbol(DirtyMacro));
EXPECT_EQ(1, seen(DirtySymbol));
EXPECT_EQ(1, seen(DirtyMacro));
#endif // _MSC_VER && __MINGW32__
return true;
}
@ -155,20 +153,20 @@ TEST_F(FindAllSymbolsTest, VariableSymbols) {
runFindAllSymbols(Header, Main);
SymbolInfo Symbol =
SymbolInfo("xargc", SymbolInfo::SymbolKind::Variable, HeaderName, 2, {});
EXPECT_TRUE(hasSymbol(Symbol));
EXPECT_TRUE(hasUse(Symbol));
SymbolInfo("xargc", SymbolInfo::SymbolKind::Variable, HeaderName, {});
EXPECT_EQ(1, seen(Symbol));
EXPECT_EQ(1, used(Symbol));
Symbol = SymbolInfo("SSSS", SymbolInfo::SymbolKind::Variable, HeaderName, 4,
Symbol = SymbolInfo("SSSS", SymbolInfo::SymbolKind::Variable, HeaderName,
{{SymbolInfo::ContextType::Namespace, "na"}});
EXPECT_TRUE(hasSymbol(Symbol));
EXPECT_TRUE(hasUse(Symbol));
EXPECT_EQ(1, seen(Symbol));
EXPECT_EQ(1, used(Symbol));
Symbol = SymbolInfo("XXXX", SymbolInfo::SymbolKind::Variable, HeaderName, 5,
Symbol = SymbolInfo("XXXX", SymbolInfo::SymbolKind::Variable, HeaderName,
{{SymbolInfo::ContextType::Namespace, "nb"},
{SymbolInfo::ContextType::Namespace, "na"}});
EXPECT_TRUE(hasSymbol(Symbol));
EXPECT_TRUE(hasUse(Symbol));
EXPECT_EQ(1, seen(Symbol));
EXPECT_EQ(1, used(Symbol));
}
TEST_F(FindAllSymbolsTest, ExternCSymbols) {
@ -188,14 +186,14 @@ TEST_F(FindAllSymbolsTest, ExternCSymbols) {
runFindAllSymbols(Header, Main);
SymbolInfo Symbol =
SymbolInfo("C_Func", SymbolInfo::SymbolKind::Function, HeaderName, 3, {});
EXPECT_TRUE(hasSymbol(Symbol));
EXPECT_TRUE(hasUse(Symbol));
SymbolInfo("C_Func", SymbolInfo::SymbolKind::Function, HeaderName, {});
EXPECT_EQ(1, seen(Symbol));
EXPECT_EQ(1, used(Symbol));
Symbol =
SymbolInfo("C_struct", SymbolInfo::SymbolKind::Class, HeaderName, 4, {});
EXPECT_TRUE(hasSymbol(Symbol));
EXPECT_TRUE(hasUse(Symbol));
SymbolInfo("C_struct", SymbolInfo::SymbolKind::Class, HeaderName, {});
EXPECT_EQ(1, seen(Symbol));
EXPECT_EQ(1, used(Symbol));
}
TEST_F(FindAllSymbolsTest, CXXRecordSymbols) {
@ -219,20 +217,20 @@ TEST_F(FindAllSymbolsTest, CXXRecordSymbols) {
runFindAllSymbols(Header, Main);
SymbolInfo Symbol =
SymbolInfo("Glob", SymbolInfo::SymbolKind::Class, HeaderName, 2, {});
EXPECT_TRUE(hasSymbol(Symbol));
EXPECT_TRUE(hasUse(Symbol));
SymbolInfo("Glob", SymbolInfo::SymbolKind::Class, HeaderName, {});
EXPECT_EQ(1, seen(Symbol));
EXPECT_EQ(1, used(Symbol));
Symbol = SymbolInfo("A", SymbolInfo::SymbolKind::Class, HeaderName, 6,
Symbol = SymbolInfo("A", SymbolInfo::SymbolKind::Class, HeaderName,
{{SymbolInfo::ContextType::Namespace, "na"}});
EXPECT_TRUE(hasSymbol(Symbol));
EXPECT_TRUE(hasUse(Symbol));
EXPECT_EQ(1, seen(Symbol));
EXPECT_EQ(1, used(Symbol));
Symbol = SymbolInfo("AAA", SymbolInfo::SymbolKind::Class, HeaderName, 7,
Symbol = SymbolInfo("AAA", SymbolInfo::SymbolKind::Class, HeaderName,
{{SymbolInfo::ContextType::Record, "A"},
{SymbolInfo::ContextType::Namespace, "na"}});
EXPECT_FALSE(hasSymbol(Symbol));
EXPECT_FALSE(hasUse(Symbol));
EXPECT_EQ(0, seen(Symbol));
EXPECT_EQ(0, used(Symbol));
}
TEST_F(FindAllSymbolsTest, CXXRecordSymbolsTemplate) {
@ -257,9 +255,9 @@ TEST_F(FindAllSymbolsTest, CXXRecordSymbolsTemplate) {
runFindAllSymbols(Header, Main);
SymbolInfo Symbol =
SymbolInfo("T_TEMP", SymbolInfo::SymbolKind::Class, HeaderName, 3, {});
EXPECT_TRUE(hasSymbol(Symbol));
EXPECT_TRUE(hasUse(Symbol));
SymbolInfo("T_TEMP", SymbolInfo::SymbolKind::Class, HeaderName, {});
EXPECT_EQ(1, seen(Symbol));
EXPECT_EQ(1, used(Symbol));
}
TEST_F(FindAllSymbolsTest, DontIgnoreTemplatePartialSpecialization) {
@ -274,14 +272,10 @@ TEST_F(FindAllSymbolsTest, DontIgnoreTemplatePartialSpecialization) {
)";
runFindAllSymbols(Code, "");
SymbolInfo Symbol =
SymbolInfo("Class", SymbolInfo::SymbolKind::Class, HeaderName, 4, {});
EXPECT_TRUE(hasSymbol(Symbol));
Symbol =
SymbolInfo("f", SymbolInfo::SymbolKind::Function, HeaderName, 7, {});
EXPECT_TRUE(hasSymbol(Symbol));
Symbol =
SymbolInfo("f", SymbolInfo::SymbolKind::Function, HeaderName, 8, {});
EXPECT_FALSE(hasSymbol(Symbol));
SymbolInfo("Class", SymbolInfo::SymbolKind::Class, HeaderName, {});
EXPECT_EQ(1, seen(Symbol));
Symbol = SymbolInfo("f", SymbolInfo::SymbolKind::Function, HeaderName, {});
EXPECT_EQ(1, seen(Symbol));
}
TEST_F(FindAllSymbolsTest, FunctionSymbols) {
@ -309,26 +303,26 @@ TEST_F(FindAllSymbolsTest, FunctionSymbols) {
runFindAllSymbols(Header, Main);
SymbolInfo Symbol =
SymbolInfo("gg", SymbolInfo::SymbolKind::Function, HeaderName, 3,
SymbolInfo("gg", SymbolInfo::SymbolKind::Function, HeaderName,
{{SymbolInfo::ContextType::Namespace, "na"}});
EXPECT_TRUE(hasSymbol(Symbol));
EXPECT_TRUE(hasUse(Symbol));
EXPECT_EQ(1, seen(Symbol));
EXPECT_EQ(1, used(Symbol));
Symbol = SymbolInfo("f", SymbolInfo::SymbolKind::Function, HeaderName, 4,
Symbol = SymbolInfo("f", SymbolInfo::SymbolKind::Function, HeaderName,
{{SymbolInfo::ContextType::Namespace, "na"}});
EXPECT_TRUE(hasSymbol(Symbol));
EXPECT_TRUE(hasUse(Symbol));
EXPECT_EQ(1, seen(Symbol));
EXPECT_EQ(1, used(Symbol));
Symbol = SymbolInfo("SSSFFF", SymbolInfo::SymbolKind::Function, HeaderName, 5,
Symbol = SymbolInfo("SSSFFF", SymbolInfo::SymbolKind::Function, HeaderName,
{{SymbolInfo::ContextType::Namespace, "na"}});
EXPECT_TRUE(hasSymbol(Symbol));
EXPECT_TRUE(hasUse(Symbol));
EXPECT_EQ(1, seen(Symbol));
EXPECT_EQ(1, used(Symbol));
Symbol = SymbolInfo("fun", SymbolInfo::SymbolKind::Function, HeaderName, 10,
Symbol = SymbolInfo("fun", SymbolInfo::SymbolKind::Function, HeaderName,
{{SymbolInfo::ContextType::Namespace, "nb"},
{SymbolInfo::ContextType::Namespace, "na"}});
EXPECT_TRUE(hasSymbol(Symbol));
EXPECT_TRUE(hasUse(Symbol));
EXPECT_EQ(1, seen(Symbol));
EXPECT_EQ(1, used(Symbol));
}
TEST_F(FindAllSymbolsTest, NamespaceTest) {
@ -350,31 +344,31 @@ TEST_F(FindAllSymbolsTest, NamespaceTest) {
runFindAllSymbols(Header, Main);
SymbolInfo Symbol =
SymbolInfo("X1", SymbolInfo::SymbolKind::Variable, HeaderName, 2, {});
EXPECT_TRUE(hasSymbol(Symbol));
EXPECT_TRUE(hasUse(Symbol));
SymbolInfo("X1", SymbolInfo::SymbolKind::Variable, HeaderName, {});
EXPECT_EQ(1, seen(Symbol));
EXPECT_EQ(1, used(Symbol));
Symbol = SymbolInfo("X2", SymbolInfo::SymbolKind::Variable, HeaderName, 3,
Symbol = SymbolInfo("X2", SymbolInfo::SymbolKind::Variable, HeaderName,
{{SymbolInfo::ContextType::Namespace, ""}});
EXPECT_TRUE(hasSymbol(Symbol));
EXPECT_TRUE(hasUse(Symbol));
EXPECT_EQ(1, seen(Symbol));
EXPECT_EQ(1, used(Symbol));
Symbol = SymbolInfo("X3", SymbolInfo::SymbolKind::Variable, HeaderName, 4,
Symbol = SymbolInfo("X3", SymbolInfo::SymbolKind::Variable, HeaderName,
{{SymbolInfo::ContextType::Namespace, ""},
{SymbolInfo::ContextType::Namespace, ""}});
EXPECT_TRUE(hasSymbol(Symbol));
EXPECT_TRUE(hasUse(Symbol));
EXPECT_EQ(1, seen(Symbol));
EXPECT_EQ(1, used(Symbol));
Symbol = SymbolInfo("X4", SymbolInfo::SymbolKind::Variable, HeaderName, 5,
Symbol = SymbolInfo("X4", SymbolInfo::SymbolKind::Variable, HeaderName,
{{SymbolInfo::ContextType::Namespace, "nb"},
{SymbolInfo::ContextType::Namespace, ""}});
EXPECT_TRUE(hasSymbol(Symbol));
EXPECT_TRUE(hasUse(Symbol));
EXPECT_EQ(1, seen(Symbol));
EXPECT_EQ(1, used(Symbol));
Symbol = SymbolInfo("X5", SymbolInfo::SymbolKind::Variable, HeaderName, 6,
Symbol = SymbolInfo("X5", SymbolInfo::SymbolKind::Variable, HeaderName,
{{SymbolInfo::ContextType::Namespace, "na"}});
EXPECT_TRUE(hasSymbol(Symbol));
EXPECT_TRUE(hasUse(Symbol));
EXPECT_EQ(1, seen(Symbol));
EXPECT_EQ(1, used(Symbol));
}
TEST_F(FindAllSymbolsTest, DecayedTypeTest) {
@ -382,9 +376,9 @@ TEST_F(FindAllSymbolsTest, DecayedTypeTest) {
static const char Main[] = R"(int main() { DecayedFunc(nullptr, nullptr); })";
runFindAllSymbols(Header, Main);
SymbolInfo Symbol = SymbolInfo(
"DecayedFunc", SymbolInfo::SymbolKind::Function, HeaderName, 1, {});
EXPECT_TRUE(hasSymbol(Symbol));
EXPECT_TRUE(hasUse(Symbol));
"DecayedFunc", SymbolInfo::SymbolKind::Function, HeaderName, {});
EXPECT_EQ(1, seen(Symbol));
EXPECT_EQ(1, used(Symbol));
}
TEST_F(FindAllSymbolsTest, CTypedefTest) {
@ -402,19 +396,18 @@ TEST_F(FindAllSymbolsTest, CTypedefTest) {
runFindAllSymbols(Header, Main);
SymbolInfo Symbol = SymbolInfo("size_t_", SymbolInfo::SymbolKind::TypedefName,
HeaderName, 2, {});
EXPECT_TRUE(hasSymbol(Symbol));
EXPECT_TRUE(hasUse(Symbol));
HeaderName, {});
EXPECT_EQ(1, seen(Symbol));
EXPECT_EQ(1, used(Symbol));
Symbol = SymbolInfo("X", SymbolInfo::SymbolKind::TypedefName, HeaderName, {});
EXPECT_EQ(1, seen(Symbol));
EXPECT_EQ(1, used(Symbol));
Symbol =
SymbolInfo("X", SymbolInfo::SymbolKind::TypedefName, HeaderName, 3, {});
EXPECT_TRUE(hasSymbol(Symbol));
EXPECT_TRUE(hasUse(Symbol));
Symbol =
SymbolInfo("XX", SymbolInfo::SymbolKind::TypedefName, HeaderName, 4, {});
EXPECT_TRUE(hasSymbol(Symbol));
EXPECT_TRUE(hasUse(Symbol));
SymbolInfo("XX", SymbolInfo::SymbolKind::TypedefName, HeaderName, {});
EXPECT_EQ(1, seen(Symbol));
EXPECT_EQ(1, used(Symbol));
}
TEST_F(FindAllSymbolsTest, EnumTest) {
@ -438,57 +431,56 @@ TEST_F(FindAllSymbolsTest, EnumTest) {
runFindAllSymbols(Header, Main);
SymbolInfo Symbol =
SymbolInfo("Glob_E", SymbolInfo::SymbolKind::EnumDecl, HeaderName, 2, {});
EXPECT_TRUE(hasSymbol(Symbol));
EXPECT_FALSE(hasUse(Symbol));
SymbolInfo("Glob_E", SymbolInfo::SymbolKind::EnumDecl, HeaderName, {});
EXPECT_EQ(1, seen(Symbol));
EXPECT_EQ(0, used(Symbol));
Symbol =
SymbolInfo("G1", SymbolInfo::SymbolKind::EnumConstantDecl, HeaderName, 2,
SymbolInfo("G1", SymbolInfo::SymbolKind::EnumConstantDecl, HeaderName,
{{SymbolInfo::ContextType::EnumDecl, "Glob_E"}});
EXPECT_TRUE(hasSymbol(Symbol));
EXPECT_TRUE(hasUse(Symbol));
EXPECT_EQ(1, seen(Symbol));
EXPECT_EQ(1, used(Symbol));
Symbol =
SymbolInfo("G2", SymbolInfo::SymbolKind::EnumConstantDecl, HeaderName, 2,
SymbolInfo("G2", SymbolInfo::SymbolKind::EnumConstantDecl, HeaderName,
{{SymbolInfo::ContextType::EnumDecl, "Glob_E"}});
EXPECT_TRUE(hasSymbol(Symbol));
EXPECT_TRUE(hasUse(Symbol));
EXPECT_EQ(1, seen(Symbol));
EXPECT_EQ(1, used(Symbol));
Symbol = SymbolInfo("Altitude", SymbolInfo::SymbolKind::EnumDecl, HeaderName,
3, {});
EXPECT_TRUE(hasSymbol(Symbol));
EXPECT_TRUE(hasUse(Symbol));
Symbol =
SymbolInfo("Altitude", SymbolInfo::SymbolKind::EnumDecl, HeaderName, {});
EXPECT_EQ(1, seen(Symbol));
EXPECT_EQ(1, used(Symbol));
Symbol =
SymbolInfo("high", SymbolInfo::SymbolKind::EnumConstantDecl, HeaderName,
3, {{SymbolInfo::ContextType::EnumDecl, "Altitude"}});
EXPECT_FALSE(hasSymbol(Symbol));
EXPECT_FALSE(hasUse(Symbol));
{{SymbolInfo::ContextType::EnumDecl, "Altitude"}});
EXPECT_EQ(0, seen(Symbol));
EXPECT_EQ(0, used(Symbol));
Symbol = SymbolInfo("A1", SymbolInfo::SymbolKind::EnumConstantDecl,
HeaderName, 4, {{SymbolInfo::ContextType::EnumDecl, ""}});
EXPECT_TRUE(hasSymbol(Symbol));
EXPECT_TRUE(hasUse(Symbol));
HeaderName, {{SymbolInfo::ContextType::EnumDecl, ""}});
EXPECT_EQ(1, seen(Symbol));
EXPECT_EQ(1, used(Symbol));
Symbol = SymbolInfo("A2", SymbolInfo::SymbolKind::EnumConstantDecl,
HeaderName, 4, {{SymbolInfo::ContextType::EnumDecl, ""}});
EXPECT_TRUE(hasSymbol(Symbol));
EXPECT_TRUE(hasUse(Symbol));
Symbol = SymbolInfo("", SymbolInfo::SymbolKind::EnumDecl, HeaderName, 4, {});
EXPECT_FALSE(hasSymbol(Symbol));
EXPECT_FALSE(hasUse(Symbol));
HeaderName, {{SymbolInfo::ContextType::EnumDecl, ""}});
EXPECT_EQ(1, seen(Symbol));
EXPECT_EQ(1, used(Symbol));
Symbol = SymbolInfo("", SymbolInfo::SymbolKind::EnumDecl, HeaderName, {});
EXPECT_EQ(0, seen(Symbol));
EXPECT_EQ(0, used(Symbol));
Symbol = SymbolInfo("A_ENUM", SymbolInfo::SymbolKind::EnumDecl, HeaderName, 7,
Symbol = SymbolInfo("A_ENUM", SymbolInfo::SymbolKind::EnumDecl, HeaderName,
{{SymbolInfo::ContextType::Record, "A"}});
EXPECT_FALSE(hasSymbol(Symbol));
EXPECT_FALSE(hasUse(Symbol));
EXPECT_EQ(0, seen(Symbol));
EXPECT_EQ(0, used(Symbol));
Symbol = SymbolInfo("X1", SymbolInfo::SymbolKind::EnumDecl, HeaderName, 7,
Symbol = SymbolInfo("X1", SymbolInfo::SymbolKind::EnumDecl, HeaderName,
{{SymbolInfo::ContextType::EnumDecl, "A_ENUM"},
{SymbolInfo::ContextType::Record, "A"}});
EXPECT_FALSE(hasSymbol(Symbol));
EXPECT_EQ(0, seen(Symbol));
Symbol =
SymbolInfo("DECL", SymbolInfo::SymbolKind::EnumDecl, HeaderName, 9, {});
EXPECT_FALSE(hasSymbol(Symbol));
Symbol = SymbolInfo("DECL", SymbolInfo::SymbolKind::EnumDecl, HeaderName, {});
EXPECT_EQ(0, seen(Symbol));
}
TEST_F(FindAllSymbolsTest, IWYUPrivatePragmaTest) {
@ -503,9 +495,9 @@ TEST_F(FindAllSymbolsTest, IWYUPrivatePragmaTest) {
runFindAllSymbols(Header, Main);
SymbolInfo Symbol =
SymbolInfo("Bar", SymbolInfo::SymbolKind::Class, "bar.h", 3, {});
EXPECT_TRUE(hasSymbol(Symbol));
EXPECT_TRUE(hasUse(Symbol));
SymbolInfo("Bar", SymbolInfo::SymbolKind::Class, "bar.h", {});
EXPECT_EQ(1, seen(Symbol));
EXPECT_EQ(1, used(Symbol));
}
TEST_F(FindAllSymbolsTest, MacroTest) {
@ -521,17 +513,17 @@ TEST_F(FindAllSymbolsTest, MacroTest) {
)";
runFindAllSymbols(Header, Main);
SymbolInfo Symbol =
SymbolInfo("X", SymbolInfo::SymbolKind::Macro, HeaderName, 2, {});
EXPECT_TRUE(hasSymbol(Symbol));
EXPECT_TRUE(hasUse(Symbol));
SymbolInfo("X", SymbolInfo::SymbolKind::Macro, HeaderName, {});
EXPECT_EQ(1, seen(Symbol));
EXPECT_EQ(1, used(Symbol));
Symbol = SymbolInfo("Y", SymbolInfo::SymbolKind::Macro, HeaderName, 3, {});
EXPECT_TRUE(hasSymbol(Symbol));
EXPECT_TRUE(hasUse(Symbol));
Symbol = SymbolInfo("Y", SymbolInfo::SymbolKind::Macro, HeaderName, {});
EXPECT_EQ(1, seen(Symbol));
EXPECT_EQ(1, used(Symbol));
Symbol = SymbolInfo("MAX", SymbolInfo::SymbolKind::Macro, HeaderName, 4, {});
EXPECT_TRUE(hasSymbol(Symbol));
EXPECT_TRUE(hasUse(Symbol));
Symbol = SymbolInfo("MAX", SymbolInfo::SymbolKind::Macro, HeaderName, {});
EXPECT_EQ(1, seen(Symbol));
EXPECT_EQ(1, used(Symbol));
}
TEST_F(FindAllSymbolsTest, MacroTestWithIWYU) {
@ -548,17 +540,17 @@ TEST_F(FindAllSymbolsTest, MacroTestWithIWYU) {
)";
runFindAllSymbols(Header, Main);
SymbolInfo Symbol =
SymbolInfo("X", SymbolInfo::SymbolKind::Macro, "bar.h", 3, {});
EXPECT_TRUE(hasSymbol(Symbol));
EXPECT_TRUE(hasUse(Symbol));
SymbolInfo("X", SymbolInfo::SymbolKind::Macro, "bar.h", {});
EXPECT_EQ(1, seen(Symbol));
EXPECT_EQ(1, used(Symbol));
Symbol = SymbolInfo("Y", SymbolInfo::SymbolKind::Macro, "bar.h", 4, {});
EXPECT_TRUE(hasSymbol(Symbol));
EXPECT_TRUE(hasUse(Symbol));
Symbol = SymbolInfo("Y", SymbolInfo::SymbolKind::Macro, "bar.h", {});
EXPECT_EQ(1, seen(Symbol));
EXPECT_EQ(1, used(Symbol));
Symbol = SymbolInfo("MAX", SymbolInfo::SymbolKind::Macro, "bar.h", 5, {});
EXPECT_TRUE(hasSymbol(Symbol));
EXPECT_TRUE(hasUse(Symbol));
Symbol = SymbolInfo("MAX", SymbolInfo::SymbolKind::Macro, "bar.h", {});
EXPECT_EQ(1, seen(Symbol));
EXPECT_EQ(1, used(Symbol));
}
TEST_F(FindAllSymbolsTest, NoFriendTest) {
@ -569,17 +561,17 @@ TEST_F(FindAllSymbolsTest, NoFriendTest) {
};
)";
runFindAllSymbols(Header, "");
SymbolInfo Symbol = SymbolInfo("WorstFriend", SymbolInfo::SymbolKind::Class,
HeaderName, 2, {});
EXPECT_TRUE(hasSymbol(Symbol));
SymbolInfo Symbol =
SymbolInfo("WorstFriend", SymbolInfo::SymbolKind::Class, HeaderName, {});
EXPECT_EQ(1, seen(Symbol));
Symbol = SymbolInfo("Friend", SymbolInfo::SymbolKind::Function, HeaderName,
3, {});
EXPECT_FALSE(hasSymbol(Symbol));
Symbol =
SymbolInfo("Friend", SymbolInfo::SymbolKind::Function, HeaderName, {});
EXPECT_EQ(0, seen(Symbol));
Symbol = SymbolInfo("BestFriend", SymbolInfo::SymbolKind::Class, HeaderName,
4, {});
EXPECT_FALSE(hasSymbol(Symbol));
Symbol =
SymbolInfo("BestFriend", SymbolInfo::SymbolKind::Class, HeaderName, {});
EXPECT_EQ(0, seen(Symbol));
}
} // namespace find_all_symbols