Index: clang-tools-extra/trunk/include-fixer/find-all-symbols/SymbolInfo.h =================================================================== --- clang-tools-extra/trunk/include-fixer/find-all-symbols/SymbolInfo.h +++ clang-tools-extra/trunk/include-fixer/find-all-symbols/SymbolInfo.h @@ -51,7 +51,8 @@ SymbolInfo() : Type(SymbolKind::Unknown), LineNumber(-1) {} SymbolInfo(llvm::StringRef Name, SymbolKind Type, llvm::StringRef FilePath, - int LineNumber, const std::vector &Contexts); + int LineNumber, const std::vector &Contexts, + unsigned NumOccurrences = 0); /// \brief Get symbol name. llvm::StringRef getName() const; @@ -68,6 +69,9 @@ /// \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 @@ /// \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). Index: clang-tools-extra/trunk/include-fixer/find-all-symbols/SymbolInfo.cpp =================================================================== --- clang-tools-extra/trunk/include-fixer/find-all-symbols/SymbolInfo.cpp +++ clang-tools-extra/trunk/include-fixer/find-all-symbols/SymbolInfo.cpp @@ -33,6 +33,7 @@ io.mapRequired("FilePath", Symbol.FilePath); io.mapRequired("LineNumber", Symbol.LineNumber); io.mapRequired("Type", Symbol.Type); + io.mapRequired("NumOccurrences", Symbol.NumOccurrences); } }; @@ -72,9 +73,10 @@ SymbolInfo::SymbolInfo(llvm::StringRef Name, SymbolKind Type, llvm::StringRef FilePath, int LineNumber, - const std::vector &Contexts) + const std::vector &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 @@ 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, Index: clang-tools-extra/trunk/include-fixer/find-all-symbols/tool/FindAllSymbolsMain.cpp =================================================================== --- clang-tools-extra/trunk/include-fixer/find-all-symbols/tool/FindAllSymbolsMain.cpp +++ clang-tools-extra/trunk/include-fixer/find-all-symbols/tool/FindAllSymbolsMain.cpp @@ -87,12 +87,13 @@ bool Merge(llvm::StringRef MergeDir, llvm::StringRef OutputFile) { std::error_code EC; - std::set UniqueSymbols; + std::map SymbolToNumOccurrences; std::mutex SymbolMutex; auto AddSymbols = [&](ArrayRef Symbols) { // Synchronize set accesses. std::unique_lock 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 @@ << '\n'; return false; } - WriteSymbolInfosToStream(OS, UniqueSymbols); + std::set 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; } Index: clang-tools-extra/trunk/test/include-fixer/Inputs/fake_yaml_db.yaml =================================================================== --- clang-tools-extra/trunk/test/include-fixer/Inputs/fake_yaml_db.yaml +++ clang-tools-extra/trunk/test/include-fixer/Inputs/fake_yaml_db.yaml @@ -8,6 +8,7 @@ FilePath: foo.h LineNumber: 1 Type: Class +NumOccurrences: 1 ... --- Name: bar @@ -19,4 +20,5 @@ FilePath: ../include/bar.h LineNumber: 1 Type: Class +NumOccurrences: 1 ...