45#include "llvm/ADT/ArrayRef.h"
46#include "llvm/ADT/DenseSet.h"
47#include "llvm/ADT/SmallBitVector.h"
48#include "llvm/ADT/SmallPtrSet.h"
49#include "llvm/ADT/SmallString.h"
50#include "llvm/ADT/StringExtras.h"
51#include "llvm/ADT/StringSwitch.h"
52#include "llvm/ADT/Twine.h"
53#include "llvm/ADT/iterator_range.h"
54#include "llvm/Support/Casting.h"
55#include "llvm/Support/Path.h"
56#include "llvm/Support/raw_ostream.h"
75 typedef bool (ResultBuilder::*LookupFilter)(
const NamedDecl *)
const;
81 std::vector<Result> Results;
88 typedef std::pair<const NamedDecl *, unsigned> DeclIndexPair;
93 class ShadowMapEntry {
98 llvm::PointerUnion<const NamedDecl *, DeclIndexPairVector *> DeclOrVector;
102 unsigned SingleDeclIndex = 0;
105 ShadowMapEntry() =
default;
106 ShadowMapEntry(
const ShadowMapEntry &) =
delete;
107 ShadowMapEntry(ShadowMapEntry &&Move) { *
this = std::move(Move); }
108 ShadowMapEntry &operator=(
const ShadowMapEntry &) =
delete;
109 ShadowMapEntry &operator=(ShadowMapEntry &&Move) {
110 SingleDeclIndex =
Move.SingleDeclIndex;
111 DeclOrVector =
Move.DeclOrVector;
112 Move.DeclOrVector =
nullptr;
117 if (DeclOrVector.isNull()) {
120 SingleDeclIndex = Index;
125 DeclOrVector.dyn_cast<
const NamedDecl *>()) {
128 DeclIndexPairVector *Vec =
new DeclIndexPairVector;
129 Vec->push_back(DeclIndexPair(PrevND, SingleDeclIndex));
134 DeclOrVector.get<DeclIndexPairVector *>()->push_back(
135 DeclIndexPair(ND, Index));
139 if (DeclIndexPairVector *Vec =
140 DeclOrVector.dyn_cast<DeclIndexPairVector *>()) {
148 iterator begin()
const;
149 iterator end()
const;
155 typedef llvm::DenseMap<DeclarationName, ShadowMapEntry> ShadowMap;
172 bool AllowNestedNameSpecifiers;
183 std::list<ShadowMap> ShadowMaps;
197 bool HasObjectTypeQualifiers;
209 void AdjustResultPriorityForDecl(Result &R);
211 void MaybeAddConstructorResults(Result R);
217 LookupFilter Filter =
nullptr)
218 : SemaRef(SemaRef), Allocator(Allocator), CCTUInfo(CCTUInfo),
220 HasObjectTypeQualifiers(
false), CompletionContext(CompletionContext),
221 ObjCImplementation(nullptr) {
224 switch (CompletionContext.
getKind()) {
232 if (Method->isInstanceMethod())
234 ObjCImplementation =
Interface->getImplementation();
243 unsigned getBasePriority(
const NamedDecl *D);
247 bool includeCodePatterns()
const {
253 void setFilter(LookupFilter Filter) { this->Filter =
Filter; }
255 Result *data() {
return Results.empty() ? nullptr : &Results.front(); }
256 unsigned size()
const {
return Results.size(); }
257 bool empty()
const {
return Results.empty(); }
272 ObjectTypeQualifiers = Quals;
274 HasObjectTypeQualifiers =
true;
282 void setPreferredSelector(
Selector Sel) { PreferredSelector = Sel; }
287 return CompletionContext;
291 void allowNestedNameSpecifiers(
bool Allow =
true) {
292 AllowNestedNameSpecifiers = Allow;
297 Sema &getSema()
const {
return SemaRef; }
311 bool isInterestingDecl(
const NamedDecl *ND,
312 bool &AsNestedNameSpecifier)
const;
337 bool CheckHiddenResult(Result &R,
DeclContext *CurContext,
347 void MaybeAddResult(Result R,
DeclContext *CurContext =
nullptr);
364 bool InBaseClass,
QualType BaseExprType);
367 void AddResult(Result R);
370 void EnterNewScope();
389 bool IsOrdinaryName(
const NamedDecl *ND)
const;
390 bool IsOrdinaryNonTypeName(
const NamedDecl *ND)
const;
391 bool IsIntegralConstantValue(
const NamedDecl *ND)
const;
392 bool IsOrdinaryNonValueName(
const NamedDecl *ND)
const;
393 bool IsNestedNameSpecifier(
const NamedDecl *ND)
const;
395 bool IsClassOrStruct(
const NamedDecl *ND)
const;
397 bool IsNamespace(
const NamedDecl *ND)
const;
398 bool IsNamespaceOrAlias(
const NamedDecl *ND)
const;
400 bool IsMember(
const NamedDecl *ND)
const;
401 bool IsObjCIvar(
const NamedDecl *ND)
const;
402 bool IsObjCMessageReceiver(
const NamedDecl *ND)
const;
403 bool IsObjCMessageReceiverOrLambdaCapture(
const NamedDecl *ND)
const;
404 bool IsObjCCollection(
const NamedDecl *ND)
const;
405 bool IsImpossibleToSatisfy(
const NamedDecl *ND)
const;
415 ComputeType =
nullptr;
416 Type = BSI->ReturnType;
420 ComputeType =
nullptr;
423 }
else if (
const auto *Method = dyn_cast<ObjCMethodDecl>(S.
CurContext)) {
424 ComputeType =
nullptr;
425 Type = Method->getReturnType();
433 auto *VD = llvm::dyn_cast_or_null<ValueDecl>(D);
434 ComputeType =
nullptr;
446 ComputeType =
nullptr;
455 this->ComputeType = ComputeType;
465 if (ExpectedLoc == LParLoc)
476 if (Op == tok::plus || Op == tok::plusequal || Op == tok::minusequal)
479 if (Op == tok::minus)
492 case tok::minusequal:
494 case tok::percentequal:
496 case tok::slashequal:
502 case tok::equalequal:
503 case tok::exclaimequal:
507 case tok::greaterequal:
511 case tok::greatergreater:
512 case tok::greatergreaterequal:
514 case tok::lesslessequal:
521 case tok::caretcaret:
528 case tok::caretequal:
536 case tok::periodstar:
564 case tok::minusminus:
574 assert(
false &&
"unhandled unary op");
583 ComputeType =
nullptr;
590 if (!Enabled || !
Base)
593 if (ExpectedLoc !=
Base->getBeginLoc())
604 ComputeType =
nullptr;
613 ComputeType =
nullptr;
622 ComputeType =
nullptr;
630 ComputeType =
nullptr;
636 llvm::PointerUnion<const NamedDecl *, const DeclIndexPair *> DeclOrIterator;
637 unsigned SingleDeclIndex;
657 : DeclOrIterator(SingleDecl), SingleDeclIndex(Index) {}
660 : DeclOrIterator(Iterator), SingleDeclIndex(0) {}
663 if (DeclOrIterator.is<
const NamedDecl *>()) {
669 const DeclIndexPair *I = DeclOrIterator.get<
const DeclIndexPair *>();
685 return *DeclOrIterator.get<
const DeclIndexPair *>();
691 return X.DeclOrIterator.getOpaqueValue() ==
692 Y.DeclOrIterator.getOpaqueValue() &&
693 X.SingleDeclIndex == Y.SingleDeclIndex;
702ResultBuilder::ShadowMapEntry::begin()
const {
703 if (DeclOrVector.isNull())
707 return iterator(ND, SingleDeclIndex);
709 return iterator(DeclOrVector.get<DeclIndexPairVector *>()->begin());
713ResultBuilder::ShadowMapEntry::end()
const {
714 if (DeclOrVector.is<
const NamedDecl *>() || DeclOrVector.isNull())
717 return iterator(DeclOrVector.get<DeclIndexPairVector *>()->end());
738 for (
const DeclContext *CommonAncestor = TargetContext;
739 CommonAncestor && !CommonAncestor->
Encloses(CurContext);
740 CommonAncestor = CommonAncestor->getLookupParent()) {
741 if (CommonAncestor->isTransparentContext() ||
742 CommonAncestor->isFunctionOrMethod())
745 TargetParents.push_back(CommonAncestor);
749 while (!TargetParents.empty()) {
752 if (
const auto *Namespace = dyn_cast<NamespaceDecl>(
Parent)) {
753 if (!Namespace->getIdentifier())
757 }
else if (
const auto *TD = dyn_cast<TagDecl>(
Parent))
788bool ResultBuilder::isInterestingDecl(
const NamedDecl *ND,
789 bool &AsNestedNameSpecifier)
const {
790 AsNestedNameSpecifier =
false;
805 if (isa<ClassTemplateSpecializationDecl>(ND) ||
806 isa<ClassTemplatePartialSpecializationDecl>(ND))
810 if (isa<UsingDecl>(ND))
816 if (Filter == &ResultBuilder::IsNestedNameSpecifier ||
817 (isa<NamespaceDecl>(ND) && Filter != &ResultBuilder::IsNamespace &&
818 Filter != &ResultBuilder::IsNamespaceOrAlias && Filter !=
nullptr))
819 AsNestedNameSpecifier =
true;
822 if (Filter && !(this->*Filter)(Named)) {
824 if (AllowNestedNameSpecifiers && SemaRef.
getLangOpts().CPlusPlus &&
825 IsNestedNameSpecifier(ND) &&
826 (Filter != &ResultBuilder::IsMember ||
827 (isa<CXXRecordDecl>(ND) &&
828 cast<CXXRecordDecl>(ND)->isInjectedClassName()))) {
829 AsNestedNameSpecifier =
true;
859 R.QualifierIsInformative =
false;
863 R.Declaration->getDeclContext());
872 switch (cast<BuiltinType>(
T)->
getKind()) {
873 case BuiltinType::Void:
876 case BuiltinType::NullPtr:
879 case BuiltinType::Overload:
880 case BuiltinType::Dependent:
883 case BuiltinType::ObjCId:
884 case BuiltinType::ObjCClass:
885 case BuiltinType::ObjCSel:
898 case Type::BlockPointer:
901 case Type::LValueReference:
902 case Type::RValueReference:
905 case Type::ConstantArray:
906 case Type::IncompleteArray:
907 case Type::VariableArray:
908 case Type::DependentSizedArray:
911 case Type::DependentSizedExtVector:
913 case Type::ExtVector:
916 case Type::FunctionProto:
917 case Type::FunctionNoProto:
926 case Type::ObjCObject:
927 case Type::ObjCInterface:
928 case Type::ObjCObjectPointer:
941 if (
const auto *
Type = dyn_cast<TypeDecl>(ND))
942 return C.getTypeDeclType(
Type);
943 if (
const auto *Iface = dyn_cast<ObjCInterfaceDecl>(ND))
944 return C.getObjCInterfaceType(Iface);
949 else if (
const auto *Method = dyn_cast<ObjCMethodDecl>(ND))
950 T = Method->getSendResultType();
951 else if (
const auto *Enumerator = dyn_cast<EnumConstantDecl>(ND))
952 T =
C.getTypeDeclType(cast<EnumDecl>(Enumerator->getDeclContext()));
953 else if (
const auto *
Property = dyn_cast<ObjCPropertyDecl>(ND))
955 else if (
const auto *
Value = dyn_cast<ValueDecl>(ND))
971 if (
Pointer->getPointeeType()->isFunctionType()) {
980 T =
Block->getPointeeType();
995unsigned ResultBuilder::getBasePriority(
const NamedDecl *ND) {
1003 if (
const auto *ImplicitParam = dyn_cast<ImplicitParamDecl>(ND))
1004 if (ImplicitParam->getIdentifier() &&
1005 ImplicitParam->getIdentifier()->isStr(
"_cmd"))
1012 if (DC->
isRecord() || isa<ObjCContainerDecl>(DC)) {
1014 if (isa<CXXDestructorDecl>(ND))
1026 if (isa<EnumConstantDecl>(ND))
1032 if ((isa<TypeDecl>(ND) || isa<ObjCInterfaceDecl>(ND)) &&
1034 CompletionContext.
getKind() ==
1036 CompletionContext.
getKind() ==
1043void ResultBuilder::AdjustResultPriorityForDecl(
Result &R) {
1046 if (!PreferredSelector.
isNull())
1047 if (
const auto *Method = dyn_cast<ObjCMethodDecl>(R.Declaration))
1048 if (PreferredSelector == Method->getSelector())
1053 if (!PreferredType.
isNull()) {
1063 !(PreferredType->isEnumeralType() && TC->isEnumeralType()))
1075 return Record->lookup(ConstructorName);
1078void ResultBuilder::MaybeAddConstructorResults(
Result R) {
1079 if (!SemaRef.
getLangOpts().CPlusPlus || !R.Declaration ||
1086 Record = ClassTemplate->getTemplatedDecl();
1087 else if ((
Record = dyn_cast<CXXRecordDecl>(D))) {
1089 if (isa<ClassTemplateSpecializationDecl>(
Record))
1101 R.Declaration = Ctor;
1103 Results.push_back(R);
1108 if (
const auto *Tmpl = dyn_cast<FunctionTemplateDecl>(ND))
1109 ND = Tmpl->getTemplatedDecl();
1110 return isa<CXXConstructorDecl>(ND);
1114 assert(!ShadowMaps.empty() &&
"Must enter into a results scope");
1116 if (R.Kind != Result::RK_Declaration) {
1118 Results.push_back(R);
1123 if (
const UsingShadowDecl *Using = dyn_cast<UsingShadowDecl>(R.Declaration)) {
1125 getBasePriority(
Using->getTargetDecl()),
1129 std::move(R.FixIts));
1131 MaybeAddResult(
Result, CurContext);
1138 bool AsNestedNameSpecifier =
false;
1139 if (!isInterestingDecl(R.Declaration, AsNestedNameSpecifier))
1146 ShadowMap &
SMap = ShadowMaps.back();
1147 ShadowMapEntry::iterator I, IEnd;
1148 ShadowMap::iterator NamePos =
SMap.find(R.Declaration->getDeclName());
1149 if (NamePos !=
SMap.end()) {
1150 I = NamePos->second.begin();
1151 IEnd = NamePos->second.end();
1154 for (; I != IEnd; ++I) {
1156 unsigned Index = I->second;
1159 Results[Index].Declaration = R.Declaration;
1169 std::list<ShadowMap>::iterator
SM, SMEnd = ShadowMaps.end();
1171 for (
SM = ShadowMaps.begin();
SM != SMEnd; ++
SM) {
1172 ShadowMapEntry::iterator I, IEnd;
1173 ShadowMap::iterator NamePos =
SM->find(R.Declaration->getDeclName());
1174 if (NamePos !=
SM->end()) {
1175 I = NamePos->second.begin();
1176 IEnd = NamePos->second.end();
1178 for (; I != IEnd; ++I) {
1180 if (I->first->hasTagIdentifierNamespace() &&
1188 I->first->getIdentifierNamespace() != IDNS)
1192 if (CheckHiddenResult(R, CurContext, I->first))
1200 if (!AllDeclsFound.insert(CanonDecl).second)
1205 if (AsNestedNameSpecifier) {
1206 R.StartsNestedNameSpecifier =
true;
1209 AdjustResultPriorityForDecl(R);
1212 if (R.QualifierIsInformative && !R.Qualifier &&
1213 !R.StartsNestedNameSpecifier) {
1214 const DeclContext *Ctx = R.Declaration->getDeclContext();
1215 if (
const NamespaceDecl *Namespace = dyn_cast<NamespaceDecl>(Ctx))
1218 else if (
const TagDecl *Tag = dyn_cast<TagDecl>(Ctx))
1220 SemaRef.
Context,
nullptr,
false,
1223 R.QualifierIsInformative =
false;
1228 SMap[R.Declaration->getDeclName()].Add(R.Declaration, Results.size());
1229 Results.push_back(R);
1231 if (!AsNestedNameSpecifier)
1232 MaybeAddConstructorResults(R);
1251 return OverloadCompare::BothViable;
1256 return OverloadCompare::BothViable;
1257 for (
unsigned I = 0, E = Candidate.
getNumParams(); I != E; ++I)
1258 if (Candidate.
parameters()[I]->getType().getCanonicalType() !=
1259 Incumbent.
parameters()[I]->getType().getCanonicalType())
1260 return OverloadCompare::BothViable;
1263 return OverloadCompare::BothViable;
1268 if (CandidateRef != IncumbentRef) {
1275 return CandidateRef ==
RQ_RValue ? OverloadCompare::Dominates
1276 : OverloadCompare::Dominated;
1284 if (CandidateSuperset == IncumbentSuperset)
1285 return OverloadCompare::BothViable;
1286 return IncumbentSuperset ? OverloadCompare::Dominates
1287 : OverloadCompare::Dominated;
1290bool ResultBuilder::canCxxMethodBeCalled(
const CXXMethodDecl *Method,
1296 const auto *CurrentClassScope = [&]() ->
const CXXRecordDecl * {
1298 const auto *CtxMethod = llvm::dyn_cast<CXXMethodDecl>(Ctx);
1299 if (CtxMethod && !CtxMethod->getParent()->isLambda()) {
1300 return CtxMethod->getParent();
1307 bool FunctionCanBeCall =
1308 CurrentClassScope &&
1309 (CurrentClassScope == Method->
getParent() ||
1313 if (FunctionCanBeCall)
1318 BaseExprType.
isNull() ?
nullptr
1322 MaybeDerived == MaybeBase || MaybeDerived->
isDerivedFrom(MaybeBase);
1325 return FunctionCanBeCall;
1328bool ResultBuilder::canFunctionBeCalled(
const NamedDecl *ND,
1339 if (
const auto *FuncTmpl = dyn_cast<FunctionTemplateDecl>(ND)) {
1340 ND = FuncTmpl->getTemplatedDecl();
1342 const auto *Method = dyn_cast<CXXMethodDecl>(ND);
1343 if (Method && !Method->
isStatic()) {
1344 return canCxxMethodBeCalled(Method, BaseExprType);
1351 NamedDecl *Hiding,
bool InBaseClass =
false,
1353 if (R.Kind != Result::RK_Declaration) {
1355 Results.push_back(R);
1360 if (
const auto *Using = dyn_cast<UsingShadowDecl>(R.Declaration)) {
1362 getBasePriority(
Using->getTargetDecl()),
1366 std::move(R.FixIts));
1368 AddResult(
Result, CurContext, Hiding,
false,
1373 bool AsNestedNameSpecifier =
false;
1374 if (!isInterestingDecl(R.Declaration, AsNestedNameSpecifier))
1381 if (Hiding && CheckHiddenResult(R, CurContext, Hiding))
1385 if (!AllDeclsFound.insert(R.Declaration->getCanonicalDecl()).second)
1390 if (AsNestedNameSpecifier) {
1391 R.StartsNestedNameSpecifier =
true;
1393 }
else if (Filter == &ResultBuilder::IsMember && !R.Qualifier &&
1396 R.Declaration->getDeclContext()->getRedeclContext()))
1397 R.QualifierIsInformative =
true;
1400 if (R.QualifierIsInformative && !R.Qualifier &&
1401 !R.StartsNestedNameSpecifier) {
1402 const DeclContext *Ctx = R.Declaration->getDeclContext();
1403 if (
const auto *Namespace = dyn_cast<NamespaceDecl>(Ctx))
1406 else if (
const auto *Tag = dyn_cast<TagDecl>(Ctx))
1408 SemaRef.
Context,
nullptr,
false,
1411 R.QualifierIsInformative =
false;
1418 AdjustResultPriorityForDecl(R);
1420 if (HasObjectTypeQualifiers)
1421 if (
const auto *Method = dyn_cast<CXXMethodDecl>(R.Declaration))
1424 if (ObjectTypeQualifiers == MethodQuals)
1426 else if (ObjectTypeQualifiers - MethodQuals) {
1448 auto &OverloadSet = OverloadMap[std::make_pair(
1450 for (
const DeclIndexPair Entry : OverloadSet) {
1451 Result &Incumbent = Results[Entry.second];
1453 *cast<CXXMethodDecl>(Incumbent.Declaration),
1454 ObjectTypeQualifiers, ObjectKind)) {
1455 case OverloadCompare::Dominates:
1459 Incumbent = std::move(R);
1461 case OverloadCompare::Dominated:
1464 case OverloadCompare::BothViable:
1468 OverloadSet.Add(Method, Results.size());
1471 R.FunctionCanBeCall = canFunctionBeCalled(R.getDeclaration(), BaseExprType);
1474 Results.push_back(R);
1476 if (!AsNestedNameSpecifier)
1477 MaybeAddConstructorResults(R);
1480void ResultBuilder::AddResult(
Result R) {
1481 assert(R.Kind != Result::RK_Declaration &&
1482 "Declaration results need more context");
1483 Results.push_back(R);
1487void ResultBuilder::EnterNewScope() { ShadowMaps.emplace_back(); }
1490void ResultBuilder::ExitScope() {
1491 ShadowMaps.pop_back();
1496bool ResultBuilder::IsOrdinaryName(
const NamedDecl *ND)
const {
1505 if (isa<ObjCIvarDecl>(ND))
1514bool ResultBuilder::IsOrdinaryNonTypeName(
const NamedDecl *ND)
const {
1516 if (isa<TypeDecl>(ND))
1521 if (
const auto *ID = dyn_cast<ObjCInterfaceDecl>(ND)) {
1522 if (!
ID->getDefinition())
1530 if (isa<ObjCIvarDecl>(ND))
1537bool ResultBuilder::IsIntegralConstantValue(
const NamedDecl *ND)
const {
1538 if (!IsOrdinaryNonTypeName(ND))
1542 if (VD->getType()->isIntegralOrEnumerationType())
1550bool ResultBuilder::IsOrdinaryNonValueName(
const NamedDecl *ND)
const {
1558 !isa<FunctionTemplateDecl>(ND) && !isa<ObjCPropertyDecl>(ND);
1563bool ResultBuilder::IsNestedNameSpecifier(
const NamedDecl *ND)
const {
1565 if (
const auto *ClassTemplate = dyn_cast<ClassTemplateDecl>(ND))
1566 ND = ClassTemplate->getTemplatedDecl();
1572bool ResultBuilder::IsEnum(
const NamedDecl *ND)
const {
1573 return isa<EnumDecl>(ND);
1577bool ResultBuilder::IsClassOrStruct(
const NamedDecl *ND)
const {
1579 if (
const auto *ClassTemplate = dyn_cast<ClassTemplateDecl>(ND))
1580 ND = ClassTemplate->getTemplatedDecl();
1583 if (
const auto *RD = dyn_cast<RecordDecl>(ND))
1592bool ResultBuilder::IsUnion(
const NamedDecl *ND)
const {
1594 if (
const auto *ClassTemplate = dyn_cast<ClassTemplateDecl>(ND))
1595 ND = ClassTemplate->getTemplatedDecl();
1597 if (
const auto *RD = dyn_cast<RecordDecl>(ND))
1604bool ResultBuilder::IsNamespace(
const NamedDecl *ND)
const {
1605 return isa<NamespaceDecl>(ND);
1610bool ResultBuilder::IsNamespaceOrAlias(
const NamedDecl *ND)
const {
1615bool ResultBuilder::IsType(
const NamedDecl *ND)
const {
1617 return isa<TypeDecl>(ND) || isa<ObjCInterfaceDecl>(ND);
1623bool ResultBuilder::IsMember(
const NamedDecl *ND)
const {
1625 return isa<ValueDecl>(ND) || isa<FunctionTemplateDecl>(ND) ||
1626 isa<ObjCPropertyDecl>(ND);
1630 T =
C.getCanonicalType(
T);
1632 case Type::ObjCObject:
1633 case Type::ObjCInterface:
1634 case Type::ObjCObjectPointer:
1638 switch (cast<BuiltinType>(
T)->
getKind()) {
1639 case BuiltinType::ObjCId:
1640 case BuiltinType::ObjCClass:
1641 case BuiltinType::ObjCSel:
1653 if (!
C.getLangOpts().CPlusPlus)
1662bool ResultBuilder::IsObjCMessageReceiver(
const NamedDecl *ND)
const {
1671bool ResultBuilder::IsObjCMessageReceiverOrLambdaCapture(
1673 if (IsObjCMessageReceiver(ND))
1676 const auto *Var = dyn_cast<VarDecl>(ND);
1680 return Var->hasLocalStorage() && !Var->hasAttr<BlocksAttr>();
1683bool ResultBuilder::IsObjCCollection(
const NamedDecl *ND)
const {
1684 if ((SemaRef.
getLangOpts().CPlusPlus && !IsOrdinaryName(ND)) ||
1685 (!SemaRef.
getLangOpts().CPlusPlus && !IsOrdinaryNonTypeName(ND)))
1698bool ResultBuilder::IsImpossibleToSatisfy(
const NamedDecl *ND)
const {
1704bool ResultBuilder::IsObjCIvar(
const NamedDecl *ND)
const {
1705 return isa<ObjCIvarDecl>(ND);
1713 ResultBuilder &Results;
1719 std::vector<FixItHint> FixIts;
1722 CodeCompletionDeclConsumer(
1723 ResultBuilder &Results,
DeclContext *InitialLookupCtx,
1725 std::vector<FixItHint> FixIts = std::vector<FixItHint>())
1726 : Results(Results), InitialLookupCtx(InitialLookupCtx),
1727 FixIts(
std::move(FixIts)) {
1728 NamingClass = llvm::dyn_cast<CXXRecordDecl>(InitialLookupCtx);
1731 auto ThisType = Results.getSema().getCurrentThisType();
1732 if (!ThisType.isNull()) {
1733 assert(ThisType->isPointerType());
1739 this->BaseType = BaseType;
1743 bool InBaseClass)
override {
1746 Results.AddResult(Result, InitialLookupCtx, Hiding, InBaseClass, BaseType);
1750 Results.addVisitedContext(Ctx);
1759 auto *NamingClass = this->NamingClass;
1760 QualType BaseType = this->BaseType;
1761 if (
auto *Cls = llvm::dyn_cast_or_null<CXXRecordDecl>(Ctx)) {
1776 NamingClass =
nullptr;
1779 return Results.getSema().IsSimplyAccessible(ND, NamingClass, BaseType);
1786 ResultBuilder &Results) {
1812 Results.getCodeCompletionTUInfo());
1813 if (LangOpts.CPlusPlus) {
1821 Builder.AddTypedTextChunk(
"typename");
1823 Builder.AddPlaceholderChunk(
"name");
1824 Results.AddResult(
Result(Builder.TakeString()));
1826 if (LangOpts.CPlusPlus11) {
1831 Builder.AddTypedTextChunk(
"decltype");
1833 Builder.AddPlaceholderChunk(
"expression");
1835 Results.AddResult(
Result(Builder.TakeString()));
1841 if (LangOpts.GNUKeywords) {
1847 Builder.AddTypedTextChunk(
"typeof");
1849 Builder.AddPlaceholderChunk(
"expression");
1850 Results.AddResult(
Result(Builder.TakeString()));
1852 Builder.AddTypedTextChunk(
"typeof");
1854 Builder.AddPlaceholderChunk(
"type");
1856 Results.AddResult(
Result(Builder.TakeString()));
1867 ResultBuilder &Results) {
1872 Results.AddResult(
Result(
"extern"));
1873 Results.AddResult(
Result(
"static"));
1875 if (LangOpts.CPlusPlus11) {
1880 Builder.AddTypedTextChunk(
"alignas");
1882 Builder.AddPlaceholderChunk(
"expression");
1884 Results.AddResult(
Result(Builder.TakeString()));
1886 Results.AddResult(
Result(
"constexpr"));
1887 Results.AddResult(
Result(
"thread_local"));
1893 ResultBuilder &Results) {
1898 if (LangOpts.CPlusPlus) {
1899 Results.AddResult(
Result(
"explicit"));
1900 Results.AddResult(
Result(
"friend"));
1901 Results.AddResult(
Result(
"mutable"));
1902 Results.AddResult(
Result(
"virtual"));
1910 if (LangOpts.CPlusPlus || LangOpts.C99)
1911 Results.AddResult(
Result(
"inline"));
1931 ResultBuilder &Results,
bool NeedAt);
1933 ResultBuilder &Results,
bool NeedAt);
1935 ResultBuilder &Results,
bool NeedAt);
1940 Results.getCodeCompletionTUInfo());
1941 Builder.AddTypedTextChunk(
"typedef");
1943 Builder.AddPlaceholderChunk(
"type");
1945 Builder.AddPlaceholderChunk(
"name");
1952 ResultBuilder &Results) {
1953 Builder.AddTypedTextChunk(
"using");
1955 Builder.AddPlaceholderChunk(
"name");
1957 Builder.AddPlaceholderChunk(
"type");
1980 return LangOpts.CPlusPlus;
1987 return LangOpts.CPlusPlus || LangOpts.ObjC || LangOpts.C99;
1990 llvm_unreachable(
"Invalid ParserCompletionContext!");
2017 if (!
T.getLocalQualifiers()) {
2020 return BT->getNameAsCString(Policy);
2023 if (
const TagType *TagT = dyn_cast<TagType>(
T))
2024 if (
TagDecl *Tag = TagT->getDecl())
2025 if (!Tag->hasNameForLinkage()) {
2026 switch (Tag->getTagKind()) {
2028 return "struct <anonymous>";
2030 return "__interface <anonymous>";
2032 return "class <anonymous>";
2034 return "union <anonymous>";
2036 return "enum <anonymous>";
2043 T.getAsStringInternal(
Result, Policy);
2044 return Allocator.CopyString(
Result);
2056 Builder.AddResultTypeChunk(
2058 Builder.AddTypedTextChunk(
"this");
2063 ResultBuilder &Results,
2065 if (!LangOpts.CPlusPlus11)
2068 Builder.AddTypedTextChunk(
"static_assert");
2070 Builder.AddPlaceholderChunk(
"expression");
2072 Builder.AddPlaceholderChunk(
"message");
2081 Sema &S = Results.getSema();
2082 const auto *CR = llvm::dyn_cast<CXXRecordDecl>(S.
CurContext);
2088 llvm::StringMap<std::vector<FunctionDecl *>> Overrides;
2089 for (
auto *Method : CR->methods()) {
2092 Overrides[Method->
getName()].push_back(Method);
2095 for (
const auto &
Base : CR->bases()) {
2096 const auto *BR =
Base.getType().getTypePtr()->getAsCXXRecordDecl();
2099 for (
auto *Method : BR->methods()) {
2102 const auto it = Overrides.find(Method->
getName());
2103 bool IsOverriden =
false;
2104 if (it != Overrides.end()) {
2105 for (
auto *MD : it->second) {
2118 std::string OverrideSignature;
2119 llvm::raw_string_ostream OS(OverrideSignature);
2125 false, CCContext, Policy);
2134 Sema &SemaRef, ResultBuilder &Results) {
2142 if (Results.includeCodePatterns()) {
2144 Builder.AddTypedTextChunk(
"namespace");
2146 Builder.AddPlaceholderChunk(
"identifier");
2150 Builder.AddPlaceholderChunk(
"declarations");
2153 Results.AddResult(
Result(Builder.TakeString()));
2157 Builder.AddTypedTextChunk(
"namespace");
2159 Builder.AddPlaceholderChunk(
"name");
2161 Builder.AddPlaceholderChunk(
"namespace");
2163 Results.AddResult(
Result(Builder.TakeString()));
2166 Builder.AddTypedTextChunk(
"using namespace");
2168 Builder.AddPlaceholderChunk(
"identifier");
2170 Results.AddResult(
Result(Builder.TakeString()));
2173 Builder.AddTypedTextChunk(
"asm");
2175 Builder.AddPlaceholderChunk(
"string-literal");
2177 Results.AddResult(
Result(Builder.TakeString()));
2179 if (Results.includeCodePatterns()) {
2181 Builder.AddTypedTextChunk(
"template");
2183 Builder.AddPlaceholderChunk(
"declaration");
2184 Results.AddResult(
Result(Builder.TakeString()));
2199 Builder.AddTypedTextChunk(
"using");
2201 Builder.AddPlaceholderChunk(
"qualifier");
2202 Builder.AddTextChunk(
"::");
2203 Builder.AddPlaceholderChunk(
"name");
2205 Results.AddResult(
Result(Builder.TakeString()));
2212 Builder.AddTypedTextChunk(
"using typename");
2214 Builder.AddPlaceholderChunk(
"qualifier");
2215 Builder.AddTextChunk(
"::");
2216 Builder.AddPlaceholderChunk(
"name");
2218 Results.AddResult(
Result(Builder.TakeString()));
2226 bool IsNotInheritanceScope = !S->isClassInheritanceScope();
2228 Builder.AddTypedTextChunk(
"public");
2229 if (IsNotInheritanceScope && Results.includeCodePatterns())
2231 Results.AddResult(
Result(Builder.TakeString()));
2234 Builder.AddTypedTextChunk(
"protected");
2235 if (IsNotInheritanceScope && Results.includeCodePatterns())
2237 Results.AddResult(
Result(Builder.TakeString()));
2240 Builder.AddTypedTextChunk(
"private");
2241 if (IsNotInheritanceScope && Results.includeCodePatterns())
2243 Results.AddResult(
Result(Builder.TakeString()));
2256 if (SemaRef.
getLangOpts().CPlusPlus && Results.includeCodePatterns()) {
2258 Builder.AddTypedTextChunk(
"template");
2260 Builder.AddPlaceholderChunk(
"parameters");
2262 Results.AddResult(
Result(Builder.TakeString()));
2295 if (SemaRef.
getLangOpts().CPlusPlus && Results.includeCodePatterns() &&
2297 Builder.AddTypedTextChunk(
"try");
2301 Builder.AddPlaceholderChunk(
"statements");
2305 Builder.AddTextChunk(
"catch");
2308 Builder.AddPlaceholderChunk(
"declaration");
2313 Builder.AddPlaceholderChunk(
"statements");
2316 Results.AddResult(
Result(Builder.TakeString()));
2321 if (Results.includeCodePatterns()) {
2323 Builder.AddTypedTextChunk(
"if");
2327 Builder.AddPlaceholderChunk(
"condition");
2329 Builder.AddPlaceholderChunk(
"expression");
2334 Builder.AddPlaceholderChunk(
"statements");
2337 Results.AddResult(
Result(Builder.TakeString()));
2340 Builder.AddTypedTextChunk(
"switch");
2344 Builder.AddPlaceholderChunk(
"condition");
2346 Builder.AddPlaceholderChunk(
"expression");
2351 Builder.AddPlaceholderChunk(
"cases");
2354 Results.AddResult(
Result(Builder.TakeString()));
2361 Builder.AddTypedTextChunk(
"case");
2363 Builder.AddPlaceholderChunk(
"expression");
2365 Results.AddResult(
Result(Builder.TakeString()));
2368 Builder.AddTypedTextChunk(
"default");
2370 Results.AddResult(
Result(Builder.TakeString()));
2373 if (Results.includeCodePatterns()) {
2375 Builder.AddTypedTextChunk(
"while");
2379 Builder.AddPlaceholderChunk(
"condition");
2381 Builder.AddPlaceholderChunk(
"expression");
2386 Builder.AddPlaceholderChunk(
"statements");
2389 Results.AddResult(
Result(Builder.TakeString()));
2392 Builder.AddTypedTextChunk(
"do");
2396 Builder.AddPlaceholderChunk(
"statements");
2399 Builder.AddTextChunk(
"while");
2402 Builder.AddPlaceholderChunk(
"expression");
2404 Results.AddResult(
Result(Builder.TakeString()));
2407 Builder.AddTypedTextChunk(
"for");
2411 Builder.AddPlaceholderChunk(
"init-statement");
2413 Builder.AddPlaceholderChunk(
"init-expression");
2416 Builder.AddPlaceholderChunk(
"condition");
2419 Builder.AddPlaceholderChunk(
"inc-expression");
2424 Builder.AddPlaceholderChunk(
"statements");
2427 Results.AddResult(
Result(Builder.TakeString()));
2431 Builder.AddTypedTextChunk(
"for");
2434 Builder.AddPlaceholderChunk(
"range-declaration");
2437 Builder.AddTextChunk(
"in");
2441 Builder.AddPlaceholderChunk(
"range-expression");
2446 Builder.AddPlaceholderChunk(
"statements");
2449 Results.AddResult(
Result(Builder.TakeString()));
2453 if (S->getContinueParent()) {
2455 Builder.AddTypedTextChunk(
"continue");
2457 Results.AddResult(
Result(Builder.TakeString()));
2460 if (S->getBreakParent()) {
2462 Builder.AddTypedTextChunk(
"break");
2464 Results.AddResult(
Result(Builder.TakeString()));
2470 ReturnType =
Function->getReturnType();
2471 else if (
const auto *Method = dyn_cast<ObjCMethodDecl>(SemaRef.
CurContext))
2477 Builder.AddTypedTextChunk(
"return");
2479 Results.AddResult(
Result(Builder.TakeString()));
2481 assert(!ReturnType.
isNull());
2483 Builder.AddTypedTextChunk(
"return");
2485 Builder.AddPlaceholderChunk(
"expression");
2487 Results.AddResult(
Result(Builder.TakeString()));
2490 Builder.AddTypedTextChunk(
"return true");
2492 Results.AddResult(
Result(Builder.TakeString()));
2494 Builder.AddTypedTextChunk(
"return false");
2496 Results.AddResult(
Result(Builder.TakeString()));
2501 Builder.AddTypedTextChunk(
"return nullptr");
2503 Results.AddResult(
Result(Builder.TakeString()));
2508 Builder.AddTypedTextChunk(
"goto");
2510 Builder.AddPlaceholderChunk(
"label");
2512 Results.AddResult(
Result(Builder.TakeString()));
2515 Builder.AddTypedTextChunk(
"using namespace");
2517 Builder.AddPlaceholderChunk(
"identifier");
2519 Results.AddResult(
Result(Builder.TakeString()));
2536 Builder.AddTypedTextChunk(
"__bridge");
2538 Builder.AddPlaceholderChunk(
"type");
2540 Builder.AddPlaceholderChunk(
"expression");
2541 Results.AddResult(
Result(Builder.TakeString()));
2544 Builder.AddTypedTextChunk(
"__bridge_transfer");
2546 Builder.AddPlaceholderChunk(
"Objective-C type");
2548 Builder.AddPlaceholderChunk(
"expression");
2549 Results.AddResult(
Result(Builder.TakeString()));
2552 Builder.AddTypedTextChunk(
"__bridge_retained");
2554 Builder.AddPlaceholderChunk(
"CF type");
2556 Builder.AddPlaceholderChunk(
"expression");
2557 Results.AddResult(
Result(Builder.TakeString()));
2568 Builder.AddResultTypeChunk(
"bool");
2569 Builder.AddTypedTextChunk(
"true");
2570 Results.AddResult(
Result(Builder.TakeString()));
2573 Builder.AddResultTypeChunk(
"bool");
2574 Builder.AddTypedTextChunk(
"false");
2575 Results.AddResult(
Result(Builder.TakeString()));
2579 Builder.AddTypedTextChunk(
"dynamic_cast");
2581 Builder.AddPlaceholderChunk(
"type");
2584 Builder.AddPlaceholderChunk(
"expression");
2586 Results.AddResult(
Result(Builder.TakeString()));
2590 Builder.AddTypedTextChunk(
"static_cast");
2592 Builder.AddPlaceholderChunk(
"type");
2595 Builder.AddPlaceholderChunk(
"expression");
2597 Results.AddResult(
Result(Builder.TakeString()));
2600 Builder.AddTypedTextChunk(
"reinterpret_cast");
2602 Builder.AddPlaceholderChunk(
"type");
2605 Builder.AddPlaceholderChunk(
"expression");
2607 Results.AddResult(
Result(Builder.TakeString()));
2610 Builder.AddTypedTextChunk(
"const_cast");
2612 Builder.AddPlaceholderChunk(
"type");
2615 Builder.AddPlaceholderChunk(
"expression");
2617 Results.AddResult(
Result(Builder.TakeString()));
2621 Builder.AddResultTypeChunk(
"std::type_info");
2622 Builder.AddTypedTextChunk(
"typeid");
2624 Builder.AddPlaceholderChunk(
"expression-or-type");
2626 Results.AddResult(
Result(Builder.TakeString()));
2630 Builder.AddTypedTextChunk(
"new");
2632 Builder.AddPlaceholderChunk(
"type");
2634 Builder.AddPlaceholderChunk(
"expressions");
2636 Results.AddResult(
Result(Builder.TakeString()));
2639 Builder.AddTypedTextChunk(
"new");
2641 Builder.AddPlaceholderChunk(
"type");
2643 Builder.AddPlaceholderChunk(
"size");
2646 Builder.AddPlaceholderChunk(
"expressions");
2648 Results.AddResult(
Result(Builder.TakeString()));
2651 Builder.AddResultTypeChunk(
"void");
2652 Builder.AddTypedTextChunk(
"delete");
2654 Builder.AddPlaceholderChunk(
"expression");
2655 Results.AddResult(
Result(Builder.TakeString()));
2658 Builder.AddResultTypeChunk(
"void");
2659 Builder.AddTypedTextChunk(
"delete");
2664 Builder.AddPlaceholderChunk(
"expression");
2665 Results.AddResult(
Result(Builder.TakeString()));
2669 Builder.AddResultTypeChunk(
"void");
2670 Builder.AddTypedTextChunk(
"throw");
2672 Builder.AddPlaceholderChunk(
"expression");
2673 Results.AddResult(
Result(Builder.TakeString()));
2680 Builder.AddResultTypeChunk(
"std::nullptr_t");
2681 Builder.AddTypedTextChunk(
"nullptr");
2682 Results.AddResult(
Result(Builder.TakeString()));
2685 Builder.AddResultTypeChunk(
"size_t");
2686 Builder.AddTypedTextChunk(
"alignof");
2688 Builder.AddPlaceholderChunk(
"type");
2690 Results.AddResult(
Result(Builder.TakeString()));
2693 Builder.AddResultTypeChunk(
"bool");
2694 Builder.AddTypedTextChunk(
"noexcept");
2696 Builder.AddPlaceholderChunk(
"expression");
2698 Results.AddResult(
Result(Builder.TakeString()));
2701 Builder.AddResultTypeChunk(
"size_t");
2702 Builder.AddTypedTextChunk(
"sizeof...");
2704 Builder.AddPlaceholderChunk(
"parameter-pack");
2706 Results.AddResult(
Result(Builder.TakeString()));
2715 if (ID->getSuperClass()) {
2716 std::string SuperType;
2717 SuperType = ID->getSuperClass()->getNameAsString();
2718 if (Method->isInstanceMethod())
2721 Builder.AddResultTypeChunk(Allocator.CopyString(SuperType));
2722 Builder.AddTypedTextChunk(
"super");
2723 Results.AddResult(
Result(Builder.TakeString()));
2732 Builder.AddResultTypeChunk(
"size_t");
2734 Builder.AddTypedTextChunk(
"alignof");
2736 Builder.AddTypedTextChunk(
"_Alignof");
2738 Builder.AddPlaceholderChunk(
"type");
2740 Results.AddResult(
Result(Builder.TakeString()));
2745 Builder.AddResultTypeChunk(
"nullptr_t");
2746 Builder.AddTypedTextChunk(
"nullptr");
2747 Results.AddResult(
Result(Builder.TakeString()));
2751 Builder.AddResultTypeChunk(
"size_t");
2752 Builder.AddTypedTextChunk(
"sizeof");
2754 Builder.AddPlaceholderChunk(
"expression-or-type");
2756 Results.AddResult(
Result(Builder.TakeString()));
2769 Results.AddResult(
Result(
"operator"));
2790 else if (
const auto *Method = dyn_cast<ObjCMethodDecl>(ND)) {
2792 T = Method->getSendResultType(BaseType);
2795 }
else if (
const auto *Enumerator = dyn_cast<EnumConstantDecl>(ND)) {
2798 }
else if (isa<UnresolvedUsingValueDecl>(ND)) {
2800 }
else if (
const auto *Ivar = dyn_cast<ObjCIvarDecl>(ND)) {
2802 T = Ivar->getUsageType(BaseType);
2804 T = Ivar->getType();
2805 }
else if (
const auto *
Value = dyn_cast<ValueDecl>(ND)) {
2807 }
else if (
const auto *
Property = dyn_cast<ObjCPropertyDecl>(ND)) {
2817 Result.AddResultTypeChunk(
2824 if (SentinelAttr *Sentinel = FunctionOrMethod->
getAttr<SentinelAttr>())
2825 if (Sentinel->getSentinel() == 0) {
2827 Result.AddTextChunk(
", nil");
2829 Result.AddTextChunk(
", NULL");
2831 Result.AddTextChunk(
", (void*)0");
2852 switch (*nullability) {
2862 Result +=
"null_unspecified ";
2866 llvm_unreachable(
"Not supported as a context-sensitive keyword!");
2883 bool SuppressBlock =
false) {
2889 if (!SuppressBlock) {
2892 TypedefTL.getTypedefNameDecl()->getTypeSourceInfo()) {
2905 TL = AttrTL.getModifiedLoc();
2924 bool SuppressBlockName =
false,
bool SuppressBlock =
false,
2929 bool SuppressName =
false,
bool SuppressBlock =
false,
2937 if (
const auto *PVD = dyn_cast<ParmVarDecl>(Param))
2938 ObjCQual = PVD->getObjCDeclQualifier();
2939 bool ObjCMethodParam = isa<ObjCMethodDecl>(Param->
getDeclContext());
2946 if (Param->
getIdentifier() && !ObjCMethodParam && !SuppressName)
2953 if (ObjCMethodParam) {
2972 if (!
Block && ObjCMethodParam &&
2973 cast<ObjCMethodDecl>(Param->
getDeclContext())->isPropertyAccessor()) {
2974 if (
const auto *PD = cast<ObjCMethodDecl>(Param->
getDeclContext())
2975 ->findPropertyDecl(
false))
2989 if (ObjCMethodParam) {
2994 if (
Result.back() !=
')')
3008 false, SuppressBlock,
3024 bool SuppressBlockName,
bool SuppressBlock,
3032 if (!ResultType->
isVoidType() || SuppressBlock)
3037 if (!BlockProto ||
Block.getNumParams() == 0) {
3044 for (
unsigned I = 0, N =
Block.getNumParams(); I != N; ++I) {
3057 if (SuppressBlock) {
3060 if (!SuppressBlockName &&
BlockDecl->getIdentifier())
3069 if (!SuppressBlockName &&
BlockDecl->getIdentifier())
3089 if (srcText.empty() || srcText ==
"=") {
3095 std::string DefValue(srcText.str());
3098 if (DefValue.at(0) !=
'=') {
3102 return " = " + DefValue;
3104 return " " + DefValue;
3113 bool InOptional =
false) {
3114 bool FirstParameter =
true;
3116 for (
unsigned P = Start, N =
Function->getNumParams();
P != N; ++
P) {
3123 Result.getCodeCompletionTUInfo());
3124 if (!FirstParameter)
3132 FirstParameter =
false;
3144 if (
Function->isVariadic() &&
P == N - 1)
3145 PlaceholderStr +=
", ...";
3148 Result.AddPlaceholderChunk(
3149 Result.getAllocator().CopyString(PlaceholderStr));
3153 if (Proto->isVariadic()) {
3154 if (Proto->getNumParams() == 0)
3155 Result.AddPlaceholderChunk(
"...");
3165 unsigned MaxParameters = 0,
unsigned Start = 0,
bool InDefaultArg =
false) {
3166 bool FirstParameter =
true;
3175 PEnd = Params->
begin() + MaxParameters;
3178 bool HasDefaultArg =
false;
3179 std::string PlaceholderStr;
3181 if (TTP->wasDeclaredWithTypename())
3182 PlaceholderStr =
"typename";
3183 else if (
const auto *TC = TTP->getTypeConstraint()) {
3184 llvm::raw_string_ostream OS(PlaceholderStr);
3185 TC->print(OS, Policy);
3188 PlaceholderStr =
"class";
3190 if (TTP->getIdentifier()) {
3191 PlaceholderStr +=
' ';
3192 PlaceholderStr += TTP->getIdentifier()->deuglifiedName();
3195 HasDefaultArg = TTP->hasDefaultArgument();
3197 dyn_cast<NonTypeTemplateParmDecl>(*
P)) {
3198 if (NTTP->getIdentifier())
3199 PlaceholderStr = std::string(NTTP->getIdentifier()->deuglifiedName());
3200 NTTP->getType().getAsStringInternal(PlaceholderStr, Policy);
3201 HasDefaultArg = NTTP->hasDefaultArgument();
3203 assert(isa<TemplateTemplateParmDecl>(*
P));
3208 PlaceholderStr =
"template<...> class";
3210 PlaceholderStr +=
' ';
3217 if (HasDefaultArg && !InDefaultArg) {
3221 Result.getCodeCompletionTUInfo());
3222 if (!FirstParameter)
3225 P - Params->
begin(),
true);
3230 InDefaultArg =
false;
3233 FirstParameter =
false;
3238 Result.AddPlaceholderChunk(
3239 Result.getAllocator().CopyString(PlaceholderStr));
3247 bool QualifierIsInformative,
3253 std::string PrintedNNS;
3255 llvm::raw_string_ostream OS(PrintedNNS);
3256 Qualifier->print(OS, Policy);
3258 if (QualifierIsInformative)
3259 Result.AddInformativeChunk(
Result.getAllocator().CopyString(PrintedNNS));
3261 Result.AddTextChunk(
Result.getAllocator().CopyString(PrintedNNS));
3268 if (!Proto || !Proto->getMethodQuals())
3274 if (Proto->getMethodQuals().hasOnlyConst()) {
3275 Result.AddInformativeChunk(
" const");
3279 if (Proto->getMethodQuals().hasOnlyVolatile()) {
3280 Result.AddInformativeChunk(
" volatile");
3284 if (Proto->getMethodQuals().hasOnlyRestrict()) {
3285 Result.AddInformativeChunk(
" restrict");
3290 std::string QualsStr;
3291 if (Proto->isConst())
3292 QualsStr +=
" const";
3293 if (Proto->isVolatile())
3294 QualsStr +=
" volatile";
3295 if (Proto->isRestrict())
3296 QualsStr +=
" restrict";
3297 Result.AddInformativeChunk(
Result.getAllocator().CopyString(QualsStr));
3308 switch (Name.getNameKind()) {
3310 const char *OperatorName =
nullptr;
3311 switch (Name.getCXXOverloadedOperator()) {
3313 case OO_Conditional:
3315 OperatorName =
"operator";
3318#define OVERLOADED_OPERATOR(Name, Spelling, Token, Unary, Binary, MemberOnly) \
3320 OperatorName = "operator" Spelling; \
3322#define OVERLOADED_OPERATOR_MULTI(Name, Spelling, Unary, Binary, MemberOnly)
3323#include "clang/Basic/OperatorKinds.def"
3326 OperatorName =
"operator new";
3329 OperatorName =
"operator delete";
3332 OperatorName =
"operator new[]";
3334 case OO_Array_Delete:
3335 OperatorName =
"operator delete[]";
3338 OperatorName =
"operator()";
3341 OperatorName =
"operator[]";
3344 Result.AddTypedTextChunk(OperatorName);
3352 Result.AddTypedTextChunk(
3365 QualType Ty = Name.getCXXNameType();
3367 Record = cast<CXXRecordDecl>(RecordTy->getDecl());
3369 Record = InjectedTy->getDecl();
3371 Result.AddTypedTextChunk(
3376 Result.AddTypedTextChunk(
3377 Result.getAllocator().CopyString(
Record->getNameAsString()));
3391 bool IncludeBriefComments) {
3393 CCTUInfo, IncludeBriefComments);
3405 return Result.TakeString();
3416 Result.AddPlaceholderChunk(
"...");
3430 Result.AddPlaceholderChunk(
Result.getAllocator().CopyString(Arg));
3435 Result.AddPlaceholderChunk(
3436 Result.getAllocator().CopyString((*A)->getName()));
3439 return Result.TakeString();
3451 bool IncludeBriefComments) {
3467 Result.addBriefComment(RC->getBriefText(Ctx));
3477 return Result.TakeString();
3481 PP, Ctx,
Result, IncludeBriefComments, CCContext, Policy);
3485 std::string &BeforeName,
3486 std::string &NameAndSignature) {
3487 bool SeenTypedChunk =
false;
3488 for (
auto &Chunk : CCS) {
3490 assert(SeenTypedChunk &&
"optional parameter before name");
3497 NameAndSignature += Chunk.Text;
3499 BeforeName += Chunk.Text;
3511 std::string BeforeName;
3512 std::string NameAndSignature;
3515 NameAndSignature +=
" override";
3517 Result.AddTextChunk(
Result.getAllocator().CopyString(BeforeName));
3519 Result.AddTypedTextChunk(
Result.getAllocator().CopyString(NameAndSignature));
3520 return Result.TakeString();
3526 const auto *VD = dyn_cast<VarDecl>(ND);
3529 const auto *
RecordDecl = VD->getType()->getAsCXXRecordDecl();
3542 if (IncludeBriefComments) {
3545 Result.addBriefComment(RC->getBriefText(Ctx));
3550 Result.AddTypedTextChunk(
3552 Result.AddTextChunk(
"::");
3553 return Result.TakeString();
3557 Result.AddAnnotation(
Result.getAllocator().CopyString(I->getAnnotation()));
3570 if (
const auto *
Function = dyn_cast<FunctionDecl>(ND)) {
3571 AddFunctionTypeAndResult(
Function);
3572 return Result.TakeString();
3575 if (
const auto *CallOperator =
3577 AddFunctionTypeAndResult(CallOperator);
3578 return Result.TakeString();
3584 dyn_cast<FunctionTemplateDecl>(ND)) {
3595 llvm::SmallBitVector Deduced(FunTmpl->getTemplateParameters()->size());
3600 unsigned LastDeducibleArgument;
3601 for (LastDeducibleArgument = Deduced.size(); LastDeducibleArgument > 0;
3602 --LastDeducibleArgument) {
3603 if (!Deduced[LastDeducibleArgument - 1]) {
3607 bool HasDefaultArg =
false;
3608 NamedDecl *Param = FunTmpl->getTemplateParameters()->getParam(
3609 LastDeducibleArgument - 1);
3611 HasDefaultArg = TTP->hasDefaultArgument();
3613 dyn_cast<NonTypeTemplateParmDecl>(Param))
3614 HasDefaultArg = NTTP->hasDefaultArgument();
3616 assert(isa<TemplateTemplateParmDecl>(Param));
3618 cast<TemplateTemplateParmDecl>(Param)->hasDefaultArgument();
3641 LastDeducibleArgument);
3650 return Result.TakeString();
3653 if (
const auto *Template = dyn_cast<TemplateDecl>(ND)) {
3656 Result.AddTypedTextChunk(
3657 Result.getAllocator().CopyString(Template->getNameAsString()));
3661 return Result.TakeString();
3664 if (
const auto *Method = dyn_cast<ObjCMethodDecl>(ND)) {
3665 Selector Sel = Method->getSelector();
3667 Result.AddTypedTextChunk(
3669 return Result.TakeString();
3675 Result.AddTypedTextChunk(
Result.getAllocator().CopyString(SelName));
3677 Result.AddInformativeChunk(
Result.getAllocator().CopyString(SelName));
3682 Result.AddTypedTextChunk(
"");
3689 P != PEnd && Idx < Sel.
getNumArgs(); (
void)++
P, ++Idx) {
3708 QualType ParamType = (*P)->getType();
3709 std::optional<ArrayRef<QualType>> ObjCSubsts;
3725 Arg += II->getName();
3732 Result.AddTextChunk(
Result.getAllocator().CopyString(Arg));
3734 Result.AddInformativeChunk(
Result.getAllocator().CopyString(Arg));
3736 Result.AddPlaceholderChunk(
Result.getAllocator().CopyString(Arg));
3742 Result.AddTextChunk(
", ...");
3744 Result.AddInformativeChunk(
", ...");
3746 Result.AddPlaceholderChunk(
", ...");
3752 return Result.TakeString();
3759 Result.AddTypedTextChunk(
3761 return Result.TakeString();
3772 const auto *M = dyn_cast<ObjCMethodDecl>(ND);
3784 const auto *M = dyn_cast_or_null<ObjCMethodDecl>(ND);
3785 if (!M || !M->isPropertyAccessor())
3808 auto FDecl =
Result.getFunction();
3811 if (ArgIndex < FDecl->getNumParams())
3819 unsigned CurrentArg) {
3820 unsigned ChunkIndex = 0;
3821 auto AddChunk = [&](llvm::StringRef Placeholder) {
3824 const char *
Copy =
Result.getAllocator().CopyString(Placeholder);
3825 if (ChunkIndex == CurrentArg)
3833 if (
auto *CRD = llvm::dyn_cast<CXXRecordDecl>(RD)) {
3834 for (
const auto &
Base : CRD->bases())
3835 AddChunk(
Base.getType().getAsString(Policy));
3837 for (
const auto &Field : RD->
fields())
3847 unsigned CurrentArg,
unsigned Start = 0,
bool InOptional =
false) {
3853 bool FirstParameter =
true;
3854 unsigned NumParams =
3857 for (
unsigned P = Start;
P != NumParams; ++
P) {
3862 Result.getCodeCompletionTUInfo());
3863 if (!FirstParameter)
3867 PrototypeLoc, Opt, CurrentArg,
P,
3874 FirstParameter =
false;
3881 std::string Placeholder;
3882 assert(P < Prototype->getNumParams());
3891 Placeholder =
Prototype->getParamType(
P).getAsString(Policy);
3894 if (
P == CurrentArg)
3895 Result.AddCurrentParameterChunk(
3896 Result.getAllocator().CopyString(Placeholder));
3898 Result.AddPlaceholderChunk(
Result.getAllocator().CopyString(Placeholder));
3903 Result.getCodeCompletionTUInfo());
3904 if (!FirstParameter)
3907 if (CurrentArg < NumParams)
3919 if (
const auto *
Type = dyn_cast<TemplateTypeParmDecl>(Param)) {
3921 }
else if (
const auto *NonType = dyn_cast<NonTypeTemplateParmDecl>(Param)) {
3922 Optional = NonType->hasDefaultArgument();
3923 }
else if (
const auto *Template = dyn_cast<TemplateTemplateParmDecl>(Param)) {
3924 Optional = Template->hasDefaultArgument();
3927 llvm::raw_string_ostream OS(
Result);
3928 Param->
print(OS, Policy);
3934 if (
const auto *CTD = dyn_cast<ClassTemplateDecl>(TD))
3935 return CTD->getTemplatedDecl()->getKindName().str();
3936 if (
const auto *VTD = dyn_cast<VarTemplateDecl>(TD))
3937 return VTD->getTemplatedDecl()->getType().getAsString(Policy);
3938 if (
const auto *FTD = dyn_cast<FunctionTemplateDecl>(TD))
3939 return FTD->getTemplatedDecl()->getReturnType().getAsString(Policy);
3940 if (isa<TypeAliasTemplateDecl>(TD))
3942 if (isa<TemplateTemplateParmDecl>(TD))
3944 if (isa<ConceptDecl>(TD))
3954 Builder.getCodeCompletionTUInfo());
3956 if (!ResultType.empty())
3957 Builder.AddResultTypeChunk(Builder.getAllocator().CopyString(ResultType));
3958 Builder.AddTextChunk(
3964 for (
unsigned I = 0; I < Params.size(); ++I) {
3966 std::string Placeholder =
3969 Current = &OptionalBuilder;
3972 Current->AddChunk(I == CurrentArg
3975 Current->getAllocator().CopyString(Placeholder));
3978 if (Current == &OptionalBuilder)
3979 Builder.AddOptionalChunk(OptionalBuilder.
TakeString());
3983 if (isa<FunctionTemplateDecl>(TD))
3984 Builder.AddInformativeChunk(
"()");
3985 return Builder.TakeString();
3992 bool Braced)
const {
4016 if (IncludeBriefComments) {
4023 llvm::raw_string_ostream OS(Name);
4025 Result.AddTextChunk(
Result.getAllocator().CopyString(OS.str()));
4028 Result.AddResultTypeChunk(
Result.getAllocator().CopyString(
4043 return Result.TakeString();
4048 bool PreferredTypeIsPointer) {
4052 if (MacroName.equals(
"nil") || MacroName.equals(
"NULL") ||
4053 MacroName.equals(
"Nil")) {
4055 if (PreferredTypeIsPointer)
4059 else if (MacroName.equals(
"YES") || MacroName.equals(
"NO") ||
4060 MacroName.equals(
"true") || MacroName.equals(
"false"))
4063 else if (MacroName.equals(
"bool"))
4076 case Decl::EnumConstant:
4080 case Decl::Function:
4082 case Decl::ObjCCategory:
4084 case Decl::ObjCCategoryImpl:
4086 case Decl::ObjCImplementation:
4089 case Decl::ObjCInterface:
4091 case Decl::ObjCIvar:
4093 case Decl::ObjCMethod:
4094 return cast<ObjCMethodDecl>(D)->isInstanceMethod()
4097 case Decl::CXXMethod:
4099 case Decl::CXXConstructor:
4101 case Decl::CXXDestructor:
4103 case Decl::CXXConversion:
4105 case Decl::ObjCProperty:
4107 case Decl::ObjCProtocol:
4113 case Decl::TypeAlias:
4115 case Decl::TypeAliasTemplate:
4119 case Decl::Namespace:
4121 case Decl::NamespaceAlias:
4123 case Decl::TemplateTypeParm:
4125 case Decl::NonTypeTemplateParm:
4127 case Decl::TemplateTemplateParm:
4129 case Decl::FunctionTemplate:
4131 case Decl::ClassTemplate:
4133 case Decl::AccessSpec:
4135 case Decl::ClassTemplatePartialSpecialization:
4137 case Decl::UsingDirective:
4139 case Decl::StaticAssert:
4143 case Decl::TranslationUnit:
4147 case Decl::UnresolvedUsingValue:
4148 case Decl::UnresolvedUsingTypename:
4151 case Decl::UsingEnum:
4154 case Decl::ObjCPropertyImpl:
4155 switch (cast<ObjCPropertyImplDecl>(D)->getPropertyImplementation()) {
4162 llvm_unreachable(
"Unexpected Kind!");
4167 case Decl::ObjCTypeParam:
4173 case Decl::LinkageSpec:
4177 if (
const auto *TD = dyn_cast<TagDecl>(D)) {
4178 switch (TD->getTagKind()) {
4196 bool LoadExternal,
bool IncludeUndefined,
4197 bool TargetTypeIsPointer =
false) {
4200 Results.EnterNewScope();
4206 if (IncludeUndefined || MD) {
4214 TargetTypeIsPointer)));
4218 Results.ExitScope();
4222 ResultBuilder &Results) {
4225 Results.EnterNewScope();
4229 if (LangOpts.C99 || LangOpts.CPlusPlus11)
4231 Results.ExitScope();
4238 unsigned NumResults) {
4300 llvm_unreachable(
"Invalid ParserCompletionContext!");
4312 ResultBuilder &Results) {
4315 while (isa<BlockDecl>(CurContext))
4318 CXXMethodDecl *Method = dyn_cast<CXXMethodDecl>(CurContext);
4325 if (!
P->getDeclName())
4331 Results.getCodeCompletionTUInfo());
4338 S.
Context, CurContext, Overridden->getDeclContext());
4341 llvm::raw_string_ostream OS(Str);
4342 NNS->
print(OS, Policy);
4343 Builder.AddTextChunk(Results.getAllocator().CopyString(OS.str()));
4345 }
else if (!InContext->
Equals(Overridden->getDeclContext()))
4348 Builder.AddTypedTextChunk(
4349 Results.getAllocator().CopyString(Overridden->getNameAsString()));
4351 bool FirstParam =
true;
4358 Builder.AddPlaceholderChunk(
4359 Results.getAllocator().CopyString(
P->getIdentifier()->getName()));
4365 Results.Ignore(Overridden);
4372 ResultBuilder Results(*
this, CodeCompleter->getAllocator(),
4373 CodeCompleter->getCodeCompletionTUInfo(),
4375 Results.EnterNewScope();
4383 PP.getHeaderSearchInfo().collectAllModules(Modules);
4384 for (
unsigned I = 0, N = Modules.size(); I != N; ++I) {
4385 Builder.AddTypedTextChunk(
4386 Builder.getAllocator().CopyString(Modules[I]->Name));
4387 Results.AddResult(
Result(
4392 }
else if (getLangOpts().Modules) {
4400 Builder.AddTypedTextChunk(
4401 Builder.getAllocator().CopyString(Submodule->Name));
4402 Results.AddResult(
Result(
4409 Results.ExitScope();
4411 Results.data(), Results.size());
4416 ResultBuilder Results(*
this, CodeCompleter->getAllocator(),
4417 CodeCompleter->getCodeCompletionTUInfo(),
4419 Results.EnterNewScope();
4424 switch (CompletionContext) {
4427 case PCC_ObjCInterface:
4428 case PCC_ObjCImplementation:
4429 case PCC_ObjCInstanceVariableList:
4431 case PCC_MemberTemplate:
4433 case PCC_LocalDeclarationSpecifiers:
4434 Results.setFilter(&ResultBuilder::IsOrdinaryNonValueName);
4438 case PCC_TopLevelOrExpression:
4439 case PCC_ParenthesizedExpression:
4440 case PCC_Expression:
4444 Results.setFilter(&ResultBuilder::IsOrdinaryName);
4446 Results.setFilter(&ResultBuilder::IsOrdinaryNonTypeName);
4452 case PCC_RecoveryInFunction:
4459 auto ThisType = getCurrentThisType();
4460 if (!ThisType.isNull())
4461 Results.setObjectTypeQualifiers(ThisType->getPointeeType().getQualifiers(),
4464 CodeCompletionDeclConsumer Consumer(Results, CurContext);
4465 LookupVisibleDecls(S, LookupOrdinaryName, Consumer,
4466 CodeCompleter->includeGlobals(),
4467 CodeCompleter->loadExternal());
4470 Results.ExitScope();
4472 switch (CompletionContext) {
4473 case PCC_ParenthesizedExpression:
4474 case PCC_Expression:
4476 case PCC_TopLevelOrExpression:
4477 case PCC_RecoveryInFunction:
4478 if (S->getFnParent())
4484 case PCC_ObjCInterface:
4485 case PCC_ObjCImplementation:
4486 case PCC_ObjCInstanceVariableList:
4488 case PCC_MemberTemplate:
4492 case PCC_LocalDeclarationSpecifiers:
4496 if (CodeCompleter->includeMacros())
4500 Results.data(), Results.size());
4506 bool AtArgumentExpression,
bool IsSuper,
4507 ResultBuilder &Results);
4510 bool AllowNonIdentifiers,
4511 bool AllowNestedNameSpecifiers) {
4513 ResultBuilder Results(
4514 *
this, CodeCompleter->getAllocator(),
4515 CodeCompleter->getCodeCompletionTUInfo(),
4516 AllowNestedNameSpecifiers
4521 Results.EnterNewScope();
4524 Results.AddResult(
Result(
"const"));
4525 Results.AddResult(
Result(
"volatile"));
4526 if (getLangOpts().
C99)
4527 Results.AddResult(
Result(
"restrict"));
4533 Results.AddResult(
"final");
4535 if (AllowNonIdentifiers) {
4536 Results.AddResult(
Result(
"operator"));
4540 if (AllowNestedNameSpecifiers) {
4541 Results.allowNestedNameSpecifiers();
4542 Results.setFilter(&ResultBuilder::IsImpossibleToSatisfy);
4543 CodeCompletionDeclConsumer Consumer(Results, CurContext);
4544 LookupVisibleDecls(S, LookupNestedNameSpecifierName, Consumer,
4545 CodeCompleter->includeGlobals(),
4546 CodeCompleter->loadExternal());
4547 Results.setFilter(
nullptr);
4550 Results.ExitScope();
4556 if (AllowNonIdentifiers && !AllowNestedNameSpecifiers &&
4576 Results.data(), Results.size());
4580 if (
Scope ==
"clang")
4588 if (
Scope ==
"_Clang")
4590 if (
Scope ==
"__gnu__")
4598 if (Completion == AttributeCompletion::None)
4600 ResultBuilder Results(*
this, CodeCompleter->getAllocator(),
4601 CodeCompleter->getCodeCompletionTUInfo(),
4614 llvm::StringRef InScopeName;
4615 bool InScopeUnderscore =
false;
4617 InScopeName = InScope->
getName();
4619 InScopeName = NoUnderscore;
4620 InScopeUnderscore =
true;
4629 if (A.IsTargetSpecific && !A.existsInTarget(Context.
getTargetInfo()))
4631 if (!A.acceptsLangOpts(getLangOpts()))
4633 for (
const auto &S : A.Spellings) {
4634 if (S.Syntax != Syntax)
4636 llvm::StringRef Name = S.NormalizedFullName;
4637 llvm::StringRef
Scope;
4640 std::tie(
Scope, Name) = Name.split(
"::");
4642 std::swap(Name,
Scope);
4646 if (Completion == AttributeCompletion::Scope) {
4648 if (!
Scope.empty() && FoundScopes.insert(
Scope).second) {
4659 if (!InScopeName.empty()) {
4660 if (
Scope != InScopeName)
4665 auto Add = [&](llvm::StringRef
Scope, llvm::StringRef Name,
4668 Results.getCodeCompletionTUInfo());
4670 if (!
Scope.empty()) {
4679 Builder.AddTypedTextChunk(Results.getAllocator().CopyString(
Text));
4681 if (!A.ArgNames.empty()) {
4684 for (
const char *Arg : A.ArgNames) {
4688 Builder.AddPlaceholderChunk(Arg);
4693 Results.AddResult(Builder.TakeString());
4700 if (!InScopeUnderscore)
4701 Add(
Scope, Name,
false);
4706 if (!(InScope && !InScopeUnderscore) && SyntaxSupportsGuards) {
4708 if (
Scope.empty()) {
4709 Add(
Scope, Name,
true);
4714 Add(GuardedScope, Name,
true);
4724 for (
const auto &Entry : ParsedAttrInfoRegistry::entries())
4725 AddCompletions(*Entry.instantiate());
4728 Results.data(), Results.size());
4733 bool IsParenthesized =
false)
4734 : PreferredType(PreferredType), IntegralConstantExpression(
false),
4735 ObjCCollection(
false), IsParenthesized(IsParenthesized) {}
4746struct CoveredEnumerators {
4754 const CoveredEnumerators &Enumerators) {
4756 if (Context.
getLangOpts().CPlusPlus && !Qualifier && Enumerators.Seen.empty()) {
4763 Results.EnterNewScope();
4764 for (
auto *E :
Enum->enumerators()) {
4765 if (Enumerators.Seen.count(E))
4769 Results.AddResult(R, CurContext,
nullptr,
false);
4771 Results.ExitScope();
4777 assert(!
T.isNull());
4800 if (!Results.includeCodePatterns())
4803 Results.getCodeCompletionTUInfo());
4808 if (!Parameters.empty()) {
4817 constexpr llvm::StringLiteral NamePlaceholder =
"!#!NAME_GOES_HERE!#!";
4818 std::string
Type = std::string(NamePlaceholder);
4820 llvm::StringRef Prefix, Suffix;
4821 std::tie(Prefix, Suffix) = llvm::StringRef(
Type).split(NamePlaceholder);
4822 Prefix = Prefix.rtrim();
4823 Suffix = Suffix.ltrim();
4846 ResultBuilder Results(
4847 *
this, CodeCompleter->getAllocator(),
4848 CodeCompleter->getCodeCompletionTUInfo(),
4850 Data.IsParenthesized
4853 Data.PreferredType));
4855 Data.IsParenthesized ? PCC_ParenthesizedExpression : PCC_Expression;
4856 if (
Data.ObjCCollection)
4857 Results.setFilter(&ResultBuilder::IsObjCCollection);
4858 else if (
Data.IntegralConstantExpression)
4859 Results.setFilter(&ResultBuilder::IsIntegralConstantValue);
4861 Results.setFilter(&ResultBuilder::IsOrdinaryName);
4863 Results.setFilter(&ResultBuilder::IsOrdinaryNonTypeName);
4865 if (!
Data.PreferredType.isNull())
4866 Results.setPreferredType(
Data.PreferredType.getNonReferenceType());
4869 for (
unsigned I = 0, N =
Data.IgnoreDecls.size(); I != N; ++I)
4870 Results.Ignore(
Data.IgnoreDecls[I]);
4872 CodeCompletionDeclConsumer Consumer(Results, CurContext);
4873 LookupVisibleDecls(S, LookupOrdinaryName, Consumer,
4874 CodeCompleter->includeGlobals(),
4875 CodeCompleter->loadExternal());
4877 Results.EnterNewScope();
4879 Results.ExitScope();
4881 bool PreferredTypeIsPointer =
false;
4882 if (!
Data.PreferredType.isNull()) {
4883 PreferredTypeIsPointer =
Data.PreferredType->isAnyPointerType() ||
4884 Data.PreferredType->isMemberPointerType() ||
4885 Data.PreferredType->isBlockPointerType();
4886 if (
Data.PreferredType->isEnumeralType()) {
4888 if (
auto *Def =
Enum->getDefinition())
4896 if (S->getFnParent() && !
Data.ObjCCollection &&
4897 !
Data.IntegralConstantExpression)
4900 if (CodeCompleter->includeMacros())
4902 PreferredTypeIsPointer);
4912 Results.data(), Results.size());
4916 bool IsParenthesized) {
4917 return CodeCompleteExpression(
4924 CodeCompleteExpression(S, PreferredType);
4925 else if (getLangOpts().
ObjC)
4926 CodeCompleteObjCInstanceMessage(S, E.
get(), std::nullopt,
false);
4943 if (Protocol->hasDefinition())
4944 return Protocol->getDefinition();
4958 Builder.AddResultTypeChunk(
4960 Policy, Builder.getAllocator()));
4966 Builder.AddPlaceholderChunk(
"...");
4968 for (
unsigned I = 0, N = BlockLoc.
getNumParams(); I != N; ++I) {
4973 std::string PlaceholderStr =
4976 if (I == N - 1 && BlockProtoLoc &&
4978 PlaceholderStr +=
", ...";
4981 Builder.AddPlaceholderChunk(
4982 Builder.getAllocator().CopyString(PlaceholderStr));
4992 bool AllowNullaryMethods,
DeclContext *CurContext,
4994 bool IsBaseExprStatement =
false,
4995 bool IsClassProperty =
false,
bool InOriginalClass =
true) {
5003 if (!AddedProperties.insert(
P->getIdentifier()).second)
5008 if (!
P->getType().getTypePtr()->isBlockPointerType() ||
5009 !IsBaseExprStatement) {
5011 if (!InOriginalClass)
5013 Results.MaybeAddResult(R, CurContext);
5025 if (!InOriginalClass)
5027 Results.MaybeAddResult(R, CurContext);
5034 Results.getCodeCompletionTUInfo());
5037 BlockLoc, BlockProtoLoc);
5038 Result R =
Result(Builder.TakeString(),
P, Results.getBasePriority(
P));
5039 if (!InOriginalClass)
5041 Results.MaybeAddResult(R, CurContext);
5045 if (!
P->isReadOnly()) {
5047 Results.getCodeCompletionTUInfo());
5051 Builder.AddTypedTextChunk(
5052 Results.getAllocator().CopyString(
P->getName()));
5057 BlockProtoLoc,
true);
5059 Builder.AddPlaceholderChunk(
5060 Builder.getAllocator().CopyString(PlaceholderStr));
5068 Result(Builder.TakeString(),
P,
5069 Results.getBasePriority(
P) +
5073 if (!InOriginalClass)
5075 Results.MaybeAddResult(R, CurContext);
5079 if (IsClassProperty) {
5080 for (
const auto *
P : Container->class_properties())
5083 for (
const auto *
P : Container->instance_properties())
5088 if (AllowNullaryMethods) {
5089 ASTContext &Context = Container->getASTContext();
5093 const IdentifierInfo *Name = M->getSelector().getIdentifierInfoForSlot(0);
5096 if (!AddedProperties.insert(Name).second)
5099 Results.getCodeCompletionTUInfo());
5101 Builder.AddTypedTextChunk(
5102 Results.getAllocator().CopyString(Name->getName()));
5105 if (!InOriginalClass)
5107 Results.MaybeAddResult(R, CurContext);
5110 if (IsClassProperty) {
5111 for (
const auto *M : Container->methods()) {
5115 if (!M->getSelector().isUnarySelector() ||
5116 M->getReturnType()->isVoidType() || M->isInstanceMethod())
5121 for (
auto *M : Container->methods()) {
5122 if (M->getSelector().isUnarySelector())
5130 for (
auto *
P : Protocol->protocols())
5132 CurContext, AddedProperties, Results,
5133 IsBaseExprStatement, IsClassProperty,
5136 dyn_cast<ObjCInterfaceDecl>(Container)) {
5137 if (AllowCategories) {
5139 for (
auto *Cat : IFace->known_categories())
5141 CurContext, AddedProperties, Results,
5142 IsBaseExprStatement, IsClassProperty,
5147 for (
auto *I : IFace->all_referenced_protocols())
5149 CurContext, AddedProperties, Results,
5150 IsBaseExprStatement, IsClassProperty,
5154 if (IFace->getSuperClass())
5156 AllowNullaryMethods, CurContext, AddedProperties,
5157 Results, IsBaseExprStatement, IsClassProperty,
5160 dyn_cast<ObjCCategoryDecl>(Container)) {
5164 CurContext, AddedProperties, Results,
5165 IsBaseExprStatement, IsClassProperty,
5174 std::optional<FixItHint> AccessOpFixIt) {
5177 Results.setObjectTypeQualifiers(BaseType.
getQualifiers(), BaseKind);
5180 Results.allowNestedNameSpecifiers();
5181 std::vector<FixItHint> FixIts;
5183 FixIts.emplace_back(*AccessOpFixIt);
5184 CodeCompletionDeclConsumer Consumer(Results, RD, BaseType, std::move(FixIts));
5191 if (!Results.empty()) {
5197 for (
Scope *DepScope = S; DepScope; DepScope = DepScope->getParent())
5216 if (
const auto *CTSD =
5217 llvm::dyn_cast<ClassTemplateSpecializationDecl>(RD)) {
5221 RD = CTSD->getSpecializedTemplate()->getTemplatedDecl();
5227 if (
const auto *TD = dyn_cast_or_null<ClassTemplateDecl>(
5228 TST->getTemplateName().getAsTemplateDecl())) {
5229 return TD->getTemplatedDecl();
5273 std::optional<SmallVector<QualType, 1>> ArgTypes;
5275 enum AccessOperator {
5292 std::string AsString;
5294 llvm::raw_string_ostream OS(AsString);
5295 QualType ExactType = deduceType(*ResultType);
5301 B.AddResultTypeChunk(Alloc.
CopyString(AsString));
5304 B.AddTypedTextChunk(Alloc.
CopyString(Name->getName()));
5321 return B.TakeString();
5329 auto *TemplatedEntity = getTemplatedEntity(BaseType.
getDecl(), S);
5330 for (
const Expr *E : constraintsForTemplatedEntity(TemplatedEntity))
5331 believe(E, &BaseType);
5334 std::vector<Member> members() {
5335 std::vector<Member> Results;
5336 for (
const auto &E : this->Results)
5337 Results.push_back(E.second);
5338 llvm::sort(Results, [](
const Member &L,
const Member &R) {
5339 return L.Name->getName() < R.Name->getName();
5349 if (
auto *CSE = dyn_cast<ConceptSpecializationExpr>(E)) {
5363 for (
const auto &Arg : CSE->getTemplateArguments()) {
5364 if (Index >= Params->
size())
5366 if (isApprox(Arg,
T)) {
5367 auto *TTPD = dyn_cast<TemplateTypeParmDecl>(Params->
getParam(Index));
5371 auto *TT = cast<TemplateTypeParmType>(TTPD->getTypeForDecl());
5379 }
else if (
auto *BO = dyn_cast<BinaryOperator>(E)) {
5382 if (BO->getOpcode() == BO_LAnd || BO->getOpcode() == BO_LOr) {
5383 believe(BO->getLHS(),
T);
5384 believe(BO->getRHS(),
T);
5386 }
else if (
auto *RE = dyn_cast<RequiresExpr>(E)) {
5389 if (!Req->isDependent())
5393 if (
auto *TR = dyn_cast<concepts::TypeRequirement>(Req)) {
5395 QualType AssertedType = TR->getType()->getType();
5396 ValidVisitor(
this,
T).TraverseType(AssertedType);
5397 }
else if (
auto *ER = dyn_cast<concepts::ExprRequirement>(Req)) {
5398 ValidVisitor Visitor(
this,
T);
5402 if (ER->getReturnTypeRequirement().isTypeConstraint()) {
5404 ER->getReturnTypeRequirement().getTypeConstraint();
5405 Visitor.OuterExpr = ER->getExpr();
5407 Visitor.TraverseStmt(ER->getExpr());
5408 }
else if (
auto *NR = dyn_cast<concepts::NestedRequirement>(Req)) {
5409 believe(NR->getConstraintExpr(),
T);
5426 Expr *OuterExpr =
nullptr;
5430 : Outer(Outer),
T(
T) {
5438 if (
Base->isPointerType() && IsArrow) {
5440 Base =
Base->getPointeeType().getTypePtr();
5442 if (isApprox(
Base,
T))
5443 addValue(E, E->
getMember(), IsArrow ? Member::Arrow : Member::Dot);
5457 if (Q && isApprox(Q->getAsType(),
T))
5468 if (Q && isApprox(Q->getAsType(),
T))
5486 void addResult(
Member &&M) {
5487 auto R = Outer->Results.try_emplace(M.Name);
5488 Member &O = R.first->second;
5492 std::make_tuple(M.ArgTypes.has_value(), M.ResultType !=
nullptr,
5493 M.Operator) > std::make_tuple(O.ArgTypes.has_value(),
5494 O.ResultType !=
nullptr,
5504 M.Operator = Member::Colons;
5505 addResult(std::move(M));
5509 Member::AccessOperator Operator) {
5510 if (!Name.isIdentifier())
5513 Result.Name = Name.getAsIdentifierInfo();
5514 Result.Operator = Operator;
5517 if (Caller !=
nullptr && Callee == E) {
5518 Result.ArgTypes.emplace();
5519 for (
const auto *Arg : Caller->
arguments())
5520 Result.ArgTypes->push_back(Arg->getType());
5521 if (Caller == OuterExpr) {
5522 Result.ResultType = OuterType;
5526 Result.ResultType = OuterType;
5528 addResult(std::move(Result));
5537 static bool isApprox(
const Type *T1,
const Type *T2) {
5550 Scope *Inner =
nullptr;
5552 if (S->isTemplateParamScope() && S->isDeclScope(D))
5553 return Inner ? Inner->getEntity() :
nullptr;
5569 TD->getAssociatedConstraints(Result);
5571 if (
const auto *CTPSD =
5572 dyn_cast<ClassTemplatePartialSpecializationDecl>(DC))
5573 CTPSD->getAssociatedConstraints(Result);
5574 if (
const auto *VTPSD = dyn_cast<VarTemplatePartialSpecializationDecl>(DC))
5575 VTPSD->getAssociatedConstraints(Result);
5586 if (
const auto *Args =
T.getTemplateArgsAsWritten())
5587 if (Args->getNumTemplateArgs() == 1) {
5588 const auto &Arg = Args->arguments().front().getArgument();
5595 llvm::DenseMap<const IdentifierInfo *, Member> Results;
5608 if (!
Unresolved->isSpecificBuiltinType(BuiltinType::Dependent)) {
5610 if (!
Auto || !
Auto->isUndeducedAutoType())
5614 if (
const CallExpr *CE = llvm::dyn_cast<CallExpr>(E)) {
5617 Callee->isSpecificPlaceholderType(BuiltinType::BoundMember))
5623 Callee = FnTypePtr->getPointeeType();
5625 Callee = BPT->getPointeeType();
5628 return FnType->getReturnType().getNonReferenceType();
5631 if (
const auto *OE = llvm::dyn_cast<OverloadExpr>(CE->
getCallee())) {
5635 const Type *Common =
nullptr;
5636 for (
const auto *D : OE->decls()) {
5638 if (
const auto *FD = llvm::dyn_cast<FunctionDecl>(D))
5639 ReturnType = FD->getReturnType();
5640 else if (
const auto *FTD = llvm::dyn_cast<FunctionTemplateDecl>(D))
5641 ReturnType = FTD->getTemplatedDecl()->getReturnType();
5644 const Type *Candidate =
5646 if (Common && Common != Candidate)
5650 if (Common !=
nullptr)
5655 if (
const auto *CDSME = llvm::dyn_cast<CXXDependentScopeMemberExpr>(E)) {
5657 ? CDSME->getBaseType()
5658 : getApproximateType(CDSME->getBase());
5659 if (CDSME->isArrow() && !
Base.isNull())
5665 if (RD && RD->isCompleteDefinition()) {
5667 for (
const auto *
Member : RD->lookupDependentName(
5669 return llvm::isa<ValueDecl>(Member);
5671 return llvm::cast<ValueDecl>(
Member)->getType().getNonReferenceType();
5676 if (
const auto *DRE = llvm::dyn_cast<DeclRefExpr>(E)) {
5677 if (
const auto *VD = llvm::dyn_cast<VarDecl>(DRE->getDecl())) {
5679 return getApproximateType(VD->getInit());
5682 if (
const auto *UO = llvm::dyn_cast<UnaryOperator>(E)) {
5683 if (UO->getOpcode() == UnaryOperatorKind::UO_Deref)
5684 return UO->getSubExpr()->getType()->getPointeeType();
5694 if (
auto *PLE = llvm::dyn_cast_or_null<ParenListExpr>(
Base)) {
5695 if (PLE->getNumExprs() == 0)
5697 Base = PLE->getExpr(PLE->getNumExprs() - 1);
5707 bool IsBaseExprStatement,
5710 OtherOpBase = unwrapParenList(OtherOpBase);
5711 if (!
Base || !CodeCompleter)
5714 ExprResult ConvertedBase = PerformMemberExprBaseConversion(
Base, IsArrow);
5717 QualType ConvertedBaseType = getApproximateType(ConvertedBase.
get());
5739 ResultBuilder Results(*
this, CodeCompleter->getAllocator(),
5740 CodeCompleter->getCodeCompletionTUInfo(), CCContext,
5741 &ResultBuilder::IsMember);
5743 auto DoCompletion = [&](
Expr *
Base,
bool IsArrow,
5744 std::optional<FixItHint> AccessOpFixIt) ->
bool {
5748 ExprResult ConvertedBase = PerformMemberExprBaseConversion(
Base, IsArrow);
5772 RD, std::move(AccessOpFixIt));
5773 }
else if (
const auto *TTPT =
5774 dyn_cast<TemplateTypeParmType>(BaseType.
getTypePtr())) {
5776 IsArrow ? ConceptInfo::Member::Arrow : ConceptInfo::Member::Dot;
5777 for (
const auto &R : ConceptInfo(*TTPT, S).members()) {
5778 if (R.Operator != Operator)
5781 R.render(*
this, CodeCompleter->getAllocator(),
5782 CodeCompleter->getCodeCompletionTUInfo()));
5784 Result.FixIts.push_back(*AccessOpFixIt);
5785 Results.AddResult(std::move(
Result));
5791 if (AccessOpFixIt) {
5799 assert(ObjCPtr &&
"Non-NULL pointer guaranteed above!");
5802 AddedProperties, Results, IsBaseExprStatement);
5808 CurContext, AddedProperties, Results,
5809 IsBaseExprStatement,
false,
5816 if (AccessOpFixIt) {
5822 Class = ObjCPtr->getInterfaceDecl();
5828 CodeCompletionDeclConsumer Consumer(Results,
Class, BaseType);
5829 Results.setFilter(&ResultBuilder::IsObjCIvar);
5831 Class, LookupMemberName, Consumer, CodeCompleter->includeGlobals(),
5832 false, CodeCompleter->loadExternal());
5840 Results.EnterNewScope();
5842 bool CompletionSucceded = DoCompletion(
Base, IsArrow, std::nullopt);
5843 if (CodeCompleter->includeFixIts()) {
5846 CompletionSucceded |= DoCompletion(
5847 OtherOpBase, !IsArrow,
5851 Results.ExitScope();
5853 if (!CompletionSucceded)
5858 Results.data(), Results.size());
5864 bool IsBaseExprStatement) {
5871 ResultBuilder Results(*
this, CodeCompleter->getAllocator(),
5872 CodeCompleter->getCodeCompletionTUInfo(), CCContext,
5873 &ResultBuilder::IsMember);
5874 Results.EnterNewScope();
5877 true, CurContext, AddedProperties,
5878 Results, IsBaseExprStatement,
5880 Results.ExitScope();
5882 Results.data(), Results.size());
5889 ResultBuilder::LookupFilter Filter =
nullptr;
5894 Filter = &ResultBuilder::IsEnum;
5899 Filter = &ResultBuilder::IsUnion;
5906 Filter = &ResultBuilder::IsClassOrStruct;
5911 llvm_unreachable(
"Unknown type specifier kind in CodeCompleteTag");
5914 ResultBuilder Results(*
this, CodeCompleter->getAllocator(),
5915 CodeCompleter->getCodeCompletionTUInfo(), ContextKind);
5916 CodeCompletionDeclConsumer Consumer(Results, CurContext);
5919 Results.setFilter(Filter);
5920 LookupVisibleDecls(S, LookupTagName, Consumer,
5921 CodeCompleter->includeGlobals(),
5922 CodeCompleter->loadExternal());
5924 if (CodeCompleter->includeGlobals()) {
5926 Results.setFilter(&ResultBuilder::IsNestedNameSpecifier);
5927 LookupVisibleDecls(S, LookupNestedNameSpecifierName, Consumer,
5928 CodeCompleter->includeGlobals(),
5929 CodeCompleter->loadExternal());
5933 Results.data(), Results.size());
5939 Results.AddResult(
"const");
5941 Results.AddResult(
"volatile");
5943 Results.AddResult(
"restrict");
5945 Results.AddResult(
"_Atomic");
5947 Results.AddResult(
"__unaligned");
5951 ResultBuilder Results(*
this, CodeCompleter->getAllocator(),
5952 CodeCompleter->getCodeCompletionTUInfo(),
5954 Results.EnterNewScope();
5956 Results.ExitScope();
5958 Results.data(), Results.size());
5963 ResultBuilder Results(*
this, CodeCompleter->getAllocator(),
5964 CodeCompleter->getCodeCompletionTUInfo(),
5966 Results.EnterNewScope();
5968 if (LangOpts.CPlusPlus11) {
5969 Results.AddResult(
"noexcept");
5973 Results.AddResult(
"final");
5975 Results.AddResult(
"override");
5978 Results.ExitScope();
5980 Results.data(), Results.size());
5984 CodeCompleteExpression(S,
QualType(getASTContext().getSizeType()));
5988 if (getCurFunction()->SwitchStack.empty() || !CodeCompleter)
5996 if (!
type->isEnumeralType()) {
5998 Data.IntegralConstantExpression =
true;
5999 CodeCompleteExpression(S,
Data);
6013 CoveredEnumerators Enumerators;
6015 SC = SC->getNextSwitchCase()) {
6016 CaseStmt *Case = dyn_cast<CaseStmt>(SC);
6021 if (
auto *DRE = dyn_cast<DeclRefExpr>(CaseVal))
6022 if (
auto *Enumerator =
6023 dyn_cast<EnumConstantDecl>(DRE->getDecl())) {
6030 Enumerators.Seen.insert(Enumerator);
6043 Enumerators.SuggestedQualifier = DRE->getQualifier();
6048 ResultBuilder Results(*
this, CodeCompleter->getAllocator(),
6049 CodeCompleter->getCodeCompletionTUInfo(),
6053 if (CodeCompleter->includeMacros()) {
6057 Results.data(), Results.size());
6061 if (Args.size() && !Args.data())
6064 for (
unsigned I = 0; I != Args.size(); ++I)
6085 if (Candidate.Function) {
6086 if (Candidate.Function->isDeleted())
6089 Candidate.Function) &&
6090 Candidate.Function->getNumParams() <= ArgSize &&
6099 if (Candidate.Viable)
6113 for (
auto &Candidate : Candidates) {
6114 QualType CandidateParamType = Candidate.getParamType(N);
6115 if (CandidateParamType.
isNull())
6117 if (ParamType.
isNull()) {
6118 ParamType = CandidateParamType;
6135 if (Candidates.empty())
6139 SemaRef, CurrentArg, Candidates.data(), Candidates.size(), OpenParLoc,
6151 Target =
T->getDecl()->getTypeSourceInfo()->getTypeLoc();
6153 }
else if (
const auto *DR = dyn_cast<DeclRefExpr>(Fn)) {
6154 const auto *D = DR->getDecl();
6155 if (
const auto *
const VD = dyn_cast<VarDecl>(D)) {
6156 Target = VD->getTypeSourceInfo()->getTypeLoc();
6158 }
else if (
const auto *ME = dyn_cast<MemberExpr>(Fn)) {
6159 const auto *MD = ME->getMemberDecl();
6160 if (
const auto *FD = dyn_cast<FieldDecl>(MD)) {
6161 Target = FD->getTypeSourceInfo()->getTypeLoc();
6175 Target = A.getModifiedLoc();
6194 Fn = unwrapParenList(Fn);
6195 if (!CodeCompleter || !Fn)
6205 auto ArgsWithoutDependentTypes =
6215 if (
auto ULE = dyn_cast<UnresolvedLookupExpr>(NakedFn)) {
6216 AddOverloadedCallCandidates(ULE, ArgsWithoutDependentTypes, CandidateSet,
6218 }
else if (
auto UME = dyn_cast<UnresolvedMemberExpr>(NakedFn)) {
6220 if (UME->hasExplicitTemplateArgs()) {
6221 UME->copyTemplateArgumentsInto(TemplateArgsBuffer);
6222 TemplateArgs = &TemplateArgsBuffer;
6227 1, UME->isImplicitAccess() ?
nullptr : UME->getBase());
6228 ArgExprs.append(ArgsWithoutDependentTypes.begin(),
6229 ArgsWithoutDependentTypes.end());
6231 Decls.
append(UME->decls_begin(), UME->decls_end());
6232 const bool FirstArgumentIsBase = !UME->isImplicitAccess() && UME->getBase();
6233 AddFunctionCandidates(Decls, ArgExprs, CandidateSet, TemplateArgs,
6235 true, FirstArgumentIsBase);
6238 if (
auto *MCE = dyn_cast<MemberExpr>(NakedFn))
6239 FD = dyn_cast<FunctionDecl>(MCE->getMemberDecl());
6240 else if (
auto *DRE = dyn_cast<DeclRefExpr>(NakedFn))
6241 FD = dyn_cast<FunctionDecl>(DRE->getDecl());
6248 ArgsWithoutDependentTypes, CandidateSet,
6256 if (isCompleteType(Loc, NakedFn->
getType())) {
6259 LookupResult R(*
this, OpName, Loc, LookupOrdinaryName);
6260 LookupQualifiedName(R, DC);
6263 ArgExprs.append(ArgsWithoutDependentTypes.begin(),
6264 ArgsWithoutDependentTypes.end());
6281 ArgsWithoutDependentTypes.size(),
6317static std::optional<unsigned>
6320 static constexpr unsigned Invalid = std::numeric_limits<unsigned>::max();
6326 unsigned ArgsAfterDesignator = 0;
6327 for (
const Expr *Arg : Args) {
6328 if (
const auto *DIE = dyn_cast<DesignatedInitExpr>(Arg)) {
6329 if (DIE->size() == 1 && DIE->getDesignator(0)->isFieldDesignator()) {
6330 DesignatedFieldName = DIE->getDesignator(0)->getFieldName();
6331 ArgsAfterDesignator = 0;
6335 }
else if (isa<DesignatedInitUpdateExpr>(Arg)) {
6338 ++ArgsAfterDesignator;
6341 if (!DesignatedFieldName)
6342 return std::nullopt;
6346 unsigned DesignatedIndex = 0;
6347 const FieldDecl *DesignatedField =
nullptr;
6348 for (
const auto *Field :
Aggregate.getAggregate()->fields()) {
6349 if (Field->getIdentifier() == DesignatedFieldName) {
6350 DesignatedField = Field;
6355 if (!DesignatedField)
6359 unsigned AggregateSize =
Aggregate.getNumParams();
6360 while (DesignatedIndex < AggregateSize &&
6361 Aggregate.getParamDecl(DesignatedIndex) != DesignatedField)
6365 return DesignatedIndex + ArgsAfterDesignator + 1;
6390 if (Braced && !RD->
isUnion() &&
6391 (!LangOpts.CPlusPlus || (CRD && CRD->
isAggregate()))) {
6395 if (
auto NextIndex =
6398 if (*NextIndex >= AggregateSize)
6400 Results.push_back(AggregateSig);
6406 if (Args.size() < AggregateSize)
6407 Results.push_back(AggregateSig);
6415 for (
NamedDecl *
C : LookupConstructors(CRD)) {
6416 if (
auto *FD = dyn_cast<FunctionDecl>(
C)) {
6419 if (Braced && LangOpts.CPlusPlus && isInitListConstructor(FD))
6426 }
else if (
auto *FTD = dyn_cast<FunctionTemplateDecl>(
C)) {
6427 if (Braced && LangOpts.CPlusPlus &&
6428 isInitListConstructor(FTD->getTemplatedDecl()))
6431 AddTemplateOverloadCandidate(
6433 nullptr, Args, CandidateSet,
6452 dyn_cast<CXXConstructorDecl>(ConstructorDecl);
6456 if (
ValueDecl *MemberDecl = tryLookupCtorInitMemberDecl(
6457 Constructor->getParent(), SS, TemplateTypeTy, II))
6458 return ProduceConstructorSignatureHelp(MemberDecl->getType(),
6459 MemberDecl->getLocation(), ArgExprs,
6460 OpenParLoc, Braced);
6468 if (Index < Params.
size())
6471 Param = Params.
asArray().back();
6477 return llvm::isa<TemplateTypeParmDecl>(Param);
6479 return llvm::isa<NonTypeTemplateParmDecl>(Param);
6481 return llvm::isa<TemplateTemplateParmDecl>(Param);
6483 llvm_unreachable(
"Unhandled switch case");
6489 if (!CodeCompleter || !ParsedTemplate)
6495 bool Matches =
true;
6496 for (
unsigned I = 0; I < Args.size(); ++I) {
6503 Results.emplace_back(TD);
6511 if (
const auto *TD = llvm::dyn_cast<TemplateDecl>(ND))
6524 if (D.isArrayDesignator() || D.isArrayRangeDesignator()) {
6528 assert(D.isFieldDesignator());
6530 if (RD && RD->isCompleteDefinition()) {
6531 for (
const auto *
Member : RD->lookup(D.getFieldDecl()))
6533 NextType = FD->getType();
6538 BaseType = NextType;
6550 if (!RD || RD->fields().empty())
6555 ResultBuilder Results(*
this, CodeCompleter->getAllocator(),
6556 CodeCompleter->getCodeCompletionTUInfo(), CCC);
6558 Results.EnterNewScope();
6559 for (
const Decl *D : RD->decls()) {
6561 if (
auto *IFD = dyn_cast<IndirectFieldDecl>(D))
6562 FD = IFD->getAnonField();
6563 else if (
auto *DFD = dyn_cast<FieldDecl>(D))
6571 Results.AddResult(
Result, CurContext,
nullptr);
6573 Results.ExitScope();
6575 Results.data(), Results.size());
6579 ValueDecl *VD = dyn_cast_or_null<ValueDecl>(D);
6581 CodeCompleteOrdinaryName(S, PCC_Expression);
6588 Data.IgnoreDecls.push_back(VD);
6590 CodeCompleteExpression(S,
Data);
6594 ResultBuilder Results(*
this, CodeCompleter->getAllocator(),
6595 CodeCompleter->getCodeCompletionTUInfo(),
6597 Results.setFilter(&ResultBuilder::IsOrdinaryName);
6598 Results.EnterNewScope();
6600 CodeCompletionDeclConsumer Consumer(Results, CurContext);
6601 LookupVisibleDecls(S, LookupOrdinaryName, Consumer,
6602 CodeCompleter->includeGlobals(),
6603 CodeCompleter->loadExternal());
6609 Results.getCodeCompletionTUInfo());
6611 auto AddElseBodyPattern = [&] {
6616 Builder.AddPlaceholderChunk(
"statements");
6622 Builder.AddPlaceholderChunk(
"statement");
6626 Builder.AddTypedTextChunk(
"else");
6627 if (Results.includeCodePatterns())
6628 AddElseBodyPattern();
6629 Results.AddResult(Builder.TakeString());
6632 Builder.AddTypedTextChunk(
"else if");
6636 Builder.AddPlaceholderChunk(
"condition");
6638 Builder.AddPlaceholderChunk(
"expression");
6640 if (Results.includeCodePatterns()) {
6641 AddElseBodyPattern();
6643 Results.AddResult(Builder.TakeString());
6645 Results.ExitScope();
6647 if (S->getFnParent())
6650 if (CodeCompleter->includeMacros())
6654 Results.data(), Results.size());
6658 bool EnteringContext,
6659 bool IsUsingDeclaration,
QualType BaseType,
6661 if (SS.
isEmpty() || !CodeCompleter)
6676 ResultBuilder DummyResults(*
this, CodeCompleter->getAllocator(),
6677 CodeCompleter->getCodeCompletionTUInfo(), CC);
6678 if (!PreferredType.
isNull())
6679 DummyResults.setPreferredType(PreferredType);
6680 if (S->getEntity()) {
6681 CodeCompletionDeclConsumer Consumer(DummyResults, S->getEntity(),
6683 LookupVisibleDecls(S, LookupOrdinaryName, Consumer,
6688 DummyResults.getCompletionContext(),
nullptr, 0);
6699 if (Ctx ==
nullptr || RequireCompleteDeclContext(SS, Ctx))
6703 ResultBuilder Results(*
this, CodeCompleter->getAllocator(),
6704 CodeCompleter->getCodeCompletionTUInfo(), CC);
6705 if (!PreferredType.
isNull())
6706 Results.setPreferredType(PreferredType);
6707 Results.EnterNewScope();
6712 if (!Results.empty() && NNS && NNS->
isDependent())
6713 Results.AddResult(
"template");
6717 if (
const auto *TTPT =
6718 dyn_cast_or_null<TemplateTypeParmType>(NNS->
getAsType())) {
6719 for (
const auto &R : ConceptInfo(*TTPT, S).members()) {
6720 if (R.Operator != ConceptInfo::Member::Colons)
6723 R.render(*
this, CodeCompleter->getAllocator(),
6724 CodeCompleter->getCodeCompletionTUInfo())));
6733 if (Ctx && !EnteringContext)
6735 Results.ExitScope();
6738 (CodeCompleter->includeNamespaceLevelDecls() || !Ctx->
isFileContext())) {
6739 CodeCompletionDeclConsumer Consumer(Results, Ctx, BaseType);
6740 LookupVisibleDecls(Ctx, LookupOrdinaryName, Consumer,
6743 CodeCompleter->loadExternal());
6747 Results.data(), Results.size());
6757 Context.setIsUsingDeclaration(
true);
6759 ResultBuilder Results(*
this, CodeCompleter->getAllocator(),
6760 CodeCompleter->getCodeCompletionTUInfo(), Context,
6761 &ResultBuilder::IsNestedNameSpecifier);
6762 Results.EnterNewScope();
6765 if (!S->isClassScope())
6770 CodeCompletionDeclConsumer Consumer(Results, CurContext);
6771 LookupVisibleDecls(S, LookupOrdinaryName, Consumer,
6772 CodeCompleter->includeGlobals(),
6773 CodeCompleter->loadExternal());
6774 Results.ExitScope();
6777 Results.data(), Results.size());
6786 ResultBuilder Results(*
this, CodeCompleter->getAllocator(),
6787 CodeCompleter->getCodeCompletionTUInfo(),
6789 &ResultBuilder::IsNamespaceOrAlias);
6790 Results.EnterNewScope();
6791 CodeCompletionDeclConsumer Consumer(Results, CurContext);
6792 LookupVisibleDecls(S, LookupOrdinaryName, Consumer,
6793 CodeCompleter->includeGlobals(),
6794 CodeCompleter->loadExternal());
6795 Results.ExitScope();
6797 Results.data(), Results.size());
6805 if (!S->getParent())
6808 bool SuppressedGlobalResults =
6809 Ctx && !CodeCompleter->includeGlobals() && isa<TranslationUnitDecl>(Ctx);
6811 ResultBuilder Results(*
this, CodeCompleter->getAllocator(),
6812 CodeCompleter->getCodeCompletionTUInfo(),
6813 SuppressedGlobalResults
6816 &ResultBuilder::IsNamespace);
6818 if (Ctx && Ctx->
isFileContext() && !SuppressedGlobalResults) {
6823 std::map<NamespaceDecl *, NamespaceDecl *> OrigToLatest;
6828 OrigToLatest[NS->getOriginalNamespace()] = *NS;
6832 Results.EnterNewScope();
6833 for (std::map<NamespaceDecl *, NamespaceDecl *>::iterator
6834 NS = OrigToLatest.begin(),
6835 NSEnd = OrigToLatest.end();
6840 CurContext,
nullptr,
false);
6841 Results.ExitScope();
6845 Results.data(), Results.size());
6853 ResultBuilder Results(*
this, CodeCompleter->getAllocator(),
6854 CodeCompleter->getCodeCompletionTUInfo(),
6856 &ResultBuilder::IsNamespaceOrAlias);
6857 CodeCompletionDeclConsumer Consumer(Results, CurContext);
6858 LookupVisibleDecls(S, LookupOrdinaryName, Consumer,
6859 CodeCompleter->includeGlobals(),
6860 CodeCompleter->loadExternal());
6862 Results.data(), Results.size());
6870 ResultBuilder Results(*
this, CodeCompleter->getAllocator(),
6871 CodeCompleter->getCodeCompletionTUInfo(),
6873 &ResultBuilder::IsType);
6874 Results.EnterNewScope();
6878#define OVERLOADED_OPERATOR(Name, Spelling, Token, Unary, Binary, MemberOnly) \
6879 if (OO_##Name != OO_Conditional) \
6880 Results.AddResult(Result(Spelling));
6881#include "clang/Basic/OperatorKinds.def"
6884 Results.allowNestedNameSpecifiers();
6885 CodeCompletionDeclConsumer Consumer(Results, CurContext);
6886 LookupVisibleDecls(S, LookupOrdinaryName, Consumer,
6887 CodeCompleter->includeGlobals(),
6888 CodeCompleter->loadExternal());
6892 Results.ExitScope();
6895 Results.data(), Results.size());
6903 AdjustDeclIfTemplate(ConstructorD);
6905 auto *Constructor = dyn_cast<CXXConstructorDecl>(ConstructorD);
6909 ResultBuilder Results(*
this, CodeCompleter->getAllocator(),
6910 CodeCompleter->getCodeCompletionTUInfo(),
6912 Results.EnterNewScope();
6917 for (
unsigned I = 0, E = Initializers.size(); I != E; ++I) {
6918 if (Initializers[I]->isBaseInitializer())
6920 QualType(Initializers[I]->getBaseClass(), 0)));
6922 InitializedFields.insert(
6923 cast<FieldDecl>(Initializers[I]->getAnyMember()));
6928 bool SawLastInitializer = Initializers.empty();
6931 auto GenerateCCS = [&](
const NamedDecl *ND,
const char *Name) {
6933 Results.getCodeCompletionTUInfo());
6934 Builder.AddTypedTextChunk(Name);
6936 if (
const auto *
Function = dyn_cast<FunctionDecl>(ND))
6938 else if (
const auto *FunTemplDecl = dyn_cast<FunctionTemplateDecl>(ND))
6942 return Builder.TakeString();
6944 auto AddDefaultCtorInit = [&](
const char *Name,
const char *
Type,
6947 Results.getCodeCompletionTUInfo());
6948 Builder.AddTypedTextChunk(Name);
6950 Builder.AddPlaceholderChunk(
Type);
6954 Builder.TakeString(), ND,
6956 if (isa<FieldDecl>(ND))
6958 return Results.AddResult(CCR);
6961 Builder.TakeString(),
6965 const char *Name,
const FieldDecl *FD) {
6967 return AddDefaultCtorInit(Name,
6968 FD ? Results.getAllocator().CopyString(
6969 FD->getType().getAsString(Policy))
6973 if (Ctors.begin() == Ctors.end())
6974 return AddDefaultCtorInit(Name, Name, RD);
6978 Results.AddResult(CCR);
6982 const char *BaseName =
6983 Results.getAllocator().CopyString(
Base.getType().getAsString(Policy));
6984 const auto *RD =
Base.getType()->getAsCXXRecordDecl();
6989 auto AddField = [&](
const FieldDecl *FD) {
6990 const char *FieldName =
6991 Results.getAllocator().CopyString(FD->getIdentifier()->getName());
6992 const CXXRecordDecl *RD = FD->getType()->getAsCXXRecordDecl();
6998 for (
const auto &
Base : ClassDecl->
bases()) {
7001 SawLastInitializer =
7002 !Initializers.empty() && Initializers.back()->isBaseInitializer() &&
7004 Base.getType(),
QualType(Initializers.back()->getBaseClass(), 0));
7009 SawLastInitializer =
false;
7013 for (
const auto &
Base : ClassDecl->
vbases()) {
7016 SawLastInitializer =
7017 !Initializers.empty() && Initializers.back()->isBaseInitializer() &&
7019 Base.getType(),
QualType(Initializers.back()->getBaseClass(), 0));
7024 SawLastInitializer =
false;
7028 for (
auto *Field : ClassDecl->
fields()) {
7029 if (!InitializedFields.insert(cast<FieldDecl>(Field->getCanonicalDecl()))
7031 SawLastInitializer = !Initializers.empty() &&
7032 Initializers.back()->isAnyMemberInitializer() &&
7033 Initializers.back()->getAnyMember() == Field;
7037 if (!Field->getDeclName())
7041 SawLastInitializer =
false;
7043 Results.ExitScope();
7046 Results.data(), Results.size());
7059 bool AfterAmpersand) {
7060 ResultBuilder Results(*
this, CodeCompleter->getAllocator(),
7061 CodeCompleter->getCodeCompletionTUInfo(),
7063 Results.EnterNewScope();
7067 bool IncludedThis =
false;
7070 IncludedThis =
true;
7079 for (
const auto *D : S->decls()) {
7080 const auto *Var = dyn_cast<VarDecl>(D);
7081 if (!Var || !Var->hasLocalStorage() || Var->hasAttr<BlocksAttr>())
7084 if (Known.insert(Var->getIdentifier()).second)
7086 CurContext,
nullptr,
false);
7094 Results.ExitScope();
7097 Results.data(), Results.size());
7101 if (!LangOpts.CPlusPlus11)
7103 ResultBuilder Results(*
this, CodeCompleter->getAllocator(),
7104 CodeCompleter->getCodeCompletionTUInfo(),
7106 auto ShouldAddDefault = [&D,
this]() {
7118 auto Op =
Id.OperatorFunctionId.Operator;
7121 if (Op == OverloadedOperatorKind::OO_Equal)
7123 if (LangOpts.CPlusPlus20 &&
7124 (Op == OverloadedOperatorKind::OO_EqualEqual ||
7125 Op == OverloadedOperatorKind::OO_ExclaimEqual ||
7126 Op == OverloadedOperatorKind::OO_Less ||
7127 Op == OverloadedOperatorKind::OO_LessEqual ||
7128 Op == OverloadedOperatorKind::OO_Greater ||
7129 Op == OverloadedOperatorKind::OO_GreaterEqual ||
7130 Op == OverloadedOperatorKind::OO_Spaceship))
7136 Results.EnterNewScope();
7137 if (ShouldAddDefault())
7138 Results.AddResult(
"default");
7141 Results.AddResult(
"delete");
7142 Results.ExitScope();
7144 Results.data(), Results.size());
7149#define OBJC_AT_KEYWORD_NAME(NeedAt, Keyword) ((NeedAt) ? "@" Keyword : Keyword)
7152 ResultBuilder &Results,
bool NeedAt) {
7158 Results.getCodeCompletionTUInfo());
7159 if (LangOpts.ObjC) {
7163 Builder.AddPlaceholderChunk(
"property");
7164 Results.AddResult(
Result(Builder.TakeString()));
7169 Builder.AddPlaceholderChunk(
"property");
7170 Results.AddResult(
Result(Builder.TakeString()));
7175 ResultBuilder &Results,
bool NeedAt) {
7181 if (LangOpts.ObjC) {
7196 Results.getCodeCompletionTUInfo());
7201 Builder.AddPlaceholderChunk(
"name");
7202 Results.AddResult(
Result(Builder.TakeString()));
7204 if (Results.includeCodePatterns()) {
7210 Builder.AddPlaceholderChunk(
"class");
7211 Results.AddResult(
Result(Builder.TakeString()));
7216 Builder.AddPlaceholderChunk(
"protocol");
7217 Results.AddResult(
Result(Builder.TakeString()));
7222 Builder.AddPlaceholderChunk(
"class");
7223 Results.AddResult(
Result(Builder.TakeString()));
7227 Builder.AddTypedTextChunk(
7230 Builder.AddPlaceholderChunk(
"alias");
7232 Builder.AddPlaceholderChunk(
"class");
7233 Results.AddResult(
Result(Builder.TakeString()));
7235 if (Results.getSema().getLangOpts().Modules) {
7239 Builder.AddPlaceholderChunk(
"module");
7240 Results.AddResult(
Result(Builder.TakeString()));
7245 ResultBuilder Results(*
this, CodeCompleter->getAllocator(),
7246 CodeCompleter->getCodeCompletionTUInfo(),
7248 Results.EnterNewScope();
7249 if (isa<ObjCImplDecl>(CurContext))
7255 Results.ExitScope();
7257 Results.data(), Results.size());
7263 Results.getCodeCompletionTUInfo());
7266 const char *EncodeType =
"char[]";
7267 if (Results.getSema().getLangOpts().CPlusPlus ||
7268 Results.getSema().getLangOpts().ConstStrings)
7269 EncodeType =
"const char[]";
7270 Builder.AddResultTypeChunk(EncodeType);
7273 Builder.AddPlaceholderChunk(
"type-name");
7275 Results.AddResult(
Result(Builder.TakeString()));
7278 Builder.AddResultTypeChunk(
"Protocol *");
7281 Builder.AddPlaceholderChunk(
"protocol-name");
7283 Results.AddResult(
Result(Builder.TakeString()));
7286 Builder.AddResultTypeChunk(
"SEL");
7289 Builder.AddPlaceholderChunk(
"selector");
7291 Results.AddResult(
Result(Builder.TakeString()));
7294 Builder.AddResultTypeChunk(
"NSString *");
7296 Builder.AddPlaceholderChunk(
"string");
7297 Builder.AddTextChunk(
"\"");
7298 Results.AddResult(
Result(Builder.TakeString()));
7301 Builder.AddResultTypeChunk(
"NSArray *");
7303 Builder.AddPlaceholderChunk(
"objects, ...");
7305 Results.AddResult(
Result(Builder.TakeString()));
7308 Builder.AddResultTypeChunk(
"NSDictionary *");
7310 Builder.AddPlaceholderChunk(
"key");
7313 Builder.AddPlaceholderChunk(
"object, ...");
7315 Results.AddResult(
Result(Builder.TakeString()));
7318 Builder.AddResultTypeChunk(
"id");
7320 Builder.AddPlaceholderChunk(
"expression");
7322 Results.AddResult(
Result(Builder.TakeString()));
7328 Results.getCodeCompletionTUInfo());
7330 if (Results.includeCodePatterns()) {
7335 Builder.AddPlaceholderChunk(
"statements");
7337 Builder.AddTextChunk(
"@catch");
7339 Builder.AddPlaceholderChunk(
"parameter");
7342 Builder.AddPlaceholderChunk(
"statements");
7344 Builder.AddTextChunk(
"@finally");
7346 Builder.AddPlaceholderChunk(
"statements");
7348 Results.AddResult(
Result(Builder.TakeString()));
7354 Builder.AddPlaceholderChunk(
"expression");
7355 Results.AddResult(
Result(Builder.TakeString()));
7357 if (Results.includeCodePatterns()) {
7362 Builder.AddPlaceholderChunk(
"expression");
7365 Builder.AddPlaceholderChunk(
"statements");
7367 Results.AddResult(
Result(Builder.TakeString()));
7372 ResultBuilder &Results,
bool NeedAt) {
7382 ResultBuilder Results(*
this, CodeCompleter->getAllocator(),
7383 CodeCompleter->getCodeCompletionTUInfo(),
7385 Results.EnterNewScope();
7387 Results.ExitScope();
7389 Results.data(), Results.size());
7393 ResultBuilder Results(*
this, CodeCompleter->getAllocator(),
7394 CodeCompleter->getCodeCompletionTUInfo(),
7396 Results.EnterNewScope();
7399 Results.ExitScope();
7401 Results.data(), Results.size());
7405 ResultBuilder Results(*
this, CodeCompleter->getAllocator(),
7406 CodeCompleter->getCodeCompletionTUInfo(),
7408 Results.EnterNewScope();
7410 Results.ExitScope();
7412 Results.data(), Results.size());
7419 if (Attributes & NewFlag)
7422 Attributes |= NewFlag;
7430 unsigned AssignCopyRetMask =
7436 if (AssignCopyRetMask &&
7454 ResultBuilder Results(*
this, CodeCompleter->getAllocator(),
7455 CodeCompleter->getCodeCompletionTUInfo(),
7457 Results.EnterNewScope();
7494 Results.getCodeCompletionTUInfo());
7503 Results.getCodeCompletionTUInfo());
7516 Results.ExitScope();
7518 Results.data(), Results.size());
7531 bool AllowSameLength =
true) {
7532 unsigned NumSelIdents = SelIdents.size();
7545 if (!AllowSameLength && NumSelIdents && NumSelIdents == Sel.
getNumArgs())
7548 for (
unsigned I = 0; I != NumSelIdents; ++I)
7558 bool AllowSameLength =
true) {
7592 ResultBuilder &Results,
bool InOriginalClass =
true,
7593 bool IsRootClass =
false) {
7597 IsRootClass = IsRootClass || (IFace && !IFace->
getSuperClass());
7601 if (M->isInstanceMethod() == WantInstanceMethods ||
7602 (IsRootClass && !WantInstanceMethods)) {
7608 if (!Selectors.insert(M->getSelector()).second)
7611 Result R =
Result(M, Results.getBasePriority(M),
nullptr);
7612 R.StartParameter = SelIdents.size();
7613 R.AllParametersAreInformative = (WantKind !=
MK_Any);
7614 if (!InOriginalClass)
7616 Results.MaybeAddResult(R, CurContext);
7621 if (
const auto *Protocol = dyn_cast<ObjCProtocolDecl>(Container)) {
7622 if (Protocol->hasDefinition()) {
7624 Protocol->getReferencedProtocols();
7626 E = Protocols.
end();
7628 AddObjCMethods(*I, WantInstanceMethods, WantKind, SelIdents, CurContext,
7629 Selectors, AllowSameLength, Results,
false, IsRootClass);
7638 AddObjCMethods(I, WantInstanceMethods, WantKind, SelIdents, CurContext,
7639 Selectors, AllowSameLength, Results,
false, IsRootClass);
7643 AddObjCMethods(CatDecl, WantInstanceMethods, WantKind, SelIdents,
7644 CurContext, Selectors, AllowSameLength, Results,
7645 InOriginalClass, IsRootClass);
7649 CatDecl->getReferencedProtocols();
7651 E = Protocols.
end();
7653 AddObjCMethods(*I, WantInstanceMethods, WantKind, SelIdents, CurContext,
7654 Selectors, AllowSameLength, Results,
false, IsRootClass);
7658 AddObjCMethods(Impl, WantInstanceMethods, WantKind, SelIdents, CurContext,
7659 Selectors, AllowSameLength, Results, InOriginalClass,
7667 SelIdents, CurContext, Selectors, AllowSameLength, Results,
7672 AddObjCMethods(Impl, WantInstanceMethods, WantKind, SelIdents, CurContext,
7673 Selectors, AllowSameLength, Results, InOriginalClass,
7682 dyn_cast_or_null<ObjCCategoryDecl>(CurContext))
7690 ResultBuilder Results(*
this, CodeCompleter->getAllocator(),
7691 CodeCompleter->getCodeCompletionTUInfo(),
7693 Results.EnterNewScope();
7699 Results.ExitScope();
7701 Results.data(), Results.size());
7709 dyn_cast_or_null<ObjCCategoryDecl>(CurContext))
7717 ResultBuilder Results(*
this, CodeCompleter->getAllocator(),
7718 CodeCompleter->getCodeCompletionTUInfo(),
7720 Results.EnterNewScope();
7727 Results.ExitScope();
7729 Results.data(), Results.size());
7734 ResultBuilder Results(*
this, CodeCompleter->getAllocator(),
7735 CodeCompleter->getCodeCompletionTUInfo(),
7737 Results.EnterNewScope();
7740 bool AddedInOut =
false;
7743 Results.AddResult(
"in");
7744 Results.AddResult(
"inout");
7749 Results.AddResult(
"out");
7751 Results.AddResult(
"inout");
7756 Results.AddResult(
"bycopy");
7757 Results.AddResult(
"byref");
7758 Results.AddResult(
"oneway");
7761 Results.AddResult(
"nonnull");
7762 Results.AddResult(
"nullable");
7763 Results.AddResult(
"null_unspecified");
7771 PP.isMacroDefined(
"IBAction")) {
7773 Results.getCodeCompletionTUInfo(),
7775 Builder.AddTypedTextChunk(
"IBAction");
7777 Builder.AddPlaceholderChunk(
"selector");
7780 Builder.AddTextChunk(
"id");
7782 Builder.AddTextChunk(
"sender");
7793 Results.ExitScope();
7796 Results.setFilter(&ResultBuilder::IsOrdinaryNonValueName);
7797 CodeCompletionDeclConsumer Consumer(Results, CurContext);
7798 LookupVisibleDecls(S, LookupOrdinaryName, Consumer,
7799 CodeCompleter->includeGlobals(),
7800 CodeCompleter->loadExternal());
7802 if (CodeCompleter->includeMacros())
7806 Results.data(), Results.size());
7814 auto *Msg = dyn_cast_or_null<ObjCMessageExpr>(E);
7832 switch (Msg->getReceiverKind()) {
7836 IFace = ObjType->getInterface();
7840 QualType T = Msg->getInstanceReceiver()->getType();
7842 IFace = Ptr->getInterfaceDecl();
7856 return llvm::StringSwitch<ObjCInterfaceDecl *>(
Id->getName())
7857 .Case(
"retain", IFace)
7858 .Case(
"strong", IFace)
7859 .Case(
"autorelease", IFace)
7860 .Case(
"copy", IFace)
7861 .Case(
"copyWithZone", IFace)
7862 .Case(
"mutableCopy", IFace)
7863 .Case(
"mutableCopyWithZone", IFace)
7864 .Case(
"awakeFromCoder", IFace)
7865 .Case(
"replacementObjectFromCoder", IFace)
7866 .Case(
"class", IFace)
7867 .Case(
"classForCoder", IFace)
7868 .Case(
"superclass", Super)
7871 return llvm::StringSwitch<ObjCInterfaceDecl *>(
Id->getName())
7873 .Case(
"alloc", IFace)
7874 .Case(
"allocWithZone", IFace)
7875 .Case(
"class", IFace)
7876 .Case(
"superclass", Super)
7899 ResultBuilder &Results) {
7910 while ((
Class =
Class->getSuperClass()) && !SuperMethod) {
7917 for (
const auto *Cat :
Class->known_categories()) {
7918 if ((SuperMethod = Cat->getMethod(CurMethod->
getSelector(),
7936 CurP != CurPEnd; ++CurP, ++SuperP) {
7939 (*SuperP)->getType()))
7943 if (!(*CurP)->getIdentifier())
7949 Results.getCodeCompletionTUInfo());
7953 Results.getCompletionContext().getBaseType(), Builder);
7956 if (NeedSuperKeyword) {
7957 Builder.AddTypedTextChunk(
"super");
7963 if (NeedSuperKeyword)
7964 Builder.AddTextChunk(
7967 Builder.AddTypedTextChunk(
7971 for (
unsigned I = 0, N = Sel.
getNumArgs(); I != N; ++I, ++CurP) {
7972 if (I > SelIdents.size())
7975 if (I < SelIdents.size())
7976 Builder.AddInformativeChunk(
7978 else if (NeedSuperKeyword || I > SelIdents.size()) {
7979 Builder.AddTextChunk(
7981 Builder.AddPlaceholderChunk(Builder.getAllocator().CopyString(
7982 (*CurP)->getIdentifier()->getName()));
7984 Builder.AddTypedTextChunk(
7986 Builder.AddPlaceholderChunk(Builder.getAllocator().CopyString(
7987 (*CurP)->getIdentifier()->getName()));
7999 ResultBuilder Results(
8000 *
this, CodeCompleter->getAllocator(),
8001 CodeCompleter->getCodeCompletionTUInfo(),
8004 ? &ResultBuilder::IsObjCMessageReceiverOrLambdaCapture
8005 : &ResultBuilder::IsObjCMessageReceiver);
8007 CodeCompletionDeclConsumer Consumer(Results, CurContext);
8008 Results.EnterNewScope();
8009 LookupVisibleDecls(S, LookupOrdinaryName, Consumer,
8010 CodeCompleter->includeGlobals(),
8011 CodeCompleter->loadExternal());
8017 if (Iface->getSuperClass()) {
8018 Results.AddResult(
Result(
"super"));
8027 Results.ExitScope();
8029 if (CodeCompleter->includeMacros())
8032 Results.data(), Results.size());
8041 CDecl = CurMethod->getClassInterface();
8050 if (CurMethod->isInstanceMethod()) {
8054 return CodeCompleteObjCInstanceMessage(S,
nullptr, SelIdents,
8055 AtArgumentExpression, CDecl);
8063 NamedDecl *ND = LookupSingleName(S, Super, SuperLoc, LookupOrdinaryName);
8064 if ((CDecl = dyn_cast_or_null<ObjCInterfaceDecl>(ND))) {
8066 }
else if (
TypeDecl *TD = dyn_cast_or_null<TypeDecl>(ND)) {
8069 CDecl = Iface->getInterface();
8070 }
else if (ND && isa<UnresolvedUsingTypenameDecl>(ND)) {
8078 ExprResult SuperExpr = ActOnIdExpression(S, SS, TemplateKWLoc,
id,
8081 return CodeCompleteObjCInstanceMessage(S, (
Expr *)SuperExpr.
get(),
8082 SelIdents, AtArgumentExpression);
8091 return CodeCompleteObjCClassMessage(S, Receiver, SelIdents,
8092 AtArgumentExpression,
8099 unsigned NumSelIdents) {
8101 ASTContext &Context = Results.getSema().Context;
8105 Result *ResultsData = Results.data();
8106 for (
unsigned I = 0, N = Results.size(); I != N; ++I) {
8107 Result &R = ResultsData[I];
8108 if (R.Kind == Result::RK_Declaration &&
8109 isa<ObjCMethodDecl>(R.Declaration)) {
8110 if (R.Priority <= BestPriority) {
8111 const ObjCMethodDecl *Method = cast<ObjCMethodDecl>(R.Declaration);
8112 if (NumSelIdents <= Method->param_size()) {
8114 Method->
parameters()[NumSelIdents - 1]->getType();
8115 if (R.Priority < BestPriority || PreferredType.
isNull()) {
8116 BestPriority = R.Priority;
8117 PreferredType = MyPreferredType;
8127 return PreferredType;
8133 bool AtArgumentExpression,
bool IsSuper,
8134 ResultBuilder &Results) {
8149 Results.EnterNewScope();
8156 Results.Ignore(SuperMethod);
8162 Results.setPreferredSelector(CurMethod->getSelector());
8167 Selectors, AtArgumentExpression, Results);
8174 for (uint32_t I = 0,
8189 MethList && MethList->
getMethod(); MethList = MethList->getNext()) {
8193 Result R(MethList->getMethod(),
8194 Results.getBasePriority(MethList->getMethod()),
nullptr);
8195 R.StartParameter = SelIdents.size();
8196 R.AllParametersAreInformative =
false;
8197 Results.MaybeAddResult(R, SemaRef.
CurContext);
8202 Results.ExitScope();
8207 bool AtArgumentExpression,
bool IsSuper) {
8209 QualType T = this->GetTypeFromParser(Receiver);
8211 ResultBuilder Results(
8212 *
this, CodeCompleter->getAllocator(),
8213 CodeCompleter->getCodeCompletionTUInfo(),
8218 AtArgumentExpression, IsSuper, Results);
8225 if (AtArgumentExpression) {
8228 if (PreferredType.
isNull())
8229 CodeCompleteOrdinaryName(S, PCC_Expression);
8231 CodeCompleteExpression(S, PreferredType);
8236 Results.data(), Results.size());
8244 Expr *RecExpr =
static_cast<Expr *
>(Receiver);
8249 ExprResult Conv = DefaultFunctionArrayLvalueConversion(RecExpr);
8252 RecExpr = Conv.
get();
8266 return CodeCompleteObjCClassMessage(
8268 AtArgumentExpression, Super);
8273 }
else if (RecExpr && getLangOpts().
CPlusPlus) {
8274 ExprResult Conv = PerformContextuallyConvertToObjCPointer(RecExpr);
8276 RecExpr = Conv.
get();
8277 ReceiverType = RecExpr->
getType();
8282 ResultBuilder Results(
8283 *
this, CodeCompleter->getAllocator(),
8284 CodeCompleter->getCodeCompletionTUInfo(),
8286 ReceiverType, SelIdents));
8288 Results.EnterNewScope();
8295 Results.Ignore(SuperMethod);
8301 Results.setPreferredSelector(CurMethod->getSelector());
8314 Selectors, AtArgumentExpression, Results);
8321 for (
auto *I : QualID->quals())
8323 AtArgumentExpression, Results);
8330 CurContext, Selectors, AtArgumentExpression, Results);
8333 for (
auto *I : IFacePtr->quals())
8335 AtArgumentExpression, Results);
8348 if (Sel.
isNull() || MethodPool.count(Sel))
8351 ReadMethodPool(Sel);
8356 MEnd = MethodPool.end();
8359 MethList && MethList->
getMethod(); MethList = MethList->getNext()) {
8363 if (!Selectors.insert(MethList->getMethod()->getSelector()).second)
8366 Result R(MethList->getMethod(),
8367 Results.getBasePriority(MethList->getMethod()),
nullptr);
8368 R.StartParameter = SelIdents.size();
8369 R.AllParametersAreInformative =
false;
8370 Results.MaybeAddResult(R, CurContext);
8374 Results.ExitScope();
8381 if (AtArgumentExpression) {
8384 if (PreferredType.
isNull())
8385 CodeCompleteOrdinaryName(S, PCC_Expression);
8387 CodeCompleteExpression(S, PreferredType);
8392 Results.data(), Results.size());
8398 Data.ObjCCollection =
true;
8404 Data.IgnoreDecls.push_back(*I);
8408 CodeCompleteExpression(S,
Data);
8419 if (Sel.
isNull() || MethodPool.count(Sel))
8422 ReadMethodPool(Sel);
8426 ResultBuilder Results(*
this, CodeCompleter->getAllocator(),
8427 CodeCompleter->getCodeCompletionTUInfo(),
8429 Results.EnterNewScope();
8431 MEnd = MethodPool.end();
8439 Results.getCodeCompletionTUInfo());
8441 Builder.AddTypedTextChunk(
8443 Results.AddResult(Builder.TakeString());
8447 std::string Accumulator;
8448 for (
unsigned I = 0, N = Sel.
getNumArgs(); I != N; ++I) {
8449 if (I == SelIdents.size()) {
8450 if (!Accumulator.empty()) {
8451 Builder.AddInformativeChunk(
8452 Builder.getAllocator().CopyString(Accumulator));
8453 Accumulator.clear();
8460 Builder.AddTypedTextChunk(Builder.getAllocator().CopyString(Accumulator));
8461 Results.AddResult(Builder.TakeString());
8463 Results.ExitScope();
8466 Results.data(), Results.size());
8472 bool OnlyForwardDeclarations,
8473 ResultBuilder &Results) {
8476 for (
const auto *D : Ctx->
decls()) {
8478 if (
const auto *Proto = dyn_cast<ObjCProtocolDecl>(D))
8479 if (!OnlyForwardDeclarations || !Proto->hasDefinition())
8481 Result(Proto, Results.getBasePriority(Proto),
nullptr), CurContext,
8488 ResultBuilder Results(*
this, CodeCompleter->getAllocator(),
8489 CodeCompleter->getCodeCompletionTUInfo(),
8492 if (CodeCompleter->includeGlobals()) {
8493 Results.EnterNewScope();
8500 Results.Ignore(Protocol);
8506 Results.ExitScope();
8510 Results.data(), Results.size());
8514 ResultBuilder Results(*
this, CodeCompleter->getAllocator(),
8515 CodeCompleter->getCodeCompletionTUInfo(),
8518 if (CodeCompleter->includeGlobals()) {
8519 Results.EnterNewScope();
8525 Results.ExitScope();
8529 Results.data(), Results.size());
8535 bool OnlyForwardDeclarations,
8536 bool OnlyUnimplemented,
8537 ResultBuilder &Results) {
8540 for (
const auto *D : Ctx->
decls()) {
8542 if (
const auto *
Class = dyn_cast<ObjCInterfaceDecl>(D))
8543 if ((!OnlyForwardDeclarations || !
Class->hasDefinition()) &&
8544 (!OnlyUnimplemented || !
Class->getImplementation()))
8552 ResultBuilder Results(*
this, CodeCompleter->getAllocator(),
8553 CodeCompleter->getCodeCompletionTUInfo(),
8555 Results.EnterNewScope();
8557 if (CodeCompleter->includeGlobals()) {
8563 Results.ExitScope();
8566 Results.data(), Results.size());
8570 ResultBuilder Results(*
this, CodeCompleter->getAllocator(),
8571 CodeCompleter->getCodeCompletionTUInfo(),
8573 Results.EnterNewScope();
8575 if (CodeCompleter->includeGlobals()) {
8581 Results.ExitScope();
8584 Results.data(), Results.size());
8589 ResultBuilder Results(*
this, CodeCompleter->getAllocator(),
8590 CodeCompleter->getCodeCompletionTUInfo(),
8592 Results.EnterNewScope();
8596 LookupSingleName(TUScope, ClassName, ClassNameLoc, LookupOrdinaryName);
8597 if (CurClass && isa<ObjCInterfaceDecl>(CurClass))
8598 Results.Ignore(CurClass);
8600 if (CodeCompleter->includeGlobals()) {
8606 Results.ExitScope();
8609 Results.data(), Results.size());
8613 ResultBuilder Results(*
this, CodeCompleter->getAllocator(),
8614 CodeCompleter->getCodeCompletionTUInfo(),
8616 Results.EnterNewScope();
8618 if (CodeCompleter->includeGlobals()) {
8624 Results.ExitScope();
8627 Results.data(), Results.size());
8635 ResultBuilder Results(*
this, CodeCompleter->getAllocator(),
8636 CodeCompleter->getCodeCompletionTUInfo(),
8643 LookupSingleName(TUScope, ClassName, ClassNameLoc, LookupOrdinaryName);
8645 dyn_cast_or_null<ObjCInterfaceDecl>(CurClass)) {
8646 for (
const auto *Cat :
Class->visible_categories())
8647 CategoryNames.insert(Cat->getIdentifier());
8651 Results.EnterNewScope();
8653 for (
const auto *D : TU->
decls())
8654 if (
const auto *
Category = dyn_cast<ObjCCategoryDecl>(D))
8655 if (CategoryNames.insert(
Category->getIdentifier()).second)
8658 CurContext,
nullptr,
false);
8659 Results.ExitScope();
8662 Results.data(), Results.size());
8674 LookupSingleName(TUScope, ClassName, ClassNameLoc, LookupOrdinaryName);
8677 return CodeCompleteObjCInterfaceCategory(S, ClassName, ClassNameLoc);
8679 ResultBuilder Results(*
this, CodeCompleter->getAllocator(),
8680 CodeCompleter->getCodeCompletionTUInfo(),
8687 Results.EnterNewScope();
8688 bool IgnoreImplemented =
true;
8690 for (
const auto *Cat :
Class->visible_categories()) {
8691 if ((!IgnoreImplemented || !Cat->getImplementation()) &&
8692 CategoryNames.insert(Cat->getIdentifier()).second)
8693 Results.AddResult(
Result(Cat, Results.getBasePriority(Cat),
nullptr),
8694 CurContext,
nullptr,
false);
8698 IgnoreImplemented =
false;
8700 Results.ExitScope();
8703 Results.data(), Results.size());
8708 ResultBuilder Results(*
this, CodeCompleter->getAllocator(),
8709 CodeCompleter->getCodeCompletionTUInfo(), CCContext);
8713 dyn_cast_or_null<ObjCContainerDecl>(CurContext);
8714 if (!Container || (!isa<ObjCImplementationDecl>(Container) &&
8715 !isa<ObjCCategoryImplDecl>(Container)))
8720 for (
const auto *D : Container->decls())
8721 if (
const auto *PropertyImpl = dyn_cast<ObjCPropertyImplDecl>(D))
8722 Results.Ignore(PropertyImpl->getPropertyDecl());
8726 Results.EnterNewScope();
8728 dyn_cast<ObjCImplementationDecl>(Container))
8731 AddedProperties, Results);
8734 cast<ObjCCategoryImplDecl>(Container)->getCategoryDecl(),
8735 false,
false, CurContext,
8736 AddedProperties, Results);
8737 Results.ExitScope();
8740 Results.data(), Results.size());
8746 ResultBuilder Results(*
this, CodeCompleter->getAllocator(),
8747 CodeCompleter->getCodeCompletionTUInfo(),
8752 dyn_cast_or_null<ObjCContainerDecl>(CurContext);
8753 if (!Container || (!isa<ObjCImplementationDecl>(Container) &&
8754 !isa<ObjCCategoryImplDecl>(Container)))
8760 dyn_cast<ObjCImplementationDecl>(Container))
8761 Class = ClassImpl->getClassInterface();
8763 Class = cast<ObjCCategoryImplDecl>(Container)
8765 ->getClassInterface();
8773 Property->getType().getNonReferenceType().getUnqualifiedType();
8776 Results.setPreferredType(PropertyType);
8781 Results.EnterNewScope();
8782 bool SawSimilarlyNamedIvar =
false;
8783 std::string NameWithPrefix;
8784 NameWithPrefix +=
'_';
8785 NameWithPrefix += PropertyName->getName();
8786 std::string NameWithSuffix = PropertyName->getName().str();
8787 NameWithSuffix +=
'_';
8790 Ivar = Ivar->getNextIvar()) {
8791 Results.AddResult(
Result(Ivar, Results.getBasePriority(Ivar),
nullptr),
8792 CurContext,
nullptr,
false);
8796 if ((PropertyName == Ivar->getIdentifier() ||
8797 NameWithPrefix == Ivar->getName() ||
8798 NameWithSuffix == Ivar->getName())) {
8799 SawSimilarlyNamedIvar =
true;
8803 if (Results.size() &&
8804 Results.data()[Results.size() - 1].Kind ==
8806 Results.data()[Results.size() - 1].Declaration == Ivar)
8807 Results.data()[Results.size() - 1].Priority--;
8812 if (!SawSimilarlyNamedIvar) {
8822 Builder.AddResultTypeChunk(
8824 Builder.AddTypedTextChunk(Allocator.CopyString(NameWithPrefix));
8829 Results.ExitScope();
8832 Results.data(), Results.size());
8838 llvm::PointerIntPair<ObjCMethodDecl *, 1, bool>>
8847 std::optional<bool> WantInstanceMethods,
8850 bool InOriginalClass =
true) {
8853 if (!IFace->hasDefinition())
8856 IFace = IFace->getDefinition();
8860 IFace->getReferencedProtocols();
8862 E = Protocols.
end();
8865 KnownMethods, InOriginalClass);
8868 for (
auto *Cat : IFace->visible_categories()) {
8870 KnownMethods,
false);
8874 if (IFace->getSuperClass())
8876 WantInstanceMethods, ReturnType, KnownMethods,
8883 Category->getReferencedProtocols();
8885 E = Protocols.
end();
8888 KnownMethods, InOriginalClass);
8891 if (InOriginalClass &&
Category->getClassInterface())
8893 WantInstanceMethods, ReturnType, KnownMethods,
8899 if (!Protocol->hasDefinition())
8901 Protocol = Protocol->getDefinition();
8902 Container = Protocol;
8906 Protocol->getReferencedProtocols();
8908 E = Protocols.
end();
8911 KnownMethods,
false);
8917 for (
auto *M : Container->methods()) {
8918 if (!WantInstanceMethods || M->isInstanceMethod() == *WantInstanceMethods) {
8919 if (!ReturnType.
isNull() &&
8923 KnownMethods[M->getSelector()] =
8924 KnownMethodsMap::mapped_type(M, InOriginalClass);
8938 Builder.AddTextChunk(Builder.getAllocator().CopyString(Quals));
8939 Builder.AddTextChunk(
8950 if (
Class->getIdentifier() &&
Class->getIdentifier()->getName() == Name)
8959 bool IsInstanceMethod,
8962 ResultBuilder &Results) {
8964 if (!PropName || PropName->
getLength() == 0)
8982 const char *CopiedKey;
8985 : Allocator(Allocator), Key(Key), CopiedKey(
nullptr) {}
8987 operator const char *() {
8991 return CopiedKey = Allocator.CopyString(Key);
8993 } Key(Allocator, PropName->
getName());
8996 std::string UpperKey = std::string(PropName->
getName());
8997 if (!UpperKey.empty())
9000 bool ReturnTypeMatchesProperty =
9004 bool ReturnTypeMatchesVoid = ReturnType.
isNull() || ReturnType->
isVoidType();
9007 if (IsInstanceMethod &&
9009 ReturnTypeMatchesProperty && !
Property->getGetterMethodDecl()) {
9014 Builder.AddTypedTextChunk(Key);
9021 if (IsInstanceMethod &&
9022 ((!ReturnType.
isNull() &&
9025 Property->getType()->isBooleanType())))) {
9026 std::string SelectorName = (Twine(
"is") + UpperKey).str();
9030 if (ReturnType.
isNull()) {
9032 Builder.AddTextChunk(
"BOOL");
9036 Builder.AddTypedTextChunk(Allocator.CopyString(SelectorId->
getName()));
9043 if (IsInstanceMethod && ReturnTypeMatchesVoid &&
9044 !
Property->getSetterMethodDecl()) {
9045 std::string SelectorName = (Twine(
"set") + UpperKey).str();
9047 if (KnownSelectors.insert(Selectors.
getUnarySelector(SelectorId)).second) {
9048 if (ReturnType.
isNull()) {
9050 Builder.AddTextChunk(
"void");
9054 Builder.AddTypedTextChunk(
9055 Allocator.CopyString(SelectorId->
getName() +
":"));
9058 Builder.AddTextChunk(Key);
9069 if (
const auto *ObjCPointer =
9094 if (IsInstanceMethod &&
9096 std::string SelectorName = (Twine(
"countOf") + UpperKey).str();
9100 if (ReturnType.
isNull()) {
9102 Builder.AddTextChunk(
"NSUInteger");
9106 Builder.AddTypedTextChunk(Allocator.CopyString(SelectorId->
getName()));
9108 Result(Builder.TakeString(),
9109 std::min(IndexedGetterPriority, UnorderedGetterPriority),
9116 if (IsInstanceMethod &&
9118 std::string SelectorName = (Twine(
"objectIn") + UpperKey +
"AtIndex").str();
9120 if (KnownSelectors.insert(Selectors.
getUnarySelector(SelectorId)).second) {
9121 if (ReturnType.
isNull()) {
9123 Builder.AddTextChunk(
"id");
9127 Builder.AddTypedTextChunk(Allocator.CopyString(SelectorName +
":"));
9129 Builder.AddTextChunk(
"NSUInteger");
9131 Builder.AddTextChunk(
"index");
9132 Results.AddResult(
Result(Builder.TakeString(), IndexedGetterPriority,
9138 if (IsInstanceMethod &&
9145 std::string SelectorName = (Twine(
Property->getName()) +
"AtIndexes").str();
9147 if (KnownSelectors.insert(Selectors.
getUnarySelector(SelectorId)).second) {
9148 if (ReturnType.
isNull()) {
9150 Builder.AddTextChunk(
"NSArray *");
9154 Builder.AddTypedTextChunk(Allocator.CopyString(SelectorName +
":"));
9156 Builder.AddTextChunk(
"NSIndexSet *");
9158 Builder.AddTextChunk(
"indexes");
9159 Results.AddResult(
Result(Builder.TakeString(), IndexedGetterPriority,
9165 if (IsInstanceMethod && ReturnTypeMatchesVoid) {
9166 std::string SelectorName = (Twine(
"get") + UpperKey).str();
9170 if (KnownSelectors.insert(Selectors.
getSelector(2, SelectorIds)).second) {
9171 if (ReturnType.
isNull()) {
9173 Builder.AddTextChunk(
"void");
9177 Builder.AddTypedTextChunk(Allocator.CopyString(SelectorName +
":"));
9179 Builder.AddPlaceholderChunk(
"object-type");
9180 Builder.AddTextChunk(
" **");
9182 Builder.AddTextChunk(
"buffer");
9184 Builder.AddTypedTextChunk(
"range:");
9186 Builder.AddTextChunk(
"NSRange");
9188 Builder.AddTextChunk(
"inRange");
9189 Results.AddResult(
Result(Builder.TakeString(), IndexedGetterPriority,
9197 if (IsInstanceMethod && ReturnTypeMatchesVoid) {
9198 std::string SelectorName = (Twine(
"in") + UpperKey +
"AtIndex").str();
9202 if (KnownSelectors.insert(Selectors.
getSelector(2, SelectorIds)).second) {
9203 if (ReturnType.
isNull()) {
9205 Builder.AddTextChunk(
"void");
9209 Builder.AddTypedTextChunk(
"insertObject:");
9211 Builder.AddPlaceholderChunk(
"object-type");
9212 Builder.AddTextChunk(
" *");
9214 Builder.AddTextChunk(
"object");
9216 Builder.AddTypedTextChunk(Allocator.CopyString(SelectorName +
":"));
9218 Builder.AddPlaceholderChunk(
"NSUInteger");
9220 Builder.AddTextChunk(
"index");
9221 Results.AddResult(
Result(Builder.TakeString(), IndexedSetterPriority,
9227 if (IsInstanceMethod && ReturnTypeMatchesVoid) {
9228 std::string SelectorName = (Twine(
"insert") + UpperKey).str();
9232 if (KnownSelectors.insert(Selectors.
getSelector(2, SelectorIds)).second) {
9233 if (ReturnType.
isNull()) {
9235 Builder.AddTextChunk(
"void");
9239 Builder.AddTypedTextChunk(Allocator.CopyString(SelectorName +
":"));
9241 Builder.AddTextChunk(
"NSArray *");
9243 Builder.AddTextChunk(
"array");
9245 Builder.AddTypedTextChunk(
"atIndexes:");
9247 Builder.AddPlaceholderChunk(
"NSIndexSet *");
9249 Builder.AddTextChunk(
"indexes");
9250 Results.AddResult(
Result(Builder.TakeString(), IndexedSetterPriority,
9256 if (IsInstanceMethod && ReturnTypeMatchesVoid) {
9257 std::string SelectorName =
9258 (Twine(
"removeObjectFrom") + UpperKey +
"AtIndex").str();
9260 if (KnownSelectors.insert(Selectors.
getUnarySelector(SelectorId)).second) {
9261 if (ReturnType.
isNull()) {
9263 Builder.AddTextChunk(
"void");
9267 Builder.AddTypedTextChunk(Allocator.CopyString(SelectorName +
":"));
9269 Builder.AddTextChunk(
"NSUInteger");
9271 Builder.AddTextChunk(
"index");
9272 Results.AddResult(
Result(Builder.TakeString(), IndexedSetterPriority,
9278 if (IsInstanceMethod && ReturnTypeMatchesVoid) {
9279 std::string SelectorName = (Twine(
"remove") + UpperKey +
"AtIndexes").str();
9281 if (KnownSelectors.insert(Selectors.
getUnarySelector(SelectorId)).second) {
9282 if (ReturnType.
isNull()) {
9284 Builder.AddTextChunk(
"void");
9288 Builder.AddTypedTextChunk(Allocator.CopyString(SelectorName +
":"));
9290 Builder.AddTextChunk(
"NSIndexSet *");
9292 Builder.AddTextChunk(
"indexes");
9293 Results.AddResult(
Result(Builder.TakeString(), IndexedSetterPriority,
9299 if (IsInstanceMethod && ReturnTypeMatchesVoid) {
9300 std::string SelectorName =
9301 (Twine(
"replaceObjectIn") + UpperKey +
"AtIndex").str();
9305 if (KnownSelectors.insert(Selectors.
getSelector(2, SelectorIds)).second) {
9306 if (ReturnType.
isNull()) {
9308 Builder.AddTextChunk(
"void");
9312 Builder.AddTypedTextChunk(Allocator.CopyString(SelectorName +
":"));
9314 Builder.AddPlaceholderChunk(
"NSUInteger");
9316 Builder.AddTextChunk(
"index");
9318 Builder.AddTypedTextChunk(
"withObject:");
9320 Builder.AddTextChunk(
"id");
9322 Builder.AddTextChunk(
"object");
9323 Results.AddResult(
Result(Builder.TakeString(), IndexedSetterPriority,
9329 if (IsInstanceMethod && ReturnTypeMatchesVoid) {
9330 std::string SelectorName1 =
9331 (Twine(
"replace") + UpperKey +
"AtIndexes").str();
9332 std::string SelectorName2 = (Twine(
"with") + UpperKey).str();
9336 if (KnownSelectors.insert(Selectors.
getSelector(2, SelectorIds)).second) {
9337 if (ReturnType.
isNull()) {
9339 Builder.AddTextChunk(
"void");
9343 Builder.AddTypedTextChunk(Allocator.CopyString(SelectorName1 +
":"));
9345 Builder.AddPlaceholderChunk(
"NSIndexSet *");
9347 Builder.AddTextChunk(
"indexes");
9349 Builder.AddTypedTextChunk(Allocator.CopyString(SelectorName2 +
":"));
9351 Builder.AddTextChunk(
"NSArray *");
9353 Builder.AddTextChunk(
"array");
9354 Results.AddResult(
Result(Builder.TakeString(), IndexedSetterPriority,
9361 if (IsInstanceMethod &&
9367 ->
getName() ==
"NSEnumerator"))) {
9368 std::string SelectorName = (Twine(
"enumeratorOf") + UpperKey).str();
9372 if (ReturnType.
isNull()) {
9374 Builder.AddTextChunk(
"NSEnumerator *");
9378 Builder.AddTypedTextChunk(Allocator.CopyString(SelectorName));
9379 Results.AddResult(
Result(Builder.TakeString(), UnorderedGetterPriority,
9385 if (IsInstanceMethod &&
9387 std::string SelectorName = (Twine(
"memberOf") + UpperKey).str();
9389 if (KnownSelectors.insert(Selectors.
getUnarySelector(SelectorId)).second) {
9390 if (ReturnType.
isNull()) {
9392 Builder.AddPlaceholderChunk(
"object-type");
9393 Builder.AddTextChunk(
" *");
9397 Builder.AddTypedTextChunk(Allocator.CopyString(SelectorName +
":"));
9399 if (ReturnType.
isNull()) {
9400 Builder.AddPlaceholderChunk(
"object-type");
9401 Builder.AddTextChunk(
" *");
9404 ReturnType, Context, Policy, Builder.getAllocator()));
9407 Builder.AddTextChunk(
"object");
9408 Results.AddResult(
Result(Builder.TakeString(), UnorderedGetterPriority,
9415 if (IsInstanceMethod && ReturnTypeMatchesVoid) {
9416 std::string SelectorName =
9417 (Twine(
"add") + UpperKey + Twine(
"Object")).str();
9419 if (KnownSelectors.insert(Selectors.
getUnarySelector(SelectorId)).second) {
9420 if (ReturnType.
isNull()) {
9422 Builder.AddTextChunk(
"void");
9426 Builder.AddTypedTextChunk(Allocator.CopyString(SelectorName +
":"));
9428 Builder.AddPlaceholderChunk(
"object-type");
9429 Builder.AddTextChunk(
" *");
9431 Builder.AddTextChunk(
"object");
9432 Results.AddResult(
Result(Builder.TakeString(), UnorderedSetterPriority,
9438 if (IsInstanceMethod && ReturnTypeMatchesVoid) {
9439 std::string SelectorName = (Twine(
"add") + UpperKey).str();
9441 if (KnownSelectors.insert(Selectors.
getUnarySelector(SelectorId)).second) {
9442 if (ReturnType.
isNull()) {
9444 Builder.AddTextChunk(
"void");
9448 Builder.AddTypedTextChunk(Allocator.CopyString(SelectorName +
":"));
9450 Builder.AddTextChunk(
"NSSet *");
9452 Builder.AddTextChunk(
"objects");
9453 Results.AddResult(
Result(Builder.TakeString(), UnorderedSetterPriority,
9459 if (IsInstanceMethod && ReturnTypeMatchesVoid) {
9460 std::string SelectorName =
9461 (Twine(
"remove") + UpperKey + Twine(
"Object")).str();
9463 if (KnownSelectors.insert(Selectors.
getUnarySelector(SelectorId)).second) {
9464 if (ReturnType.
isNull()) {
9466 Builder.AddTextChunk(
"void");
9470 Builder.AddTypedTextChunk(Allocator.CopyString(SelectorName +
":"));
9472 Builder.AddPlaceholderChunk(
"object-type");
9473 Builder.AddTextChunk(
" *");
9475 Builder.AddTextChunk(
"object");
9476 Results.AddResult(
Result(Builder.TakeString(), UnorderedSetterPriority,
9482 if (IsInstanceMethod && ReturnTypeMatchesVoid) {
9483 std::string SelectorName = (Twine(
"remove") + UpperKey).str();
9485 if (KnownSelectors.insert(Selectors.
getUnarySelector(SelectorId)).second) {
9486 if (ReturnType.
isNull()) {
9488 Builder.AddTextChunk(
"void");
9492 Builder.AddTypedTextChunk(Allocator.CopyString(SelectorName +
":"));
9494 Builder.AddTextChunk(
"NSSet *");
9496 Builder.AddTextChunk(
"objects");
9497 Results.AddResult(
Result(Builder.TakeString(), UnorderedSetterPriority,
9503 if (IsInstanceMethod && ReturnTypeMatchesVoid) {
9504 std::string SelectorName = (Twine(
"intersect") + UpperKey).str();
9506 if (KnownSelectors.insert(Selectors.
getUnarySelector(SelectorId)).second) {
9507 if (ReturnType.
isNull()) {
9509 Builder.AddTextChunk(
"void");
9513 Builder.AddTypedTextChunk(Allocator.CopyString(SelectorName +
":"));
9515 Builder.AddTextChunk(
"NSSet *");
9517 Builder.AddTextChunk(
"objects");
9518 Results.AddResult(
Result(Builder.TakeString(), UnorderedSetterPriority,
9525 if (!IsInstanceMethod &&
9532 std::string SelectorName =
9533 (Twine(
"keyPathsForValuesAffecting") + UpperKey).str();
9537 if (ReturnType.
isNull()) {
9539 Builder.AddTextChunk(
"NSSet<NSString *> *");
9543 Builder.AddTypedTextChunk(Allocator.CopyString(SelectorName));
9550 if (!IsInstanceMethod &&
9553 std::string SelectorName =
9554 (Twine(
"automaticallyNotifiesObserversOf") + UpperKey).str();
9558 if (ReturnType.
isNull()) {
9560 Builder.AddTextChunk(
"BOOL");
9564 Builder.AddTypedTextChunk(Allocator.CopyString(SelectorName));
9572 std::optional<bool> IsInstanceMethod,
9576 QualType ReturnType = GetTypeFromParser(ReturnTy);
9577 Decl *IDecl =
nullptr;
9584 bool IsInImplementation =
false;
9585 if (
Decl *D = IDecl) {
9587 SearchDecl = Impl->getClassInterface();
9588 IsInImplementation =
true;
9590 dyn_cast<ObjCCategoryImplDecl>(D)) {
9591 SearchDecl = CatImpl->getCategoryDecl();
9592 IsInImplementation =
true;
9594 SearchDecl = dyn_cast<ObjCContainerDecl>(D);
9597 if (!SearchDecl && S) {
9599 SearchDecl = dyn_cast<ObjCContainerDecl>(DC);
9615 ResultBuilder Results(*
this, CodeCompleter->getAllocator(),
9616 CodeCompleter->getCodeCompletionTUInfo(),
9618 Results.EnterNewScope();
9620 for (KnownMethodsMap::iterator M = KnownMethods.begin(),
9621 MEnd = KnownMethods.end();
9625 Results.getCodeCompletionTUInfo());
9628 if (!IsInstanceMethod) {
9635 if (ReturnType.
isNull()) {
9646 Builder.AddTypedTextChunk(
9653 P != PEnd; (
void)++
P, ++I) {
9656 Builder.AddTypedTextChunk(
9660 Builder.AddTypedTextChunk(
9668 ParamType = (*P)->getType();
9670 ParamType = (*P)->getOriginalType();
9675 Context, Policy, Builder);
9678 Builder.AddTextChunk(
9679 Builder.getAllocator().CopyString(
Id->getName()));
9686 Builder.AddTextChunk(
"...");
9689 if (IsInImplementation && Results.includeCodePatterns()) {
9696 Builder.AddTextChunk(
"return");
9698 Builder.AddPlaceholderChunk(
"expression");
9701 Builder.AddPlaceholderChunk(
"statements");
9709 if (!M->second.getInt())
9711 Results.AddResult(std::move(R));
9718 Containers.push_back(SearchDecl);
9721 for (KnownMethodsMap::iterator M = KnownMethods.begin(),
9722 MEnd = KnownMethods.end();
9724 KnownSelectors.insert(M->first);
9729 IFace =
Category->getClassInterface();
9734 if (IsInstanceMethod) {
9735 for (
unsigned I = 0, N = Containers.size(); I != N; ++I)
9736 for (
auto *
P : Containers[I]->instance_properties())
9738 KnownSelectors, Results);
9742 Results.ExitScope();
9745 Results.data(), Results.size());
9749 Scope *S,
bool IsInstanceMethod,
bool AtParameterName,
ParsedType ReturnTy,
9757 if (Sel.
isNull() || MethodPool.count(Sel))
9760 ReadMethodPool(Sel);
9766 ResultBuilder Results(*
this, CodeCompleter->getAllocator(),
9767 CodeCompleter->getCodeCompletionTUInfo(),
9771 Results.setPreferredType(GetTypeFromParser(ReturnTy).getNonReferenceType());
9773 Results.EnterNewScope();
9775 MEnd = MethodPool.end();
9777 for (
ObjCMethodList *MethList = IsInstanceMethod ? &M->second.first
9778 : &M->second.second;
9779 MethList && MethList->getMethod(); MethList = MethList->getNext()) {
9783 if (AtParameterName) {
9785 unsigned NumSelIdents = SelIdents.size();
9787 NumSelIdents <= MethList->getMethod()->param_size()) {
9789 MethList->getMethod()->parameters()[NumSelIdents - 1];
9792 Results.getCodeCompletionTUInfo());
9793 Builder.AddTypedTextChunk(Builder.getAllocator().CopyString(
9795 Results.AddResult(Builder.TakeString());
9802 Result R(MethList->getMethod(),
9803 Results.getBasePriority(MethList->getMethod()),
nullptr);
9804 R.StartParameter = SelIdents.size();
9805 R.AllParametersAreInformative =
false;
9806 R.DeclaringEntity =
true;
9807 Results.MaybeAddResult(R, CurContext);
9811 Results.ExitScope();
9813 if (!AtParameterName && !SelIdents.empty() &&
9814 SelIdents.front()->getName().starts_with(
"init")) {
9815 for (
const auto &M : PP.macros()) {
9816 if (M.first->getName() !=
"NS_DESIGNATED_INITIALIZER")
9818 Results.EnterNewScope();
9820 Results.getCodeCompletionTUInfo());
9821 Builder.AddTypedTextChunk(
9822 Builder.getAllocator().CopyString(M.first->getName()));
9825 Results.ExitScope();
9830 Results.data(), Results.size());
9834 ResultBuilder Results(*
this, CodeCompleter->getAllocator(),
9835 CodeCompleter->getCodeCompletionTUInfo(),
9837 Results.EnterNewScope();
9841 Results.getCodeCompletionTUInfo());
9842 Builder.AddTypedTextChunk(
"if");
9844 Builder.AddPlaceholderChunk(
"condition");
9845 Results.AddResult(Builder.TakeString());
9848 Builder.AddTypedTextChunk(
"ifdef");
9850 Builder.AddPlaceholderChunk(
"macro");
9851 Results.AddResult(Builder.TakeString());
9854 Builder.AddTypedTextChunk(
"ifndef");
9856 Builder.AddPlaceholderChunk(
"macro");
9857 Results.AddResult(Builder.TakeString());
9859 if (InConditional) {
9861 Builder.AddTypedTextChunk(
"elif");
9863 Builder.AddPlaceholderChunk(
"condition");
9864 Results.AddResult(Builder.TakeString());
9867 Builder.AddTypedTextChunk(
"elifdef");
9869 Builder.AddPlaceholderChunk(
"macro");
9870 Results.AddResult(Builder.TakeString());
9873 Builder.AddTypedTextChunk(
"elifndef");
9875 Builder.AddPlaceholderChunk(
"macro");
9876 Results.AddResult(Builder.TakeString());
9879 Builder.AddTypedTextChunk(
"else");
9880 Results.AddResult(Builder.TakeString());
9883 Builder.AddTypedTextChunk(
"endif");
9884 Results.AddResult(Builder.TakeString());
9888 Builder.AddTypedTextChunk(
"include");
9890 Builder.AddTextChunk(
"\"");
9891 Builder.AddPlaceholderChunk(
"header");
9892 Builder.AddTextChunk(
"\"");
9893 Results.AddResult(Builder.TakeString());
9896 Builder.AddTypedTextChunk(
"include");
9898 Builder.AddTextChunk(
"<");
9899 Builder.AddPlaceholderChunk(
"header");
9900 Builder.AddTextChunk(
">");
9901 Results.AddResult(Builder.TakeString());
9904 Builder.AddTypedTextChunk(
"define");
9906 Builder.AddPlaceholderChunk(
"macro");
9907 Results.AddResult(Builder.TakeString());
9910 Builder.AddTypedTextChunk(
"define");
9912 Builder.AddPlaceholderChunk(
"macro");
9914 Builder.AddPlaceholderChunk(
"args");
9916 Results.AddResult(Builder.TakeString());
9919 Builder.AddTypedTextChunk(
"undef");
9921 Builder.AddPlaceholderChunk(
"macro");
9922 Results.AddResult(Builder.TakeString());
9925 Builder.AddTypedTextChunk(
"line");
9927 Builder.AddPlaceholderChunk(
"number");
9928 Results.AddResult(Builder.TakeString());
9931 Builder.AddTypedTextChunk(
"line");
9933 Builder.AddPlaceholderChunk(
"number");
9935 Builder.AddTextChunk(
"\"");
9936 Builder.AddPlaceholderChunk(
"filename");
9937 Builder.AddTextChunk(
"\"");
9938 Results.AddResult(Builder.TakeString());
9941 Builder.AddTypedTextChunk(
"error");
9943 Builder.AddPlaceholderChunk(
"message");
9944 Results.AddResult(Builder.TakeString());
9947 Builder.AddTypedTextChunk(
"pragma");
9949 Builder.AddPlaceholderChunk(
"arguments");
9950 Results.AddResult(Builder.TakeString());
9952 if (getLangOpts().
ObjC) {
9954 Builder.AddTypedTextChunk(
"import");
9956 Builder.AddTextChunk(
"\"");
9957 Builder.AddPlaceholderChunk(
"header");
9958 Builder.AddTextChunk(
"\"");
9959 Results.AddResult(Builder.TakeString());
9962 Builder.AddTypedTextChunk(
"import");
9964 Builder.AddTextChunk(
"<");
9965 Builder.AddPlaceholderChunk(
"header");
9966 Builder.AddTextChunk(
">");
9967 Results.AddResult(Builder.TakeString());
9971 Builder.AddTypedTextChunk(
"include_next");
9973 Builder.AddTextChunk(
"\"");
9974 Builder.AddPlaceholderChunk(
"header");
9975 Builder.AddTextChunk(
"\"");
9976 Results.AddResult(Builder.TakeString());
9979 Builder.AddTypedTextChunk(
"include_next");
9981 Builder.AddTextChunk(
"<");
9982 Builder.AddPlaceholderChunk(
"header");
9983 Builder.AddTextChunk(
">");
9984 Results.AddResult(Builder.TakeString());
9987 Builder.AddTypedTextChunk(
"warning");
9989 Builder.AddPlaceholderChunk(
"message");
9990 Results.AddResult(Builder.TakeString());
9997 Results.ExitScope();
10000 Results.data(), Results.size());
10009 ResultBuilder Results(*
this, CodeCompleter->getAllocator(),
10010 CodeCompleter->getCodeCompletionTUInfo(),
10013 if (!IsDefinition && CodeCompleter->includeMacros()) {
10016 Results.getCodeCompletionTUInfo());
10017 Results.EnterNewScope();
10019 MEnd = PP.macro_end();
10021 Builder.AddTypedTextChunk(
10022 Builder.getAllocator().CopyString(M->first->getName()));
10026 Results.ExitScope();
10027 }
else if (IsDefinition) {
10032 Results.data(), Results.size());
10036 ResultBuilder Results(*
this, CodeCompleter->getAllocator(),
10037 CodeCompleter->getCodeCompletionTUInfo(),
10040 if (CodeCompleter->includeMacros())
10044 Results.EnterNewScope();
10046 Results.getCodeCompletionTUInfo());
10047 Builder.AddTypedTextChunk(
"defined");
10050 Builder.AddPlaceholderChunk(
"macro");
10052 Results.AddResult(Builder.TakeString());
10053 Results.ExitScope();
10056 Results.data(), Results.size());
10062 unsigned Argument) {
10076 std::string RelDir = llvm::sys::path::convert_to_slash(Dir);
10079 llvm::sys::path::native(NativeRelDir);
10080 llvm::vfs::FileSystem &FS =
10081 getSourceManager().getFileManager().getVirtualFileSystem();
10083 ResultBuilder Results(*
this, CodeCompleter->getAllocator(),
10084 CodeCompleter->getCodeCompletionTUInfo(),
10089 auto AddCompletion = [&](StringRef
Filename,
bool IsDirectory) {
10092 TypedChunk.push_back(IsDirectory ?
'/' : Angled ?
'>' :
'"');
10093 auto R = SeenResults.insert(TypedChunk);
10095 const char *InternedTyped = Results.getAllocator().CopyString(TypedChunk);
10096 *R.first = InternedTyped;
10098 CodeCompleter->getCodeCompletionTUInfo());
10099 Builder.AddTypedTextChunk(InternedTyped);
10107 auto AddFilesFromIncludeDir = [&](StringRef IncludeDir,
10111 if (!NativeRelDir.empty()) {
10115 auto Begin = llvm::sys::path::begin(NativeRelDir);
10116 auto End = llvm::sys::path::end(NativeRelDir);
10118 llvm::sys::path::append(Dir, *
Begin +
".framework",
"Headers");
10119 llvm::sys::path::append(Dir, ++
Begin, End);
10121 llvm::sys::path::append(Dir, NativeRelDir);
10125 const StringRef &Dirname = llvm::sys::path::filename(Dir);
10126 const bool isQt = Dirname.starts_with(
"Qt") || Dirname ==
"ActiveQt";
10127 const bool ExtensionlessHeaders =
10128 IsSystem || isQt || Dir.ends_with(
".framework/Headers");
10129 std::error_code EC;
10130 unsigned Count = 0;
10131 for (
auto It = FS.dir_begin(Dir, EC);
10132 !EC && It != llvm::vfs::directory_iterator(); It.increment(EC)) {
10133 if (++Count == 2500)
10135 StringRef
Filename = llvm::sys::path::filename(It->path());
10140 llvm::sys::fs::file_type
Type = It->type();
10141 if (
Type == llvm::sys::fs::file_type::symlink_file) {
10142 if (
auto FileStatus = FS.status(It->path()))
10143 Type = FileStatus->getType();
10146 case llvm::sys::fs::file_type::directory_file:
10150 NativeRelDir.empty() && !
Filename.consume_back(
".framework"))
10155 case llvm::sys::fs::file_type::regular_file: {
10157 const bool IsHeader =
Filename.ends_with_insensitive(
".h") ||
10158 Filename.ends_with_insensitive(
".hh") ||
10159 Filename.ends_with_insensitive(
".hpp") ||
10160 Filename.ends_with_insensitive(
".hxx") ||
10161 Filename.ends_with_insensitive(
".inc") ||
10162 (ExtensionlessHeaders && !
Filename.contains(
'.'));
10177 switch (IncludeDir.getLookupType()) {
10182 AddFilesFromIncludeDir(IncludeDir.getDirRef()->getName(), IsSystem,
10186 AddFilesFromIncludeDir(IncludeDir.getFrameworkDirRef()->getName(),
10195 const auto &S = PP.getHeaderSearchInfo();
10196 using llvm::make_range;
10199 if (
auto CurFile = PP.getCurrentFileLexer()->getFileEntry())
10200 AddFilesFromIncludeDir(CurFile->getDir().getName(),
false,
10202 for (
const auto &D : make_range(S.quoted_dir_begin(), S.quoted_dir_end()))
10203 AddFilesFromDirLookup(D,
false);
10205 for (
const auto &D : make_range(S.angled_dir_begin(), S.angled_dir_end()))
10206 AddFilesFromDirLookup(D,
false);
10207 for (
const auto &D : make_range(S.system_dir_begin(), S.system_dir_end()))
10208 AddFilesFromDirLookup(D,
true);
10211 Results.data(), Results.size());
10221 ResultBuilder Results(*
this, CodeCompleter->getAllocator(),
10222 CodeCompleter->getCodeCompletionTUInfo(),
10224 Results.EnterNewScope();
10225 static const char *Platforms[] = {
"macOS",
"iOS",
"watchOS",
"tvOS"};
10229 Twine(Platform) +
"ApplicationExtension")));
10231 Results.ExitScope();
10233 Results.data(), Results.size());
10239 ResultBuilder Builder(*
this, Allocator, CCTUInfo,
10241 if (!CodeCompleter || CodeCompleter->includeGlobals()) {
10242 CodeCompletionDeclConsumer Consumer(Builder,
10246 !CodeCompleter || CodeCompleter->loadExternal());
10249 if (!CodeCompleter || CodeCompleter->includeMacros())
10251 !CodeCompleter || CodeCompleter->loadExternal(),
true);
10254 Results.insert(Results.end(), Builder.data(),
10255 Builder.data() + Builder.size());
This file provides AST data structures related to concepts.
llvm::DenseMap< const Stmt *, CFGBlock * > SMap
static Decl::Kind getKind(const Decl *D)
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate....
Defines the C++ template declaration subclasses.
Defines the clang::Expr interface and subclasses for C++ expressions.
Defines Expressions and AST nodes for C++2a concepts.
llvm::MachO::Target Target
llvm::MachO::Record Record
Defines the clang::MacroInfo and clang::MacroDirective classes.
Defines an enumeration for C++ overloaded operators.
Defines the clang::Preprocessor interface.
static std::string getName(const CallEvent &Call)
static AccessResult IsAccessible(Sema &S, const EffectiveContext &EC, AccessTarget &Entity)
Determines whether the accessed entity is accessible.
static QualType getPreferredArgumentTypeForMessageSend(ResultBuilder &Results, unsigned NumSelIdents)
Given a set of code-completion results for the argument of a message send, determine the preferred ty...
static void printOverrideString(const CodeCompletionString &CCS, std::string &BeforeName, std::string &NameAndSignature)
static bool isConstructor(const Decl *ND)
static void findTypeLocationForBlockDecl(const TypeSourceInfo *TSInfo, FunctionTypeLoc &Block, FunctionProtoTypeLoc &BlockProto, bool SuppressBlock=false)
Tries to find the most appropriate type location for an Objective-C block placeholder.
static void AddQualifierToCompletionString(CodeCompletionBuilder &Result, NestedNameSpecifier *Qualifier, bool QualifierIsInformative, ASTContext &Context, const PrintingPolicy &Policy)
Add a qualifier to the given code-completion string, if the provided nested-name-specifier is non-NUL...
static bool isObjCReceiverType(ASTContext &C, QualType T)
static void AddMacroResults(Preprocessor &PP, ResultBuilder &Results, bool LoadExternal, bool IncludeUndefined, bool TargetTypeIsPointer=false)
static std::string formatTemplateParameterPlaceholder(const NamedDecl *Param, bool &Optional, const PrintingPolicy &Policy)
static std::string formatBlockPlaceholder(const PrintingPolicy &Policy, const NamedDecl *BlockDecl, FunctionTypeLoc &Block, FunctionProtoTypeLoc &BlockProto, bool SuppressBlockName=false, bool SuppressBlock=false, std::optional< ArrayRef< QualType > > ObjCSubsts=std::nullopt)
Returns a placeholder string that corresponds to an Objective-C block declaration.
static void AddTemplateParameterChunks(ASTContext &Context, const PrintingPolicy &Policy, const TemplateDecl *Template, CodeCompletionBuilder &Result, unsigned MaxParameters=0, unsigned Start=0, bool InDefaultArg=false)
Add template parameter chunks to the given code completion string.
static void AddObjCTopLevelResults(ResultBuilder &Results, bool NeedAt)
static FunctionProtoTypeLoc GetPrototypeLoc(Expr *Fn)
static void AddFunctionParameterChunks(Preprocessor &PP, const PrintingPolicy &Policy, const FunctionDecl *Function, CodeCompletionBuilder &Result, unsigned Start=0, bool InOptional=false)
Add function parameter chunks to the given code completion string.
llvm::SmallPtrSet< const IdentifierInfo *, 16 > AddedPropertiesSet
The set of properties that have already been added, referenced by property name.
static bool argMatchesTemplateParams(const ParsedTemplateArgument &Arg, unsigned Index, const TemplateParameterList &Params)
static void setInBaseClass(ResultBuilder::Result &R)
static void AddObjCMethods(ObjCContainerDecl *Container, bool WantInstanceMethods, ObjCMethodKind WantKind, ArrayRef< const IdentifierInfo * > SelIdents, DeclContext *CurContext, VisitedSelectorSet &Selectors, bool AllowSameLength, ResultBuilder &Results, bool InOriginalClass=true, bool IsRootClass=false)
Add all of the Objective-C methods in the given Objective-C container to the set of results.
static void AddFunctionSpecifiers(Sema::ParserCompletionContext CCC, const LangOptions &LangOpts, ResultBuilder &Results)
static bool shouldIgnoreDueToReservedName(const NamedDecl *ND, Sema &SemaRef)
static RecordDecl * getAsRecordDecl(QualType BaseType)
static CodeCompletionString * createTemplateSignatureString(const TemplateDecl *TD, CodeCompletionBuilder &Builder, unsigned CurrentArg, const PrintingPolicy &Policy)
static QualType getParamType(Sema &SemaRef, ArrayRef< ResultCandidate > Candidates, unsigned N)
Get the type of the Nth parameter from a given set of overload candidates.
static const NamedDecl * extractFunctorCallOperator(const NamedDecl *ND)
static QualType ProduceSignatureHelp(Sema &SemaRef, MutableArrayRef< ResultCandidate > Candidates, unsigned CurrentArg, SourceLocation OpenParLoc, bool Braced)
static OverloadCompare compareOverloads(const CXXMethodDecl &Candidate, const CXXMethodDecl &Incumbent, const Qualifiers &ObjectQuals, ExprValueKind ObjectKind)
static std::string FormatFunctionParameter(const PrintingPolicy &Policy, const DeclaratorDecl *Param, bool SuppressName=false, bool SuppressBlock=false, std::optional< ArrayRef< QualType > > ObjCSubsts=std::nullopt)
static void AddOverrideResults(ResultBuilder &Results, const CodeCompletionContext &CCContext, CodeCompletionBuilder &Builder)
static void AddOrdinaryNameResults(Sema::ParserCompletionContext CCC, Scope *S, Sema &SemaRef, ResultBuilder &Results)
Add language constructs that show up for "ordinary" names.
static std::string formatObjCParamQualifiers(unsigned ObjCQuals, QualType &Type)
llvm::SmallPtrSet< Selector, 16 > VisitedSelectorSet
A set of selectors, which is used to avoid introducing multiple completions with the same selector in...
static void AddOverloadAggregateChunks(const RecordDecl *RD, const PrintingPolicy &Policy, CodeCompletionBuilder &Result, unsigned CurrentArg)
static void AddStorageSpecifiers(Sema::ParserCompletionContext CCC, const LangOptions &LangOpts, ResultBuilder &Results)
static void AddTypedefResult(ResultBuilder &Results)
static void AddPrettyFunctionResults(const LangOptions &LangOpts, ResultBuilder &Results)
static QualType getDesignatedType(QualType BaseType, const Designation &Desig)
static void AddObjCPassingTypeChunk(QualType Type, unsigned ObjCDeclQuals, ASTContext &Context, const PrintingPolicy &Policy, CodeCompletionBuilder &Builder)
Add the parenthesized return or parameter type chunk to a code completion string.
static void AddObjCKeyValueCompletions(ObjCPropertyDecl *Property, bool IsInstanceMethod, QualType ReturnType, ASTContext &Context, VisitedSelectorSet &KnownSelectors, ResultBuilder &Results)
Add code completions for Objective-C Key-Value Coding (KVC) and Key-Value Observing (KVO).
static void AddObjCStatementResults(ResultBuilder &Results, bool NeedAt)
static bool ObjCPropertyFlagConflicts(unsigned Attributes, unsigned NewFlag)
Determine whether the addition of the given flag to an Objective-C property's attributes will cause a...
static void AddEnumerators(ResultBuilder &Results, ASTContext &Context, EnumDecl *Enum, DeclContext *CurContext, const CoveredEnumerators &Enumerators)
llvm::DenseMap< Selector, llvm::PointerIntPair< ObjCMethodDecl *, 1, bool > > KnownMethodsMap
static const FunctionProtoType * TryDeconstructFunctionLike(QualType T)
Try to find a corresponding FunctionProtoType for function-like types (e.g.
static DeclContext::lookup_result getConstructors(ASTContext &Context, const CXXRecordDecl *Record)
static void AddResultTypeChunk(ASTContext &Context, const PrintingPolicy &Policy, const NamedDecl *ND, QualType BaseType, CodeCompletionBuilder &Result)
If the given declaration has an associated type, add it as a result type chunk.
static void AddObjCVisibilityResults(const LangOptions &LangOpts, ResultBuilder &Results, bool NeedAt)
static void addThisCompletion(Sema &S, ResultBuilder &Results)
Add a completion for "this", if we're in a member function.
static void AddObjCImplementationResults(const LangOptions &LangOpts, ResultBuilder &Results, bool NeedAt)
static ObjCMethodDecl * AddSuperSendCompletion(Sema &S, bool NeedSuperKeyword, ArrayRef< const IdentifierInfo * > SelIdents, ResultBuilder &Results)
static void AddRecordMembersCompletionResults(Sema &SemaRef, ResultBuilder &Results, Scope *S, QualType BaseType, ExprValueKind BaseKind, RecordDecl *RD, std::optional< FixItHint > AccessOpFixIt)
static void AddObjCBlockCall(ASTContext &Context, const PrintingPolicy &Policy, CodeCompletionBuilder &Builder, const NamedDecl *BD, const FunctionTypeLoc &BlockLoc, const FunctionProtoTypeLoc &BlockProtoLoc)
Adds a block invocation code completion result for the given block declaration BD.
static void AddLambdaCompletion(ResultBuilder &Results, llvm::ArrayRef< QualType > Parameters, const LangOptions &LangOpts)
Adds a pattern completion for a lambda expression with the specified parameter types and placeholders...
static void AddTypeSpecifierResults(const LangOptions &LangOpts, ResultBuilder &Results)
Add type specifiers for the current language as keyword results.
static std::optional< unsigned > getNextAggregateIndexAfterDesignatedInit(const ResultCandidate &Aggregate, ArrayRef< Expr * > Args)
static std::string GetDefaultValueString(const ParmVarDecl *Param, const SourceManager &SM, const LangOptions &LangOpts)
static void AddInterfaceResults(DeclContext *Ctx, DeclContext *CurContext, bool OnlyForwardDeclarations, bool OnlyUnimplemented, ResultBuilder &Results)
Add all of the Objective-C interface declarations that we find in the given (translation unit) contex...
static NestedNameSpecifier * getRequiredQualification(ASTContext &Context, const DeclContext *CurContext, const DeclContext *TargetContext)
Compute the qualification required to get from the current context (CurContext) to the target context...
static void FindImplementableMethods(ASTContext &Context, ObjCContainerDecl *Container, std::optional< bool > WantInstanceMethods, QualType ReturnType, KnownMethodsMap &KnownMethods, bool InOriginalClass=true)
Find all of the methods that reside in the given container (and its superclasses, protocols,...
static bool anyNullArguments(ArrayRef< Expr * > Args)
static const char * noUnderscoreAttrScope(llvm::StringRef Scope)
static void AddFunctionTypeQualsToCompletionString(CodeCompletionBuilder &Result, const FunctionDecl *Function)
static void MaybeAddSentinel(Preprocessor &PP, const NamedDecl *FunctionOrMethod, CodeCompletionBuilder &Result)
static void AddOverloadParameterChunks(ASTContext &Context, const PrintingPolicy &Policy, const FunctionDecl *Function, const FunctionProtoType *Prototype, FunctionProtoTypeLoc PrototypeLoc, CodeCompletionBuilder &Result, unsigned CurrentArg, unsigned Start=0, bool InOptional=false)
Add function overload parameter chunks to the given code completion string.
static void AddObjCProperties(const CodeCompletionContext &CCContext, ObjCContainerDecl *Container, bool AllowCategories, bool AllowNullaryMethods, DeclContext *CurContext, AddedPropertiesSet &AddedProperties, ResultBuilder &Results, bool IsBaseExprStatement=false, bool IsClassProperty=false, bool InOriginalClass=true)
static void HandleCodeCompleteResults(Sema *S, CodeCompleteConsumer *CodeCompleter, const CodeCompletionContext &Context, CodeCompletionResult *Results, unsigned NumResults)
static void AddTypeQualifierResults(DeclSpec &DS, ResultBuilder &Results, const LangOptions &LangOpts)
static void MaybeAddOverrideCalls(Sema &S, DeclContext *InContext, ResultBuilder &Results)
If we're in a C++ virtual member function, add completion results that invoke the functions we overri...
static ObjCContainerDecl * getContainerDef(ObjCContainerDecl *Container)
Retrieve the container definition, if any?
static const char * underscoreAttrScope(llvm::StringRef Scope)
static bool isAcceptableObjCMethod(ObjCMethodDecl *Method, ObjCMethodKind WantKind, ArrayRef< const IdentifierInfo * > SelIdents, bool AllowSameLength=true)
static void AddObjCExpressionResults(ResultBuilder &Results, bool NeedAt)
CodeCompleteConsumer::OverloadCandidate ResultCandidate
static std::string templateResultType(const TemplateDecl *TD, const PrintingPolicy &Policy)
static void AddTypedNameChunk(ASTContext &Context, const PrintingPolicy &Policy, const NamedDecl *ND, CodeCompletionBuilder &Result)
Add the name of the given declaration.
static void AddClassMessageCompletions(Sema &SemaRef, Scope *S, ParsedType Receiver, ArrayRef< const IdentifierInfo * > SelIdents, bool AtArgumentExpression, bool IsSuper, ResultBuilder &Results)
static const char * GetCompletionTypeString(QualType T, ASTContext &Context, const PrintingPolicy &Policy, CodeCompletionAllocator &Allocator)
Retrieve the string representation of the given type as a string that has the appropriate lifetime fo...
static bool InheritsFromClassNamed(ObjCInterfaceDecl *Class, StringRef Name)
Determine whether the given class is or inherits from a class by the given name.
#define OBJC_AT_KEYWORD_NAME(NeedAt, Keyword)
Macro that optionally prepends an "@" to the string literal passed in via Keyword,...
static bool isAcceptableObjCSelector(Selector Sel, ObjCMethodKind WantKind, ArrayRef< const IdentifierInfo * > SelIdents, bool AllowSameLength=true)
static QualType getPreferredTypeOfBinaryRHS(Sema &S, Expr *LHS, tok::TokenKind Op)
static QualType getPreferredTypeOfUnaryArg(Sema &S, QualType ContextType, tok::TokenKind Op)
Get preferred type for an argument of an unary expression.
static void AddUsingAliasResult(CodeCompletionBuilder &Builder, ResultBuilder &Results)
static ObjCInterfaceDecl * GetAssumedMessageSendExprType(Expr *E)
When we have an expression with type "id", we may assume that it has some more-specific class type ba...
ObjCMethodKind
Describes the kind of Objective-C method that we want to find via code completion.
@ MK_OneArgSelector
One-argument selector.
@ MK_ZeroArgSelector
Zero-argument (unary) selector.
@ MK_Any
Any kind of method, provided it means other specified criteria.
static bool WantTypesInContext(Sema::ParserCompletionContext CCC, const LangOptions &LangOpts)
static void mergeCandidatesWithResults(Sema &SemaRef, SmallVectorImpl< ResultCandidate > &Results, OverloadCandidateSet &CandidateSet, SourceLocation Loc, size_t ArgSize)
static void AddProtocolResults(DeclContext *Ctx, DeclContext *CurContext, bool OnlyForwardDeclarations, ResultBuilder &Results)
Add all of the protocol declarations that we find in the given (translation unit) context.
static void AddStaticAssertResult(CodeCompletionBuilder &Builder, ResultBuilder &Results, const LangOptions &LangOpts)
static void AddObjCInterfaceResults(const LangOptions &LangOpts, ResultBuilder &Results, bool NeedAt)
static bool isNamespaceScope(Scope *S)
Determine whether this scope denotes a namespace.
static CodeCompletionContext mapCodeCompletionContext(Sema &S, Sema::ParserCompletionContext PCC)
static PrintingPolicy getCompletionPrintingPolicy(const ASTContext &Context, const Preprocessor &PP)
static TemplateDecl * getDescribedTemplate(Decl *Templated)
Defines various enumerations that describe declaration and type specifiers.
enum clang::format::@1261::AnnotatingParser::Context::@343 ContextType
C Language Family Type Representation.
pointer(const DeclIndexPair &Value)
const DeclIndexPair * operator->() const
pointer operator->() const
reference operator*() const
std::ptrdiff_t difference_type
friend bool operator!=(const iterator &X, const iterator &Y)
iterator(const NamedDecl *SingleDecl, unsigned Index)
std::input_iterator_tag iterator_category
iterator(const DeclIndexPair *Iterator)
friend bool operator==(const iterator &X, const iterator &Y)
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
SourceManager & getSourceManager()
TranslationUnitDecl * getTranslationUnitDecl() const
QualType getObjCInterfaceType(const ObjCInterfaceDecl *Decl, ObjCInterfaceDecl *PrevDecl=nullptr) const
getObjCInterfaceType - Return the unique reference to the type for the specified ObjC interface decl.
DeclarationNameTable DeclarationNames
CanQualType getCanonicalType(QualType T) const
Return the canonical (structural) type corresponding to the specified potentially non-canonical type ...
bool hasSameType(QualType T1, QualType T2) const
Determine whether the given types T1 and T2 are equivalent.
QualType getPointerType(QualType T) const
Return the uniqued reference to the type for a pointer to the specified type.
QualType getTypeDeclType(const TypeDecl *Decl, const TypeDecl *PrevDecl=nullptr) const
Return the unique reference to the type for the specified type declaration.
const LangOptions & getLangOpts() const
SelectorTable & Selectors
QualType getBaseElementType(const ArrayType *VAT) const
Return the innermost element type of an array type.
QualType getPointerDiffType() const
Return the unique type for "ptrdiff_t" (C99 7.17) defined in <stddef.h>.
QualType getObjCObjectPointerType(QualType OIT) const
Return a ObjCObjectPointerType type for the given ObjCObjectType.
const RawComment * getRawCommentForAnyRedecl(const Decl *D, const Decl **OriginalDecl=nullptr) const
Return the documentation comment attached to a given declaration.
QualType getObjCIdType() const
Represents the Objective-CC id type.
bool hasSameUnqualifiedType(QualType T1, QualType T2) const
Determine whether the given types are equivalent after cvr-qualifiers have been removed.
const TargetInfo & getTargetInfo() const
QualType getElementType() const
Syntax
The style used to specify an attribute.
Type source information for an attributed type.
static std::optional< NullabilityKind > stripOuterNullability(QualType &T)
Strip off the top-level nullability annotation on the given type, if it's there.
Represents a C++11 auto or C++14 decltype(auto) type, possibly constrained by a type-constraint.
Represents a block literal declaration, which is like an unnamed FunctionDecl.
Wrapper for source info for block pointers.
This class is used for builtin types like 'int'.
Represents a base class of a C++ class.
Represents a C++ constructor within a class.
Represents a C++ member access expression where the actual member referenced could not be resolved be...
bool isArrow() const
Determine whether this member expression used the '->' operator; otherwise, it used the '.
QualType getBaseType() const
DeclarationName getMember() const
Retrieve the name of the member that this expression refers to.
Represents a static or instance method of a struct/union/class.
overridden_method_range overridden_methods() const
RefQualifierKind getRefQualifier() const
Retrieve the ref-qualifier associated with this method.
const CXXRecordDecl * getParent() const
Return the parent of this method declaration, which is the class in which this method is defined.
Qualifiers getMethodQualifiers() const
CXXMethodDecl * getCanonicalDecl() override
Retrieves the "canonical" declaration of the given declaration.
Represents a C++ struct/union/class.
bool isAggregate() const
Determine whether this class is an aggregate (C++ [dcl.init.aggr]), which is a class with no user-dec...
CXXRecordDecl * getDefinition() const
base_class_range vbases()
CXXRecordDecl * getCanonicalDecl() override
Retrieves the "canonical" declaration of the given declaration.
bool isDerivedFrom(const CXXRecordDecl *Base) const
Determine whether this class is derived from the class Base.
Represents a C++ nested-name-specifier or a global scope specifier.
bool isValid() const
A scope specifier is present, and it refers to a real scope.
NestedNameSpecifier * getScopeRep() const
Retrieve the representation of the nested-name-specifier.
bool isInvalid() const
An error occurred during parsing of the scope specifier.
bool isEmpty() const
No scope specifier.
CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
CaseStmt - Represent a case statement.
Represents a character-granular source range.
static CharSourceRange getTokenRange(SourceRange R)
Declaration of a class template.
CodeCompletionString * CreateSignatureString(unsigned CurrentArg, Sema &S, CodeCompletionAllocator &Allocator, CodeCompletionTUInfo &CCTUInfo, bool IncludeBriefComments, bool Braced) const
Create a new code-completion string that describes the function signature of this overload candidate.
const FunctionType * getFunctionType() const
Retrieve the function type of the entity, regardless of how the function is stored.
const TemplateDecl * getTemplate() const
CandidateKind getKind() const
Determine the kind of overload candidate.
const RecordDecl * getAggregate() const
Retrieve the aggregate type being initialized.
FunctionDecl * getFunction() const
Retrieve the function overload candidate or the templated function declaration for a function templat...
const FunctionProtoTypeLoc getFunctionProtoTypeLoc() const
Retrieve the function ProtoTypeLoc candidate.
@ CK_Aggregate
The candidate is aggregate initialization of a record type.
@ CK_Template
The candidate is a template, template arguments are being completed.
unsigned getNumParams() const
Get the number of parameters in this signature.
Abstract interface for a consumer of code-completion information.
bool includeGlobals() const
Whether to include global (top-level) declaration results.
virtual void ProcessCodeCompleteResults(Sema &S, CodeCompletionContext Context, CodeCompletionResult *Results, unsigned NumResults)
Process the finalized code-completion results.
bool includeCodePatterns() const
Whether the code-completion consumer wants to see code patterns.
bool loadExternal() const
Hint whether to load data from the external AST in order to provide full results.
virtual void ProcessOverloadCandidates(Sema &S, unsigned CurrentArg, OverloadCandidate *Candidates, unsigned NumCandidates, SourceLocation OpenParLoc, bool Braced)
An allocator used specifically for the purpose of code completion.
const char * CopyString(const Twine &String)
Copy the given string into this allocator.
A builder class used to construct new code-completion strings.
CodeCompletionString * TakeString()
Take the resulting completion string.
void AddPlaceholderChunk(const char *Placeholder)
Add a new placeholder chunk.
void AddTextChunk(const char *Text)
Add a new text chunk.
void AddCurrentParameterChunk(const char *CurrentParameter)
Add a new current-parameter chunk.
void AddTypedTextChunk(const char *Text)
Add a new typed-text chunk.
void AddChunk(CodeCompletionString::ChunkKind CK, const char *Text="")
Add a new chunk.
CodeCompletionAllocator & getAllocator() const
Retrieve the allocator into which the code completion strings should be allocated.
The context in which code completion occurred, so that the code-completion consumer can process the r...
Kind getKind() const
Retrieve the kind of code-completion context.
void setCXXScopeSpecifier(CXXScopeSpec SS)
Sets the scope specifier that comes before the completion token.
@ CCC_TypeQualifiers
Code completion within a type-qualifier list.
@ CCC_ObjCMessageReceiver
Code completion occurred where an Objective-C message receiver is expected.
@ CCC_PreprocessorExpression
Code completion occurred within a preprocessor expression.
@ CCC_ObjCCategoryName
Code completion where an Objective-C category name is expected.
@ CCC_ObjCIvarList
Code completion occurred within the instance variable list of an Objective-C interface,...
@ CCC_Statement
Code completion occurred where a statement (or declaration) is expected in a function,...
@ CCC_Type
Code completion occurred where a type name is expected.
@ CCC_ArrowMemberAccess
Code completion occurred on the right-hand side of a member access expression using the arrow operato...
@ CCC_ClassStructUnion
Code completion occurred within a class, struct, or union.
@ CCC_ObjCInterface
Code completion occurred within an Objective-C interface, protocol, or category interface.
@ CCC_ObjCPropertyAccess
Code completion occurred on the right-hand side of an Objective-C property access expression.
@ CCC_Expression
Code completion occurred where an expression is expected.
@ CCC_SelectorName
Code completion for a selector, as in an @selector expression.
@ CCC_TopLevelOrExpression
Code completion at a top level, i.e.
@ CCC_EnumTag
Code completion occurred after the "enum" keyword, to indicate an enumeration name.
@ CCC_UnionTag
Code completion occurred after the "union" keyword, to indicate a union name.
@ CCC_ParenthesizedExpression
Code completion in a parenthesized expression, which means that we may also have types here in C and ...
@ CCC_TopLevel
Code completion occurred within a "top-level" completion context, e.g., at namespace or global scope.
@ CCC_ClassOrStructTag
Code completion occurred after the "struct" or "class" keyword, to indicate a struct or class name.
@ CCC_ObjCClassMessage
Code completion where an Objective-C class message is expected.
@ CCC_ObjCImplementation
Code completion occurred within an Objective-C implementation or category implementation.
@ CCC_IncludedFile
Code completion inside the filename part of a #include directive.
@ CCC_ObjCInstanceMessage
Code completion where an Objective-C instance message is expected.
@ CCC_SymbolOrNewName
Code completion occurred where both a new name and an existing symbol is permissible.
@ CCC_Recovery
An unknown context, in which we are recovering from a parsing error and don't know which completions ...
@ CCC_ObjCProtocolName
Code completion occurred where a protocol name is expected.
@ CCC_NewName
Code completion occurred where a new name is expected.
@ CCC_MacroNameUse
Code completion occurred where a macro name is expected (without any arguments, in the case of a func...
@ CCC_Symbol
Code completion occurred where an existing name(such as type, function or variable) is expected.
@ CCC_Attribute
Code completion of an attribute name.
@ CCC_Other
An unspecified code-completion context.
@ CCC_DotMemberAccess
Code completion occurred on the right-hand side of a member access expression using the dot operator.
@ CCC_MacroName
Code completion occurred where an macro is being defined.
@ CCC_Namespace
Code completion occurred where a namespace or namespace alias is expected.
@ CCC_PreprocessorDirective
Code completion occurred where a preprocessor directive is expected.
@ CCC_NaturalLanguage
Code completion occurred in a context where natural language is expected, e.g., a comment or string l...
@ CCC_ObjCInterfaceName
Code completion where the name of an Objective-C class is expected.
@ CCC_ObjCClassForwardDecl
QualType getBaseType() const
Retrieve the type of the base object in a member-access expression.
void setPreferredType(QualType T)
bool wantConstructorResults() const
Determines whether we want C++ constructors as results within this context.
void setIsUsingDeclaration(bool V)
void addVisitedContext(DeclContext *Ctx)
Adds a visited context.
Captures a result of code completion.
bool DeclaringEntity
Whether we're completing a declaration of the given entity, rather than a use of that entity.
ResultKind Kind
The kind of result stored here.
const char * Keyword
When Kind == RK_Keyword, the string representing the keyword or symbol's spelling.
CXAvailabilityKind Availability
The availability of this result.
NestedNameSpecifier * Qualifier
If the result should have a nested-name-specifier, this is it.
CodeCompletionString * CreateCodeCompletionString(Sema &S, const CodeCompletionContext &CCContext, CodeCompletionAllocator &Allocator, CodeCompletionTUInfo &CCTUInfo, bool IncludeBriefComments)
Create a new code-completion string that describes how to insert this result into a program.
bool QualifierIsInformative
Whether this result was found via lookup into a base class.
const NamedDecl * Declaration
When Kind == RK_Declaration or RK_Pattern, the declaration we are referring to.
CodeCompletionString * createCodeCompletionStringForDecl(Preprocessor &PP, ASTContext &Ctx, CodeCompletionBuilder &Result, bool IncludeBriefComments, const CodeCompletionContext &CCContext, PrintingPolicy &Policy)
CodeCompletionString * CreateCodeCompletionStringForMacro(Preprocessor &PP, CodeCompletionAllocator &Allocator, CodeCompletionTUInfo &CCTUInfo)
Creates a new code-completion string for the macro result.
unsigned StartParameter
Specifies which parameter (of a function, Objective-C method, macro, etc.) we should start with when ...
bool InBaseClass
Whether this is a class member from base class.
unsigned Priority
The priority of this particular code-completion result.
bool StartsNestedNameSpecifier
Whether this declaration is the beginning of a nested-name-specifier and, therefore,...
CodeCompletionString * Pattern
When Kind == RK_Pattern, the code-completion string that describes the completion text to insert.
bool FunctionCanBeCall
When completing a function, whether it can be a call.
bool AllParametersAreInformative
Whether all parameters (of a function, Objective-C method, etc.) should be considered "informative".
CodeCompletionString * createCodeCompletionStringForOverride(Preprocessor &PP, ASTContext &Ctx, CodeCompletionBuilder &Result, bool IncludeBriefComments, const CodeCompletionContext &CCContext, PrintingPolicy &Policy)
const IdentifierInfo * Macro
When Kind == RK_Macro, the identifier that refers to a macro.
@ RK_Pattern
Refers to a precomputed pattern.
@ RK_Declaration
Refers to a declaration.
@ RK_Macro
Refers to a macro.
@ RK_Keyword
Refers to a keyword or symbol.
A "string" used to describe how code completion can be performed for an entity.
@ CK_Optional
A code completion string that is entirely optional.
@ CK_CurrentParameter
A piece of text that describes the parameter that corresponds to the code-completion location within ...
@ CK_Comma
A comma separator (',').
@ CK_Placeholder
A string that acts as a placeholder for, e.g., a function call argument.
@ CK_LeftParen
A left parenthesis ('(').
@ CK_HorizontalSpace
Horizontal whitespace (' ').
@ CK_RightAngle
A right angle bracket ('>').
@ CK_LeftBracket
A left bracket ('[').
@ CK_RightParen
A right parenthesis (')').
@ CK_RightBrace
A right brace ('}').
@ CK_VerticalSpace
Vertical whitespace ('\n' or '\r\n', depending on the platform).
@ CK_SemiColon
A semicolon (';').
@ CK_TypedText
The piece of text that the user is expected to type to match the code-completion string,...
@ CK_RightBracket
A right bracket (']').
@ CK_LeftBrace
A left brace ('{').
@ CK_LeftAngle
A left angle bracket ('<').
Declaration of a C++20 concept.
Expr * getConstraintExpr() const
const TypeClass * getTypePtr() const
static DeclAccessPair make(NamedDecl *D, AccessSpecifier AS)
The results of name lookup within a DeclContext.
specific_decl_iterator - Iterates over a subrange of declarations stored in a DeclContext,...
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
DeclContext * getParent()
getParent - Returns the containing DeclContext.
bool Equals(const DeclContext *DC) const
Determine whether this declaration context is equivalent to the declaration context DC.
bool isFileContext() const
bool isObjCContainer() const
bool isDependentContext() const
Determines whether this context is dependent on a template parameter.
DeclContext * getRedeclContext()
getRedeclContext - Retrieve the context in which an entity conflicts with other entities of the same ...
decl_iterator decls_end() const
decl_range decls() const
decls_begin/decls_end - Iterate over the declarations stored in this context.
bool isFunctionOrMethod() const
bool Encloses(const DeclContext *DC) const
Determine whether this declaration context encloses the declaration context DC.
decl_iterator decls_begin() const
Captures information about "declaration specifiers".
static const TST TST_typename
TST getTypeSpecType() const
static const TST TST_interface
unsigned getTypeQualifiers() const
getTypeQualifiers - Return a set of TQs.
static const TST TST_union
TSC getTypeSpecComplex() const
ParsedType getRepAsType() const
static const TST TST_enum
static const TST TST_class
unsigned getParsedSpecifiers() const
Return a bitmask of which flavors of specifiers this DeclSpec includes.
bool isTypeAltiVecVector() const
TypeSpecifierSign getTypeSpecSign() const
static const TST TST_struct
Decl - This represents one declaration (or definition), e.g.
FriendObjectKind getFriendObjectKind() const
Determines whether this declaration is the object of a friend declaration and, if so,...
ASTContext & getASTContext() const LLVM_READONLY
@ FOK_Undeclared
A friend of a previously-undeclared entity.
FunctionDecl * getAsFunction() LLVM_READONLY
Returns the function itself, or the templated function if this is a function template.
ObjCDeclQualifier
ObjCDeclQualifier - 'Qualifiers' written next to the return and parameter types in method declaration...
@ OBJC_TQ_CSNullability
The nullability qualifier is set when the nullability of the result or parameter was expressed via a ...
unsigned getIdentifierNamespace() const
llvm::iterator_range< specific_attr_iterator< T > > specific_attrs() const
SourceLocation getLocation() const
@ IDNS_Ordinary
Ordinary names.
@ IDNS_Member
Members, declared with object declarations within tag definitions.
@ IDNS_ObjCProtocol
Objective C @protocol.
@ IDNS_Namespace
Namespaces, declared with 'namespace foo {}'.
@ IDNS_LocalExtern
This declaration is a function-local extern declaration of a variable or function.
@ IDNS_Tag
Tags, declared with 'struct foo;' and referenced with 'struct foo'.
DeclContext * getDeclContext()
AccessSpecifier getAccess() const
void print(raw_ostream &Out, unsigned Indentation=0, bool PrintInstantiation=false) const
DeclContext * getLexicalDeclContext()
getLexicalDeclContext - The declaration context where this Decl was lexically declared (LexicalDC).
virtual Decl * getCanonicalDecl()
Retrieves the "canonical" declaration of the given declaration.
The name of a declaration.
uintptr_t getAsOpaqueInteger() const
Get the representation of this declaration name as an opaque integer.
IdentifierInfo * getAsIdentifierInfo() const
Retrieve the IdentifierInfo * stored in this declaration name, or null if this declaration name isn't...
void print(raw_ostream &OS, const PrintingPolicy &Policy) const
@ CXXConversionFunctionName
NameKind getNameKind() const
Determine what kind of name this is.
bool isIdentifier() const
Predicate functions for querying what type of name this is.
Represents a ValueDecl that came out of a declarator.
TypeSourceInfo * getTypeSourceInfo() const
Information about one declarator, including the parsed type information and the identifier.
bool isFunctionDeclarator(unsigned &idx) const
isFunctionDeclarator - This method returns true if the declarator is a function declarator (looking t...
DeclaratorContext getContext() const
bool isCtorOrDtor()
Returns true if this declares a constructor or a destructor.
UnqualifiedId & getName()
Retrieve the name specified by this declarator.
bool isStaticMember()
Returns true if this declares a static member.
DeclaratorChunk::FunctionTypeInfo & getFunctionTypeInfo()
getFunctionTypeInfo - Retrieves the function type info object (looking through parentheses).
Represents a qualified type name for which the type name is dependent.
NestedNameSpecifier * getQualifier() const
Retrieve the qualification on this type.
const IdentifierInfo * getIdentifier() const
Retrieve the type named by the typename specifier as an identifier.
A qualified reference to a name whose declaration cannot yet be resolved.
NestedNameSpecifier * getQualifier() const
Retrieve the nested-name-specifier that qualifies this declaration.
DeclarationName getDeclName() const
Retrieve the name that this expression refers to.
Designation - Represent a full designation, which is a sequence of designators.
const Designator & getDesignator(unsigned Idx) const
unsigned getNumDesignators() const
DirectoryLookup - This class represents one entry in the search list that specifies the search order ...
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of enums.
This represents one expression.
static QualType findBoundMemberType(const Expr *expr)
Given an expression of bound-member type, find the type of the member.
Expr * IgnoreParenCasts() LLVM_READONLY
Skip past any parentheses and casts which might surround this expression until reaching a fixed point...
bool isTypeDependent() const
Determines whether the type of this expression depends on.
Expr * IgnoreParenImpCasts() LLVM_READONLY
Skip past any parentheses and implicit casts which might surround this expression until reaching a fi...
SourceLocation getExprLoc() const LLVM_READONLY
getExprLoc - Return the preferred location for the arrow when diagnosing a problem with a generic exp...
virtual Selector GetExternalSelector(uint32_t ID)
Resolve a selector ID into a selector.
virtual uint32_t GetNumExternalSelectors()
Returns the number of selectors known to the external AST source.
Represents a member of a struct/union/class.
static FixItHint CreateReplacement(CharSourceRange RemoveRange, StringRef Code)
Create a code modification hint that replaces the given source range with the given code string.
Represents a function declaration or definition.
unsigned getMinRequiredArguments() const
Returns the minimum number of arguments needed to call this function.
param_iterator param_end()
QualType getReturnType() const
ArrayRef< ParmVarDecl * > parameters() const
param_iterator param_begin()
bool isVariadic() const
Whether this function is variadic.
unsigned getNumParams() const
Return the number of parameters this function must have based on its FunctionType.
size_t param_size() const
Represents a prototype with parameter type info, e.g.
bool isVariadic() const
Whether this function prototype is variadic.
Declaration of a template function.
Wrapper for source info for functions.
unsigned getNumParams() const
ParmVarDecl * getParam(unsigned i) const
TypeLoc getReturnLoc() const
FunctionType - C99 6.7.5.3 - Function Declarators.
QualType getReturnType() const
One of these records is kept for each identifier that is lexed.
unsigned getLength() const
Efficiently return the length of this identifier info.
bool isStr(const char(&Str)[StrLen]) const
Return true if this is the identifier for the specified string.
StringRef deuglifiedName() const
If the identifier is an "uglified" reserved name, return a cleaned form.
StringRef getName() const
Return the actual identifier string.
IdentifierInfo & get(StringRef Name)
Return the identifier token info for the specified named identifier.
const TypeClass * getTypePtr() const
The injected class name of a C++ class template or class template partial specialization.
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
static StringRef getSourceText(CharSourceRange Range, const SourceManager &SM, const LangOptions &LangOpts, bool *Invalid=nullptr)
Returns a string for the source that the range encompasses.
Represents the results of name lookup.
const UnresolvedSetImpl & asUnresolvedSet() const
void suppressDiagnostics()
Suppress the diagnostics that would normally fire because of this lookup.
Encapsulates the data about a macro definition (e.g.
bool isC99Varargs() const
bool isFunctionLike() const
param_iterator param_begin() const
IdentifierInfo *const * param_iterator
Parameters - The list of parameters for a function-like macro.
param_iterator param_end() const
bool isUsedForHeaderGuard() const
Determine whether this macro was used for a header guard.
Describes a module or submodule.
@ AllVisible
All of the names in this module are visible.
llvm::iterator_range< submodule_iterator > submodules()
This represents a decl that may have a name.
NamedDecl * getUnderlyingDecl()
Looks through UsingDecls and ObjCCompatibleAliasDecls for the underlying named decl.
IdentifierInfo * getIdentifier() const
Get the identifier that names this declaration, if there is one.
StringRef getName() const
Get the name of identifier for this declaration as a StringRef.
DeclarationName getDeclName() const
Get the actual, stored name of the declaration, which may be a special name.
std::string getNameAsString() const
Get a human-readable name for the declaration, even if it is one of the special kinds of names (C++ c...
ReservedIdentifierStatus isReserved(const LangOptions &LangOpts) const
Determine if the declaration obeys the reserved identifier rules of the given language.
Represent a C++ namespace.
A C++ nested-name-specifier augmented with source location information.
NestedNameSpecifier * getNestedNameSpecifier() const
Retrieve the nested-name-specifier to which this instance refers.
Represents a C++ nested name specifier, such as "\::std::vector<int>::".
bool isDependent() const
Whether this nested name specifier refers to a dependent type or not.
static NestedNameSpecifier * Create(const ASTContext &Context, NestedNameSpecifier *Prefix, const IdentifierInfo *II)
Builds a specifier combining a prefix and an identifier.
IdentifierInfo * getAsIdentifier() const
Retrieve the identifier stored in this nested name specifier.
NestedNameSpecifier * getPrefix() const
Return the prefix of this nested name specifier.
void print(raw_ostream &OS, const PrintingPolicy &Policy, bool ResolveTemplateArguments=false) const
Print this nested name specifier to the given output stream.
const Type * getAsType() const
Retrieve the type stored in this nested name specifier.
NonTypeTemplateParmDecl - Declares a non-type template parameter, e.g., "Size" in.
ObjCCategoryDecl - Represents a category declaration.
ObjCCategoryImplDecl - An object of this class encapsulates a category @implementation declaration.
ObjCContainerDecl - Represents a container for method declarations.
Captures information about "declaration specifiers" specific to Objective-C.
ObjCPropertyAttribute::Kind getPropertyAttributes() const
ObjCDeclQualifier getObjCDeclQualifier() const
ObjCImplementationDecl - Represents a class definition - this is where method definitions are specifi...
Represents an ObjC class declaration.
bool hasDefinition() const
Determine whether this class has been defined.
protocol_range protocols() const
known_categories_range known_categories() const
ObjCImplementationDecl * getImplementation() const
visible_categories_range visible_categories() const
ObjCInterfaceDecl * getSuperClass() const
ObjCIvarDecl - Represents an ObjC instance variable.
ObjCList - This is a simple template class used to hold various lists of decls etc,...
@ SuperInstance
The receiver is the instance of the superclass object.
@ Instance
The receiver is an object instance.
@ SuperClass
The receiver is a superclass.
@ Class
The receiver is a class.
ObjCMethodDecl - Represents an instance or class method declaration.
ObjCDeclQualifier getObjCDeclQualifier() const
ArrayRef< ParmVarDecl * > parameters() const
unsigned param_size() const
param_const_iterator param_end() const
QualType getSendResultType() const
Determine the type of an expression that sends a message to this function.
param_const_iterator param_begin() const
const ParmVarDecl *const * param_const_iterator
Selector getSelector() const
bool isInstanceMethod() const
QualType getReturnType() const
ParmVarDecl *const * param_iterator
ObjCInterfaceDecl * getClassInterface()
Represents a pointer to an Objective C object.
ObjCInterfaceDecl * getInterfaceDecl() const
If this pointer points to an Objective @interface type, gets the declaration for that interface.
Represents a class type in Objective C.
Represents one property declaration in an Objective-C interface.
static ObjCPropertyDecl * findPropertyDecl(const DeclContext *DC, const IdentifierInfo *propertyID, ObjCPropertyQueryKind queryKind)
Lookup a property by name in the specified DeclContext.
Selector getGetterName() const
Represents an Objective-C protocol declaration.
void * getAsOpaquePtr() const
static OpaquePtr make(QualType P)
OverloadCandidateSet - A set of overload candidates, used in C++ overload resolution (C++ 13....
@ CSK_Normal
Normal lookup.
CandidateSetKind getKind() const
Represents a parameter to a function.
SourceRange getDefaultArgRange() const
Retrieve the source range that covers the entire default argument.
bool hasDefaultArg() const
Determines whether this parameter has a default argument, either parsed or not.
Represents the parsed form of a C++ template argument.
KindType getKind() const
Determine what kind of template argument we have.
@ Type
A template type parameter, stored as a type.
@ Template
A template template argument, stored as a template name.
@ NonType
A non-type template parameter, stored as an expression.
Wrapper for source info for pointers.
PointerType - C99 6.7.5.1 - Pointer Declarators.
void enterFunctionArgument(SourceLocation Tok, llvm::function_ref< QualType()> ComputeType)
Computing a type for the function argument may require running overloading, so we postpone its comput...
void enterCondition(Sema &S, SourceLocation Tok)
void enterTypeCast(SourceLocation Tok, QualType CastType)
Handles all type casts, including C-style cast, C++ casts, etc.
void enterMemAccess(Sema &S, SourceLocation Tok, Expr *Base)
void enterSubscript(Sema &S, SourceLocation Tok, Expr *LHS)
void enterUnary(Sema &S, SourceLocation Tok, tok::TokenKind OpKind, SourceLocation OpLoc)
void enterReturn(Sema &S, SourceLocation Tok)
void enterDesignatedInitializer(SourceLocation Tok, QualType BaseType, const Designation &D)
Handles e.g. BaseType{ .D = Tok...
void enterBinary(Sema &S, SourceLocation Tok, Expr *LHS, tok::TokenKind Op)
void enterParenExpr(SourceLocation Tok, SourceLocation LParLoc)
void enterVariableInit(SourceLocation Tok, Decl *D)
QualType get(SourceLocation Tok) const
Get the expected type associated with this location, if any.
Engages in a tight little dance with the lexer to efficiently preprocess tokens.
const MacroInfo * getMacroInfo(const IdentifierInfo *II) const
macro_iterator macro_begin(bool IncludeExternalMacros=true) const
macro_iterator macro_end(bool IncludeExternalMacros=true) const
SourceManager & getSourceManager() const
MacroDefinition getMacroDefinition(const IdentifierInfo *II)
bool isMacroDefined(StringRef Id)
MacroMap::const_iterator macro_iterator
const LangOptions & getLangOpts() const
bool isCodeCompletionReached() const
Returns true if code-completion is enabled and we have hit the code-completion point.
A (possibly-)qualified type.
bool isNull() const
Return true if this QualType doesn't point to a type yet.
const Type * getTypePtr() const
Retrieves a pointer to the underlying (unqualified) type.
Qualifiers getQualifiers() const
Retrieve the set of qualifiers applied to this type.
QualType stripObjCKindOfType(const ASTContext &ctx) const
Strip Objective-C "__kindof" types from the given type.
void print(raw_ostream &OS, const PrintingPolicy &Policy, const Twine &PlaceHolder=Twine(), unsigned Indentation=0) const
void getAsStringInternal(std::string &Str, const PrintingPolicy &Policy) const
QualType getNonReferenceType() const
If Type is a reference type (e.g., const int&), returns the type that the reference refers to ("const...
QualType getCanonicalType() const
QualType getUnqualifiedType() const
Retrieve the unqualified variant of the given type, removing as little sugar as possible.
QualType substObjCTypeArgs(ASTContext &ctx, ArrayRef< QualType > typeArgs, ObjCSubstitutionContext context) const
Substitute type arguments for the Objective-C type parameters used in the subject type.
static std::string getAsString(SplitQualType split, const PrintingPolicy &Policy)
Wrapper of type source information for a type with non-trivial direct qualifiers.
The collection of all-type qualifiers we support.
bool compatiblyIncludes(Qualifiers other) const
Determines if these qualifiers compatibly include another set.
Represents a struct/union/class.
bool isLambda() const
Determine whether this record is a class describing a lambda function object.
field_range fields() const
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of structs/unions/cl...
A class that does preorder or postorder depth-first traversal on the entire Clang AST and visits each...
bool TraverseNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS)
Recursively visit a C++ nested-name-specifier with location information.
Base for LValueReferenceType and RValueReferenceType.
QualType getPointeeType() const
Scope - A scope is a transient data structure that is used while parsing the program.
@ FunctionPrototypeScope
This is a scope that corresponds to the parameters within a function prototype.
@ AtCatchScope
This is a scope that corresponds to the Objective-C @catch statement.
@ TemplateParamScope
This is a scope that corresponds to the template parameters of a C++ template.
@ ClassScope
The scope of a struct/union/class definition.
@ DeclScope
This is a scope that can contain a declaration.
This table allows us to fully hide how we implement multi-keyword caching.
Selector getNullarySelector(const IdentifierInfo *ID)
Selector getSelector(unsigned NumArgs, const IdentifierInfo **IIV)
Can create any sort of selector.
Selector getUnarySelector(const IdentifierInfo *ID)
Smart pointer class that efficiently represents Objective-C method names.
StringRef getNameForSlot(unsigned argIndex) const
Retrieve the name at a given position in the selector.
const IdentifierInfo * getIdentifierInfoForSlot(unsigned argIndex) const
Retrieve the identifier at a given position in the selector.
bool isUnarySelector() const
bool isNull() const
Determine whether this is the empty selector.
unsigned getNumArgs() const
llvm::DenseMap< Selector, Lists >::iterator iterator
int count(Selector Sel) const
Sema - This implements semantic analysis and AST building for C.
QualType getCurrentThisType()
Try to retrieve the type of the 'this' pointer.
void CodeCompleteObjCMethodDeclSelector(Scope *S, bool IsInstanceMethod, bool AtParameterName, ParsedType ReturnType, ArrayRef< const IdentifierInfo * > SelIdents)
void GatherGlobalCodeCompletions(CodeCompletionAllocator &Allocator, CodeCompletionTUInfo &CCTUInfo, SmallVectorImpl< CodeCompletionResult > &Results)
void CodeCompleteObjCProtocolDecl(Scope *S)
void CodeCompleteTag(Scope *S, unsigned TagSpec)
bool IsOverload(FunctionDecl *New, FunctionDecl *Old, bool UseMemberUsingDeclRules, bool ConsiderCudaAttrs=true)
@ LookupMemberName
Member name lookup, which finds the names of class/struct/union members.
void CodeCompleteUsing(Scope *S)
void CodeCompleteMemberReferenceExpr(Scope *S, Expr *Base, Expr *OtherOpBase, SourceLocation OpLoc, bool IsArrow, bool IsBaseExprStatement, QualType PreferredType)
void CodeCompleteCase(Scope *S)
void CodeCompleteObjCMessageReceiver(Scope *S)
QualType ProduceCallSignatureHelp(Expr *Fn, ArrayRef< Expr * > Args, SourceLocation OpenParLoc)
Determines the preferred type of the current function argument, by examining the signatures of all po...
void CodeCompleteInitializer(Scope *S, Decl *D)
QualType ProduceConstructorSignatureHelp(QualType Type, SourceLocation Loc, ArrayRef< Expr * > Args, SourceLocation OpenParLoc, bool Braced)
void CodeCompleteObjCAtDirective(Scope *S)
void CodeCompleteObjCClassPropertyRefExpr(Scope *S, const IdentifierInfo &ClassName, SourceLocation ClassNameLoc, bool IsBaseExprStatement)
Preprocessor & getPreprocessor() const
void CodeCompletePreprocessorMacroArgument(Scope *S, IdentifierInfo *Macro, MacroInfo *MacroInfo, unsigned Argument)
void CodeCompleteObjCAtExpression(Scope *S)
void CodeCompleteObjCPropertySynthesizeIvar(Scope *S, IdentifierInfo *PropertyName)
void CodeCompleteLambdaIntroducer(Scope *S, LambdaIntroducer &Intro, bool AfterAmpersand)
void CodeCompletePostfixExpression(Scope *S, ExprResult LHS, QualType PreferredType)
void CodeCompleteObjCClassForwardDecl(Scope *S)
QualType ProduceTemplateArgumentSignatureHelp(TemplateTy, ArrayRef< ParsedTemplateArgument >, SourceLocation LAngleLoc)
void CodeCompleteAfterIf(Scope *S, bool IsBracedThen)
void CodeCompleteAvailabilityPlatformName()
ASTContext & getASTContext() const
void CodeCompleteObjCPropertyDefinition(Scope *S)
void CodeCompleteUsingDirective(Scope *S)
void CodeCompleteTypeQualifiers(DeclSpec &DS)
PrintingPolicy getPrintingPolicy() const
Retrieve a suitable printing policy for diagnostics.
ObjCMethodDecl * getCurMethodDecl()
getCurMethodDecl - If inside of a method body, this returns a pointer to the method decl for the meth...
void CodeCompleteInPreprocessorConditionalExclusion(Scope *S)
void CodeCompleteExpression(Scope *S, const CodeCompleteExpressionData &Data)
Perform code-completion in an expression context when we know what type we're looking for.
void CodeCompleteQualifiedId(Scope *S, CXXScopeSpec &SS, bool EnteringContext, bool IsUsingDeclaration, QualType BaseType, QualType PreferredType)
const LangOptions & getLangOpts() const
void LookupVisibleDecls(Scope *S, LookupNameKind Kind, VisibleDeclConsumer &Consumer, bool IncludeGlobalScope=true, bool LoadExternal=true)
void CodeCompleteObjCImplementationDecl(Scope *S)
void CodeCompleteObjCPropertySetter(Scope *S)
void CodeCompleteFunctionQualifiers(DeclSpec &DS, Declarator &D, const VirtSpecifiers *VS=nullptr)
void CodeCompleteObjCInstanceMessage(Scope *S, Expr *Receiver, ArrayRef< const IdentifierInfo * > SelIdents, bool AtArgumentExpression, ObjCInterfaceDecl *Super=nullptr)
void CodeCompleteNamespaceDecl(Scope *S)
void CodeCompleteDesignator(const QualType BaseType, llvm::ArrayRef< Expr * > InitExprs, const Designation &D)
Trigger code completion for a record of BaseType.
void CodeCompleteNaturalLanguage()
void CodeCompleteOperatorName(Scope *S)
void CodeCompleteObjCProtocolReferences(ArrayRef< IdentifierLocPair > Protocols)
sema::FunctionScopeInfo * getCurFunction() const
void CodeCompleteObjCAtVisibility(Scope *S)
void CodeCompleteNamespaceAliasDecl(Scope *S)
void CodeCompleteAttribute(AttributeCommonInfo::Syntax Syntax, AttributeCompletion Completion=AttributeCompletion::Attribute, const IdentifierInfo *Scope=nullptr)
void CodeCompleteIncludedFile(llvm::StringRef Dir, bool IsAngled)
sema::BlockScopeInfo * getCurBlock()
Retrieve the current block, if any.
DeclContext * CurContext
CurContext - This is the current declaration context of parsing.
void CodeCompleteObjCSuperclass(Scope *S, IdentifierInfo *ClassName, SourceLocation ClassNameLoc)
QualType ProduceCtorInitMemberSignatureHelp(Decl *ConstructorDecl, CXXScopeSpec SS, ParsedType TemplateTypeTy, ArrayRef< Expr * > ArgExprs, IdentifierInfo *II, SourceLocation OpenParLoc, bool Braced)
ParserCompletionContext
Describes the context in which code completion occurs.
@ PCC_RecoveryInFunction
Code completion occurs within the body of a function on a recovery path, where we do not have a speci...
@ PCC_LocalDeclarationSpecifiers
Code completion occurs within a sequence of declaration specifiers within a function,...
@ PCC_Template
Code completion occurs following one or more template headers.
@ PCC_MemberTemplate
Code completion occurs following one or more template headers within a class.
@ PCC_Expression
Code completion occurs within an expression.
@ PCC_ObjCInterface
Code completion occurs within an Objective-C interface, protocol, or category.
@ PCC_TopLevelOrExpression
Code completion occurs at top-level in a REPL session.
@ PCC_Class
Code completion occurs within a class, struct, or union.
@ PCC_ObjCImplementation
Code completion occurs within an Objective-C implementation or category implementation.
@ PCC_ParenthesizedExpression
Code completion occurs in a parenthesized expression, which might also be a type cast.
@ PCC_Namespace
Code completion occurs at top-level or namespace context.
@ PCC_Type
Code completion occurs where only a type is permitted.
@ PCC_Condition
Code completion occurs within the condition of an if, while, switch, or for statement.
@ PCC_ForInit
Code completion occurs at the beginning of the initialization statement (or expression) in a for loop...
@ PCC_Statement
Code completion occurs within a statement, which may also be an expression or a declaration.
@ PCC_ObjCInstanceVariableList
Code completion occurs within the list of instance variables in an Objective-C interface,...
GlobalMethodPool MethodPool
Method Pool - allows efficient lookup when typechecking messages to "id".
void CodeCompleteBracketDeclarator(Scope *S)
ExternalSemaSource * getExternalSource() const
void CodeCompleteObjCInterfaceCategory(Scope *S, IdentifierInfo *ClassName, SourceLocation ClassNameLoc)
void CodeCompleteObjCMethodDecl(Scope *S, std::optional< bool > IsInstanceMethod, ParsedType ReturnType)
void CodeCompleteObjCPassingType(Scope *S, ObjCDeclSpec &DS, bool IsParameter)
void CodeCompleteConstructorInitializer(Decl *Constructor, ArrayRef< CXXCtorInitializer * > Initializers)
bool isAcceptableNestedNameSpecifier(const NamedDecl *SD, bool *CanCorrect=nullptr)
Determines whether the given declaration is an valid acceptable result for name lookup of a nested-na...
void CodeCompleteObjCClassMessage(Scope *S, ParsedType Receiver, ArrayRef< const IdentifierInfo * > SelIdents, bool AtArgumentExpression, bool IsSuper=false)
void CodeCompleteModuleImport(SourceLocation ImportLoc, ModuleIdPath Path)
void CodeCompletePreprocessorMacroName(bool IsDefinition)
void CodeCompleteOrdinaryName(Scope *S, ParserCompletionContext CompletionContext)
void CodeCompleteObjCPropertyFlags(Scope *S, ObjCDeclSpec &ODS)
void CodeCompleteObjCPropertyGetter(Scope *S)
void ReadMethodPool(Selector Sel)
Read the contents of the method pool for a given selector from external storage.
void CodeCompleteObjCSelector(Scope *S, ArrayRef< const IdentifierInfo * > SelIdents)
SourceManager & SourceMgr
void CodeCompleteDeclSpec(Scope *S, DeclSpec &DS, bool AllowNonIdentifiers, bool AllowNestedNameSpecifiers)
void CodeCompleteAfterFunctionEquals(Declarator &D)
void CodeCompleteObjCAtStatement(Scope *S)
void CodeCompleteObjCInterfaceDecl(Scope *S)
CodeCompleteConsumer * CodeCompleter
Code-completion consumer.
void CodeCompleteObjCImplementationCategory(Scope *S, IdentifierInfo *ClassName, SourceLocation ClassNameLoc)
void CodeCompletePreprocessorDirective(bool InConditional)
void CodeCompletePreprocessorExpression()
void CodeCompleteObjCForCollection(Scope *S, DeclGroupPtrTy IterationVar)
static QualType GetTypeFromParser(ParsedType Ty, TypeSourceInfo **TInfo=nullptr)
void MarkDeducedTemplateParameters(const FunctionTemplateDecl *FunctionTemplate, llvm::SmallBitVector &Deduced)
void CodeCompleteObjCSuperMessage(Scope *S, SourceLocation SuperLoc, ArrayRef< const IdentifierInfo * > SelIdents, bool AtArgumentExpression)
Encodes a location in the source.
This class handles loading and caching of source files into memory.
SourceLocation getSpellingLoc(SourceLocation Loc) const
Given a SourceLocation object, return the spelling location referenced by the ID.
bool isInSystemHeader(SourceLocation Loc) const
Returns if a SourceLocation is in a system header.
A trivial tuple used to represent a source range.
SwitchStmt - This represents a 'switch' stmt.
Represents the declaration of a struct/union/class/enum.
A convenient class for passing around template argument information.
Represents a template argument.
QualType getAsType() const
Retrieve the type for a type template argument.
@ Type
The template argument is a type.
ArgKind getKind() const
Return the kind of stored template argument.
The base class of all kinds of template declarations (e.g., class, function, etc.).
TemplateParameterList * getTemplateParameters() const
Get the list of template parameters.
Represents a C++ template name within the type system.
TemplateDecl * getAsTemplateDecl() const
Retrieve the underlying template declaration that this template name refers to, if known.
OverloadedTemplateStorage * getAsOverloadedTemplate() const
Retrieve the underlying, overloaded function template declarations that this template name refers to,...
Stores a list of template parameters for a TemplateDecl and its derived classes.
NamedDecl * getParam(unsigned Idx)
bool hasParameterPack() const
Determine whether this template parameter list contains a parameter pack.
ArrayRef< NamedDecl * > asArray()
Represents a type template specialization; the template must be a class template, a type alias templa...
TemplateTemplateParmDecl - Declares a template template parameter, e.g., "T" in.
bool hasDefaultArgument() const
Determine whether this template parameter has a default argument.
Declaration of a template type parameter.
TemplateTypeParmDecl * getDecl() const
The top declaration context.
Models the abbreviated syntax to constrain a template type parameter: template <convertible_to<string...
void print(llvm::raw_ostream &OS, const PrintingPolicy &Policy) const
Represents a declaration of a type.
Base wrapper for a particular "section" of type source info.
UnqualTypeLoc getUnqualifiedLoc() const
Skips past any qualifiers, if this is qualified.
QualType getType() const
Get the type for which this source info wrapper provides information.
T getAs() const
Convert to the specified TypeLoc type, returning a null TypeLoc if this TypeLoc is not of the desired...
TypeLoc IgnoreParens() const
T getAsAdjusted() const
Convert to the specified TypeLoc type, returning a null TypeLoc if this TypeLoc is not of the desired...
A container of type source information.
TypeLoc getTypeLoc() const
Return the TypeLoc wrapper for the type source info.
The base class of the type hierarchy.
CXXRecordDecl * getAsCXXRecordDecl() const
Retrieves the CXXRecordDecl that this type refers to, either because the type is a RecordType or beca...
bool isBlockPointerType() const
bool isBooleanType() const
const ObjCObjectPointerType * getAsObjCQualifiedIdType() const
bool isPointerType() const
CanQualType getCanonicalTypeUnqualified() const
bool isIntegerType() const
isIntegerType() does not include complex integers (a GCC extension).
const T * castAs() const
Member-template castAs<specific type>.
const ObjCObjectPointerType * getAsObjCInterfacePointerType() const
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee.
bool isIntegralOrEnumerationType() const
Determine whether this type is an integral or enumeration type.
bool isObjCObjectOrInterfaceType() const
bool isDependentType() const
Whether this type is a dependent type, meaning that its definition somehow depends on a template para...
bool isTemplateTypeParmType() const
bool isMemberPointerType() const
bool isObjCIdType() const
bool isObjCObjectType() const
const ArrayType * getAsArrayTypeUnsafe() const
A variant of getAs<> for array types which silently discards qualifiers from the outermost type.
bool isObjCObjectPointerType() const
bool isObjCQualifiedClassType() const
bool isObjCClassType() const
std::optional< ArrayRef< QualType > > getObjCSubstitutions(const DeclContext *dc) const
Retrieve the set of substitutions required when accessing a member of the Objective-C receiver type t...
TypeClass getTypeClass() const
const T * getAs() const
Member-template getAs<specific type>'.
bool isRecordType() const
RecordDecl * getAsRecordDecl() const
Retrieves the RecordDecl this type refers to.
Wrapper for source info for typedefs.
Represents a C++ unqualified-id that has been parsed.
void setIdentifier(const IdentifierInfo *Id, SourceLocation IdLoc)
Specify that this unqualified-id was parsed as an identifier.
void append(iterator I, iterator E)
A set of unresolved declarations.
Represents a shadow declaration implicitly introduced into a scope by a (resolved) using-declaration ...
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
Represents a C++11 virt-specifier-seq.
bool isOverrideSpecified() const
bool isFinalSpecified() const
Consumes visible declarations found when searching for all visible names within a given scope or cont...
A static requirement that can be used in a requires-expression to check properties of types and expre...
Retains information about a block that is currently being parsed.
QualType ReturnType
ReturnType - The target type of return statements in this context, or null if unknown.
SmallVector< SwitchInfo, 8 > SwitchStack
SwitchStack - This is the current set of active switch statements in the block.
CXCursorKind
Describes the kind of entity that a cursor refers to.
@ CXCursor_ObjCInterfaceDecl
An Objective-C @interface.
@ CXCursor_Namespace
A C++ namespace.
@ CXCursor_TypedefDecl
A typedef.
@ CXCursor_CXXAccessSpecifier
An access specifier.
@ CXCursor_EnumConstantDecl
An enumerator constant.
@ CXCursor_ConversionFunction
A C++ conversion function.
@ CXCursor_ConceptDecl
a concept declaration.
@ CXCursor_ClassTemplate
A C++ class template.
@ CXCursor_UnionDecl
A C or C++ union.
@ CXCursor_ObjCSynthesizeDecl
An Objective-C @synthesize definition.
@ CXCursor_ParmDecl
A function or method parameter.
@ CXCursor_FieldDecl
A field (in C) or non-static data member (in C++) in a struct, union, or C++ class.
@ CXCursor_CXXMethod
A C++ class method.
@ CXCursor_EnumDecl
An enumeration.
@ CXCursor_ObjCClassMethodDecl
An Objective-C class method.
@ CXCursor_TranslationUnit
Cursor that represents the translation unit itself.
@ CXCursor_ClassTemplatePartialSpecialization
A C++ class template partial specialization.
@ CXCursor_ObjCProtocolDecl
An Objective-C @protocol declaration.
@ CXCursor_FunctionTemplate
A C++ function template.
@ CXCursor_ObjCImplementationDecl
An Objective-C @implementation.
@ CXCursor_NonTypeTemplateParameter
A C++ non-type template parameter.
@ CXCursor_FunctionDecl
A function.
@ CXCursor_ObjCPropertyDecl
An Objective-C @property declaration.
@ CXCursor_Destructor
A C++ destructor.
@ CXCursor_ObjCIvarDecl
An Objective-C instance variable.
@ CXCursor_TypeAliasTemplateDecl
@ CXCursor_ObjCCategoryImplDecl
An Objective-C @implementation for a category.
@ CXCursor_ObjCDynamicDecl
An Objective-C @dynamic definition.
@ CXCursor_MacroDefinition
@ CXCursor_VarDecl
A variable.
@ CXCursor_TemplateTypeParameter
A C++ template type parameter.
@ CXCursor_TemplateTemplateParameter
A C++ template template parameter.
@ CXCursor_UnexposedDecl
A declaration whose specific kind is not exposed via this interface.
@ CXCursor_ObjCInstanceMethodDecl
An Objective-C instance method.
@ CXCursor_StructDecl
A C or C++ struct.
@ CXCursor_UsingDeclaration
A C++ using declaration.
@ CXCursor_LinkageSpec
A linkage specification, e.g.
@ CXCursor_ClassDecl
A C++ class.
@ CXCursor_ObjCCategoryDecl
An Objective-C @interface for a category.
@ CXCursor_StaticAssert
A static_assert or _Static_assert node.
@ CXCursor_ModuleImportDecl
A module import declaration.
@ CXCursor_MemberRef
A reference to a member of a struct, union, or class that occurs in some non-expression context,...
@ CXCursor_NamespaceAlias
A C++ namespace alias declaration.
@ CXCursor_Constructor
A C++ constructor.
@ CXCursor_FriendDecl
a friend declaration.
@ CXCursor_TypeAliasDecl
A C++ alias declaration.
@ CXCursor_UsingDirective
A C++ using directive.
@ CXAvailability_Available
The entity is available.
@ CXAvailability_Deprecated
The entity is available, but has been deprecated (and its use is not recommended).
@ CXAvailability_NotAvailable
The entity is not available; any use of it will be an error.
@ kind_nullability
Indicates that the nullability of the type was spelled with a property attribute rather than a type q...
QualType getFullyQualifiedType(QualType QT, const ASTContext &Ctx, bool WithGlobalNsPrefix=false)
Generates a QualType that can be used to name the same type if used at the end of the current transla...
const internal::VariadicAllOfMatcher< Type > type
Matches Types in the clang AST.
bool Add(InterpState &S, CodePtr OpPC)
TokenKind
Provides a simple uniform namespace for tokens from all C languages.
The JSON file list parser is used to communicate input to InstallAPI.
TypeSpecifierType
Specifies the kind of type.
@ OO_None
Not an overloaded operator.
@ NUM_OVERLOADED_OPERATORS
@ Specialization
We are substituting template parameters for template arguments in order to form a template specializa...
@ CCF_ExactTypeMatch
Divide by this factor when a code-completion result's type exactly matches the type we expect.
@ CCF_SimilarTypeMatch
Divide by this factor when a code-completion result's type is similar to the type we expect (e....
QualType getDeclUsageType(ASTContext &C, const NamedDecl *ND)
Determine the type that this declaration will have if it is used as a type or in an expression.
bool isReservedInAllContexts(ReservedIdentifierStatus Status)
Determine whether an identifier is reserved in all contexts.
@ Nullable
Values of this type can be null.
@ Unspecified
Whether values of this type can be null is (explicitly) unspecified.
@ NonNull
Values of this type can never be null.
CXCursorKind getCursorKindForDecl(const Decl *D)
Determine the libclang cursor kind associated with the given declaration.
RefQualifierKind
The kind of C++11 ref-qualifier associated with a function type.
@ RQ_None
No ref-qualifier was provided.
@ RQ_LValue
An lvalue ref-qualifier was provided (&).
@ RQ_RValue
An rvalue ref-qualifier was provided (&&).
const RawComment * getParameterComment(const ASTContext &Ctx, const CodeCompleteConsumer::OverloadCandidate &Result, unsigned ArgIndex)
Get the documentation comment used to produce CodeCompletionString::BriefComment for OverloadCandidat...
@ LCK_This
Capturing the *this object by reference.
@ IK_ConstructorName
A constructor name.
@ IK_DestructorName
A destructor name.
@ IK_OperatorFunctionId
An overloaded operator name, e.g., operator+.
@ Property
The type of a property.
@ Parameter
The parameter type of a method or function.
@ Result
The result type of a method or function.
SimplifiedTypeClass
A simplified classification of types used when determining "similar" types for code completion.
const RawComment * getPatternCompletionComment(const ASTContext &Ctx, const NamedDecl *Decl)
Get the documentation comment used to produce CodeCompletionString::BriefComment for RK_Pattern.
@ Interface
The "__interface" keyword.
@ Struct
The "struct" keyword.
@ Class
The "class" keyword.
@ Union
The "union" keyword.
@ Enum
The "enum" keyword.
LLVM_READONLY char toUppercase(char c)
Converts the given ASCII character to its uppercase equivalent.
const RawComment * getCompletionComment(const ASTContext &Ctx, const NamedDecl *Decl)
Get the documentation comment used to produce CodeCompletionString::BriefComment for RK_Declaration.
SimplifiedTypeClass getSimplifiedTypeClass(CanQualType T)
Determine the simplified type class of the given canonical type.
@ CCD_SelectorMatch
The selector of the given message exactly matches the selector of the current method,...
@ CCD_ObjectQualifierMatch
The result is a C++ non-static member function whose qualifiers exactly match the object type on whic...
@ CCD_bool_in_ObjC
Adjustment to the "bool" type in Objective-C, where the typedef "BOOL" is preferred.
@ CCD_InBaseClass
The result is in a base class.
@ CCD_ProbablyNotObjCCollection
Adjustment for KVC code pattern priorities when it doesn't look like the.
@ CCD_BlockPropertySetter
An Objective-C block property completed as a setter with a block placeholder.
@ CCD_MethodAsProperty
An Objective-C method being used as a property.
ExprValueKind
The categorization of expression values, currently following the C++11 scheme.
@ VK_XValue
An x-value expression is a reference to an object with independent storage but which can be "moved",...
@ VK_LValue
An l-value expression is a reference to an object with independent storage.
bool isBetterOverloadCandidate(Sema &S, const OverloadCandidate &Cand1, const OverloadCandidate &Cand2, SourceLocation Loc, OverloadCandidateSet::CandidateSetKind Kind)
isBetterOverloadCandidate - Determines whether the first overload candidate is a better candidate tha...
@ CCP_Type
Priority for a type.
@ CCP_ObjC_cmd
Priority for the Objective-C "_cmd" implicit parameter.
@ CCP_Macro
Priority for a preprocessor macro.
@ CCP_LocalDeclaration
Priority for a declaration that is in the local scope.
@ CCP_Unlikely
Priority for a result that isn't likely to be what the user wants, but is included for completeness.
@ CCP_NestedNameSpecifier
Priority for a nested-name-specifier.
@ CCP_SuperCompletion
Priority for a send-to-super completion.
@ CCP_NextInitializer
Priority for the next initialization in a constructor initializer list.
@ CCP_Declaration
Priority for a non-type declaration.
@ CCP_Constant
Priority for a constant value (e.g., enumerator).
@ CCP_MemberDeclaration
Priority for a member declaration found from the current method or member function.
@ CCP_EnumInCase
Priority for an enumeration constant inside a switch whose condition is of the enumeration type.
@ CCP_CodePattern
Priority for a code pattern.
const FunctionProtoType * T
unsigned getMacroUsagePriority(StringRef MacroName, const LangOptions &LangOpts, bool PreferredTypeIsPointer=false)
Determine the priority to be given to a macro code completion result with the given name.
bool shouldEnforceArgLimit(bool PartialOverloading, FunctionDecl *Function)
llvm::StringRef getAsString(SyncScope S)
@ TooManyArguments
When performing template argument deduction for a function template, there were too many call argumen...
@ TSK_Undeclared
This template specialization was formed from a template-id but has not yet been declared,...
std::pair< IdentifierInfo *, SourceLocation > IdentifierLocPair
A simple pair of identifier info and location.
@ Interface
The "__interface" keyword introduces the elaborated-type-specifier.
@ Class
The "class" keyword introduces the elaborated-type-specifier.
@ Enum
The "enum" keyword introduces the elaborated-type-specifier.
@ StartsWithDoubleUnderscore
__UINTPTR_TYPE__ uintptr_t
An unsigned integer type with the property that any valid pointer to void can be converted to this ty...
CodeCompleteExpressionData(QualType PreferredType=QualType(), bool IsParenthesized=false)
SmallVector< Decl *, 4 > IgnoreDecls
bool IntegralConstantExpression
unsigned NumParams
NumParams - This is the number of formal parameters specified by the declarator.
Represents a complete lambda introducer.
SmallVector< LambdaCapture, 4 > Captures
LambdaCaptureDefault Default
a linked list of methods with the same selector name but different signatures.
ObjCMethodDecl * getMethod() const
OverloadCandidate - A single candidate in an overload set (C++ 13.3).
static ArrayRef< const ParsedAttrInfo * > getAllBuiltin()
Describes how types, statements, expressions, and declarations should be printed.
unsigned SuppressUnwrittenScope
Suppress printing parts of scope specifiers that are never written, e.g., for anonymous namespaces.
unsigned AnonymousTagLocations
When printing an anonymous tag name, also print the location of that entity (e.g.,...
unsigned CleanUglifiedParameters
Whether to strip underscores when printing reserved parameter names.
unsigned SuppressStrongLifetime
When true, suppress printing of the __strong lifetime qualifier in ARC.
unsigned SuppressScope
Suppresses printing of scope specifiers.
unsigned SuppressTemplateArgsInCXXConstructors
When true, suppresses printing template arguments in names of C++ constructors.