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>() ||
58 D->hasAttr<CUDASharedAttr>() ||
59 D->hasAttr<CUDAGlobalAttr>();
60 return isDeviceSideDecl == LangOpts.CUDAIsDevice;
72 const unsigned *
const FunctionScopeIndexToStopAt) {
86 CaptureType, DeclRefType,
87 FunctionScopeIndexToStopAt);
94 assert(!(D->hasAttr<DLLImportAttr>() && D->hasAttr<DLLExportAttr>()) &&
95 "A declaration cannot be both dllimport and dllexport.");
96 if (
auto *Import = D->getAttr<DLLImportAttr>())
98 if (
auto *Export = D->getAttr<DLLExportAttr>())
105 typedef llvm::StringMap<TypoResultList> TypoResultsMap;
106 typedef std::map<unsigned, TypoResultsMap> TypoEditDistanceMap;
113 std::unique_ptr<CorrectionCandidateCallback> CCC,
115 bool EnteringContext)
116 : Typo(TypoName.getName().getAsIdentifierInfo()), CurrentTCIndex(0),
117 SavedTCIndex(0), SemaRef(SemaRef), S(S),
118 SS(SS ? llvm::make_unique<
CXXScopeSpec>(*SS) : nullptr),
119 CorrectionValidator(std::move(CCC)), MemberContext(MemberContext),
120 Result(SemaRef, TypoName, LookupKind),
121 Namespaces(SemaRef.
Context, SemaRef.CurContext, SS),
122 EnteringContext(EnteringContext), SearchNamespaces(
false) {
132 bool InBaseClass)
override;
138 return CorrectionResults.empty() && ValidatedCorrections.size() == 1;
144 return CorrectionResults.begin()->second[
Name];
150 if (CorrectionResults.empty())
153 unsigned BestED = CorrectionResults.begin()->first;
162 addNamespaces(
const llvm::MapVector<NamespaceDecl *, bool> &KnownNamespaces);
173 return CurrentTCIndex < ValidatedCorrections.size()
174 ? ValidatedCorrections[CurrentTCIndex]
175 : ValidatedCorrections[0];
199 return CorrectionResults.empty() &&
200 CurrentTCIndex >= ValidatedCorrections.size();
206 SavedTCIndex = CurrentTCIndex;
211 CurrentTCIndex = SavedTCIndex;
221 return CorrectionValidator.get();
225 class NamespaceSpecifierSet {
226 struct SpecifierInfo {
229 unsigned EditDistance;
232 typedef SmallVector<DeclContext*, 4> DeclContextList;
233 typedef SmallVector<SpecifierInfo, 16> SpecifierInfoList;
236 DeclContextList CurContextChain;
237 std::string CurNameSpecifier;
238 SmallVector<const IdentifierInfo*, 4> CurContextIdentifiers;
239 SmallVector<const IdentifierInfo*, 4> CurNameSpecifierIdentifiers;
241 std::map<unsigned, SpecifierInfoList> DistanceMap;
245 static DeclContextList buildContextChain(DeclContext *Start);
247 unsigned buildNestedNameSpecifier(DeclContextList &DeclChain,
248 NestedNameSpecifier *&NNS);
252 CXXScopeSpec *CurScopeSpec);
256 void addNameSpecifier(DeclContext *Ctx);
260 :
public llvm::iterator_facade_base<iterator, std::forward_iterator_tag,
271 : OuterBack(std::prev(Set.DistanceMap.
end())),
272 Outer(Set.DistanceMap.
begin()),
273 Inner(!IsAtEnd ? Outer->second.
begin() : OuterBack->second.
end()) {
274 assert(!Set.DistanceMap.empty());
279 if (Inner == Outer->second.end() && Outer != OuterBack) {
281 Inner = Outer->second.begin();
294 void addName(StringRef
Name, NamedDecl *ND,
295 NestedNameSpecifier *NNS =
nullptr,
bool isKeyword =
false);
300 bool resolveCorrection(TypoCorrection &Candidate);
306 void performQualifiedLookups();
309 IdentifierInfo *Typo;
316 TypoEditDistanceMap CorrectionResults;
318 SmallVector<TypoCorrection, 4> ValidatedCorrections;
319 size_t CurrentTCIndex;
324 std::unique_ptr<CXXScopeSpec> SS;
325 std::unique_ptr<CorrectionCandidateCallback> CorrectionValidator;
326 DeclContext *MemberContext;
328 NamespaceSpecifierSet Namespaces;
329 SmallVector<TypoCorrection, 2> QualifiedResults;
330 bool EnteringContext;
331 bool SearchNamespaces;
334 inline Sema::TypoExprState::TypoExprState() {}
336 inline Sema::TypoExprState::TypoExprState(TypoExprState &&other) LLVM_NOEXCEPT {
337 *
this = std::move(other);
340 inline Sema::TypoExprState &Sema::TypoExprState::operator=(
341 Sema::TypoExprState &&other) LLVM_NOEXCEPT {
342 Consumer = std::move(other.Consumer);
343 DiagHandler = std::move(other.DiagHandler);
344 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
CorrectionCandidateCallback * getCorrectionValidator() const
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.
llvm::MapVector< NamedDecl *, SourceLocation > UndefinedButUsed
UndefinedInternals - all the used, undefined objects which require a definition in this translation u...
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 ...
Base class for callback objects used by Sema::CorrectTypo to check the validity of a potential typo c...
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)
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
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)
char __ovld __cnfn max(char x, char y)
Returns y if x < y, otherwise it returns x.
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...
bool isInline() const
Whether this variable is (C++1z) inline.
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...