clang: include/clang/Sema/TypoCorrection.h Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
13
14#ifndef LLVM_CLANG_SEMA_TYPOCORRECTION_H
15#define LLVM_CLANG_SEMA_TYPOCORRECTION_H
16
23#include "llvm/ADT/ArrayRef.h"
24#include "llvm/ADT/SmallVector.h"
25#include "llvm/Support/Casting.h"
26#include
27#include
28#include
29#include
30#include
31
33
34class DeclContext;
35class IdentifierInfo;
36class LangOptions;
37class MemberExpr;
38class NestedNameSpecifier;
39class Sema;
40
41
43public:
44
45 static const unsigned InvalidDistance = std::numeric_limits::max();
46
47
48
50
51
52
53
54
58
61 unsigned QualifierDistance = 0)
62 : CorrectionName(Name), CorrectionNameSpec(NNS),
63 CharDistance(CharDistance), QualifierDistance(QualifierDistance) {
64 if (NameDecl)
65 CorrectionDecls.push_back(NameDecl);
66 }
67
69 unsigned CharDistance = 0)
70 : CorrectionName(Name->getDeclName()), CorrectionNameSpec(NNS),
71 CharDistance(CharDistance) {
72 if (Name)
73 CorrectionDecls.push_back(Name);
74 }
75
77 unsigned CharDistance = 0)
78 : CorrectionName(Name), CorrectionNameSpec(NNS),
79 CharDistance(CharDistance) {}
80
82
83
85
88 }
89
90
92 return CorrectionNameSpec;
93 }
94
96 CorrectionNameSpec = NNS;
97 ForceSpecifierReplacement = (NNS != nullptr);
98 }
99
101 ForceSpecifierReplacement = ForceReplacement;
102 }
103
105 return ForceSpecifierReplacement;
106 }
107
109 QualifierDistance = ED;
110 }
111
113 CallbackDistance = ED;
114 }
115
116
117
118
123 }
124
125
126
127
132 unsigned ED =
138
139
140
142 }
143
144
145
147 return hasCorrectionDecl() ? *(CorrectionDecls.begin()) : nullptr;
148 }
149
150
153 return D ? D->getUnderlyingDecl() : nullptr;
154 }
155 template
158 }
159
160
162 CorrectionDecls.clear();
163 }
164
165
167 CorrectionDecls.clear();
169 }
170
171
173 CorrectionDecls.clear();
174 CorrectionDecls.insert(CorrectionDecls.begin(), Decls.begin(), Decls.end());
175 }
176
177
178
180
182
185 }
186
187
188 explicit operator bool() const { return bool(CorrectionName); }
189
190
191
192
193
195 CorrectionDecls.clear();
196 CorrectionDecls.push_back(nullptr);
197 ForceSpecifierReplacement = true;
198 }
199
200
201
203 return !CorrectionDecls.empty() && CorrectionDecls.front() == nullptr;
204 }
205
206
207 template<std::size_t StrLen>
208 bool isKeyword(const char (&Str)[StrLen]) const {
210 }
211
212
213 bool isResolved() const { return !CorrectionDecls.empty(); }
214
216 return CorrectionDecls.size() > 1;
217 }
218
222 if (ForceSpecifierReplacement && SS && !SS->isEmpty())
224 }
225
227 return CorrectionRange;
228 }
229
231
233 return isKeyword() ? CorrectionDecls.end() : CorrectionDecls.begin();
234 }
235
237
239
241 return isKeyword() ? CorrectionDecls.end() : CorrectionDecls.begin();
242 }
243
245
246
247
250
251
252
254 ExtraDiagnostics.push_back(std::move(PD));
255 }
257 return ExtraDiagnostics;
258 }
259
260private:
261 bool hasCorrectionDecl() const {
262 return (() && !CorrectionDecls.empty());
263 }
264
265
266 DeclarationName CorrectionName;
267 NestedNameSpecifier *CorrectionNameSpec = nullptr;
268 SmallVector<NamedDecl *, 1> CorrectionDecls;
269 unsigned CharDistance = 0;
270 unsigned QualifierDistance = 0;
271 unsigned CallbackDistance = 0;
272 SourceRange CorrectionRange;
273 bool ForceSpecifierReplacement = false;
274 bool RequiresImport = false;
275
276 std::vector ExtraDiagnostics;
277};
278
279
280
282public:
284
288
290
291
292
293
294
295
296
297
298
299
300
302
303
304
305
306
307
308
311 ? 0
313 }
314
315
316
317
318
319
320 virtual std::unique_ptr clone() = 0;
321
324
325
326
327
334
335
338
339protected:
343
344
346 }
347
350};
351
353public:
357
358 std::unique_ptr clone() override {
359 return std::make_unique(*this);
360 }
361};
362
363
364
365template
367public:
371
374 }
375 std::unique_ptr clone() override {
376 return std::make_unique(*this);
377 }
378};
379
380
381
382
384public:
386 bool HasExplicitTemplateArgs,
388
390 std::unique_ptr clone() override {
391 return std::make_unique(*this);
392 }
393
394private:
395 unsigned NumArgs;
396 bool HasExplicitTemplateArgs;
399};
400
401
403public:
410 }
411
413 return false;
414 }
415 std::unique_ptr clone() override {
416 return std::make_unique(*this);
417 }
418};
419
420}
421
422#endif
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified.
Implements a partial diagnostic that can be emitted anwyhere in a DiagnosticBuilder stream.
Defines the clang::SourceLocation class and associated facilities.
Represents a C++ nested-name-specifier or a global scope specifier.
SourceLocation getBeginLoc() const
bool isEmpty() const
No scope specifier.
Base class for callback objects used by Sema::CorrectTypo to check the validity of a potential typo c...
bool WantExpressionKeywords
void setTypoName(const IdentifierInfo *II)
virtual unsigned RankCandidate(const TypoCorrection &candidate)
Method used by Sema::CorrectTypo to assign an "edit distance" rank to a candidate (where a lower valu...
NestedNameSpecifier * TypoNNS
virtual bool ValidateCandidate(const TypoCorrection &candidate)
Simple predicate used by the default RankCandidate to determine whether to return an edit distance of...
const IdentifierInfo * Typo
bool MatchesTypo(const TypoCorrection &candidate)
bool WantFunctionLikeCasts
virtual ~CorrectionCandidateCallback()=default
CorrectionCandidateCallback(const IdentifierInfo *Typo=nullptr, NestedNameSpecifier *TypoNNS=nullptr)
void setTypoNNS(NestedNameSpecifier *NNS)
static const unsigned InvalidDistance
bool WantRemainingKeywords
virtual std::unique_ptr< CorrectionCandidateCallback > clone()=0
Clone this CorrectionCandidateCallback.
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Simple template class for restricting typo correction candidates to ones having a single Decl* of the...
DeclFilterCCC(const IdentifierInfo *Typo=nullptr, NestedNameSpecifier *TypoNNS=nullptr)
std::unique_ptr< CorrectionCandidateCallback > clone() override
Clone this CorrectionCandidateCallback.
bool ValidateCandidate(const TypoCorrection &candidate) override
Simple predicate used by the default RankCandidate to determine whether to return an edit distance of...
The name of a declaration.
IdentifierInfo * getAsIdentifierInfo() const
Retrieve the IdentifierInfo * stored in this declaration name, or null if this declaration name isn't...
std::unique_ptr< CorrectionCandidateCallback > clone() override
Clone this CorrectionCandidateCallback.
DefaultFilterCCC(const IdentifierInfo *Typo=nullptr, NestedNameSpecifier *TypoNNS=nullptr)
bool ValidateCandidate(const TypoCorrection &candidate) override
Simple predicate used by the default RankCandidate to determine whether to return an edit distance of...
std::unique_ptr< CorrectionCandidateCallback > clone() override
Clone this CorrectionCandidateCallback.
One of these records is kept for each identifier that is lexed.
bool isStr(const char(&Str)[StrLen]) const
Return true if this is the identifier for the specified string.
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
MemberExpr - [C99 6.5.2.3] Structure and Union Members.
This represents a decl that may have a name.
Represents a C++ nested name specifier, such as "\::std::vector::".
std::unique_ptr< CorrectionCandidateCallback > clone() override
Clone this CorrectionCandidateCallback.
bool ValidateCandidate(const TypoCorrection &candidate) override
Simple predicate used by the default RankCandidate to determine whether to return an edit distance of...
Sema - This implements semantic analysis and AST building for C.
A trivial tuple used to represent a source range.
void setBegin(SourceLocation b)
Simple class containing the result of Sema::CorrectTypo.
IdentifierInfo * getCorrectionAsIdentifierInfo() const
TypoCorrection(DeclarationName Name, NestedNameSpecifier *NNS=nullptr, unsigned CharDistance=0)
TypoCorrection(const DeclarationName &Name, NamedDecl *NameDecl, NestedNameSpecifier *NNS=nullptr, unsigned CharDistance=0, unsigned QualifierDistance=0)
void setCorrectionSpecifier(NestedNameSpecifier *NNS)
ArrayRef< PartialDiagnostic > getExtraDiagnostics() const
static const unsigned InvalidDistance
void addCorrectionDecl(NamedDecl *CDecl)
Add the given NamedDecl to the list of NamedDecls that are the declarations associated with the Decla...
TypoCorrection(NamedDecl *Name, NestedNameSpecifier *NNS=nullptr, unsigned CharDistance=0)
void setCorrectionDecls(ArrayRef< NamedDecl * > Decls)
Clears the list of NamedDecls and adds the given set.
std::string getAsString(const LangOptions &LO) const
static const unsigned MaximumDistance
bool requiresImport() const
Returns whether this typo correction is correcting to a declaration that was declared in a module tha...
const_decl_iterator begin() const
void setCorrectionRange(CXXScopeSpec *SS, const DeclarationNameInfo &TypoName)
NamedDecl * getCorrectionDecl() const
Gets the pointer to the declaration of the typo correction.
bool isKeyword(const char(&Str)[StrLen]) const
SourceRange getCorrectionRange() const
void setQualifierDistance(unsigned ED)
void WillReplaceSpecifier(bool ForceReplacement)
void setCallbackDistance(unsigned ED)
SmallVectorImpl< NamedDecl * >::const_iterator const_decl_iterator
static unsigned NormalizeEditDistance(unsigned ED)
DeclClass * getCorrectionDeclAs() const
const_decl_iterator end() const
DeclarationName getCorrection() const
Gets the DeclarationName of the typo correction.
unsigned getEditDistance(bool Normalized=true) const
Gets the "edit distance" of the typo correction from the typo.
void ClearCorrectionDecls()
Clears the list of NamedDecls.
static const unsigned CallbackDistanceWeight
NestedNameSpecifier * getCorrectionSpecifier() const
Gets the NestedNameSpecifier needed to use the typo correction.
static const unsigned QualifierDistanceWeight
SmallVectorImpl< NamedDecl * >::iterator decl_iterator
void setCorrectionDecl(NamedDecl *CDecl)
Clears the list of NamedDecls before adding the new one.
void setRequiresImport(bool Req)
std::string getQuoted(const LangOptions &LO) const
bool isOverloaded() const
static const unsigned CharDistanceWeight
bool WillReplaceSpecifier() const
NamedDecl * getFoundDecl() const
Get the correction declaration found by name lookup (before we looked through using shadow declaratio...
void addExtraDiagnostic(PartialDiagnostic PD)
Extra diagnostics are printed after the first diagnostic for the typo.
void makeKeyword()
Mark this TypoCorrection as being a keyword.
The JSON file list parser is used to communicate input to InstallAPI.
DeclarationNameInfo - A collector data type for bundling together a DeclarationName and the correspon...
SourceRange getSourceRange() const LLVM_READONLY
getSourceRange - The range of the declaration name.