Mercurial > hg > CbC > CbC_llvm
comparison clang-tools-extra/clangd/Quality.h @ 221:79ff65ed7e25
LLVM12 Original
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 15 Jun 2021 19:15:29 +0900 |
parents | 1d019706d866 |
children | c4bab56944e8 |
comparison
equal
deleted
inserted
replaced
220:42394fc6a535 | 221:79ff65ed7e25 |
---|---|
27 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_QUALITY_H | 27 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_QUALITY_H |
28 #define LLVM_CLANG_TOOLS_EXTRA_CLANGD_QUALITY_H | 28 #define LLVM_CLANG_TOOLS_EXTRA_CLANGD_QUALITY_H |
29 | 29 |
30 #include "ExpectedTypes.h" | 30 #include "ExpectedTypes.h" |
31 #include "FileDistance.h" | 31 #include "FileDistance.h" |
32 #include "TUScheduler.h" | |
32 #include "clang/Sema/CodeCompleteConsumer.h" | 33 #include "clang/Sema/CodeCompleteConsumer.h" |
33 #include "llvm/ADT/ArrayRef.h" | 34 #include "llvm/ADT/ArrayRef.h" |
34 #include "llvm/ADT/StringRef.h" | 35 #include "llvm/ADT/StringRef.h" |
35 #include "llvm/ADT/StringSet.h" | 36 #include "llvm/ADT/StringSet.h" |
36 #include <algorithm> | 37 #include <algorithm> |
76 | 77 |
77 void merge(const CodeCompletionResult &SemaCCResult); | 78 void merge(const CodeCompletionResult &SemaCCResult); |
78 void merge(const Symbol &IndexResult); | 79 void merge(const Symbol &IndexResult); |
79 | 80 |
80 // Condense these signals down to a single number, higher is better. | 81 // Condense these signals down to a single number, higher is better. |
81 float evaluate() const; | 82 float evaluateHeuristics() const; |
82 }; | 83 }; |
83 llvm::raw_ostream &operator<<(llvm::raw_ostream &, | 84 llvm::raw_ostream &operator<<(llvm::raw_ostream &, |
84 const SymbolQualitySignals &); | 85 const SymbolQualitySignals &); |
85 | 86 |
86 /// Attributes of a symbol-query pair that affect how much we like it. | 87 /// Attributes of a symbol-query pair that affect how much we like it. |
134 // Whether a source completion item or a symbol had a type information. | 135 // Whether a source completion item or a symbol had a type information. |
135 bool HadSymbolType = false; | 136 bool HadSymbolType = false; |
136 // Whether the item matches the type expected in the completion context. | 137 // Whether the item matches the type expected in the completion context. |
137 bool TypeMatchesPreferred = false; | 138 bool TypeMatchesPreferred = false; |
138 | 139 |
140 /// Length of the unqualified partial name of Symbol typed in | |
141 /// CompletionPrefix. | |
142 unsigned FilterLength = 0; | |
143 | |
144 const ASTSignals *MainFileSignals = nullptr; | |
145 /// Number of references to the candidate in the main file. | |
146 unsigned MainFileRefs = 0; | |
147 /// Number of unique symbols in the main file which belongs to candidate's | |
148 /// namespace. This indicates how relevant the namespace is in the current | |
149 /// file. | |
150 unsigned ScopeRefsInFile = 0; | |
151 | |
152 /// Set of derived signals computed by calculateDerivedSignals(). Must not be | |
153 /// set explicitly. | |
154 struct DerivedSignals { | |
155 /// Whether Name contains some word from context. | |
156 bool NameMatchesContext = false; | |
157 /// Min distance between SymbolURI and all the headers included by the TU. | |
158 unsigned FileProximityDistance = FileDistance::Unreachable; | |
159 /// Min distance between SymbolScope and all the available scopes. | |
160 unsigned ScopeProximityDistance = FileDistance::Unreachable; | |
161 }; | |
162 | |
163 DerivedSignals calculateDerivedSignals() const; | |
164 | |
139 void merge(const CodeCompletionResult &SemaResult); | 165 void merge(const CodeCompletionResult &SemaResult); |
140 void merge(const Symbol &IndexResult); | 166 void merge(const Symbol &IndexResult); |
167 void computeASTSignals(const CodeCompletionResult &SemaResult); | |
141 | 168 |
142 // Condense these signals down to a single number, higher is better. | 169 // Condense these signals down to a single number, higher is better. |
143 float evaluate() const; | 170 float evaluateHeuristics() const; |
144 }; | 171 }; |
145 llvm::raw_ostream &operator<<(llvm::raw_ostream &, | 172 llvm::raw_ostream &operator<<(llvm::raw_ostream &, |
146 const SymbolRelevanceSignals &); | 173 const SymbolRelevanceSignals &); |
147 | 174 |
148 /// Combine symbol quality and relevance into a single score. | 175 /// Combine symbol quality and relevance into a single score. |
149 float evaluateSymbolAndRelevance(float SymbolQuality, float SymbolRelevance); | 176 float evaluateSymbolAndRelevance(float SymbolQuality, float SymbolRelevance); |
177 | |
178 /// Same semantics as CodeComplete::Score. Quality score and Relevance score | |
179 /// have been removed since DecisionForest cannot assign individual scores to | |
180 /// Quality and Relevance signals. | |
181 struct DecisionForestScores { | |
182 float Total = 0.f; | |
183 float ExcludingName = 0.f; | |
184 }; | |
185 | |
186 DecisionForestScores | |
187 evaluateDecisionForest(const SymbolQualitySignals &Quality, | |
188 const SymbolRelevanceSignals &Relevance, float Base); | |
150 | 189 |
151 /// TopN<T> is a lossy container that preserves only the "best" N elements. | 190 /// TopN<T> is a lossy container that preserves only the "best" N elements. |
152 template <typename T, typename Compare = std::greater<T>> class TopN { | 191 template <typename T, typename Compare = std::greater<T>> class TopN { |
153 public: | 192 public: |
154 using value_type = T; | 193 using value_type = T; |