14#ifndef LLVM_CLANG_SEMA_SEMAINTERNAL_H
15#define LLVM_CLANG_SEMA_SEMAINTERNAL_H
28 cast<ParmVarDecl>(FTI.
Params[0].
Param)->getType()->isVoidType();
41 if (!LangOpts.CUDA || !
D)
43 bool isDeviceSideDecl =
D->
hasAttr<CUDADeviceAttr>() ||
46 return isDeviceSideDecl == LangOpts.CUDAIsDevice;
52 "A declaration cannot be both dllimport and dllexport.");
53 if (
auto *Import =
D->
getAttr<DLLImportAttr>())
55 if (
auto *Export =
D->
getAttr<DLLExportAttr>())
62 if (
const auto *TTP = dyn_cast<TemplateTypeParmDecl>(ND))
63 return std::make_pair(TTP->getDepth(), TTP->getIndex());
65 if (
const auto *NTTP = dyn_cast<NonTypeTemplateParmDecl>(ND))
66 return std::make_pair(NTTP->getDepth(), NTTP->getIndex());
68 const auto *TTP = cast<TemplateTemplateParmDecl>(ND);
69 return std::make_pair(TTP->getDepth(), TTP->getIndex());
73inline std::pair<unsigned, unsigned>
76 return std::make_pair(TTP->getDepth(), TTP->getIndex());
83 typedef llvm::StringMap<TypoResultList> TypoResultsMap;
84 typedef std::map<unsigned, TypoResultsMap> TypoEditDistanceMap;
91 std::unique_ptr<CorrectionCandidateCallback> CCC,
94 : Typo(TypoName.
getName().getAsIdentifierInfo()), CurrentTCIndex(0),
95 SavedTCIndex(0), SemaRef(SemaRef), S(S),
97 CorrectionValidator(
std::move(CCC)), MemberContext(MemberContext),
98 Result(SemaRef, TypoName, LookupKind),
99 Namespaces(SemaRef.Context, SemaRef.CurContext, SS),
100 EnteringContext(EnteringContext), SearchNamespaces(
false) {
110 bool InBaseClass)
override;
116 return CorrectionResults.empty() && ValidatedCorrections.size() == 1;
122 return CorrectionResults.begin()->second[Name];
128 if (CorrectionResults.empty())
129 return (std::numeric_limits<unsigned>::max)();
131 unsigned BestED = CorrectionResults.begin()->first;
140 addNamespaces(
const llvm::MapVector<NamespaceDecl *, bool> &KnownNamespaces);
151 return CurrentTCIndex < ValidatedCorrections.size()
152 ? ValidatedCorrections[CurrentTCIndex]
153 : ValidatedCorrections[0];
161 auto Current = CurrentTCIndex;
163 CurrentTCIndex = Current;
182 return CorrectionResults.empty() &&
183 CurrentTCIndex >= ValidatedCorrections.size();
189 SavedTCIndex = CurrentTCIndex;
194 CurrentTCIndex = SavedTCIndex;
204 return CorrectionValidator.get();
208 class NamespaceSpecifierSet {
209 struct SpecifierInfo {
212 unsigned EditDistance;
215 typedef SmallVector<DeclContext*, 4> DeclContextList;
216 typedef SmallVector<SpecifierInfo, 16> SpecifierInfoList;
219 DeclContextList CurContextChain;
220 std::string CurNameSpecifier;
221 SmallVector<const IdentifierInfo*, 4> CurContextIdentifiers;
222 SmallVector<const IdentifierInfo*, 4> CurNameSpecifierIdentifiers;
224 std::map<unsigned, SpecifierInfoList> DistanceMap;
228 static DeclContextList buildContextChain(DeclContext *Start);
230 unsigned buildNestedNameSpecifier(DeclContextList &DeclChain,
231 NestedNameSpecifier *&NNS);
234 NamespaceSpecifierSet(ASTContext &Context, DeclContext *CurContext,
235 CXXScopeSpec *CurScopeSpec);
239 void addNameSpecifier(DeclContext *Ctx);
243 :
public llvm::iterator_facade_base<iterator, std::forward_iterator_tag,
246 const std::map<unsigned, SpecifierInfoList>::iterator OuterBack;
248 std::map<unsigned, SpecifierInfoList>::iterator Outer;
250 SpecifierInfoList::iterator Inner;
254 : OuterBack(
std::prev(
Set.DistanceMap.end())),
255 Outer(
Set.DistanceMap.begin()),
256 Inner(!IsAtEnd ? Outer->second.begin() : OuterBack->second.end()) {
257 assert(!
Set.DistanceMap.empty());
262 if (Inner == Outer->second.end() && Outer != OuterBack) {
264 Inner = Outer->second.begin();
273 iterator begin() {
return iterator(*
this,
false); }
274 iterator end() {
return iterator(*
this,
true); }
277 void addName(StringRef Name, NamedDecl *ND,
278 NestedNameSpecifier *NNS =
nullptr,
bool isKeyword =
false);
283 bool resolveCorrection(TypoCorrection &Candidate);
289 void performQualifiedLookups();
292 IdentifierInfo *Typo;
299 TypoEditDistanceMap CorrectionResults;
301 SmallVector<TypoCorrection, 4> ValidatedCorrections;
302 size_t CurrentTCIndex;
307 std::unique_ptr<CXXScopeSpec> SS;
308 std::unique_ptr<CorrectionCandidateCallback> CorrectionValidator;
309 DeclContext *MemberContext;
311 NamespaceSpecifierSet Namespaces;
312 SmallVector<TypoCorrection, 2> QualifiedResults;
313 bool EnteringContext;
314 bool SearchNamespaces;
320 *
this = std::move(other);
325 Consumer = std::move(other.Consumer);
326 DiagHandler = std::move(other.DiagHandler);
327 RecoveryHandler = std::move(other.RecoveryHandler);
Defines the clang::ASTContext interface.
static std::string getName(const CallEvent &Call)
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Represents a C++ nested-name-specifier or a global scope specifier.
Base class for callback objects used by Sema::CorrectTypo to check the validity of a potential typo c...
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Decl - This represents one declaration (or definition), e.g.
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Represents the results of name lookup.
void suppressDiagnostics()
Suppress the diagnostics that would normally fire because of this lookup.
This represents a decl that may have a name.
Represents a C++ nested name specifier, such as "\::std::vector<int>::".
Scope - A scope is a transient data structure that is used while parsing the program.
Sema - This implements semantic analysis and AST building for C.
LookupNameKind
Describes the kind of name lookup to perform.
Provides flat iteration over specifiers, sorted by distance.
SpecifierInfo & operator*()
iterator(NamespaceSpecifierSet &Set, bool IsAtEnd)
bool operator==(const iterator &RHS) const
void resetCorrectionStream()
Reset the consumer's position in the stream of viable corrections (i.e.
bool isAddressOfOperand() const
void addKeywordResult(StringRef Keyword)
void restoreSavedPosition()
Restore the saved position in the correction stream.
const LookupResult & getLookupResult() const
void addCorrection(TypoCorrection Correction)
const TypoCorrection & getCurrentCorrection()
Get the last correction returned by getNextCorrection().
void saveCurrentPosition()
Save the current position in the correction stream (overwriting any previously saved position).
const CXXScopeSpec * getSS() const
TypoCorrectionConsumer(Sema &SemaRef, const DeclarationNameInfo &TypoName, Sema::LookupNameKind LookupKind, Scope *S, CXXScopeSpec *SS, std::unique_ptr< CorrectionCandidateCallback > CCC, DeclContext *MemberContext, bool EnteringContext)
const TypoCorrection & peekNextCorrection()
Return the next typo correction like getNextCorrection, but keep the internal state pointed to the cu...
bool includeHiddenDecls() const override
Determine whether hidden declarations (from unimported modules) should be given to this consumer.
bool finished()
Return whether the end of the stream of corrections has been reached.
unsigned getBestEditDistance(bool Normalized)
Return the edit distance of the corrections that have the closest/best edit distance from the origina...
bool hasMadeAnyCorrectionProgress() const
In the case of deeply invalid expressions, getNextCorrection() will never be called since the transfo...
const TypoCorrection & getNextCorrection()
Return the next typo correction that passes all internal filters and is deemed valid by the consumer'...
TypoResultList & operator[](StringRef Name)
Return the list of TypoCorrections for the given identifier from the set of corrections that have the...
ASTContext & getContext() const
void FoundName(StringRef Name)
void addNamespaces(const llvm::MapVector< NamespaceDecl *, bool > &KnownNamespaces)
Set-up method to add to the consumer the set of namespaces to use in performing corrections to nested...
CorrectionCandidateCallback * getCorrectionValidator() const
Simple class containing the result of Sema::CorrectTypo.
static unsigned NormalizeEditDistance(unsigned ED)
Consumes visible declarations found when searching for all visible names within a given scope or cont...
The JSON file list parser is used to communicate input to InstallAPI.
bool FTIHasNonVoidParameters(const DeclaratorChunk::FunctionTypeInfo &FTI)
bool DeclAttrsMatchCUDAMode(const LangOptions &LangOpts, Decl *D)
bool FTIHasSingleVoidParameter(const DeclaratorChunk::FunctionTypeInfo &FTI)
InheritableAttr * getDLLAttr(Decl *D)
Return a DLL attribute from the declaration.
std::pair< unsigned, unsigned > getDepthAndIndex(NamedDecl *ND)
Retrieve the depth and index of a template parameter.
std::pair< llvm::PointerUnion< const TemplateTypeParmType *, NamedDecl * >, SourceLocation > UnexpandedParameterPack
DeclarationNameInfo - A collector data type for bundling together a DeclarationName and the correspon...
unsigned isVariadic
isVariadic - If this function has a prototype, and if that proto ends with ',...)',...
ParamInfo * Params
Params - This is a pointer to a new[]'d array of ParamInfo objects that describe the parameters speci...
unsigned NumParams
NumParams - This is the number of formal parameters specified by the declarator.
const IdentifierInfo * Ident
TypoExprState & operator=(TypoExprState &&other) noexcept