38 #include "llvm/ADT/STLExtras.h" 39 #include "llvm/ADT/SmallPtrSet.h" 40 #include "llvm/ADT/TinyPtrVector.h" 41 #include "llvm/ADT/edit_distance.h" 42 #include "llvm/Support/ErrorHandling.h" 50 #include "OpenCLBuiltins.inc" 52 using namespace clang;
56 class UnqualUsingEntry {
63 : Nominated(Nominated), CommonAncestor(CommonAncestor) {
67 return CommonAncestor;
76 bool operator()(
const UnqualUsingEntry &L,
const UnqualUsingEntry &R) {
77 return L.getCommonAncestor() < R.getCommonAncestor();
80 bool operator()(
const UnqualUsingEntry &E,
const DeclContext *DC) {
81 return E.getCommonAncestor() < DC;
84 bool operator()(
const DeclContext *DC,
const UnqualUsingEntry &E) {
85 return DC < E.getCommonAncestor();
92 class UnqualUsingDirectiveSet {
98 llvm::SmallPtrSet<DeclContext*, 8> visited;
101 UnqualUsingDirectiveSet(
Sema &SemaRef) : SemaRef(SemaRef) {}
103 void visitScopeChain(
Scope *S,
Scope *InnermostFileScope) {
121 visit(I, InnermostFileDC);
134 if (!visited.insert(DC).second)
137 addUsingDirectives(DC, EffectiveDC);
145 if (!visited.insert(NS).second)
148 addUsingDirective(UD, EffectiveDC);
149 addUsingDirectives(NS, EffectiveDC);
160 if (SemaRef.
isVisible(UD) && visited.insert(NS).second) {
161 addUsingDirective(UD, EffectiveDC);
169 DC = queue.pop_back_val();
184 while (!Common->
Encloses(EffectiveDC))
191 void done() { llvm::sort(list, UnqualUsingEntry::Comparator()); }
193 typedef ListTy::const_iterator const_iterator;
195 const_iterator begin()
const {
return list.begin(); }
196 const_iterator end()
const {
return list.end(); }
198 llvm::iterator_range<const_iterator>
200 return llvm::make_range(std::equal_range(begin(), end(),
202 UnqualUsingEntry::Comparator()));
211 bool Redeclaration) {
231 assert(!Redeclaration &&
"cannot do redeclaration operator lookup");
270 assert(Redeclaration &&
"should only be used for redecl lookup");
297 void LookupResult::configure() {
299 isForRedeclaration());
304 switch (NameInfo.getName().getCXXOverloadedOperator()) {
308 case OO_Array_Delete:
309 getSema().DeclareGlobalNewDelete();
319 if (
unsigned BuiltinID =
Id->getBuiltinID()) {
320 if (!getSema().Context.BuiltinInfo.isPredefinedLibFunction(BuiltinID))
326 bool LookupResult::sanity()
const {
328 assert(ResultKind != NotFound || Decls.size() == 0);
329 assert(ResultKind != Found || Decls.size() == 1);
330 assert(ResultKind != FoundOverloaded || Decls.size() > 1 ||
331 (Decls.size() == 1 &&
332 isa<FunctionTemplateDecl>((*begin())->getUnderlyingDecl())));
333 assert(ResultKind != FoundUnresolvedValue || sanityCheckUnresolved());
334 assert(ResultKind != Ambiguous || Decls.size() > 1 ||
335 (Decls.size() == 1 && (Ambiguity == AmbiguousBaseSubobjects ||
336 Ambiguity == AmbiguousBaseSubobjectTypes)));
337 assert((Paths !=
nullptr) == (ResultKind == Ambiguous &&
338 (Ambiguity == AmbiguousBaseSubobjectTypes ||
339 Ambiguity == AmbiguousBaseSubobjects)));
370 !isa<UsingShadowDecl>(Existing))
382 if (DUnderlying->getCanonicalDecl() != EUnderlying->getCanonicalDecl()) {
383 assert(isa<TypeDecl>(DUnderlying) && isa<TypeDecl>(EUnderlying));
384 bool HaveTag = isa<TagDecl>(EUnderlying);
386 return HaveTag != WantTag;
393 if (
auto *DFD = dyn_cast<FunctionDecl>(DUnderlying)) {
394 auto *EFD = cast<FunctionDecl>(EUnderlying);
395 unsigned DMin = DFD->getMinRequiredArguments();
396 unsigned EMin = EFD->getMinRequiredArguments();
405 if (
auto *DTD = dyn_cast<TemplateDecl>(DUnderlying)) {
406 auto *ETD = cast<TemplateDecl>(EUnderlying);
407 unsigned DMin = DTD->getTemplateParameters()->getMinRequiredArguments();
408 unsigned EMin = ETD->getTemplateParameters()->getMinRequiredArguments();
417 for (
unsigned I = DMin, N = DTD->getTemplateParameters()->size();
420 ETD->getTemplateParameters()->getParam(I)) &&
422 DTD->getTemplateParameters()->getParam(I)))
429 if (
VarDecl *DVD = dyn_cast<VarDecl>(DUnderlying)) {
430 VarDecl *EVD = cast<VarDecl>(EUnderlying);
432 !DVD->getType()->isIncompleteType()) {
440 if (!isa<FunctionDecl>(DUnderlying) && !isa<VarDecl>(DUnderlying)) {
449 if (Prev == EUnderlying)
469 return isa<VarDecl>(D) || isa<EnumConstantDecl>(D) || isa<FunctionDecl>(D) ||
470 isa<FunctionTemplateDecl>(D) || isa<FieldDecl>(D) ||
471 isa<UnresolvedUsingValueDecl>(D);
476 unsigned N = Decls.size();
480 assert(ResultKind == NotFound ||
481 ResultKind == NotFoundInCurrentInstantiation);
488 NamedDecl *D = (*Decls.begin())->getUnderlyingDecl();
489 if (isa<FunctionTemplateDecl>(D))
490 ResultKind = FoundOverloaded;
491 else if (isa<UnresolvedUsingValueDecl>(D))
492 ResultKind = FoundUnresolvedValue;
497 if (ResultKind == Ambiguous)
return;
499 llvm::SmallDenseMap<NamedDecl*, unsigned, 16> Unique;
500 llvm::SmallDenseMap<QualType, unsigned, 16> UniqueTypes;
502 bool Ambiguous =
false;
503 bool HasTag =
false, HasFunction =
false;
504 bool HasFunctionTemplate =
false, HasUnresolved =
false;
509 unsigned UniqueTagIndex = 0;
518 Decls[I] = Decls[--N];
528 if (
TypeDecl *TD = dyn_cast<TypeDecl>(D)) {
529 QualType T = getSema().Context.getTypeDeclType(TD);
530 auto UniqueResult = UniqueTypes.insert(
532 if (!UniqueResult.second) {
534 ExistingI = UniqueResult.first->second;
541 auto UniqueResult = Unique.insert(std::make_pair(D, I));
542 if (!UniqueResult.second) {
544 ExistingI = UniqueResult.first->second;
553 Decls[*ExistingI] = Decls[I];
554 Decls[I] = Decls[--N];
560 if (isa<UnresolvedUsingValueDecl>(D)) {
561 HasUnresolved =
true;
562 }
else if (isa<TagDecl>(D)) {
567 }
else if (isa<FunctionTemplateDecl>(D)) {
569 HasFunctionTemplate =
true;
570 }
else if (isa<FunctionDecl>(D)) {
573 if (HasNonFunction) {
578 if (getSema().isEquivalentInternalLinkageDeclaration(HasNonFunction,
580 EquivalentNonFunctions.push_back(D);
581 Decls[I] = Decls[--N];
601 if (N > 1 && HideTags && HasTag && !Ambiguous &&
602 (HasFunction || HasNonFunction || HasUnresolved)) {
603 NamedDecl *OtherDecl = Decls[UniqueTagIndex ? 0 : N - 1];
604 if (isa<TagDecl>(Decls[UniqueTagIndex]->getUnderlyingDecl()) &&
608 Decls[UniqueTagIndex] = Decls[--N];
615 if (!EquivalentNonFunctions.empty() && !Ambiguous)
616 getSema().diagnoseEquivalentInternalLinkageDeclarations(
617 getNameLoc(), HasNonFunction, EquivalentNonFunctions);
621 if (HasNonFunction && (HasFunction || HasUnresolved))
626 else if (HasUnresolved)
628 else if (N > 1 || HasFunctionTemplate)
634 void LookupResult::addDeclsFromBasePaths(
const CXXBasePaths &
P) {
636 for (I = P.
begin(), E = P.
end(); I != E; ++I)
638 DE = I->Decls.end(); DI != DE; ++DI)
645 addDeclsFromBasePaths(*Paths);
647 setAmbiguous(AmbiguousBaseSubobjects);
653 addDeclsFromBasePaths(*Paths);
655 setAmbiguous(AmbiguousBaseSubobjectTypes);
659 Out << Decls.size() <<
" result(s)";
660 if (isAmbiguous()) Out <<
", ambiguous";
661 if (Paths) Out <<
", base paths present";
663 for (
iterator I = begin(), E = end(); I != E; ++I) {
670 llvm::errs() <<
"lookup results for " << getLookupName().getAsString()
688 ASTContext &Context,
const OpenCLBuiltinStruct &OpenCLBuiltin,
692 unsigned Sig = SignatureTable[OpenCLBuiltin.SigTableIndex];
693 OCL2Qual(Context, TypeTable[Sig], RetTypes);
694 GenTypeMaxCnt = RetTypes.size();
698 for (
unsigned Index = 1; Index < OpenCLBuiltin.NumTypes; Index++) {
701 TypeTable[SignatureTable[OpenCLBuiltin.SigTableIndex + Index]], Ty);
702 GenTypeMaxCnt = (Ty.size() > GenTypeMaxCnt) ? Ty.size() : GenTypeMaxCnt;
703 ArgTypes.push_back(std::move(Ty));
724 for (
unsigned IGenType = 0; IGenType < GenTypeMaxCnt; IGenType++) {
727 for (
unsigned A = 0; A < ArgTypes.size(); A++) {
731 assert(GenTypeMaxCnt % ArgTypes[A].size() == 0 &&
732 "argument type count not compatible with gentype type count");
733 unsigned Idx = IGenType % ArgTypes[A].size();
734 ArgList.push_back(ArgTypes[A][Idx]);
738 RetTypes[(RetTypes.size() != 1) ? IGenType : 0], ArgList, PI));
749 StringRef E = FunctionExtensionTable[BIDecl.Extension];
765 const unsigned FctIndex,
766 const unsigned Len) {
768 bool HasGenType =
false;
772 unsigned GenTypeMaxCnt;
774 for (
unsigned SignatureIndex = 0; SignatureIndex < Len; SignatureIndex++) {
775 const OpenCLBuiltinStruct &OpenCLBuiltin =
776 BuiltinTable[FctIndex + SignatureIndex];
780 unsigned OpenCLVersion = Context.
getLangOpts().OpenCLVersion;
783 if (OpenCLVersion < OpenCLBuiltin.MinVersion)
785 if ((OpenCLBuiltin.MaxVersion != 0) &&
786 (OpenCLVersion >= OpenCLBuiltin.MaxVersion))
795 if (GenTypeMaxCnt > 1) {
800 std::vector<QualType> FunctionList;
808 for (
unsigned Index = 0; Index < GenTypeMaxCnt; Index++) {
810 Context, Parent, Loc, Loc, II, FunctionList[Index],
812 FunctionList[Index]->isFunctionProtoType());
818 dyn_cast<FunctionProtoType>(FunctionList[Index])) {
820 for (
unsigned IParm = 0, e = FP->getNumParams(); IParm != e; ++IParm) {
823 nullptr, FP->getParamType(IParm),
826 ParmList.push_back(Parm);
828 NewOpenCLBuiltin->setParams(ParmList);
832 if (OpenCLBuiltin.IsPure)
833 NewOpenCLBuiltin->
addAttr(PureAttr::CreateImplicit(Context));
834 if (OpenCLBuiltin.IsConst)
835 NewOpenCLBuiltin->
addAttr(ConstAttr::CreateImplicit(Context));
836 if (OpenCLBuiltin.IsConv)
837 NewOpenCLBuiltin->
addAttr(ConvergentAttr::CreateImplicit(Context));
840 NewOpenCLBuiltin->
addAttr(OverloadableAttr::CreateImplicit(Context));
849 if (Len > 1 || HasGenType)
866 if (II == getASTContext().getMakeIntegerSeqName()) {
867 R.
addDecl(getASTContext().getMakeIntegerSeqDecl());
869 }
else if (II == getASTContext().getTypePackElementName()) {
870 R.
addDecl(getASTContext().getTypePackElementDecl());
876 if (getLangOpts().
OpenCL && getLangOpts().DeclareOpenCLBuiltins) {
877 auto Index = isOpenCLBuiltin(II->
getName());
924 DeclareImplicitDefaultConstructor(Class);
928 DeclareImplicitCopyConstructor(Class);
932 DeclareImplicitCopyAssignment(Class);
934 if (getLangOpts().CPlusPlus11) {
937 DeclareImplicitMoveConstructor(Class);
941 DeclareImplicitMoveAssignment(Class);
946 DeclareImplicitDestructor(Class);
978 if (
const CXXRecordDecl *Record = dyn_cast<CXXRecordDecl>(DC))
981 if (Record->needsImplicitDefaultConstructor())
983 if (Record->needsImplicitCopyConstructor())
986 Record->needsImplicitMoveConstructor())
992 if (
const CXXRecordDecl *Record = dyn_cast<CXXRecordDecl>(DC))
993 if (Record->getDefinition() && Record->needsImplicitDestructor() &&
1002 if (
const CXXRecordDecl *Record = dyn_cast<CXXRecordDecl>(DC)) {
1005 if (Record->needsImplicitCopyAssignment())
1008 Record->needsImplicitMoveAssignment())
1048 !isa<CXXRecordDecl>(DC))
1062 auto *ContainedDeducedType =
1066 ContainedDeducedType && ContainedDeducedType->isUndeducedType())
1100 assert(ConvProto &&
"Nonsensical conversion function template type");
1115 Specialization, Info)
1128 DeclContext *NS, UnqualUsingDirectiveSet &UDirs) {
1130 assert(NS && NS->
isFileContext() &&
"CppNamespaceLookup() requires namespace!");
1137 for (
const UnqualUsingEntry &UUE : UDirs.getNamespacesFor(NS))
1164 if (OuterS->getEntity()) {
1165 Lexical = OuterS->getEntity();
1192 if (!Lexical || !DC || !S->
getParent() ||
1194 return std::make_pair(Lexical,
false);
1200 while (OutermostTemplateScope->
getParent() &&
1202 OutermostTemplateScope = OutermostTemplateScope->
getParent();
1216 return std::make_pair(Semantic,
true);
1218 return std::make_pair(Lexical,
false);
1224 struct FindLocalExternScope {
1234 ~FindLocalExternScope() {
1238 bool OldFindLocalExtern;
1243 assert(getLangOpts().
CPlusPlus &&
"Can perform only C++ lookup");
1261 I = IdResolver.begin(Name),
1262 IEnd = IdResolver.end();
1282 UnqualUsingDirectiveSet UDirs(*
this);
1283 bool VisitedUsingDirectives =
false;
1284 bool LeftStartingScope =
false;
1288 FindLocalExternScope FindLocals(R);
1292 bool SearchNamespaceScope =
true;
1296 if (NameKind == LookupRedeclarationWithLinkage &&
1297 !(*I)->isTemplateParameter()) {
1303 if (!LeftStartingScope && !Initial->
isDeclScope(*I))
1304 LeftStartingScope =
true;
1308 if (LeftStartingScope && !((*I)->hasLinkage())) {
1315 SearchNamespaceScope =
false;
1320 if (!SearchNamespaceScope) {
1323 if (
CXXRecordDecl *Record = dyn_cast_or_null<CXXRecordDecl>(Ctx))
1328 if (NameKind == LookupLocalFriendName && !S->
isClassScope()) {
1344 Ctx = OutsideOfTemplateParamDC;
1345 OutsideOfTemplateParamDC =
nullptr;
1350 bool SearchAfterTemplateScope;
1352 if (SearchAfterTemplateScope)
1353 OutsideOfTemplateParamDC = OuterCtx;
1372 if (
ObjCIvarDecl *Ivar = Class->lookupInstanceVariable(
1391 if (!VisitedUsingDirectives) {
1394 if (UCtx->isTransparentContext())
1397 UDirs.visit(UCtx, UCtx);
1402 Scope *InnermostFileScope = S;
1403 while (InnermostFileScope &&
1405 InnermostFileScope = InnermostFileScope->
getParent();
1406 UDirs.visitScopeChain(Initial, InnermostFileScope);
1410 VisitedUsingDirectives =
true;
1427 if (LookupQualifiedName(R, Ctx,
true))
1435 if (!S)
return false;
1438 if (NameKind == LookupMemberName)
1446 if (!VisitedUsingDirectives) {
1447 UDirs.visitScopeChain(Initial, S);
1454 FindLocals.restore();
1487 Ctx = OutsideOfTemplateParamDC;
1488 OutsideOfTemplateParamDC =
nullptr;
1493 bool SearchAfterTemplateScope;
1495 if (SearchAfterTemplateScope)
1496 OutsideOfTemplateParamDC = OuterCtx;
1510 "We should have been looking only at file context here already.");
1535 if (
auto *M = getCurrentModule())
1543 if (
auto *TD = dyn_cast<TemplateDecl>(ND))
1544 for (
auto *Param : *TD->getTemplateParameters())
1545 makeMergedDefinitionVisible(Param);
1550 if (
FunctionDecl *FD = dyn_cast<FunctionDecl>(Entity)) {
1555 }
else if (
CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(Entity)) {
1558 }
else if (
EnumDecl *ED = dyn_cast<EnumDecl>(Entity)) {
1559 if (
auto *Pattern = ED->getTemplateInstantiationPattern())
1561 }
else if (
VarDecl *VD = dyn_cast<VarDecl>(Entity)) {
1575 unsigned N = CodeSynthesisContexts.size();
1576 for (
unsigned I = CodeSynthesisContextLookupModules.size();
1578 Module *M = CodeSynthesisContexts[I].Entity ?
1581 if (M && !LookupModulesCache.insert(M).second)
1583 CodeSynthesisContextLookupModules.push_back(M);
1585 return LookupModulesCache;
1599 if (isModuleVisible(Merged))
1611 template<
typename ParmDecl>
1615 if (!D->hasDefaultArgument())
1619 auto &DefaultArg = D->getDefaultArgStorage();
1620 if (!DefaultArg.isInherited() && S.
isVisible(D))
1623 if (!DefaultArg.isInherited() && Modules) {
1624 auto *NonConstD =
const_cast<ParmDecl*
>(D);
1629 D = DefaultArg.getInheritedFrom();
1636 if (
auto *P = dyn_cast<TemplateTypeParmDecl>(D))
1638 if (
auto *P = dyn_cast<NonTypeTemplateParmDecl>(D))
1644 template<
typename Filter>
1648 bool HasFilteredRedecls =
false;
1650 for (
auto *Redecl : D->
redecls()) {
1651 auto *R = cast<NamedDecl>(Redecl);
1658 HasFilteredRedecls =
true;
1661 Modules->push_back(R->getOwningModule());
1665 if (HasFilteredRedecls)
1674 if (
auto *RD = dyn_cast<CXXRecordDecl>(D))
1676 if (
auto *FD = dyn_cast<FunctionDecl>(D))
1678 if (
auto *VD = dyn_cast<VarDecl>(D))
1680 llvm_unreachable(
"unknown explicit specialization kind");
1687 "not a member specialization");
1708 bool LookupResult::isVisibleSlow(
Sema &SemaRef,
NamedDecl *D) {
1709 assert(D->
isHidden() &&
"should not call this: not in slow case");
1712 assert(DeclModule &&
"hidden decl has no owning module");
1721 auto IsEffectivelyFileContext = [](
const DeclContext *DC) {
1723 isa<ExportDecl>(DC);
1729 if (DC && !IsEffectivelyFileContext(DC)) {
1737 bool VisibleWithinParent;
1739 bool SearchDefinitions =
true;
1740 if (
const auto *DCD = dyn_cast<Decl>(DC)) {
1741 if (
const auto *TD = DCD->getDescribedTemplate()) {
1744 SearchDefinitions = Index >= TPL->
size() || TPL->
getParam(Index) != D;
1747 if (SearchDefinitions)
1750 VisibleWithinParent = isVisible(SemaRef, cast<NamedDecl>(DC));
1751 }
else if (isa<ParmVarDecl>(D) ||
1752 (isa<FunctionDecl>(DC) && !SemaRef.
getLangOpts().CPlusPlus))
1753 VisibleWithinParent = isVisible(SemaRef, cast<NamedDecl>(DC));
1757 VisibleWithinParent =
false;
1760 VisibleWithinParent =
true;
1764 }
while (!IsEffectivelyFileContext(DC));
1776 return VisibleWithinParent;
1786 if (ModulePrivate) {
1790 if (VisibleModules.isVisible(M))
1798 const auto &LookupModules = getLookupModules();
1799 if (LookupModules.empty())
1803 if (LookupModules.count(M))
1811 return llvm::any_of(LookupModules, [&](
const Module *LookupM) {
1816 bool Sema::isVisibleSlow(
const NamedDecl *D) {
1834 "should not have hidden, non-externally-declarable result here");
1868 for (
auto RD : D->
redecls()) {
1873 auto ND = cast<NamedDecl>(RD);
1877 if (ND->isInIdentifierNamespace(IDNS) &&
1887 assert(!isVisible(D) &&
"not in slow case");
1889 [](
const NamedDecl *) {
return true; });
1893 if (
auto *ND = dyn_cast<NamespaceDecl>(D)) {
1901 if (
auto *Acceptable = getSema().VisibleNamespaceCache.lookup(Key))
1903 auto *Acceptable = isVisible(getSema(), Key)
1907 getSema().VisibleNamespaceCache.insert(std::make_pair(Key, Acceptable));
1944 if (!Name)
return false;
1959 FindLocalExternScope FindLocals(R);
1965 bool LeftStartingScope =
false;
1968 IEnd = IdResolver.end();
1971 if (NameKind == LookupRedeclarationWithLinkage) {
1975 LeftStartingScope =
true;
1979 if (LeftStartingScope && !((*I)->hasLinkage())) {
1984 else if (NameKind == LookupObjCImplicitSelfParam &&
1985 !isa<ImplicitParamDecl>(*I))
2010 for (++LastI; LastI != IEnd; ++LastI) {
2035 if (CppLookupName(R, S))
2042 if (AllowBuiltinCreation && LookupBuiltin(R))
2049 return (ExternalSource && ExternalSource->LookupUnqualified(R, S));
2081 assert(StartDC->
isFileContext() &&
"start context is not a file context");
2088 llvm::SmallPtrSet<DeclContext*, 8> Visited;
2089 Visited.insert(StartDC);
2095 if (S.
isVisible(I) && Visited.insert(ND).second)
2096 Queue.push_back(ND);
2103 bool FoundTag =
false;
2104 bool FoundNonTag =
false;
2109 while (!Queue.empty()) {
2114 bool UseLocal = !R.
empty();
2143 if (S.
isVisible(I) && Visited.insert(Nom).second)
2144 Queue.push_back(Nom);
2149 if (FoundTag && FoundNonTag)
2169 template<
typename InputIterator>
2172 if (isa<VarDecl>(D) || isa<TypeDecl>(D) || isa<EnumConstantDecl>(D))
2175 if (isa<CXXMethodDecl>(D)) {
2177 bool AllMethodsAreStatic =
true;
2178 for(; First != Last; ++First) {
2179 D = (*First)->getUnderlyingDecl();
2181 if (!isa<CXXMethodDecl>(D)) {
2182 assert(isa<TagDecl>(D) &&
"Non-function must be a tag decl");
2186 if (!cast<CXXMethodDecl>(D)->isStatic()) {
2187 AllMethodsAreStatic =
false;
2192 if (AllMethodsAreStatic)
2222 bool InUnqualifiedLookup) {
2223 assert(LookupCtx &&
"Sema::LookupQualifiedName requires a lookup context");
2229 assert((!isa<TagDecl>(LookupCtx) ||
2231 cast<TagDecl>(LookupCtx)->isCompleteDefinition() ||
2232 cast<TagDecl>(LookupCtx)->isBeingDefined()) &&
2233 "Declaration context must already be complete!");
2235 struct QualifiedLookupInScope {
2239 QualifiedLookupInScope(
DeclContext *ctx) : Context(ctx) {
2242 ~QualifiedLookupInScope() {
2249 if (isa<CXXRecordDecl>(LookupCtx))
2295 case LookupObjCImplicitSelfParam:
2296 case LookupOrdinaryName:
2297 case LookupMemberName:
2298 case LookupRedeclarationWithLinkage:
2299 case LookupLocalFriendName:
2311 case LookupOMPReductionName:
2315 case LookupOMPMapperName:
2319 case LookupUsingDeclName:
2322 case LookupOperatorName:
2323 case LookupNamespaceName:
2324 case LookupObjCProtocolName:
2329 case LookupNestedNameSpecifierName:
2337 return BaseCallback(Specifier, Path, Name);
2351 int SubobjectNumber = 0;
2355 Path != PathEnd; ++Path) {
2363 if (SubobjectType.
isNull()) {
2391 if (
auto *TD = getAsTemplateNameDecl(D))
2396 while (FirstD != FirstPath->Decls.end() &&
2398 if (GetRepresentativeDecl(*FirstD) !=
2399 GetRepresentativeDecl(*CurrentD))
2406 if (FirstD == FirstPath->Decls.end() &&
2462 return LookupInSuper(R, NNS->getAsRecordDecl());
2465 return LookupQualifiedName(R, LookupCtx);
2488 bool AllowBuiltinCreation,
bool EnteringContext) {
2495 if (SS && SS->
isSet()) {
2500 if (
DeclContext *DC = computeDeclContext(*SS, EnteringContext)) {
2507 return LookupQualifiedName(R, DC);
2519 return LookupName(R, S, AllowBuiltinCreation);
2536 for (
const auto &BaseSpec : Class->
bases()) {
2538 BaseSpec.getType()->castAs<
RecordType>()->getDecl());
2541 LookupQualifiedName(Result, RD);
2545 for (
auto I = Result.begin(), E = Result.end(); I != E; ++I) {
2551 Result.suppressDiagnostics();
2565 assert(Result.
isAmbiguous() &&
"Lookup result must be ambiguous");
2574 QualType SubobjectType = Paths->
front().back().Base->getType();
2575 Diag(NameLoc, diag::err_ambiguous_member_multiple_subobjects)
2576 << Name << SubobjectType << getAmbiguousPathsDisplayString(*Paths)
2580 while (isa<CXXMethodDecl>(*Found) &&
2581 cast<CXXMethodDecl>(*Found)->isStatic())
2584 Diag((*Found)->getLocation(), diag::note_ambiguous_member_found);
2589 Diag(NameLoc, diag::err_ambiguous_member_multiple_subobject_types)
2590 << Name << LookupRange;
2593 std::set<Decl *> DeclsPrinted;
2595 PathEnd = Paths->
end();
2596 Path != PathEnd; ++Path) {
2597 Decl *D = Path->Decls.front();
2598 if (DeclsPrinted.insert(D).second)
2605 Diag(NameLoc, diag::err_ambiguous_tag_hiding) << Name << LookupRange;
2607 llvm::SmallPtrSet<NamedDecl*, 8> TagDecls;
2609 for (
auto *D : Result)
2610 if (
TagDecl *TD = dyn_cast<TagDecl>(D)) {
2611 TagDecls.insert(TD);
2612 Diag(TD->getLocation(), diag::note_hidden_tag);
2615 for (
auto *D : Result)
2616 if (!isa<TagDecl>(D))
2622 if (TagDecls.count(F.
next()))
2630 Diag(NameLoc, diag::err_ambiguous_reference) << Name << LookupRange;
2632 for (
auto *D : Result)
2640 struct AssociatedLookup {
2644 : S(S), Namespaces(Namespaces), Classes(Classes),
2645 InstantiationLoc(InstantiationLoc) {
2650 return ClassesTransitive.insert(RD);
2718 DeclContext *Ctx = ClassTemplate->getDeclContext();
2719 if (
CXXRecordDecl *EnclosingClass = dyn_cast<CXXRecordDecl>(Ctx))
2720 Result.Classes.insert(EnclosingClass);
2749 if (Class->
getDeclName() == Result.S.VAListTagName)
2762 if (
CXXRecordDecl *EnclosingClass = dyn_cast<CXXRecordDecl>(Ctx))
2763 Result.Classes.insert(EnclosingClass);
2778 = dyn_cast<ClassTemplateSpecializationDecl>(Class)) {
2779 DeclContext *Ctx = Spec->getSpecializedTemplate()->getDeclContext();
2780 if (
CXXRecordDecl *EnclosingClass = dyn_cast<CXXRecordDecl>(Ctx))
2781 Result.Classes.insert(EnclosingClass);
2786 for (
unsigned I = 0, N = TemplateArgs.
size(); I != N; ++I)
2792 if (!Result.addClassTransitive(Class))
2796 if (!Result.S.isCompleteType(Result.InstantiationLoc,
2797 Result.S.Context.getRecordType(Class)))
2803 Bases.push_back(Class);
2804 while (!Bases.empty()) {
2806 Class = Bases.pop_back_val();
2809 for (
const auto &
Base : Class->
bases()) {
2820 if (Result.addClassTransitive(BaseDecl)) {
2827 Bases.push_back(BaseDecl);
2855 #define TYPE(Class, Base) 2856 #define DEPENDENT_TYPE(Class, Base) case Type::Class: 2857 #define NON_CANONICAL_TYPE(Class, Base) case Type::Class: 2858 #define NON_CANONICAL_UNLESS_DEPENDENT_TYPE(Class, Base) case Type::Class: 2859 #define ABSTRACT_TYPE(Class, Base) 2860 #include "clang/AST/TypeNodes.inc" 2871 T = cast<PointerType>(T)->getPointeeType().getTypePtr();
2873 case Type::ConstantArray:
2874 case Type::IncompleteArray:
2875 case Type::VariableArray:
2876 T = cast<ArrayType>(T)->getElementType().getTypePtr();
2889 case Type::Record: {
2891 cast<CXXRecordDecl>(cast<RecordType>(T)->getDecl());
2901 EnumDecl *Enum = cast<EnumType>(T)->getDecl();
2904 if (
CXXRecordDecl *EnclosingClass = dyn_cast<CXXRecordDecl>(Ctx))
2905 Result.Classes.insert(EnclosingClass);
2916 case Type::FunctionProto: {
2919 Queue.push_back(Arg.getTypePtr());
2923 case Type::FunctionNoProto: {
2938 case Type::MemberPointer: {
2942 Queue.push_back(MemberPtr->
getClass());
2950 case Type::BlockPointer:
2951 T = cast<BlockPointerType>(T)->getPointeeType().getTypePtr();
2956 case Type::LValueReference:
2957 case Type::RValueReference:
2958 T = cast<ReferenceType>(T)->getPointeeType().getTypePtr();
2963 case Type::ExtVector:
2969 case Type::DeducedTemplateSpecialization:
2975 case Type::ObjCObject:
2976 case Type::ObjCInterface:
2977 case Type::ObjCObjectPointer:
2978 Result.Namespaces.insert(Result.S.Context.getTranslationUnitDecl());
2984 T = cast<AtomicType>(T)->getValueType().getTypePtr();
2987 T = cast<PipeType>(T)->getElementType().getTypePtr();
2993 T = Queue.pop_back_val();
3008 AssociatedNamespaces.clear();
3009 AssociatedClasses.clear();
3011 AssociatedLookup Result(*
this, InstantiationLoc,
3012 AssociatedNamespaces, AssociatedClasses);
3021 for (
unsigned ArgIdx = 0; ArgIdx != Args.size(); ++ArgIdx) {
3022 Expr *Arg = Args[ArgIdx];
3062 Decl *D = LookupSingleName(TUScope, II, IdLoc,
3063 LookupObjCProtocolName, Redecl);
3064 return cast_or_null<ObjCProtocolDecl>(D);
3078 LookupName(Operators, S);
3080 assert(!Operators.
isAmbiguous() &&
"Operator lookup cannot be ambiguous");
3090 bool VolatileThis) {
3092 "doing special member lookup into record that isn't fully complete");
3094 if (RValueThis || ConstThis || VolatileThis)
3095 assert((SM == CXXCopyAssignment || SM == CXXMoveAssignment) &&
3096 "constructors and destructors always have unqualified lvalue this");
3097 if (ConstArg || VolatileArg)
3098 assert((SM != CXXDefaultConstructor && SM != CXXDestructor) &&
3099 "parameter-less special members can't have qualified arguments");
3104 llvm::FoldingSetNodeID
ID;
3107 ID.AddInteger(ConstArg);
3108 ID.AddInteger(VolatileArg);
3109 ID.AddInteger(RValueThis);
3110 ID.AddInteger(ConstThis);
3111 ID.AddInteger(VolatileThis);
3115 SpecialMemberCache.FindNodeOrInsertPos(ID, InsertPoint);
3123 SpecialMemberCache.InsertNode(Result, InsertPoint);
3125 if (SM == CXXDestructor) {
3128 DeclareImplicitDestructor(RD);
3133 Result->
setKind(DD && !DD->isDeleted()
3134 ? SpecialMemberOverloadResult::Success
3135 : SpecialMemberOverloadResult::NoMemberOrDeleted);
3143 Expr *Arg =
nullptr;
3149 if (SM == CXXDefaultConstructor) {
3154 DeclareImplicitDefaultConstructor(RD);
3158 if (SM == CXXCopyConstructor || SM == CXXMoveConstructor) {
3162 DeclareImplicitCopyConstructor(RD);
3167 DeclareImplicitMoveConstructor(RD);
3174 DeclareImplicitCopyAssignment(RD);
3179 DeclareImplicitMoveAssignment(RD);
3196 if (SM == CXXCopyConstructor || SM == CXXCopyAssignment)
3204 if (SM != CXXDefaultConstructor) {
3230 assert(SM == CXXDefaultConstructor &&
3231 "lookup for a constructor or assignment operator was empty");
3233 Result->
setKind(SpecialMemberOverloadResult::NoMemberOrDeleted);
3241 for (
NamedDecl *CandDecl : Candidates) {
3242 if (CandDecl->isInvalidDecl())
3248 if (SM == CXXCopyAssignment || SM == CXXMoveAssignment)
3249 AddMethodCandidate(M, Cand, RD, ThisTy, Classification,
3250 llvm::makeArrayRef(&Arg, NumArgs), OCS,
true);
3252 AddOverloadCandidate(CtorInfo.Constructor, CtorInfo.FoundDecl,
3253 llvm::makeArrayRef(&Arg, NumArgs), OCS,
3256 AddOverloadCandidate(M, Cand, llvm::makeArrayRef(&Arg, NumArgs), OCS,
3260 if (SM == CXXCopyAssignment || SM == CXXMoveAssignment)
3261 AddMethodTemplateCandidate(
3262 Tmpl, Cand, RD,
nullptr, ThisTy, Classification,
3263 llvm::makeArrayRef(&Arg, NumArgs), OCS,
true);
3265 AddTemplateOverloadCandidate(
3266 CtorInfo.ConstructorTmpl, CtorInfo.FoundDecl,
nullptr,
3267 llvm::makeArrayRef(&Arg, NumArgs), OCS,
true);
3269 AddTemplateOverloadCandidate(
3270 Tmpl, Cand,
nullptr, llvm::makeArrayRef(&Arg, NumArgs), OCS,
true);
3272 assert(isa<UsingDecl>(Cand.
getDecl()) &&
3273 "illegal Kind of operator = Decl");
3280 Result->
setMethod(cast<CXXMethodDecl>(Best->Function));
3281 Result->
setKind(SpecialMemberOverloadResult::Success);
3285 Result->
setMethod(cast<CXXMethodDecl>(Best->Function));
3286 Result->
setKind(SpecialMemberOverloadResult::NoMemberOrDeleted);
3291 Result->
setKind(SpecialMemberOverloadResult::Ambiguous);
3296 Result->
setKind(SpecialMemberOverloadResult::NoMemberOrDeleted);
3306 LookupSpecialMember(Class, CXXDefaultConstructor,
false,
false,
false,
3309 return cast_or_null<CXXConstructorDecl>(Result.
getMethod());
3316 "non-const, non-volatile qualifiers for copy ctor arg");
3321 return cast_or_null<CXXConstructorDecl>(Result.
getMethod());
3331 return cast_or_null<CXXConstructorDecl>(Result.
getMethod());
3340 DeclareImplicitDefaultConstructor(Class);
3342 DeclareImplicitCopyConstructor(Class);
3344 DeclareImplicitMoveConstructor(Class);
3350 return Class->
lookup(Name);
3355 unsigned Quals,
bool RValueThis,
3356 unsigned ThisQuals) {
3358 "non-const, non-volatile qualifiers for copy assignment arg");
3360 "non-const, non-volatile qualifiers for copy assignment this");
3364 ThisQuals & Qualifiers::Const,
3365 ThisQuals & Qualifiers::Volatile);
3374 unsigned ThisQuals) {
3376 "non-const, non-volatile qualifiers for copy assignment this");
3380 ThisQuals & Qualifiers::Const,
3381 ThisQuals & Qualifiers::Volatile);
3393 return cast<CXXDestructorDecl>(LookupSpecialMember(Class, CXXDestructor,
3394 false,
false,
false,
3395 false,
false).getMethod());
3407 bool AllowRaw,
bool AllowTemplate,
3408 bool AllowStringTemplate,
bool DiagnoseMissing) {
3411 "literal operator lookup can't be ambiguous");
3416 bool FoundRaw =
false;
3417 bool FoundTemplate =
false;
3418 bool FoundStringTemplate =
false;
3419 bool FoundExactMatch =
false;
3421 while (F.hasNext()) {
3424 D = USD->getTargetDecl();
3433 bool IsTemplate =
false;
3434 bool IsStringTemplate =
false;
3435 bool IsExactMatch =
false;
3438 if (FD->getNumParams() == 1 &&
3439 FD->getParamDecl(0)->getType()->getAs<
PointerType>())
3441 else if (FD->getNumParams() == ArgTys.size()) {
3442 IsExactMatch =
true;
3443 for (
unsigned ArgIdx = 0; ArgIdx != ArgTys.size(); ++ArgIdx) {
3444 QualType ParamTy = FD->getParamDecl(ArgIdx)->getType();
3446 IsExactMatch =
false;
3454 if (Params->
size() == 1)
3457 IsStringTemplate =
true;
3461 FoundExactMatch =
true;
3463 AllowTemplate =
false;
3464 AllowStringTemplate =
false;
3465 if (FoundRaw || FoundTemplate || FoundStringTemplate) {
3469 FoundRaw = FoundTemplate = FoundStringTemplate =
false;
3471 }
else if (AllowRaw && IsRaw) {
3473 }
else if (AllowTemplate && IsTemplate) {
3474 FoundTemplate =
true;
3475 }
else if (AllowStringTemplate && IsStringTemplate) {
3476 FoundStringTemplate =
true;
3487 if (FoundExactMatch)
3492 if (FoundRaw && FoundTemplate) {
3495 NoteOverloadCandidate(*I, (*I)->getUnderlyingDecl()->getAsFunction());
3503 return LOLR_Template;
3505 if (FoundStringTemplate)
3506 return LOLR_StringTemplate;
3509 if (DiagnoseMissing) {
3512 << (ArgTys.size() == 2 ? ArgTys[1] :
QualType()) << AllowRaw
3513 << (AllowTemplate || AllowStringTemplate);
3517 return LOLR_ErrorNoDiagnostic;
3525 if (Old ==
nullptr || Old == New) {
3540 if (!Cursor)
return;
3543 if (Cursor == OldFD)
break;
3557 FindAssociatedClassesAndNamespaces(Loc, Args,
3558 AssociatedNamespaces,
3572 for (
auto *NS : AssociatedNamespaces) {
3586 auto *Underlying = D;
3587 if (
auto *USD = dyn_cast<UsingShadowDecl>(D))
3588 Underlying = USD->getTargetDecl();
3590 if (!isa<FunctionDecl>(Underlying) &&
3591 !isa<FunctionTemplateDecl>(Underlying))
3597 bool Visible =
false;
3607 if (AssociatedClasses.count(RD) && isVisible(D)) {
3616 Result.
insert(Underlying);
3630 class ShadowContextRAII;
3632 class VisibleDeclsRecord {
3637 typedef llvm::TinyPtrVector<NamedDecl*> ShadowMapEntry;
3642 typedef llvm::DenseMap<DeclarationName, ShadowMapEntry> ShadowMap;
3645 std::list<ShadowMap> ShadowMaps;
3648 llvm::SmallPtrSet<DeclContext *, 8> VisitedContexts;
3650 friend class ShadowContextRAII;
3656 return !VisitedContexts.insert(Ctx).second;
3660 return VisitedContexts.count(Ctx);
3672 ShadowMaps.back()[ND->
getDeclName()].push_back(ND);
3677 class ShadowContextRAII {
3678 VisibleDeclsRecord &Visible;
3680 typedef VisibleDeclsRecord::ShadowMap ShadowMap;
3683 ShadowContextRAII(VisibleDeclsRecord &Visible) : Visible(Visible) {
3684 Visible.ShadowMaps.emplace_back();
3687 ~ShadowContextRAII() {
3688 Visible.ShadowMaps.pop_back();
3696 std::list<ShadowMap>::reverse_iterator
SM = ShadowMaps.rbegin();
3697 for (std::list<ShadowMap>::reverse_iterator SMEnd = ShadowMaps.rend();
3698 SM != SMEnd; ++
SM) {
3699 ShadowMap::iterator Pos = SM->find(ND->
getDeclName());
3700 if (Pos == SM->end())
3703 for (
auto *D : Pos->second) {
3721 SM == ShadowMaps.rbegin())
3726 if (isa<UsingShadowDecl>(ND) && isa<UsingDecl>(D) &&
3727 cast<UsingShadowDecl>(ND)->getUsingDecl() == D)
3739 class LookupVisibleHelper {
3743 : Consumer(Consumer), IncludeDependentBases(IncludeDependentBases),
3744 LoadExternal(LoadExternal) {}
3747 bool IncludeGlobalScope) {
3751 UnqualUsingDirectiveSet UDirs(SemaRef);
3757 UDirs.visitScopeChain(Initial, S);
3764 if (!IncludeGlobalScope)
3766 ShadowContextRAII Shadow(Visited);
3767 lookupInScope(Initial, Result, UDirs);
3774 if (!IncludeGlobalScope)
3777 ShadowContextRAII Shadow(Visited);
3778 lookupInDeclContext(Ctx, Result,
true,
3784 bool QualifiedNameLookup,
bool InBaseClass) {
3795 if (isa<TranslationUnitDecl>(Ctx) &&
3798 auto &Idents = S.Context.Idents;
3803 Idents.getExternalIdentifierLookup()) {
3804 std::unique_ptr<IdentifierIterator> Iter(External->getIdentifiers());
3805 for (StringRef Name = Iter->Next(); !Name.empty();
3806 Name = Iter->Next())
3811 for (
const auto &Ident : Idents) {
3812 for (
auto I = S.IdResolver.begin(Ident.getValue()),
3813 E = S.IdResolver.end();
3815 if (S.IdResolver.isDeclInScope(*I, Ctx)) {
3817 Consumer.
FoundDecl(ND, Visited.checkHidden(ND), Ctx, InBaseClass);
3831 bool Load = LoadExternal ||
3832 !(isa<TranslationUnitDecl>(Ctx) || isa<NamespaceDecl>(Ctx));
3839 Consumer.
FoundDecl(ND, Visited.checkHidden(ND), Ctx, InBaseClass);
3846 if (QualifiedNameLookup) {
3847 ShadowContextRAII Shadow(Visited);
3851 lookupInDeclContext(I->getNominatedNamespace(), Result,
3852 QualifiedNameLookup, InBaseClass);
3858 if (!Record->hasDefinition())
3861 for (
const auto &B : Record->bases()) {
3866 if (!IncludeDependentBases) {
3879 RD = TD->getTemplatedDecl();
3884 RD = Record->getDecl();
3907 ShadowContextRAII Shadow(Visited);
3908 lookupInDeclContext(RD, Result, QualifiedNameLookup,
3916 for (
auto *Cat : IFace->visible_categories()) {
3917 ShadowContextRAII Shadow(Visited);
3918 lookupInDeclContext(Cat, Result, QualifiedNameLookup,
3923 for (
auto *I : IFace->all_referenced_protocols()) {
3924 ShadowContextRAII Shadow(Visited);
3925 lookupInDeclContext(I, Result, QualifiedNameLookup,
3930 if (IFace->getSuperClass()) {
3931 ShadowContextRAII Shadow(Visited);
3932 lookupInDeclContext(IFace->getSuperClass(), Result, QualifiedNameLookup,
3938 if (IFace->getImplementation()) {
3939 ShadowContextRAII Shadow(Visited);
3940 lookupInDeclContext(IFace->getImplementation(), Result,
3941 QualifiedNameLookup, InBaseClass);
3944 for (
auto *I : Protocol->protocols()) {
3945 ShadowContextRAII Shadow(Visited);
3946 lookupInDeclContext(I, Result, QualifiedNameLookup,
3950 for (
auto *I :
Category->protocols()) {
3951 ShadowContextRAII Shadow(Visited);
3952 lookupInDeclContext(I, Result, QualifiedNameLookup,
3957 if (
Category->getImplementation()) {
3958 ShadowContextRAII Shadow(Visited);
3959 lookupInDeclContext(
Category->getImplementation(), Result,
3960 QualifiedNameLookup,
true);
3966 UnqualUsingDirectiveSet &UDirs) {
3969 assert(!IncludeDependentBases &&
"Unsupported flag for lookupInScope");
3977 FindLocalExternScope FindLocals(Result);
3981 for (
Decl *D : ScopeDecls) {
3982 if (
NamedDecl *ND = dyn_cast<NamedDecl>(D))
3984 Consumer.
FoundDecl(ND, Visited.checkHidden(ND),
nullptr,
false);
4002 if (Method->isInstanceMethod()) {
4008 lookupInDeclContext(IFace, IvarResult,
4023 lookupInDeclContext(Ctx, Result,
false,
4038 lookupInDeclContext(Entity, Result,
false,
4045 for (
const UnqualUsingEntry &UUE : UDirs.getNamespacesFor(Entity))
4046 lookupInDeclContext(
4047 const_cast<DeclContext *>(UUE.getNominatedNamespace()), Result,
4053 ShadowContextRAII Shadow(Visited);
4054 lookupInScope(S->
getParent(), Result, UDirs);
4058 VisibleDeclsRecord Visited;
4060 bool IncludeDependentBases;
4067 bool IncludeGlobalScope,
bool LoadExternal) {
4068 LookupVisibleHelper H(Consumer,
false,
4070 H.lookupVisibleDecls(*
this, S, Kind, IncludeGlobalScope);
4075 bool IncludeGlobalScope,
4076 bool IncludeDependentBases,
bool LoadExternal) {
4077 LookupVisibleHelper H(Consumer, IncludeDependentBases, LoadExternal);
4078 H.lookupVisibleDecls(*
this, Ctx, Kind, IncludeGlobalScope);
4093 Scope *S = CurScope;
4094 PushOnScopeChains(Res, S,
true);
4095 return cast<LabelDecl>(Res);
4099 Res = LookupSingleName(CurScope, II, Loc, LookupLabel, NotForRedeclaration);
4102 if (Res && Res->getDeclContext() != CurContext)
4108 assert(S &&
"Not in a function?");
4109 PushOnScopeChains(Res, S,
true);
4111 return cast<LabelDecl>(Res);
4129 bool EnteringContext,
4130 bool isObjCIvarLookup,
4139 for (; DI != DE; ++DI)
4149 bool AnyVisibleDecls = !NewDecls.empty();
4151 for (; DI != DE; ++DI) {
4153 if (!AnyVisibleDecls) {
4155 AnyVisibleDecls =
true;
4158 NewDecls.push_back(*DI);
4159 }
else if (!AnyVisibleDecls && !(*DI)->isModulePrivate())
4160 NewDecls.push_back(*DI);
4163 if (NewDecls.empty())
4180 Identifiers.clear();
4210 Identifiers.push_back(II);
4237 addName(Name,
nullptr);
4243 addName(Keyword,
nullptr,
nullptr,
true);
4246 void TypoCorrectionConsumer::addName(StringRef Name,
NamedDecl *ND,
4250 StringRef TypoStr = Typo->getName();
4251 unsigned MinED =
abs((
int)Name.size() - (int)TypoStr.size());
4252 if (MinED && TypoStr.size() / MinED < 3)
4257 unsigned UpperBound = (TypoStr.size() + 2) / 3;
4258 unsigned ED = TypoStr.edit_distance(Name,
true, UpperBound);
4259 if (ED > UpperBound)
return;
4263 TC.setCorrectionRange(
nullptr, Result.getLookupNameInfo());
4270 StringRef TypoStr = Typo->getName();
4276 if (TypoStr.size() < 3 &&
4277 (Name != TypoStr || Correction.
getEditDistance(
true) > TypoStr.size()))
4290 if (!CList.empty() && !CList.back().isResolved())
4294 for (TypoResultList::iterator RI = CList.begin(), RIEnd = CList.end();
4295 RI != RIEnd; ++RI) {
4300 if (RI->getCorrectionDecl() == NewND) {
4307 if (CList.empty() || Correction.
isResolved())
4308 CList.push_back(Correction);
4311 CorrectionResults.erase(std::prev(CorrectionResults.end()));
4315 const llvm::MapVector<NamespaceDecl *, bool> &KnownNamespaces) {
4316 SearchNamespaces =
true;
4318 for (
auto KNPair : KnownNamespaces)
4319 Namespaces.addNameSpecifier(KNPair.first);
4321 bool SSIsTemplate =
false;
4325 SSIsTemplate = T->
getTypeClass() == Type::TemplateSpecialization;
4331 for (
unsigned I = 0; I != Types.size(); ++I) {
4332 const auto *TI = Types[I];
4334 CD = CD->getCanonicalDecl();
4335 if (!CD->isDependentType() && !CD->isAnonymousStructOrUnion() &&
4336 !CD->isUnion() && CD->getIdentifier() &&
4337 (SSIsTemplate || !isa<ClassTemplateSpecializationDecl>(CD)) &&
4338 (CD->isBeingDefined() || CD->isCompleteDefinition()))
4339 Namespaces.addNameSpecifier(CD);
4345 if (++CurrentTCIndex < ValidatedCorrections.size())
4346 return ValidatedCorrections[CurrentTCIndex];
4348 CurrentTCIndex = ValidatedCorrections.size();
4349 while (!CorrectionResults.empty()) {
4350 auto DI = CorrectionResults.
begin();
4351 if (DI->second.empty()) {
4352 CorrectionResults.erase(DI);
4356 auto RI = DI->second.begin();
4357 if (RI->second.empty()) {
4358 DI->second.erase(RI);
4359 performQualifiedLookups();
4365 ValidatedCorrections.push_back(TC);
4366 return ValidatedCorrections[CurrentTCIndex];
4369 return ValidatedCorrections[0];
4372 bool TypoCorrectionConsumer::resolveCorrection(
TypoCorrection &Candidate) {
4379 CorrectionValidator->IsObjCIvarLookup,
4381 switch (Result.getResultKind()) {
4391 if (TempMemberContext) {
4394 TempMemberContext =
nullptr;
4397 if (SearchNamespaces)
4398 QualifiedResults.push_back(Candidate);
4408 for (
auto *TRD : Result)
4412 if (SearchNamespaces)
4413 QualifiedResults.push_back(Candidate);
4422 void TypoCorrectionConsumer::performQualifiedLookups() {
4423 unsigned TypoLen = Typo->getName().size();
4425 for (
const auto &NSI : Namespaces) {
4427 const Type *NSType = NSI.NameSpecifier->getAsType();
4435 if (NSDecl->getIdentifier() == QR.getCorrectionAsIdentifierInfo())
4449 if (QR.getCorrectionAsIdentifierInfo() != Typo && TmpED &&
4450 TypoLen / TmpED < 3)
4454 Result.setLookupName(QR.getCorrectionAsIdentifierInfo());
4460 switch (Result.getResultKind()) {
4465 std::string OldQualified;
4466 llvm::raw_string_ostream OldOStream(OldQualified);
4468 OldOStream << Typo->getName();
4472 if (OldOStream.str() == NewQualified)
4476 TRD != TRDEnd; ++TRD) {
4497 QualifiedResults.clear();
4500 TypoCorrectionConsumer::NamespaceSpecifierSet::NamespaceSpecifierSet(
4502 : Context(Context), CurContextChain(buildContextChain(CurContext)) {
4504 CurScopeSpec ? CurScopeSpec->
getScopeRep() :
nullptr) {
4505 llvm::raw_string_ostream SpecifierOStream(CurNameSpecifier);
4513 for (
DeclContext *C : llvm::reverse(CurContextChain)) {
4514 if (
auto *ND = dyn_cast_or_null<NamespaceDecl>(C))
4521 DistanceMap[1].push_back(SI);
4524 auto TypoCorrectionConsumer::NamespaceSpecifierSet::buildContextChain(
4526 assert(Start &&
"Building a context chain from a null context");
4527 DeclContextList Chain;
4539 TypoCorrectionConsumer::NamespaceSpecifierSet::buildNestedNameSpecifier(
4541 unsigned NumSpecifiers = 0;
4543 if (
auto *ND = dyn_cast_or_null<NamespaceDecl>(C)) {
4546 }
else if (
auto *RD = dyn_cast_or_null<RecordDecl>(C)) {
4548 RD->getTypeForDecl());
4552 return NumSpecifiers;
4555 void TypoCorrectionConsumer::NamespaceSpecifierSet::addNameSpecifier(
4558 unsigned NumSpecifiers = 0;
4559 DeclContextList NamespaceDeclChain(buildContextChain(Ctx));
4560 DeclContextList FullNamespaceDeclChain(NamespaceDeclChain);
4563 for (
DeclContext *C : llvm::reverse(CurContextChain)) {
4564 if (NamespaceDeclChain.empty() || NamespaceDeclChain.back() != C)
4566 NamespaceDeclChain.pop_back();
4570 NumSpecifiers = buildNestedNameSpecifier(NamespaceDeclChain, NNS);
4573 if (NamespaceDeclChain.empty()) {
4577 buildNestedNameSpecifier(FullNamespaceDeclChain, NNS);
4579 dyn_cast_or_null<NamedDecl>(NamespaceDeclChain.back())) {
4581 bool SameNameSpecifier =
false;
4582 if (std::find(CurNameSpecifierIdentifiers.begin(),
4583 CurNameSpecifierIdentifiers.end(),
4584 Name) != CurNameSpecifierIdentifiers.end()) {
4585 std::string NewNameSpecifier;
4586 llvm::raw_string_ostream SpecifierOStream(NewNameSpecifier);
4590 SpecifierOStream.flush();
4591 SameNameSpecifier = NewNameSpecifier == CurNameSpecifier;
4593 if (SameNameSpecifier || llvm::find(CurContextIdentifiers, Name) !=
4594 CurContextIdentifiers.end()) {
4598 buildNestedNameSpecifier(FullNamespaceDeclChain, NNS);
4606 if (NNS && !CurNameSpecifierIdentifiers.empty()) {
4609 NumSpecifiers = llvm::ComputeEditDistance(
4610 llvm::makeArrayRef(CurNameSpecifierIdentifiers),
4611 llvm::makeArrayRef(NewNameSpecifierIdentifiers));
4614 SpecifierInfo SI = {Ctx, NNS, NumSpecifiers};
4615 DistanceMap[NumSpecifiers].push_back(SI);
4624 bool EnteringContext,
4625 bool isObjCIvarLookup,
4631 if (MemberContext) {
4633 if (isObjCIvarLookup) {
4634 if (
ObjCIvarDecl *Ivar = Class->lookupInstanceVariable(Name)) {
4659 if (Method->isInstanceMethod() && Method->getClassInterface() &&
4664 = Method->getClassInterface()->lookupInstanceVariable(Name)) {
4676 bool AfterNestedNameSpecifier) {
4677 if (AfterNestedNameSpecifier) {
4690 static const char *
const CTypeSpecs[] = {
4691 "char",
"const",
"double",
"enum",
"float",
"int",
"long",
"short",
4692 "signed",
"struct",
"union",
"unsigned",
"void",
"volatile",
4693 "_Complex",
"_Imaginary",
4695 "extern",
"inline",
"static",
"typedef" 4698 const unsigned NumCTypeSpecs = llvm::array_lengthof(CTypeSpecs);
4699 for (
unsigned I = 0; I != NumCTypeSpecs; ++I)
4726 static const char *
const CastableTypeSpecs[] = {
4727 "char",
"double",
"float",
"int",
"long",
"short",
4728 "signed",
"unsigned",
"void" 4730 for (
auto *kw : CastableTypeSpecs)
4749 static const char *
const CXXExprs[] = {
4750 "delete",
"new",
"operator",
"throw",
"typeid" 4752 const unsigned NumCXXExprs = llvm::array_lengthof(CXXExprs);
4753 for (
unsigned I = 0; I != NumCXXExprs; ++I)
4756 if (isa<CXXMethodDecl>(SemaRef.
CurContext) &&
4757 cast<CXXMethodDecl>(SemaRef.
CurContext)->isInstance())
4776 static const char *
const CStmts[] = {
4777 "do",
"else",
"for",
"goto",
"if",
"return",
"switch",
"while" };
4778 const unsigned NumCStmts = llvm::array_lengthof(CStmts);
4779 for (
unsigned I = 0; I != NumCStmts; ++I)
4824 std::unique_ptr<TypoCorrectionConsumer> Sema::makeTypoCorrectionConsumer(
4830 if (Diags.hasFatalErrorOccurred() || !getLangOpts().SpellChecking ||
4831 DisableTypoCorrection)
4838 isa<CXXMethodDecl>(CurContext))
4852 if (!CodeSynthesisContexts.empty())
4860 IdentifierSourceLocations::iterator locs = TypoCorrectionFailures.find(Typo);
4861 if (locs != TypoCorrectionFailures.end() &&
4862 locs->second.count(TypoName.
getLoc()))
4868 if ((getLangOpts().AltiVec || getLangOpts().ZVector) && Typo->
isStr(
"vector"))
4874 unsigned Limit = getDiagnostics().getDiagnosticOptions().SpellCheckingLimit;
4875 if (Limit && TyposCorrected >= Limit)
4881 if (ErrorRecovery && getLangOpts().Modules &&
4882 getLangOpts().ModulesSearchAll) {
4884 getModuleLoader().lookupMissingImports(Typo->
getName(),
4892 std::unique_ptr<CorrectionCandidateCallback> ClonedCCC = CCC.
clone();
4893 auto Consumer = std::make_unique<TypoCorrectionConsumer>(
4894 *
this, TypoName, LookupKind, S, SS, std::move(ClonedCCC), MemberContext,
4898 bool IsUnqualifiedLookup =
false;
4900 if (MemberContext) {
4901 LookupVisibleDecls(MemberContext, LookupKind, *Consumer);
4905 for (
auto *I : OPT->
quals())
4906 LookupVisibleDecls(I, LookupKind, *Consumer);
4908 }
else if (SS && SS->isSet()) {
4909 QualifiedDC = computeDeclContext(*SS, EnteringContext);
4913 LookupVisibleDecls(QualifiedDC, LookupKind, *Consumer);
4915 IsUnqualifiedLookup =
true;
4920 bool SearchNamespaces
4921 = getLangOpts().CPlusPlus &&
4922 (IsUnqualifiedLookup || (SS && SS->isSet()));
4924 if (IsUnqualifiedLookup || SearchNamespaces) {
4928 for (
const auto &I : Context.
Idents)
4929 Consumer->FoundName(I.getKey());
4935 std::unique_ptr<IdentifierIterator> Iter(External->getIdentifiers());
4937 StringRef Name = Iter->Next();
4941 Consumer->FoundName(Name);
4947 *Consumer->getCorrectionValidator(),
4948 SS && SS->isNotEmpty());
4952 if (SearchNamespaces) {
4954 if (ExternalSource && !LoadedExternalKnownNamespaces) {
4956 LoadedExternalKnownNamespaces =
true;
4957 ExternalSource->ReadKnownNamespaces(ExternalKnownNamespaces);
4958 for (
auto *N : ExternalKnownNamespaces)
4959 KnownNamespaces[N] =
true;
4962 Consumer->addNamespaces(KnownNamespaces);
5005 bool EnteringContext,
5007 bool RecordFailure) {
5010 if (ExternalSource) {
5012 ExternalSource->CorrectTypo(TypoName, LookupKind, S, SS, CCC,
5013 MemberContext, EnteringContext, OPT))
5024 auto Consumer = makeTypoCorrectionConsumer(TypoName, LookupKind, S, SS, CCC,
5025 MemberContext, EnteringContext,
5026 OPT, Mode == CTK_ErrorRecovery);
5032 if (Consumer->empty())
5033 return FailedCorrection(Typo, TypoName.
getLoc(), RecordFailure);
5037 unsigned ED = Consumer->getBestEditDistance(
true);
5038 unsigned TypoLen = Typo->
getName().size();
5039 if (ED > 0 && TypoLen / ED < 3)
5040 return FailedCorrection(Typo, TypoName.
getLoc(), RecordFailure);
5045 return FailedCorrection(Typo, TypoName.
getLoc(), RecordFailure);
5049 if (TypoLen >= 3 && ED > 0 && TypoLen / ED < 3) {
5053 return FailedCorrection(Typo, TypoName.
getLoc(), RecordFailure);
5057 if (!SecondBestTC ||
5058 SecondBestTC.
getEditDistance(
false) > BestTC.getEditDistance(
false)) {
5064 return FailedCorrection(Typo, TypoName.
getLoc(), RecordFailure);
5070 }
else if (SecondBestTC && ObjCMessageReceiver) {
5074 if (BestTC.getCorrection().getAsString() !=
"super") {
5076 BestTC = SecondBestTC;
5077 else if ((*Consumer)[
"super"].front().isKeyword())
5078 BestTC = (*Consumer)[
"super"].front();
5082 if (BestTC.getEditDistance() == 0 ||
5083 BestTC.getCorrection().getAsString() !=
"super")
5084 return FailedCorrection(Typo, TypoName.
getLoc(), RecordFailure);
5093 return FailedCorrection(Typo, TypoName.
getLoc(), RecordFailure && !SecondBestTC);
5140 auto Consumer = makeTypoCorrectionConsumer(TypoName, LookupKind, S, SS, CCC,
5141 MemberContext, EnteringContext,
5142 OPT, Mode == CTK_ErrorRecovery);
5146 if (ExternalSource && Consumer) {
5147 ExternalTypo = ExternalSource->CorrectTypo(
5148 TypoName, LookupKind, S, SS, *Consumer->getCorrectionValidator(),
5149 MemberContext, EnteringContext, OPT);
5151 Consumer->addCorrection(ExternalTypo);
5154 if (!Consumer || Consumer->empty())
5159 unsigned ED = Consumer->getBestEditDistance(
true);
5161 if (!ExternalTypo && ED > 0 && Typo->
getName().size() / ED < 3)
5164 ExprEvalContexts.back().NumTypos++;
5165 return createDelayedTypo(std::move(Consumer), std::move(TDG), std::move(TRC));
5172 CorrectionDecls.clear();
5174 CorrectionDecls.push_back(CDecl);
5176 if (!CorrectionName)
5181 if (CorrectionNameSpec) {
5182 std::string tmpBuffer;
5183 llvm::raw_string_ostream PrefixOStream(tmpBuffer);
5185 PrefixOStream << CorrectionName;
5186 return PrefixOStream.str();
5189 return CorrectionName.getAsString();
5198 return WantTypeSpecifiers || WantExpressionKeywords || WantCXXNamedCasts ||
5199 WantRemainingKeywords || WantObjCSuper;
5201 bool HasNonType =
false;
5202 bool HasStaticMethod =
false;
5203 bool HasNonStaticMethod =
false;
5204 for (
Decl *D : candidate) {
5206 D = FTD->getTemplatedDecl();
5208 if (Method->isStatic())
5209 HasStaticMethod =
true;
5211 HasNonStaticMethod =
true;
5213 if (!isa<TypeDecl>(D))
5217 if (IsAddressOfOperand && HasNonStaticMethod && !HasStaticMethod &&
5218 !candidate.getCorrectionSpecifier())
5221 return WantTypeSpecifiers || HasNonType;
5225 bool HasExplicitTemplateArgs,
5227 : NumArgs(NumArgs), HasExplicitTemplateArgs(HasExplicitTemplateArgs),
5228 CurContext(SemaRef.CurContext), MemberFn(ME) {
5231 !HasExplicitTemplateArgs && NumArgs == 1;
5240 for (
auto *
C : candidate) {
5244 FD = FTD->getTemplatedDecl();
5245 if (!HasExplicitTemplateArgs && !FD) {
5246 if (!(FD = dyn_cast<FunctionDecl>(ND)) && isa<ValueDecl>(ND)) {
5250 QualType ValType = cast<ValueDecl>(ND)->getType();
5256 if (FPT->getNumParams() == NumArgs)
5263 : isa<TypeDecl>(ND)) &&
5266 return NumArgs <= 1 || HasExplicitTemplateArgs || isa<CXXRecordDecl>(ND);
5279 if (MemberFn || !MD->isStatic()) {
5282 ? dyn_cast_or_null<CXXMethodDecl>(MemberFn->
getMemberDecl())
5283 : dyn_cast_or_null<CXXMethodDecl>(CurContext);
5298 bool ErrorRecovery) {
5299 diagnoseTypo(Correction, TypoDiag, PDiag(diag::note_previous_decl),
5306 if (
VarDecl *VD = dyn_cast<VarDecl>(D))
5307 return VD->getDefinition();
5309 return FD->getDefinition();
5310 if (
TagDecl *TD = dyn_cast<TagDecl>(D))
5311 return TD->getDefinition();
5318 return PD->getDefinition();
5320 if (
NamedDecl *TTD = TD->getTemplatedDecl())
5333 Module *Owner = getOwningModule(Def);
5334 assert(Owner &&
"definition of hidden declaration is not in a module");
5337 OwningModules.push_back(Owner);
5339 OwningModules.insert(OwningModules.end(), Merged.begin(), Merged.end());
5341 diagnoseMissingImport(Loc, Def, Def->
getLocation(), OwningModules, MIK,
5349 llvm::StringRef IncludingFile) {
5350 bool IsSystem =
false;
5352 E, IncludingFile, &IsSystem);
5353 return (IsSystem ?
'<' :
'"') + Path + (IsSystem ?
'>' :
'"');
5360 assert(!Modules.empty());
5362 auto NotePrevious = [&] {
5365 case MissingImportKind::Declaration:
5366 DiagID = diag::note_previous_declaration;
5368 case MissingImportKind::Definition:
5369 DiagID = diag::note_previous_definition;
5371 case MissingImportKind::DefaultArgument:
5372 DiagID = diag::note_default_argument_declared_here;
5374 case MissingImportKind::ExplicitSpecialization:
5375 DiagID = diag::note_explicit_specialization_declared_here;
5377 case MissingImportKind::PartialSpecialization:
5378 DiagID = diag::note_partial_specialization_declared_here;
5381 Diag(DeclLoc, DiagID);
5386 llvm::SmallDenseSet<Module*, 8> UniqueModuleSet;
5387 for (
auto *M : Modules) {
5390 if (UniqueModuleSet.insert(M).second)
5391 UniqueModules.push_back(M);
5394 llvm::StringRef IncludingFile;
5396 SourceMgr.getFileEntryForID(SourceMgr.getFileID(UseLoc)))
5397 IncludingFile = FE->tryGetRealPathName();
5399 if (UniqueModules.empty()) {
5402 PP.getModuleHeaderToIncludeForDiagnostics(UseLoc, Modules[0], DeclLoc);
5405 Diag(UseLoc, diag::err_module_unimported_use_global_module_fragment)
5406 << (int)MIK << Decl << !!E
5415 createImplicitModuleImportForErrorRecovery(UseLoc, Modules[0]);
5419 Modules = UniqueModules;
5421 if (Modules.size() > 1) {
5422 std::string ModuleList;
5424 for (
Module *M : Modules) {
5425 ModuleList +=
"\n ";
5426 if (++N == 5 && N != Modules.size()) {
5427 ModuleList +=
"[...]";
5430 ModuleList += M->getFullModuleName();
5433 Diag(UseLoc, diag::err_module_unimported_use_multiple)
5434 << (int)MIK << Decl << ModuleList;
5435 }
else if (
const FileEntry *E = PP.getModuleHeaderToIncludeForDiagnostics(
5436 UseLoc, Modules[0], DeclLoc)) {
5442 Diag(UseLoc, diag::err_module_unimported_use_header)
5443 << (int)MIK << Decl << Modules[0]->getFullModuleName()
5447 Diag(UseLoc, diag::err_module_unimported_use)
5448 << (int)MIK << Decl << Modules[0]->getFullModuleName();
5455 createImplicitModuleImportForErrorRecovery(UseLoc, Modules[0]);
5473 bool ErrorRecovery) {
5474 std::string CorrectedStr = Correction.
getAsString(getLangOpts());
5475 std::string CorrectedQuotedStr = Correction.
getQuoted(getLangOpts());
5482 assert(Decl &&
"import required but no declaration to import");
5485 MissingImportKind::Declaration, ErrorRecovery);
5490 << CorrectedQuotedStr << (ErrorRecovery ? FixTypo :
FixItHint());
5495 Diag(ChosenDecl->getLocation(), PrevNote)
5496 << CorrectedQuotedStr << (ErrorRecovery ?
FixItHint() : FixTypo);
5503 TypoExpr *Sema::createDelayedTypo(std::unique_ptr<TypoCorrectionConsumer> TCC,
5506 assert(TCC &&
"createDelayedTypo requires a valid TypoCorrectionConsumer");
5508 auto &
State = DelayedTypos[TE];
5509 State.Consumer = std::move(TCC);
5510 State.DiagHandler = std::move(TDG);
5511 State.RecoveryHandler = std::move(TRC);
5513 TypoExprs.push_back(TE);
5518 auto Entry = DelayedTypos.find(TE);
5519 assert(Entry != DelayedTypos.end() &&
5520 "Failed to get the state for a TypoExpr!");
5521 return Entry->second;
5525 DelayedTypos.erase(TE);
SourceLocation getLoc() const
getLoc - Returns the main location of the declaration name.
Defines the clang::ASTContext interface.
void setScopeInfo(unsigned scopeDepth, unsigned parameterIndex)
Name lookup results in an ambiguity because multiple definitions of entity that meet the lookup crite...
void setImplicit(bool I=true)
Represents a function declaration or definition.
FunctionCallFilterCCC(Sema &SemaRef, unsigned NumArgs, bool HasExplicitTemplateArgs, MemberExpr *ME=nullptr)
Name lookup found a set of overloaded functions that met the criteria.
static DiagnosticBuilder Diag(DiagnosticsEngine *Diags, const LangOptions &Features, FullSourceLoc TokLoc, const char *TokBegin, const char *TokRangeBegin, const char *TokRangeEnd, unsigned DiagID)
Produce a diagnostic highlighting some portion of a literal.
bool isForRedeclaration() const
True if this lookup is just looking for an existing declaration.
SourceRange getCorrectionRange() const
bool isPredefinedLibFunction(unsigned ID) const
Determines whether this builtin is a predefined libc/libm function, such as "malloc", where we know the signature a priori.
void setOrigin(CXXRecordDecl *Rec)
CXXMethodDecl * getMethod() const
no exception specification
PointerType - C99 6.7.5.1 - Pointer Declarators.
A (possibly-)qualified type.
Simple class containing the result of Sema::CorrectTypo.
ValueDecl * getMemberDecl() const
Retrieve the member declaration to which this expression refers.
bool hasVisibleDeclarationSlow(const NamedDecl *D, llvm::SmallVectorImpl< Module *> *Modules)
virtual unsigned RankCandidate(const TypoCorrection &candidate)
Method used by Sema::CorrectTypo to assign an "edit distance" rank to a candidate (where a lower valu...
Template argument deduction was successful.
Defines the clang::FileManager interface and associated types.
Ordinary name lookup, which finds ordinary names (functions, variables, typedefs, etc...
void setLookupName(DeclarationName Name)
Sets the name to look up.
bool LookupName(LookupResult &R, Scope *S, bool AllowBuiltinCreation=false)
Perform unqualified name lookup starting from a given scope.
AmbiguityKind getAmbiguityKind() const
Look up the name of an Objective-C protocol.
Filter makeFilter()
Create a filter for this result set.
CXXMethodDecl * LookupMovingAssignment(CXXRecordDecl *Class, unsigned Quals, bool RValueThis, unsigned ThisQuals)
Look up the moving assignment operator for the given class.
FunctionType - C99 6.7.5.3 - Function Declarators.
Provides information about an attempted template argument deduction, whose success or failure was des...
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee...
void addConst()
Add the const type qualifier to this QualType.
Microsoft's '__super' specifier, stored as a CXXRecordDecl* of the class it appeared in...
void ForceDeclarationOfImplicitMembers(CXXRecordDecl *Class)
Force the declaration of any implicitly-declared members of this class.
The template argument is an expression, and we've not resolved it to one of the other forms yet...
unsigned size() const
Retrieve the number of template arguments in this template argument list.
bool isSingleTagDecl() const
Asks if the result is a single tag decl.
void erase()
Erase the last element returned from this iterator.
ConstructorInfo getConstructorInfo(NamedDecl *ND)
Decl - This represents one declaration (or definition), e.g.
__DEVICE__ long long abs(long long __n)
bool isModuleVisible(const Module *M, bool ModulePrivate=false)
NestedNameSpecifier * getPrefix() const
Return the prefix of this nested name specifier.
SmallVectorImpl< NamedDecl * >::iterator decl_iterator
Name lookup results in an ambiguity because multiple nonstatic entities that meet the lookup criteria...
Defines the C++ template declaration subclasses.
bool LookupParsedName(LookupResult &R, Scope *S, CXXScopeSpec *SS, bool AllowBuiltinCreation=false, bool EnteringContext=false)
Performs name lookup for a name that was parsed in the source code, and may contain a C++ scope speci...
Classification Classify(ASTContext &Ctx) const
Classify - Classify this expression according to the C++11 expression taxonomy.
OverloadedOperatorKind getCXXOverloadedOperator() const
If this name is the name of an overloadable operator in C++ (e.g., operator+), retrieve the kind of o...
bool isTemplateParamScope() const
isTemplateParamScope - Return true if this scope is a C++ template parameter scope.
void swap(CXXBasePaths &Other)
Swap this data structure's contents with another CXXBasePaths object.
SmallVector< CodeSynthesisContext, 16 > CodeSynthesisContexts
List of active code synthesis contexts.
static bool hasVisibleDeclarationImpl(Sema &S, const NamedDecl *D, llvm::SmallVectorImpl< Module *> *Modules, Filter F)
Decl * getPreviousDecl()
Retrieve the previous declaration that declares the same entity as this declaration, or NULL if there is no previous declaration.
NamedDecl * getDecl() const
The base class of the type hierarchy.
SourceLocation getBeginLoc() const
getBeginLoc - Retrieve the location of the first token.
MissingImportKind
Kinds of missing import.
bool isDerivedFrom(const CXXRecordDecl *Base) const
Determine whether this class is derived from the class Base.
The template argument is a declaration that was provided for a pointer, reference, or pointer to member non-type template parameter.
Represent a C++ namespace.
RedeclarationKind
Specifies whether (or how) name lookup is being performed for a redeclaration (vs.
Ambiguous candidates found.
NamedDecl * getParam(unsigned Idx)
AccessSpecifier
A C++ access specifier (public, private, protected), plus the special value "none" which means differ...
const NestedNameSpecifier * Specifier
Look up of a name that precedes the '::' scope resolution operator in C++.
void makeKeyword()
Mark this TypoCorrection as being a keyword.
static FunctionDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation NLoc, DeclarationName N, QualType T, TypeSourceInfo *TInfo, StorageClass SC, bool isInlineSpecified=false, bool hasWrittenPrototype=true, ConstexprSpecKind ConstexprKind=CSK_unspecified, Expr *TrailingRequiresClause=nullptr)
bool needsImplicitMoveAssignment() const
Determine whether this class should get an implicit move assignment operator or if any existing speci...
Scope * getContinueParent()
getContinueParent - Return the closest scope that a continue statement would be affected by...
void setCorrectionSpecifier(NestedNameSpecifier *NNS)
Represents a path from a specific derived class (which is not represented as part of the path) to a p...
LiteralOperatorLookupResult
The possible outcomes of name lookup for a literal operator.
unsigned getIdentifierNamespace() const
Represents a C++ constructor within a class.
LLVM_ATTRIBUTE_REINITIALIZES void clear()
Clears out any current state.
bool isCompleteDefinition() const
Return true if this decl has its body fully specified.
lookups_range noload_lookups(bool PreserveInternalState) const
Look up a namespace name within a C++ using directive or namespace alias definition, ignoring non-namespace names (C++ [basic.lookup.udir]p1).
CXXMethodDecl * DeclareImplicitMoveAssignment(CXXRecordDecl *ClassDecl)
Declare the implicit move assignment operator for the given class.
Consumes visible declarations found when searching for all visible names within a given scope or cont...
An identifier, stored as an IdentifierInfo*.
CXXConstructorDecl * LookupMovingConstructor(CXXRecordDecl *Class, unsigned Quals)
Look up the moving constructor for the given class.
std::list< CXXBasePath >::iterator paths_iterator
DeclContext::lookup_result Decls
The set of declarations found inside this base class subobject.
Represents a variable declaration or definition.
CXXMethodDecl * LookupCopyingAssignment(CXXRecordDecl *Class, unsigned Quals, bool RValueThis, unsigned ThisQuals)
Look up the copying assignment operator for the given class.
static NestedNameSpecifier * Create(const ASTContext &Context, NestedNameSpecifier *Prefix, IdentifierInfo *II)
Builds a specifier combining a prefix and an identifier.
DeclarationName getLookupName() const
Gets the name to look up.
const T * getAs() const
Member-template getAs<specific type>'.
PrintingPolicy getPrintingPolicy() const
Retrieve a suitable printing policy for diagnostics.
static bool HasOnlyStaticMembers(InputIterator First, InputIterator Last)
Determine whether the given set of member declarations contains only static members, nested types, and enumerators.
bool isInObjcMethodScope() const
isInObjcMethodScope - Return true if this scope is, or is contained in, an Objective-C method body...
Represents an empty template argument, e.g., one that has not been deduced.
Extra information about a function prototype.
static bool CanDeclareSpecialMemberFunction(const CXXRecordDecl *Class)
Determine whether we can declare a special member function within the class at this point...
bool needsImplicitCopyAssignment() const
Determine whether this class needs an implicit copy assignment operator to be lazily declared...
void setNotFoundInCurrentInstantiation()
Note that while no result was found in the current instantiation, there were dependent base classes t...
ObjCMethodDecl - Represents an instance or class method declaration.
NamedDecl * getUnderlyingDecl()
Looks through UsingDecls and ObjCCompatibleAliasDecls for the underlying named decl.
static bool FindOMPReductionMember(const CXXBaseSpecifier *Specifier, CXXBasePath &Path, DeclarationName Name)
Base-class lookup callback that determines whether there exists an OpenMP declare reduction member wi...
A namespace, stored as a NamespaceDecl*.
unsigned getDiagID() const
bool isInvalidDecl() const
Stores a list of template parameters for a TemplateDecl and its derived classes.
Describes how types, statements, expressions, and declarations should be printed. ...
SpecifierKind getKind() const
Determine what kind of nested name specifier is stored.
Look up an ordinary name that is going to be redeclared as a name with linkage.
Represents a parameter to a function.
Defines the clang::Expr interface and subclasses for C++ expressions.
void addKeywordResult(StringRef Keyword)
static void InsertOCLBuiltinDeclarationsFromTable(Sema &S, LookupResult &LR, IdentifierInfo *II, const unsigned FctIndex, const unsigned Len)
When trying to resolve a function name, if isOpenCLBuiltin() returns a non-null <Index, Len> pair, then the name is referencing an OpenCL builtin function.
bool WantExpressionKeywords
void setMethod(CXXMethodDecl *MD)
ModuleKind Kind
The kind of this module.
IdentifierInfo * getIdentifier() const
Get the identifier that names this declaration, if there is one.
Types, declared with 'struct foo', typedefs, etc.
Represents a struct/union/class.
bool LookupInSuper(LookupResult &R, CXXRecordDecl *Class)
Perform qualified name lookup into all base classes of the given class.
DeclarationName getDeclName() const
Get the actual, stored name of the declaration, which may be a special name.
bool Encloses(const DeclContext *DC) const
Determine whether this declaration context encloses the declaration context DC.
FunctionType::ExtInfo ExtInfo
Represents a class template specialization, which refers to a class template with a given set of temp...
One of these records is kept for each identifier that is lexed.
Name lookup results in an ambiguity; use getAmbiguityKind to figure out what kind of ambiguity we hav...
bool isStr(const char(&Str)[StrLen]) const
Return true if this is the identifier for the specified string.
std::string getQuoted(const LangOptions &LO) const
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
DeclarationName getCorrection() const
Gets the DeclarationName of the typo correction.
The results of name lookup within a DeclContext.
The template argument is an integral value stored in an llvm::APSInt that was provided for an integra...
TemplateDecl * getAsTemplateDecl() const
Retrieve the underlying template declaration that this template name refers to, if known...
Base class for callback objects used by Sema::CorrectTypo to check the validity of a potential typo c...
sema::BlockScopeInfo * getCurBlock()
Retrieve the current block, if any.
void setAmbiguousBaseSubobjectTypes(CXXBasePaths &P)
Make these results show that the name was found in base classes of different types.
NameKind getNameKind() const
Determine what kind of name this is.
const Type * getAsType() const
Retrieve the type stored in this nested name specifier.
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...
This declaration is a friend function.
void setVisibleDespiteOwningModule()
Set that this declaration is globally visible, even if it came from a module that is not visible...
const DeclarationNameInfo & getLookupNameInfo() const
Gets the name info to look up.
conversion_iterator conversion_end() const
bool isReferenceType() const
The iterator over UnresolvedSets.
void addCorrectionDecl(NamedDecl *CDecl)
Add the given NamedDecl to the list of NamedDecls that are the declarations associated with the Decla...
bool isDefinedOutsideFunctionOrMethod() const
isDefinedOutsideFunctionOrMethod - This predicate returns true if this scoped decl is defined outside...
static std::string getIncludeStringForHeader(Preprocessor &PP, const FileEntry *E, llvm::StringRef IncludingFile)
Get a "quoted.h" or <angled.h> include path to use in a diagnostic suggesting the addition of a #incl...
bool Equals(const DeclContext *DC) const
Determine whether this declaration context is equivalent to the declaration context DC...
bool isExternallyDeclarable() const
Determine whether this declaration can be redeclared in a different translation unit.
LookupResultKind getResultKind() const
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Scope * getBreakParent()
getBreakParent - Return the closest scope that a break statement would be affected by...
No entity found met the criteria within the current instantiation,, but there were dependent base cla...
bool requiresImport() const
Returns whether this typo correction is correcting to a declaration that was declared in a module tha...
Describes a module or submodule.
SpecialMemberOverloadResult - The overloading result for a special member function.
void setCallbackDistance(unsigned ED)
An r-value expression (a pr-value in the C++11 taxonomy) produces a temporary value.
DeclClass * getAsSingle() const
StringRef getTopLevelModuleName() const
Retrieve the name of the top-level module.
CXXBasePaths * getBasePaths() const
Return the base paths structure that's associated with these results, or null if none is...
bool isTemplateNameLookup() const
CXXRecordDecl * getAsRecordDecl() const
Retrieve the record declaration stored in this nested name specifier.
Look up implicit 'self' parameter of an objective-c method.
IdentifierInfo * getAsIdentifier() const
Retrieve the identifier stored in this nested name specifier.
void resolveKind()
Resolves the result kind of the lookup, possibly hiding decls.
Represents the results of name lookup.
void setAmbiguousBaseSubobjects(CXXBasePaths &P)
Make these results show that the name was found in distinct base classes of the same type...
static DeclAccessPair make(NamedDecl *D, AccessSpecifier AS)
virtual bool includeHiddenDecls() const
Determine whether hidden declarations (from unimported modules) should be given to this consumer...
ObjCMethodDecl * getCurMethodDecl()
getCurMethodDecl - If inside of a method body, this returns a pointer to the method decl for the meth...
Namespaces, declared with 'namespace foo {}'.
static void LookupPotentialTypoResult(Sema &SemaRef, LookupResult &Res, IdentifierInfo *Name, Scope *S, CXXScopeSpec *SS, DeclContext *MemberContext, bool EnteringContext, bool isObjCIvarLookup, bool FindHidden)
Perform name lookup for a possible result for typo correction.
HeaderSearch & getHeaderSearchInfo() const
void setQualifierDistance(unsigned ED)
bool hasTagIdentifierNamespace() const
Succeeded, but refers to a deleted function.
bool ValidateCandidate(const TypoCorrection &candidate) override
Simple predicate used by the default RankCandidate to determine whether to return an edit distance of...
CXXConstructorDecl * DeclareImplicitMoveConstructor(CXXRecordDecl *ClassDecl)
Declare the implicit move constructor for the given class.
Look up all declarations in a scope with the given name, including resolved using declarations...
static NamedDecl * getDefinitionToImport(NamedDecl *D)
Find which declaration we should import to provide the definition of the given declaration.
NamespaceAliasDecl * getAsNamespaceAlias() const
Retrieve the namespace alias stored in this nested name specifier.
TemplateDecl * getAsTypeTemplateDecl(Decl *D)
const clang::PrintingPolicy & getPrintingPolicy() const
IdentifierInfoLookup * getExternalIdentifierLookup() const
Retrieve the external identifier lookup object, if any.
Represents a declaration of a type.
A set of unresolved declarations.
static unsigned getIDNS(Sema::LookupNameKind NameKind, bool CPlusPlus, bool Redeclaration)
Module * Parent
The parent of this module.
const Type * getClass() const
Look up the name of an OpenMP user-defined reduction operation.
std::function< ExprResult(Sema &, TypoExpr *, TypoCorrection)> TypoRecoveryCallback
Scope - A scope is a transient data structure that is used while parsing the program.
void DiagnoseAmbiguousLookup(LookupResult &Result)
Produce a diagnostic describing the ambiguity that resulted from name lookup.
const Type * getTypePtr() const
Retrieves a pointer to the underlying (unqualified) type.
CXXRecordDecl * getCanonicalDecl() override
Retrieves the "canonical" declaration of the given declaration.
TypoExpr - Internal placeholder for expressions where typo correction still needs to be performed and...
using_directives_range using_directives()
void append(iterator I, iterator E)
Represents a C++ nested-name-specifier or a global scope specifier.
base_class_iterator bases_begin()
Represents an Objective-C protocol declaration.
lookups_range lookups() const
DeclContext * getLexicalDeclContext()
getLexicalDeclContext - The declaration context where this Decl was lexically declared (LexicalDC)...
LabelDecl * LookupOrCreateLabel(IdentifierInfo *II, SourceLocation IdentLoc, SourceLocation GnuLabelLoc=SourceLocation())
LookupOrCreateLabel - Do a name lookup of a label with the specified name.
const LangOptions & getLangOpts() const
Labels, declared with 'x:' and referenced with 'goto x'.
const TypoCorrection & getNextCorrection()
Return the next typo correction that passes all internal filters and is deemed valid by the consumer'...
CXXDestructorDecl * getDestructor() const
Returns the destructor decl for this class.
Represents an ObjC class declaration.
void addDecl(NamedDecl *D)
Add a declaration to these results with its natural access.
Member name lookup, which finds the names of class/struct/union members.
void print(raw_ostream &OS, const PrintingPolicy &Policy, bool ResolveTemplateArguments=false) const
Print this nested name specifier to the given output stream.
virtual Decl * getCanonicalDecl()
Retrieves the "canonical" declaration of the given declaration.
lookup_result lookup(DeclarationName Name) const
lookup - Find the declarations (if any) with the given Name in this context.
ExtInfo withCallingConv(CallingConv cc) const
static const unsigned InvalidDistance
CXXSpecialMember
Kinds of C++ special members.
unsigned getFlags() const
getFlags - Return the flags for this scope.
bool WantRemainingKeywords
void LookupVisibleDecls(Scope *S, LookupNameKind Kind, VisibleDeclConsumer &Consumer, bool IncludeGlobalScope=true, bool LoadExternal=true)
Sema - This implements semantic analysis and AST building for C.
udir_range using_directives() const
Returns iterator range [First, Last) of UsingDirectiveDecls stored within this context.
NamedDecl * getFoundDecl() const
Get the correction declaration found by name lookup (before we looked through using shadow declaratio...
void setNamingClass(CXXRecordDecl *Record)
Sets the 'naming class' for this lookup.
ArrayRef< Module * > getModulesWithMergedDefinition(const NamedDecl *Def)
Get the additional modules in which the definition Def has been merged.
virtual void FoundDecl(NamedDecl *ND, NamedDecl *Hiding, DeclContext *Ctx, bool InBaseClass)=0
Invoked each time Sema::LookupVisibleDecls() finds a declaration visible from the current scope or co...
CXXRecordDecl * getAsCXXRecordDecl() const
Retrieves the CXXRecordDecl that this type refers to, either because the type is a RecordType or beca...
Represents a prototype with parameter type info, e.g.
std::string CurrentModule
The name of the current module, of which the main source file is a part.
This declaration is a C++ operator declared in a non-class context.
virtual void EnteredContext(DeclContext *Ctx)
Callback to inform the client that Sema entered into a new context to find a visible declaration...
bool hasMergedDefinitionInCurrentModule(NamedDecl *Def)
The return type of classify().
std::pair< unsigned, unsigned > getDepthAndIndex(NamedDecl *ND)
Retrieve the depth and index of a template parameter.
DeclarationNameTable DeclarationNames
Provides lookups to, and iteration over, IdentiferInfo objects.
SourceRange getRange() const
unsigned getEditDistance(bool Normalized=true) const
Gets the "edit distance" of the typo correction from the typo.
std::function< void(const TypoCorrection &)> TypoDiagnosticGenerator
This declaration is a friend class.
std::string getAsString(const LangOptions &LO) const
static bool LookupAnyMember(const CXXBaseSpecifier *Specifier, CXXBasePath &Path, DeclarationName Name)
Callback that looks for any member of a class with the given name.
void runWithSufficientStackSpace(llvm::function_ref< void()> Diag, llvm::function_ref< void()> Fn)
Run a given function on a stack with "sufficient" space.
virtual bool ValidateCandidate(const TypoCorrection &candidate)
Simple predicate used by the default RankCandidate to determine whether to return an edit distance of...
void ArgumentDependentLookup(DeclarationName Name, SourceLocation Loc, ArrayRef< Expr *> Args, ADLResult &Functions)
bool isInlineNamespace() const
static bool LookupQualifiedNameInUsingDirectives(Sema &S, LookupResult &R, DeclContext *StartDC)
Perform qualified name lookup in the namespaces nominated by using directives by the given context...
DeclContext * getLexicalParent()
getLexicalParent - Returns the containing lexical DeclContext.
QualType getCXXNameType() const
If this name is one of the C++ names (of a constructor, destructor, or conversion function)...
NamespaceDecl * getAsNamespace() const
Retrieve the namespace stored in this nested name specifier.
TypoExpr * CorrectTypoDelayed(const DeclarationNameInfo &Typo, Sema::LookupNameKind LookupKind, Scope *S, CXXScopeSpec *SS, CorrectionCandidateCallback &CCC, TypoDiagnosticGenerator TDG, TypoRecoveryCallback TRC, CorrectTypoKind Mode, DeclContext *MemberContext=nullptr, bool EnteringContext=false, const ObjCObjectPointerType *OPT=nullptr)
Try to "correct" a typo in the source code by finding visible declarations whose names are similar to...
This represents one expression.
Defines the clang::LangOptions interface.
void setOpenCLExtensionForDecl(Decl *FD, llvm::StringRef Exts)
Set OpenCL extensions for a declaration which can only be used when these OpenCL extensions are enabl...
LookupNameKind
Describes the kind of name lookup to perform.
ExprValueKind
The categorization of expression values, currently following the C++11 scheme.
llvm::StringRef getAsString(SyncScope S)
bool isDeclScope(Decl *D)
isDeclScope - Return true if this is the scope that the specified decl is declared in...
Look up the name of an OpenMP user-defined mapper.
int SubobjectNumber
Identifies which base class subobject (of type Base->getType()) this base path element refers to...
static FindResult find(Expr *E)
Finds the overloaded expression in the given expression E of OverloadTy.
DeclContext * getEntity() const
void makeMergedDefinitionVisible(NamedDecl *ND)
Make a merged definition of an existing hidden definition ND visible at the specified location...
void setHideTags(bool Hide)
Sets whether tag declarations should be hidden by non-tag declarations during resolution.
This file defines the classes used to store parsed information about declaration-specifiers and decla...
const T * castAs() const
Member-template castAs<specific type>.
The template argument is a null pointer or null pointer to member that was provided for a non-type te...
Represents a C++ destructor within a class.
std::string getAsString() const
Retrieve the human-readable string for this name.
This declaration is an OpenMP user defined reduction construction.
bool isAnonymousNamespace() const
Returns true if this is an anonymous namespace declaration.
const CXXRecordDecl * getTemplateInstantiationPattern() const
Retrieve the record declaration from which this record could be instantiated.
SmallVector< SwitchInfo, 8 > SwitchStack
SwitchStack - This is the current set of active switch statements in the block.
QualType getTagDeclType(const TagDecl *Decl) const
Return the unique reference to the type for the specified TagDecl (struct/union/class/enum) decl...
static NamedDecl * findAcceptableDecl(Sema &SemaRef, NamedDecl *D, unsigned IDNS)
Retrieve the visible declaration corresponding to D, if any.
Defines the clang::Preprocessor interface.
void setRequiresImport(bool Req)
Name lookup results in an ambiguity because an entity with a tag name was hidden by an entity with an...
bool isFileContext() const
DeclContext * getDeclContext()
static bool FindNestedNameSpecifierMember(const CXXBaseSpecifier *Specifier, CXXBasePath &Path, DeclarationName Name)
Base-class lookup callback that determines whether there exists a member with the given name that can...
CXXRecordDecl * getDefinition() const
Overload resolution succeeded.
bool hasAnyDependentBases() const
Determine whether this class has any dependent base classes which are not the current instantiation...
bool isTemplateParameter() const
isTemplateParameter - Determines whether this declaration is a template parameter.
Represents a C++ template name within the type system.
bool needsImplicitDestructor() const
Determine whether this class needs an implicit destructor to be lazily declared.
A namespace alias, stored as a NamespaceAliasDecl*.
bool isVisible(const NamedDecl *D)
Determine whether a declaration is visible to name lookup.
VarDecl * getTemplateInstantiationPattern() const
Retrieve the variable declaration from which this variable could be instantiated, if it is an instant...
IdentifierInfo * getAsIdentifierInfo() const
Retrieve the IdentifierInfo * stored in this declaration name, or null if this declaration name isn't...
This declaration is an OpenMP user defined mapper.
bool isClassScope() const
isClassScope - Return true if this scope is a class/struct/union scope.
bool isFunctionOrMethod() const
Module * getOwningModule(const Decl *Entity)
Get the module owning an entity.
bool isSingleResult() const
Determines if this names a single result which is not an unresolved value using decl.
DeclContext * getParent()
getParent - Returns the containing DeclContext.
void addCorrection(TypoCorrection Correction)
QualType getRecordType(const RecordDecl *Decl) const
static bool FindOrdinaryMember(const CXXBaseSpecifier *Specifier, CXXBasePath &Path, DeclarationName Name)
Base-class lookup callback that determines whether there exists a member with the given name...
void diagnoseMissingImport(SourceLocation Loc, NamedDecl *Decl, MissingImportKind MIK, bool Recover=true)
Diagnose that the specified declaration needs to be visible but isn't, and suggest a module import th...
QualType getFunctionType(QualType ResultTy, ArrayRef< QualType > Args, const FunctionProtoType::ExtProtoInfo &EPI) const
Return a normal function type with a typed argument list.
bool isDependentContext() const
Determines whether this context is dependent on a template parameter.
bool needsImplicitDefaultConstructor() const
Determine if we need to declare a default constructor for this class.
QualType getTypeDeclType(const TypeDecl *Decl, const TypeDecl *PrevDecl=nullptr) const
Return the unique reference to the type for the specified type declaration.
NamedDecl * LookupSingleName(Scope *S, DeclarationName Name, SourceLocation Loc, LookupNameKind NameKind, RedeclarationKind Redecl=NotForRedeclaration)
Look up a name, looking for a single declaration.
bool isNull() const
Return true if this QualType doesn't point to a type yet.
A type, stored as a Type*.
CXXConstructorDecl * LookupCopyingConstructor(CXXRecordDecl *Class, unsigned Quals)
Look up the copying constructor for the given class.
Name lookup results in an ambiguity because multiple entities that meet the lookup criteria were foun...
FriendObjectKind getFriendObjectKind() const
Determines whether this declaration is the object of a friend declaration and, if so...
CXXDestructorDecl * LookupDestructor(CXXRecordDecl *Class)
Look for the destructor of the given class.
unsigned getBuiltinID() const
Return a value indicating whether this is a builtin function.
bool LookupBuiltin(LookupResult &R)
Lookup a builtin function, when name lookup would otherwise fail.
bool hasVisibleMemberSpecialization(const NamedDecl *D, llvm::SmallVectorImpl< Module *> *Modules=nullptr)
Determine if there is a visible declaration of D that is a member specialization declaration (as oppo...
static void AddOpenCLExtensions(Sema &S, const OpenCLBuiltinStruct &BIDecl, FunctionDecl *FDecl)
Add extensions to the function declaration.
RecordDecl * getDecl() const
static void GetOpenCLBuiltinFctOverloads(ASTContext &Context, unsigned GenTypeMaxCnt, std::vector< QualType > &FunctionList, SmallVector< QualType, 1 > &RetTypes, SmallVector< SmallVector< QualType, 1 >, 5 > &ArgTypes)
Create a list of the candidate function overloads for an OpenCL builtin function. ...
static bool isImplicitlyDeclaredMemberFunctionName(DeclarationName Name)
Determine whether this is the name of an implicitly-declared special member function.
NestedNameSpecifier * getScopeRep() const
Retrieve the representation of the nested-name-specifier.
const CXXBaseSpecifier * Base
The base specifier that states the link from a derived class to a base class, which will be followed ...
static Module * getDefiningModule(Sema &S, Decl *Entity)
Find the module in which the given declaration was defined.
OpaqueValueExpr - An expression referring to an opaque object of a fixed type and value class...
SmallVectorImpl< OverloadCandidate >::iterator iterator
Tag name lookup, which finds the names of enums, classes, structs, and unions.
A reference to an overloaded function set, either an UnresolvedLookupExpr or an UnresolvedMemberExpr...
decl_type * getPreviousDecl()
Return the previous declaration of this declaration or NULL if this is the first declaration.
param_type_range param_types() const
ExtProtoInfo getExtProtoInfo() const
FunctionDecl * getAsFunction() LLVM_READONLY
Returns the function itself, or the templated function if this is a function template.
ASTContext & getASTContext() const
FunctionDecl * getTemplatedDecl() const
Get the underlying function declaration of the template.
Encodes a location in the source.
void addVolatile()
Add the volatile type qualifier to this QualType.
IdentifierInfo & get(StringRef Name)
Return the identifier token info for the specified named identifier.
QualType getReturnType() const
Members, declared with object declarations within tag definitions.
void FindAssociatedClassesAndNamespaces(SourceLocation InstantiationLoc, ArrayRef< Expr *> Args, AssociatedNamespaceSet &AssociatedNamespaces, AssociatedClassSet &AssociatedClasses)
Find the associated classes and namespaces for argument-dependent lookup for a call with the given se...
DeclarationName getName() const
getName - Returns the embedded declaration name.
Represents the declaration of a struct/union/class/enum.
void FoundName(StringRef Name)
Represents the declaration of a label.
Cached information about one file (either on disk or in the virtual file system). ...
bool hasVisibleMergedDefinition(NamedDecl *Def)
bool hasVisibleDefaultArgument(const NamedDecl *D, llvm::SmallVectorImpl< Module *> *Modules=nullptr)
Determine if the template parameter D has a visible default argument.
Represents a static or instance method of a struct/union/class.
static bool FindOMPMapperMember(const CXXBaseSpecifier *Specifier, CXXBasePath &Path, DeclarationName Name)
Base-class lookup callback that determines whether there exists an OpenMP declare mapper member with ...
bool hasVisibleDefinition(NamedDecl *D, NamedDecl **Suggested, bool OnlyNeedComplete=false)
Determine if D has a visible definition.
Represents a C++ nested name specifier, such as "\::std::vector<int>::".
Name lookup found an unresolvable value declaration and cannot yet complete.
bool isModuleVisible(const Module *M) const
Determine whether the specified module would be visible to a lookup at the end of this module...
llvm::DenseSet< Module * > & getLookupModules()
Get the set of additional modules that should be checked during name lookup.
ObjCCategoryDecl - Represents a category declaration.
virtual std::unique_ptr< CorrectionCandidateCallback > clone()=0
Clone this CorrectionCandidateCallback.
SourceRange getContextRange() const
Gets the source range of the context of this name; for C++ qualified lookups, this is the source rang...
This is a fragment of the global module within some C++ module.
static bool hasVisibleDefaultArgument(Sema &S, const ParmDecl *D, llvm::SmallVectorImpl< Module *> *Modules)
OverloadingResult BestViableFunction(Sema &S, SourceLocation Loc, OverloadCandidateSet::iterator &Best)
Find the best viable function on this overload set, if it exists.
TemplateDeductionResult DeduceTemplateArguments(ClassTemplatePartialSpecializationDecl *Partial, const TemplateArgumentList &TemplateArgs, sema::TemplateDeductionInfo &Info)
Perform template argument deduction to determine whether the given template arguments match the given...
TypoCorrection CorrectTypo(const DeclarationNameInfo &Typo, Sema::LookupNameKind LookupKind, Scope *S, CXXScopeSpec *SS, CorrectionCandidateCallback &CCC, CorrectTypoKind Mode, DeclContext *MemberContext=nullptr, bool EnteringContext=false, const ObjCObjectPointerType *OPT=nullptr, bool RecordFailure=true)
Try to "correct" a typo in the source code by finding visible declarations whose names are similar to...
Look up any declaration with any name.
bool isAnyPointerType() const
A class for iterating through a result set and possibly filtering out results.
const TypoExprState & getTypoExprState(TypoExpr *TE) const
Represents one property declaration in an Objective-C interface.
ObjCProtocolDecl * LookupProtocol(IdentifierInfo *II, SourceLocation IdLoc, RedeclarationKind Redecl=NotForRedeclaration)
Find the protocol with the given name, if any.
No entity found met the criteria.
TypeClass getTypeClass() const
unsigned getMinRequiredArguments() const
Returns the minimum number of arguments needed to call this function.
const SmallVectorImpl< Type * > & getTypes() const
static bool canHideTag(NamedDecl *D)
Determine whether D can hide a tag declaration.
OverloadCandidateSet - A set of overload candidates, used in C++ overload resolution (C++ 13...
bool isInvalid() const
An error occurred during parsing of the scope specifier.
bool hasSameUnqualifiedType(QualType T1, QualType T2) const
Determine whether the given types are equivalent after cvr-qualifiers have been removed.
Sema & getSema() const
Get the Sema object that this lookup result is searching with.
CXXDestructorDecl * DeclareImplicitDestructor(CXXRecordDecl *ClassDecl)
Declare the implicit destructor for the given class.
ArrayRef< TemplateArgument > pack_elements() const
Iterator range referencing all of the elements of a template argument pack.
A POD class for pairing a NamedDecl* with an access specifier.
StringRef getName() const
Return the actual identifier string.
A class for storing results from argument-dependent lookup.
Represents an element in a path from a derived class to a base class.
void diagnoseTypo(const TypoCorrection &Correction, const PartialDiagnostic &TypoDiag, bool ErrorRecovery=true)
Represents a template argument.
static void CollectEnclosingNamespace(Sema::AssociatedNamespaceSet &Namespaces, DeclContext *Ctx)
static DeclContext * getContextForScopeMatching(Decl *D)
Get a representative context for a declaration such that two declarations will have the same context ...
DeclContextLookupResult LookupConstructors(CXXRecordDecl *Class)
Look up the constructors for the given class.
bool hasVisibleExplicitSpecialization(const NamedDecl *D, llvm::SmallVectorImpl< Module *> *Modules=nullptr)
Determine if there is a visible declaration of D that is an explicit specialization declaration for a...
redecl_range redecls() const
Returns an iterator range for all the redeclarations of the same decl.
NamespaceDecl * getNominatedNamespace()
Returns the namespace nominated by this using-directive.
static ParmVarDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, IdentifierInfo *Id, QualType T, TypeSourceInfo *TInfo, StorageClass S, Expr *DefArg)
void setAllowHidden(bool AH)
Specify whether hidden declarations are visible, e.g., for recovery reasons.
std::list< CXXBasePath >::const_iterator const_paths_iterator
Dataflow Directional Tag Classes.
bool isValid() const
Return true if this is a valid SourceLocation object.
CXXConstructorDecl * DeclareImplicitCopyConstructor(CXXRecordDecl *ClassDecl)
Declare the implicit copy constructor for the given class.
DeducedType * getContainedDeducedType() const
Get the DeducedType whose type will be deduced for a variable with an initializer of this type...
static void getNestedNameSpecifierIdentifiers(NestedNameSpecifier *NNS, SmallVectorImpl< const IdentifierInfo *> &Identifiers)
static void checkCorrectionVisibility(Sema &SemaRef, TypoCorrection &TC)
Check whether the declarations found for a typo correction are visible.
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
static void AddKeywordsToConsumer(Sema &SemaRef, TypoCorrectionConsumer &Consumer, Scope *S, CorrectionCandidateCallback &CCC, bool AfterNestedNameSpecifier)
Add keywords to the consumer as possible typo corrections.
The base class of all kinds of template declarations (e.g., class, function, etc.).
unsigned getIdentifierNamespace() const
Returns the identifier namespace mask for this lookup.
void setContextRange(SourceRange SR)
Sets a 'context' source range.
OverloadedOperatorKind
Enumeration specifying the different kinds of C++ overloaded operators.
const Scope * getParent() const
getParent - Return the scope that this is nested in.
The template argument is a pack expansion of a template name that was provided for a template templat...
bool isFunctionOrFunctionTemplate() const
Whether this declaration is a function or function template.
void setAmbiguousQualifiedTagHiding()
Make these results show that the name was found in different contexts and a tag decl was hidden by an...
void clearDelayedTypo(TypoExpr *TE)
Clears the state of the given TypoExpr.
AccessSpecifier getAccess() const
NamespaceDecl * getOriginalNamespace()
Get the original (first) namespace declaration.
void insert(NamedDecl *D)
Adds a new ADL candidate to this map.
void setShadowed()
Note that we found and ignored a declaration while performing lookup.
FunctionDecl * getTemplateInstantiationPattern() const
Retrieve the function declaration from which this function could be instantiated, if it is an instant...
conversion_iterator conversion_begin() const
NamedDecl * getCorrectionDecl() const
Gets the pointer to the declaration of the typo correction.
The name of a declaration.
NamedDecl * getFoundDecl() const
Fetch the unique decl found by this lookup.
const CXXRecordDecl * getParent() const
Return the parent of this method declaration, which is the class in which this method is defined...
OverloadExpr * Expression
static const unsigned MaxTypoDistanceResultSets
A pointer to member type per C++ 8.3.3 - Pointers to members.
DeclarationNameInfo - A collector data type for bundling together a DeclarationName and the correspnd...
Tags, declared with 'struct foo;' and referenced with 'struct foo'.
A type that was preceded by the 'template' keyword, stored as a Type*.
NamedDecl * getCurFunctionOrMethodDecl()
getCurFunctionOrMethodDecl - Return the Decl for the current ObjC method or C function we're in...
bool isHidden() const
Determine whether this declaration might be hidden from name lookup.
IdentifierInfo * getCorrectionAsIdentifierInfo() const
static LabelDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation IdentL, IdentifierInfo *II)
bool isValid() const
A scope specifier is present, and it refers to a real scope.
CXXConstructorDecl * DeclareImplicitDefaultConstructor(CXXRecordDecl *ClassDecl)
Declare the implicit default constructor for the given class.
void LookupOverloadedOperatorName(OverloadedOperatorKind Op, Scope *S, QualType T1, QualType T2, UnresolvedSetImpl &Functions)
Represents a pointer to an Objective C object.
SpecialMemberOverloadResult LookupSpecialMember(CXXRecordDecl *D, CXXSpecialMember SM, bool ConstArg, bool VolatileArg, bool RValueThis, bool ConstThis, bool VolatileThis)
Name lookup found a single declaration that met the criteria.
static AccessSpecifier MergeAccess(AccessSpecifier PathAccess, AccessSpecifier DeclAccess)
Calculates the access of a decl that is reached along a path.
bool lookupInBases(BaseMatchesCallback BaseMatches, CXXBasePaths &Paths, bool LookupInDependent=false) const
Look for entities within the base classes of this C++ class, transitively searching all base class su...
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of structs/unions/cl...
The lookup is a reference to this name that is not for the purpose of redeclaring the name...
QualType getCanonicalTypeInternal() const
This template specialization was declared or defined by an explicit specialization (C++ [temp...
static bool isFunctionOrMethod(const Decl *D)
isFunctionOrMethod - Return true if the given decl has function type (function or function-typed vari...
static void DeclareImplicitMemberFunctionsWithName(Sema &S, DeclarationName Name, SourceLocation Loc, const DeclContext *DC)
If there are any implicit member functions with the given name that need to be declared in the given ...
DeclContext * getRedeclContext()
getRedeclContext - Retrieve the context in which an entity conflicts with other entities of the same ...
The template argument is a type.
static bool FindTagMember(const CXXBaseSpecifier *Specifier, CXXBasePath &Path, DeclarationName Name)
Base-class lookup callback that determines whether there exists a tag with the given name...
Sema::LookupNameKind getLookupKind() const
Gets the kind of lookup to perform.
The template argument is actually a parameter pack.
Represents a base class of a C++ class.
This is a scope that can contain a declaration.
bool isIncompleteType(NamedDecl **Def=nullptr) const
Types are partitioned into 3 broad categories (C99 6.2.5p1): object types, function types...
bool LookupQualifiedName(LookupResult &R, DeclContext *LookupCtx, bool InUnqualifiedLookup=false)
Perform qualified name lookup into a given context.
llvm::iterator_range< decls_iterator > decls() const
CanQualType getCanonicalType(QualType T) const
Return the canonical (structural) type corresponding to the specified potentially non-canonical type ...
A template argument list.
bool isSet() const
Deprecated.
bool needsImplicitCopyConstructor() const
Determine whether this class needs an implicit copy constructor to be lazily declared.
void mergeDefinitionIntoModule(NamedDecl *ND, Module *M, bool NotifyListeners=true)
Note that the definition ND has been merged into module M, and should be visible whenever M is visibl...
ArgKind getKind() const
Return the kind of stored template argument.
static bool isNamespaceOrTranslationUnitScope(Scope *S)
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate.h) and friends (in DeclFriend.h).
TemplateDecl * getCXXDeductionGuideTemplate() const
If this name is the name of a C++ deduction guide, return the template associated with that name...
TranslationUnitDecl * getTranslationUnitDecl() const
MemberExpr - [C99 6.5.2.3] Structure and Union Members.
void setCorrectionDecls(ArrayRef< NamedDecl *> Decls)
Clears the list of NamedDecls and adds the given set.
static void GetQualTypesForOpenCLBuiltin(ASTContext &Context, const OpenCLBuiltinStruct &OpenCLBuiltin, unsigned &GenTypeMaxCnt, SmallVector< QualType, 1 > &RetTypes, SmallVector< SmallVector< QualType, 1 >, 5 > &ArgTypes)
Get the QualType instances of the return type and arguments for an OpenCL builtin function signature...
Represents a C++ struct/union/class.
void ClearCorrectionDecls()
Clears the list of NamedDecls.
The template argument is a template name that was provided for a template template parameter...
sema::FunctionScopeInfo * getCurFunction() const
Look up a friend of a local class.
bool setUseQualifiedLookup(bool use=true) const
void addAllDecls(const LookupResult &Other)
Add all the declarations from another set of lookup results.
LiteralOperatorLookupResult LookupLiteralOperator(Scope *S, LookupResult &R, ArrayRef< QualType > ArgTys, bool AllowRaw, bool AllowTemplate, bool AllowStringTemplate, bool DiagnoseMissing)
LookupLiteralOperator - Determine which literal operator should be used for a user-defined literal...
ObjCIvarDecl - Represents an ObjC instance variable.
base_class_iterator bases_end()
void setCorrectionRange(CXXScopeSpec *SS, const DeclarationNameInfo &TypoName)
void print(raw_ostream &)
AccessResult CheckMemberAccess(SourceLocation UseLoc, CXXRecordDecl *NamingClass, DeclAccessPair Found)
Checks access to a member.
Builtin::Context & BuiltinInfo
DeclContext * CurContext
CurContext - This is the current declaration context of parsing.
void DeclareImplicitDeductionGuides(TemplateDecl *Template, SourceLocation Loc)
Declare implicit deduction guides for a class template if we've not already done so.
Declaration of a class template.
DeclContext * getLookupParent()
Find the parent context of this context that will be used for unqualified name lookup.
static FixItHint CreateReplacement(CharSourceRange RemoveRange, StringRef Code)
Create a code modification hint that replaces the given source range with the given code string...
NamedDecl * getAcceptableDecl(NamedDecl *D) const
Retrieve the accepted (re)declaration of the given declaration, if there is one.
__DEVICE__ int min(int __a, int __b)
static bool isPreferredLookupResult(Sema &S, Sema::LookupNameKind Kind, NamedDecl *D, NamedDecl *Existing)
Determine whether D is a better lookup result than Existing, given that they declare the same entity...
AccessSpecifier Access
The access along this inheritance path.
ASTContext & getParentASTContext() const
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...
virtual ~VisibleDeclConsumer()
Destroys the visible declaration consumer.
bool isDependentType() const
Whether this type is a dependent type, meaning that its definition somehow depends on a template para...
QualType getAsType() const
Retrieve the type for a type template argument.
This declaration is a function-local extern declaration of a variable or function.
const Scope * getFnParent() const
getFnParent - Return the closest scope that is a function body.
static void addAssociatedClassesAndNamespaces(AssociatedLookup &Result, QualType T)
Represents a type template specialization; the template must be a class template, a type alias templa...
NamedDecl * getMostRecentDecl()
CXXMethodDecl * DeclareImplicitCopyAssignment(CXXRecordDecl *ClassDecl)
Declare the implicit copy assignment operator for the given class.
CXXConstructorDecl * LookupDefaultConstructor(CXXRecordDecl *Class)
Look up the default constructor for the given class.
DeclContext * getPrimaryContext()
getPrimaryContext - There may be many different declarations of the same entity (including forward de...
BasePaths - Represents the set of paths from a derived class to one of its (direct or indirect) bases...
Annotates a diagnostic with some code that should be inserted, removed, or replaced to fix the proble...
bool needsImplicitMoveConstructor() const
Determine whether this class should get an implicit move constructor or if any existing special membe...
No viable function found.
void suppressDiagnostics()
Suppress the diagnostics that would normally fire because of this lookup.
static std::pair< DeclContext *, bool > findOuterContext(Scope *S)
An l-value expression is a reference to an object with independent storage.
bool empty() const
Return true if no decls were found.
bool Load(InterpState &S, CodePtr OpPC)
A trivial tuple used to represent a source range.
bool isModulePrivate() const
Whether this declaration was marked as being private to the module in which it was defined...
This represents a decl that may have a name.
bool isTranslationUnit() const
Represents C++ using-directive.
SourceLocation getNameLoc() const
Gets the location of the identifier.
static bool isInCurrentModule(const Module *M, const LangOptions &LangOpts)
Determine whether the module M is part of the current module from the perspective of a module-private...
Look up of an operator name (e.g., operator+) for use with operator overloading.
static bool CppNamespaceLookup(Sema &S, LookupResult &R, ASTContext &Context, DeclContext *NS, UnqualUsingDirectiveSet &UDirs)
The global specifier '::'. There is no stored value.
TemplateName getAsTemplateOrTemplatePattern() const
Retrieve the template argument as a template name; if the argument is a pack expansion, return the pattern as a template name.
static bool LookupDirect(Sema &S, LookupResult &R, const DeclContext *DC)
unsigned getNumParams() const
Return the number of parameters this function must have based on its FunctionType.
SourceLocation getBegin() const
const LangOptions & getLangOpts() const
void WillReplaceSpecifier(bool ForceReplacement)
bool WantFunctionLikeCasts
ExceptionSpecInfo ExceptionSpec
Defines enum values for all the target-independent builtin functions.
Declaration of a template function.
iterator - Iterate over the decls of a specified declaration name.
void setFindLocalExtern(bool FindLocalExtern)
SourceLocation getLocation() const
QualType getPointeeType() const
Represents a shadow declaration introduced into a scope by a (resolved) using declaration.
bool isBeingDefined() const
Return true if this decl is currently being defined.
static bool isCandidateViable(CorrectionCandidateCallback &CCC, TypoCorrection &Candidate)
Engages in a tight little dance with the lexer to efficiently preprocess tokens.
This declaration is a using declaration.
static bool isVisible(Sema &SemaRef, NamedDecl *D)
Determine whether the given declaration is visible to the program.
bool isTransparentContext() const
isTransparentContext - Determines whether this context is a "transparent" context, meaning that the members declared in this context are semantically declared in the nearest enclosing non-transparent (opaque) context but are lexically declared in this context.
void ActOnPragmaDump(Scope *S, SourceLocation Loc, IdentifierInfo *II)
Called on #pragma clang __debug dump II.
ArrayRef< PartialDiagnostic > getExtraDiagnostics() const
QualType getType() const
Retrieves the type of the base class.
static NestedNameSpecifier * GlobalSpecifier(const ASTContext &Context)
Returns the nested name specifier representing the global scope.