diff options
4 files changed, 28 insertions, 6 deletions
diff --git a/clang-tools-extra/include-fixer/find-all-symbols/SymbolInfo.cpp b/clang-tools-extra/include-fixer/find-all-symbols/SymbolInfo.cpp index dfe624a..b5a8a73 100644 --- a/clang-tools-extra/include-fixer/find-all-symbols/SymbolInfo.cpp +++ b/clang-tools-extra/include-fixer/find-all-symbols/SymbolInfo.cpp @@ -33,6 +33,7 @@ template <> struct MappingTraits<SymbolInfo> { 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> &SymbolInfo::getContexts() const { 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, diff --git a/clang-tools-extra/include-fixer/find-all-symbols/SymbolInfo.h b/clang-tools-extra/include-fixer/find-all-symbols/SymbolInfo.h index 34d9e10..c5b6999 100644 --- a/clang-tools-extra/include-fixer/find-all-symbols/SymbolInfo.h +++ b/clang-tools-extra/include-fixer/find-all-symbols/SymbolInfo.h @@ -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). diff --git a/clang-tools-extra/include-fixer/find-all-symbols/tool/FindAllSymbolsMain.cpp b/clang-tools-extra/include-fixer/find-all-symbols/tool/FindAllSymbolsMain.cpp index a529adc..08a869f 100644 --- a/clang-tools-extra/include-fixer/find-all-symbols/tool/FindAllSymbolsMain.cpp +++ b/clang-tools-extra/include-fixer/find-all-symbols/tool/FindAllSymbolsMain.cpp @@ -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, llvm::StringRef OutputFile) { << '\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; } diff --git a/clang-tools-extra/test/include-fixer/Inputs/fake_yaml_db.yaml b/clang-tools-extra/test/include-fixer/Inputs/fake_yaml_db.yaml index fb0e668..7e60fc2 100644 --- a/clang-tools-extra/test/include-fixer/Inputs/fake_yaml_db.yaml +++ b/clang-tools-extra/test/include-fixer/Inputs/fake_yaml_db.yaml @@ -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 ... |
