aboutsummaryrefslogtreecommitdiff
path: root/include-fixer
diff options
context:
space:
mode:
authorSam McCall <sam.mccall@gmail.com>2017-03-09 10:47:44 +0000
committerSam McCall <sam.mccall@gmail.com>2017-03-09 10:47:44 +0000
commit32420e9af12c9c1fc5c287574c10277b3f89370c (patch)
tree16267f4433d6a9d05ce996936b1a1c0add718a4f /include-fixer
parent4671b3eee4c85fd02801eb75a6da661314409c85 (diff)
downloadclang-tools-extra-32420e9af12c9c1fc5c287574c10277b3f89370c.tar.gz
[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 git-svn-id: https://llvm.org/svn/llvm-project/clang-tools-extra/trunk@297371 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include-fixer')
-rw-r--r--include-fixer/IncludeFixer.cpp3
-rw-r--r--include-fixer/find-all-symbols/FindAllMacros.cpp3
-rw-r--r--include-fixer/find-all-symbols/FindAllSymbols.cpp9
-rw-r--r--include-fixer/find-all-symbols/SymbolInfo.cpp16
-rw-r--r--include-fixer/find-all-symbols/SymbolInfo.h16
-rw-r--r--include-fixer/tool/ClangIncludeFixer.cpp2
6 files changed, 20 insertions, 29 deletions
diff --git a/include-fixer/IncludeFixer.cpp b/include-fixer/IncludeFixer.cpp
index ca4d863d..e68231b8 100644
--- a/include-fixer/IncludeFixer.cpp
+++ b/include-fixer/IncludeFixer.cpp
@@ -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);
}
diff --git a/include-fixer/find-all-symbols/FindAllMacros.cpp b/include-fixer/find-all-symbols/FindAllMacros.cpp
index d1ef3515..3dc2b96f 100644
--- a/include-fixer/find-all-symbols/FindAllMacros.cpp
+++ b/include-fixer/find-all-symbols/FindAllMacros.cpp
@@ -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,
diff --git a/include-fixer/find-all-symbols/FindAllSymbols.cpp b/include-fixer/find-all-symbols/FindAllSymbols.cpp
index 629851ff..cf8ce4ea 100644
--- a/include-fixer/find-all-symbols/FindAllSymbols.cpp
+++ b/include-fixer/find-all-symbols/FindAllSymbols.cpp
@@ -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"))))),
diff --git a/include-fixer/find-all-symbols/SymbolInfo.cpp b/include-fixer/find-all-symbols/SymbolInfo.cpp
index 7194f2e2..a2195392 100644
--- a/include-fixer/find-all-symbols/SymbolInfo.cpp
+++ b/include-fixer/find-all-symbols/SymbolInfo.cpp
@@ -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 {
diff --git a/include-fixer/find-all-symbols/SymbolInfo.h b/include-fixer/find-all-symbols/SymbolInfo.h
index e2960bfe..92d360d3 100644
--- a/include-fixer/find-all-symbols/SymbolInfo.h
+++ b/include-fixer/find-all-symbols/SymbolInfo.h
@@ -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 {
diff --git a/include-fixer/tool/ClangIncludeFixer.cpp b/include-fixer/tool/ClangIncludeFixer.cpp
index e2054130..2740c4d2 100644
--- a/include-fixer/tool/ClangIncludeFixer.cpp
+++ b/include-fixer/tool/ClangIncludeFixer.cpp
@@ -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)});