[clang-tools-extra] r271268 - [include-fixer] collect the number of times a symbols is found in an indexing run and use it for symbols popularity ranking.
Eric Liu via cfe-commits
cfe-commits at lists.llvm.org
Tue May 31 05:01:57 PDT 2016
Author: ioeric
Date: Tue May 31 07:01:48 2016
New Revision: 271268
URL: http://llvm.org/viewvc/llvm-project?rev=271268&view=rev
Log:
[include-fixer] collect the number of times a symbols is found in an indexing run and use it for symbols popularity ranking.
Summary:
[include-fixer] collect the number of times a symbols is found in an
indexing run and use it for symbols popularity ranking.
Reviewers: bkramer
Subscribers: cfe-commits, hokein, djasper
Differential Revision: http://reviews.llvm.org/D20804
Modified:
clang-tools-extra/trunk/include-fixer/find-all-symbols/SymbolInfo.cpp
clang-tools-extra/trunk/include-fixer/find-all-symbols/SymbolInfo.h
clang-tools-extra/trunk/include-fixer/find-all-symbols/tool/FindAllSymbolsMain.cpp
clang-tools-extra/trunk/test/include-fixer/Inputs/fake_yaml_db.yaml
Modified: clang-tools-extra/trunk/include-fixer/find-all-symbols/SymbolInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/include-fixer/find-all-symbols/SymbolInfo.cpp?rev=271268&r1=271267&r2=271268&view=diff
==============================================================================
--- clang-tools-extra/trunk/include-fixer/find-all-symbols/SymbolInfo.cpp (original)
+++ clang-tools-extra/trunk/include-fixer/find-all-symbols/SymbolInfo.cpp Tue May 31 07:01:48 2016
@@ -33,6 +33,7 @@ template <> struct MappingTraits<SymbolI
io.mapRequired("FilePath", Symbol.FilePath);
io.mapRequired("LineNumber", Symbol.LineNumber);
io.mapRequired("Type", Symbol.Type);
+ io.mapRequired("NumOccurrences", Symbol.NumOccurrences);
}
};
@@ -72,9 +73,10 @@ namespace find_all_symbols {
SymbolInfo::SymbolInfo(llvm::StringRef Name, SymbolKind Type,
llvm::StringRef FilePath, int LineNumber,
- const std::vector<Context> &Contexts)
+ const std::vector<Context> &Contexts,
+ unsigned NumOccurrences)
: Name(Name), Type(Type), FilePath(FilePath), Contexts(Contexts),
- LineNumber(LineNumber) {}
+ LineNumber(LineNumber), NumOccurrences(NumOccurrences) {}
llvm::StringRef SymbolInfo::getName() const { return Name; }
@@ -88,6 +90,8 @@ const std::vector<SymbolInfo::Context> &
int SymbolInfo::getLineNumber() const { return LineNumber; }
+unsigned SymbolInfo::getNumOccurrences() const { return NumOccurrences; }
+
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,
Modified: clang-tools-extra/trunk/include-fixer/find-all-symbols/SymbolInfo.h
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/include-fixer/find-all-symbols/SymbolInfo.h?rev=271268&r1=271267&r2=271268&view=diff
==============================================================================
--- clang-tools-extra/trunk/include-fixer/find-all-symbols/SymbolInfo.h (original)
+++ clang-tools-extra/trunk/include-fixer/find-all-symbols/SymbolInfo.h Tue May 31 07:01:48 2016
@@ -51,7 +51,8 @@ public:
SymbolInfo() : Type(SymbolKind::Unknown), LineNumber(-1) {}
SymbolInfo(llvm::StringRef Name, SymbolKind Type, llvm::StringRef FilePath,
- int LineNumber, const std::vector<Context> &Contexts);
+ int LineNumber, const std::vector<Context> &Contexts,
+ unsigned NumOccurrences = 0);
/// \brief Get symbol name.
llvm::StringRef getName() const;
@@ -68,6 +69,9 @@ public:
/// \brief Get a 1-based line number of the symbol's declaration.
int getLineNumber() const;
+ /// \brief The number of times this symbol was found during an indexing run.
+ unsigned getNumOccurrences() const;
+
bool operator<(const SymbolInfo &Symbol) const;
bool operator==(const SymbolInfo &Symbol) const;
@@ -99,6 +103,10 @@ private:
/// \brief The 1-based line number of of the symbol's declaration.
int LineNumber;
+
+ /// \brief The number of times this symbol was found during an indexing
+ /// run. Populated by the reducer and used to rank results.
+ unsigned NumOccurrences;
};
/// \brief Write SymbolInfos to a stream (YAML format).
Modified: clang-tools-extra/trunk/include-fixer/find-all-symbols/tool/FindAllSymbolsMain.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/include-fixer/find-all-symbols/tool/FindAllSymbolsMain.cpp?rev=271268&r1=271267&r2=271268&view=diff
==============================================================================
--- clang-tools-extra/trunk/include-fixer/find-all-symbols/tool/FindAllSymbolsMain.cpp (original)
+++ clang-tools-extra/trunk/include-fixer/find-all-symbols/tool/FindAllSymbolsMain.cpp Tue May 31 07:01:48 2016
@@ -87,12 +87,13 @@ private:
bool Merge(llvm::StringRef MergeDir, llvm::StringRef OutputFile) {
std::error_code EC;
- std::set<SymbolInfo> UniqueSymbols;
+ std::map<SymbolInfo, int> SymbolToNumOccurrences;
std::mutex SymbolMutex;
auto AddSymbols = [&](ArrayRef<SymbolInfo> Symbols) {
// Synchronize set accesses.
std::unique_lock<std::mutex> LockGuard(SymbolMutex);
- UniqueSymbols.insert(Symbols.begin(), Symbols.end());
+ for (const auto &Symbol : Symbols)
+ ++SymbolToNumOccurrences[Symbol];
};
// Load all symbol files in MergeDir.
@@ -123,7 +124,14 @@ bool Merge(llvm::StringRef MergeDir, llv
<< '\n';
return false;
}
- WriteSymbolInfosToStream(OS, UniqueSymbols);
+ std::set<SymbolInfo> Result;
+ for (const auto &Entry : SymbolToNumOccurrences) {
+ const auto &Symbol = Entry.first;
+ Result.insert(SymbolInfo(Symbol.getName(), Symbol.getSymbolKind(),
+ Symbol.getFilePath(), Symbol.getLineNumber(),
+ Symbol.getContexts(), Entry.second));
+ }
+ WriteSymbolInfosToStream(OS, Result);
return true;
}
Modified: clang-tools-extra/trunk/test/include-fixer/Inputs/fake_yaml_db.yaml
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/include-fixer/Inputs/fake_yaml_db.yaml?rev=271268&r1=271267&r2=271268&view=diff
==============================================================================
--- clang-tools-extra/trunk/test/include-fixer/Inputs/fake_yaml_db.yaml (original)
+++ clang-tools-extra/trunk/test/include-fixer/Inputs/fake_yaml_db.yaml Tue May 31 07:01:48 2016
@@ -8,6 +8,7 @@ Contexts:
FilePath: foo.h
LineNumber: 1
Type: Class
+NumOccurrences: 1
...
---
Name: bar
@@ -19,4 +20,5 @@ Contexts:
FilePath: ../include/bar.h
LineNumber: 1
Type: Class
+NumOccurrences: 1
...
More information about the cfe-commits
mailing list