44#include "llvm/ADT/ArrayRef.h"
45#include "llvm/ADT/DenseSet.h"
46#include "llvm/ADT/SmallBitVector.h"
47#include "llvm/ADT/SmallPtrSet.h"
48#include "llvm/ADT/SmallString.h"
49#include "llvm/ADT/StringExtras.h"
50#include "llvm/ADT/StringSwitch.h"
51#include "llvm/ADT/Twine.h"
52#include "llvm/ADT/iterator_range.h"
53#include "llvm/Support/Casting.h"
54#include "llvm/Support/Path.h"
55#include "llvm/Support/raw_ostream.h"
74 typedef bool (ResultBuilder::*LookupFilter)(
const NamedDecl *)
const;
80 std::vector<Result> Results;
87 typedef std::pair<const NamedDecl *, unsigned> DeclIndexPair;
92 class ShadowMapEntry {
97 llvm::PointerUnion<const NamedDecl *, DeclIndexPairVector *> DeclOrVector;
101 unsigned SingleDeclIndex = 0;
104 ShadowMapEntry() =
default;
105 ShadowMapEntry(
const ShadowMapEntry &) =
delete;
106 ShadowMapEntry(ShadowMapEntry &&Move) { *
this = std::move(Move); }
107 ShadowMapEntry &operator=(
const ShadowMapEntry &) =
delete;
108 ShadowMapEntry &operator=(ShadowMapEntry &&Move) {
109 SingleDeclIndex =
Move.SingleDeclIndex;
110 DeclOrVector =
Move.DeclOrVector;
111 Move.DeclOrVector =
nullptr;
116 if (DeclOrVector.isNull()) {
119 SingleDeclIndex = Index;
124 DeclOrVector.dyn_cast<
const NamedDecl *>()) {
127 DeclIndexPairVector *Vec =
new DeclIndexPairVector;
128 Vec->push_back(DeclIndexPair(PrevND, SingleDeclIndex));
133 DeclOrVector.get<DeclIndexPairVector *>()->push_back(
134 DeclIndexPair(ND, Index));
138 if (DeclIndexPairVector *Vec =
139 DeclOrVector.dyn_cast<DeclIndexPairVector *>()) {
147 iterator begin()
const;
148 iterator end()
const;
154 typedef llvm::DenseMap<DeclarationName, ShadowMapEntry> ShadowMap;
171 bool AllowNestedNameSpecifiers;
182 std::list<ShadowMap> ShadowMaps;
196 bool HasObjectTypeQualifiers;
208 void AdjustResultPriorityForDecl(Result &R);
210 void MaybeAddConstructorResults(Result R);
216 LookupFilter Filter =
nullptr)
217 : SemaRef(SemaRef), Allocator(Allocator), CCTUInfo(CCTUInfo),
219 HasObjectTypeQualifiers(
false), CompletionContext(CompletionContext),
220 ObjCImplementation(nullptr) {
223 switch (CompletionContext.
getKind()) {
231 if (Method->isInstanceMethod())
233 ObjCImplementation =
Interface->getImplementation();
242 unsigned getBasePriority(
const NamedDecl *D);
246 bool includeCodePatterns()
const {
252 void setFilter(LookupFilter Filter) { this->Filter =
Filter; }
254 Result *data() {
return Results.empty() ? nullptr : &Results.front(); }
255 unsigned size()
const {
return Results.size(); }
256 bool empty()
const {
return Results.empty(); }
271 ObjectTypeQualifiers = Quals;
273 HasObjectTypeQualifiers =
true;
281 void setPreferredSelector(
Selector Sel) { PreferredSelector = Sel; }
286 return CompletionContext;
290 void allowNestedNameSpecifiers(
bool Allow =
true) {
291 AllowNestedNameSpecifiers = Allow;
296 Sema &getSema()
const {
return SemaRef; }
310 bool isInterestingDecl(
const NamedDecl *ND,
311 bool &AsNestedNameSpecifier)
const;
336 bool CheckHiddenResult(Result &R,
DeclContext *CurContext,
346 void MaybeAddResult(Result R,
DeclContext *CurContext =
nullptr);
363 bool InBaseClass,
QualType BaseExprType);
366 void AddResult(Result R);
369 void EnterNewScope();
388 bool IsOrdinaryName(
const NamedDecl *ND)
const;
389 bool IsOrdinaryNonTypeName(
const NamedDecl *ND)
const;
390 bool IsIntegralConstantValue(
const NamedDecl *ND)
const;
391 bool IsOrdinaryNonValueName(
const NamedDecl *ND)
const;
392 bool IsNestedNameSpecifier(
const NamedDecl *ND)
const;
394 bool IsClassOrStruct(
const NamedDecl *ND)
const;
396 bool IsNamespace(
const NamedDecl *ND)
const;
397 bool IsNamespaceOrAlias(
const NamedDecl *ND)
const;
399 bool IsMember(
const NamedDecl *ND)
const;
400 bool IsObjCIvar(
const NamedDecl *ND)
const;
401 bool IsObjCMessageReceiver(
const NamedDecl *ND)
const;
402 bool IsObjCMessageReceiverOrLambdaCapture(
const NamedDecl *ND)
const;
403 bool IsObjCCollection(
const NamedDecl *ND)
const;
404 bool IsImpossibleToSatisfy(
const NamedDecl *ND)
const;
414 ComputeType =
nullptr;
415 Type = BSI->ReturnType;
419 ComputeType =
nullptr;
422 }
else if (
const auto *Method = dyn_cast<ObjCMethodDecl>(S.
CurContext)) {
423 ComputeType =
nullptr;
424 Type = Method->getReturnType();
432 auto *VD = llvm::dyn_cast_or_null<ValueDecl>(D);
433 ComputeType =
nullptr;
445 ComputeType =
nullptr;
454 this->ComputeType = ComputeType;
464 if (ExpectedLoc == LParLoc)
475 if (Op == tok::plus || Op == tok::plusequal || Op == tok::minusequal)
478 if (Op == tok::minus)
491 case tok::minusequal:
493 case tok::percentequal:
495 case tok::slashequal:
501 case tok::equalequal:
502 case tok::exclaimequal:
506 case tok::greaterequal:
510 case tok::greatergreater:
511 case tok::greatergreaterequal:
513 case tok::lesslessequal:
520 case tok::caretcaret:
527 case tok::caretequal:
535 case tok::periodstar:
563 case tok::minusminus:
573 assert(
false &&
"unhandled unary op");
582 ComputeType =
nullptr;
589 if (!Enabled || !
Base)
592 if (ExpectedLoc !=
Base->getBeginLoc())
603 ComputeType =
nullptr;
612 ComputeType =
nullptr;
621 ComputeType =
nullptr;
629 ComputeType =
nullptr;
635 llvm::PointerUnion<const NamedDecl *, const DeclIndexPair *> DeclOrIterator;
636 unsigned SingleDeclIndex;
656 : DeclOrIterator(SingleDecl), SingleDeclIndex(Index) {}
659 : DeclOrIterator(Iterator), SingleDeclIndex(0) {}
662 if (DeclOrIterator.is<
const NamedDecl *>()) {
668 const DeclIndexPair *I = DeclOrIterator.get<
const DeclIndexPair *>();
684 return *DeclOrIterator.get<
const DeclIndexPair *>();
690 return X.DeclOrIterator.getOpaqueValue() ==
691 Y.DeclOrIterator.getOpaqueValue() &&
692 X.SingleDeclIndex == Y.SingleDeclIndex;
701ResultBuilder::ShadowMapEntry::begin()
const {
702 if (DeclOrVector.isNull())
706 return iterator(ND, SingleDeclIndex);
708 return iterator(DeclOrVector.get<DeclIndexPairVector *>()->begin());
712ResultBuilder::ShadowMapEntry::end()
const {
713 if (DeclOrVector.is<
const NamedDecl *>() || DeclOrVector.isNull())
716 return iterator(DeclOrVector.get<DeclIndexPairVector *>()->end());
737 for (
const DeclContext *CommonAncestor = TargetContext;
738 CommonAncestor && !CommonAncestor->
Encloses(CurContext);
739 CommonAncestor = CommonAncestor->getLookupParent()) {
740 if (CommonAncestor->isTransparentContext() ||
741 CommonAncestor->isFunctionOrMethod())
744 TargetParents.push_back(CommonAncestor);
748 while (!TargetParents.empty()) {
751 if (
const auto *Namespace = dyn_cast<NamespaceDecl>(
Parent)) {
752 if (!Namespace->getIdentifier())
756 }
else if (
const auto *TD = dyn_cast<TagDecl>(
Parent))
787bool ResultBuilder::isInterestingDecl(
const NamedDecl *ND,
788 bool &AsNestedNameSpecifier)
const {
789 AsNestedNameSpecifier =
false;
804 if (isa<ClassTemplateSpecializationDecl>(ND) ||
805 isa<ClassTemplatePartialSpecializationDecl>(ND))
809 if (isa<UsingDecl>(ND))
815 if (Filter == &ResultBuilder::IsNestedNameSpecifier ||
816 (isa<NamespaceDecl>(ND) && Filter != &ResultBuilder::IsNamespace &&
817 Filter != &ResultBuilder::IsNamespaceOrAlias && Filter !=
nullptr))
818 AsNestedNameSpecifier =
true;
821 if (Filter && !(this->*Filter)(Named)) {
823 if (AllowNestedNameSpecifiers && SemaRef.
getLangOpts().CPlusPlus &&
824 IsNestedNameSpecifier(ND) &&
825 (Filter != &ResultBuilder::IsMember ||
826 (isa<CXXRecordDecl>(ND) &&
827 cast<CXXRecordDecl>(ND)->isInjectedClassName()))) {
828 AsNestedNameSpecifier =
true;
858 R.QualifierIsInformative =
false;
862 R.Declaration->getDeclContext());
869 switch (T->getTypeClass()) {
871 switch (cast<BuiltinType>(T)->
getKind()) {
872 case BuiltinType::Void:
875 case BuiltinType::NullPtr:
878 case BuiltinType::Overload:
879 case BuiltinType::Dependent:
882 case BuiltinType::ObjCId:
883 case BuiltinType::ObjCClass:
884 case BuiltinType::ObjCSel:
897 case Type::BlockPointer:
900 case Type::LValueReference:
901 case Type::RValueReference:
904 case Type::ConstantArray:
905 case Type::IncompleteArray:
906 case Type::VariableArray:
907 case Type::DependentSizedArray:
910 case Type::DependentSizedExtVector:
912 case Type::ExtVector:
915 case Type::FunctionProto:
916 case Type::FunctionNoProto:
925 case Type::ObjCObject:
926 case Type::ObjCInterface:
927 case Type::ObjCObjectPointer:
940 if (
const auto *
Type = dyn_cast<TypeDecl>(ND))
941 return C.getTypeDeclType(
Type);
942 if (
const auto *Iface = dyn_cast<ObjCInterfaceDecl>(ND))
943 return C.getObjCInterfaceType(Iface);
948 else if (
const auto *Method = dyn_cast<ObjCMethodDecl>(ND))
949 T = Method->getSendResultType();
950 else if (
const auto *Enumerator = dyn_cast<EnumConstantDecl>(ND))
951 T =
C.getTypeDeclType(cast<EnumDecl>(Enumerator->getDeclContext()));
952 else if (
const auto *
Property = dyn_cast<ObjCPropertyDecl>(ND))
954 else if (
const auto *
Value = dyn_cast<ValueDecl>(ND))
970 if (
Pointer->getPointeeType()->isFunctionType()) {
979 T =
Block->getPointeeType();
994unsigned ResultBuilder::getBasePriority(
const NamedDecl *ND) {
1002 if (
const auto *ImplicitParam = dyn_cast<ImplicitParamDecl>(ND))
1003 if (ImplicitParam->getIdentifier() &&
1004 ImplicitParam->getIdentifier()->isStr(
"_cmd"))
1011 if (DC->
isRecord() || isa<ObjCContainerDecl>(DC)) {
1013 if (isa<CXXDestructorDecl>(ND))
1025 if (isa<EnumConstantDecl>(ND))
1031 if ((isa<TypeDecl>(ND) || isa<ObjCInterfaceDecl>(ND)) &&
1033 CompletionContext.
getKind() ==
1035 CompletionContext.
getKind() ==
1042void ResultBuilder::AdjustResultPriorityForDecl(
Result &R) {
1045 if (!PreferredSelector.
isNull())
1046 if (
const auto *Method = dyn_cast<ObjCMethodDecl>(R.Declaration))
1047 if (PreferredSelector == Method->getSelector())
1052 if (!PreferredType.
isNull()) {
1062 !(PreferredType->isEnumeralType() && TC->isEnumeralType()))
1074 return Record->lookup(ConstructorName);
1077void ResultBuilder::MaybeAddConstructorResults(
Result R) {
1078 if (!SemaRef.
getLangOpts().CPlusPlus || !R.Declaration ||
1085 Record = ClassTemplate->getTemplatedDecl();
1086 else if ((
Record = dyn_cast<CXXRecordDecl>(D))) {
1088 if (isa<ClassTemplateSpecializationDecl>(
Record))
1100 R.Declaration = Ctor;
1102 Results.push_back(R);
1107 if (
const auto *Tmpl = dyn_cast<FunctionTemplateDecl>(ND))
1108 ND = Tmpl->getTemplatedDecl();
1109 return isa<CXXConstructorDecl>(ND);
1113 assert(!ShadowMaps.empty() &&
"Must enter into a results scope");
1115 if (R.Kind != Result::RK_Declaration) {
1117 Results.push_back(R);
1122 if (
const UsingShadowDecl *Using = dyn_cast<UsingShadowDecl>(R.Declaration)) {
1124 getBasePriority(
Using->getTargetDecl()),
1128 std::move(R.FixIts));
1130 MaybeAddResult(
Result, CurContext);
1137 bool AsNestedNameSpecifier =
false;
1138 if (!isInterestingDecl(R.Declaration, AsNestedNameSpecifier))
1145 ShadowMap &
SMap = ShadowMaps.back();
1146 ShadowMapEntry::iterator I, IEnd;
1147 ShadowMap::iterator NamePos =
SMap.find(R.Declaration->getDeclName());
1148 if (NamePos !=
SMap.end()) {
1149 I = NamePos->second.begin();
1150 IEnd = NamePos->second.end();
1153 for (; I != IEnd; ++I) {
1155 unsigned Index = I->second;
1158 Results[Index].Declaration = R.Declaration;
1168 std::list<ShadowMap>::iterator
SM, SMEnd = ShadowMaps.end();
1170 for (
SM = ShadowMaps.begin();
SM != SMEnd; ++
SM) {
1171 ShadowMapEntry::iterator I, IEnd;
1172 ShadowMap::iterator NamePos =
SM->find(R.Declaration->getDeclName());
1173 if (NamePos !=
SM->end()) {
1174 I = NamePos->second.begin();
1175 IEnd = NamePos->second.end();
1177 for (; I != IEnd; ++I) {
1179 if (I->first->hasTagIdentifierNamespace() &&
1187 I->first->getIdentifierNamespace() != IDNS)
1191 if (CheckHiddenResult(R, CurContext, I->first))
1199 if (!AllDeclsFound.insert(CanonDecl).second)
1204 if (AsNestedNameSpecifier) {
1205 R.StartsNestedNameSpecifier =
true;
1208 AdjustResultPriorityForDecl(R);
1211 if (R.QualifierIsInformative && !R.Qualifier &&
1212 !R.StartsNestedNameSpecifier) {
1213 const DeclContext *Ctx = R.Declaration->getDeclContext();
1214 if (
const NamespaceDecl *Namespace = dyn_cast<NamespaceDecl>(Ctx))
1217 else if (
const TagDecl *Tag = dyn_cast<TagDecl>(Ctx))
1219 SemaRef.
Context,
nullptr,
false,
1222 R.QualifierIsInformative =
false;
1227 SMap[R.Declaration->getDeclName()].Add(R.Declaration, Results.size());
1228 Results.push_back(R);
1230 if (!AsNestedNameSpecifier)
1231 MaybeAddConstructorResults(R);
1250 return OverloadCompare::BothViable;
1255 return OverloadCompare::BothViable;
1256 for (
unsigned I = 0, E = Candidate.
getNumParams(); I != E; ++I)
1257 if (Candidate.
parameters()[I]->getType().getCanonicalType() !=
1258 Incumbent.
parameters()[I]->getType().getCanonicalType())
1259 return OverloadCompare::BothViable;
1262 return OverloadCompare::BothViable;
1267 if (CandidateRef != IncumbentRef) {
1274 return CandidateRef ==
RQ_RValue ? OverloadCompare::Dominates
1275 : OverloadCompare::Dominated;
1283 if (CandidateSuperset == IncumbentSuperset)
1284 return OverloadCompare::BothViable;
1285 return IncumbentSuperset ? OverloadCompare::Dominates
1286 : OverloadCompare::Dominated;
1289bool ResultBuilder::canCxxMethodBeCalled(
const CXXMethodDecl *Method,
1295 const auto *CurrentClassScope = [&]() ->
const CXXRecordDecl * {
1297 const auto *CtxMethod = llvm::dyn_cast<CXXMethodDecl>(Ctx);
1298 if (CtxMethod && !CtxMethod->getParent()->isLambda()) {
1299 return CtxMethod->getParent();
1306 bool FunctionCanBeCall =
1307 CurrentClassScope &&
1308 (CurrentClassScope == Method->
getParent() ||
1312 if (FunctionCanBeCall)
1317 BaseExprType.
isNull() ?
nullptr
1321 MaybeDerived == MaybeBase || MaybeDerived->
isDerivedFrom(MaybeBase);
1324 return FunctionCanBeCall;
1327bool ResultBuilder::canFunctionBeCalled(
const NamedDecl *ND,
1338 if (
const auto *FuncTmpl = dyn_cast<FunctionTemplateDecl>(ND)) {
1339 ND = FuncTmpl->getTemplatedDecl();
1341 const auto *Method = dyn_cast<CXXMethodDecl>(ND);
1342 if (Method && !Method->
isStatic()) {
1343 return canCxxMethodBeCalled(Method, BaseExprType);
1350 NamedDecl *Hiding,
bool InBaseClass =
false,
1352 if (R.Kind != Result::RK_Declaration) {
1354 Results.push_back(R);
1359 if (
const auto *Using = dyn_cast<UsingShadowDecl>(R.Declaration)) {
1361 getBasePriority(
Using->getTargetDecl()),
1365 std::move(R.FixIts));
1367 AddResult(
Result, CurContext, Hiding,
false,
1372 bool AsNestedNameSpecifier =
false;
1373 if (!isInterestingDecl(R.Declaration, AsNestedNameSpecifier))
1380 if (Hiding && CheckHiddenResult(R, CurContext, Hiding))
1384 if (!AllDeclsFound.insert(R.Declaration->getCanonicalDecl()).second)
1389 if (AsNestedNameSpecifier) {
1390 R.StartsNestedNameSpecifier =
true;
1392 }
else if (Filter == &ResultBuilder::IsMember && !R.Qualifier &&
1395 R.Declaration->getDeclContext()->getRedeclContext()))
1396 R.QualifierIsInformative =
true;
1399 if (R.QualifierIsInformative && !R.Qualifier &&
1400 !R.StartsNestedNameSpecifier) {
1401 const DeclContext *Ctx = R.Declaration->getDeclContext();
1402 if (
const auto *Namespace = dyn_cast<NamespaceDecl>(Ctx))
1405 else if (
const auto *Tag = dyn_cast<TagDecl>(Ctx))
1407 SemaRef.
Context,
nullptr,
false,
1410 R.QualifierIsInformative =
false;
1417 AdjustResultPriorityForDecl(R);
1419 if (HasObjectTypeQualifiers)
1420 if (
const auto *Method = dyn_cast<CXXMethodDecl>(R.Declaration))
1423 if (ObjectTypeQualifiers == MethodQuals)
1425 else if (ObjectTypeQualifiers - MethodQuals) {
1447 auto &OverloadSet = OverloadMap[std::make_pair(
1449 for (
const DeclIndexPair Entry : OverloadSet) {
1450 Result &Incumbent = Results[Entry.second];
1452 *cast<CXXMethodDecl>(Incumbent.Declaration),
1453 ObjectTypeQualifiers, ObjectKind)) {
1454 case OverloadCompare::Dominates:
1458 Incumbent = std::move(R);
1460 case OverloadCompare::Dominated:
1463 case OverloadCompare::BothViable:
1467 OverloadSet.Add(Method, Results.size());
1470 R.FunctionCanBeCall = canFunctionBeCalled(R.getDeclaration(), BaseExprType);
1473 Results.push_back(R);
1475 if (!AsNestedNameSpecifier)
1476 MaybeAddConstructorResults(R);
1479void ResultBuilder::AddResult(
Result R) {
1480 assert(R.Kind != Result::RK_Declaration &&
1481 "Declaration results need more context");
1482 Results.push_back(R);
1486void ResultBuilder::EnterNewScope() { ShadowMaps.emplace_back(); }
1489void ResultBuilder::ExitScope() {
1490 ShadowMaps.pop_back();
1495bool ResultBuilder::IsOrdinaryName(
const NamedDecl *ND)
const {
1504 if (isa<ObjCIvarDecl>(ND))
1513bool ResultBuilder::IsOrdinaryNonTypeName(
const NamedDecl *ND)
const {
1515 if (isa<TypeDecl>(ND))
1520 if (
const auto *ID = dyn_cast<ObjCInterfaceDecl>(ND)) {
1521 if (!
ID->getDefinition())
1529 if (isa<ObjCIvarDecl>(ND))
1536bool ResultBuilder::IsIntegralConstantValue(
const NamedDecl *ND)
const {
1537 if (!IsOrdinaryNonTypeName(ND))
1541 if (VD->getType()->isIntegralOrEnumerationType())
1549bool ResultBuilder::IsOrdinaryNonValueName(
const NamedDecl *ND)
const {
1557 !isa<FunctionTemplateDecl>(ND) && !isa<ObjCPropertyDecl>(ND);
1562bool ResultBuilder::IsNestedNameSpecifier(
const NamedDecl *ND)
const {
1564 if (
const auto *ClassTemplate = dyn_cast<ClassTemplateDecl>(ND))
1565 ND = ClassTemplate->getTemplatedDecl();
1571bool ResultBuilder::IsEnum(
const NamedDecl *ND)
const {
1572 return isa<EnumDecl>(ND);
1576bool ResultBuilder::IsClassOrStruct(
const NamedDecl *ND)
const {
1578 if (
const auto *ClassTemplate = dyn_cast<ClassTemplateDecl>(ND))
1579 ND = ClassTemplate->getTemplatedDecl();
1582 if (
const auto *RD = dyn_cast<RecordDecl>(ND))
1591bool ResultBuilder::IsUnion(
const NamedDecl *ND)
const {
1593 if (
const auto *ClassTemplate = dyn_cast<ClassTemplateDecl>(ND))
1594 ND = ClassTemplate->getTemplatedDecl();
1596 if (
const auto *RD = dyn_cast<RecordDecl>(ND))
1603bool ResultBuilder::IsNamespace(
const NamedDecl *ND)
const {
1604 return isa<NamespaceDecl>(ND);
1609bool ResultBuilder::IsNamespaceOrAlias(
const NamedDecl *ND)
const {
1614bool ResultBuilder::IsType(
const NamedDecl *ND)
const {
1616 return isa<TypeDecl>(ND) || isa<ObjCInterfaceDecl>(ND);
1622bool ResultBuilder::IsMember(
const NamedDecl *ND)
const {
1624 return isa<ValueDecl>(ND) || isa<FunctionTemplateDecl>(ND) ||
1625 isa<ObjCPropertyDecl>(ND);
1629 T =
C.getCanonicalType(T);
1631 case Type::ObjCObject:
1632 case Type::ObjCInterface:
1633 case Type::ObjCObjectPointer:
1637 switch (cast<BuiltinType>(T)->
getKind()) {
1638 case BuiltinType::ObjCId:
1639 case BuiltinType::ObjCClass:
1640 case BuiltinType::ObjCSel:
1652 if (!
C.getLangOpts().CPlusPlus)
1661bool ResultBuilder::IsObjCMessageReceiver(
const NamedDecl *ND)
const {
1670bool ResultBuilder::IsObjCMessageReceiverOrLambdaCapture(
1672 if (IsObjCMessageReceiver(ND))
1675 const auto *Var = dyn_cast<VarDecl>(ND);
1679 return Var->hasLocalStorage() && !Var->hasAttr<BlocksAttr>();
1682bool ResultBuilder::IsObjCCollection(
const NamedDecl *ND)
const {
1683 if ((SemaRef.
getLangOpts().CPlusPlus && !IsOrdinaryName(ND)) ||
1684 (!SemaRef.
getLangOpts().CPlusPlus && !IsOrdinaryNonTypeName(ND)))
1697bool ResultBuilder::IsImpossibleToSatisfy(
const NamedDecl *ND)
const {
1703bool ResultBuilder::IsObjCIvar(
const NamedDecl *ND)
const {
1704 return isa<ObjCIvarDecl>(ND);
1712 ResultBuilder &Results;
1718 std::vector<FixItHint> FixIts;
1721 CodeCompletionDeclConsumer(
1722 ResultBuilder &Results,
DeclContext *InitialLookupCtx,
1724 std::vector<FixItHint> FixIts = std::vector<FixItHint>())
1725 : Results(Results), InitialLookupCtx(InitialLookupCtx),
1726 FixIts(
std::move(FixIts)) {
1727 NamingClass = llvm::dyn_cast<CXXRecordDecl>(InitialLookupCtx);
1730 auto ThisType = Results.getSema().getCurrentThisType();
1731 if (!ThisType.isNull()) {
1732 assert(ThisType->isPointerType());
1738 this->BaseType = BaseType;
1742 bool InBaseClass)
override {
1745 Results.AddResult(Result, InitialLookupCtx, Hiding, InBaseClass, BaseType);
1749 Results.addVisitedContext(Ctx);
1758 auto *NamingClass = this->NamingClass;
1759 QualType BaseType = this->BaseType;
1760 if (
auto *Cls = llvm::dyn_cast_or_null<CXXRecordDecl>(Ctx)) {
1775 NamingClass =
nullptr;
1778 return Results.getSema().IsSimplyAccessible(ND, NamingClass, BaseType);
1785 ResultBuilder &Results) {
1811 Results.getCodeCompletionTUInfo());
1812 if (LangOpts.CPlusPlus) {
1820 Builder.AddTypedTextChunk(
"typename");
1822 Builder.AddPlaceholderChunk(
"name");
1823 Results.AddResult(
Result(Builder.TakeString()));
1825 if (LangOpts.CPlusPlus11) {
1830 Builder.AddTypedTextChunk(
"decltype");
1832 Builder.AddPlaceholderChunk(
"expression");
1834 Results.AddResult(
Result(Builder.TakeString()));
1840 if (LangOpts.GNUKeywords) {
1846 Builder.AddTypedTextChunk(
"typeof");
1848 Builder.AddPlaceholderChunk(
"expression");
1849 Results.AddResult(
Result(Builder.TakeString()));
1851 Builder.AddTypedTextChunk(
"typeof");
1853 Builder.AddPlaceholderChunk(
"type");
1855 Results.AddResult(
Result(Builder.TakeString()));
1866 ResultBuilder &Results) {
1871 Results.AddResult(
Result(
"extern"));
1872 Results.AddResult(
Result(
"static"));
1874 if (LangOpts.CPlusPlus11) {
1879 Builder.AddTypedTextChunk(
"alignas");
1881 Builder.AddPlaceholderChunk(
"expression");
1883 Results.AddResult(
Result(Builder.TakeString()));
1885 Results.AddResult(
Result(
"constexpr"));
1886 Results.AddResult(
Result(
"thread_local"));
1892 ResultBuilder &Results) {
1897 if (LangOpts.CPlusPlus) {
1898 Results.AddResult(
Result(
"explicit"));
1899 Results.AddResult(
Result(
"friend"));
1900 Results.AddResult(
Result(
"mutable"));
1901 Results.AddResult(
Result(
"virtual"));
1909 if (LangOpts.CPlusPlus || LangOpts.C99)
1910 Results.AddResult(
Result(
"inline"));
1930 ResultBuilder &Results,
bool NeedAt);
1932 ResultBuilder &Results,
bool NeedAt);
1934 ResultBuilder &Results,
bool NeedAt);
1939 Results.getCodeCompletionTUInfo());
1940 Builder.AddTypedTextChunk(
"typedef");
1942 Builder.AddPlaceholderChunk(
"type");
1944 Builder.AddPlaceholderChunk(
"name");
1951 ResultBuilder &Results) {
1952 Builder.AddTypedTextChunk(
"using");
1954 Builder.AddPlaceholderChunk(
"name");
1956 Builder.AddPlaceholderChunk(
"type");
1979 return LangOpts.CPlusPlus;
1986 return LangOpts.CPlusPlus || LangOpts.ObjC || LangOpts.C99;
1989 llvm_unreachable(
"Invalid ParserCompletionContext!");
2018 if (
const BuiltinType *BT = dyn_cast<BuiltinType>(T))
2019 return BT->getNameAsCString(Policy);
2022 if (
const TagType *TagT = dyn_cast<TagType>(T))
2023 if (
TagDecl *Tag = TagT->getDecl())
2024 if (!Tag->hasNameForLinkage()) {
2025 switch (Tag->getTagKind()) {
2027 return "struct <anonymous>";
2029 return "__interface <anonymous>";
2031 return "class <anonymous>";
2033 return "union <anonymous>";
2035 return "enum <anonymous>";
2043 return Allocator.CopyString(
Result);
2055 Builder.AddResultTypeChunk(
2057 Builder.AddTypedTextChunk(
"this");
2062 ResultBuilder &Results,
2064 if (!LangOpts.CPlusPlus11)
2067 Builder.AddTypedTextChunk(
"static_assert");
2069 Builder.AddPlaceholderChunk(
"expression");
2071 Builder.AddPlaceholderChunk(
"message");
2080 Sema &S = Results.getSema();
2081 const auto *CR = llvm::dyn_cast<CXXRecordDecl>(S.
CurContext);
2087 llvm::StringMap<std::vector<FunctionDecl *>> Overrides;
2088 for (
auto *Method : CR->methods()) {
2091 Overrides[Method->
getName()].push_back(Method);
2094 for (
const auto &
Base : CR->bases()) {
2095 const auto *BR =
Base.getType().getTypePtr()->getAsCXXRecordDecl();
2098 for (
auto *Method : BR->methods()) {
2101 const auto it = Overrides.find(Method->
getName());
2102 bool IsOverriden =
false;
2103 if (it != Overrides.end()) {
2104 for (
auto *MD : it->second) {
2117 std::string OverrideSignature;
2118 llvm::raw_string_ostream OS(OverrideSignature);
2124 false, CCContext, Policy);
2133 Sema &SemaRef, ResultBuilder &Results) {
2141 if (Results.includeCodePatterns()) {
2143 Builder.AddTypedTextChunk(
"namespace");
2145 Builder.AddPlaceholderChunk(
"identifier");
2149 Builder.AddPlaceholderChunk(
"declarations");
2152 Results.AddResult(
Result(Builder.TakeString()));
2156 Builder.AddTypedTextChunk(
"namespace");
2158 Builder.AddPlaceholderChunk(
"name");
2160 Builder.AddPlaceholderChunk(
"namespace");
2162 Results.AddResult(
Result(Builder.TakeString()));
2165 Builder.AddTypedTextChunk(
"using namespace");
2167 Builder.AddPlaceholderChunk(
"identifier");
2169 Results.AddResult(
Result(Builder.TakeString()));
2172 Builder.AddTypedTextChunk(
"asm");
2174 Builder.AddPlaceholderChunk(
"string-literal");
2176 Results.AddResult(
Result(Builder.TakeString()));
2178 if (Results.includeCodePatterns()) {
2180 Builder.AddTypedTextChunk(
"template");
2182 Builder.AddPlaceholderChunk(
"declaration");
2183 Results.AddResult(
Result(Builder.TakeString()));
2198 Builder.AddTypedTextChunk(
"using");
2200 Builder.AddPlaceholderChunk(
"qualifier");
2201 Builder.AddTextChunk(
"::");
2202 Builder.AddPlaceholderChunk(
"name");
2204 Results.AddResult(
Result(Builder.TakeString()));
2211 Builder.AddTypedTextChunk(
"using typename");
2213 Builder.AddPlaceholderChunk(
"qualifier");
2214 Builder.AddTextChunk(
"::");
2215 Builder.AddPlaceholderChunk(
"name");
2217 Results.AddResult(
Result(Builder.TakeString()));
2225 bool IsNotInheritanceScope = !S->isClassInheritanceScope();
2227 Builder.AddTypedTextChunk(
"public");
2228 if (IsNotInheritanceScope && Results.includeCodePatterns())
2230 Results.AddResult(
Result(Builder.TakeString()));
2233 Builder.AddTypedTextChunk(
"protected");
2234 if (IsNotInheritanceScope && Results.includeCodePatterns())
2236 Results.AddResult(
Result(Builder.TakeString()));
2239 Builder.AddTypedTextChunk(
"private");
2240 if (IsNotInheritanceScope && Results.includeCodePatterns())
2242 Results.AddResult(
Result(Builder.TakeString()));
2255 if (SemaRef.
getLangOpts().CPlusPlus && Results.includeCodePatterns()) {
2257 Builder.AddTypedTextChunk(
"template");
2259 Builder.AddPlaceholderChunk(
"parameters");
2261 Results.AddResult(
Result(Builder.TakeString()));
2294 if (SemaRef.
getLangOpts().CPlusPlus && Results.includeCodePatterns() &&
2296 Builder.AddTypedTextChunk(
"try");
2300 Builder.AddPlaceholderChunk(
"statements");
2304 Builder.AddTextChunk(
"catch");
2307 Builder.AddPlaceholderChunk(
"declaration");
2312 Builder.AddPlaceholderChunk(
"statements");
2315 Results.AddResult(
Result(Builder.TakeString()));
2320 if (Results.includeCodePatterns()) {
2322 Builder.AddTypedTextChunk(
"if");
2326 Builder.AddPlaceholderChunk(
"condition");
2328 Builder.AddPlaceholderChunk(
"expression");
2333 Builder.AddPlaceholderChunk(
"statements");
2336 Results.AddResult(
Result(Builder.TakeString()));
2339 Builder.AddTypedTextChunk(
"switch");
2343 Builder.AddPlaceholderChunk(
"condition");
2345 Builder.AddPlaceholderChunk(
"expression");
2350 Builder.AddPlaceholderChunk(
"cases");
2353 Results.AddResult(
Result(Builder.TakeString()));
2360 Builder.AddTypedTextChunk(
"case");
2362 Builder.AddPlaceholderChunk(
"expression");
2364 Results.AddResult(
Result(Builder.TakeString()));
2367 Builder.AddTypedTextChunk(
"default");
2369 Results.AddResult(
Result(Builder.TakeString()));
2372 if (Results.includeCodePatterns()) {
2374 Builder.AddTypedTextChunk(
"while");
2378 Builder.AddPlaceholderChunk(
"condition");
2380 Builder.AddPlaceholderChunk(
"expression");
2385 Builder.AddPlaceholderChunk(
"statements");
2388 Results.AddResult(
Result(Builder.TakeString()));
2391 Builder.AddTypedTextChunk(
"do");
2395 Builder.AddPlaceholderChunk(
"statements");
2398 Builder.AddTextChunk(
"while");
2401 Builder.AddPlaceholderChunk(
"expression");
2403 Results.AddResult(
Result(Builder.TakeString()));
2406 Builder.AddTypedTextChunk(
"for");
2410 Builder.AddPlaceholderChunk(
"init-statement");
2412 Builder.AddPlaceholderChunk(
"init-expression");
2415 Builder.AddPlaceholderChunk(
"condition");
2418 Builder.AddPlaceholderChunk(
"inc-expression");
2423 Builder.AddPlaceholderChunk(
"statements");
2426 Results.AddResult(
Result(Builder.TakeString()));
2430 Builder.AddTypedTextChunk(
"for");
2433 Builder.AddPlaceholderChunk(
"range-declaration");
2436 Builder.AddTextChunk(
"in");
2440 Builder.AddPlaceholderChunk(
"range-expression");
2445 Builder.AddPlaceholderChunk(
"statements");
2448 Results.AddResult(
Result(Builder.TakeString()));
2452 if (S->getContinueParent()) {
2454 Builder.AddTypedTextChunk(
"continue");
2456 Results.AddResult(
Result(Builder.TakeString()));
2459 if (S->getBreakParent()) {
2461 Builder.AddTypedTextChunk(
"break");
2463 Results.AddResult(
Result(Builder.TakeString()));
2469 ReturnType =
Function->getReturnType();
2470 else if (
const auto *Method = dyn_cast<ObjCMethodDecl>(SemaRef.
CurContext))
2476 Builder.AddTypedTextChunk(
"return");
2478 Results.AddResult(
Result(Builder.TakeString()));
2480 assert(!ReturnType.
isNull());
2482 Builder.AddTypedTextChunk(
"return");
2484 Builder.AddPlaceholderChunk(
"expression");
2486 Results.AddResult(
Result(Builder.TakeString()));
2489 Builder.AddTypedTextChunk(
"return true");
2491 Results.AddResult(
Result(Builder.TakeString()));
2493 Builder.AddTypedTextChunk(
"return false");
2495 Results.AddResult(
Result(Builder.TakeString()));
2500 Builder.AddTypedTextChunk(
"return nullptr");
2502 Results.AddResult(
Result(Builder.TakeString()));
2507 Builder.AddTypedTextChunk(
"goto");
2509 Builder.AddPlaceholderChunk(
"label");
2511 Results.AddResult(
Result(Builder.TakeString()));
2514 Builder.AddTypedTextChunk(
"using namespace");
2516 Builder.AddPlaceholderChunk(
"identifier");
2518 Results.AddResult(
Result(Builder.TakeString()));
2535 Builder.AddTypedTextChunk(
"__bridge");
2537 Builder.AddPlaceholderChunk(
"type");
2539 Builder.AddPlaceholderChunk(
"expression");
2540 Results.AddResult(
Result(Builder.TakeString()));
2543 Builder.AddTypedTextChunk(
"__bridge_transfer");
2545 Builder.AddPlaceholderChunk(
"Objective-C type");
2547 Builder.AddPlaceholderChunk(
"expression");
2548 Results.AddResult(
Result(Builder.TakeString()));
2551 Builder.AddTypedTextChunk(
"__bridge_retained");
2553 Builder.AddPlaceholderChunk(
"CF type");
2555 Builder.AddPlaceholderChunk(
"expression");
2556 Results.AddResult(
Result(Builder.TakeString()));
2567 Builder.AddResultTypeChunk(
"bool");
2568 Builder.AddTypedTextChunk(
"true");
2569 Results.AddResult(
Result(Builder.TakeString()));
2572 Builder.AddResultTypeChunk(
"bool");
2573 Builder.AddTypedTextChunk(
"false");
2574 Results.AddResult(
Result(Builder.TakeString()));
2578 Builder.AddTypedTextChunk(
"dynamic_cast");
2580 Builder.AddPlaceholderChunk(
"type");
2583 Builder.AddPlaceholderChunk(
"expression");
2585 Results.AddResult(
Result(Builder.TakeString()));
2589 Builder.AddTypedTextChunk(
"static_cast");
2591 Builder.AddPlaceholderChunk(
"type");
2594 Builder.AddPlaceholderChunk(
"expression");
2596 Results.AddResult(
Result(Builder.TakeString()));
2599 Builder.AddTypedTextChunk(
"reinterpret_cast");
2601 Builder.AddPlaceholderChunk(
"type");
2604 Builder.AddPlaceholderChunk(
"expression");
2606 Results.AddResult(
Result(Builder.TakeString()));
2609 Builder.AddTypedTextChunk(
"const_cast");
2611 Builder.AddPlaceholderChunk(
"type");
2614 Builder.AddPlaceholderChunk(
"expression");
2616 Results.AddResult(
Result(Builder.TakeString()));
2620 Builder.AddResultTypeChunk(
"std::type_info");
2621 Builder.AddTypedTextChunk(
"typeid");
2623 Builder.AddPlaceholderChunk(
"expression-or-type");
2625 Results.AddResult(
Result(Builder.TakeString()));
2629 Builder.AddTypedTextChunk(
"new");
2631 Builder.AddPlaceholderChunk(
"type");
2633 Builder.AddPlaceholderChunk(
"expressions");
2635 Results.AddResult(
Result(Builder.TakeString()));
2638 Builder.AddTypedTextChunk(
"new");
2640 Builder.AddPlaceholderChunk(
"type");
2642 Builder.AddPlaceholderChunk(
"size");
2645 Builder.AddPlaceholderChunk(
"expressions");
2647 Results.AddResult(
Result(Builder.TakeString()));
2650 Builder.AddResultTypeChunk(
"void");
2651 Builder.AddTypedTextChunk(
"delete");
2653 Builder.AddPlaceholderChunk(
"expression");
2654 Results.AddResult(
Result(Builder.TakeString()));
2657 Builder.AddResultTypeChunk(
"void");
2658 Builder.AddTypedTextChunk(
"delete");
2663 Builder.AddPlaceholderChunk(
"expression");
2664 Results.AddResult(
Result(Builder.TakeString()));
2668 Builder.AddResultTypeChunk(
"void");
2669 Builder.AddTypedTextChunk(
"throw");
2671 Builder.AddPlaceholderChunk(
"expression");
2672 Results.AddResult(
Result(Builder.TakeString()));
2679 Builder.AddResultTypeChunk(
"std::nullptr_t");
2680 Builder.AddTypedTextChunk(
"nullptr");
2681 Results.AddResult(
Result(Builder.TakeString()));
2684 Builder.AddResultTypeChunk(
"size_t");
2685 Builder.AddTypedTextChunk(
"alignof");
2687 Builder.AddPlaceholderChunk(
"type");
2689 Results.AddResult(
Result(Builder.TakeString()));
2692 Builder.AddResultTypeChunk(
"bool");
2693 Builder.AddTypedTextChunk(
"noexcept");
2695 Builder.AddPlaceholderChunk(
"expression");
2697 Results.AddResult(
Result(Builder.TakeString()));
2700 Builder.AddResultTypeChunk(
"size_t");
2701 Builder.AddTypedTextChunk(
"sizeof...");
2703 Builder.AddPlaceholderChunk(
"parameter-pack");
2705 Results.AddResult(
Result(Builder.TakeString()));
2714 if (ID->getSuperClass()) {
2715 std::string SuperType;
2716 SuperType = ID->getSuperClass()->getNameAsString();
2717 if (Method->isInstanceMethod())
2720 Builder.AddResultTypeChunk(Allocator.CopyString(SuperType));
2721 Builder.AddTypedTextChunk(
"super");
2722 Results.AddResult(
Result(Builder.TakeString()));
2731 Builder.AddResultTypeChunk(
"size_t");
2733 Builder.AddTypedTextChunk(
"alignof");
2735 Builder.AddTypedTextChunk(
"_Alignof");
2737 Builder.AddPlaceholderChunk(
"type");
2739 Results.AddResult(
Result(Builder.TakeString()));
2744 Builder.AddResultTypeChunk(
"nullptr_t");
2745 Builder.AddTypedTextChunk(
"nullptr");
2746 Results.AddResult(
Result(Builder.TakeString()));
2750 Builder.AddResultTypeChunk(
"size_t");
2751 Builder.AddTypedTextChunk(
"sizeof");
2753 Builder.AddPlaceholderChunk(
"expression-or-type");
2755 Results.AddResult(
Result(Builder.TakeString()));
2768 Results.AddResult(
Result(
"operator"));
2789 else if (
const auto *Method = dyn_cast<ObjCMethodDecl>(ND)) {
2791 T = Method->getSendResultType(BaseType);
2794 }
else if (
const auto *Enumerator = dyn_cast<EnumConstantDecl>(ND)) {
2795 T = Context.
getTypeDeclType(cast<TypeDecl>(Enumerator->getDeclContext()));
2797 }
else if (isa<UnresolvedUsingValueDecl>(ND)) {
2799 }
else if (
const auto *Ivar = dyn_cast<ObjCIvarDecl>(ND)) {
2801 T = Ivar->getUsageType(BaseType);
2803 T = Ivar->getType();
2804 }
else if (
const auto *
Value = dyn_cast<ValueDecl>(ND)) {
2806 }
else if (
const auto *
Property = dyn_cast<ObjCPropertyDecl>(ND)) {
2808 T =
Property->getUsageType(BaseType);
2816 Result.AddResultTypeChunk(
2823 if (SentinelAttr *Sentinel = FunctionOrMethod->
getAttr<SentinelAttr>())
2824 if (Sentinel->getSentinel() == 0) {
2826 Result.AddTextChunk(
", nil");
2828 Result.AddTextChunk(
", NULL");
2830 Result.AddTextChunk(
", (void*)0");
2851 switch (*nullability) {
2861 Result +=
"null_unspecified ";
2865 llvm_unreachable(
"Not supported as a context-sensitive keyword!");
2882 bool SuppressBlock =
false) {
2888 if (!SuppressBlock) {
2891 TypedefTL.getTypedefNameDecl()->getTypeSourceInfo()) {
2904 TL = AttrTL.getModifiedLoc();
2923 bool SuppressBlockName =
false,
bool SuppressBlock =
false,
2928 bool SuppressName =
false,
bool SuppressBlock =
false,
2936 if (
const auto *PVD = dyn_cast<ParmVarDecl>(Param))
2937 ObjCQual = PVD->getObjCDeclQualifier();
2938 bool ObjCMethodParam = isa<ObjCMethodDecl>(Param->
getDeclContext());
2945 if (Param->
getIdentifier() && !ObjCMethodParam && !SuppressName)
2952 if (ObjCMethodParam) {
2971 if (!
Block && ObjCMethodParam &&
2972 cast<ObjCMethodDecl>(Param->
getDeclContext())->isPropertyAccessor()) {
2973 if (
const auto *PD = cast<ObjCMethodDecl>(Param->
getDeclContext())
2974 ->findPropertyDecl(
false))
2988 if (ObjCMethodParam) {
2993 if (
Result.back() !=
')')
3007 false, SuppressBlock,
3023 bool SuppressBlockName,
bool SuppressBlock,
3031 if (!ResultType->
isVoidType() || SuppressBlock)
3036 if (!BlockProto ||
Block.getNumParams() == 0) {
3043 for (
unsigned I = 0, N =
Block.getNumParams(); I != N; ++I) {
3056 if (SuppressBlock) {
3059 if (!SuppressBlockName &&
BlockDecl->getIdentifier())
3068 if (!SuppressBlockName &&
BlockDecl->getIdentifier())
3088 if (srcText.empty() || srcText ==
"=") {
3094 std::string DefValue(srcText.str());
3097 if (DefValue.at(0) !=
'=') {
3101 return " = " + DefValue;
3103 return " " + DefValue;
3112 bool InOptional =
false) {
3113 bool FirstParameter =
true;
3115 for (
unsigned P = Start, N =
Function->getNumParams();
P != N; ++
P) {
3122 Result.getCodeCompletionTUInfo());
3123 if (!FirstParameter)
3131 FirstParameter =
false;
3143 if (
Function->isVariadic() &&
P == N - 1)
3144 PlaceholderStr +=
", ...";
3147 Result.AddPlaceholderChunk(
3148 Result.getAllocator().CopyString(PlaceholderStr));
3152 if (Proto->isVariadic()) {
3153 if (Proto->getNumParams() == 0)
3154 Result.AddPlaceholderChunk(
"...");
3164 unsigned MaxParameters = 0,
unsigned Start = 0,
bool InDefaultArg =
false) {
3165 bool FirstParameter =
true;
3174 PEnd = Params->
begin() + MaxParameters;
3177 bool HasDefaultArg =
false;
3178 std::string PlaceholderStr;
3180 if (TTP->wasDeclaredWithTypename())
3181 PlaceholderStr =
"typename";
3182 else if (
const auto *TC = TTP->getTypeConstraint()) {
3183 llvm::raw_string_ostream OS(PlaceholderStr);
3184 TC->print(OS, Policy);
3187 PlaceholderStr =
"class";
3189 if (TTP->getIdentifier()) {
3190 PlaceholderStr +=
' ';
3191 PlaceholderStr += TTP->getIdentifier()->deuglifiedName();
3194 HasDefaultArg = TTP->hasDefaultArgument();
3196 dyn_cast<NonTypeTemplateParmDecl>(*
P)) {
3197 if (NTTP->getIdentifier())
3198 PlaceholderStr = std::string(NTTP->getIdentifier()->deuglifiedName());
3199 NTTP->getType().getAsStringInternal(PlaceholderStr, Policy);
3200 HasDefaultArg = NTTP->hasDefaultArgument();
3202 assert(isa<TemplateTemplateParmDecl>(*
P));
3207 PlaceholderStr =
"template<...> class";
3209 PlaceholderStr +=
' ';
3216 if (HasDefaultArg && !InDefaultArg) {
3220 Result.getCodeCompletionTUInfo());
3221 if (!FirstParameter)
3224 P - Params->
begin(),
true);
3229 InDefaultArg =
false;
3232 FirstParameter =
false;
3237 Result.AddPlaceholderChunk(
3238 Result.getAllocator().CopyString(PlaceholderStr));
3246 bool QualifierIsInformative,
3252 std::string PrintedNNS;
3254 llvm::raw_string_ostream OS(PrintedNNS);
3255 Qualifier->print(OS, Policy);
3257 if (QualifierIsInformative)
3258 Result.AddInformativeChunk(
Result.getAllocator().CopyString(PrintedNNS));
3260 Result.AddTextChunk(
Result.getAllocator().CopyString(PrintedNNS));
3267 if (!Proto || !Proto->getMethodQuals())
3273 if (Proto->getMethodQuals().hasOnlyConst()) {
3274 Result.AddInformativeChunk(
" const");
3278 if (Proto->getMethodQuals().hasOnlyVolatile()) {
3279 Result.AddInformativeChunk(
" volatile");
3283 if (Proto->getMethodQuals().hasOnlyRestrict()) {
3284 Result.AddInformativeChunk(
" restrict");
3289 std::string QualsStr;
3290 if (Proto->isConst())
3291 QualsStr +=
" const";
3292 if (Proto->isVolatile())
3293 QualsStr +=
" volatile";
3294 if (Proto->isRestrict())
3295 QualsStr +=
" restrict";
3296 Result.AddInformativeChunk(
Result.getAllocator().CopyString(QualsStr));
3307 switch (Name.getNameKind()) {
3309 const char *OperatorName =
nullptr;
3310 switch (Name.getCXXOverloadedOperator()) {
3312 case OO_Conditional:
3314 OperatorName =
"operator";
3317#define OVERLOADED_OPERATOR(Name, Spelling, Token, Unary, Binary, MemberOnly) \
3319 OperatorName = "operator" Spelling; \
3321#define OVERLOADED_OPERATOR_MULTI(Name, Spelling, Unary, Binary, MemberOnly)
3322#include "clang/Basic/OperatorKinds.def"
3325 OperatorName =
"operator new";
3328 OperatorName =
"operator delete";
3331 OperatorName =
"operator new[]";
3333 case OO_Array_Delete:
3334 OperatorName =
"operator delete[]";
3337 OperatorName =
"operator()";
3340 OperatorName =
"operator[]";
3343 Result.AddTypedTextChunk(OperatorName);
3351 Result.AddTypedTextChunk(
3364 QualType Ty = Name.getCXXNameType();
3366 Record = cast<CXXRecordDecl>(RecordTy->getDecl());
3368 Record = InjectedTy->getDecl();
3370 Result.AddTypedTextChunk(
3375 Result.AddTypedTextChunk(
3376 Result.getAllocator().CopyString(
Record->getNameAsString()));
3390 bool IncludeBriefComments) {
3392 CCTUInfo, IncludeBriefComments);
3404 return Result.TakeString();
3415 Result.AddPlaceholderChunk(
"...");
3429 Result.AddPlaceholderChunk(
Result.getAllocator().CopyString(Arg));
3434 Result.AddPlaceholderChunk(
3435 Result.getAllocator().CopyString((*A)->getName()));
3438 return Result.TakeString();
3450 bool IncludeBriefComments) {
3466 Result.addBriefComment(RC->getBriefText(Ctx));
3476 return Result.TakeString();
3480 PP, Ctx,
Result, IncludeBriefComments, CCContext, Policy);
3484 std::string &BeforeName,
3485 std::string &NameAndSignature) {
3486 bool SeenTypedChunk =
false;
3487 for (
auto &Chunk : CCS) {
3489 assert(SeenTypedChunk &&
"optional parameter before name");
3496 NameAndSignature += Chunk.Text;
3498 BeforeName += Chunk.Text;
3510 std::string BeforeName;
3511 std::string NameAndSignature;
3514 NameAndSignature +=
" override";
3516 Result.AddTextChunk(
Result.getAllocator().CopyString(BeforeName));
3518 Result.AddTypedTextChunk(
Result.getAllocator().CopyString(NameAndSignature));
3519 return Result.TakeString();
3525 const auto *VD = dyn_cast<VarDecl>(ND);
3528 const auto *
RecordDecl = VD->getType()->getAsCXXRecordDecl();
3541 if (IncludeBriefComments) {
3544 Result.addBriefComment(RC->getBriefText(Ctx));
3549 Result.AddTypedTextChunk(
3551 Result.AddTextChunk(
"::");
3552 return Result.TakeString();
3556 Result.AddAnnotation(
Result.getAllocator().CopyString(I->getAnnotation()));
3569 if (
const auto *
Function = dyn_cast<FunctionDecl>(ND)) {
3570 AddFunctionTypeAndResult(
Function);
3571 return Result.TakeString();
3574 if (
const auto *CallOperator =
3576 AddFunctionTypeAndResult(CallOperator);
3577 return Result.TakeString();
3583 dyn_cast<FunctionTemplateDecl>(ND)) {
3594 llvm::SmallBitVector Deduced(FunTmpl->getTemplateParameters()->size());
3599 unsigned LastDeducibleArgument;
3600 for (LastDeducibleArgument = Deduced.size(); LastDeducibleArgument > 0;
3601 --LastDeducibleArgument) {
3602 if (!Deduced[LastDeducibleArgument - 1]) {
3606 bool HasDefaultArg =
false;
3607 NamedDecl *Param = FunTmpl->getTemplateParameters()->getParam(
3608 LastDeducibleArgument - 1);
3610 HasDefaultArg = TTP->hasDefaultArgument();
3612 dyn_cast<NonTypeTemplateParmDecl>(Param))
3613 HasDefaultArg = NTTP->hasDefaultArgument();
3615 assert(isa<TemplateTemplateParmDecl>(Param));
3617 cast<TemplateTemplateParmDecl>(Param)->hasDefaultArgument();
3640 LastDeducibleArgument);
3649 return Result.TakeString();
3652 if (
const auto *Template = dyn_cast<TemplateDecl>(ND)) {
3655 Result.AddTypedTextChunk(
3656 Result.getAllocator().CopyString(Template->getNameAsString()));
3660 return Result.TakeString();
3663 if (
const auto *Method = dyn_cast<ObjCMethodDecl>(ND)) {
3664 Selector Sel = Method->getSelector();
3666 Result.AddTypedTextChunk(
3668 return Result.TakeString();
3674 Result.AddTypedTextChunk(
Result.getAllocator().CopyString(SelName));
3676 Result.AddInformativeChunk(
Result.getAllocator().CopyString(SelName));
3681 Result.AddTypedTextChunk(
"");
3688 P != PEnd && Idx < Sel.
getNumArgs(); (
void)++
P, ++Idx) {
3707 QualType ParamType = (*P)->getType();
3708 std::optional<ArrayRef<QualType>> ObjCSubsts;
3724 Arg += II->getName();
3731 Result.AddTextChunk(
Result.getAllocator().CopyString(Arg));
3733 Result.AddInformativeChunk(
Result.getAllocator().CopyString(Arg));
3735 Result.AddPlaceholderChunk(
Result.getAllocator().CopyString(Arg));
3741 Result.AddTextChunk(
", ...");
3743 Result.AddInformativeChunk(
", ...");
3745 Result.AddPlaceholderChunk(
", ...");
3751 return Result.TakeString();
3758 Result.AddTypedTextChunk(
3760 return Result.TakeString();
3771 const auto *M = dyn_cast<ObjCMethodDecl>(ND);
3783 const auto *M = dyn_cast_or_null<ObjCMethodDecl>(ND);
3784 if (!M || !M->isPropertyAccessor())
3807 auto FDecl =
Result.getFunction();
3810 if (ArgIndex < FDecl->getNumParams())
3818 unsigned CurrentArg) {
3819 unsigned ChunkIndex = 0;
3820 auto AddChunk = [&](llvm::StringRef Placeholder) {
3823 const char *
Copy =
Result.getAllocator().CopyString(Placeholder);
3824 if (ChunkIndex == CurrentArg)
3832 if (
auto *CRD = llvm::dyn_cast<CXXRecordDecl>(RD)) {
3833 for (
const auto &
Base : CRD->bases())
3834 AddChunk(
Base.getType().getAsString(Policy));
3836 for (
const auto &Field : RD->
fields())
3846 unsigned CurrentArg,
unsigned Start = 0,
bool InOptional =
false) {
3852 bool FirstParameter =
true;
3853 unsigned NumParams =
3856 for (
unsigned P = Start;
P != NumParams; ++
P) {
3861 Result.getCodeCompletionTUInfo());
3862 if (!FirstParameter)
3866 PrototypeLoc, Opt, CurrentArg,
P,
3873 FirstParameter =
false;
3880 std::string Placeholder;
3881 assert(P < Prototype->getNumParams());
3890 Placeholder =
Prototype->getParamType(
P).getAsString(Policy);
3893 if (
P == CurrentArg)
3894 Result.AddCurrentParameterChunk(
3895 Result.getAllocator().CopyString(Placeholder));
3897 Result.AddPlaceholderChunk(
Result.getAllocator().CopyString(Placeholder));
3902 Result.getCodeCompletionTUInfo());
3903 if (!FirstParameter)
3906 if (CurrentArg < NumParams)
3918 if (
const auto *
Type = dyn_cast<TemplateTypeParmDecl>(Param)) {
3920 }
else if (
const auto *NonType = dyn_cast<NonTypeTemplateParmDecl>(Param)) {
3921 Optional = NonType->hasDefaultArgument();
3922 }
else if (
const auto *Template = dyn_cast<TemplateTemplateParmDecl>(Param)) {
3923 Optional = Template->hasDefaultArgument();
3926 llvm::raw_string_ostream OS(
Result);
3927 Param->
print(OS, Policy);
3933 if (
const auto *CTD = dyn_cast<ClassTemplateDecl>(TD))
3934 return CTD->getTemplatedDecl()->getKindName().str();
3935 if (
const auto *VTD = dyn_cast<VarTemplateDecl>(TD))
3936 return VTD->getTemplatedDecl()->getType().getAsString(Policy);
3937 if (
const auto *FTD = dyn_cast<FunctionTemplateDecl>(TD))
3938 return FTD->getTemplatedDecl()->getReturnType().getAsString(Policy);
3939 if (isa<TypeAliasTemplateDecl>(TD))
3941 if (isa<TemplateTemplateParmDecl>(TD))
3943 if (isa<ConceptDecl>(TD))
3953 Builder.getCodeCompletionTUInfo());
3955 if (!ResultType.empty())
3956 Builder.AddResultTypeChunk(Builder.getAllocator().CopyString(ResultType));
3957 Builder.AddTextChunk(
3963 for (
unsigned I = 0; I < Params.size(); ++I) {
3965 std::string Placeholder =
3968 Current = &OptionalBuilder;
3971 Current->AddChunk(I == CurrentArg
3974 Current->getAllocator().CopyString(Placeholder));
3977 if (Current == &OptionalBuilder)
3978 Builder.AddOptionalChunk(OptionalBuilder.
TakeString());
3982 if (isa<FunctionTemplateDecl>(TD))
3983 Builder.AddInformativeChunk(
"()");
3984 return Builder.TakeString();
3991 bool Braced)
const {
4015 if (IncludeBriefComments) {
4022 llvm::raw_string_ostream OS(Name);
4024 Result.AddTextChunk(
Result.getAllocator().CopyString(OS.str()));
4027 Result.AddResultTypeChunk(
Result.getAllocator().CopyString(
4042 return Result.TakeString();
4047 bool PreferredTypeIsPointer) {
4051 if (MacroName.equals(
"nil") || MacroName.equals(
"NULL") ||
4052 MacroName.equals(
"Nil")) {
4054 if (PreferredTypeIsPointer)
4058 else if (MacroName.equals(
"YES") || MacroName.equals(
"NO") ||
4059 MacroName.equals(
"true") || MacroName.equals(
"false"))
4062 else if (MacroName.equals(
"bool"))
4075 case Decl::EnumConstant:
4079 case Decl::Function:
4081 case Decl::ObjCCategory:
4083 case Decl::ObjCCategoryImpl:
4085 case Decl::ObjCImplementation:
4088 case Decl::ObjCInterface:
4090 case Decl::ObjCIvar:
4092 case Decl::ObjCMethod:
4093 return cast<ObjCMethodDecl>(D)->isInstanceMethod()
4096 case Decl::CXXMethod:
4098 case Decl::CXXConstructor:
4100 case Decl::CXXDestructor:
4102 case Decl::CXXConversion:
4104 case Decl::ObjCProperty:
4106 case Decl::ObjCProtocol:
4112 case Decl::TypeAlias:
4114 case Decl::TypeAliasTemplate:
4118 case Decl::Namespace:
4120 case Decl::NamespaceAlias:
4122 case Decl::TemplateTypeParm:
4124 case Decl::NonTypeTemplateParm:
4126 case Decl::TemplateTemplateParm:
4128 case Decl::FunctionTemplate:
4130 case Decl::ClassTemplate:
4132 case Decl::AccessSpec:
4134 case Decl::ClassTemplatePartialSpecialization:
4136 case Decl::UsingDirective:
4138 case Decl::StaticAssert:
4142 case Decl::TranslationUnit:
4146 case Decl::UnresolvedUsingValue:
4147 case Decl::UnresolvedUsingTypename:
4150 case Decl::UsingEnum:
4153 case Decl::ObjCPropertyImpl:
4154 switch (cast<ObjCPropertyImplDecl>(D)->getPropertyImplementation()) {
4161 llvm_unreachable(
"Unexpected Kind!");
4166 case Decl::ObjCTypeParam:
4172 case Decl::LinkageSpec:
4176 if (
const auto *TD = dyn_cast<TagDecl>(D)) {
4177 switch (TD->getTagKind()) {
4195 bool LoadExternal,
bool IncludeUndefined,
4196 bool TargetTypeIsPointer =
false) {
4199 Results.EnterNewScope();
4205 if (IncludeUndefined || MD) {
4213 TargetTypeIsPointer)));
4217 Results.ExitScope();
4221 ResultBuilder &Results) {
4224 Results.EnterNewScope();
4228 if (LangOpts.C99 || LangOpts.CPlusPlus11)
4230 Results.ExitScope();
4237 unsigned NumResults) {
4299 llvm_unreachable(
"Invalid ParserCompletionContext!");
4311 ResultBuilder &Results) {
4314 while (isa<BlockDecl>(CurContext))
4317 CXXMethodDecl *Method = dyn_cast<CXXMethodDecl>(CurContext);
4324 if (!
P->getDeclName())
4330 Results.getCodeCompletionTUInfo());
4337 S.
Context, CurContext, Overridden->getDeclContext());
4340 llvm::raw_string_ostream OS(Str);
4341 NNS->
print(OS, Policy);
4342 Builder.AddTextChunk(Results.getAllocator().CopyString(OS.str()));
4344 }
else if (!InContext->
Equals(Overridden->getDeclContext()))
4347 Builder.AddTypedTextChunk(
4348 Results.getAllocator().CopyString(Overridden->getNameAsString()));
4350 bool FirstParam =
true;
4357 Builder.AddPlaceholderChunk(
4358 Results.getAllocator().CopyString(
P->getIdentifier()->getName()));
4364 Results.Ignore(Overridden);
4371 ResultBuilder Results(*
this, CodeCompleter->getAllocator(),
4372 CodeCompleter->getCodeCompletionTUInfo(),
4374 Results.EnterNewScope();
4382 PP.getHeaderSearchInfo().collectAllModules(Modules);
4383 for (
unsigned I = 0, N = Modules.size(); I != N; ++I) {
4384 Builder.AddTypedTextChunk(
4385 Builder.getAllocator().CopyString(Modules[I]->Name));
4386 Results.AddResult(
Result(
4391 }
else if (getLangOpts().Modules) {
4399 Builder.AddTypedTextChunk(
4400 Builder.getAllocator().CopyString(Submodule->Name));
4401 Results.AddResult(
Result(
4408 Results.ExitScope();
4410 Results.data(), Results.size());
4415 ResultBuilder Results(*
this, CodeCompleter->getAllocator(),
4416 CodeCompleter->getCodeCompletionTUInfo(),
4418 Results.EnterNewScope();
4423 switch (CompletionContext) {
4426 case PCC_ObjCInterface:
4427 case PCC_ObjCImplementation:
4428 case PCC_ObjCInstanceVariableList:
4430 case PCC_MemberTemplate:
4432 case PCC_LocalDeclarationSpecifiers:
4433 Results.setFilter(&ResultBuilder::IsOrdinaryNonValueName);
4437 case PCC_TopLevelOrExpression:
4438 case PCC_ParenthesizedExpression:
4439 case PCC_Expression:
4443 Results.setFilter(&ResultBuilder::IsOrdinaryName);
4445 Results.setFilter(&ResultBuilder::IsOrdinaryNonTypeName);
4451 case PCC_RecoveryInFunction:
4458 auto ThisType = getCurrentThisType();
4459 if (!ThisType.isNull())
4460 Results.setObjectTypeQualifiers(ThisType->getPointeeType().getQualifiers(),
4463 CodeCompletionDeclConsumer Consumer(Results, CurContext);
4464 LookupVisibleDecls(S, LookupOrdinaryName, Consumer,
4465 CodeCompleter->includeGlobals(),
4466 CodeCompleter->loadExternal());
4469 Results.ExitScope();
4471 switch (CompletionContext) {
4472 case PCC_ParenthesizedExpression:
4473 case PCC_Expression:
4475 case PCC_TopLevelOrExpression:
4476 case PCC_RecoveryInFunction:
4477 if (S->getFnParent())
4483 case PCC_ObjCInterface:
4484 case PCC_ObjCImplementation:
4485 case PCC_ObjCInstanceVariableList:
4487 case PCC_MemberTemplate:
4491 case PCC_LocalDeclarationSpecifiers:
4495 if (CodeCompleter->includeMacros())
4499 Results.data(), Results.size());
4505 bool AtArgumentExpression,
bool IsSuper,
4506 ResultBuilder &Results);
4509 bool AllowNonIdentifiers,
4510 bool AllowNestedNameSpecifiers) {
4512 ResultBuilder Results(
4513 *
this, CodeCompleter->getAllocator(),
4514 CodeCompleter->getCodeCompletionTUInfo(),
4515 AllowNestedNameSpecifiers
4520 Results.EnterNewScope();
4523 Results.AddResult(
Result(
"const"));
4524 Results.AddResult(
Result(
"volatile"));
4525 if (getLangOpts().
C99)
4526 Results.AddResult(
Result(
"restrict"));
4532 Results.AddResult(
"final");
4534 if (AllowNonIdentifiers) {
4535 Results.AddResult(
Result(
"operator"));
4539 if (AllowNestedNameSpecifiers) {
4540 Results.allowNestedNameSpecifiers();
4541 Results.setFilter(&ResultBuilder::IsImpossibleToSatisfy);
4542 CodeCompletionDeclConsumer Consumer(Results, CurContext);
4543 LookupVisibleDecls(S, LookupNestedNameSpecifierName, Consumer,
4544 CodeCompleter->includeGlobals(),
4545 CodeCompleter->loadExternal());
4546 Results.setFilter(
nullptr);
4549 Results.ExitScope();
4555 if (AllowNonIdentifiers && !AllowNestedNameSpecifiers &&
4575 Results.data(), Results.size());
4579 if (
Scope ==
"clang")
4587 if (
Scope ==
"_Clang")
4589 if (
Scope ==
"__gnu__")
4597 if (Completion == AttributeCompletion::None)
4599 ResultBuilder Results(*
this, CodeCompleter->getAllocator(),
4600 CodeCompleter->getCodeCompletionTUInfo(),
4613 llvm::StringRef InScopeName;
4614 bool InScopeUnderscore =
false;
4616 InScopeName = InScope->
getName();
4618 InScopeName = NoUnderscore;
4619 InScopeUnderscore =
true;
4628 if (A.IsTargetSpecific && !A.existsInTarget(Context.
getTargetInfo()))
4630 if (!A.acceptsLangOpts(getLangOpts()))
4632 for (
const auto &S : A.Spellings) {
4633 if (S.Syntax != Syntax)
4635 llvm::StringRef Name = S.NormalizedFullName;
4636 llvm::StringRef
Scope;
4639 std::tie(
Scope, Name) = Name.split(
"::");
4641 std::swap(Name,
Scope);
4645 if (Completion == AttributeCompletion::Scope) {
4647 if (!
Scope.empty() && FoundScopes.insert(
Scope).second) {
4658 if (!InScopeName.empty()) {
4659 if (
Scope != InScopeName)
4664 auto Add = [&](llvm::StringRef
Scope, llvm::StringRef Name,
4667 Results.getCodeCompletionTUInfo());
4669 if (!
Scope.empty()) {
4678 Builder.AddTypedTextChunk(Results.getAllocator().CopyString(
Text));
4680 if (!A.ArgNames.empty()) {
4683 for (
const char *Arg : A.ArgNames) {
4687 Builder.AddPlaceholderChunk(Arg);
4692 Results.AddResult(Builder.TakeString());
4699 if (!InScopeUnderscore)
4700 Add(
Scope, Name,
false);
4705 if (!(InScope && !InScopeUnderscore) && SyntaxSupportsGuards) {
4707 if (
Scope.empty()) {
4708 Add(
Scope, Name,
true);
4713 Add(GuardedScope, Name,
true);
4723 for (
const auto &Entry : ParsedAttrInfoRegistry::entries())
4724 AddCompletions(*Entry.instantiate());
4727 Results.data(), Results.size());
4732 bool IsParenthesized =
false)
4733 : PreferredType(PreferredType), IntegralConstantExpression(
false),
4734 ObjCCollection(
false), IsParenthesized(IsParenthesized) {}
4745struct CoveredEnumerators {
4753 const CoveredEnumerators &Enumerators) {
4755 if (Context.
getLangOpts().CPlusPlus && !Qualifier && Enumerators.Seen.empty()) {
4762 Results.EnterNewScope();
4763 for (
auto *E :
Enum->enumerators()) {
4764 if (Enumerators.Seen.count(E))
4768 Results.AddResult(R, CurContext,
nullptr,
false);
4770 Results.ExitScope();
4799 if (!Results.includeCodePatterns())
4802 Results.getCodeCompletionTUInfo());
4807 if (!Parameters.empty()) {
4816 constexpr llvm::StringLiteral NamePlaceholder =
"!#!NAME_GOES_HERE!#!";
4817 std::string
Type = std::string(NamePlaceholder);
4819 llvm::StringRef Prefix, Suffix;
4820 std::tie(Prefix, Suffix) = llvm::StringRef(
Type).split(NamePlaceholder);
4821 Prefix = Prefix.rtrim();
4822 Suffix = Suffix.ltrim();
4845 ResultBuilder Results(
4846 *
this, CodeCompleter->getAllocator(),
4847 CodeCompleter->getCodeCompletionTUInfo(),
4849 Data.IsParenthesized
4852 Data.PreferredType));
4854 Data.IsParenthesized ? PCC_ParenthesizedExpression : PCC_Expression;
4855 if (
Data.ObjCCollection)
4856 Results.setFilter(&ResultBuilder::IsObjCCollection);
4857 else if (
Data.IntegralConstantExpression)
4858 Results.setFilter(&ResultBuilder::IsIntegralConstantValue);
4860 Results.setFilter(&ResultBuilder::IsOrdinaryName);
4862 Results.setFilter(&ResultBuilder::IsOrdinaryNonTypeName);
4864 if (!
Data.PreferredType.isNull())
4865 Results.setPreferredType(
Data.PreferredType.getNonReferenceType());
4868 for (
unsigned I = 0, N =
Data.IgnoreDecls.size(); I != N; ++I)
4869 Results.Ignore(
Data.IgnoreDecls[I]);
4871 CodeCompletionDeclConsumer Consumer(Results, CurContext);
4872 LookupVisibleDecls(S, LookupOrdinaryName, Consumer,
4873 CodeCompleter->includeGlobals(),
4874 CodeCompleter->loadExternal());
4876 Results.EnterNewScope();
4878 Results.ExitScope();
4880 bool PreferredTypeIsPointer =
false;
4881 if (!
Data.PreferredType.isNull()) {
4882 PreferredTypeIsPointer =
Data.PreferredType->isAnyPointerType() ||
4883 Data.PreferredType->isMemberPointerType() ||
4884 Data.PreferredType->isBlockPointerType();
4885 if (
Data.PreferredType->isEnumeralType()) {
4887 if (
auto *Def =
Enum->getDefinition())
4895 if (S->getFnParent() && !
Data.ObjCCollection &&
4896 !
Data.IntegralConstantExpression)
4899 if (CodeCompleter->includeMacros())
4901 PreferredTypeIsPointer);
4911 Results.data(), Results.size());
4915 bool IsParenthesized) {
4916 return CodeCompleteExpression(
4923 CodeCompleteExpression(S, PreferredType);
4924 else if (getLangOpts().
ObjC)
4925 CodeCompleteObjCInstanceMessage(S, E.
get(), std::nullopt,
false);
4942 if (Protocol->hasDefinition())
4943 return Protocol->getDefinition();
4957 Builder.AddResultTypeChunk(
4959 Policy, Builder.getAllocator()));
4965 Builder.AddPlaceholderChunk(
"...");
4967 for (
unsigned I = 0, N = BlockLoc.
getNumParams(); I != N; ++I) {
4972 std::string PlaceholderStr =
4975 if (I == N - 1 && BlockProtoLoc &&
4977 PlaceholderStr +=
", ...";
4980 Builder.AddPlaceholderChunk(
4981 Builder.getAllocator().CopyString(PlaceholderStr));
4991 bool AllowNullaryMethods,
DeclContext *CurContext,
4993 bool IsBaseExprStatement =
false,
4994 bool IsClassProperty =
false,
bool InOriginalClass =
true) {
5002 if (!AddedProperties.insert(
P->getIdentifier()).second)
5007 if (!
P->getType().getTypePtr()->isBlockPointerType() ||
5008 !IsBaseExprStatement) {
5010 if (!InOriginalClass)
5012 Results.MaybeAddResult(R, CurContext);
5024 if (!InOriginalClass)
5026 Results.MaybeAddResult(R, CurContext);
5033 Results.getCodeCompletionTUInfo());
5036 BlockLoc, BlockProtoLoc);
5037 Result R =
Result(Builder.TakeString(),
P, Results.getBasePriority(
P));
5038 if (!InOriginalClass)
5040 Results.MaybeAddResult(R, CurContext);
5044 if (!
P->isReadOnly()) {
5046 Results.getCodeCompletionTUInfo());
5050 Builder.AddTypedTextChunk(
5051 Results.getAllocator().CopyString(
P->getName()));
5056 BlockProtoLoc,
true);
5058 Builder.AddPlaceholderChunk(
5059 Builder.getAllocator().CopyString(PlaceholderStr));
5067 Result(Builder.TakeString(),
P,
5068 Results.getBasePriority(
P) +
5072 if (!InOriginalClass)
5074 Results.MaybeAddResult(R, CurContext);
5078 if (IsClassProperty) {
5079 for (
const auto *
P : Container->class_properties())
5082 for (
const auto *
P : Container->instance_properties())
5087 if (AllowNullaryMethods) {
5088 ASTContext &Context = Container->getASTContext();
5092 IdentifierInfo *Name = M->getSelector().getIdentifierInfoForSlot(0);
5095 if (!AddedProperties.insert(Name).second)
5098 Results.getCodeCompletionTUInfo());
5100 Builder.AddTypedTextChunk(
5101 Results.getAllocator().CopyString(Name->getName()));
5104 if (!InOriginalClass)
5106 Results.MaybeAddResult(R, CurContext);
5109 if (IsClassProperty) {
5110 for (
const auto *M : Container->methods()) {
5114 if (!M->getSelector().isUnarySelector() ||
5115 M->getReturnType()->isVoidType() || M->isInstanceMethod())
5120 for (
auto *M : Container->methods()) {
5121 if (M->getSelector().isUnarySelector())
5129 for (
auto *
P : Protocol->protocols())
5131 CurContext, AddedProperties, Results,
5132 IsBaseExprStatement, IsClassProperty,
5135 dyn_cast<ObjCInterfaceDecl>(Container)) {
5136 if (AllowCategories) {
5138 for (
auto *Cat : IFace->known_categories())
5140 CurContext, AddedProperties, Results,
5141 IsBaseExprStatement, IsClassProperty,
5146 for (
auto *I : IFace->all_referenced_protocols())
5148 CurContext, AddedProperties, Results,
5149 IsBaseExprStatement, IsClassProperty,
5153 if (IFace->getSuperClass())
5155 AllowNullaryMethods, CurContext, AddedProperties,
5156 Results, IsBaseExprStatement, IsClassProperty,
5159 dyn_cast<ObjCCategoryDecl>(Container)) {
5163 CurContext, AddedProperties, Results,
5164 IsBaseExprStatement, IsClassProperty,
5173 std::optional<FixItHint> AccessOpFixIt) {
5176 Results.setObjectTypeQualifiers(BaseType.
getQualifiers(), BaseKind);
5179 Results.allowNestedNameSpecifiers();
5180 std::vector<FixItHint> FixIts;
5182 FixIts.emplace_back(*AccessOpFixIt);
5183 CodeCompletionDeclConsumer Consumer(Results, RD, BaseType, std::move(FixIts));
5190 if (!Results.empty()) {
5196 for (
Scope *DepScope = S; DepScope; DepScope = DepScope->getParent())
5215 if (
const auto *CTSD =
5216 llvm::dyn_cast<ClassTemplateSpecializationDecl>(RD)) {
5220 RD = CTSD->getSpecializedTemplate()->getTemplatedDecl();
5226 if (
const auto *TD = dyn_cast_or_null<ClassTemplateDecl>(
5227 TST->getTemplateName().getAsTemplateDecl())) {
5228 return TD->getTemplatedDecl();
5272 std::optional<SmallVector<QualType, 1>> ArgTypes;
5274 enum AccessOperator {
5291 std::string AsString;
5293 llvm::raw_string_ostream OS(AsString);
5294 QualType ExactType = deduceType(*ResultType);
5300 B.AddResultTypeChunk(Alloc.
CopyString(AsString));
5303 B.AddTypedTextChunk(Alloc.
CopyString(Name->getName()));
5320 return B.TakeString();
5328 auto *TemplatedEntity = getTemplatedEntity(BaseType.
getDecl(), S);
5329 for (
const Expr *E : constraintsForTemplatedEntity(TemplatedEntity))
5330 believe(E, &BaseType);
5333 std::vector<Member> members() {
5334 std::vector<Member> Results;
5335 for (
const auto &E : this->Results)
5336 Results.push_back(E.second);
5337 llvm::sort(Results, [](
const Member &L,
const Member &R) {
5338 return L.Name->getName() < R.Name->getName();
5348 if (
auto *CSE = dyn_cast<ConceptSpecializationExpr>(E)) {
5362 for (
const auto &Arg : CSE->getTemplateArguments()) {
5363 if (Index >= Params->
size())
5365 if (isApprox(Arg, T)) {
5366 auto *TTPD = dyn_cast<TemplateTypeParmDecl>(Params->
getParam(Index));
5370 auto *TT = cast<TemplateTypeParmType>(TTPD->getTypeForDecl());
5378 }
else if (
auto *BO = dyn_cast<BinaryOperator>(E)) {
5381 if (BO->getOpcode() == BO_LAnd || BO->getOpcode() == BO_LOr) {
5382 believe(BO->getLHS(), T);
5383 believe(BO->getRHS(), T);
5385 }
else if (
auto *RE = dyn_cast<RequiresExpr>(E)) {
5388 if (!Req->isDependent())
5392 if (
auto *TR = dyn_cast<concepts::TypeRequirement>(Req)) {
5394 QualType AssertedType = TR->getType()->getType();
5395 ValidVisitor(
this, T).TraverseType(AssertedType);
5396 }
else if (
auto *ER = dyn_cast<concepts::ExprRequirement>(Req)) {
5397 ValidVisitor Visitor(
this, T);
5401 if (ER->getReturnTypeRequirement().isTypeConstraint()) {
5403 ER->getReturnTypeRequirement().getTypeConstraint();
5404 Visitor.OuterExpr = ER->getExpr();
5406 Visitor.TraverseStmt(ER->getExpr());
5407 }
else if (
auto *NR = dyn_cast<concepts::NestedRequirement>(Req)) {
5408 believe(NR->getConstraintExpr(), T);
5425 Expr *OuterExpr =
nullptr;
5429 : Outer(Outer), T(T) {
5437 if (
Base->isPointerType() && IsArrow) {
5439 Base =
Base->getPointeeType().getTypePtr();
5441 if (isApprox(
Base, T))
5442 addValue(E, E->
getMember(), IsArrow ? Member::Arrow : Member::Dot);
5456 if (Q && isApprox(Q->getAsType(), T))
5467 if (Q && isApprox(Q->getAsType(), T))
5485 void addResult(
Member &&M) {
5486 auto R = Outer->Results.try_emplace(M.Name);
5487 Member &O = R.first->second;
5491 std::make_tuple(M.ArgTypes.has_value(), M.ResultType !=
nullptr,
5492 M.Operator) > std::make_tuple(O.ArgTypes.has_value(),
5493 O.ResultType !=
nullptr,
5503 M.Operator = Member::Colons;
5504 addResult(std::move(M));
5508 Member::AccessOperator Operator) {
5509 if (!Name.isIdentifier())
5512 Result.Name = Name.getAsIdentifierInfo();
5513 Result.Operator = Operator;
5516 if (Caller !=
nullptr && Callee == E) {
5517 Result.ArgTypes.emplace();
5518 for (
const auto *Arg : Caller->
arguments())
5519 Result.ArgTypes->push_back(Arg->getType());
5520 if (Caller == OuterExpr) {
5521 Result.ResultType = OuterType;
5525 Result.ResultType = OuterType;
5527 addResult(std::move(Result));
5536 static bool isApprox(
const Type *T1,
const Type *T2) {
5549 Scope *Inner =
nullptr;
5551 if (S->isTemplateParamScope() && S->isDeclScope(D))
5552 return Inner ? Inner->getEntity() :
nullptr;
5568 TD->getAssociatedConstraints(Result);
5570 if (
const auto *CTPSD =
5571 dyn_cast<ClassTemplatePartialSpecializationDecl>(DC))
5572 CTPSD->getAssociatedConstraints(Result);
5573 if (
const auto *VTPSD = dyn_cast<VarTemplatePartialSpecializationDecl>(DC))
5574 VTPSD->getAssociatedConstraints(Result);
5586 if (Args->getNumTemplateArgs() == 1) {
5587 const auto &Arg = Args->arguments().front().getArgument();
5594 llvm::DenseMap<const IdentifierInfo *, Member> Results;
5607 if (!
Unresolved->isSpecificBuiltinType(BuiltinType::Dependent)) {
5609 if (!
Auto || !
Auto->isUndeducedAutoType())
5613 if (
const CallExpr *CE = llvm::dyn_cast<CallExpr>(E)) {
5616 Callee->isSpecificPlaceholderType(BuiltinType::BoundMember))
5622 Callee = FnTypePtr->getPointeeType();
5624 Callee = BPT->getPointeeType();
5627 return FnType->getReturnType().getNonReferenceType();
5630 if (
const auto *OE = llvm::dyn_cast<OverloadExpr>(CE->
getCallee())) {
5634 const Type *Common =
nullptr;
5635 for (
const auto *D : OE->decls()) {
5637 if (
const auto *FD = llvm::dyn_cast<FunctionDecl>(D))
5638 ReturnType = FD->getReturnType();
5639 else if (
const auto *FTD = llvm::dyn_cast<FunctionTemplateDecl>(D))
5640 ReturnType = FTD->getTemplatedDecl()->getReturnType();
5643 const Type *Candidate =
5645 if (Common && Common != Candidate)
5649 if (Common !=
nullptr)
5654 if (
const auto *CDSME = llvm::dyn_cast<CXXDependentScopeMemberExpr>(E)) {
5656 ? CDSME->getBaseType()
5657 : getApproximateType(CDSME->getBase());
5658 if (CDSME->isArrow() && !
Base.isNull())
5664 if (RD && RD->isCompleteDefinition()) {
5666 for (
const auto *
Member : RD->lookupDependentName(
5668 return llvm::isa<ValueDecl>(Member);
5670 return llvm::cast<ValueDecl>(
Member)->getType().getNonReferenceType();
5675 if (
const auto *DRE = llvm::dyn_cast<DeclRefExpr>(E)) {
5676 if (
const auto *VD = llvm::dyn_cast<VarDecl>(DRE->getDecl())) {
5678 return getApproximateType(VD->getInit());
5689 if (
auto *PLE = llvm::dyn_cast_or_null<ParenListExpr>(
Base)) {
5690 if (PLE->getNumExprs() == 0)
5692 Base = PLE->getExpr(PLE->getNumExprs() - 1);
5702 bool IsBaseExprStatement,
5705 OtherOpBase = unwrapParenList(OtherOpBase);
5706 if (!
Base || !CodeCompleter)
5709 ExprResult ConvertedBase = PerformMemberExprBaseConversion(
Base, IsArrow);
5712 QualType ConvertedBaseType = getApproximateType(ConvertedBase.
get());
5734 ResultBuilder Results(*
this, CodeCompleter->getAllocator(),
5735 CodeCompleter->getCodeCompletionTUInfo(), CCContext,
5736 &ResultBuilder::IsMember);
5738 auto DoCompletion = [&](
Expr *
Base,
bool IsArrow,
5739 std::optional<FixItHint> AccessOpFixIt) ->
bool {
5743 ExprResult ConvertedBase = PerformMemberExprBaseConversion(
Base, IsArrow);
5767 RD, std::move(AccessOpFixIt));
5768 }
else if (
const auto *TTPT =
5769 dyn_cast<TemplateTypeParmType>(BaseType.
getTypePtr())) {
5771 IsArrow ? ConceptInfo::Member::Arrow : ConceptInfo::Member::Dot;
5772 for (
const auto &R : ConceptInfo(*TTPT, S).members()) {
5773 if (R.Operator != Operator)
5776 R.render(*
this, CodeCompleter->getAllocator(),
5777 CodeCompleter->getCodeCompletionTUInfo()));
5779 Result.FixIts.push_back(*AccessOpFixIt);
5780 Results.AddResult(std::move(
Result));
5786 if (AccessOpFixIt) {
5794 assert(ObjCPtr &&
"Non-NULL pointer guaranteed above!");
5797 AddedProperties, Results, IsBaseExprStatement);
5803 CurContext, AddedProperties, Results,
5804 IsBaseExprStatement,
false,
5811 if (AccessOpFixIt) {
5817 Class = ObjCPtr->getInterfaceDecl();
5823 CodeCompletionDeclConsumer Consumer(Results,
Class, BaseType);
5824 Results.setFilter(&ResultBuilder::IsObjCIvar);
5826 Class, LookupMemberName, Consumer, CodeCompleter->includeGlobals(),
5827 false, CodeCompleter->loadExternal());
5835 Results.EnterNewScope();
5837 bool CompletionSucceded = DoCompletion(
Base, IsArrow, std::nullopt);
5838 if (CodeCompleter->includeFixIts()) {
5841 CompletionSucceded |= DoCompletion(
5842 OtherOpBase, !IsArrow,
5846 Results.ExitScope();
5848 if (!CompletionSucceded)
5853 Results.data(), Results.size());
5859 bool IsBaseExprStatement) {
5866 ResultBuilder Results(*
this, CodeCompleter->getAllocator(),
5867 CodeCompleter->getCodeCompletionTUInfo(), CCContext,
5868 &ResultBuilder::IsMember);
5869 Results.EnterNewScope();
5872 true, CurContext, AddedProperties,
5873 Results, IsBaseExprStatement,
5875 Results.ExitScope();
5877 Results.data(), Results.size());
5884 ResultBuilder::LookupFilter Filter =
nullptr;
5889 Filter = &ResultBuilder::IsEnum;
5894 Filter = &ResultBuilder::IsUnion;
5901 Filter = &ResultBuilder::IsClassOrStruct;
5906 llvm_unreachable(
"Unknown type specifier kind in CodeCompleteTag");
5909 ResultBuilder Results(*
this, CodeCompleter->getAllocator(),
5910 CodeCompleter->getCodeCompletionTUInfo(), ContextKind);
5911 CodeCompletionDeclConsumer Consumer(Results, CurContext);
5914 Results.setFilter(Filter);
5915 LookupVisibleDecls(S, LookupTagName, Consumer,
5916 CodeCompleter->includeGlobals(),
5917 CodeCompleter->loadExternal());
5919 if (CodeCompleter->includeGlobals()) {
5921 Results.setFilter(&ResultBuilder::IsNestedNameSpecifier);
5922 LookupVisibleDecls(S, LookupNestedNameSpecifierName, Consumer,
5923 CodeCompleter->includeGlobals(),
5924 CodeCompleter->loadExternal());
5928 Results.data(), Results.size());
5934 Results.AddResult(
"const");
5936 Results.AddResult(
"volatile");
5938 Results.AddResult(
"restrict");
5940 Results.AddResult(
"_Atomic");
5942 Results.AddResult(
"__unaligned");
5946 ResultBuilder Results(*
this, CodeCompleter->getAllocator(),
5947 CodeCompleter->getCodeCompletionTUInfo(),
5949 Results.EnterNewScope();
5951 Results.ExitScope();
5953 Results.data(), Results.size());
5958 ResultBuilder Results(*
this, CodeCompleter->getAllocator(),
5959 CodeCompleter->getCodeCompletionTUInfo(),
5961 Results.EnterNewScope();
5963 if (LangOpts.CPlusPlus11) {
5964 Results.AddResult(
"noexcept");
5968 Results.AddResult(
"final");
5970 Results.AddResult(
"override");
5973 Results.ExitScope();
5975 Results.data(), Results.size());
5979 CodeCompleteExpression(S,
QualType(getASTContext().getSizeType()));
5983 if (getCurFunction()->SwitchStack.empty() || !CodeCompleter)
5991 if (!
type->isEnumeralType()) {
5993 Data.IntegralConstantExpression =
true;
5994 CodeCompleteExpression(S,
Data);
6008 CoveredEnumerators Enumerators;
6010 SC = SC->getNextSwitchCase()) {
6011 CaseStmt *Case = dyn_cast<CaseStmt>(SC);
6016 if (
auto *DRE = dyn_cast<DeclRefExpr>(CaseVal))
6017 if (
auto *Enumerator =
6018 dyn_cast<EnumConstantDecl>(DRE->getDecl())) {
6025 Enumerators.Seen.insert(Enumerator);
6038 Enumerators.SuggestedQualifier = DRE->getQualifier();
6043 ResultBuilder Results(*
this, CodeCompleter->getAllocator(),
6044 CodeCompleter->getCodeCompletionTUInfo(),
6048 if (CodeCompleter->includeMacros()) {
6052 Results.data(), Results.size());
6056 if (Args.size() && !Args.data())
6059 for (
unsigned I = 0; I != Args.size(); ++I)
6080 if (Candidate.Function) {
6081 if (Candidate.Function->isDeleted())
6084 Candidate.Function) &&
6085 Candidate.Function->getNumParams() <= ArgSize &&
6094 if (Candidate.Viable)
6108 for (
auto &Candidate : Candidates) {
6109 QualType CandidateParamType = Candidate.getParamType(N);
6110 if (CandidateParamType.
isNull())
6112 if (ParamType.
isNull()) {
6113 ParamType = CandidateParamType;
6130 if (Candidates.empty())
6134 SemaRef, CurrentArg, Candidates.data(), Candidates.size(), OpenParLoc,
6146 Target = T->getDecl()->getTypeSourceInfo()->getTypeLoc();
6148 }
else if (
const auto *DR = dyn_cast<DeclRefExpr>(Fn)) {
6149 const auto *D = DR->getDecl();
6150 if (
const auto *
const VD = dyn_cast<VarDecl>(D)) {
6151 Target = VD->getTypeSourceInfo()->getTypeLoc();
6153 }
else if (
const auto *ME = dyn_cast<MemberExpr>(Fn)) {
6154 const auto *MD = ME->getMemberDecl();
6155 if (
const auto *FD = dyn_cast<FieldDecl>(MD)) {
6156 Target = FD->getTypeSourceInfo()->getTypeLoc();
6170 Target = A.getModifiedLoc();
6189 Fn = unwrapParenList(Fn);
6190 if (!CodeCompleter || !Fn)
6200 auto ArgsWithoutDependentTypes =
6210 if (
auto ULE = dyn_cast<UnresolvedLookupExpr>(NakedFn)) {
6211 AddOverloadedCallCandidates(ULE, ArgsWithoutDependentTypes, CandidateSet,
6213 }
else if (
auto UME = dyn_cast<UnresolvedMemberExpr>(NakedFn)) {
6215 if (UME->hasExplicitTemplateArgs()) {
6216 UME->copyTemplateArgumentsInto(TemplateArgsBuffer);
6217 TemplateArgs = &TemplateArgsBuffer;
6222 1, UME->isImplicitAccess() ?
nullptr : UME->getBase());
6223 ArgExprs.append(ArgsWithoutDependentTypes.begin(),
6224 ArgsWithoutDependentTypes.end());
6226 Decls.
append(UME->decls_begin(), UME->decls_end());
6227 const bool FirstArgumentIsBase = !UME->isImplicitAccess() && UME->getBase();
6228 AddFunctionCandidates(Decls, ArgExprs, CandidateSet, TemplateArgs,
6230 true, FirstArgumentIsBase);
6233 if (
auto *MCE = dyn_cast<MemberExpr>(NakedFn))
6234 FD = dyn_cast<FunctionDecl>(MCE->getMemberDecl());
6235 else if (
auto *DRE = dyn_cast<DeclRefExpr>(NakedFn))
6236 FD = dyn_cast<FunctionDecl>(DRE->getDecl());
6243 ArgsWithoutDependentTypes, CandidateSet,
6251 if (isCompleteType(Loc, NakedFn->
getType())) {
6254 LookupResult R(*
this, OpName, Loc, LookupOrdinaryName);
6255 LookupQualifiedName(R, DC);
6258 ArgExprs.append(ArgsWithoutDependentTypes.begin(),
6259 ArgsWithoutDependentTypes.end());
6276 ArgsWithoutDependentTypes.size(),
6312static std::optional<unsigned>
6315 static constexpr unsigned Invalid = std::numeric_limits<unsigned>::max();
6321 unsigned ArgsAfterDesignator = 0;
6322 for (
const Expr *Arg : Args) {
6323 if (
const auto *DIE = dyn_cast<DesignatedInitExpr>(Arg)) {
6324 if (DIE->size() == 1 && DIE->getDesignator(0)->isFieldDesignator()) {
6325 DesignatedFieldName = DIE->getDesignator(0)->getFieldName();
6326 ArgsAfterDesignator = 0;
6330 }
else if (isa<DesignatedInitUpdateExpr>(Arg)) {
6333 ++ArgsAfterDesignator;
6336 if (!DesignatedFieldName)
6337 return std::nullopt;
6341 unsigned DesignatedIndex = 0;
6342 const FieldDecl *DesignatedField =
nullptr;
6343 for (
const auto *Field :
Aggregate.getAggregate()->fields()) {
6344 if (Field->getIdentifier() == DesignatedFieldName) {
6345 DesignatedField = Field;
6350 if (!DesignatedField)
6354 unsigned AggregateSize =
Aggregate.getNumParams();
6355 while (DesignatedIndex < AggregateSize &&
6356 Aggregate.getParamDecl(DesignatedIndex) != DesignatedField)
6360 return DesignatedIndex + ArgsAfterDesignator + 1;
6385 if (Braced && !RD->
isUnion() &&
6386 (!LangOpts.CPlusPlus || (CRD && CRD->
isAggregate()))) {
6390 if (
auto NextIndex =
6393 if (*NextIndex >= AggregateSize)
6395 Results.push_back(AggregateSig);
6401 if (Args.size() < AggregateSize)
6402 Results.push_back(AggregateSig);
6410 for (
NamedDecl *
C : LookupConstructors(CRD)) {
6411 if (
auto *FD = dyn_cast<FunctionDecl>(
C)) {
6414 if (Braced && LangOpts.CPlusPlus && isInitListConstructor(FD))
6421 }
else if (
auto *FTD = dyn_cast<FunctionTemplateDecl>(
C)) {
6422 if (Braced && LangOpts.CPlusPlus &&
6423 isInitListConstructor(FTD->getTemplatedDecl()))
6426 AddTemplateOverloadCandidate(
6428 nullptr, Args, CandidateSet,
6447 dyn_cast<CXXConstructorDecl>(ConstructorDecl);
6451 if (
ValueDecl *MemberDecl = tryLookupCtorInitMemberDecl(
6452 Constructor->getParent(), SS, TemplateTypeTy, II))
6453 return ProduceConstructorSignatureHelp(MemberDecl->getType(),
6454 MemberDecl->getLocation(), ArgExprs,
6455 OpenParLoc, Braced);
6463 if (Index < Params.
size())
6466 Param = Params.
asArray().back();
6472 return llvm::isa<TemplateTypeParmDecl>(Param);
6474 return llvm::isa<NonTypeTemplateParmDecl>(Param);
6476 return llvm::isa<TemplateTemplateParmDecl>(Param);
6478 llvm_unreachable(
"Unhandled switch case");
6484 if (!CodeCompleter || !ParsedTemplate)
6490 bool Matches =
true;
6491 for (
unsigned I = 0; I < Args.size(); ++I) {
6498 Results.emplace_back(TD);
6506 if (
const auto *TD = llvm::dyn_cast<TemplateDecl>(ND))
6519 if (D.isArrayDesignator() || D.isArrayRangeDesignator()) {
6523 assert(D.isFieldDesignator());
6525 if (RD && RD->isCompleteDefinition()) {
6526 for (
const auto *
Member : RD->lookup(D.getFieldDecl()))
6528 NextType = FD->getType();
6533 BaseType = NextType;
6545 if (!RD || RD->fields().empty())
6550 ResultBuilder Results(*
this, CodeCompleter->getAllocator(),
6551 CodeCompleter->getCodeCompletionTUInfo(), CCC);
6553 Results.EnterNewScope();
6554 for (
const Decl *D : RD->decls()) {
6556 if (
auto *IFD = dyn_cast<IndirectFieldDecl>(D))
6557 FD = IFD->getAnonField();
6558 else if (
auto *DFD = dyn_cast<FieldDecl>(D))
6566 Results.AddResult(
Result, CurContext,
nullptr);
6568 Results.ExitScope();
6570 Results.data(), Results.size());
6574 ValueDecl *VD = dyn_cast_or_null<ValueDecl>(D);
6576 CodeCompleteOrdinaryName(S, PCC_Expression);
6583 Data.IgnoreDecls.push_back(VD);
6585 CodeCompleteExpression(S,
Data);
6589 ResultBuilder Results(*
this, CodeCompleter->getAllocator(),
6590 CodeCompleter->getCodeCompletionTUInfo(),
6592 Results.setFilter(&ResultBuilder::IsOrdinaryName);
6593 Results.EnterNewScope();
6595 CodeCompletionDeclConsumer Consumer(Results, CurContext);
6596 LookupVisibleDecls(S, LookupOrdinaryName, Consumer,
6597 CodeCompleter->includeGlobals(),
6598 CodeCompleter->loadExternal());
6604 Results.getCodeCompletionTUInfo());
6606 auto AddElseBodyPattern = [&] {
6611 Builder.AddPlaceholderChunk(
"statements");
6617 Builder.AddPlaceholderChunk(
"statement");
6621 Builder.AddTypedTextChunk(
"else");
6622 if (Results.includeCodePatterns())
6623 AddElseBodyPattern();
6624 Results.AddResult(Builder.TakeString());
6627 Builder.AddTypedTextChunk(
"else if");
6631 Builder.AddPlaceholderChunk(
"condition");
6633 Builder.AddPlaceholderChunk(
"expression");
6635 if (Results.includeCodePatterns()) {
6636 AddElseBodyPattern();
6638 Results.AddResult(Builder.TakeString());
6640 Results.ExitScope();
6642 if (S->getFnParent())
6645 if (CodeCompleter->includeMacros())
6649 Results.data(), Results.size());
6653 bool EnteringContext,
6654 bool IsUsingDeclaration,
QualType BaseType,
6656 if (SS.
isEmpty() || !CodeCompleter)
6671 ResultBuilder DummyResults(*
this, CodeCompleter->getAllocator(),
6672 CodeCompleter->getCodeCompletionTUInfo(), CC);
6673 if (!PreferredType.
isNull())
6674 DummyResults.setPreferredType(PreferredType);
6675 if (S->getEntity()) {
6676 CodeCompletionDeclConsumer Consumer(DummyResults, S->getEntity(),
6678 LookupVisibleDecls(S, LookupOrdinaryName, Consumer,
6683 DummyResults.getCompletionContext(),
nullptr, 0);
6694 if (Ctx ==
nullptr || RequireCompleteDeclContext(SS, Ctx))
6698 ResultBuilder Results(*
this, CodeCompleter->getAllocator(),
6699 CodeCompleter->getCodeCompletionTUInfo(), CC);
6700 if (!PreferredType.
isNull())
6701 Results.setPreferredType(PreferredType);
6702 Results.EnterNewScope();
6707 if (!Results.empty() && NNS && NNS->
isDependent())
6708 Results.AddResult(
"template");
6712 if (
const auto *TTPT =
6713 dyn_cast_or_null<TemplateTypeParmType>(NNS->
getAsType())) {
6714 for (
const auto &R : ConceptInfo(*TTPT, S).members()) {
6715 if (R.Operator != ConceptInfo::Member::Colons)
6718 R.render(*
this, CodeCompleter->getAllocator(),
6719 CodeCompleter->getCodeCompletionTUInfo())));
6728 if (Ctx && !EnteringContext)
6730 Results.ExitScope();
6733 (CodeCompleter->includeNamespaceLevelDecls() || !Ctx->
isFileContext())) {
6734 CodeCompletionDeclConsumer Consumer(Results, Ctx, BaseType);
6735 LookupVisibleDecls(Ctx, LookupOrdinaryName, Consumer,
6738 CodeCompleter->loadExternal());
6742 Results.data(), Results.size());
6752 Context.setIsUsingDeclaration(
true);
6754 ResultBuilder Results(*
this, CodeCompleter->getAllocator(),
6755 CodeCompleter->getCodeCompletionTUInfo(), Context,
6756 &ResultBuilder::IsNestedNameSpecifier);
6757 Results.EnterNewScope();
6760 if (!S->isClassScope())
6765 CodeCompletionDeclConsumer Consumer(Results, CurContext);
6766 LookupVisibleDecls(S, LookupOrdinaryName, Consumer,
6767 CodeCompleter->includeGlobals(),
6768 CodeCompleter->loadExternal());
6769 Results.ExitScope();
6772 Results.data(), Results.size());
6781 ResultBuilder Results(*
this, CodeCompleter->getAllocator(),
6782 CodeCompleter->getCodeCompletionTUInfo(),
6784 &ResultBuilder::IsNamespaceOrAlias);
6785 Results.EnterNewScope();
6786 CodeCompletionDeclConsumer Consumer(Results, CurContext);
6787 LookupVisibleDecls(S, LookupOrdinaryName, Consumer,
6788 CodeCompleter->includeGlobals(),
6789 CodeCompleter->loadExternal());
6790 Results.ExitScope();
6792 Results.data(), Results.size());
6800 if (!S->getParent())
6803 bool SuppressedGlobalResults =
6804 Ctx && !CodeCompleter->includeGlobals() && isa<TranslationUnitDecl>(Ctx);
6806 ResultBuilder Results(*
this, CodeCompleter->getAllocator(),
6807 CodeCompleter->getCodeCompletionTUInfo(),
6808 SuppressedGlobalResults
6811 &ResultBuilder::IsNamespace);
6813 if (Ctx && Ctx->
isFileContext() && !SuppressedGlobalResults) {
6818 std::map<NamespaceDecl *, NamespaceDecl *> OrigToLatest;
6823 OrigToLatest[NS->getOriginalNamespace()] = *NS;
6827 Results.EnterNewScope();
6828 for (std::map<NamespaceDecl *, NamespaceDecl *>::iterator
6829 NS = OrigToLatest.begin(),
6830 NSEnd = OrigToLatest.end();
6835 CurContext,
nullptr,
false);
6836 Results.ExitScope();
6840 Results.data(), Results.size());
6848 ResultBuilder Results(*
this, CodeCompleter->getAllocator(),
6849 CodeCompleter->getCodeCompletionTUInfo(),
6851 &ResultBuilder::IsNamespaceOrAlias);
6852 CodeCompletionDeclConsumer Consumer(Results, CurContext);
6853 LookupVisibleDecls(S, LookupOrdinaryName, Consumer,
6854 CodeCompleter->includeGlobals(),
6855 CodeCompleter->loadExternal());
6857 Results.data(), Results.size());
6865 ResultBuilder Results(*
this, CodeCompleter->getAllocator(),
6866 CodeCompleter->getCodeCompletionTUInfo(),
6868 &ResultBuilder::IsType);
6869 Results.EnterNewScope();
6873#define OVERLOADED_OPERATOR(Name, Spelling, Token, Unary, Binary, MemberOnly) \
6874 if (OO_##Name != OO_Conditional) \
6875 Results.AddResult(Result(Spelling));
6876#include "clang/Basic/OperatorKinds.def"
6879 Results.allowNestedNameSpecifiers();
6880 CodeCompletionDeclConsumer Consumer(Results, CurContext);
6881 LookupVisibleDecls(S, LookupOrdinaryName, Consumer,
6882 CodeCompleter->includeGlobals(),
6883 CodeCompleter->loadExternal());
6887 Results.ExitScope();
6890 Results.data(), Results.size());
6898 AdjustDeclIfTemplate(ConstructorD);
6900 auto *Constructor = dyn_cast<CXXConstructorDecl>(ConstructorD);
6904 ResultBuilder Results(*
this, CodeCompleter->getAllocator(),
6905 CodeCompleter->getCodeCompletionTUInfo(),
6907 Results.EnterNewScope();
6912 for (
unsigned I = 0, E = Initializers.size(); I != E; ++I) {
6913 if (Initializers[I]->isBaseInitializer())
6915 QualType(Initializers[I]->getBaseClass(), 0)));
6917 InitializedFields.insert(
6918 cast<FieldDecl>(Initializers[I]->getAnyMember()));
6923 bool SawLastInitializer = Initializers.empty();
6926 auto GenerateCCS = [&](
const NamedDecl *ND,
const char *Name) {
6928 Results.getCodeCompletionTUInfo());
6929 Builder.AddTypedTextChunk(Name);
6931 if (
const auto *
Function = dyn_cast<FunctionDecl>(ND))
6933 else if (
const auto *FunTemplDecl = dyn_cast<FunctionTemplateDecl>(ND))
6937 return Builder.TakeString();
6939 auto AddDefaultCtorInit = [&](
const char *Name,
const char *
Type,
6942 Results.getCodeCompletionTUInfo());
6943 Builder.AddTypedTextChunk(Name);
6945 Builder.AddPlaceholderChunk(
Type);
6949 Builder.TakeString(), ND,
6951 if (isa<FieldDecl>(ND))
6953 return Results.AddResult(CCR);
6956 Builder.TakeString(),
6960 const char *Name,
const FieldDecl *FD) {
6962 return AddDefaultCtorInit(Name,
6963 FD ? Results.getAllocator().CopyString(
6964 FD->getType().getAsString(Policy))
6968 if (Ctors.begin() == Ctors.end())
6969 return AddDefaultCtorInit(Name, Name, RD);
6973 Results.AddResult(CCR);
6977 const char *BaseName =
6978 Results.getAllocator().CopyString(
Base.getType().getAsString(Policy));
6979 const auto *RD =
Base.getType()->getAsCXXRecordDecl();
6984 auto AddField = [&](
const FieldDecl *FD) {
6985 const char *FieldName =
6986 Results.getAllocator().CopyString(FD->getIdentifier()->getName());
6987 const CXXRecordDecl *RD = FD->getType()->getAsCXXRecordDecl();
6993 for (
const auto &
Base : ClassDecl->
bases()) {
6996 SawLastInitializer =
6997 !Initializers.empty() && Initializers.back()->isBaseInitializer() &&
6999 Base.getType(),
QualType(Initializers.back()->getBaseClass(), 0));
7004 SawLastInitializer =
false;
7008 for (
const auto &
Base : ClassDecl->
vbases()) {
7011 SawLastInitializer =
7012 !Initializers.empty() && Initializers.back()->isBaseInitializer() &&
7014 Base.getType(),
QualType(Initializers.back()->getBaseClass(), 0));
7019 SawLastInitializer =
false;
7023 for (
auto *Field : ClassDecl->
fields()) {
7024 if (!InitializedFields.insert(cast<FieldDecl>(Field->getCanonicalDecl()))
7026 SawLastInitializer = !Initializers.empty() &&
7027 Initializers.back()->isAnyMemberInitializer() &&
7028 Initializers.back()->getAnyMember() == Field;
7032 if (!Field->getDeclName())
7036 SawLastInitializer =
false;
7038 Results.ExitScope();
7041 Results.data(), Results.size());
7054 bool AfterAmpersand) {
7055 ResultBuilder Results(*
this, CodeCompleter->getAllocator(),
7056 CodeCompleter->getCodeCompletionTUInfo(),
7058 Results.EnterNewScope();
7062 bool IncludedThis =
false;
7065 IncludedThis =
true;
7074 for (
const auto *D : S->decls()) {
7075 const auto *Var = dyn_cast<VarDecl>(D);
7076 if (!Var || !Var->hasLocalStorage() || Var->hasAttr<BlocksAttr>())
7079 if (Known.insert(Var->getIdentifier()).second)
7081 CurContext,
nullptr,
false);
7089 Results.ExitScope();
7092 Results.data(), Results.size());
7096 if (!LangOpts.CPlusPlus11)
7098 ResultBuilder Results(*
this, CodeCompleter->getAllocator(),
7099 CodeCompleter->getCodeCompletionTUInfo(),
7101 auto ShouldAddDefault = [&D,
this]() {
7113 auto Op =
Id.OperatorFunctionId.Operator;
7116 if (Op == OverloadedOperatorKind::OO_Equal)
7118 if (LangOpts.CPlusPlus20 &&
7119 (Op == OverloadedOperatorKind::OO_EqualEqual ||
7120 Op == OverloadedOperatorKind::OO_ExclaimEqual ||
7121 Op == OverloadedOperatorKind::OO_Less ||
7122 Op == OverloadedOperatorKind::OO_LessEqual ||
7123 Op == OverloadedOperatorKind::OO_Greater ||
7124 Op == OverloadedOperatorKind::OO_GreaterEqual ||
7125 Op == OverloadedOperatorKind::OO_Spaceship))
7131 Results.EnterNewScope();
7132 if (ShouldAddDefault())
7133 Results.AddResult(
"default");
7136 Results.AddResult(
"delete");
7137 Results.ExitScope();
7139 Results.data(), Results.size());
7144#define OBJC_AT_KEYWORD_NAME(NeedAt, Keyword) ((NeedAt) ? "@" Keyword : Keyword)
7147 ResultBuilder &Results,
bool NeedAt) {
7153 Results.getCodeCompletionTUInfo());
7154 if (LangOpts.ObjC) {
7158 Builder.AddPlaceholderChunk(
"property");
7159 Results.AddResult(
Result(Builder.TakeString()));
7164 Builder.AddPlaceholderChunk(
"property");
7165 Results.AddResult(
Result(Builder.TakeString()));
7170 ResultBuilder &Results,
bool NeedAt) {
7176 if (LangOpts.ObjC) {
7191 Results.getCodeCompletionTUInfo());
7196 Builder.AddPlaceholderChunk(
"name");
7197 Results.AddResult(
Result(Builder.TakeString()));
7199 if (Results.includeCodePatterns()) {
7205 Builder.AddPlaceholderChunk(
"class");
7206 Results.AddResult(
Result(Builder.TakeString()));
7211 Builder.AddPlaceholderChunk(
"protocol");
7212 Results.AddResult(
Result(Builder.TakeString()));
7217 Builder.AddPlaceholderChunk(
"class");
7218 Results.AddResult(
Result(Builder.TakeString()));
7222 Builder.AddTypedTextChunk(
7225 Builder.AddPlaceholderChunk(
"alias");
7227 Builder.AddPlaceholderChunk(
"class");
7228 Results.AddResult(
Result(Builder.TakeString()));
7230 if (Results.getSema().getLangOpts().Modules) {
7234 Builder.AddPlaceholderChunk(
"module");
7235 Results.AddResult(
Result(Builder.TakeString()));
7240 ResultBuilder Results(*
this, CodeCompleter->getAllocator(),
7241 CodeCompleter->getCodeCompletionTUInfo(),
7243 Results.EnterNewScope();
7244 if (isa<ObjCImplDecl>(CurContext))
7250 Results.ExitScope();
7252 Results.data(), Results.size());
7258 Results.getCodeCompletionTUInfo());
7261 const char *EncodeType =
"char[]";
7262 if (Results.getSema().getLangOpts().CPlusPlus ||
7263 Results.getSema().getLangOpts().ConstStrings)
7264 EncodeType =
"const char[]";
7265 Builder.AddResultTypeChunk(EncodeType);
7268 Builder.AddPlaceholderChunk(
"type-name");
7270 Results.AddResult(
Result(Builder.TakeString()));
7273 Builder.AddResultTypeChunk(
"Protocol *");
7276 Builder.AddPlaceholderChunk(
"protocol-name");
7278 Results.AddResult(
Result(Builder.TakeString()));
7281 Builder.AddResultTypeChunk(
"SEL");
7284 Builder.AddPlaceholderChunk(
"selector");
7286 Results.AddResult(
Result(Builder.TakeString()));
7289 Builder.AddResultTypeChunk(
"NSString *");
7291 Builder.AddPlaceholderChunk(
"string");
7292 Builder.AddTextChunk(
"\"");
7293 Results.AddResult(
Result(Builder.TakeString()));
7296 Builder.AddResultTypeChunk(
"NSArray *");
7298 Builder.AddPlaceholderChunk(
"objects, ...");
7300 Results.AddResult(
Result(Builder.TakeString()));
7303 Builder.AddResultTypeChunk(
"NSDictionary *");
7305 Builder.AddPlaceholderChunk(
"key");
7308 Builder.AddPlaceholderChunk(
"object, ...");
7310 Results.AddResult(
Result(Builder.TakeString()));
7313 Builder.AddResultTypeChunk(
"id");
7315 Builder.AddPlaceholderChunk(
"expression");
7317 Results.AddResult(
Result(Builder.TakeString()));
7323 Results.getCodeCompletionTUInfo());
7325 if (Results.includeCodePatterns()) {
7330 Builder.AddPlaceholderChunk(
"statements");
7332 Builder.AddTextChunk(
"@catch");
7334 Builder.AddPlaceholderChunk(
"parameter");
7337 Builder.AddPlaceholderChunk(
"statements");
7339 Builder.AddTextChunk(
"@finally");
7341 Builder.AddPlaceholderChunk(
"statements");
7343 Results.AddResult(
Result(Builder.TakeString()));
7349 Builder.AddPlaceholderChunk(
"expression");
7350 Results.AddResult(
Result(Builder.TakeString()));
7352 if (Results.includeCodePatterns()) {
7357 Builder.AddPlaceholderChunk(
"expression");
7360 Builder.AddPlaceholderChunk(
"statements");
7362 Results.AddResult(
Result(Builder.TakeString()));
7367 ResultBuilder &Results,
bool NeedAt) {
7377 ResultBuilder Results(*
this, CodeCompleter->getAllocator(),
7378 CodeCompleter->getCodeCompletionTUInfo(),
7380 Results.EnterNewScope();
7382 Results.ExitScope();
7384 Results.data(), Results.size());
7388 ResultBuilder Results(*
this, CodeCompleter->getAllocator(),
7389 CodeCompleter->getCodeCompletionTUInfo(),
7391 Results.EnterNewScope();
7394 Results.ExitScope();
7396 Results.data(), Results.size());
7400 ResultBuilder Results(*
this, CodeCompleter->getAllocator(),
7401 CodeCompleter->getCodeCompletionTUInfo(),
7403 Results.EnterNewScope();
7405 Results.ExitScope();
7407 Results.data(), Results.size());
7414 if (Attributes & NewFlag)
7417 Attributes |= NewFlag;
7425 unsigned AssignCopyRetMask =
7431 if (AssignCopyRetMask &&
7449 ResultBuilder Results(*
this, CodeCompleter->getAllocator(),
7450 CodeCompleter->getCodeCompletionTUInfo(),
7452 Results.EnterNewScope();
7489 Results.getCodeCompletionTUInfo());
7498 Results.getCodeCompletionTUInfo());
7511 Results.ExitScope();
7513 Results.data(), Results.size());
7526 bool AllowSameLength =
true) {
7527 unsigned NumSelIdents = SelIdents.size();
7540 if (!AllowSameLength && NumSelIdents && NumSelIdents == Sel.
getNumArgs())
7543 for (
unsigned I = 0; I != NumSelIdents; ++I)
7553 bool AllowSameLength =
true) {
7587 ResultBuilder &Results,
bool InOriginalClass =
true,
7588 bool IsRootClass =
false) {
7592 IsRootClass = IsRootClass || (IFace && !IFace->
getSuperClass());
7596 if (M->isInstanceMethod() == WantInstanceMethods ||
7597 (IsRootClass && !WantInstanceMethods)) {
7603 if (!Selectors.insert(M->getSelector()).second)
7606 Result R =
Result(M, Results.getBasePriority(M),
nullptr);
7607 R.StartParameter = SelIdents.size();
7608 R.AllParametersAreInformative = (WantKind !=
MK_Any);
7609 if (!InOriginalClass)
7611 Results.MaybeAddResult(R, CurContext);
7616 if (
const auto *Protocol = dyn_cast<ObjCProtocolDecl>(Container)) {
7617 if (Protocol->hasDefinition()) {
7619 Protocol->getReferencedProtocols();
7621 E = Protocols.
end();
7623 AddObjCMethods(*I, WantInstanceMethods, WantKind, SelIdents, CurContext,
7624 Selectors, AllowSameLength, Results,
false, IsRootClass);
7633 AddObjCMethods(I, WantInstanceMethods, WantKind, SelIdents, CurContext,
7634 Selectors, AllowSameLength, Results,
false, IsRootClass);
7638 AddObjCMethods(CatDecl, WantInstanceMethods, WantKind, SelIdents,
7639 CurContext, Selectors, AllowSameLength, Results,
7640 InOriginalClass, IsRootClass);
7644 CatDecl->getReferencedProtocols();
7646 E = Protocols.
end();
7648 AddObjCMethods(*I, WantInstanceMethods, WantKind, SelIdents, CurContext,
7649 Selectors, AllowSameLength, Results,
false, IsRootClass);
7653 AddObjCMethods(Impl, WantInstanceMethods, WantKind, SelIdents, CurContext,
7654 Selectors, AllowSameLength, Results, InOriginalClass,
7662 SelIdents, CurContext, Selectors, AllowSameLength, Results,
7667 AddObjCMethods(Impl, WantInstanceMethods, WantKind, SelIdents, CurContext,
7668 Selectors, AllowSameLength, Results, InOriginalClass,
7677 dyn_cast_or_null<ObjCCategoryDecl>(CurContext))
7685 ResultBuilder Results(*
this, CodeCompleter->getAllocator(),
7686 CodeCompleter->getCodeCompletionTUInfo(),
7688 Results.EnterNewScope();
7694 Results.ExitScope();
7696 Results.data(), Results.size());
7704 dyn_cast_or_null<ObjCCategoryDecl>(CurContext))
7712 ResultBuilder Results(*
this, CodeCompleter->getAllocator(),
7713 CodeCompleter->getCodeCompletionTUInfo(),
7715 Results.EnterNewScope();
7722 Results.ExitScope();
7724 Results.data(), Results.size());
7729 ResultBuilder Results(*
this, CodeCompleter->getAllocator(),
7730 CodeCompleter->getCodeCompletionTUInfo(),
7732 Results.EnterNewScope();
7735 bool AddedInOut =
false;
7738 Results.AddResult(
"in");
7739 Results.AddResult(
"inout");
7744 Results.AddResult(
"out");
7746 Results.AddResult(
"inout");
7751 Results.AddResult(
"bycopy");
7752 Results.AddResult(
"byref");
7753 Results.AddResult(
"oneway");
7756 Results.AddResult(
"nonnull");
7757 Results.AddResult(
"nullable");
7758 Results.AddResult(
"null_unspecified");
7766 PP.isMacroDefined(
"IBAction")) {
7768 Results.getCodeCompletionTUInfo(),
7770 Builder.AddTypedTextChunk(
"IBAction");
7772 Builder.AddPlaceholderChunk(
"selector");
7775 Builder.AddTextChunk(
"id");
7777 Builder.AddTextChunk(
"sender");
7788 Results.ExitScope();
7791 Results.setFilter(&ResultBuilder::IsOrdinaryNonValueName);
7792 CodeCompletionDeclConsumer Consumer(Results, CurContext);
7793 LookupVisibleDecls(S, LookupOrdinaryName, Consumer,
7794 CodeCompleter->includeGlobals(),
7795 CodeCompleter->loadExternal());
7797 if (CodeCompleter->includeMacros())
7801 Results.data(), Results.size());
7809 auto *Msg = dyn_cast_or_null<ObjCMessageExpr>(E);
7827 switch (Msg->getReceiverKind()) {
7831 IFace = ObjType->getInterface();
7835 QualType T = Msg->getInstanceReceiver()->getType();
7837 IFace = Ptr->getInterfaceDecl();
7851 return llvm::StringSwitch<ObjCInterfaceDecl *>(
Id->getName())
7852 .Case(
"retain", IFace)
7853 .Case(
"strong", IFace)
7854 .Case(
"autorelease", IFace)
7855 .Case(
"copy", IFace)
7856 .Case(
"copyWithZone", IFace)
7857 .Case(
"mutableCopy", IFace)
7858 .Case(
"mutableCopyWithZone", IFace)
7859 .Case(
"awakeFromCoder", IFace)
7860 .Case(
"replacementObjectFromCoder", IFace)
7861 .Case(
"class", IFace)
7862 .Case(
"classForCoder", IFace)
7863 .Case(
"superclass", Super)
7866 return llvm::StringSwitch<ObjCInterfaceDecl *>(
Id->getName())
7868 .Case(
"alloc", IFace)
7869 .Case(
"allocWithZone", IFace)
7870 .Case(
"class", IFace)
7871 .Case(
"superclass", Super)
7894 ResultBuilder &Results) {
7905 while ((
Class =
Class->getSuperClass()) && !SuperMethod) {
7912 for (
const auto *Cat :
Class->known_categories()) {
7913 if ((SuperMethod = Cat->getMethod(CurMethod->
getSelector(),
7931 CurP != CurPEnd; ++CurP, ++SuperP) {
7934 (*SuperP)->getType()))
7938 if (!(*CurP)->getIdentifier())
7944 Results.getCodeCompletionTUInfo());
7948 Results.getCompletionContext().getBaseType(), Builder);
7951 if (NeedSuperKeyword) {
7952 Builder.AddTypedTextChunk(
"super");
7958 if (NeedSuperKeyword)
7959 Builder.AddTextChunk(
7962 Builder.AddTypedTextChunk(
7966 for (
unsigned I = 0, N = Sel.
getNumArgs(); I != N; ++I, ++CurP) {
7967 if (I > SelIdents.size())
7970 if (I < SelIdents.size())
7971 Builder.AddInformativeChunk(
7973 else if (NeedSuperKeyword || I > SelIdents.size()) {
7974 Builder.AddTextChunk(
7976 Builder.AddPlaceholderChunk(Builder.getAllocator().CopyString(
7977 (*CurP)->getIdentifier()->getName()));
7979 Builder.AddTypedTextChunk(
7981 Builder.AddPlaceholderChunk(Builder.getAllocator().CopyString(
7982 (*CurP)->getIdentifier()->getName()));
7994 ResultBuilder Results(
7995 *
this, CodeCompleter->getAllocator(),
7996 CodeCompleter->getCodeCompletionTUInfo(),
7999 ? &ResultBuilder::IsObjCMessageReceiverOrLambdaCapture
8000 : &ResultBuilder::IsObjCMessageReceiver);
8002 CodeCompletionDeclConsumer Consumer(Results, CurContext);
8003 Results.EnterNewScope();
8004 LookupVisibleDecls(S, LookupOrdinaryName, Consumer,
8005 CodeCompleter->includeGlobals(),
8006 CodeCompleter->loadExternal());
8012 if (Iface->getSuperClass()) {
8013 Results.AddResult(
Result(
"super"));
8022 Results.ExitScope();
8024 if (CodeCompleter->includeMacros())
8027 Results.data(), Results.size());
8032 bool AtArgumentExpression) {
8036 CDecl = CurMethod->getClassInterface();
8045 if (CurMethod->isInstanceMethod()) {
8049 return CodeCompleteObjCInstanceMessage(S,
nullptr, SelIdents,
8050 AtArgumentExpression, CDecl);
8058 NamedDecl *ND = LookupSingleName(S, Super, SuperLoc, LookupOrdinaryName);
8059 if ((CDecl = dyn_cast_or_null<ObjCInterfaceDecl>(ND))) {
8061 }
else if (
TypeDecl *TD = dyn_cast_or_null<TypeDecl>(ND)) {
8064 CDecl = Iface->getInterface();
8065 }
else if (ND && isa<UnresolvedUsingTypenameDecl>(ND)) {
8073 ExprResult SuperExpr = ActOnIdExpression(S, SS, TemplateKWLoc,
id,
8076 return CodeCompleteObjCInstanceMessage(S, (
Expr *)SuperExpr.
get(),
8077 SelIdents, AtArgumentExpression);
8086 return CodeCompleteObjCClassMessage(S, Receiver, SelIdents,
8087 AtArgumentExpression,
8094 unsigned NumSelIdents) {
8096 ASTContext &Context = Results.getSema().Context;
8100 Result *ResultsData = Results.data();
8101 for (
unsigned I = 0, N = Results.size(); I != N; ++I) {
8102 Result &R = ResultsData[I];
8103 if (R.Kind == Result::RK_Declaration &&
8104 isa<ObjCMethodDecl>(R.Declaration)) {
8105 if (R.Priority <= BestPriority) {
8106 const ObjCMethodDecl *Method = cast<ObjCMethodDecl>(R.Declaration);
8107 if (NumSelIdents <= Method->param_size()) {
8109 Method->
parameters()[NumSelIdents - 1]->getType();
8110 if (R.Priority < BestPriority || PreferredType.
isNull()) {
8111 BestPriority = R.Priority;
8112 PreferredType = MyPreferredType;
8122 return PreferredType;
8128 bool AtArgumentExpression,
bool IsSuper,
8129 ResultBuilder &Results) {
8144 Results.EnterNewScope();
8151 Results.Ignore(SuperMethod);
8157 Results.setPreferredSelector(CurMethod->getSelector());
8162 Selectors, AtArgumentExpression, Results);
8169 for (uint32_t I = 0,
8184 MethList && MethList->
getMethod(); MethList = MethList->getNext()) {
8188 Result R(MethList->getMethod(),
8189 Results.getBasePriority(MethList->getMethod()),
nullptr);
8190 R.StartParameter = SelIdents.size();
8191 R.AllParametersAreInformative =
false;
8192 Results.MaybeAddResult(R, SemaRef.
CurContext);
8197 Results.ExitScope();
8202 bool AtArgumentExpression,
8205 QualType T = this->GetTypeFromParser(Receiver);
8207 ResultBuilder Results(
8208 *
this, CodeCompleter->getAllocator(),
8209 CodeCompleter->getCodeCompletionTUInfo(),
8214 AtArgumentExpression, IsSuper, Results);
8221 if (AtArgumentExpression) {
8224 if (PreferredType.
isNull())
8225 CodeCompleteOrdinaryName(S, PCC_Expression);
8227 CodeCompleteExpression(S, PreferredType);
8232 Results.data(), Results.size());
8237 bool AtArgumentExpression,
8241 Expr *RecExpr =
static_cast<Expr *
>(Receiver);
8246 ExprResult Conv = DefaultFunctionArrayLvalueConversion(RecExpr);
8249 RecExpr = Conv.
get();
8263 return CodeCompleteObjCClassMessage(
8265 AtArgumentExpression, Super);
8270 }
else if (RecExpr && getLangOpts().
CPlusPlus) {
8271 ExprResult Conv = PerformContextuallyConvertToObjCPointer(RecExpr);
8273 RecExpr = Conv.
get();
8274 ReceiverType = RecExpr->
getType();
8279 ResultBuilder Results(
8280 *
this, CodeCompleter->getAllocator(),
8281 CodeCompleter->getCodeCompletionTUInfo(),
8283 ReceiverType, SelIdents));
8285 Results.EnterNewScope();
8292 Results.Ignore(SuperMethod);
8298 Results.setPreferredSelector(CurMethod->getSelector());
8311 Selectors, AtArgumentExpression, Results);
8318 for (
auto *I : QualID->quals())
8320 AtArgumentExpression, Results);
8327 CurContext, Selectors, AtArgumentExpression, Results);
8330 for (
auto *I : IFacePtr->quals())
8332 AtArgumentExpression, Results);
8345 if (Sel.
isNull() || MethodPool.count(Sel))
8348 ReadMethodPool(Sel);
8353 MEnd = MethodPool.end();
8356 MethList && MethList->
getMethod(); MethList = MethList->getNext()) {
8360 if (!Selectors.insert(MethList->getMethod()->getSelector()).second)
8363 Result R(MethList->getMethod(),
8364 Results.getBasePriority(MethList->getMethod()),
nullptr);
8365 R.StartParameter = SelIdents.size();
8366 R.AllParametersAreInformative =
false;
8367 Results.MaybeAddResult(R, CurContext);
8371 Results.ExitScope();
8378 if (AtArgumentExpression) {
8381 if (PreferredType.
isNull())
8382 CodeCompleteOrdinaryName(S, PCC_Expression);
8384 CodeCompleteExpression(S, PreferredType);
8389 Results.data(), Results.size());
8395 Data.ObjCCollection =
true;
8401 Data.IgnoreDecls.push_back(*I);
8405 CodeCompleteExpression(S,
Data);
8416 if (Sel.
isNull() || MethodPool.count(Sel))
8419 ReadMethodPool(Sel);
8423 ResultBuilder Results(*
this, CodeCompleter->getAllocator(),
8424 CodeCompleter->getCodeCompletionTUInfo(),
8426 Results.EnterNewScope();
8428 MEnd = MethodPool.end();
8436 Results.getCodeCompletionTUInfo());
8438 Builder.AddTypedTextChunk(
8440 Results.AddResult(Builder.TakeString());
8444 std::string Accumulator;
8445 for (
unsigned I = 0, N = Sel.
getNumArgs(); I != N; ++I) {
8446 if (I == SelIdents.size()) {
8447 if (!Accumulator.empty()) {
8448 Builder.AddInformativeChunk(
8449 Builder.getAllocator().CopyString(Accumulator));
8450 Accumulator.clear();
8457 Builder.AddTypedTextChunk(Builder.getAllocator().CopyString(Accumulator));
8458 Results.AddResult(Builder.TakeString());
8460 Results.ExitScope();
8463 Results.data(), Results.size());
8469 bool OnlyForwardDeclarations,
8470 ResultBuilder &Results) {
8473 for (
const auto *D : Ctx->
decls()) {
8475 if (
const auto *Proto = dyn_cast<ObjCProtocolDecl>(D))
8476 if (!OnlyForwardDeclarations || !Proto->hasDefinition())
8478 Result(Proto, Results.getBasePriority(Proto),
nullptr), CurContext,
8485 ResultBuilder Results(*
this, CodeCompleter->getAllocator(),
8486 CodeCompleter->getCodeCompletionTUInfo(),
8489 if (CodeCompleter->includeGlobals()) {
8490 Results.EnterNewScope();
8497 Results.Ignore(Protocol);
8503 Results.ExitScope();
8507 Results.data(), Results.size());
8511 ResultBuilder Results(*
this, CodeCompleter->getAllocator(),
8512 CodeCompleter->getCodeCompletionTUInfo(),
8515 if (CodeCompleter->includeGlobals()) {
8516 Results.EnterNewScope();
8522 Results.ExitScope();
8526 Results.data(), Results.size());
8532 bool OnlyForwardDeclarations,
8533 bool OnlyUnimplemented,
8534 ResultBuilder &Results) {
8537 for (
const auto *D : Ctx->
decls()) {
8539 if (
const auto *
Class = dyn_cast<ObjCInterfaceDecl>(D))
8540 if ((!OnlyForwardDeclarations || !
Class->hasDefinition()) &&
8541 (!OnlyUnimplemented || !
Class->getImplementation()))
8549 ResultBuilder Results(*
this, CodeCompleter->getAllocator(),
8550 CodeCompleter->getCodeCompletionTUInfo(),
8552 Results.EnterNewScope();
8554 if (CodeCompleter->includeGlobals()) {
8560 Results.ExitScope();
8563 Results.data(), Results.size());
8567 ResultBuilder Results(*
this, CodeCompleter->getAllocator(),
8568 CodeCompleter->getCodeCompletionTUInfo(),
8570 Results.EnterNewScope();
8572 if (CodeCompleter->includeGlobals()) {
8578 Results.ExitScope();
8581 Results.data(), Results.size());
8586 ResultBuilder Results(*
this, CodeCompleter->getAllocator(),
8587 CodeCompleter->getCodeCompletionTUInfo(),
8589 Results.EnterNewScope();
8593 LookupSingleName(TUScope, ClassName, ClassNameLoc, LookupOrdinaryName);
8594 if (CurClass && isa<ObjCInterfaceDecl>(CurClass))
8595 Results.Ignore(CurClass);
8597 if (CodeCompleter->includeGlobals()) {
8603 Results.ExitScope();
8606 Results.data(), Results.size());
8610 ResultBuilder Results(*
this, CodeCompleter->getAllocator(),
8611 CodeCompleter->getCodeCompletionTUInfo(),
8613 Results.EnterNewScope();
8615 if (CodeCompleter->includeGlobals()) {
8621 Results.ExitScope();
8624 Results.data(), Results.size());
8632 ResultBuilder Results(*
this, CodeCompleter->getAllocator(),
8633 CodeCompleter->getCodeCompletionTUInfo(),
8640 LookupSingleName(TUScope, ClassName, ClassNameLoc, LookupOrdinaryName);
8642 dyn_cast_or_null<ObjCInterfaceDecl>(CurClass)) {
8643 for (
const auto *Cat :
Class->visible_categories())
8644 CategoryNames.insert(Cat->getIdentifier());
8648 Results.EnterNewScope();
8650 for (
const auto *D : TU->
decls())
8651 if (
const auto *
Category = dyn_cast<ObjCCategoryDecl>(D))
8652 if (CategoryNames.insert(
Category->getIdentifier()).second)
8655 CurContext,
nullptr,
false);
8656 Results.ExitScope();
8659 Results.data(), Results.size());
8671 LookupSingleName(TUScope, ClassName, ClassNameLoc, LookupOrdinaryName);
8674 return CodeCompleteObjCInterfaceCategory(S, ClassName, ClassNameLoc);
8676 ResultBuilder Results(*
this, CodeCompleter->getAllocator(),
8677 CodeCompleter->getCodeCompletionTUInfo(),
8684 Results.EnterNewScope();
8685 bool IgnoreImplemented =
true;
8687 for (
const auto *Cat :
Class->visible_categories()) {
8688 if ((!IgnoreImplemented || !Cat->getImplementation()) &&
8689 CategoryNames.insert(Cat->getIdentifier()).second)
8690 Results.AddResult(
Result(Cat, Results.getBasePriority(Cat),
nullptr),
8691 CurContext,
nullptr,
false);
8695 IgnoreImplemented =
false;
8697 Results.ExitScope();
8700 Results.data(), Results.size());
8705 ResultBuilder Results(*
this, CodeCompleter->getAllocator(),
8706 CodeCompleter->getCodeCompletionTUInfo(), CCContext);
8710 dyn_cast_or_null<ObjCContainerDecl>(CurContext);
8711 if (!Container || (!isa<ObjCImplementationDecl>(Container) &&
8712 !isa<ObjCCategoryImplDecl>(Container)))
8717 for (
const auto *D : Container->decls())
8718 if (
const auto *PropertyImpl = dyn_cast<ObjCPropertyImplDecl>(D))
8719 Results.Ignore(PropertyImpl->getPropertyDecl());
8723 Results.EnterNewScope();
8725 dyn_cast<ObjCImplementationDecl>(Container))
8728 AddedProperties, Results);
8731 cast<ObjCCategoryImplDecl>(Container)->getCategoryDecl(),
8732 false,
false, CurContext,
8733 AddedProperties, Results);
8734 Results.ExitScope();
8737 Results.data(), Results.size());
8743 ResultBuilder Results(*
this, CodeCompleter->getAllocator(),
8744 CodeCompleter->getCodeCompletionTUInfo(),
8749 dyn_cast_or_null<ObjCContainerDecl>(CurContext);
8750 if (!Container || (!isa<ObjCImplementationDecl>(Container) &&
8751 !isa<ObjCCategoryImplDecl>(Container)))
8757 dyn_cast<ObjCImplementationDecl>(Container))
8758 Class = ClassImpl->getClassInterface();
8760 Class = cast<ObjCCategoryImplDecl>(Container)
8762 ->getClassInterface();
8770 Property->getType().getNonReferenceType().getUnqualifiedType();
8773 Results.setPreferredType(PropertyType);
8778 Results.EnterNewScope();
8779 bool SawSimilarlyNamedIvar =
false;
8780 std::string NameWithPrefix;
8781 NameWithPrefix +=
'_';
8782 NameWithPrefix += PropertyName->getName();
8783 std::string NameWithSuffix = PropertyName->getName().str();
8784 NameWithSuffix +=
'_';
8787 Ivar = Ivar->getNextIvar()) {
8788 Results.AddResult(
Result(Ivar, Results.getBasePriority(Ivar),
nullptr),
8789 CurContext,
nullptr,
false);
8793 if ((PropertyName == Ivar->getIdentifier() ||
8794 NameWithPrefix == Ivar->getName() ||
8795 NameWithSuffix == Ivar->getName())) {
8796 SawSimilarlyNamedIvar =
true;
8800 if (Results.size() &&
8801 Results.data()[Results.size() - 1].Kind ==
8803 Results.data()[Results.size() - 1].Declaration == Ivar)
8804 Results.data()[Results.size() - 1].Priority--;
8809 if (!SawSimilarlyNamedIvar) {
8819 Builder.AddResultTypeChunk(
8821 Builder.AddTypedTextChunk(Allocator.CopyString(NameWithPrefix));
8826 Results.ExitScope();
8829 Results.data(), Results.size());
8835 llvm::PointerIntPair<ObjCMethodDecl *, 1, bool>>
8844 std::optional<bool> WantInstanceMethods,
8847 bool InOriginalClass =
true) {
8850 if (!IFace->hasDefinition())
8853 IFace = IFace->getDefinition();
8857 IFace->getReferencedProtocols();
8859 E = Protocols.
end();
8862 KnownMethods, InOriginalClass);
8865 for (
auto *Cat : IFace->visible_categories()) {
8867 KnownMethods,
false);
8871 if (IFace->getSuperClass())
8873 WantInstanceMethods, ReturnType, KnownMethods,
8880 Category->getReferencedProtocols();
8882 E = Protocols.
end();
8885 KnownMethods, InOriginalClass);
8888 if (InOriginalClass &&
Category->getClassInterface())
8890 WantInstanceMethods, ReturnType, KnownMethods,
8896 if (!Protocol->hasDefinition())
8898 Protocol = Protocol->getDefinition();
8899 Container = Protocol;
8903 Protocol->getReferencedProtocols();
8905 E = Protocols.
end();
8908 KnownMethods,
false);
8914 for (
auto *M : Container->methods()) {
8915 if (!WantInstanceMethods || M->isInstanceMethod() == *WantInstanceMethods) {
8916 if (!ReturnType.
isNull() &&
8920 KnownMethods[M->getSelector()] =
8921 KnownMethodsMap::mapped_type(M, InOriginalClass);
8935 Builder.AddTextChunk(Builder.getAllocator().CopyString(Quals));
8936 Builder.AddTextChunk(
8947 if (
Class->getIdentifier() &&
Class->getIdentifier()->getName() == Name)
8956 bool IsInstanceMethod,
8959 ResultBuilder &Results) {
8961 if (!PropName || PropName->
getLength() == 0)
8979 const char *CopiedKey;
8982 : Allocator(Allocator), Key(Key), CopiedKey(
nullptr) {}
8984 operator const char *() {
8988 return CopiedKey = Allocator.CopyString(Key);
8990 } Key(Allocator, PropName->
getName());
8993 std::string UpperKey = std::string(PropName->
getName());
8994 if (!UpperKey.empty())
8997 bool ReturnTypeMatchesProperty =
9001 bool ReturnTypeMatchesVoid = ReturnType.
isNull() || ReturnType->
isVoidType();
9004 if (IsInstanceMethod &&
9006 ReturnTypeMatchesProperty && !
Property->getGetterMethodDecl()) {
9011 Builder.AddTypedTextChunk(Key);
9018 if (IsInstanceMethod &&
9019 ((!ReturnType.
isNull() &&
9022 Property->getType()->isBooleanType())))) {
9023 std::string SelectorName = (Twine(
"is") + UpperKey).str();
9027 if (ReturnType.
isNull()) {
9029 Builder.AddTextChunk(
"BOOL");
9033 Builder.AddTypedTextChunk(Allocator.CopyString(SelectorId->
getName()));
9040 if (IsInstanceMethod && ReturnTypeMatchesVoid &&
9041 !
Property->getSetterMethodDecl()) {
9042 std::string SelectorName = (Twine(
"set") + UpperKey).str();
9044 if (KnownSelectors.insert(Selectors.
getUnarySelector(SelectorId)).second) {
9045 if (ReturnType.
isNull()) {
9047 Builder.AddTextChunk(
"void");
9051 Builder.AddTypedTextChunk(
9052 Allocator.CopyString(SelectorId->
getName() +
":"));
9055 Builder.AddTextChunk(Key);
9066 if (
const auto *ObjCPointer =
9091 if (IsInstanceMethod &&
9093 std::string SelectorName = (Twine(
"countOf") + UpperKey).str();
9097 if (ReturnType.
isNull()) {
9099 Builder.AddTextChunk(
"NSUInteger");
9103 Builder.AddTypedTextChunk(Allocator.CopyString(SelectorId->
getName()));
9105 Result(Builder.TakeString(),
9106 std::min(IndexedGetterPriority, UnorderedGetterPriority),
9113 if (IsInstanceMethod &&
9115 std::string SelectorName = (Twine(
"objectIn") + UpperKey +
"AtIndex").str();
9117 if (KnownSelectors.insert(Selectors.
getUnarySelector(SelectorId)).second) {
9118 if (ReturnType.
isNull()) {
9120 Builder.AddTextChunk(
"id");
9124 Builder.AddTypedTextChunk(Allocator.CopyString(SelectorName +
":"));
9126 Builder.AddTextChunk(
"NSUInteger");
9128 Builder.AddTextChunk(
"index");
9129 Results.AddResult(
Result(Builder.TakeString(), IndexedGetterPriority,
9135 if (IsInstanceMethod &&
9142 std::string SelectorName = (Twine(
Property->getName()) +
"AtIndexes").str();
9144 if (KnownSelectors.insert(Selectors.
getUnarySelector(SelectorId)).second) {
9145 if (ReturnType.
isNull()) {
9147 Builder.AddTextChunk(
"NSArray *");
9151 Builder.AddTypedTextChunk(Allocator.CopyString(SelectorName +
":"));
9153 Builder.AddTextChunk(
"NSIndexSet *");
9155 Builder.AddTextChunk(
"indexes");
9156 Results.AddResult(
Result(Builder.TakeString(), IndexedGetterPriority,
9162 if (IsInstanceMethod && ReturnTypeMatchesVoid) {
9163 std::string SelectorName = (Twine(
"get") + UpperKey).str();
9167 if (KnownSelectors.insert(Selectors.
getSelector(2, SelectorIds)).second) {
9168 if (ReturnType.
isNull()) {
9170 Builder.AddTextChunk(
"void");
9174 Builder.AddTypedTextChunk(Allocator.CopyString(SelectorName +
":"));
9176 Builder.AddPlaceholderChunk(
"object-type");
9177 Builder.AddTextChunk(
" **");
9179 Builder.AddTextChunk(
"buffer");
9181 Builder.AddTypedTextChunk(
"range:");
9183 Builder.AddTextChunk(
"NSRange");
9185 Builder.AddTextChunk(
"inRange");
9186 Results.AddResult(
Result(Builder.TakeString(), IndexedGetterPriority,
9194 if (IsInstanceMethod && ReturnTypeMatchesVoid) {
9195 std::string SelectorName = (Twine(
"in") + UpperKey +
"AtIndex").str();
9199 if (KnownSelectors.insert(Selectors.
getSelector(2, SelectorIds)).second) {
9200 if (ReturnType.
isNull()) {
9202 Builder.AddTextChunk(
"void");
9206 Builder.AddTypedTextChunk(
"insertObject:");
9208 Builder.AddPlaceholderChunk(
"object-type");
9209 Builder.AddTextChunk(
" *");
9211 Builder.AddTextChunk(
"object");
9213 Builder.AddTypedTextChunk(Allocator.CopyString(SelectorName +
":"));
9215 Builder.AddPlaceholderChunk(
"NSUInteger");
9217 Builder.AddTextChunk(
"index");
9218 Results.AddResult(
Result(Builder.TakeString(), IndexedSetterPriority,
9224 if (IsInstanceMethod && ReturnTypeMatchesVoid) {
9225 std::string SelectorName = (Twine(
"insert") + UpperKey).str();
9229 if (KnownSelectors.insert(Selectors.
getSelector(2, SelectorIds)).second) {
9230 if (ReturnType.
isNull()) {
9232 Builder.AddTextChunk(
"void");
9236 Builder.AddTypedTextChunk(Allocator.CopyString(SelectorName +
":"));
9238 Builder.AddTextChunk(
"NSArray *");
9240 Builder.AddTextChunk(
"array");
9242 Builder.AddTypedTextChunk(
"atIndexes:");
9244 Builder.AddPlaceholderChunk(
"NSIndexSet *");
9246 Builder.AddTextChunk(
"indexes");
9247 Results.AddResult(
Result(Builder.TakeString(), IndexedSetterPriority,
9253 if (IsInstanceMethod && ReturnTypeMatchesVoid) {
9254 std::string SelectorName =
9255 (Twine(
"removeObjectFrom") + UpperKey +
"AtIndex").str();
9257 if (KnownSelectors.insert(Selectors.
getUnarySelector(SelectorId)).second) {
9258 if (ReturnType.
isNull()) {
9260 Builder.AddTextChunk(
"void");
9264 Builder.AddTypedTextChunk(Allocator.CopyString(SelectorName +
":"));
9266 Builder.AddTextChunk(
"NSUInteger");
9268 Builder.AddTextChunk(
"index");
9269 Results.AddResult(
Result(Builder.TakeString(), IndexedSetterPriority,
9275 if (IsInstanceMethod && ReturnTypeMatchesVoid) {
9276 std::string SelectorName = (Twine(
"remove") + UpperKey +
"AtIndexes").str();
9278 if (KnownSelectors.insert(Selectors.
getUnarySelector(SelectorId)).second) {
9279 if (ReturnType.
isNull()) {
9281 Builder.AddTextChunk(
"void");
9285 Builder.AddTypedTextChunk(Allocator.CopyString(SelectorName +
":"));
9287 Builder.AddTextChunk(
"NSIndexSet *");
9289 Builder.AddTextChunk(
"indexes");
9290 Results.AddResult(
Result(Builder.TakeString(), IndexedSetterPriority,
9296 if (IsInstanceMethod && ReturnTypeMatchesVoid) {
9297 std::string SelectorName =
9298 (Twine(
"replaceObjectIn") + UpperKey +
"AtIndex").str();
9302 if (KnownSelectors.insert(Selectors.
getSelector(2, SelectorIds)).second) {
9303 if (ReturnType.
isNull()) {
9305 Builder.AddTextChunk(
"void");
9309 Builder.AddTypedTextChunk(Allocator.CopyString(SelectorName +
":"));
9311 Builder.AddPlaceholderChunk(
"NSUInteger");
9313 Builder.AddTextChunk(
"index");
9315 Builder.AddTypedTextChunk(
"withObject:");
9317 Builder.AddTextChunk(
"id");
9319 Builder.AddTextChunk(
"object");
9320 Results.AddResult(
Result(Builder.TakeString(), IndexedSetterPriority,
9326 if (IsInstanceMethod && ReturnTypeMatchesVoid) {
9327 std::string SelectorName1 =
9328 (Twine(
"replace") + UpperKey +
"AtIndexes").str();
9329 std::string SelectorName2 = (Twine(
"with") + UpperKey).str();
9333 if (KnownSelectors.insert(Selectors.
getSelector(2, SelectorIds)).second) {
9334 if (ReturnType.
isNull()) {
9336 Builder.AddTextChunk(
"void");
9340 Builder.AddTypedTextChunk(Allocator.CopyString(SelectorName1 +
":"));
9342 Builder.AddPlaceholderChunk(
"NSIndexSet *");
9344 Builder.AddTextChunk(
"indexes");
9346 Builder.AddTypedTextChunk(Allocator.CopyString(SelectorName2 +
":"));
9348 Builder.AddTextChunk(
"NSArray *");
9350 Builder.AddTextChunk(
"array");
9351 Results.AddResult(
Result(Builder.TakeString(), IndexedSetterPriority,
9358 if (IsInstanceMethod &&
9364 ->
getName() ==
"NSEnumerator"))) {
9365 std::string SelectorName = (Twine(
"enumeratorOf") + UpperKey).str();
9369 if (ReturnType.
isNull()) {
9371 Builder.AddTextChunk(
"NSEnumerator *");
9375 Builder.AddTypedTextChunk(Allocator.CopyString(SelectorName));
9376 Results.AddResult(
Result(Builder.TakeString(), UnorderedGetterPriority,
9382 if (IsInstanceMethod &&
9384 std::string SelectorName = (Twine(
"memberOf") + UpperKey).str();
9386 if (KnownSelectors.insert(Selectors.
getUnarySelector(SelectorId)).second) {
9387 if (ReturnType.
isNull()) {
9389 Builder.AddPlaceholderChunk(
"object-type");
9390 Builder.AddTextChunk(
" *");
9394 Builder.AddTypedTextChunk(Allocator.CopyString(SelectorName +
":"));
9396 if (ReturnType.
isNull()) {
9397 Builder.AddPlaceholderChunk(
"object-type");
9398 Builder.AddTextChunk(
" *");
9401 ReturnType, Context, Policy, Builder.getAllocator()));
9404 Builder.AddTextChunk(
"object");
9405 Results.AddResult(
Result(Builder.TakeString(), UnorderedGetterPriority,
9412 if (IsInstanceMethod && ReturnTypeMatchesVoid) {
9413 std::string SelectorName =
9414 (Twine(
"add") + UpperKey + Twine(
"Object")).str();
9416 if (KnownSelectors.insert(Selectors.
getUnarySelector(SelectorId)).second) {
9417 if (ReturnType.
isNull()) {
9419 Builder.AddTextChunk(
"void");
9423 Builder.AddTypedTextChunk(Allocator.CopyString(SelectorName +
":"));
9425 Builder.AddPlaceholderChunk(
"object-type");
9426 Builder.AddTextChunk(
" *");
9428 Builder.AddTextChunk(
"object");
9429 Results.AddResult(
Result(Builder.TakeString(), UnorderedSetterPriority,
9435 if (IsInstanceMethod && ReturnTypeMatchesVoid) {
9436 std::string SelectorName = (Twine(
"add") + UpperKey).str();
9438 if (KnownSelectors.insert(Selectors.
getUnarySelector(SelectorId)).second) {
9439 if (ReturnType.
isNull()) {
9441 Builder.AddTextChunk(
"void");
9445 Builder.AddTypedTextChunk(Allocator.CopyString(SelectorName +
":"));
9447 Builder.AddTextChunk(
"NSSet *");
9449 Builder.AddTextChunk(
"objects");
9450 Results.AddResult(
Result(Builder.TakeString(), UnorderedSetterPriority,
9456 if (IsInstanceMethod && ReturnTypeMatchesVoid) {
9457 std::string SelectorName =
9458 (Twine(
"remove") + UpperKey + Twine(
"Object")).str();
9460 if (KnownSelectors.insert(Selectors.
getUnarySelector(SelectorId)).second) {
9461 if (ReturnType.
isNull()) {
9463 Builder.AddTextChunk(
"void");
9467 Builder.AddTypedTextChunk(Allocator.CopyString(SelectorName +
":"));
9469 Builder.AddPlaceholderChunk(
"object-type");
9470 Builder.AddTextChunk(
" *");
9472 Builder.AddTextChunk(
"object");
9473 Results.AddResult(
Result(Builder.TakeString(), UnorderedSetterPriority,
9479 if (IsInstanceMethod && ReturnTypeMatchesVoid) {
9480 std::string SelectorName = (Twine(
"remove") + UpperKey).str();
9482 if (KnownSelectors.insert(Selectors.
getUnarySelector(SelectorId)).second) {
9483 if (ReturnType.
isNull()) {
9485 Builder.AddTextChunk(
"void");
9489 Builder.AddTypedTextChunk(Allocator.CopyString(SelectorName +
":"));
9491 Builder.AddTextChunk(
"NSSet *");
9493 Builder.AddTextChunk(
"objects");
9494 Results.AddResult(
Result(Builder.TakeString(), UnorderedSetterPriority,
9500 if (IsInstanceMethod && ReturnTypeMatchesVoid) {
9501 std::string SelectorName = (Twine(
"intersect") + UpperKey).str();
9503 if (KnownSelectors.insert(Selectors.
getUnarySelector(SelectorId)).second) {
9504 if (ReturnType.
isNull()) {
9506 Builder.AddTextChunk(
"void");
9510 Builder.AddTypedTextChunk(Allocator.CopyString(SelectorName +
":"));
9512 Builder.AddTextChunk(
"NSSet *");
9514 Builder.AddTextChunk(
"objects");
9515 Results.AddResult(
Result(Builder.TakeString(), UnorderedSetterPriority,
9522 if (!IsInstanceMethod &&
9529 std::string SelectorName =
9530 (Twine(
"keyPathsForValuesAffecting") + UpperKey).str();
9534 if (ReturnType.
isNull()) {
9536 Builder.AddTextChunk(
"NSSet<NSString *> *");
9540 Builder.AddTypedTextChunk(Allocator.CopyString(SelectorName));
9547 if (!IsInstanceMethod &&
9550 std::string SelectorName =
9551 (Twine(
"automaticallyNotifiesObserversOf") + UpperKey).str();
9555 if (ReturnType.
isNull()) {
9557 Builder.AddTextChunk(
"BOOL");
9561 Builder.AddTypedTextChunk(Allocator.CopyString(SelectorName));
9569 std::optional<bool> IsInstanceMethod,
9573 QualType ReturnType = GetTypeFromParser(ReturnTy);
9574 Decl *IDecl =
nullptr;
9581 bool IsInImplementation =
false;
9582 if (
Decl *D = IDecl) {
9584 SearchDecl = Impl->getClassInterface();
9585 IsInImplementation =
true;
9587 dyn_cast<ObjCCategoryImplDecl>(D)) {
9588 SearchDecl = CatImpl->getCategoryDecl();
9589 IsInImplementation =
true;
9591 SearchDecl = dyn_cast<ObjCContainerDecl>(D);
9594 if (!SearchDecl && S) {
9596 SearchDecl = dyn_cast<ObjCContainerDecl>(DC);
9612 ResultBuilder Results(*
this, CodeCompleter->getAllocator(),
9613 CodeCompleter->getCodeCompletionTUInfo(),
9615 Results.EnterNewScope();
9617 for (KnownMethodsMap::iterator M = KnownMethods.begin(),
9618 MEnd = KnownMethods.end();
9622 Results.getCodeCompletionTUInfo());
9625 if (!IsInstanceMethod) {
9632 if (ReturnType.
isNull()) {
9643 Builder.AddTypedTextChunk(
9650 P != PEnd; (
void)++
P, ++I) {
9653 Builder.AddTypedTextChunk(
9657 Builder.AddTypedTextChunk(
9665 ParamType = (*P)->getType();
9667 ParamType = (*P)->getOriginalType();
9672 Context, Policy, Builder);
9675 Builder.AddTextChunk(
9676 Builder.getAllocator().CopyString(
Id->getName()));
9683 Builder.AddTextChunk(
"...");
9686 if (IsInImplementation && Results.includeCodePatterns()) {
9693 Builder.AddTextChunk(
"return");
9695 Builder.AddPlaceholderChunk(
"expression");
9698 Builder.AddPlaceholderChunk(
"statements");
9706 if (!M->second.getInt())
9708 Results.AddResult(std::move(R));
9715 Containers.push_back(SearchDecl);
9718 for (KnownMethodsMap::iterator M = KnownMethods.begin(),
9719 MEnd = KnownMethods.end();
9721 KnownSelectors.insert(M->first);
9726 IFace =
Category->getClassInterface();
9731 if (IsInstanceMethod) {
9732 for (
unsigned I = 0, N = Containers.size(); I != N; ++I)
9733 for (
auto *
P : Containers[I]->instance_properties())
9735 KnownSelectors, Results);
9739 Results.ExitScope();
9742 Results.data(), Results.size());
9746 Scope *S,
bool IsInstanceMethod,
bool AtParameterName,
ParsedType ReturnTy,
9754 if (Sel.
isNull() || MethodPool.count(Sel))
9757 ReadMethodPool(Sel);
9763 ResultBuilder Results(*
this, CodeCompleter->getAllocator(),
9764 CodeCompleter->getCodeCompletionTUInfo(),
9768 Results.setPreferredType(GetTypeFromParser(ReturnTy).getNonReferenceType());
9770 Results.EnterNewScope();
9772 MEnd = MethodPool.end();
9774 for (
ObjCMethodList *MethList = IsInstanceMethod ? &M->second.first
9775 : &M->second.second;
9776 MethList && MethList->getMethod(); MethList = MethList->getNext()) {
9780 if (AtParameterName) {
9782 unsigned NumSelIdents = SelIdents.size();
9784 NumSelIdents <= MethList->getMethod()->param_size()) {
9786 MethList->getMethod()->parameters()[NumSelIdents - 1];
9789 Results.getCodeCompletionTUInfo());
9790 Builder.AddTypedTextChunk(Builder.getAllocator().CopyString(
9792 Results.AddResult(Builder.TakeString());
9799 Result R(MethList->getMethod(),
9800 Results.getBasePriority(MethList->getMethod()),
nullptr);
9801 R.StartParameter = SelIdents.size();
9802 R.AllParametersAreInformative =
false;
9803 R.DeclaringEntity =
true;
9804 Results.MaybeAddResult(R, CurContext);
9808 Results.ExitScope();
9810 if (!AtParameterName && !SelIdents.empty() &&
9811 SelIdents.front()->getName().starts_with(
"init")) {
9812 for (
const auto &M : PP.macros()) {
9813 if (M.first->getName() !=
"NS_DESIGNATED_INITIALIZER")
9815 Results.EnterNewScope();
9817 Results.getCodeCompletionTUInfo());
9818 Builder.AddTypedTextChunk(
9819 Builder.getAllocator().CopyString(M.first->getName()));
9822 Results.ExitScope();
9827 Results.data(), Results.size());
9831 ResultBuilder Results(*
this, CodeCompleter->getAllocator(),
9832 CodeCompleter->getCodeCompletionTUInfo(),
9834 Results.EnterNewScope();
9838 Results.getCodeCompletionTUInfo());
9839 Builder.AddTypedTextChunk(
"if");
9841 Builder.AddPlaceholderChunk(
"condition");
9842 Results.AddResult(Builder.TakeString());
9845 Builder.AddTypedTextChunk(
"ifdef");
9847 Builder.AddPlaceholderChunk(
"macro");
9848 Results.AddResult(Builder.TakeString());
9851 Builder.AddTypedTextChunk(
"ifndef");
9853 Builder.AddPlaceholderChunk(
"macro");
9854 Results.AddResult(Builder.TakeString());
9856 if (InConditional) {
9858 Builder.AddTypedTextChunk(
"elif");
9860 Builder.AddPlaceholderChunk(
"condition");
9861 Results.AddResult(Builder.TakeString());
9864 Builder.AddTypedTextChunk(
"elifdef");
9866 Builder.AddPlaceholderChunk(
"macro");
9867 Results.AddResult(Builder.TakeString());
9870 Builder.AddTypedTextChunk(
"elifndef");
9872 Builder.AddPlaceholderChunk(
"macro");
9873 Results.AddResult(Builder.TakeString());
9876 Builder.AddTypedTextChunk(
"else");
9877 Results.AddResult(Builder.TakeString());
9880 Builder.AddTypedTextChunk(
"endif");
9881 Results.AddResult(Builder.TakeString());
9885 Builder.AddTypedTextChunk(
"include");
9887 Builder.AddTextChunk(
"\"");
9888 Builder.AddPlaceholderChunk(
"header");
9889 Builder.AddTextChunk(
"\"");
9890 Results.AddResult(Builder.TakeString());
9893 Builder.AddTypedTextChunk(
"include");
9895 Builder.AddTextChunk(
"<");
9896 Builder.AddPlaceholderChunk(
"header");
9897 Builder.AddTextChunk(
">");
9898 Results.AddResult(Builder.TakeString());
9901 Builder.AddTypedTextChunk(
"define");
9903 Builder.AddPlaceholderChunk(
"macro");
9904 Results.AddResult(Builder.TakeString());
9907 Builder.AddTypedTextChunk(
"define");
9909 Builder.AddPlaceholderChunk(
"macro");
9911 Builder.AddPlaceholderChunk(
"args");
9913 Results.AddResult(Builder.TakeString());
9916 Builder.AddTypedTextChunk(
"undef");
9918 Builder.AddPlaceholderChunk(
"macro");
9919 Results.AddResult(Builder.TakeString());
9922 Builder.AddTypedTextChunk(
"line");
9924 Builder.AddPlaceholderChunk(
"number");
9925 Results.AddResult(Builder.TakeString());
9928 Builder.AddTypedTextChunk(
"line");
9930 Builder.AddPlaceholderChunk(
"number");
9932 Builder.AddTextChunk(
"\"");
9933 Builder.AddPlaceholderChunk(
"filename");
9934 Builder.AddTextChunk(
"\"");
9935 Results.AddResult(Builder.TakeString());
9938 Builder.AddTypedTextChunk(
"error");
9940 Builder.AddPlaceholderChunk(
"message");
9941 Results.AddResult(Builder.TakeString());
9944 Builder.AddTypedTextChunk(
"pragma");
9946 Builder.AddPlaceholderChunk(
"arguments");
9947 Results.AddResult(Builder.TakeString());
9949 if (getLangOpts().
ObjC) {
9951 Builder.AddTypedTextChunk(
"import");
9953 Builder.AddTextChunk(
"\"");
9954 Builder.AddPlaceholderChunk(
"header");
9955 Builder.AddTextChunk(
"\"");
9956 Results.AddResult(Builder.TakeString());
9959 Builder.AddTypedTextChunk(
"import");
9961 Builder.AddTextChunk(
"<");
9962 Builder.AddPlaceholderChunk(
"header");
9963 Builder.AddTextChunk(
">");
9964 Results.AddResult(Builder.TakeString());
9968 Builder.AddTypedTextChunk(
"include_next");
9970 Builder.AddTextChunk(
"\"");
9971 Builder.AddPlaceholderChunk(
"header");
9972 Builder.AddTextChunk(
"\"");
9973 Results.AddResult(Builder.TakeString());
9976 Builder.AddTypedTextChunk(
"include_next");
9978 Builder.AddTextChunk(
"<");
9979 Builder.AddPlaceholderChunk(
"header");
9980 Builder.AddTextChunk(
">");
9981 Results.AddResult(Builder.TakeString());
9984 Builder.AddTypedTextChunk(
"warning");
9986 Builder.AddPlaceholderChunk(
"message");
9987 Results.AddResult(Builder.TakeString());
9994 Results.ExitScope();
9997 Results.data(), Results.size());
10006 ResultBuilder Results(*
this, CodeCompleter->getAllocator(),
10007 CodeCompleter->getCodeCompletionTUInfo(),
10010 if (!IsDefinition && CodeCompleter->includeMacros()) {
10013 Results.getCodeCompletionTUInfo());
10014 Results.EnterNewScope();
10016 MEnd = PP.macro_end();
10018 Builder.AddTypedTextChunk(
10019 Builder.getAllocator().CopyString(M->first->getName()));
10023 Results.ExitScope();
10024 }
else if (IsDefinition) {
10029 Results.data(), Results.size());
10033 ResultBuilder Results(*
this, CodeCompleter->getAllocator(),
10034 CodeCompleter->getCodeCompletionTUInfo(),
10037 if (CodeCompleter->includeMacros())
10041 Results.EnterNewScope();
10043 Results.getCodeCompletionTUInfo());
10044 Builder.AddTypedTextChunk(
"defined");
10047 Builder.AddPlaceholderChunk(
"macro");
10049 Results.AddResult(Builder.TakeString());
10050 Results.ExitScope();
10053 Results.data(), Results.size());
10059 unsigned Argument) {
10073 std::string RelDir = llvm::sys::path::convert_to_slash(Dir);
10076 llvm::sys::path::native(NativeRelDir);
10077 llvm::vfs::FileSystem &FS =
10078 getSourceManager().getFileManager().getVirtualFileSystem();
10080 ResultBuilder Results(*
this, CodeCompleter->getAllocator(),
10081 CodeCompleter->getCodeCompletionTUInfo(),
10086 auto AddCompletion = [&](StringRef
Filename,
bool IsDirectory) {
10089 TypedChunk.push_back(IsDirectory ?
'/' : Angled ?
'>' :
'"');
10090 auto R = SeenResults.insert(TypedChunk);
10092 const char *InternedTyped = Results.getAllocator().CopyString(TypedChunk);
10093 *R.first = InternedTyped;
10095 CodeCompleter->getCodeCompletionTUInfo());
10096 Builder.AddTypedTextChunk(InternedTyped);
10104 auto AddFilesFromIncludeDir = [&](StringRef IncludeDir,
10108 if (!NativeRelDir.empty()) {
10112 auto Begin = llvm::sys::path::begin(NativeRelDir);
10113 auto End = llvm::sys::path::end(NativeRelDir);
10115 llvm::sys::path::append(Dir, *
Begin +
".framework",
"Headers");
10116 llvm::sys::path::append(Dir, ++
Begin, End);
10118 llvm::sys::path::append(Dir, NativeRelDir);
10122 const StringRef &Dirname = llvm::sys::path::filename(Dir);
10123 const bool isQt = Dirname.starts_with(
"Qt") || Dirname ==
"ActiveQt";
10124 const bool ExtensionlessHeaders =
10125 IsSystem || isQt || Dir.ends_with(
".framework/Headers");
10126 std::error_code EC;
10127 unsigned Count = 0;
10128 for (
auto It = FS.dir_begin(Dir, EC);
10129 !EC && It != llvm::vfs::directory_iterator(); It.increment(EC)) {
10130 if (++Count == 2500)
10132 StringRef
Filename = llvm::sys::path::filename(It->path());
10137 llvm::sys::fs::file_type
Type = It->type();
10138 if (
Type == llvm::sys::fs::file_type::symlink_file) {
10139 if (
auto FileStatus = FS.status(It->path()))
10140 Type = FileStatus->getType();
10143 case llvm::sys::fs::file_type::directory_file:
10147 NativeRelDir.empty() && !
Filename.consume_back(
".framework"))
10152 case llvm::sys::fs::file_type::regular_file: {
10154 const bool IsHeader =
Filename.ends_with_insensitive(
".h") ||
10155 Filename.ends_with_insensitive(
".hh") ||
10156 Filename.ends_with_insensitive(
".hpp") ||
10157 Filename.ends_with_insensitive(
".hxx") ||
10158 Filename.ends_with_insensitive(
".inc") ||
10159 (ExtensionlessHeaders && !
Filename.contains(
'.'));
10174 switch (IncludeDir.getLookupType()) {
10179 AddFilesFromIncludeDir(IncludeDir.getDirRef()->getName(), IsSystem,
10183 AddFilesFromIncludeDir(IncludeDir.getFrameworkDirRef()->getName(),
10192 const auto &S = PP.getHeaderSearchInfo();
10193 using llvm::make_range;
10196 if (
auto CurFile = PP.getCurrentFileLexer()->getFileEntry())
10197 AddFilesFromIncludeDir(CurFile->getDir().getName(),
false,
10199 for (
const auto &D : make_range(S.quoted_dir_begin(), S.quoted_dir_end()))
10200 AddFilesFromDirLookup(D,
false);
10202 for (
const auto &D : make_range(S.angled_dir_begin(), S.angled_dir_end()))
10203 AddFilesFromDirLookup(D,
false);
10204 for (
const auto &D : make_range(S.system_dir_begin(), S.system_dir_end()))
10205 AddFilesFromDirLookup(D,
true);
10208 Results.data(), Results.size());
10218 ResultBuilder Results(*
this, CodeCompleter->getAllocator(),
10219 CodeCompleter->getCodeCompletionTUInfo(),
10221 Results.EnterNewScope();
10222 static const char *Platforms[] = {
"macOS",
"iOS",
"watchOS",
"tvOS"};
10226 Twine(Platform) +
"ApplicationExtension")));
10228 Results.ExitScope();
10230 Results.data(), Results.size());
10236 ResultBuilder Builder(*
this, Allocator, CCTUInfo,
10238 if (!CodeCompleter || CodeCompleter->includeGlobals()) {
10239 CodeCompletionDeclConsumer Consumer(Builder,
10243 !CodeCompleter || CodeCompleter->loadExternal());
10246 if (!CodeCompleter || CodeCompleter->includeMacros())
10248 !CodeCompleter || CodeCompleter->loadExternal(),
true);
10251 Results.insert(Results.end(), Builder.data(),
10252 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.
static bool argMatchesTemplateParams(const ParsedTemplateArgument &Arg, unsigned Index, const TemplateParameterList &Params)
static void setInBaseClass(ResultBuilder::Result &R)
static void AddFunctionSpecifiers(Sema::ParserCompletionContext CCC, const LangOptions &LangOpts, ResultBuilder &Results)
static bool shouldIgnoreDueToReservedName(const NamedDecl *ND, Sema &SemaRef)
static ObjCMethodDecl * AddSuperSendCompletion(Sema &S, bool NeedSuperKeyword, ArrayRef< IdentifierInfo * > SelIdents, ResultBuilder &Results)
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 bool isAcceptableObjCSelector(Selector Sel, ObjCMethodKind WantKind, ArrayRef< IdentifierInfo * > SelIdents, bool AllowSameLength=true)
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)
llvm::SmallPtrSet< IdentifierInfo *, 16 > AddedPropertiesSet
The set of properties that have already been added, referenced by property name.
static void AddClassMessageCompletions(Sema &SemaRef, Scope *S, ParsedType Receiver, ArrayRef< IdentifierInfo * > SelIdents, bool AtArgumentExpression, bool IsSuper, 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 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 bool isAcceptableObjCMethod(ObjCMethodDecl *Method, ObjCMethodKind WantKind, ArrayRef< IdentifierInfo * > SelIdents, bool AllowSameLength=true)
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 void AddObjCMethods(ObjCContainerDecl *Container, bool WantInstanceMethods, ObjCMethodKind WantKind, ArrayRef< 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 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 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 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::@1245::AnnotatingParser::Context::@328 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]).
CanProxy< U > getAs() const
Retrieve a canonical type pointer with a different static type, upcasting or downcasting as needed.
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.
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.
static NestedNameSpecifier * Create(const ASTContext &Context, NestedNameSpecifier *Prefix, IdentifierInfo *II)
Builds a specifier combining a prefix and an identifier.
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)
Qualifiers getLocalQualifiers() const
Retrieve the set of qualifiers local to this particular QualType instance, not including any qualifie...
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 getSelector(unsigned NumArgs, IdentifierInfo **IIV)
Can create any sort of selector.
Selector getNullarySelector(IdentifierInfo *ID)
Selector getUnarySelector(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.
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 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 CodeCompleteObjCMethodDeclSelector(Scope *S, bool IsInstanceMethod, bool AtParameterName, ParsedType ReturnType, ArrayRef< IdentifierInfo * > SelIdents)
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)
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 CodeCompleteObjCClassPropertyRefExpr(Scope *S, IdentifierInfo &ClassName, SourceLocation ClassNameLoc, bool IsBaseExprStatement)
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 CodeCompleteObjCSelector(Scope *S, ArrayRef< IdentifierInfo * > SelIdents)
void CodeCompleteObjCImplementationDecl(Scope *S)
void CodeCompleteObjCInstanceMessage(Scope *S, Expr *Receiver, ArrayRef< IdentifierInfo * > SelIdents, bool AtArgumentExpression, ObjCInterfaceDecl *Super=nullptr)
void CodeCompleteObjCPropertySetter(Scope *S)
void CodeCompleteFunctionQualifiers(DeclSpec &DS, Declarator &D, const VirtSpecifiers *VS=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)
void CodeCompleteObjCSuperMessage(Scope *S, SourceLocation SuperLoc, ArrayRef< IdentifierInfo * > SelIdents, bool AtArgumentExpression)
ExternalSemaSource * getExternalSource() const
void CodeCompleteObjCInterfaceCategory(Scope *S, IdentifierInfo *ClassName, SourceLocation ClassNameLoc)
void CodeCompleteObjCClassMessage(Scope *S, ParsedType Receiver, ArrayRef< IdentifierInfo * > SelIdents, bool AtArgumentExpression, bool IsSuper=false)
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 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.
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)
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...
const ASTTemplateArgumentListInfo * getTemplateArgsAsWritten() const
void print(llvm::raw_ostream &OS, const PrintingPolicy &Policy) const
ConceptDecl * getNamedConcept() 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...
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+.
@ 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.
@ 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.
@ 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.
SimplifiedTypeClass getSimplifiedTypeClass(CanQualType T)
Determine the simplified type class of the given canonical type.
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...
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)
@ 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....
@ 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.