15 #ifndef LLVM_CLANG_SEMA_SEMAINTERNAL_H
16 #define LLVM_CLANG_SEMA_SEMAINTERNAL_H
33 cast<ParmVarDecl>(FTI.
Params[0].
Param)->getType()->isVoidType();
46 return !isa<ParmVarDecl>(Var) &&
55 if (!LangOpts.CUDA || !D)
57 bool isDeviceSideDecl = D->
hasAttr<CUDADeviceAttr>() ||
60 return isDeviceSideDecl == LangOpts.CUDAIsDevice;
72 const unsigned *
const FunctionScopeIndexToStopAt) {
85 CaptureType, DeclRefType,
86 FunctionScopeIndexToStopAt);
93 assert(!(D->
hasAttr<DLLImportAttr>() && D->
hasAttr<DLLExportAttr>()) &&
94 "A declaration cannot be both dllimport and dllexport.");
95 if (
auto *Import = D->
getAttr<DLLImportAttr>())
97 if (
auto *Export = D->
getAttr<DLLExportAttr>())
104 typedef llvm::StringMap<TypoResultList> TypoResultsMap;
105 typedef std::map<unsigned, TypoResultsMap> TypoEditDistanceMap;
112 std::unique_ptr<CorrectionCandidateCallback> CCC,
114 bool EnteringContext)
115 : Typo(TypoName.getName().getAsIdentifierInfo()), CurrentTCIndex(0),
116 SavedTCIndex(0), SemaRef(SemaRef), S(S),
117 SS(SS ? llvm::make_unique<
CXXScopeSpec>(*SS) : nullptr),
118 CorrectionValidator(std::move(CCC)), MemberContext(MemberContext),
119 Result(SemaRef, TypoName, LookupKind),
120 Namespaces(SemaRef.
Context, SemaRef.CurContext, SS),
121 EnteringContext(EnteringContext), SearchNamespaces(
false) {
131 bool InBaseClass)
override;
137 return CorrectionResults.empty() && ValidatedCorrections.size() == 1;
143 return CorrectionResults.begin()->second[
Name];
149 if (CorrectionResults.empty())
150 return (std::numeric_limits<unsigned>::max)();
152 unsigned BestED = CorrectionResults.begin()->first;
161 addNamespaces(
const llvm::MapVector<NamespaceDecl *, bool> &KnownNamespaces);
172 return CurrentTCIndex < ValidatedCorrections.size()
173 ? ValidatedCorrections[CurrentTCIndex]
174 : ValidatedCorrections[0];
198 return CorrectionResults.empty() &&
199 CurrentTCIndex >= ValidatedCorrections.size();
205 SavedTCIndex = CurrentTCIndex;
210 CurrentTCIndex = SavedTCIndex;
221 class NamespaceSpecifierSet {
222 struct SpecifierInfo {
225 unsigned EditDistance;
228 typedef SmallVector<DeclContext*, 4> DeclContextList;
229 typedef SmallVector<SpecifierInfo, 16> SpecifierInfoList;
232 DeclContextList CurContextChain;
233 std::string CurNameSpecifier;
234 SmallVector<const IdentifierInfo*, 4> CurContextIdentifiers;
235 SmallVector<const IdentifierInfo*, 4> CurNameSpecifierIdentifiers;
237 std::map<unsigned, SpecifierInfoList> DistanceMap;
241 static DeclContextList buildContextChain(DeclContext *Start);
243 unsigned buildNestedNameSpecifier(DeclContextList &DeclChain,
244 NestedNameSpecifier *&NNS);
248 CXXScopeSpec *CurScopeSpec);
252 void addNameSpecifier(DeclContext *Ctx);
256 :
public llvm::iterator_facade_base<iterator, std::forward_iterator_tag,
267 : OuterBack(std::prev(Set.DistanceMap.
end())),
268 Outer(Set.DistanceMap.
begin()),
269 Inner(!IsAtEnd ? Outer->second.
begin() : OuterBack->second.
end()) {
270 assert(!Set.DistanceMap.empty());
275 if (Inner == Outer->second.end() && Outer != OuterBack) {
277 Inner = Outer->second.begin();
290 void addName(StringRef
Name, NamedDecl *ND,
291 NestedNameSpecifier *NNS =
nullptr,
bool isKeyword =
false);
296 bool resolveCorrection(TypoCorrection &Candidate);
302 void performQualifiedLookups();
305 IdentifierInfo *Typo;
312 TypoEditDistanceMap CorrectionResults;
314 SmallVector<TypoCorrection, 4> ValidatedCorrections;
315 size_t CurrentTCIndex;
320 std::unique_ptr<CXXScopeSpec> SS;
321 std::unique_ptr<CorrectionCandidateCallback> CorrectionValidator;
322 DeclContext *MemberContext;
324 NamespaceSpecifierSet Namespaces;
325 SmallVector<TypoCorrection, 2> QualifiedResults;
326 bool EnteringContext;
327 bool SearchNamespaces;
330 inline Sema::TypoExprState::TypoExprState() {}
332 inline Sema::TypoExprState::TypoExprState(TypoExprState &&other) LLVM_NOEXCEPT {
333 *
this = std::move(other);
336 inline Sema::TypoExprState &Sema::TypoExprState::operator=(
337 Sema::TypoExprState &&other) LLVM_NOEXCEPT {
338 Consumer = std::move(other.Consumer);
339 DiagHandler = std::move(other.DiagHandler);
340 RecoveryHandler = std::move(other.RecoveryHandler);
Defines the clang::ASTContext interface.
bool isAddressOfOperand() const
void MarkVarDeclODRUsed(VarDecl *Var, SourceLocation Loc, Sema &SemaRef, const unsigned *const FunctionScopeIndexToStopAt)
A (possibly-)qualified type.
Simple class containing the result of Sema::CorrectTypo.
bool operator==(const iterator &RHS) const
Decl - This represents one declaration (or definition), e.g.
TypoResultList & operator[](StringRef Name)
Return the list of TypoCorrections for the given identifier from the set of corrections that have the...
void saveCurrentPosition()
Save the current position in the correction stream (overwriting any previously saved position)...
Consumes visible declarations found when searching for all visible names within a given scope or cont...
bool isUsableInConstantExpressions(ASTContext &C) const
Determine whether this variable's value can be used in a constant expression, according to the releva...
VarDecl - An instance of this class is created to represent a variable declaration or definition...
PartialDiagnostic PDiag(unsigned DiagID=0)
Build a partial diagnostic.
bool finished()
Return whether the end of the stream of corrections has been reached.
bool tryCaptureVariable(VarDecl *Var, SourceLocation Loc, TryCaptureKind Kind, SourceLocation EllipsisLoc, bool BuildAndDiagnose, QualType &CaptureType, QualType &DeclRefType, const unsigned *const FunctionScopeIndexToStopAt)
Try to capture the given variable.
void addKeywordResult(StringRef Keyword)
bool FTIHasNonVoidParameters(const DeclaratorChunk::FunctionTypeInfo &FTI)
class LLVM_ALIGNAS(8) DependentTemplateSpecializationType const IdentifierInfo * Name
Represents a template specialization type whose template cannot be resolved, e.g. ...
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
void FoundDecl(NamedDecl *ND, NamedDecl *Hiding, DeclContext *Ctx, bool InBaseClass) override
Invoked each time Sema::LookupVisibleDecls() finds a declaration visible from the current scope or co...
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.
const CXXScopeSpec * getSS() const
bool FTIHasSingleVoidParameter(const DeclaratorChunk::FunctionTypeInfo &FTI)
Scope - A scope is a transient data structure that is used while parsing the program.
static unsigned NormalizeEditDistance(unsigned ED)
Represents a C++ nested-name-specifier or a global scope specifier.
const TypoCorrection & getNextCorrection()
Return the next typo correction that passes all internal filters and is deemed valid by the consumer'...
Sema - This implements semantic analysis and AST building for C.
void restoreSavedPosition()
Restore the saved position in the correction stream.
unsigned NumParams
NumParams - This is the number of formal parameters specified by the declarator.
LookupNameKind
Describes the kind of name lookup to perform.
bool IsVariableAConstantExpression(VarDecl *Var, ASTContext &Context)
llvm::DenseMap< NamedDecl *, SourceLocation > UndefinedButUsed
UndefinedInternals - all the used, undefined objects which require a definition in this translation u...
PartialDiagnostic::StorageAllocator & getDiagAllocator()
void addCorrection(TypoCorrection Correction)
bool isExternallyVisible() const
bool checkInitIsICE() const
Determine whether the value of the initializer attached to this declaration is an integral constant e...
const LookupResult & getLookupResult() const
VarDecl * getCanonicalDecl() override
Retrieves the "canonical" declaration of the given declaration.
TypoCorrectionConsumer(Sema &SemaRef, const DeclarationNameInfo &TypoName, Sema::LookupNameKind LookupKind, Scope *S, CXXScopeSpec *SS, std::unique_ptr< CorrectionCandidateCallback > CCC, DeclContext *MemberContext, bool EnteringContext)
const Expr * getAnyInitializer() const
getAnyInitializer - Get the initializer for this variable, no matter which declaration it is attached...
Encodes a location in the source.
const TemplateArgument * iterator
SpecifierInfo & operator*()
void FoundName(StringRef Name)
InheritableAttr * getDLLAttr(Decl *D)
Return a DLL attribute from the declaration.
Represents a C++ nested name specifier, such as "\::std::vector<int>::".
This declaration is only a declaration.
Represents a template argument.
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
unsigned isVariadic
isVariadic - If this function has a prototype, and if that proto ends with ',...)', this is true.
ASTContext & getContext() const
DeclarationNameInfo - A collector data type for bundling together a DeclarationName and the correspnd...
bool DeclAttrsMatchCUDAMode(const LangOptions &LangOpts, Decl *D)
const TypoCorrection & peekNextCorrection()
Return the next typo correction like getNextCorrection, but keep the internal state pointed to the cu...
bool isStaticDataMember() const
Determines whether this is a static data member.
iterator(NamespaceSpecifierSet &Set, bool IsAtEnd)
void markUsed(ASTContext &C)
Mark the declaration used, in the sense of odr-use.
Provides flat iteration over specifiers, sorted by distance.
bool includeHiddenDecls() const override
Determine whether hidden declarations (from unimported modules) should be given to this consumer...
const TypoCorrection & getCurrentCorrection()
Get the last correction returned by getNextCorrection().
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...
unsigned getBestEditDistance(bool Normalized)
Return the edit distance of the corrections that have the closest/best edit distance from the origina...
void suppressDiagnostics()
Suppress the diagnostics that would normally fire because of this lookup.
void resetCorrectionStream()
Reset the consumer's position in the stream of viable corrections (i.e.
NamedDecl - This represents a decl with a name.
DefinitionKind hasDefinition(ASTContext &) const
Check whether this variable is defined in this translation unit.
ParamInfo * Params
Params - This is a pointer to a new[]'d array of ParamInfo objects that describe the parameters speci...