48#include "llvm/ADT/ArrayRef.h"
49#include "llvm/ADT/DenseSet.h"
50#include "llvm/ADT/SmallBitVector.h"
51#include "llvm/ADT/SmallPtrSet.h"
52#include "llvm/ADT/SmallString.h"
53#include "llvm/ADT/StringSwitch.h"
54#include "llvm/ADT/Twine.h"
55#include "llvm/ADT/iterator_range.h"
56#include "llvm/Support/Casting.h"
57#include "llvm/Support/Path.h"
58#include "llvm/Support/raw_ostream.h"
77 typedef bool (ResultBuilder::*LookupFilter)(
const NamedDecl *)
const;
79 typedef CodeCompletionResult Result;
83 std::vector<Result> Results;
88 llvm::SmallPtrSet<const Decl *, 16> AllDeclsFound;
90 typedef std::pair<const NamedDecl *, unsigned> DeclIndexPair;
95 class ShadowMapEntry {
96 typedef SmallVector<DeclIndexPair, 4> DeclIndexPairVector;
100 llvm::PointerUnion<const NamedDecl *, DeclIndexPairVector *> DeclOrVector;
104 unsigned SingleDeclIndex = 0;
107 ShadowMapEntry() =
default;
108 ShadowMapEntry(
const ShadowMapEntry &) =
delete;
109 ShadowMapEntry(ShadowMapEntry &&Move) { *
this = std::move(Move); }
110 ShadowMapEntry &operator=(
const ShadowMapEntry &) =
delete;
111 ShadowMapEntry &operator=(ShadowMapEntry &&Move) {
112 SingleDeclIndex =
Move.SingleDeclIndex;
113 DeclOrVector =
Move.DeclOrVector;
114 Move.DeclOrVector =
nullptr;
118 void Add(
const NamedDecl *ND,
unsigned Index) {
119 if (DeclOrVector.isNull()) {
122 SingleDeclIndex = Index;
126 if (
const NamedDecl *PrevND = dyn_cast<const NamedDecl *>(DeclOrVector)) {
129 DeclIndexPairVector *Vec =
new DeclIndexPairVector;
130 Vec->push_back(DeclIndexPair(PrevND, SingleDeclIndex));
136 ->push_back(DeclIndexPair(ND, Index));
140 if (DeclIndexPairVector *Vec =
141 dyn_cast_if_present<DeclIndexPairVector *>(DeclOrVector)) {
143 DeclOrVector = ((NamedDecl *)
nullptr);
156 typedef llvm::DenseMap<DeclarationName, ShadowMapEntry> ShadowMap;
163 CodeCompletionAllocator &Allocator;
165 CodeCompletionTUInfo &CCTUInfo;
173 bool AllowNestedNameSpecifiers;
184 std::list<ShadowMap> ShadowMaps;
188 llvm::DenseMap<std::pair<DeclContext *,
uintptr_t>, ShadowMapEntry>
193 Qualifiers ObjectTypeQualifiers;
198 bool HasObjectTypeQualifiers;
201 bool IsExplicitObjectMemberFunction;
204 Selector PreferredSelector;
207 CodeCompletionContext CompletionContext;
211 ObjCImplementationDecl *ObjCImplementation;
213 void AdjustResultPriorityForDecl(Result &R);
215 void MaybeAddConstructorResults(Result R);
218 explicit ResultBuilder(Sema &SemaRef, CodeCompletionAllocator &Allocator,
219 CodeCompletionTUInfo &CCTUInfo,
220 const CodeCompletionContext &CompletionContext,
221 LookupFilter Filter =
nullptr)
222 : SemaRef(SemaRef), Allocator(Allocator), CCTUInfo(CCTUInfo),
223 Filter(Filter), AllowNestedNameSpecifiers(
false),
224 HasObjectTypeQualifiers(
false), IsExplicitObjectMemberFunction(
false),
225 CompletionContext(CompletionContext), ObjCImplementation(
nullptr) {
228 switch (CompletionContext.getKind()) {
229 case CodeCompletionContext::CCC_Expression:
230 case CodeCompletionContext::CCC_ObjCMessageReceiver:
231 case CodeCompletionContext::CCC_ParenthesizedExpression:
232 case CodeCompletionContext::CCC_Statement:
233 case CodeCompletionContext::CCC_TopLevelOrExpression:
234 case CodeCompletionContext::CCC_Recovery:
235 if (ObjCMethodDecl *Method = SemaRef.getCurMethodDecl())
236 if (Method->isInstanceMethod())
237 if (ObjCInterfaceDecl *Interface = Method->getClassInterface())
238 ObjCImplementation = Interface->getImplementation();
247 unsigned getBasePriority(
const NamedDecl *D);
251 bool includeCodePatterns()
const {
252 return SemaRef.CodeCompletion().CodeCompleter &&
253 SemaRef.CodeCompletion().CodeCompleter->includeCodePatterns();
257 void setFilter(LookupFilter Filter) { this->Filter = Filter; }
259 Result *data() {
return Results.empty() ?
nullptr : &Results.front(); }
260 unsigned size()
const {
return Results.size(); }
261 bool empty()
const {
return Results.empty(); }
264 void setPreferredType(QualType T) {
265 PreferredType = SemaRef.Context.getCanonicalType(T);
275 void setObjectTypeQualifiers(Qualifiers Quals,
ExprValueKind Kind) {
276 ObjectTypeQualifiers = Quals;
278 HasObjectTypeQualifiers =
true;
281 void setExplicitObjectMemberFn(
bool IsExplicitObjectFn) {
282 IsExplicitObjectMemberFunction = IsExplicitObjectFn;
290 void setPreferredSelector(Selector Sel) { PreferredSelector = Sel; }
294 const CodeCompletionContext &getCompletionContext()
const {
295 return CompletionContext;
299 void allowNestedNameSpecifiers(
bool Allow =
true) {
300 AllowNestedNameSpecifiers =
Allow;
305 Sema &getSema()
const {
return SemaRef; }
308 CodeCompletionAllocator &getAllocator()
const {
return Allocator; }
310 CodeCompletionTUInfo &getCodeCompletionTUInfo()
const {
return CCTUInfo; }
319 bool isInterestingDecl(
const NamedDecl *ND,
320 bool &AsNestedNameSpecifier)
const;
328 bool canFunctionBeCalled(
const NamedDecl *ND, QualType BaseExprType)
const;
336 bool canCxxMethodBeCalled(
const CXXMethodDecl *
Method,
337 QualType BaseExprType)
const;
345 bool CheckHiddenResult(Result &R, DeclContext *CurContext,
346 const NamedDecl *Hiding);
355 void MaybeAddResult(Result R, DeclContext *CurContext =
nullptr);
371 void AddResult(Result R, DeclContext *CurContext, NamedDecl *Hiding,
372 bool InBaseClass, QualType BaseExprType);
375 void AddResult(Result R);
378 void EnterNewScope();
387 void addVisitedContext(DeclContext *Ctx) {
388 CompletionContext.addVisitedContext(Ctx);
397 bool IsOrdinaryName(
const NamedDecl *ND)
const;
398 bool IsOrdinaryNonTypeName(
const NamedDecl *ND)
const;
399 bool IsIntegralConstantValue(
const NamedDecl *ND)
const;
400 bool IsOrdinaryNonValueName(
const NamedDecl *ND)
const;
401 bool IsNestedNameSpecifier(
const NamedDecl *ND)
const;
402 bool IsEnum(
const NamedDecl *ND)
const;
403 bool IsClassOrStruct(
const NamedDecl *ND)
const;
404 bool IsUnion(
const NamedDecl *ND)
const;
405 bool IsNamespace(
const NamedDecl *ND)
const;
406 bool IsNamespaceOrAlias(
const NamedDecl *ND)
const;
407 bool IsType(
const NamedDecl *ND)
const;
408 bool IsMember(
const NamedDecl *ND)
const;
409 bool IsObjCIvar(
const NamedDecl *ND)
const;
410 bool IsObjCMessageReceiver(
const NamedDecl *ND)
const;
411 bool IsObjCMessageReceiverOrLambdaCapture(
const NamedDecl *ND)
const;
412 bool IsObjCCollection(
const NamedDecl *ND)
const;
413 bool IsImpossibleToSatisfy(
const NamedDecl *ND)
const;
423 ComputeType =
nullptr;
424 Type = BSI->ReturnType;
428 ComputeType =
nullptr;
432 ComputeType =
nullptr;
433 Type =
Method->getReturnType();
441 auto *VD = llvm::dyn_cast_or_null<ValueDecl>(D);
442 ComputeType =
nullptr;
443 Type = VD ? VD->getType() :
QualType();
455 ComputeType =
nullptr;
465 this->ComputeType = ComputeType;
475 if (ExpectedLoc == LParLoc)
486 if (Op == tok::plus || Op == tok::plusequal || Op == tok::minusequal)
489 if (Op == tok::minus)
502 case tok::minusequal:
504 case tok::percentequal:
506 case tok::slashequal:
512 case tok::equalequal:
513 case tok::exclaimequal:
517 case tok::greaterequal:
521 case tok::greatergreater:
522 case tok::greatergreaterequal:
524 case tok::lesslessequal:
537 case tok::caretequal:
545 case tok::periodstar:
563 if (!ContextType.isNull() && ContextType->isPointerType())
564 return ContextType->getPointeeType();
567 if (ContextType.isNull())
573 case tok::minusminus:
575 if (ContextType.isNull())
583 assert(
false &&
"unhandled unary op");
592 ComputeType =
nullptr;
599 if (!Enabled || !
Base)
602 if (ExpectedLoc !=
Base->getBeginLoc())
613 ComputeType =
nullptr;
622 ComputeType =
nullptr;
631 ComputeType =
nullptr;
639 ComputeType =
nullptr;
645 llvm::PointerUnion<const NamedDecl *, const DeclIndexPair *> DeclOrIterator;
646 unsigned SingleDeclIndex;
658 pointer(
const DeclIndexPair &Value) : Value(Value) {}
666 : DeclOrIterator(SingleDecl), SingleDeclIndex(Index) {}
669 : DeclOrIterator(Iterator), SingleDeclIndex(0) {}
691 if (
const NamedDecl *ND = dyn_cast<const NamedDecl *>(DeclOrIterator))
700 return X.DeclOrIterator.getOpaqueValue() ==
701 Y.DeclOrIterator.getOpaqueValue() &&
702 X.SingleDeclIndex == Y.SingleDeclIndex;
711ResultBuilder::ShadowMapEntry::begin()
const {
712 if (DeclOrVector.isNull())
715 if (
const NamedDecl *ND = dyn_cast<const NamedDecl *>(DeclOrVector))
716 return iterator(ND, SingleDeclIndex);
722ResultBuilder::ShadowMapEntry::end()
const {
747 for (
const DeclContext *CommonAncestor = TargetContext;
748 CommonAncestor && !CommonAncestor->
Encloses(CurContext);
749 CommonAncestor = CommonAncestor->getLookupParent()) {
750 if (CommonAncestor->isTransparentContext() ||
751 CommonAncestor->isFunctionOrMethod())
754 TargetParents.push_back(CommonAncestor);
758 while (!TargetParents.empty()) {
759 const DeclContext *Parent = TargetParents.pop_back_val();
761 if (
const auto *Namespace = dyn_cast<NamespaceDecl>(Parent)) {
762 if (!Namespace->getIdentifier())
766 }
else if (
const auto *TD = dyn_cast<TagDecl>(Parent)) {
799bool ResultBuilder::isInterestingDecl(
const NamedDecl *ND,
800 bool &AsNestedNameSpecifier)
const {
801 AsNestedNameSpecifier =
false;
827 if (Filter == &ResultBuilder::IsNestedNameSpecifier ||
829 Filter != &ResultBuilder::IsNamespaceOrAlias && Filter !=
nullptr))
830 AsNestedNameSpecifier =
true;
833 if (Filter && !(this->*Filter)(Named)) {
835 if (AllowNestedNameSpecifiers && SemaRef.
getLangOpts().CPlusPlus &&
836 IsNestedNameSpecifier(ND) &&
837 (Filter != &ResultBuilder::IsMember ||
840 AsNestedNameSpecifier =
true;
859 R.Declaration->getDeclContext()->getRedeclContext();
870 R.QualifierIsInformative =
false;
874 R.Declaration->getDeclContext());
881 switch (T->getTypeClass()) {
884 case BuiltinType::Void:
887 case BuiltinType::NullPtr:
890 case BuiltinType::Overload:
891 case BuiltinType::Dependent:
894 case BuiltinType::ObjCId:
895 case BuiltinType::ObjCClass:
896 case BuiltinType::ObjCSel:
909 case Type::BlockPointer:
912 case Type::LValueReference:
913 case Type::RValueReference:
916 case Type::ConstantArray:
917 case Type::IncompleteArray:
918 case Type::VariableArray:
919 case Type::DependentSizedArray:
922 case Type::DependentSizedExtVector:
924 case Type::ExtVector:
927 case Type::FunctionProto:
928 case Type::FunctionNoProto:
937 case Type::ObjCObject:
938 case Type::ObjCInterface:
939 case Type::ObjCObjectPointer:
953 if (
const auto *
Type = dyn_cast<TypeDecl>(ND))
955 if (
const auto *Iface = dyn_cast<ObjCInterfaceDecl>(ND))
956 return C.getObjCInterfaceType(Iface);
961 else if (
const auto *
Method = dyn_cast<ObjCMethodDecl>(ND))
962 T =
Method->getSendResultType();
963 else if (
const auto *
Enumerator = dyn_cast<EnumConstantDecl>(ND))
967 else if (
const auto *
Property = dyn_cast<ObjCPropertyDecl>(ND))
969 else if (
const auto *
Value = dyn_cast<ValueDecl>(ND))
980 T = Ref->getPointeeType();
985 if (
Pointer->getPointeeType()->isFunctionType()) {
994 T =
Block->getPointeeType();
1009unsigned ResultBuilder::getBasePriority(
const NamedDecl *ND) {
1017 if (
const auto *ImplicitParam = dyn_cast<ImplicitParamDecl>(ND))
1018 if (ImplicitParam->getIdentifier() &&
1019 ImplicitParam->getIdentifier()->isStr(
"_cmd"))
1048 CompletionContext.
getKind() ==
1050 CompletionContext.
getKind() ==
1057void ResultBuilder::AdjustResultPriorityForDecl(
Result &R) {
1060 if (!PreferredSelector.
isNull())
1061 if (
const auto *
Method = dyn_cast<ObjCMethodDecl>(
R.Declaration))
1062 if (PreferredSelector ==
Method->getSelector())
1067 if (!PreferredType.
isNull()) {
1077 !(PreferredType->isEnumeralType() && TC->isEnumeralType()))
1087 Context.DeclarationNames.getCXXConstructorName(RecordTy);
1088 return Record->lookup(ConstructorName);
1091void ResultBuilder::MaybeAddConstructorResults(
Result R) {
1092 if (!SemaRef.
getLangOpts().CPlusPlus || !
R.Declaration ||
1099 Record = ClassTemplate->getTemplatedDecl();
1100 else if ((
Record = dyn_cast<CXXRecordDecl>(D))) {
1114 R.Declaration = Ctor;
1116 Results.push_back(R);
1121 if (
const auto *Tmpl = dyn_cast<FunctionTemplateDecl>(ND))
1122 ND = Tmpl->getTemplatedDecl();
1127 assert(!ShadowMaps.empty() &&
"Must enter into a results scope");
1129 if (
R.Kind != Result::RK_Declaration) {
1131 Results.push_back(R);
1136 if (
const UsingShadowDecl *Using = dyn_cast<UsingShadowDecl>(
R.Declaration)) {
1138 getBasePriority(
Using->getTargetDecl()),
1142 std::move(
R.FixIts));
1144 MaybeAddResult(
Result, CurContext);
1148 const Decl *CanonDecl =
R.Declaration->getCanonicalDecl();
1151 bool AsNestedNameSpecifier =
false;
1152 if (!isInterestingDecl(
R.Declaration, AsNestedNameSpecifier))
1159 ShadowMap &SMap = ShadowMaps.back();
1160 ShadowMapEntry::iterator I, IEnd;
1161 ShadowMap::iterator NamePos = SMap.find(
R.Declaration->getDeclName());
1162 if (NamePos != SMap.end()) {
1163 I = NamePos->second.begin();
1164 IEnd = NamePos->second.end();
1167 for (; I != IEnd; ++I) {
1169 unsigned Index = I->second;
1172 Results[Index].Declaration =
R.Declaration;
1182 std::list<ShadowMap>::iterator
SM, SMEnd = ShadowMaps.end();
1184 for (
SM = ShadowMaps.begin();
SM != SMEnd; ++
SM) {
1185 ShadowMapEntry::iterator I, IEnd;
1186 ShadowMap::iterator NamePos =
SM->find(
R.Declaration->getDeclName());
1187 if (NamePos !=
SM->end()) {
1188 I = NamePos->second.begin();
1189 IEnd = NamePos->second.end();
1191 for (; I != IEnd; ++I) {
1193 if (I->first->hasTagIdentifierNamespace() &&
1201 I->first->getIdentifierNamespace() != IDNS)
1205 if (CheckHiddenResult(R, CurContext, I->first))
1213 if (!AllDeclsFound.insert(CanonDecl).second)
1218 if (AsNestedNameSpecifier) {
1219 R.StartsNestedNameSpecifier =
true;
1222 AdjustResultPriorityForDecl(R);
1225 if (
R.QualifierIsInformative && !
R.Qualifier &&
1226 !
R.StartsNestedNameSpecifier) {
1227 const DeclContext *Ctx =
R.Declaration->getDeclContext();
1228 if (
const NamespaceDecl *Namespace = dyn_cast<NamespaceDecl>(Ctx))
1231 else if (
const TagDecl *Tag = dyn_cast<TagDecl>(Ctx))
1235 std::nullopt, Tag,
false)
1238 R.QualifierIsInformative =
false;
1243 SMap[
R.Declaration->getDeclName()].Add(
R.Declaration, Results.size());
1244 Results.push_back(R);
1246 if (!AsNestedNameSpecifier)
1247 MaybeAddConstructorResults(R);
1252 R.InBaseClass =
true;
1273 for (
unsigned I = 0, E = Candidate.
getNumParams(); I != E; ++I)
1274 if (Candidate.
parameters()[I]->getType().getCanonicalType() !=
1275 Incumbent.
parameters()[I]->getType().getCanonicalType())
1284 if (CandidateRef != IncumbentRef) {
1300 if (CandidateSuperset == IncumbentSuperset)
1312 const auto *CurrentClassScope = [&]() ->
const CXXRecordDecl * {
1314 const auto *CtxMethod = llvm::dyn_cast<CXXMethodDecl>(Ctx);
1315 if (CtxMethod && !CtxMethod->getParent()->isLambda()) {
1316 return CtxMethod->getParent();
1323 bool FunctionCanBeCall =
1324 CurrentClassScope &&
1325 (CurrentClassScope ==
Method->getParent() ||
1326 CurrentClassScope->isDerivedFrom(
Method->getParent()));
1329 if (FunctionCanBeCall)
1334 BaseExprType.
isNull() ?
nullptr
1336 auto *MaybeBase =
Method->getParent();
1338 MaybeDerived == MaybeBase || MaybeDerived->isDerivedFrom(MaybeBase);
1341 return FunctionCanBeCall;
1344bool ResultBuilder::canFunctionBeCalled(
const NamedDecl *ND,
1355 if (
const auto *FuncTmpl = dyn_cast<FunctionTemplateDecl>(ND)) {
1356 ND = FuncTmpl->getTemplatedDecl();
1358 const auto *
Method = dyn_cast<CXXMethodDecl>(ND);
1360 return canCxxMethodBeCalled(
Method, BaseExprType);
1367 NamedDecl *Hiding,
bool InBaseClass =
false,
1369 if (
R.Kind != Result::RK_Declaration) {
1371 Results.push_back(R);
1376 if (
const auto *Using = dyn_cast<UsingShadowDecl>(
R.Declaration)) {
1378 getBasePriority(
Using->getTargetDecl()),
1382 std::move(
R.FixIts));
1384 AddResult(
Result, CurContext, Hiding,
false,
1389 bool AsNestedNameSpecifier =
false;
1390 if (!isInterestingDecl(
R.Declaration, AsNestedNameSpecifier))
1397 if (Hiding && CheckHiddenResult(R, CurContext, Hiding))
1401 if (!AllDeclsFound.insert(
R.Declaration->getCanonicalDecl()).second)
1406 if (AsNestedNameSpecifier) {
1407 R.StartsNestedNameSpecifier =
true;
1409 }
else if (Filter == &ResultBuilder::IsMember && !
R.Qualifier &&
1412 R.Declaration->getDeclContext()->getRedeclContext()))
1413 R.QualifierIsInformative =
true;
1416 if (
R.QualifierIsInformative && !
R.Qualifier &&
1417 !
R.StartsNestedNameSpecifier) {
1418 const DeclContext *Ctx =
R.Declaration->getDeclContext();
1419 if (
const auto *Namespace = dyn_cast<NamespaceDecl>(Ctx))
1422 else if (
const auto *Tag = dyn_cast<TagDecl>(Ctx))
1426 std::nullopt, Tag,
false)
1429 R.QualifierIsInformative =
false;
1436 AdjustResultPriorityForDecl(R);
1439 const auto GetQualifiers = [&](
const CXXMethodDecl *MethodDecl) {
1440 if (MethodDecl->isExplicitObjectMemberFunction())
1441 return MethodDecl->getFunctionObjectParameterType().getQualifiers();
1443 return MethodDecl->getMethodQualifiers();
1446 if (IsExplicitObjectMemberFunction &&
1455 if (HasObjectTypeQualifiers)
1456 if (
const auto *
Method = dyn_cast<CXXMethodDecl>(
R.Declaration))
1457 if (
Method->isInstance()) {
1459 if (ObjectTypeQualifiers == MethodQuals)
1461 else if (ObjectTypeQualifiers - MethodQuals) {
1467 switch (
Method->getRefQualifier()) {
1484 CurContext,
Method->getDeclName().getAsOpaqueInteger())];
1486 Result &Incumbent = Results[Entry.second];
1489 ObjectTypeQualifiers, ObjectKind,
1495 Incumbent = std::move(R);
1507 R.FunctionCanBeCall = canFunctionBeCalled(
R.getDeclaration(), BaseExprType);
1510 Results.push_back(R);
1512 if (!AsNestedNameSpecifier)
1513 MaybeAddConstructorResults(R);
1516void ResultBuilder::AddResult(
Result R) {
1517 assert(
R.Kind != Result::RK_Declaration &&
1518 "Declaration results need more context");
1519 Results.push_back(R);
1523void ResultBuilder::EnterNewScope() { ShadowMaps.emplace_back(); }
1526void ResultBuilder::ExitScope() {
1527 ShadowMaps.pop_back();
1532bool ResultBuilder::IsOrdinaryName(
const NamedDecl *ND)
const {
1550bool ResultBuilder::IsOrdinaryNonTypeName(
const NamedDecl *ND)
const {
1557 if (
const auto *ID = dyn_cast<ObjCInterfaceDecl>(ND)) {
1558 if (!
ID->getDefinition())
1573bool ResultBuilder::IsIntegralConstantValue(
const NamedDecl *ND)
const {
1574 if (!IsOrdinaryNonTypeName(ND))
1578 if (VD->getType()->isIntegralOrEnumerationType())
1586bool ResultBuilder::IsOrdinaryNonValueName(
const NamedDecl *ND)
const {
1599bool ResultBuilder::IsNestedNameSpecifier(
const NamedDecl *ND)
const {
1601 if (
const auto *ClassTemplate = dyn_cast<ClassTemplateDecl>(ND))
1602 ND = ClassTemplate->getTemplatedDecl();
1608bool ResultBuilder::IsEnum(
const NamedDecl *ND)
const {
1613bool ResultBuilder::IsClassOrStruct(
const NamedDecl *ND)
const {
1615 if (
const auto *ClassTemplate = dyn_cast<ClassTemplateDecl>(ND))
1616 ND = ClassTemplate->getTemplatedDecl();
1619 if (
const auto *RD = dyn_cast<RecordDecl>(ND))
1628bool ResultBuilder::IsUnion(
const NamedDecl *ND)
const {
1630 if (
const auto *ClassTemplate = dyn_cast<ClassTemplateDecl>(ND))
1631 ND = ClassTemplate->getTemplatedDecl();
1633 if (
const auto *RD = dyn_cast<RecordDecl>(ND))
1640bool ResultBuilder::IsNamespace(
const NamedDecl *ND)
const {
1646bool ResultBuilder::IsNamespaceOrAlias(
const NamedDecl *ND)
const {
1651bool ResultBuilder::IsType(
const NamedDecl *ND)
const {
1659bool ResultBuilder::IsMember(
const NamedDecl *ND)
const {
1666 T =
C.getCanonicalType(T);
1667 switch (T->getTypeClass()) {
1668 case Type::ObjCObject:
1669 case Type::ObjCInterface:
1670 case Type::ObjCObjectPointer:
1675 case BuiltinType::ObjCId:
1676 case BuiltinType::ObjCClass:
1677 case BuiltinType::ObjCSel:
1689 if (!
C.getLangOpts().CPlusPlus)
1695 return T->isDependentType() || T->isRecordType();
1698bool ResultBuilder::IsObjCMessageReceiver(
const NamedDecl *ND)
const {
1708bool ResultBuilder::IsObjCMessageReceiverOrLambdaCapture(
1710 if (IsObjCMessageReceiver(ND))
1713 const auto *Var = dyn_cast<VarDecl>(ND);
1717 return Var->hasLocalStorage() && !Var->hasAttr<BlocksAttr>();
1720bool ResultBuilder::IsObjCCollection(
const NamedDecl *ND)
const {
1721 if ((SemaRef.
getLangOpts().CPlusPlus && !IsOrdinaryName(ND)) ||
1722 (!SemaRef.
getLangOpts().CPlusPlus && !IsOrdinaryNonTypeName(ND)))
1736bool ResultBuilder::IsImpossibleToSatisfy(
const NamedDecl *ND)
const {
1742bool ResultBuilder::IsObjCIvar(
const NamedDecl *ND)
const {
1751 ResultBuilder &Results;
1752 DeclContext *InitialLookupCtx;
1755 CXXRecordDecl *NamingClass;
1757 std::vector<FixItHint> FixIts;
1760 CodeCompletionDeclConsumer(
1761 ResultBuilder &Results, DeclContext *InitialLookupCtx,
1762 QualType BaseType = QualType(),
1763 std::vector<FixItHint> FixIts = std::vector<FixItHint>())
1764 : Results(Results), InitialLookupCtx(InitialLookupCtx),
1765 FixIts(std::move(FixIts)) {
1766 NamingClass = llvm::dyn_cast<CXXRecordDecl>(InitialLookupCtx);
1769 auto ThisType = Results.getSema().getCurrentThisType();
1770 if (!ThisType.isNull()) {
1771 assert(ThisType->isPointerType());
1777 this->BaseType = BaseType;
1780 void FoundDecl(NamedDecl *ND, NamedDecl *Hiding, DeclContext *Ctx,
1781 bool InBaseClass)
override {
1782 ResultBuilder::Result
Result(ND, Results.getBasePriority(ND),
1786 Results.AddResult(
Result, InitialLookupCtx, Hiding, InBaseClass, BaseType);
1789 void EnteredContext(DeclContext *Ctx)
override {
1790 Results.addVisitedContext(Ctx);
1799 auto *NamingClass = this->NamingClass;
1800 QualType BaseType = this->BaseType;
1801 if (
auto *Cls = llvm::dyn_cast_or_null<CXXRecordDecl>(Ctx)) {
1810 BaseType = QualType();
1816 NamingClass =
nullptr;
1817 BaseType = QualType();
1819 return Results.getSema().IsSimplyAccessible(ND, NamingClass, BaseType);
1826 ResultBuilder &Results) {
1853 Results.getCodeCompletionTUInfo());
1854 if (LangOpts.CPlusPlus) {
1862 Builder.AddTypedTextChunk(
"typename");
1864 Builder.AddPlaceholderChunk(
"name");
1865 Results.AddResult(
Result(Builder.TakeString()));
1867 if (LangOpts.CPlusPlus11) {
1872 Builder.AddTypedTextChunk(
"decltype");
1874 Builder.AddPlaceholderChunk(
"expression");
1876 Results.AddResult(
Result(Builder.TakeString()));
1879 if (LangOpts.Char8 || LangOpts.CPlusPlus20)
1885 if (LangOpts.GNUKeywords) {
1891 Builder.AddTypedTextChunk(
"typeof");
1893 Builder.AddPlaceholderChunk(
"expression");
1894 Results.AddResult(
Result(Builder.TakeString()));
1896 Builder.AddTypedTextChunk(
"typeof");
1898 Builder.AddPlaceholderChunk(
"type");
1900 Results.AddResult(
Result(Builder.TakeString()));
1911 const LangOptions &LangOpts, ResultBuilder &Results) {
1916 Results.AddResult(
Result(
"extern"));
1917 Results.AddResult(
Result(
"static"));
1919 if (LangOpts.CPlusPlus11) {
1924 Builder.AddTypedTextChunk(
"alignas");
1926 Builder.AddPlaceholderChunk(
"expression");
1928 Results.AddResult(
Result(Builder.TakeString()));
1930 Results.AddResult(
Result(
"constexpr"));
1931 Results.AddResult(
Result(
"thread_local"));
1934 if (LangOpts.CPlusPlus20)
1935 Results.AddResult(
Result(
"constinit"));
1940 const LangOptions &LangOpts, ResultBuilder &Results) {
1945 if (LangOpts.CPlusPlus) {
1946 Results.AddResult(
Result(
"explicit"));
1947 Results.AddResult(
Result(
"friend"));
1948 Results.AddResult(
Result(
"mutable"));
1949 Results.AddResult(
Result(
"virtual"));
1957 if (LangOpts.CPlusPlus || LangOpts.C99)
1958 Results.AddResult(
Result(
"inline"));
1960 if (LangOpts.CPlusPlus20)
1961 Results.AddResult(
Result(
"consteval"));
1981 ResultBuilder &Results,
bool NeedAt);
1983 ResultBuilder &Results,
bool NeedAt);
1985 ResultBuilder &Results,
bool NeedAt);
1990 Results.getCodeCompletionTUInfo());
1991 Builder.AddTypedTextChunk(
"typedef");
1993 Builder.AddPlaceholderChunk(
"type");
1995 Builder.AddPlaceholderChunk(
"name");
2002 ResultBuilder &Results) {
2003 Builder.AddTypedTextChunk(
"using");
2005 Builder.AddPlaceholderChunk(
"name");
2007 Builder.AddPlaceholderChunk(
"type");
2030 return LangOpts.CPlusPlus;
2037 return LangOpts.CPlusPlus || LangOpts.ObjC || LangOpts.C99;
2040 llvm_unreachable(
"Invalid ParserCompletionContext!");
2067 if (!T.getLocalQualifiers()) {
2069 if (
const BuiltinType *BT = dyn_cast<BuiltinType>(T))
2070 return BT->getNameAsCString(Policy);
2073 if (
const TagType *TagT = dyn_cast<TagType>(T))
2074 if (
TagDecl *Tag = TagT->getDecl())
2075 if (!Tag->hasNameForLinkage()) {
2076 switch (Tag->getTagKind()) {
2078 return "struct <anonymous>";
2080 return "__interface <anonymous>";
2082 return "class <anonymous>";
2084 return "union <anonymous>";
2086 return "enum <anonymous>";
2093 T.getAsStringInternal(Result, Policy);
2106 Builder.AddResultTypeChunk(
2108 Builder.AddTypedTextChunk(
"this");
2113 ResultBuilder &Results,
2115 if (!LangOpts.CPlusPlus11)
2118 Builder.AddTypedTextChunk(
"static_assert");
2120 Builder.AddPlaceholderChunk(
"expression");
2122 Builder.AddPlaceholderChunk(
"message");
2131 Sema &S = Results.getSema();
2132 const auto *CR = llvm::dyn_cast<CXXRecordDecl>(S.
CurContext);
2138 llvm::StringMap<std::vector<FunctionDecl *>> Overrides;
2139 for (
auto *Method : CR->methods()) {
2140 if (!Method->isVirtual() || !Method->getIdentifier())
2142 Overrides[Method->getName()].push_back(Method);
2145 for (
const auto &
Base : CR->bases()) {
2146 const auto *BR =
Base.getType().getTypePtr()->getAsCXXRecordDecl();
2149 for (
auto *Method : BR->methods()) {
2150 if (!Method->isVirtual() || !Method->getIdentifier())
2152 const auto it = Overrides.find(Method->getName());
2153 bool IsOverriden =
false;
2154 if (it != Overrides.end()) {
2155 for (
auto *MD : it->second) {
2173 false, CCContext, Policy);
2183 Scope *S,
Sema &SemaRef, ResultBuilder &Results) {
2191 if (Results.includeCodePatterns()) {
2193 Builder.AddTypedTextChunk(
"namespace");
2195 Builder.AddPlaceholderChunk(
"identifier");
2199 Builder.AddPlaceholderChunk(
"declarations");
2202 Results.AddResult(
Result(Builder.TakeString()));
2206 Builder.AddTypedTextChunk(
"namespace");
2208 Builder.AddPlaceholderChunk(
"name");
2210 Builder.AddPlaceholderChunk(
"namespace");
2212 Results.AddResult(
Result(Builder.TakeString()));
2215 Builder.AddTypedTextChunk(
"using namespace");
2217 Builder.AddPlaceholderChunk(
"identifier");
2219 Results.AddResult(
Result(Builder.TakeString()));
2222 Builder.AddTypedTextChunk(
"asm");
2224 Builder.AddPlaceholderChunk(
"string-literal");
2226 Results.AddResult(
Result(Builder.TakeString()));
2228 if (Results.includeCodePatterns()) {
2230 Builder.AddTypedTextChunk(
"template");
2232 Builder.AddPlaceholderChunk(
"declaration");
2233 Results.AddResult(
Result(Builder.TakeString()));
2244 if (!CurrentModule) {
2246 Builder.AddTypedTextChunk(
"module");
2249 Results.AddResult(
Result(Builder.TakeString()));
2254 if (!CurrentModule ||
2259 Builder.AddTypedTextChunk(
"module");
2261 Builder.AddPlaceholderChunk(
"name");
2264 Results.AddResult(
Result(Builder.TakeString()));
2269 if (!CurrentModule ||
2273 Builder.AddTypedTextChunk(
"import");
2275 Builder.AddPlaceholderChunk(
"name");
2278 Results.AddResult(
Result(Builder.TakeString()));
2281 if (CurrentModule &&
2285 Builder.AddTypedTextChunk(
"module");
2288 Builder.AddTypedTextChunk(
"private");
2291 Results.AddResult(
Result(Builder.TakeString()));
2296 if (!CurrentModule ||
2311 Builder.AddTypedTextChunk(
"using");
2313 Builder.AddPlaceholderChunk(
"qualifier");
2314 Builder.AddTextChunk(
"::");
2315 Builder.AddPlaceholderChunk(
"name");
2317 Results.AddResult(
Result(Builder.TakeString()));
2324 Builder.AddTypedTextChunk(
"using typename");
2326 Builder.AddPlaceholderChunk(
"qualifier");
2327 Builder.AddTextChunk(
"::");
2328 Builder.AddPlaceholderChunk(
"name");
2330 Results.AddResult(
Result(Builder.TakeString()));
2340 Builder.AddTypedTextChunk(
"public");
2341 if (IsNotInheritanceScope && Results.includeCodePatterns())
2343 Results.AddResult(
Result(Builder.TakeString()));
2346 Builder.AddTypedTextChunk(
"protected");
2347 if (IsNotInheritanceScope && Results.includeCodePatterns())
2349 Results.AddResult(
Result(Builder.TakeString()));
2352 Builder.AddTypedTextChunk(
"private");
2353 if (IsNotInheritanceScope && Results.includeCodePatterns())
2355 Results.AddResult(
Result(Builder.TakeString()));
2373 if (SemaRef.
getLangOpts().CPlusPlus && Results.includeCodePatterns()) {
2375 Builder.AddTypedTextChunk(
"template");
2377 Builder.AddPlaceholderChunk(
"parameters");
2379 Results.AddResult(
Result(Builder.TakeString()));
2417 if (SemaRef.
getLangOpts().CPlusPlus && Results.includeCodePatterns() &&
2419 Builder.AddTypedTextChunk(
"try");
2423 Builder.AddPlaceholderChunk(
"statements");
2427 Builder.AddTextChunk(
"catch");
2430 Builder.AddPlaceholderChunk(
"declaration");
2435 Builder.AddPlaceholderChunk(
"statements");
2438 Results.AddResult(
Result(Builder.TakeString()));
2443 if (Results.includeCodePatterns()) {
2445 Builder.AddTypedTextChunk(
"if");
2449 Builder.AddPlaceholderChunk(
"condition");
2451 Builder.AddPlaceholderChunk(
"expression");
2456 Builder.AddPlaceholderChunk(
"statements");
2459 Results.AddResult(
Result(Builder.TakeString()));
2462 Builder.AddTypedTextChunk(
"switch");
2466 Builder.AddPlaceholderChunk(
"condition");
2468 Builder.AddPlaceholderChunk(
"expression");
2473 Builder.AddPlaceholderChunk(
"cases");
2476 Results.AddResult(
Result(Builder.TakeString()));
2483 Builder.AddTypedTextChunk(
"case");
2485 Builder.AddPlaceholderChunk(
"expression");
2487 Results.AddResult(
Result(Builder.TakeString()));
2490 Builder.AddTypedTextChunk(
"default");
2492 Results.AddResult(
Result(Builder.TakeString()));
2495 if (Results.includeCodePatterns()) {
2497 Builder.AddTypedTextChunk(
"while");
2501 Builder.AddPlaceholderChunk(
"condition");
2503 Builder.AddPlaceholderChunk(
"expression");
2508 Builder.AddPlaceholderChunk(
"statements");
2511 Results.AddResult(
Result(Builder.TakeString()));
2514 Builder.AddTypedTextChunk(
"do");
2518 Builder.AddPlaceholderChunk(
"statements");
2521 Builder.AddTextChunk(
"while");
2524 Builder.AddPlaceholderChunk(
"expression");
2526 Results.AddResult(
Result(Builder.TakeString()));
2529 Builder.AddTypedTextChunk(
"for");
2533 Builder.AddPlaceholderChunk(
"init-statement");
2535 Builder.AddPlaceholderChunk(
"init-expression");
2538 Builder.AddPlaceholderChunk(
"condition");
2541 Builder.AddPlaceholderChunk(
"inc-expression");
2546 Builder.AddPlaceholderChunk(
"statements");
2549 Results.AddResult(
Result(Builder.TakeString()));
2553 Builder.AddTypedTextChunk(
"for");
2556 Builder.AddPlaceholderChunk(
"range-declaration");
2559 Builder.AddTextChunk(
"in");
2563 Builder.AddPlaceholderChunk(
"range-expression");
2568 Builder.AddPlaceholderChunk(
"statements");
2571 Results.AddResult(
Result(Builder.TakeString()));
2577 Builder.AddTypedTextChunk(
"continue");
2579 Results.AddResult(
Result(Builder.TakeString()));
2584 Builder.AddTypedTextChunk(
"break");
2586 Results.AddResult(
Result(Builder.TakeString()));
2591 if (
const auto *Function = dyn_cast<FunctionDecl>(SemaRef.
CurContext))
2592 ReturnType = Function->getReturnType();
2593 else if (
const auto *Method = dyn_cast<ObjCMethodDecl>(SemaRef.
CurContext))
2594 ReturnType = Method->getReturnType();
2599 Builder.AddTypedTextChunk(
"return");
2601 Results.AddResult(
Result(Builder.TakeString()));
2603 assert(!ReturnType.
isNull());
2605 Builder.AddTypedTextChunk(
"return");
2607 Builder.AddPlaceholderChunk(
"expression");
2609 Results.AddResult(
Result(Builder.TakeString()));
2612 Builder.AddTypedTextChunk(
"co_return");
2614 Builder.AddPlaceholderChunk(
"expression");
2616 Results.AddResult(
Result(Builder.TakeString()));
2620 Builder.AddTypedTextChunk(
"return true");
2622 Results.AddResult(
Result(Builder.TakeString()));
2624 Builder.AddTypedTextChunk(
"return false");
2626 Results.AddResult(
Result(Builder.TakeString()));
2631 Builder.AddTypedTextChunk(
"return nullptr");
2633 Results.AddResult(
Result(Builder.TakeString()));
2638 Builder.AddTypedTextChunk(
"goto");
2640 Builder.AddPlaceholderChunk(
"label");
2642 Results.AddResult(
Result(Builder.TakeString()));
2645 Builder.AddTypedTextChunk(
"using namespace");
2647 Builder.AddPlaceholderChunk(
"identifier");
2649 Results.AddResult(
Result(Builder.TakeString()));
2666 Builder.AddTypedTextChunk(
"__bridge");
2668 Builder.AddPlaceholderChunk(
"type");
2670 Builder.AddPlaceholderChunk(
"expression");
2671 Results.AddResult(
Result(Builder.TakeString()));
2674 Builder.AddTypedTextChunk(
"__bridge_transfer");
2676 Builder.AddPlaceholderChunk(
"Objective-C type");
2678 Builder.AddPlaceholderChunk(
"expression");
2679 Results.AddResult(
Result(Builder.TakeString()));
2682 Builder.AddTypedTextChunk(
"__bridge_retained");
2684 Builder.AddPlaceholderChunk(
"CF type");
2686 Builder.AddPlaceholderChunk(
"expression");
2687 Results.AddResult(
Result(Builder.TakeString()));
2698 Builder.AddResultTypeChunk(
"bool");
2699 Builder.AddTypedTextChunk(
"true");
2700 Results.AddResult(
Result(Builder.TakeString()));
2703 Builder.AddResultTypeChunk(
"bool");
2704 Builder.AddTypedTextChunk(
"false");
2705 Results.AddResult(
Result(Builder.TakeString()));
2709 Builder.AddTypedTextChunk(
"dynamic_cast");
2711 Builder.AddPlaceholderChunk(
"type");
2714 Builder.AddPlaceholderChunk(
"expression");
2716 Results.AddResult(
Result(Builder.TakeString()));
2720 Builder.AddTypedTextChunk(
"static_cast");
2722 Builder.AddPlaceholderChunk(
"type");
2725 Builder.AddPlaceholderChunk(
"expression");
2727 Results.AddResult(
Result(Builder.TakeString()));
2730 Builder.AddTypedTextChunk(
"reinterpret_cast");
2732 Builder.AddPlaceholderChunk(
"type");
2735 Builder.AddPlaceholderChunk(
"expression");
2737 Results.AddResult(
Result(Builder.TakeString()));
2740 Builder.AddTypedTextChunk(
"const_cast");
2742 Builder.AddPlaceholderChunk(
"type");
2745 Builder.AddPlaceholderChunk(
"expression");
2747 Results.AddResult(
Result(Builder.TakeString()));
2751 Builder.AddResultTypeChunk(
"std::type_info");
2752 Builder.AddTypedTextChunk(
"typeid");
2754 Builder.AddPlaceholderChunk(
"expression-or-type");
2756 Results.AddResult(
Result(Builder.TakeString()));
2760 Builder.AddTypedTextChunk(
"new");
2762 Builder.AddPlaceholderChunk(
"type");
2764 Builder.AddPlaceholderChunk(
"expressions");
2766 Results.AddResult(
Result(Builder.TakeString()));
2769 Builder.AddTypedTextChunk(
"new");
2771 Builder.AddPlaceholderChunk(
"type");
2773 Builder.AddPlaceholderChunk(
"size");
2776 Builder.AddPlaceholderChunk(
"expressions");
2778 Results.AddResult(
Result(Builder.TakeString()));
2781 Builder.AddResultTypeChunk(
"void");
2782 Builder.AddTypedTextChunk(
"delete");
2784 Builder.AddPlaceholderChunk(
"expression");
2785 Results.AddResult(
Result(Builder.TakeString()));
2788 Builder.AddResultTypeChunk(
"void");
2789 Builder.AddTypedTextChunk(
"delete");
2794 Builder.AddPlaceholderChunk(
"expression");
2795 Results.AddResult(
Result(Builder.TakeString()));
2799 Builder.AddResultTypeChunk(
"void");
2800 Builder.AddTypedTextChunk(
"throw");
2802 Builder.AddPlaceholderChunk(
"expression");
2803 Results.AddResult(
Result(Builder.TakeString()));
2810 Builder.AddResultTypeChunk(
"std::nullptr_t");
2811 Builder.AddTypedTextChunk(
"nullptr");
2812 Results.AddResult(
Result(Builder.TakeString()));
2815 Builder.AddResultTypeChunk(
"size_t");
2816 Builder.AddTypedTextChunk(
"alignof");
2818 Builder.AddPlaceholderChunk(
"type");
2820 Results.AddResult(
Result(Builder.TakeString()));
2823 Builder.AddResultTypeChunk(
"bool");
2824 Builder.AddTypedTextChunk(
"noexcept");
2826 Builder.AddPlaceholderChunk(
"expression");
2828 Results.AddResult(
Result(Builder.TakeString()));
2831 Builder.AddResultTypeChunk(
"size_t");
2832 Builder.AddTypedTextChunk(
"sizeof...");
2834 Builder.AddPlaceholderChunk(
"parameter-pack");
2836 Results.AddResult(
Result(Builder.TakeString()));
2841 Builder.AddTypedTextChunk(
"co_await");
2843 Builder.AddPlaceholderChunk(
"expression");
2844 Results.AddResult(
Result(Builder.TakeString()));
2847 Builder.AddTypedTextChunk(
"co_yield");
2849 Builder.AddPlaceholderChunk(
"expression");
2850 Results.AddResult(
Result(Builder.TakeString()));
2853 Builder.AddResultTypeChunk(
"bool");
2854 Builder.AddTypedTextChunk(
"requires");
2857 Builder.AddPlaceholderChunk(
"parameters");
2862 Builder.AddPlaceholderChunk(
"requirements");
2865 Results.AddResult(
Result(Builder.TakeString()));
2869 Builder.AddTypedTextChunk(
"requires");
2871 Builder.AddPlaceholderChunk(
"expression");
2873 Results.AddResult(
Result(Builder.TakeString()));
2883 if (ID->getSuperClass()) {
2884 std::string SuperType;
2885 SuperType = ID->getSuperClass()->getNameAsString();
2886 if (Method->isInstanceMethod())
2889 Builder.AddResultTypeChunk(Allocator.
CopyString(SuperType));
2890 Builder.AddTypedTextChunk(
"super");
2891 Results.AddResult(
Result(Builder.TakeString()));
2900 Builder.AddResultTypeChunk(
"size_t");
2902 Builder.AddTypedTextChunk(
"alignof");
2904 Builder.AddTypedTextChunk(
"_Alignof");
2906 Builder.AddPlaceholderChunk(
"type");
2908 Results.AddResult(
Result(Builder.TakeString()));
2913 Builder.AddResultTypeChunk(
"nullptr_t");
2914 Builder.AddTypedTextChunk(
"nullptr");
2915 Results.AddResult(
Result(Builder.TakeString()));
2919 Builder.AddResultTypeChunk(
"size_t");
2920 Builder.AddTypedTextChunk(
"sizeof");
2922 Builder.AddPlaceholderChunk(
"expression-or-type");
2924 Results.AddResult(
Result(Builder.TakeString()));
2937 Results.AddResult(
Result(
"operator"));
2957 T = Function->getReturnType();
2958 else if (
const auto *Method = dyn_cast<ObjCMethodDecl>(ND)) {
2959 if (!BaseType.isNull())
2960 T = Method->getSendResultType(BaseType);
2962 T = Method->getReturnType();
2963 }
else if (
const auto *
Enumerator = dyn_cast<EnumConstantDecl>(ND)) {
2964 T = Context.getCanonicalTagType(
2968 }
else if (
const auto *Ivar = dyn_cast<ObjCIvarDecl>(ND)) {
2969 if (!BaseType.isNull())
2970 T = Ivar->getUsageType(BaseType);
2972 T = Ivar->getType();
2973 }
else if (
const auto *
Value = dyn_cast<ValueDecl>(ND)) {
2975 }
else if (
const auto *Property = dyn_cast<ObjCPropertyDecl>(ND)) {
2976 if (!BaseType.isNull())
2977 T = Property->getUsageType(BaseType);
2979 T = Property->getType();
2982 if (T.isNull() || Context.hasSameType(T, Context.DependentTy))
2985 Result.AddResultTypeChunk(
2992 if (SentinelAttr *Sentinel = FunctionOrMethod->
getAttr<SentinelAttr>())
2993 if (Sentinel->getSentinel() == 0) {
2995 Result.AddTextChunk(
", nil");
2997 Result.AddTextChunk(
", NULL");
2999 Result.AddTextChunk(
", (void*)0");
3013 Result +=
"bycopy ";
3017 Result +=
"oneway ";
3019 if (
auto nullability = AttributedType::stripOuterNullability(
Type)) {
3020 switch (*nullability) {
3022 Result +=
"nonnull ";
3026 Result +=
"nullable ";
3030 Result +=
"null_unspecified ";
3034 llvm_unreachable(
"Not supported as a context-sensitive keyword!");
3051 bool SuppressBlock =
false) {
3057 if (!SuppressBlock) {
3060 TypedefTL.getDecl()->getTypeSourceInfo()) {
3073 TL = AttrTL.getModifiedLoc();
3092 bool SuppressBlockName =
false,
bool SuppressBlock =
false,
3097 bool SuppressName =
false,
bool SuppressBlock =
false,
3105 if (
const auto *PVD = dyn_cast<ParmVarDecl>(Param))
3106 ObjCQual = PVD->getObjCDeclQualifier();
3108 if (Param->getType()->isDependentType() ||
3109 !Param->getType()->isBlockPointerType()) {
3114 if (Param->getIdentifier() && !ObjCMethodParam && !SuppressName)
3115 Result = std::string(Param->getIdentifier()->deuglifiedName());
3119 Type =
Type.substObjCTypeArgs(Param->getASTContext(), *ObjCSubsts,
3121 if (ObjCMethodParam) {
3123 Result +=
Type.getAsString(Policy) +
")";
3124 if (Param->getIdentifier() && !SuppressName)
3125 Result += Param->getIdentifier()->deuglifiedName();
3127 Type.getAsStringInternal(Result, Policy);
3140 if (!
Block && ObjCMethodParam &&
3143 ->findPropertyDecl(
false))
3152 if (!ObjCMethodParam && Param->getIdentifier())
3153 Result = std::string(Param->getIdentifier()->deuglifiedName());
3157 if (ObjCMethodParam) {
3158 Result =
Type.getAsString(Policy);
3161 Result =
"(" + Quals +
" " + Result +
")";
3162 if (Result.back() !=
')')
3164 if (Param->getIdentifier())
3165 Result += Param->getIdentifier()->deuglifiedName();
3167 Type.getAsStringInternal(Result, Policy);
3176 false, SuppressBlock,
3192 bool SuppressBlockName,
bool SuppressBlock,
3200 if (!ResultType->
isVoidType() || SuppressBlock)
3205 if (!BlockProto ||
Block.getNumParams() == 0) {
3212 for (
unsigned I = 0, N =
Block.getNumParams(); I != N; ++I) {
3225 if (SuppressBlock) {
3227 Result = Result +
" (^";
3228 if (!SuppressBlockName &&
BlockDecl->getIdentifier())
3229 Result +=
BlockDecl->getIdentifier()->getName();
3234 Result =
'^' + Result;
3237 if (!SuppressBlockName &&
BlockDecl->getIdentifier())
3238 Result +=
BlockDecl->getIdentifier()->getName();
3247 const SourceRange SrcRange = Param->getDefaultArgRange();
3257 if (srcText.empty() || srcText ==
"=") {
3263 std::string DefValue(srcText.str());
3266 if (DefValue.at(0) !=
'=') {
3270 return " = " + DefValue;
3272 return " " + DefValue;
3281 bool InOptional =
false) {
3282 bool FirstParameter =
true;
3284 for (
unsigned P = Start, N = Function->getNumParams(); P != N; ++P) {
3285 const ParmVarDecl *Param = Function->getParamDecl(P);
3287 if (Param->hasDefaultArg() && !InOptional) {
3291 Result.getCodeCompletionTUInfo());
3292 if (!FirstParameter)
3302 if (FirstParameter && Param->isExplicitObjectParameter()) {
3307 FirstParameter =
false;
3315 if (Param->hasDefaultArg())
3319 if (Function->isVariadic() && P == N - 1)
3320 PlaceholderStr +=
", ...";
3323 Result.AddPlaceholderChunk(
3324 Result.getAllocator().CopyString(PlaceholderStr));
3328 if (Proto->isVariadic()) {
3329 if (Proto->getNumParams() == 0)
3330 Result.AddPlaceholderChunk(
"...");
3340 unsigned MaxParameters = 0,
unsigned Start = 0,
bool InDefaultArg =
false) {
3341 bool FirstParameter =
true;
3350 PEnd = Params->
begin() + MaxParameters;
3353 bool HasDefaultArg =
false;
3354 std::string PlaceholderStr;
3356 if (TTP->wasDeclaredWithTypename())
3357 PlaceholderStr =
"typename";
3358 else if (
const auto *TC = TTP->getTypeConstraint()) {
3359 llvm::raw_string_ostream OS(PlaceholderStr);
3360 TC->print(OS, Policy);
3362 PlaceholderStr =
"class";
3364 if (TTP->getIdentifier()) {
3365 PlaceholderStr +=
' ';
3366 PlaceholderStr += TTP->getIdentifier()->deuglifiedName();
3369 HasDefaultArg = TTP->hasDefaultArgument();
3371 dyn_cast<NonTypeTemplateParmDecl>(*P)) {
3372 if (NTTP->getIdentifier())
3373 PlaceholderStr = std::string(NTTP->getIdentifier()->deuglifiedName());
3374 NTTP->getType().getAsStringInternal(PlaceholderStr, Policy);
3375 HasDefaultArg = NTTP->hasDefaultArgument();
3382 PlaceholderStr =
"template<...> class";
3384 PlaceholderStr +=
' ';
3391 if (HasDefaultArg && !InDefaultArg) {
3395 Result.getCodeCompletionTUInfo());
3396 if (!FirstParameter)
3399 P - Params->
begin(),
true);
3404 InDefaultArg =
false;
3407 FirstParameter =
false;
3412 Result.AddPlaceholderChunk(
3413 Result.getAllocator().CopyString(PlaceholderStr));
3421 bool QualifierIsInformative,
3427 std::string PrintedNNS;
3429 llvm::raw_string_ostream OS(PrintedNNS);
3430 Qualifier.print(OS, Policy);
3432 if (QualifierIsInformative)
3433 Result.AddInformativeChunk(Result.getAllocator().CopyString(PrintedNNS));
3435 Result.AddTextChunk(Result.getAllocator().CopyString(PrintedNNS));
3444 Result.AddInformativeChunk(
" const");
3449 Result.AddInformativeChunk(
" volatile");
3454 Result.AddInformativeChunk(
" restrict");
3459 std::string QualsStr;
3461 QualsStr +=
" const";
3463 QualsStr +=
" volatile";
3465 QualsStr +=
" restrict";
3466 Result.AddInformativeChunk(Result.getAllocator().CopyString(QualsStr));
3472 if (
auto *CxxMethodDecl = llvm::dyn_cast_if_present<CXXMethodDecl>(Function);
3473 CxxMethodDecl && CxxMethodDecl->hasCXXExplicitFunctionObjectParameter()) {
3475 const auto Quals = CxxMethodDecl->getFunctionObjectParameterType();
3476 if (!Quals.hasQualifiers())
3482 if (!Proto || !Proto->getMethodQuals())
3497 switch (ExceptInfo.Type) {
3500 NameAndSignature +=
" noexcept";
3518 const char *OperatorName =
nullptr;
3521 case OO_Conditional:
3523 OperatorName =
"operator";
3526#define OVERLOADED_OPERATOR(Name, Spelling, Token, Unary, Binary, MemberOnly) \
3528 OperatorName = "operator" Spelling; \
3530#define OVERLOADED_OPERATOR_MULTI(Name, Spelling, Unary, Binary, MemberOnly)
3531#include "clang/Basic/OperatorKinds.def"
3534 OperatorName =
"operator new";
3537 OperatorName =
"operator delete";
3540 OperatorName =
"operator new[]";
3542 case OO_Array_Delete:
3543 OperatorName =
"operator delete[]";
3546 OperatorName =
"operator()";
3549 OperatorName =
"operator[]";
3552 Result.AddTypedTextChunk(OperatorName);
3560 Result.AddTypedTextChunk(
3577 Result.AddTypedTextChunk(
3582 Result.AddTypedTextChunk(
3583 Result.getAllocator().CopyString(
Record->getNameAsString()));
3597 bool IncludeBriefComments) {
3599 CCTUInfo, IncludeBriefComments);
3611 return Result.TakeString();
3622 Result.AddPlaceholderChunk(
"...");
3636 Result.AddPlaceholderChunk(
Result.getAllocator().CopyString(Arg));
3641 Result.AddPlaceholderChunk(
3642 Result.getAllocator().CopyString((*A)->getName()));
3645 return Result.TakeString();
3657 bool IncludeBriefComments) {
3673 Result.addBriefComment(RC->getBriefText(Ctx));
3683 return Result.TakeString();
3687 PP, Ctx,
Result, IncludeBriefComments, CCContext, Policy);
3691 std::string &BeforeName,
3692 std::string &NameAndSignature) {
3693 bool SeenTypedChunk =
false;
3694 for (
auto &Chunk : CCS) {
3696 assert(SeenTypedChunk &&
"optional parameter before name");
3703 NameAndSignature += Chunk.Text;
3705 BeforeName += Chunk.Text;
3717 std::string BeforeName;
3718 std::string NameAndSignature;
3724 const auto *VirtualFunc = dyn_cast<FunctionDecl>(
Declaration);
3725 assert(VirtualFunc &&
"overridden decl must be a function");
3728 NameAndSignature +=
" override";
3730 Result.AddTextChunk(
Result.getAllocator().CopyString(BeforeName));
3732 Result.AddTypedTextChunk(
Result.getAllocator().CopyString(NameAndSignature));
3733 return Result.TakeString();
3739 const auto *VD = dyn_cast<VarDecl>(ND);
3742 const auto *
RecordDecl = VD->getType()->getAsCXXRecordDecl();
3755 if (IncludeBriefComments) {
3758 Result.addBriefComment(RC->getBriefText(Ctx));
3763 Result.AddTypedTextChunk(
3765 Result.AddTextChunk(
"::");
3766 return Result.TakeString();
3770 Result.AddAnnotation(
Result.getAllocator().CopyString(I->getAnnotation()));
3783 if (
const auto *
Function = dyn_cast<FunctionDecl>(ND)) {
3784 AddFunctionTypeAndResult(
Function);
3785 return Result.TakeString();
3788 if (
const auto *CallOperator =
3790 AddFunctionTypeAndResult(CallOperator);
3791 return Result.TakeString();
3797 dyn_cast<FunctionTemplateDecl>(ND)) {
3808 llvm::SmallBitVector Deduced(FunTmpl->getTemplateParameters()->size());
3813 unsigned LastDeducibleArgument;
3814 for (LastDeducibleArgument = Deduced.size(); LastDeducibleArgument > 0;
3815 --LastDeducibleArgument) {
3816 if (!Deduced[LastDeducibleArgument - 1]) {
3820 bool HasDefaultArg =
false;
3821 NamedDecl *Param = FunTmpl->getTemplateParameters()->getParam(
3822 LastDeducibleArgument - 1);
3824 HasDefaultArg = TTP->hasDefaultArgument();
3826 dyn_cast<NonTypeTemplateParmDecl>(Param))
3827 HasDefaultArg = NTTP->hasDefaultArgument();
3854 LastDeducibleArgument);
3863 return Result.TakeString();
3866 if (
const auto *
Template = dyn_cast<TemplateDecl>(ND)) {
3869 Result.AddTypedTextChunk(
3874 return Result.TakeString();
3877 if (
const auto *
Method = dyn_cast<ObjCMethodDecl>(ND)) {
3880 Result.AddTypedTextChunk(
3882 return Result.TakeString();
3888 Result.AddTypedTextChunk(
Result.getAllocator().CopyString(SelName));
3890 Result.AddInformativeChunk(
Result.getAllocator().CopyString(SelName));
3894 if (
Method->param_size() == 1)
3895 Result.AddTypedTextChunk(
"");
3901 PEnd =
Method->param_end();
3902 P != PEnd && Idx < Sel.
getNumArgs(); (
void)++P, ++Idx) {
3921 QualType ParamType = (*P)->getType();
3922 std::optional<ArrayRef<QualType>> ObjCSubsts;
3938 Arg += II->getName();
3941 if (
Method->isVariadic() && (P + 1) == PEnd)
3945 Result.AddTextChunk(
Result.getAllocator().CopyString(Arg));
3947 Result.AddInformativeChunk(
Result.getAllocator().CopyString(Arg));
3949 Result.AddPlaceholderChunk(
Result.getAllocator().CopyString(Arg));
3952 if (
Method->isVariadic()) {
3953 if (
Method->param_size() == 0) {
3955 Result.AddTextChunk(
", ...");
3957 Result.AddInformativeChunk(
", ...");
3959 Result.AddPlaceholderChunk(
", ...");
3965 return Result.TakeString();
3972 Result.AddTypedTextChunk(
3974 return Result.TakeString();
3985 const auto *M = dyn_cast<ObjCMethodDecl>(ND);
3997 const auto *M = dyn_cast_or_null<ObjCMethodDecl>(ND);
3998 if (!M || !M->isPropertyAccessor())
4021 auto FDecl =
Result.getFunction();
4024 if (ArgIndex < FDecl->getNumParams())
4032 unsigned CurrentArg) {
4033 unsigned ChunkIndex = 0;
4034 auto AddChunk = [&](llvm::StringRef Placeholder) {
4037 const char *
Copy = Result.getAllocator().CopyString(Placeholder);
4038 if (ChunkIndex == CurrentArg)
4039 Result.AddCurrentParameterChunk(
Copy);
4041 Result.AddPlaceholderChunk(
Copy);
4046 if (
auto *CRD = llvm::dyn_cast<CXXRecordDecl>(RD)) {
4047 for (
const auto &
Base : CRD->bases())
4048 AddChunk(
Base.getType().getAsString(Policy));
4050 for (
const auto &Field : RD->
fields())
4060 unsigned CurrentArg,
unsigned Start = 0,
bool InOptional =
false) {
4066 bool FirstParameter =
true;
4067 unsigned NumParams =
4068 Function ? Function->getNumParams() :
Prototype->getNumParams();
4070 for (
unsigned P = Start; P != NumParams; ++P) {
4071 if (Function && Function->getParamDecl(P)->hasDefaultArg() && !InOptional) {
4075 Result.getCodeCompletionTUInfo());
4076 if (!FirstParameter)
4080 PrototypeLoc, Opt, CurrentArg, P,
4089 if (Function && FirstParameter &&
4090 Function->getParamDecl(P)->isExplicitObjectParameter()) {
4095 FirstParameter =
false;
4102 std::string Placeholder;
4103 assert(P < Prototype->getNumParams());
4104 if (Function || PrototypeLoc) {
4106 Function ? Function->getParamDecl(P) : PrototypeLoc.
getParam(P);
4108 if (Param->hasDefaultArg())
4110 Context.getLangOpts());
4112 Placeholder =
Prototype->getParamType(P).getAsString(Policy);
4115 if (P == CurrentArg)
4116 Result.AddCurrentParameterChunk(
4117 Result.getAllocator().CopyString(Placeholder));
4119 Result.AddPlaceholderChunk(Result.getAllocator().CopyString(Placeholder));
4124 Result.getCodeCompletionTUInfo());
4125 if (!FirstParameter)
4128 if (CurrentArg < NumParams)
4140 if (
const auto *
Type = dyn_cast<TemplateTypeParmDecl>(Param)) {
4142 }
else if (
const auto *
NonType = dyn_cast<NonTypeTemplateParmDecl>(Param)) {
4144 }
else if (
const auto *
Template = dyn_cast<TemplateTemplateParmDecl>(Param)) {
4148 llvm::raw_string_ostream OS(Result);
4149 Param->print(OS, Policy);
4155 if (
const auto *CTD = dyn_cast<ClassTemplateDecl>(TD))
4156 return CTD->getTemplatedDecl()->getKindName().str();
4157 if (
const auto *VTD = dyn_cast<VarTemplateDecl>(TD))
4158 return VTD->getTemplatedDecl()->getType().getAsString(Policy);
4159 if (
const auto *FTD = dyn_cast<FunctionTemplateDecl>(TD))
4160 return FTD->getTemplatedDecl()->getReturnType().getAsString(Policy);
4175 Builder.getCodeCompletionTUInfo());
4177 if (!ResultType.empty())
4178 Builder.AddResultTypeChunk(Builder.getAllocator().CopyString(ResultType));
4179 Builder.AddTextChunk(
4185 for (
unsigned I = 0; I < Params.size(); ++I) {
4187 std::string Placeholder =
4190 Current = &OptionalBuilder;
4199 if (Current == &OptionalBuilder)
4205 Builder.AddInformativeChunk(
"()");
4206 return Builder.TakeString();
4213 bool Braced)
const {
4237 if (IncludeBriefComments) {
4244 llvm::raw_string_ostream OS(Name);
4246 Result.AddTextChunk(
Result.getAllocator().CopyString(Name));
4249 Result.AddResultTypeChunk(
Result.getAllocator().CopyString(
4264 return Result.TakeString();
4269 bool PreferredTypeIsPointer) {
4273 if (MacroName ==
"nil" || MacroName ==
"NULL" || MacroName ==
"Nil") {
4275 if (PreferredTypeIsPointer)
4279 else if (MacroName ==
"YES" || MacroName ==
"NO" || MacroName ==
"true" ||
4280 MacroName ==
"false")
4283 else if (MacroName ==
"bool")
4296 case Decl::EnumConstant:
4300 case Decl::Function:
4302 case Decl::ObjCCategory:
4304 case Decl::ObjCCategoryImpl:
4306 case Decl::ObjCImplementation:
4309 case Decl::ObjCInterface:
4311 case Decl::ObjCIvar:
4313 case Decl::ObjCMethod:
4317 case Decl::CXXMethod:
4319 case Decl::CXXConstructor:
4321 case Decl::CXXDestructor:
4323 case Decl::CXXConversion:
4325 case Decl::ObjCProperty:
4327 case Decl::ObjCProtocol:
4333 case Decl::TypeAlias:
4335 case Decl::TypeAliasTemplate:
4339 case Decl::Namespace:
4341 case Decl::NamespaceAlias:
4343 case Decl::TemplateTypeParm:
4345 case Decl::NonTypeTemplateParm:
4347 case Decl::TemplateTemplateParm:
4349 case Decl::FunctionTemplate:
4351 case Decl::ClassTemplate:
4353 case Decl::AccessSpec:
4355 case Decl::ClassTemplatePartialSpecialization:
4357 case Decl::UsingDirective:
4359 case Decl::StaticAssert:
4363 case Decl::TranslationUnit:
4367 case Decl::UnresolvedUsingValue:
4368 case Decl::UnresolvedUsingTypename:
4371 case Decl::UsingEnum:
4374 case Decl::ObjCPropertyImpl:
4382 llvm_unreachable(
"Unexpected Kind!");
4387 case Decl::ObjCTypeParam:
4393 case Decl::LinkageSpec:
4397 if (
const auto *TD = dyn_cast<TagDecl>(D)) {
4398 switch (TD->getTagKind()) {
4416 bool LoadExternal,
bool IncludeUndefined,
4417 bool TargetTypeIsPointer =
false) {
4420 Results.EnterNewScope();
4426 if (IncludeUndefined || MD) {
4434 TargetTypeIsPointer)));
4438 Results.ExitScope();
4442 ResultBuilder &Results) {
4445 Results.EnterNewScope();
4449 if (LangOpts.C99 || LangOpts.CPlusPlus11)
4451 Results.ExitScope();
4458 unsigned NumResults) {
4463static CodeCompletionContext
4521 llvm_unreachable(
"Invalid ParserCompletionContext!");
4533 ResultBuilder &Results) {
4539 CXXMethodDecl *Method = dyn_cast<CXXMethodDecl>(CurContext);
4540 if (!Method || !Method->isVirtual())
4545 for (
auto *P : Method->parameters())
4546 if (!P->getDeclName())
4552 Results.getCodeCompletionTUInfo());
4553 if (Overridden->getCanonicalDecl() == Method->getCanonicalDecl())
4559 S.
Context, CurContext, Overridden->getDeclContext());
4562 llvm::raw_string_ostream OS(Str);
4563 NNS.
print(OS, Policy);
4564 Builder.AddTextChunk(Results.getAllocator().CopyString(Str));
4566 }
else if (!InContext->
Equals(Overridden->getDeclContext()))
4569 Builder.AddTypedTextChunk(
4570 Results.getAllocator().CopyString(Overridden->getNameAsString()));
4572 bool FirstParam =
true;
4573 for (
auto *P : Method->parameters()) {
4579 Builder.AddPlaceholderChunk(
4580 Results.getAllocator().CopyString(P->getIdentifier()->getName()));
4586 Results.Ignore(Overridden);
4596 Results.EnterNewScope();
4604 SemaRef.PP.getHeaderSearchInfo().collectAllModules(Modules);
4605 for (
unsigned I = 0, N = Modules.size(); I != N; ++I) {
4606 Builder.AddTypedTextChunk(
4607 Builder.getAllocator().CopyString(Modules[I]->Name));
4608 Results.AddResult(
Result(
4621 Builder.AddTypedTextChunk(
4622 Builder.getAllocator().CopyString(Submodule->Name));
4623 Results.AddResult(
Result(
4630 Results.ExitScope();
4632 Results.getCompletionContext(), Results.data(),
4641 Results.EnterNewScope();
4646 switch (CompletionContext) {
4656 Results.setFilter(&ResultBuilder::IsOrdinaryNonValueName);
4666 Results.setFilter(&ResultBuilder::IsOrdinaryName);
4668 Results.setFilter(&ResultBuilder::IsOrdinaryNonTypeName);
4679 auto ThisType =
SemaRef.getCurrentThisType();
4680 if (ThisType.isNull()) {
4682 if (
auto *MethodDecl = llvm::dyn_cast_if_present<CXXMethodDecl>(
4683 SemaRef.getCurFunctionDecl()))
4684 Results.setExplicitObjectMemberFn(
4685 MethodDecl->isExplicitObjectMemberFunction());
4689 Results.setObjectTypeQualifiers(ThisType->getPointeeType().getQualifiers(),
4693 CodeCompletionDeclConsumer Consumer(Results,
SemaRef.CurContext);
4694 SemaRef.LookupVisibleDecls(S,
SemaRef.LookupOrdinaryName, Consumer,
4699 Results.ExitScope();
4701 switch (CompletionContext) {
4729 Results.getCompletionContext(), Results.data(),
4736 bool AtArgumentExpression,
bool IsSuper,
4737 ResultBuilder &Results);
4740 bool AllowNonIdentifiers,
4741 bool AllowNestedNameSpecifiers) {
4743 ResultBuilder Results(
4746 AllowNestedNameSpecifiers
4751 Results.EnterNewScope();
4754 Results.AddResult(
Result(
"const"));
4755 Results.AddResult(
Result(
"volatile"));
4757 Results.AddResult(
Result(
"restrict"));
4763 Results.AddResult(
"final");
4765 if (AllowNonIdentifiers) {
4766 Results.AddResult(
Result(
"operator"));
4770 if (AllowNestedNameSpecifiers) {
4771 Results.allowNestedNameSpecifiers();
4772 Results.setFilter(&ResultBuilder::IsImpossibleToSatisfy);
4773 CodeCompletionDeclConsumer Consumer(Results,
SemaRef.CurContext);
4777 Results.setFilter(
nullptr);
4780 Results.ExitScope();
4786 if (AllowNonIdentifiers && !AllowNestedNameSpecifiers &&
4797 if (!T.get().isNull() && T.get()->isObjCObjectOrInterfaceType())
4805 Results.getCompletionContext(), Results.data(),
4810 if (
Scope ==
"clang")
4818 if (
Scope ==
"_Clang")
4820 if (
Scope ==
"__gnu__")
4844 llvm::StringRef InScopeName;
4845 bool InScopeUnderscore =
false;
4847 InScopeName = InScope->
getName();
4849 InScopeName = NoUnderscore;
4850 InScopeUnderscore =
true;
4857 llvm::DenseSet<llvm::StringRef> FoundScopes;
4859 if (A.IsTargetSpecific &&
4864 for (
const auto &S : A.Spellings) {
4865 if (S.Syntax != Syntax)
4867 llvm::StringRef Name = S.NormalizedFullName;
4868 llvm::StringRef
Scope;
4871 std::tie(
Scope, Name) = Name.split(
"::");
4873 std::swap(Name,
Scope);
4879 if (!
Scope.empty() && FoundScopes.insert(
Scope).second) {
4890 if (!InScopeName.empty()) {
4891 if (
Scope != InScopeName)
4896 auto Add = [&](llvm::StringRef
Scope, llvm::StringRef Name,
4899 Results.getCodeCompletionTUInfo());
4901 if (!
Scope.empty()) {
4910 Builder.AddTypedTextChunk(Results.getAllocator().CopyString(
Text));
4912 if (!A.ArgNames.empty()) {
4915 for (
const char *Arg : A.ArgNames) {
4919 Builder.AddPlaceholderChunk(Arg);
4924 Results.AddResult(Builder.TakeString());
4931 if (!InScopeUnderscore)
4932 Add(
Scope, Name,
false);
4937 if (!(InScope && !InScopeUnderscore) && SyntaxSupportsGuards) {
4938 if (
Scope.empty()) {
4939 Add(
Scope, Name,
true);
4944 Add(GuardedScope, Name,
true);
4954 for (
const auto &Entry : ParsedAttrInfoRegistry::entries())
4955 AddCompletions(*Entry.instantiate());
4958 Results.getCompletionContext(), Results.data(),
4977struct CoveredEnumerators {
4985 const CoveredEnumerators &Enumerators) {
4987 if (Context.getLangOpts().CPlusPlus && !Qualifier && Enumerators.Seen.empty()) {
4994 Results.EnterNewScope();
4995 for (
auto *E :
Enum->enumerators()) {
4996 if (Enumerators.Seen.count(E))
5000 Results.AddResult(R, CurContext,
nullptr,
false);
5002 Results.ExitScope();
5008 assert(!T.isNull());
5012 if (
auto *
Specialization = T->getAs<TemplateSpecializationType>()) {
5021 if (T->isPointerType())
5022 T = T->getPointeeType();
5031 if (!Results.includeCodePatterns())
5034 Results.getCodeCompletionTUInfo());
5039 if (!Parameters.empty()) {
5048 constexpr llvm::StringLiteral NamePlaceholder =
"!#!NAME_GOES_HERE!#!";
5049 std::string
Type = std::string(NamePlaceholder);
5051 llvm::StringRef Prefix, Suffix;
5052 std::tie(Prefix, Suffix) = llvm::StringRef(
Type).split(NamePlaceholder);
5053 Prefix = Prefix.rtrim();
5054 Suffix = Suffix.ltrim();
5077 ResultBuilder Results(
5081 Data.IsParenthesized
5084 Data.PreferredType));
5087 if (
Data.ObjCCollection)
5088 Results.setFilter(&ResultBuilder::IsObjCCollection);
5089 else if (
Data.IntegralConstantExpression)
5090 Results.setFilter(&ResultBuilder::IsIntegralConstantValue);
5092 Results.setFilter(&ResultBuilder::IsOrdinaryName);
5094 Results.setFilter(&ResultBuilder::IsOrdinaryNonTypeName);
5096 if (!
Data.PreferredType.isNull())
5097 Results.setPreferredType(
Data.PreferredType.getNonReferenceType());
5100 for (
unsigned I = 0, N =
Data.IgnoreDecls.size(); I != N; ++I)
5101 Results.Ignore(
Data.IgnoreDecls[I]);
5103 CodeCompletionDeclConsumer Consumer(Results,
SemaRef.CurContext);
5108 Results.EnterNewScope();
5110 Results.ExitScope();
5112 bool PreferredTypeIsPointer =
false;
5113 if (!
Data.PreferredType.isNull()) {
5114 PreferredTypeIsPointer =
Data.PreferredType->isAnyPointerType() ||
5115 Data.PreferredType->isMemberPointerType() ||
5116 Data.PreferredType->isBlockPointerType();
5117 if (
auto *
Enum =
Data.PreferredType->getAsEnumDecl()) {
5121 CoveredEnumerators());
5126 !
Data.IntegralConstantExpression)
5131 PreferredTypeIsPointer);
5141 Results.getCompletionContext(), Results.data(),
5147 bool IsParenthesized) {
5174 if (Protocol->hasDefinition())
5175 return Protocol->getDefinition();
5189 Builder.AddResultTypeChunk(
5191 Policy, Builder.getAllocator()));
5197 Builder.AddPlaceholderChunk(
"...");
5199 for (
unsigned I = 0, N = BlockLoc.
getNumParams(); I != N; ++I) {
5204 std::string PlaceholderStr =
5207 if (I == N - 1 && BlockProtoLoc &&
5209 PlaceholderStr +=
", ...";
5212 Builder.AddPlaceholderChunk(
5213 Builder.getAllocator().CopyString(PlaceholderStr));
5223 bool AllowNullaryMethods,
DeclContext *CurContext,
5225 bool IsBaseExprStatement =
false,
5226 bool IsClassProperty =
false,
bool InOriginalClass =
true) {
5234 if (!AddedProperties.insert(P->getIdentifier()).second)
5239 if (!P->getType().getTypePtr()->isBlockPointerType() ||
5240 !IsBaseExprStatement) {
5242 Result(P, Results.getBasePriority(P), std::nullopt);
5243 if (!InOriginalClass)
5245 Results.MaybeAddResult(R, CurContext);
5257 Result(P, Results.getBasePriority(P), std::nullopt);
5258 if (!InOriginalClass)
5260 Results.MaybeAddResult(R, CurContext);
5267 Results.getCodeCompletionTUInfo());
5270 BlockLoc, BlockProtoLoc);
5271 Result R =
Result(Builder.TakeString(), P, Results.getBasePriority(P));
5272 if (!InOriginalClass)
5274 Results.MaybeAddResult(R, CurContext);
5278 if (!P->isReadOnly()) {
5280 Results.getCodeCompletionTUInfo());
5284 Builder.AddTypedTextChunk(
5285 Results.getAllocator().CopyString(P->getName()));
5290 BlockProtoLoc,
true);
5292 Builder.AddPlaceholderChunk(
5293 Builder.getAllocator().CopyString(PlaceholderStr));
5301 Result(Builder.TakeString(), P,
5302 Results.getBasePriority(P) +
5306 if (!InOriginalClass)
5308 Results.MaybeAddResult(R, CurContext);
5312 if (IsClassProperty) {
5321 if (AllowNullaryMethods) {
5326 const IdentifierInfo *Name = M->getSelector().getIdentifierInfoForSlot(0);
5329 if (!AddedProperties.insert(Name).second)
5332 Results.getCodeCompletionTUInfo());
5334 Builder.AddTypedTextChunk(
5335 Results.getAllocator().CopyString(Name->
getName()));
5336 Result R =
Result(Builder.TakeString(), M,
5338 if (!InOriginalClass)
5340 Results.MaybeAddResult(R, CurContext);
5343 if (IsClassProperty) {
5344 for (
const auto *M : Container->
methods()) {
5348 if (!M->getSelector().isUnarySelector() ||
5349 M->getReturnType()->isVoidType() || M->isInstanceMethod())
5354 for (
auto *M : Container->
methods()) {
5355 if (M->getSelector().isUnarySelector())
5363 for (
auto *P : Protocol->protocols())
5365 CurContext, AddedProperties, Results,
5366 IsBaseExprStatement, IsClassProperty,
5369 dyn_cast<ObjCInterfaceDecl>(Container)) {
5370 if (AllowCategories) {
5372 for (
auto *Cat : IFace->known_categories())
5374 CurContext, AddedProperties, Results,
5375 IsBaseExprStatement, IsClassProperty,
5380 for (
auto *I : IFace->all_referenced_protocols())
5382 CurContext, AddedProperties, Results,
5383 IsBaseExprStatement, IsClassProperty,
5387 if (IFace->getSuperClass())
5389 AllowNullaryMethods, CurContext, AddedProperties,
5390 Results, IsBaseExprStatement, IsClassProperty,
5392 }
else if (
const auto *Category =
5393 dyn_cast<ObjCCategoryDecl>(Container)) {
5395 for (
auto *P : Category->protocols())
5397 CurContext, AddedProperties, Results,
5398 IsBaseExprStatement, IsClassProperty,
5407 std::optional<FixItHint> AccessOpFixIt) {
5410 Results.setObjectTypeQualifiers(BaseType.getQualifiers(), BaseKind);
5413 Results.allowNestedNameSpecifiers();
5414 std::vector<FixItHint> FixIts;
5416 FixIts.emplace_back(*AccessOpFixIt);
5417 CodeCompletionDeclConsumer Consumer(Results, RD, BaseType, std::move(FixIts));
5425 if (!Results.empty()) {
5429 bool IsDependent = BaseType->isDependentType();
5431 for (
Scope *DepScope = S; DepScope; DepScope = DepScope->
getParent())
5449 BaseType = Resolver.
simplifyType(BaseType,
nullptr,
false);
5450 return dyn_cast_if_present<RecordDecl>(
5486 const IdentifierInfo *Name =
nullptr;
5491 std::optional<SmallVector<QualType, 1>> ArgTypes;
5493 enum AccessOperator {
5499 const TypeConstraint *ResultType =
nullptr;
5505 CodeCompletionString *render(Sema &S, CodeCompletionAllocator &Alloc,
5506 CodeCompletionTUInfo &Info)
const {
5507 CodeCompletionBuilder B(Alloc, Info);
5510 std::string AsString;
5512 llvm::raw_string_ostream
OS(AsString);
5513 QualType ExactType = deduceType(*ResultType);
5519 B.AddResultTypeChunk(
Alloc.CopyString(AsString));
5522 B.AddTypedTextChunk(
Alloc.CopyString(Name->
getName()));
5527 for (QualType Arg : *ArgTypes) {
5534 B.AddPlaceholderChunk(
Alloc.CopyString(
5539 return B.TakeString();
5546 ConceptInfo(
const TemplateTypeParmType &BaseType, Scope *S) {
5547 auto *TemplatedEntity = getTemplatedEntity(BaseType.getDecl(), S);
5548 for (
const AssociatedConstraint &AC :
5549 constraintsForTemplatedEntity(TemplatedEntity))
5550 believe(AC.ConstraintExpr, &BaseType);
5553 std::vector<Member> members() {
5554 std::vector<Member> Results;
5555 for (
const auto &E : this->Results)
5556 Results.push_back(E.second);
5557 llvm::sort(Results, [](
const Member &L,
const Member &R) {
5558 return L.Name->getName() <
R.Name->getName();
5565 void believe(
const Expr *E,
const TemplateTypeParmType *T) {
5568 if (
auto *CSE = dyn_cast<ConceptSpecializationExpr>(E)) {
5579 ConceptDecl *CD = CSE->getNamedConcept();
5582 for (
const auto &Arg : CSE->getTemplateArguments()) {
5583 if (Index >= Params->
size())
5585 if (isApprox(Arg, T)) {
5586 auto *TTPD = dyn_cast<TemplateTypeParmDecl>(Params->
getParam(Index));
5598 }
else if (
auto *BO = dyn_cast<BinaryOperator>(E)) {
5601 if (BO->getOpcode() == BO_LAnd || BO->getOpcode() == BO_LOr) {
5602 believe(BO->getLHS(), T);
5603 believe(BO->getRHS(), T);
5605 }
else if (
auto *RE = dyn_cast<RequiresExpr>(E)) {
5607 for (
const concepts::Requirement *Req : RE->getRequirements()) {
5608 if (!Req->isDependent())
5612 if (
auto *TR = dyn_cast<concepts::TypeRequirement>(Req)) {
5614 QualType AssertedType = TR->getType()->getType();
5615 ValidVisitor(
this, T).TraverseType(AssertedType);
5616 }
else if (
auto *ER = dyn_cast<concepts::ExprRequirement>(Req)) {
5617 ValidVisitor Visitor(
this, T);
5621 if (ER->getReturnTypeRequirement().isTypeConstraint()) {
5623 ER->getReturnTypeRequirement().getTypeConstraint();
5624 Visitor.OuterExpr = ER->getExpr();
5626 Visitor.TraverseStmt(ER->getExpr());
5627 }
else if (
auto *NR = dyn_cast<concepts::NestedRequirement>(Req)) {
5628 believe(NR->getConstraintExpr(), T);
5638 const TemplateTypeParmType *T;
5640 CallExpr *Caller =
nullptr;
5645 Expr *OuterExpr =
nullptr;
5646 const TypeConstraint *OuterType =
nullptr;
5648 ValidVisitor(ConceptInfo *Outer,
const TemplateTypeParmType *T)
5649 : Outer(Outer), T(T) {
5655 VisitCXXDependentScopeMemberExpr(CXXDependentScopeMemberExpr *E)
override {
5658 if (
Base->isPointerType() && IsArrow) {
5660 Base =
Base->getPointeeType().getTypePtr();
5662 if (isApprox(Base, T))
5663 addValue(E, E->
getMember(), IsArrow ? Member::Arrow : Member::Dot);
5668 bool VisitDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E)
override {
5670 if (
Qualifier.getKind() == NestedNameSpecifier::Kind::Type &&
5677 bool VisitDependentNameType(DependentNameType *DNT)
override {
5678 NestedNameSpecifier Q = DNT->getQualifier();
5679 if (Q.
getKind() == NestedNameSpecifier::Kind::Type &&
5681 addType(DNT->getIdentifier());
5690 if (NNS.
getKind() == NestedNameSpecifier::Kind::Type) {
5692 if (NestedNameSpecifier Q = NNST->
getPrefix();
5693 Q.
getKind() == NestedNameSpecifier::Kind::Type &&
5695 if (
const auto *DNT = dyn_cast_or_null<DependentNameType>(NNST))
5696 addType(DNT->getIdentifier());
5707 bool VisitCallExpr(CallExpr *CE)
override {
5714 void addResult(
Member &&M) {
5715 auto R = Outer->Results.try_emplace(M.Name);
5720 std::make_tuple(M.ArgTypes.has_value(), M.ResultType !=
nullptr,
5721 M.Operator) > std::make_tuple(O.ArgTypes.has_value(),
5722 O.ResultType !=
nullptr,
5727 void addType(
const IdentifierInfo *Name) {
5732 M.Operator = Member::Colons;
5733 addResult(std::move(M));
5736 void addValue(Expr *E, DeclarationName Name,
5737 Member::AccessOperator Operator) {
5742 Result.Operator = Operator;
5745 if (Caller !=
nullptr && Callee == E) {
5746 Result.ArgTypes.emplace();
5747 for (
const auto *Arg : Caller->
arguments())
5748 Result.ArgTypes->push_back(Arg->getType());
5749 if (Caller == OuterExpr) {
5750 Result.ResultType = OuterType;
5754 Result.ResultType = OuterType;
5756 addResult(std::move(
Result));
5760 static bool isApprox(
const TemplateArgument &Arg,
const Type *T) {
5765 static bool isApprox(
const Type *T1,
const Type *T2) {
5774 static DeclContext *getTemplatedEntity(
const TemplateTypeParmDecl *D,
5778 Scope *Inner =
nullptr;
5781 return Inner ? Inner->
getEntity() :
nullptr;
5790 static SmallVector<AssociatedConstraint, 1>
5791 constraintsForTemplatedEntity(DeclContext *DC) {
5792 SmallVector<AssociatedConstraint, 1>
Result;
5797 TD->getAssociatedConstraints(
Result);
5799 if (
const auto *CTPSD =
5800 dyn_cast<ClassTemplatePartialSpecializationDecl>(DC))
5801 CTPSD->getAssociatedConstraints(
Result);
5802 if (
const auto *VTPSD = dyn_cast<VarTemplatePartialSpecializationDecl>(DC))
5803 VTPSD->getAssociatedConstraints(
Result);
5809 static QualType deduceType(
const TypeConstraint &T) {
5815 if (Args->getNumTemplateArgs() == 1) {
5816 const auto &Arg = Args->arguments().front().getArgument();
5823 llvm::DenseMap<const IdentifierInfo *, Member> Results;
5830QualType getApproximateType(
const Expr *E, HeuristicResolver &Resolver) {
5844Expr *unwrapParenList(Expr *Base) {
5845 if (
auto *PLE = llvm::dyn_cast_or_null<ParenListExpr>(Base)) {
5846 if (PLE->getNumExprs() == 0)
5848 Base = PLE->getExpr(PLE->getNumExprs() - 1);
5857 bool IsBaseExprStatement,
QualType PreferredType) {
5859 OtherOpBase = unwrapParenList(OtherOpBase);
5864 SemaRef.PerformMemberExprBaseConversion(
Base, IsArrow);
5868 getApproximateType(ConvertedBase.
get(),
Resolver);
5874 !PointeeType.isNull()) {
5875 ConvertedBaseType = PointeeType;
5894 &ResultBuilder::IsMember);
5896 auto DoCompletion = [&](
Expr *
Base,
bool IsArrow,
5897 std::optional<FixItHint> AccessOpFixIt) ->
bool {
5902 SemaRef.PerformMemberExprBaseConversion(
Base, IsArrow);
5908 if (BaseType.isNull())
5914 !PointeeType.isNull()) {
5915 BaseType = PointeeType;
5917 }
else if (BaseType->isObjCObjectPointerType() ||
5918 BaseType->isTemplateTypeParmType()) {
5927 RD, std::move(AccessOpFixIt));
5928 }
else if (
const auto *TTPT =
5929 dyn_cast<TemplateTypeParmType>(BaseType.getTypePtr())) {
5931 IsArrow ? ConceptInfo::Member::Arrow : ConceptInfo::Member::Dot;
5932 for (
const auto &R : ConceptInfo(*TTPT, S).members()) {
5933 if (R.Operator != Operator)
5939 Result.FixIts.push_back(*AccessOpFixIt);
5940 Results.AddResult(std::move(
Result));
5942 }
else if (!IsArrow && BaseType->isObjCObjectPointerType()) {
5946 if (AccessOpFixIt) {
5954 assert(ObjCPtr &&
"Non-NULL pointer guaranteed above!");
5957 AddedProperties, Results, IsBaseExprStatement);
5963 SemaRef.CurContext, AddedProperties, Results,
5964 IsBaseExprStatement,
false,
5966 }
else if ((IsArrow && BaseType->isObjCObjectPointerType()) ||
5967 (!IsArrow && BaseType->isObjCObjectType())) {
5971 if (AccessOpFixIt) {
5977 Class = ObjCPtr->getInterfaceDecl();
5983 CodeCompletionDeclConsumer Consumer(Results,
Class, BaseType);
5984 Results.setFilter(&ResultBuilder::IsObjCIvar);
5996 Results.EnterNewScope();
5998 bool CompletionSucceded = DoCompletion(
Base, IsArrow, std::nullopt);
6002 CompletionSucceded |= DoCompletion(
6003 OtherOpBase, !IsArrow,
6007 Results.ExitScope();
6009 if (!CompletionSucceded)
6014 Results.getCompletionContext(), Results.data(),
6020 bool IsBaseExprStatement) {
6023 SemaRef.ObjC().getObjCInterfaceDecl(ClassNamePtr, ClassNameLoc);
6030 &ResultBuilder::IsMember);
6031 Results.EnterNewScope();
6035 AddedProperties, Results, IsBaseExprStatement,
6037 Results.ExitScope();
6039 Results.getCompletionContext(), Results.data(),
6047 ResultBuilder::LookupFilter Filter =
nullptr;
6052 Filter = &ResultBuilder::IsEnum;
6057 Filter = &ResultBuilder::IsUnion;
6064 Filter = &ResultBuilder::IsClassOrStruct;
6069 llvm_unreachable(
"Unknown type specifier kind in CodeCompleteTag");
6074 CodeCompletionDeclConsumer Consumer(Results,
SemaRef.CurContext);
6077 Results.setFilter(Filter);
6084 Results.setFilter(&ResultBuilder::IsNestedNameSpecifier);
6091 Results.getCompletionContext(), Results.data(),
6098 Results.AddResult(
"const");
6100 Results.AddResult(
"volatile");
6102 Results.AddResult(
"restrict");
6104 Results.AddResult(
"_Atomic");
6106 Results.AddResult(
"__unaligned");
6113 Results.EnterNewScope();
6115 Results.ExitScope();
6117 Results.getCompletionContext(), Results.data(),
6126 Results.EnterNewScope();
6129 Results.AddResult(
"noexcept");
6133 Results.AddResult(
"final");
6135 Results.AddResult(
"override");
6138 Results.ExitScope();
6140 Results.getCompletionContext(), Results.data(),
6153 SemaRef.getCurFunction()->SwitchStack.back().getPointer();
6161 Data.IntegralConstantExpression =
true;
6170 CoveredEnumerators Enumerators;
6172 SC = SC->getNextSwitchCase()) {
6173 CaseStmt *Case = dyn_cast<CaseStmt>(SC);
6178 if (
auto *DRE = dyn_cast<DeclRefExpr>(CaseVal))
6180 dyn_cast<EnumConstantDecl>(DRE->getDecl())) {
6200 Enumerators.SuggestedQualifier = DRE->getQualifier();
6215 Results.getCompletionContext(), Results.data(),
6220 if (Args.size() && !Args.data())
6223 for (
unsigned I = 0; I != Args.size(); ++I)
6244 if (Candidate.Function) {
6245 if (Candidate.Function->isDeleted())
6248 Candidate.Function) &&
6249 Candidate.Function->getNumParams() <= ArgSize &&
6258 if (Candidate.Viable)
6272 for (
auto &Candidate : Candidates) {
6273 QualType CandidateParamType = Candidate.getParamType(N);
6274 if (CandidateParamType.
isNull())
6276 if (ParamType.
isNull()) {
6277 ParamType = CandidateParamType;
6294 if (Candidates.empty())
6298 SemaRef, CurrentArg, Candidates.data(), Candidates.size(), OpenParLoc,
6306 Fn = unwrapParenList(Fn);
6317 auto ArgsWithoutDependentTypes =
6322 Expr *NakedFn = Fn->IgnoreParenCasts();
6328 if (
auto ULE = dyn_cast<UnresolvedLookupExpr>(NakedFn)) {
6329 SemaRef.AddOverloadedCallCandidates(ULE, ArgsWithoutDependentTypes,
6332 }
else if (
auto UME = dyn_cast<UnresolvedMemberExpr>(NakedFn)) {
6334 if (UME->hasExplicitTemplateArgs()) {
6335 UME->copyTemplateArgumentsInto(TemplateArgsBuffer);
6336 TemplateArgs = &TemplateArgsBuffer;
6341 1, UME->isImplicitAccess() ?
nullptr : UME->getBase());
6342 ArgExprs.append(ArgsWithoutDependentTypes.begin(),
6343 ArgsWithoutDependentTypes.end());
6345 Decls.
append(UME->decls_begin(), UME->decls_end());
6346 const bool FirstArgumentIsBase = !UME->isImplicitAccess() && UME->getBase();
6347 SemaRef.AddFunctionCandidates(Decls, ArgExprs, CandidateSet, TemplateArgs,
6350 FirstArgumentIsBase);
6353 if (
auto *MCE = dyn_cast<MemberExpr>(NakedFn))
6354 FD = dyn_cast<FunctionDecl>(MCE->getMemberDecl());
6355 else if (
auto *DRE = dyn_cast<DeclRefExpr>(NakedFn))
6356 FD = dyn_cast<FunctionDecl>(DRE->getDecl());
6362 SemaRef.AddOverloadCandidate(FD,
6364 ArgsWithoutDependentTypes, CandidateSet,
6374 getASTContext().DeclarationNames.getCXXOperatorName(OO_Call);
6376 SemaRef.LookupQualifiedName(R, DC);
6377 R.suppressDiagnostics();
6379 ArgExprs.append(ArgsWithoutDependentTypes.begin(),
6380 ArgsWithoutDependentTypes.end());
6381 SemaRef.AddFunctionCandidates(R.asUnresolvedSet(), ArgExprs,
6393 if (!T->getPointeeType().isNull())
6397 if (!
SemaRef.TooManyArguments(FP->getNumParams(),
6398 ArgsWithoutDependentTypes.size(),
6434static std::optional<unsigned>
6437 static constexpr unsigned Invalid = std::numeric_limits<unsigned>::max();
6443 unsigned ArgsAfterDesignator = 0;
6444 for (
const Expr *Arg : Args) {
6445 if (
const auto *DIE = dyn_cast<DesignatedInitExpr>(Arg)) {
6446 if (DIE->size() == 1 && DIE->getDesignator(0)->isFieldDesignator()) {
6447 DesignatedFieldName = DIE->getDesignator(0)->getFieldName();
6448 ArgsAfterDesignator = 0;
6455 ++ArgsAfterDesignator;
6458 if (!DesignatedFieldName)
6459 return std::nullopt;
6463 unsigned DesignatedIndex = 0;
6464 const FieldDecl *DesignatedField =
nullptr;
6465 for (
const auto *Field :
Aggregate.getAggregate()->fields()) {
6466 if (Field->getIdentifier() == DesignatedFieldName) {
6467 DesignatedField = Field;
6472 if (!DesignatedField)
6476 unsigned AggregateSize =
Aggregate.getNumParams();
6477 while (DesignatedIndex < AggregateSize &&
6478 Aggregate.getParamDecl(DesignatedIndex) != DesignatedField)
6482 return DesignatedIndex + ArgsAfterDesignator + 1;
6505 if (Braced && !RD->
isUnion() &&
6510 if (
auto NextIndex =
6513 if (*NextIndex >= AggregateSize)
6515 Results.push_back(AggregateSig);
6521 if (Args.size() < AggregateSize)
6522 Results.push_back(AggregateSig);
6532 if (
auto *FD = dyn_cast<FunctionDecl>(
C)) {
6536 SemaRef.isInitListConstructor(FD))
6543 }
else if (
auto *FTD = dyn_cast<FunctionTemplateDecl>(
C)) {
6545 SemaRef.isInitListConstructor(FTD->getTemplatedDecl()))
6548 SemaRef.AddTemplateOverloadCandidate(
6550 nullptr, Args, CandidateSet,
6571 dyn_cast<CXXConstructorDecl>(ConstructorDecl);
6576 Constructor->getParent(), SS, TemplateTypeTy, II))
6578 MemberDecl->getLocation(), ArgExprs,
6579 OpenParLoc, Braced);
6587 if (Index < Params.
size())
6590 Param = Params.
asArray().back();
6596 return llvm::isa<TemplateTypeParmDecl>(Param);
6598 return llvm::isa<NonTypeTemplateParmDecl>(Param);
6600 return llvm::isa<TemplateTemplateParmDecl>(Param);
6602 llvm_unreachable(
"Unhandled switch case");
6614 bool Matches =
true;
6615 for (
unsigned I = 0; I < Args.size(); ++I) {
6622 Results.emplace_back(TD);
6626 if (
const auto *TD =
Template.getAsTemplateDecl()) {
6628 }
else if (
const auto *OTS =
Template.getAsOverloadedTemplate()) {
6630 if (
const auto *TD = llvm::dyn_cast<TemplateDecl>(ND))
6640 if (BaseType.isNull())
6644 if (D.isArrayDesignator() || D.isArrayRangeDesignator()) {
6645 if (BaseType->isArrayType())
6648 assert(D.isFieldDesignator());
6650 if (RD && RD->isCompleteDefinition()) {
6651 for (
const auto *
Member : RD->lookup(D.getFieldDecl()))
6653 NextType = FD->getType();
6658 BaseType = NextType;
6666 if (BaseType.isNull())
6669 if (!RD || RD->fields().empty())
6677 Results.EnterNewScope();
6678 for (
const Decl *D : RD->decls()) {
6680 if (
auto *IFD = dyn_cast<IndirectFieldDecl>(D))
6681 FD = IFD->getAnonField();
6682 else if (
auto *DFD = dyn_cast<FieldDecl>(D))
6689 ResultBuilder::Result
Result(FD, Results.getBasePriority(FD));
6692 Results.ExitScope();
6694 Results.getCompletionContext(), Results.data(),
6699 ValueDecl *VD = dyn_cast_or_null<ValueDecl>(D);
6708 Data.IgnoreDecls.push_back(VD);
6718 Results.getCodeCompletionTUInfo());
6720 if (!AfterExclaim) {
6721 if (Results.includeCodePatterns()) {
6722 Builder.AddTypedTextChunk(
"constexpr");
6725 Builder.AddPlaceholderChunk(
"condition");
6730 Builder.AddPlaceholderChunk(
"statements");
6733 Results.AddResult({Builder.TakeString()});
6735 Results.AddResult({
"constexpr"});
6740 if (Results.includeCodePatterns()) {
6741 Builder.AddTypedTextChunk(
"consteval");
6745 Builder.AddPlaceholderChunk(
"statements");
6748 Results.AddResult({Builder.TakeString()});
6750 Results.AddResult({
"consteval"});
6755 Results.getCompletionContext(), Results.data(),
6763 Results.setFilter(&ResultBuilder::IsOrdinaryName);
6764 Results.EnterNewScope();
6766 CodeCompletionDeclConsumer Consumer(Results,
SemaRef.CurContext);
6775 Results.getCodeCompletionTUInfo());
6777 auto AddElseBodyPattern = [&] {
6782 Builder.AddPlaceholderChunk(
"statements");
6788 Builder.AddPlaceholderChunk(
"statement");
6792 Builder.AddTypedTextChunk(
"else");
6793 if (Results.includeCodePatterns())
6794 AddElseBodyPattern();
6795 Results.AddResult(Builder.TakeString());
6798 Builder.AddTypedTextChunk(
"else if");
6802 Builder.AddPlaceholderChunk(
"condition");
6804 Builder.AddPlaceholderChunk(
"expression");
6806 if (Results.includeCodePatterns()) {
6807 AddElseBodyPattern();
6809 Results.AddResult(Builder.TakeString());
6811 Results.ExitScope();
6820 Results.getCompletionContext(), Results.data(),
6825 bool EnteringContext,
6826 bool IsUsingDeclaration,
6846 if (!PreferredType.
isNull())
6847 DummyResults.setPreferredType(PreferredType);
6849 CodeCompletionDeclConsumer Consumer(DummyResults, S->
getEntity(),
6856 DummyResults.getCompletionContext(),
nullptr, 0);
6867 if (Ctx ==
nullptr ||
SemaRef.RequireCompleteDeclContext(SS, Ctx))
6873 if (!PreferredType.
isNull())
6874 Results.setPreferredType(PreferredType);
6875 Results.EnterNewScope();
6881 Results.AddResult(
"template");
6886 if (
const auto *TTPT = dyn_cast<TemplateTypeParmType>(NNS.
getAsType())) {
6887 for (
const auto &R : ConceptInfo(*TTPT, S).members()) {
6888 if (R.Operator != ConceptInfo::Member::Colons)
6902 if (Ctx && !EnteringContext)
6904 Results.ExitScope();
6908 CodeCompletionDeclConsumer Consumer(Results, Ctx, BaseType);
6916 Results.getCompletionContext(), Results.data(),
6927 Context.setIsUsingDeclaration(
true);
6931 &ResultBuilder::IsNestedNameSpecifier);
6932 Results.EnterNewScope();
6940 CodeCompletionDeclConsumer Consumer(Results,
SemaRef.CurContext);
6944 Results.ExitScope();
6947 Results.getCompletionContext(), Results.data(),
6960 &ResultBuilder::IsNamespaceOrAlias);
6961 Results.EnterNewScope();
6962 CodeCompletionDeclConsumer Consumer(Results,
SemaRef.CurContext);
6966 Results.ExitScope();
6968 Results.getCompletionContext(), Results.data(),
6980 bool SuppressedGlobalResults =
6985 SuppressedGlobalResults
6988 &ResultBuilder::IsNamespace);
6990 if (Ctx && Ctx->
isFileContext() && !SuppressedGlobalResults) {
6995 std::map<NamespaceDecl *, NamespaceDecl *> OrigToLatest;
7000 OrigToLatest[NS->getFirstDecl()] = *NS;
7004 Results.EnterNewScope();
7005 for (std::map<NamespaceDecl *, NamespaceDecl *>::iterator
7006 NS = OrigToLatest.begin(),
7007 NSEnd = OrigToLatest.end();
7012 SemaRef.CurContext,
nullptr,
false);
7013 Results.ExitScope();
7017 Results.getCompletionContext(), Results.data(),
7029 &ResultBuilder::IsNamespaceOrAlias);
7030 CodeCompletionDeclConsumer Consumer(Results,
SemaRef.CurContext);
7035 Results.getCompletionContext(), Results.data(),
7047 &ResultBuilder::IsType);
7048 Results.EnterNewScope();
7052#define OVERLOADED_OPERATOR(Name, Spelling, Token, Unary, Binary, MemberOnly) \
7053 if (OO_##Name != OO_Conditional) \
7054 Results.AddResult(Result(Spelling));
7055#include "clang/Basic/OperatorKinds.def"
7058 Results.allowNestedNameSpecifiers();
7059 CodeCompletionDeclConsumer Consumer(Results,
SemaRef.CurContext);
7066 Results.ExitScope();
7069 Results.getCompletionContext(), Results.data(),
7078 SemaRef.AdjustDeclIfTemplate(ConstructorD);
7080 auto *
Constructor = dyn_cast<CXXConstructorDecl>(ConstructorD);
7087 Results.EnterNewScope();
7092 for (
unsigned I = 0, E = Initializers.size(); I != E; ++I) {
7093 if (Initializers[I]->isBaseInitializer())
7095 QualType(Initializers[I]->getBaseClass(), 0)));
7097 InitializedFields.insert(
7103 bool SawLastInitializer = Initializers.empty();
7106 auto GenerateCCS = [&](
const NamedDecl *ND,
const char *Name) {
7108 Results.getCodeCompletionTUInfo());
7109 Builder.AddTypedTextChunk(Name);
7111 if (
const auto *
Function = dyn_cast<FunctionDecl>(ND))
7113 else if (
const auto *FunTemplDecl = dyn_cast<FunctionTemplateDecl>(ND))
7115 FunTemplDecl->getTemplatedDecl(), Builder);
7117 return Builder.TakeString();
7119 auto AddDefaultCtorInit = [&](
const char *Name,
const char *
Type,
7122 Results.getCodeCompletionTUInfo());
7123 Builder.AddTypedTextChunk(Name);
7125 Builder.AddPlaceholderChunk(
Type);
7129 Builder.TakeString(), ND,
7133 return Results.AddResult(CCR);
7136 Builder.TakeString(),
7139 auto AddCtorsWithName = [&](
const CXXRecordDecl *RD,
unsigned int Priority,
7140 const char *Name,
const FieldDecl *FD) {
7142 return AddDefaultCtorInit(Name,
7143 FD ? Results.getAllocator().CopyString(
7144 FD->getType().getAsString(Policy))
7148 if (Ctors.begin() == Ctors.end())
7149 return AddDefaultCtorInit(Name, Name, RD);
7153 Results.AddResult(CCR);
7157 const char *BaseName =
7158 Results.getAllocator().CopyString(
Base.getType().getAsString(Policy));
7159 const auto *RD =
Base.getType()->getAsCXXRecordDecl();
7164 auto AddField = [&](
const FieldDecl *FD) {
7165 const char *FieldName =
7166 Results.getAllocator().CopyString(FD->getIdentifier()->getName());
7167 const CXXRecordDecl *RD = FD->getType()->getAsCXXRecordDecl();
7173 for (
const auto &
Base : ClassDecl->
bases()) {
7174 if (!InitializedBases
7177 SawLastInitializer =
7178 !Initializers.empty() && Initializers.back()->isBaseInitializer() &&
7180 Base.getType(),
QualType(Initializers.back()->getBaseClass(), 0));
7185 SawLastInitializer =
false;
7189 for (
const auto &
Base : ClassDecl->
vbases()) {
7190 if (!InitializedBases
7193 SawLastInitializer =
7194 !Initializers.empty() && Initializers.back()->isBaseInitializer() &&
7196 Base.getType(),
QualType(Initializers.back()->getBaseClass(), 0));
7201 SawLastInitializer =
false;
7205 for (
auto *Field : ClassDecl->
fields()) {
7206 if (!InitializedFields.insert(
cast<FieldDecl>(Field->getCanonicalDecl()))
7208 SawLastInitializer = !Initializers.empty() &&
7209 Initializers.back()->isAnyMemberInitializer() &&
7210 Initializers.back()->getAnyMember() == Field;
7214 if (!Field->getDeclName())
7218 SawLastInitializer =
false;
7220 Results.ExitScope();
7223 Results.getCompletionContext(), Results.data(),
7238 bool AfterAmpersand) {
7242 Results.EnterNewScope();
7246 bool IncludedThis =
false;
7249 IncludedThis =
true;
7258 for (
const auto *D : S->
decls()) {
7259 const auto *Var = dyn_cast<VarDecl>(D);
7260 if (!Var || !Var->hasLocalStorage() || Var->hasAttr<BlocksAttr>())
7263 if (Known.insert(Var->getIdentifier()).second)
7265 SemaRef.CurContext,
nullptr,
false);
7273 Results.ExitScope();
7276 Results.getCompletionContext(), Results.data(),
7286 auto ShouldAddDefault = [&D,
this]() {
7298 auto Op = Id.OperatorFunctionId.Operator;
7301 if (Op == OverloadedOperatorKind::OO_Equal)
7304 (Op == OverloadedOperatorKind::OO_EqualEqual ||
7305 Op == OverloadedOperatorKind::OO_ExclaimEqual ||
7306 Op == OverloadedOperatorKind::OO_Less ||
7307 Op == OverloadedOperatorKind::OO_LessEqual ||
7308 Op == OverloadedOperatorKind::OO_Greater ||
7309 Op == OverloadedOperatorKind::OO_GreaterEqual ||
7310 Op == OverloadedOperatorKind::OO_Spaceship))
7316 Results.EnterNewScope();
7317 if (ShouldAddDefault())
7318 Results.AddResult(
"default");
7321 Results.AddResult(
"delete");
7322 Results.ExitScope();
7324 Results.getCompletionContext(), Results.data(),
7330#define OBJC_AT_KEYWORD_NAME(NeedAt, Keyword) ((NeedAt) ? "@" Keyword : Keyword)
7333 ResultBuilder &Results,
bool NeedAt) {
7339 Results.getCodeCompletionTUInfo());
7340 if (LangOpts.ObjC) {
7344 Builder.AddPlaceholderChunk(
"property");
7345 Results.AddResult(
Result(Builder.TakeString()));
7350 Builder.AddPlaceholderChunk(
"property");
7351 Results.AddResult(
Result(Builder.TakeString()));
7356 ResultBuilder &Results,
bool NeedAt) {
7362 if (LangOpts.ObjC) {
7377 Results.getCodeCompletionTUInfo());
7382 Builder.AddPlaceholderChunk(
"name");
7383 Results.AddResult(
Result(Builder.TakeString()));
7385 if (Results.includeCodePatterns()) {
7391 Builder.AddPlaceholderChunk(
"class");
7392 Results.AddResult(
Result(Builder.TakeString()));
7397 Builder.AddPlaceholderChunk(
"protocol");
7398 Results.AddResult(
Result(Builder.TakeString()));
7403 Builder.AddPlaceholderChunk(
"class");
7404 Results.AddResult(
Result(Builder.TakeString()));
7408 Builder.AddTypedTextChunk(
7411 Builder.AddPlaceholderChunk(
"alias");
7413 Builder.AddPlaceholderChunk(
"class");
7414 Results.AddResult(
Result(Builder.TakeString()));
7416 if (Results.getSema().getLangOpts().Modules) {
7420 Builder.AddPlaceholderChunk(
"module");
7421 Results.AddResult(
Result(Builder.TakeString()));
7429 Results.EnterNewScope();
7432 else if (
SemaRef.CurContext->isObjCContainer())
7436 Results.ExitScope();
7438 Results.getCompletionContext(), Results.data(),
7445 Results.getCodeCompletionTUInfo());
7448 const char *EncodeType =
"char[]";
7449 if (Results.getSema().getLangOpts().CPlusPlus ||
7450 Results.getSema().getLangOpts().ConstStrings)
7451 EncodeType =
"const char[]";
7452 Builder.AddResultTypeChunk(EncodeType);
7455 Builder.AddPlaceholderChunk(
"type-name");
7457 Results.AddResult(
Result(Builder.TakeString()));
7460 Builder.AddResultTypeChunk(
"Protocol *");
7463 Builder.AddPlaceholderChunk(
"protocol-name");
7465 Results.AddResult(
Result(Builder.TakeString()));
7468 Builder.AddResultTypeChunk(
"SEL");
7471 Builder.AddPlaceholderChunk(
"selector");
7473 Results.AddResult(
Result(Builder.TakeString()));
7476 Builder.AddResultTypeChunk(
"NSString *");
7478 Builder.AddPlaceholderChunk(
"string");
7479 Builder.AddTextChunk(
"\"");
7480 Results.AddResult(
Result(Builder.TakeString()));
7483 Builder.AddResultTypeChunk(
"NSArray *");
7485 Builder.AddPlaceholderChunk(
"objects, ...");
7487 Results.AddResult(
Result(Builder.TakeString()));
7490 Builder.AddResultTypeChunk(
"NSDictionary *");
7492 Builder.AddPlaceholderChunk(
"key");
7495 Builder.AddPlaceholderChunk(
"object, ...");
7497 Results.AddResult(
Result(Builder.TakeString()));
7500 Builder.AddResultTypeChunk(
"id");
7502 Builder.AddPlaceholderChunk(
"expression");
7504 Results.AddResult(
Result(Builder.TakeString()));
7510 Results.getCodeCompletionTUInfo());
7512 if (Results.includeCodePatterns()) {
7517 Builder.AddPlaceholderChunk(
"statements");
7519 Builder.AddTextChunk(
"@catch");
7521 Builder.AddPlaceholderChunk(
"parameter");
7524 Builder.AddPlaceholderChunk(
"statements");
7526 Builder.AddTextChunk(
"@finally");
7528 Builder.AddPlaceholderChunk(
"statements");
7530 Results.AddResult(
Result(Builder.TakeString()));
7536 Builder.AddPlaceholderChunk(
"expression");
7537 Results.AddResult(
Result(Builder.TakeString()));
7539 if (Results.includeCodePatterns()) {
7544 Builder.AddPlaceholderChunk(
"expression");
7547 Builder.AddPlaceholderChunk(
"statements");
7549 Results.AddResult(
Result(Builder.TakeString()));
7554 ResultBuilder &Results,
bool NeedAt) {
7567 Results.EnterNewScope();
7569 Results.ExitScope();
7571 Results.getCompletionContext(), Results.data(),
7579 Results.EnterNewScope();
7582 Results.ExitScope();
7584 Results.getCompletionContext(), Results.data(),
7592 Results.EnterNewScope();
7594 Results.ExitScope();
7596 Results.getCompletionContext(), Results.data(),
7604 if (Attributes & NewFlag)
7607 Attributes |= NewFlag;
7615 unsigned AssignCopyRetMask =
7621 if (AssignCopyRetMask &&
7643 Results.EnterNewScope();
7680 Results.getCodeCompletionTUInfo());
7689 Results.getCodeCompletionTUInfo());
7702 Results.ExitScope();
7704 Results.getCompletionContext(), Results.data(),
7718 bool AllowSameLength =
true) {
7719 unsigned NumSelIdents = SelIdents.size();
7732 if (!AllowSameLength && NumSelIdents && NumSelIdents == Sel.
getNumArgs())
7735 for (
unsigned I = 0; I != NumSelIdents; ++I)
7745 bool AllowSameLength =
true) {
7779 ResultBuilder &Results,
bool InOriginalClass =
true,
7780 bool IsRootClass =
false) {
7784 IsRootClass = IsRootClass || (IFace && !IFace->
getSuperClass());
7788 if (M->isInstanceMethod() == WantInstanceMethods ||
7789 (IsRootClass && !WantInstanceMethods)) {
7795 if (!Selectors.insert(M->getSelector()).second)
7799 Result(M, Results.getBasePriority(M), std::nullopt);
7800 R.StartParameter = SelIdents.size();
7801 R.AllParametersAreInformative = (WantKind !=
MK_Any);
7802 if (!InOriginalClass)
7804 Results.MaybeAddResult(R, CurContext);
7809 if (
const auto *Protocol = dyn_cast<ObjCProtocolDecl>(Container)) {
7810 if (Protocol->hasDefinition()) {
7812 Protocol->getReferencedProtocols();
7814 E = Protocols.
end();
7816 AddObjCMethods(*I, WantInstanceMethods, WantKind, SelIdents, CurContext,
7817 Selectors, AllowSameLength, Results,
false, IsRootClass);
7826 AddObjCMethods(I, WantInstanceMethods, WantKind, SelIdents, CurContext,
7827 Selectors, AllowSameLength, Results,
false, IsRootClass);
7831 AddObjCMethods(CatDecl, WantInstanceMethods, WantKind, SelIdents,
7832 CurContext, Selectors, AllowSameLength, Results,
7833 InOriginalClass, IsRootClass);
7837 CatDecl->getReferencedProtocols();
7839 E = Protocols.
end();
7841 AddObjCMethods(*I, WantInstanceMethods, WantKind, SelIdents, CurContext,
7842 Selectors, AllowSameLength, Results,
false, IsRootClass);
7846 AddObjCMethods(Impl, WantInstanceMethods, WantKind, SelIdents, CurContext,
7847 Selectors, AllowSameLength, Results, InOriginalClass,
7855 SelIdents, CurContext, Selectors, AllowSameLength, Results,
7860 AddObjCMethods(Impl, WantInstanceMethods, WantKind, SelIdents, CurContext,
7861 Selectors, AllowSameLength, Results, InOriginalClass,
7868 dyn_cast_or_null<ObjCInterfaceDecl>(
SemaRef.CurContext);
7871 dyn_cast_or_null<ObjCCategoryDecl>(
SemaRef.CurContext))
7872 Class = Category->getClassInterface();
7882 Results.EnterNewScope();
7888 Results.ExitScope();
7890 Results.getCompletionContext(), Results.data(),
7897 dyn_cast_or_null<ObjCInterfaceDecl>(
SemaRef.CurContext);
7900 dyn_cast_or_null<ObjCCategoryDecl>(
SemaRef.CurContext))
7901 Class = Category->getClassInterface();
7911 Results.EnterNewScope();
7918 Results.ExitScope();
7920 Results.getCompletionContext(), Results.data(),
7929 Results.EnterNewScope();
7932 bool AddedInOut =
false;
7935 Results.AddResult(
"in");
7936 Results.AddResult(
"inout");
7941 Results.AddResult(
"out");
7943 Results.AddResult(
"inout");
7948 Results.AddResult(
"bycopy");
7949 Results.AddResult(
"byref");
7950 Results.AddResult(
"oneway");
7953 Results.AddResult(
"nonnull");
7954 Results.AddResult(
"nullable");
7955 Results.AddResult(
"null_unspecified");
7963 SemaRef.PP.isMacroDefined(
"IBAction")) {
7965 Results.getCodeCompletionTUInfo(),
7967 Builder.AddTypedTextChunk(
"IBAction");
7969 Builder.AddPlaceholderChunk(
"selector");
7972 Builder.AddTextChunk(
"id");
7974 Builder.AddTextChunk(
"sender");
7985 Results.ExitScope();
7988 Results.setFilter(&ResultBuilder::IsOrdinaryNonValueName);
7989 CodeCompletionDeclConsumer Consumer(Results,
SemaRef.CurContext);
7998 Results.getCompletionContext(), Results.data(),
8007 auto *Msg = dyn_cast_or_null<ObjCMessageExpr>(E);
8025 switch (Msg->getReceiverKind()) {
8029 IFace = ObjType->getInterface();
8033 QualType T = Msg->getInstanceReceiver()->getType();
8035 IFace = Ptr->getInterfaceDecl();
8048 if (Method->isInstanceMethod())
8049 return llvm::StringSwitch<ObjCInterfaceDecl *>(Id->
getName())
8050 .Case(
"retain", IFace)
8051 .Case(
"strong", IFace)
8052 .Case(
"autorelease", IFace)
8053 .Case(
"copy", IFace)
8054 .Case(
"copyWithZone", IFace)
8055 .Case(
"mutableCopy", IFace)
8056 .Case(
"mutableCopyWithZone", IFace)
8057 .Case(
"awakeFromCoder", IFace)
8058 .Case(
"replacementObjectFromCoder", IFace)
8059 .Case(
"class", IFace)
8060 .Case(
"classForCoder", IFace)
8061 .Case(
"superclass", Super)
8064 return llvm::StringSwitch<ObjCInterfaceDecl *>(Id->
getName())
8066 .Case(
"alloc", IFace)
8067 .Case(
"allocWithZone", IFace)
8068 .Case(
"class", IFace)
8069 .Case(
"superclass", Super)
8089static ObjCMethodDecl *
8092 ResultBuilder &Results) {
8103 while ((Class = Class->getSuperClass()) && !SuperMethod) {
8105 SuperMethod = Class->getMethod(CurMethod->
getSelector(),
8110 for (
const auto *Cat : Class->known_categories()) {
8111 if ((SuperMethod = Cat->getMethod(CurMethod->
getSelector(),
8129 CurP != CurPEnd; ++CurP, ++SuperP) {
8132 (*SuperP)->getType()))
8136 if (!(*CurP)->getIdentifier())
8142 Results.getCodeCompletionTUInfo());
8146 Results.getCompletionContext().getBaseType(), Builder);
8149 if (NeedSuperKeyword) {
8150 Builder.AddTypedTextChunk(
"super");
8156 if (NeedSuperKeyword)
8157 Builder.AddTextChunk(
8160 Builder.AddTypedTextChunk(
8164 for (
unsigned I = 0, N = Sel.
getNumArgs(); I != N; ++I, ++CurP) {
8165 if (I > SelIdents.size())
8168 if (I < SelIdents.size())
8169 Builder.AddInformativeChunk(
8171 else if (NeedSuperKeyword || I > SelIdents.size()) {
8172 Builder.AddTextChunk(
8174 Builder.AddPlaceholderChunk(Builder.getAllocator().CopyString(
8175 (*CurP)->getIdentifier()->getName()));
8177 Builder.AddTypedTextChunk(
8179 Builder.AddPlaceholderChunk(Builder.getAllocator().CopyString(
8180 (*CurP)->getIdentifier()->getName()));
8192 ResultBuilder Results(
8197 ? &ResultBuilder::IsObjCMessageReceiverOrLambdaCapture
8198 : &ResultBuilder::IsObjCMessageReceiver);
8200 CodeCompletionDeclConsumer Consumer(Results,
SemaRef.CurContext);
8201 Results.EnterNewScope();
8210 if (Iface->getSuperClass()) {
8211 Results.AddResult(
Result(
"super"));
8219 Results.ExitScope();
8224 Results.getCompletionContext(), Results.data(),
8234 CDecl = CurMethod->getClassInterface();
8243 if (CurMethod->isInstanceMethod()) {
8248 AtArgumentExpression, CDecl);
8258 if ((CDecl = dyn_cast_or_null<ObjCInterfaceDecl>(ND))) {
8260 }
else if (
TypeDecl *TD = dyn_cast_or_null<TypeDecl>(ND)) {
8262 getASTContext().getTypeDeclType(TD)->getAs<ObjCObjectType>())
8263 CDecl = Iface->getInterface();
8273 SemaRef.ActOnIdExpression(S, SS, TemplateKWLoc,
id,
8277 SelIdents, AtArgumentExpression);
8287 AtArgumentExpression,
8294 unsigned NumSelIdents) {
8296 ASTContext &Context = Results.getSema().Context;
8300 Result *ResultsData = Results.data();
8301 for (
unsigned I = 0, N = Results.size(); I != N; ++I) {
8302 Result &R = ResultsData[I];
8303 if (R.Kind == Result::RK_Declaration &&
8305 if (R.Priority <= BestPriority) {
8307 if (NumSelIdents <= Method->param_size()) {
8309 Method->parameters()[NumSelIdents - 1]->getType();
8310 if (R.Priority < BestPriority || PreferredType.
isNull()) {
8311 BestPriority = R.Priority;
8312 PreferredType = MyPreferredType;
8313 }
else if (!Context.hasSameUnqualifiedType(PreferredType,
8322 return PreferredType;
8328 bool AtArgumentExpression,
bool IsSuper,
8329 ResultBuilder &Results) {
8344 Results.EnterNewScope();
8351 Results.Ignore(SuperMethod);
8357 Results.setPreferredSelector(CurMethod->getSelector());
8362 Selectors, AtArgumentExpression, Results);
8369 for (uint32_t I = 0,
8380 for (SemaObjC::GlobalMethodPool::iterator
8385 MethList && MethList->getMethod(); MethList = MethList->getNext()) {
8389 Result R(MethList->getMethod(),
8390 Results.getBasePriority(MethList->getMethod()),
8392 R.StartParameter = SelIdents.size();
8393 R.AllParametersAreInformative =
false;
8394 Results.MaybeAddResult(R, SemaRef.
CurContext);
8399 Results.ExitScope();
8404 bool AtArgumentExpression,
bool IsSuper) {
8408 ResultBuilder Results(
8415 AtArgumentExpression, IsSuper, Results);
8422 if (AtArgumentExpression) {
8425 if (PreferredType.
isNull())
8433 Results.getCompletionContext(), Results.data(),
8454 RecExpr = Conv.
get();
8458 : Super ? Context.getObjCObjectPointerType(
8459 Context.getObjCInterfaceType(Super))
8460 : Context.getObjCIdType();
8470 AtArgumentExpression, Super);
8473 Context.getObjCObjectPointerType(Context.getObjCInterfaceType(IFace));
8478 RecExpr = Conv.
get();
8479 ReceiverType = RecExpr->
getType();
8484 ResultBuilder Results(
8488 ReceiverType, SelIdents));
8490 Results.EnterNewScope();
8497 Results.Ignore(SuperMethod);
8503 Results.setPreferredSelector(CurMethod->getSelector());
8516 Selectors, AtArgumentExpression, Results);
8523 for (
auto *I : QualID->quals())
8525 AtArgumentExpression, Results);
8532 SemaRef.CurContext, Selectors, AtArgumentExpression,
8536 for (
auto *I : IFacePtr->quals())
8538 AtArgumentExpression, Results);
8548 for (uint32_t I = 0,
8549 N =
SemaRef.ExternalSource->GetNumExternalSelectors();
8555 SemaRef.ObjC().ReadMethodPool(Sel);
8559 for (SemaObjC::GlobalMethodPool::iterator
8560 M =
SemaRef.ObjC().MethodPool.begin(),
8561 MEnd =
SemaRef.ObjC().MethodPool.end();
8564 MethList && MethList->getMethod(); MethList = MethList->getNext()) {
8568 if (!Selectors.insert(MethList->getMethod()->getSelector()).second)
8571 Result R(MethList->getMethod(),
8572 Results.getBasePriority(MethList->getMethod()),
8574 R.StartParameter = SelIdents.size();
8575 R.AllParametersAreInformative =
false;
8576 Results.MaybeAddResult(R,
SemaRef.CurContext);
8580 Results.ExitScope();
8587 if (AtArgumentExpression) {
8590 if (PreferredType.
isNull())
8598 Results.getCompletionContext(), Results.data(),
8605 Data.ObjCCollection =
true;
8611 Data.IgnoreDecls.push_back(*I);
8623 for (uint32_t I = 0, N =
SemaRef.ExternalSource->GetNumExternalSelectors();
8629 SemaRef.ObjC().ReadMethodPool(Sel);
8636 Results.EnterNewScope();
8637 for (SemaObjC::GlobalMethodPool::iterator
8638 M =
SemaRef.ObjC().MethodPool.begin(),
8639 MEnd =
SemaRef.ObjC().MethodPool.end();
8647 Results.getCodeCompletionTUInfo());
8649 Builder.AddTypedTextChunk(
8651 Results.AddResult(Builder.TakeString());
8655 std::string Accumulator;
8656 for (
unsigned I = 0, N = Sel.
getNumArgs(); I != N; ++I) {
8657 if (I == SelIdents.size()) {
8658 if (!Accumulator.empty()) {
8659 Builder.AddInformativeChunk(
8660 Builder.getAllocator().CopyString(Accumulator));
8661 Accumulator.clear();
8668 Builder.AddTypedTextChunk(Builder.getAllocator().CopyString(Accumulator));
8669 Results.AddResult(Builder.TakeString());
8671 Results.ExitScope();
8674 Results.getCompletionContext(), Results.data(),
8681 bool OnlyForwardDeclarations,
8682 ResultBuilder &Results) {
8685 for (
const auto *D : Ctx->
decls()) {
8687 if (
const auto *Proto = dyn_cast<ObjCProtocolDecl>(D))
8688 if (!OnlyForwardDeclarations || !Proto->hasDefinition())
8689 Results.AddResult(
Result(Proto, Results.getBasePriority(Proto),
8691 CurContext,
nullptr,
false);
8702 Results.EnterNewScope();
8709 Pair.getIdentifierInfo(), Pair.getLoc()))
8710 Results.Ignore(Protocol);
8714 SemaRef.CurContext,
false, Results);
8716 Results.ExitScope();
8720 Results.getCompletionContext(), Results.data(),
8730 Results.EnterNewScope();
8734 SemaRef.CurContext,
true, Results);
8736 Results.ExitScope();
8740 Results.getCompletionContext(), Results.data(),
8747 bool OnlyForwardDeclarations,
8748 bool OnlyUnimplemented,
8749 ResultBuilder &Results) {
8752 for (
const auto *D : Ctx->
decls()) {
8754 if (
const auto *Class = dyn_cast<ObjCInterfaceDecl>(D))
8755 if ((!OnlyForwardDeclarations || !Class->hasDefinition()) &&
8756 (!OnlyUnimplemented || !Class->getImplementation()))
8757 Results.AddResult(
Result(Class, Results.getBasePriority(Class),
8759 CurContext,
nullptr,
false);
8767 Results.EnterNewScope();
8772 SemaRef.CurContext,
false,
false, Results);
8775 Results.ExitScope();
8778 Results.getCompletionContext(), Results.data(),
8786 Results.EnterNewScope();
8791 SemaRef.CurContext,
false,
false, Results);
8794 Results.ExitScope();
8797 Results.getCompletionContext(), Results.data(),
8806 Results.EnterNewScope();
8812 Results.Ignore(CurClass);
8817 SemaRef.CurContext,
false,
false, Results);
8820 Results.ExitScope();
8823 Results.getCompletionContext(), Results.data(),
8831 Results.EnterNewScope();
8836 SemaRef.CurContext,
false,
true, Results);
8839 Results.ExitScope();
8842 Results.getCompletionContext(), Results.data(),
8860 dyn_cast_or_null<ObjCInterfaceDecl>(CurClass)) {
8861 for (
const auto *Cat :
Class->visible_categories())
8862 CategoryNames.insert(Cat->getIdentifier());
8866 Results.EnterNewScope();
8868 for (
const auto *D : TU->
decls())
8869 if (
const auto *Category = dyn_cast<ObjCCategoryDecl>(D))
8870 if (CategoryNames.insert(Category->getIdentifier()).second)
8871 Results.AddResult(
Result(Category, Results.getBasePriority(Category),
8873 SemaRef.CurContext,
nullptr,
false);
8874 Results.ExitScope();
8877 Results.getCompletionContext(), Results.data(),
8902 Results.EnterNewScope();
8903 bool IgnoreImplemented =
true;
8905 for (
const auto *Cat :
Class->visible_categories()) {
8906 if ((!IgnoreImplemented || !Cat->getImplementation()) &&
8907 CategoryNames.insert(Cat->getIdentifier()).second)
8908 Results.AddResult(
Result(Cat, Results.getBasePriority(Cat),
8910 SemaRef.CurContext,
nullptr,
false);
8914 IgnoreImplemented =
false;
8916 Results.ExitScope();
8919 Results.getCompletionContext(), Results.data(),
8930 dyn_cast_or_null<ObjCContainerDecl>(
SemaRef.CurContext);
8937 for (
const auto *D : Container->
decls())
8938 if (
const auto *PropertyImpl = dyn_cast<ObjCPropertyImplDecl>(D))
8939 Results.Ignore(PropertyImpl->getPropertyDecl());
8943 Results.EnterNewScope();
8945 dyn_cast<ObjCImplementationDecl>(Container))
8948 AddedProperties, Results);
8952 false,
false,
SemaRef.CurContext,
8953 AddedProperties, Results);
8954 Results.ExitScope();
8957 Results.getCompletionContext(), Results.data(),
8970 dyn_cast_or_null<ObjCContainerDecl>(
SemaRef.CurContext);
8978 dyn_cast<ObjCImplementationDecl>(Container))
8979 Class = ClassImpl->getClassInterface();
8983 ->getClassInterface();
8991 Property->getType().getNonReferenceType().getUnqualifiedType();
8994 Results.setPreferredType(PropertyType);
8999 Results.EnterNewScope();
9000 bool SawSimilarlyNamedIvar =
false;
9001 std::string NameWithPrefix;
9002 NameWithPrefix +=
'_';
9003 NameWithPrefix += PropertyName->getName();
9004 std::string NameWithSuffix = PropertyName->getName().str();
9005 NameWithSuffix +=
'_';
9008 Ivar = Ivar->getNextIvar()) {
9009 Results.AddResult(
Result(Ivar, Results.getBasePriority(Ivar),
9011 SemaRef.CurContext,
nullptr,
false);
9015 if ((PropertyName == Ivar->getIdentifier() ||
9016 NameWithPrefix == Ivar->getName() ||
9017 NameWithSuffix == Ivar->getName())) {
9018 SawSimilarlyNamedIvar =
true;
9022 if (Results.size() &&
9023 Results.data()[Results.size() - 1].Kind ==
9025 Results.data()[Results.size() - 1].Declaration == Ivar)
9026 Results.data()[Results.size() - 1].Priority--;
9031 if (!SawSimilarlyNamedIvar) {
9043 Builder.AddTypedTextChunk(Allocator.
CopyString(NameWithPrefix));
9048 Results.ExitScope();
9051 Results.getCompletionContext(), Results.data(),
9058 llvm::PointerIntPair<ObjCMethodDecl *, 1, bool>>
9067 std::optional<bool> WantInstanceMethods,
9070 bool InOriginalClass =
true) {
9073 if (!IFace->hasDefinition())
9076 IFace = IFace->getDefinition();
9080 IFace->getReferencedProtocols();
9082 E = Protocols.
end();
9085 KnownMethods, InOriginalClass);
9088 for (
auto *Cat : IFace->visible_categories()) {
9090 KnownMethods,
false);
9094 if (IFace->getSuperClass())
9096 WantInstanceMethods, ReturnType, KnownMethods,
9103 Category->getReferencedProtocols();
9105 E = Protocols.
end();
9108 KnownMethods, InOriginalClass);
9111 if (InOriginalClass && Category->getClassInterface())
9113 WantInstanceMethods, ReturnType, KnownMethods,
9119 if (!Protocol->hasDefinition())
9121 Protocol = Protocol->getDefinition();
9122 Container = Protocol;
9126 Protocol->getReferencedProtocols();
9128 E = Protocols.
end();
9131 KnownMethods,
false);
9137 for (
auto *M : Container->
methods()) {
9138 if (!WantInstanceMethods || M->isInstanceMethod() == *WantInstanceMethods) {
9139 if (!ReturnType.
isNull() &&
9140 !Context.hasSameUnqualifiedType(ReturnType, M->getReturnType()))
9143 KnownMethods[M->getSelector()] =
9144 KnownMethodsMap::mapped_type(M, InOriginalClass);
9158 Builder.AddTextChunk(Builder.getAllocator().CopyString(Quals));
9159 Builder.AddTextChunk(
9170 if (Class->getIdentifier() && Class->getIdentifier()->getName() == Name)
9179 bool IsInstanceMethod,
9182 ResultBuilder &Results) {
9184 if (!PropName || PropName->
getLength() == 0)
9202 const char *CopiedKey;
9205 : Allocator(Allocator), Key(Key), CopiedKey(
nullptr) {}
9207 operator const char *() {
9211 return CopiedKey = Allocator.
CopyString(Key);
9213 } Key(Allocator, PropName->
getName());
9216 std::string UpperKey = std::string(PropName->
getName());
9217 if (!UpperKey.empty())
9220 bool ReturnTypeMatchesProperty =
9223 Property->getType());
9224 bool ReturnTypeMatchesVoid = ReturnType.
isNull() || ReturnType->
isVoidType();
9227 if (IsInstanceMethod &&
9229 ReturnTypeMatchesProperty && !Property->getGetterMethodDecl()) {
9234 Builder.AddTypedTextChunk(Key);
9241 if (IsInstanceMethod &&
9242 ((!ReturnType.
isNull() &&
9244 (ReturnType.
isNull() && (Property->getType()->isIntegerType() ||
9245 Property->getType()->isBooleanType())))) {
9246 std::string SelectorName = (Twine(
"is") + UpperKey).str();
9250 if (ReturnType.
isNull()) {
9252 Builder.AddTextChunk(
"BOOL");
9263 if (IsInstanceMethod && ReturnTypeMatchesVoid &&
9264 !Property->getSetterMethodDecl()) {
9265 std::string SelectorName = (Twine(
"set") + UpperKey).str();
9267 if (KnownSelectors.insert(Selectors.
getUnarySelector(SelectorId)).second) {
9268 if (ReturnType.
isNull()) {
9270 Builder.AddTextChunk(
"void");
9274 Builder.AddTypedTextChunk(
9278 Builder.AddTextChunk(Key);
9289 if (
const auto *ObjCPointer =
9314 if (IsInstanceMethod &&
9316 std::string SelectorName = (Twine(
"countOf") + UpperKey).str();
9320 if (ReturnType.
isNull()) {
9322 Builder.AddTextChunk(
"NSUInteger");
9328 Result(Builder.TakeString(),
9329 std::min(IndexedGetterPriority, UnorderedGetterPriority),
9336 if (IsInstanceMethod &&
9338 std::string SelectorName = (Twine(
"objectIn") + UpperKey +
"AtIndex").str();
9340 if (KnownSelectors.insert(Selectors.
getUnarySelector(SelectorId)).second) {
9341 if (ReturnType.
isNull()) {
9343 Builder.AddTextChunk(
"id");
9347 Builder.AddTypedTextChunk(Allocator.
CopyString(SelectorName +
":"));
9349 Builder.AddTextChunk(
"NSUInteger");
9351 Builder.AddTextChunk(
"index");
9352 Results.AddResult(
Result(Builder.TakeString(), IndexedGetterPriority,
9358 if (IsInstanceMethod &&
9365 std::string SelectorName = (Twine(Property->getName()) +
"AtIndexes").str();
9367 if (KnownSelectors.insert(Selectors.
getUnarySelector(SelectorId)).second) {
9368 if (ReturnType.
isNull()) {
9370 Builder.AddTextChunk(
"NSArray *");
9374 Builder.AddTypedTextChunk(Allocator.
CopyString(SelectorName +
":"));
9376 Builder.AddTextChunk(
"NSIndexSet *");
9378 Builder.AddTextChunk(
"indexes");
9379 Results.AddResult(
Result(Builder.TakeString(), IndexedGetterPriority,
9385 if (IsInstanceMethod && ReturnTypeMatchesVoid) {
9386 std::string SelectorName = (Twine(
"get") + UpperKey).str();
9387 const IdentifierInfo *SelectorIds[2] = {&Context.Idents.get(SelectorName),
9388 &Context.Idents.get(
"range")};
9390 if (KnownSelectors.insert(Selectors.
getSelector(2, SelectorIds)).second) {
9391 if (ReturnType.
isNull()) {
9393 Builder.AddTextChunk(
"void");
9397 Builder.AddTypedTextChunk(Allocator.
CopyString(SelectorName +
":"));
9399 Builder.AddPlaceholderChunk(
"object-type");
9400 Builder.AddTextChunk(
" **");
9402 Builder.AddTextChunk(
"buffer");
9404 Builder.AddTypedTextChunk(
"range:");
9406 Builder.AddTextChunk(
"NSRange");
9408 Builder.AddTextChunk(
"inRange");
9409 Results.AddResult(
Result(Builder.TakeString(), IndexedGetterPriority,
9417 if (IsInstanceMethod && ReturnTypeMatchesVoid) {
9418 std::string SelectorName = (Twine(
"in") + UpperKey +
"AtIndex").str();
9419 const IdentifierInfo *SelectorIds[2] = {&Context.Idents.get(
"insertObject"),
9420 &Context.Idents.get(SelectorName)};
9422 if (KnownSelectors.insert(Selectors.
getSelector(2, SelectorIds)).second) {
9423 if (ReturnType.
isNull()) {
9425 Builder.AddTextChunk(
"void");
9429 Builder.AddTypedTextChunk(
"insertObject:");
9431 Builder.AddPlaceholderChunk(
"object-type");
9432 Builder.AddTextChunk(
" *");
9434 Builder.AddTextChunk(
"object");
9436 Builder.AddTypedTextChunk(Allocator.
CopyString(SelectorName +
":"));
9438 Builder.AddPlaceholderChunk(
"NSUInteger");
9440 Builder.AddTextChunk(
"index");
9441 Results.AddResult(
Result(Builder.TakeString(), IndexedSetterPriority,
9447 if (IsInstanceMethod && ReturnTypeMatchesVoid) {
9448 std::string SelectorName = (Twine(
"insert") + UpperKey).str();
9449 const IdentifierInfo *SelectorIds[2] = {&Context.Idents.get(SelectorName),
9450 &Context.Idents.get(
"atIndexes")};
9452 if (KnownSelectors.insert(Selectors.
getSelector(2, SelectorIds)).second) {
9453 if (ReturnType.
isNull()) {
9455 Builder.AddTextChunk(
"void");
9459 Builder.AddTypedTextChunk(Allocator.
CopyString(SelectorName +
":"));
9461 Builder.AddTextChunk(
"NSArray *");
9463 Builder.AddTextChunk(
"array");
9465 Builder.AddTypedTextChunk(
"atIndexes:");
9467 Builder.AddPlaceholderChunk(
"NSIndexSet *");
9469 Builder.AddTextChunk(
"indexes");
9470 Results.AddResult(
Result(Builder.TakeString(), IndexedSetterPriority,
9476 if (IsInstanceMethod && ReturnTypeMatchesVoid) {
9477 std::string SelectorName =
9478 (Twine(
"removeObjectFrom") + UpperKey +
"AtIndex").str();
9479 const IdentifierInfo *SelectorId = &Context.Idents.get(SelectorName);
9480 if (KnownSelectors.insert(Selectors.
getUnarySelector(SelectorId)).second) {
9481 if (ReturnType.
isNull()) {
9483 Builder.AddTextChunk(
"void");
9487 Builder.AddTypedTextChunk(Allocator.
CopyString(SelectorName +
":"));
9489 Builder.AddTextChunk(
"NSUInteger");
9491 Builder.AddTextChunk(
"index");
9492 Results.AddResult(
Result(Builder.TakeString(), IndexedSetterPriority,
9498 if (IsInstanceMethod && ReturnTypeMatchesVoid) {
9499 std::string SelectorName = (Twine(
"remove") + UpperKey +
"AtIndexes").str();
9500 const IdentifierInfo *SelectorId = &Context.Idents.get(SelectorName);
9501 if (KnownSelectors.insert(Selectors.
getUnarySelector(SelectorId)).second) {
9502 if (ReturnType.
isNull()) {
9504 Builder.AddTextChunk(
"void");
9508 Builder.AddTypedTextChunk(Allocator.
CopyString(SelectorName +
":"));
9510 Builder.AddTextChunk(
"NSIndexSet *");
9512 Builder.AddTextChunk(
"indexes");
9513 Results.AddResult(
Result(Builder.TakeString(), IndexedSetterPriority,
9519 if (IsInstanceMethod && ReturnTypeMatchesVoid) {
9520 std::string SelectorName =
9521 (Twine(
"replaceObjectIn") + UpperKey +
"AtIndex").str();
9522 const IdentifierInfo *SelectorIds[2] = {&Context.Idents.get(SelectorName),
9523 &Context.Idents.get(
"withObject")};
9525 if (KnownSelectors.insert(Selectors.
getSelector(2, SelectorIds)).second) {
9526 if (ReturnType.
isNull()) {
9528 Builder.AddTextChunk(
"void");
9532 Builder.AddTypedTextChunk(Allocator.
CopyString(SelectorName +
":"));
9534 Builder.AddPlaceholderChunk(
"NSUInteger");
9536 Builder.AddTextChunk(
"index");
9538 Builder.AddTypedTextChunk(
"withObject:");
9540 Builder.AddTextChunk(
"id");
9542 Builder.AddTextChunk(
"object");
9543 Results.AddResult(
Result(Builder.TakeString(), IndexedSetterPriority,
9549 if (IsInstanceMethod && ReturnTypeMatchesVoid) {
9550 std::string SelectorName1 =
9551 (Twine(
"replace") + UpperKey +
"AtIndexes").str();
9552 std::string SelectorName2 = (Twine(
"with") + UpperKey).str();
9553 const IdentifierInfo *SelectorIds[2] = {&Context.Idents.get(SelectorName1),
9554 &Context.Idents.get(SelectorName2)};
9556 if (KnownSelectors.insert(Selectors.
getSelector(2, SelectorIds)).second) {
9557 if (ReturnType.
isNull()) {
9559 Builder.AddTextChunk(
"void");
9563 Builder.AddTypedTextChunk(Allocator.
CopyString(SelectorName1 +
":"));
9565 Builder.AddPlaceholderChunk(
"NSIndexSet *");
9567 Builder.AddTextChunk(
"indexes");
9569 Builder.AddTypedTextChunk(Allocator.
CopyString(SelectorName2 +
":"));
9571 Builder.AddTextChunk(
"NSArray *");
9573 Builder.AddTextChunk(
"array");
9574 Results.AddResult(
Result(Builder.TakeString(), IndexedSetterPriority,
9581 if (IsInstanceMethod &&
9587 ->
getName() ==
"NSEnumerator"))) {
9588 std::string SelectorName = (Twine(
"enumeratorOf") + UpperKey).str();
9589 const IdentifierInfo *SelectorId = &Context.Idents.get(SelectorName);
9592 if (ReturnType.
isNull()) {
9594 Builder.AddTextChunk(
"NSEnumerator *");
9598 Builder.AddTypedTextChunk(Allocator.
CopyString(SelectorName));
9599 Results.AddResult(
Result(Builder.TakeString(), UnorderedGetterPriority,
9605 if (IsInstanceMethod &&
9607 std::string SelectorName = (Twine(
"memberOf") + UpperKey).str();
9608 const IdentifierInfo *SelectorId = &Context.Idents.get(SelectorName);
9609 if (KnownSelectors.insert(Selectors.
getUnarySelector(SelectorId)).second) {
9610 if (ReturnType.
isNull()) {
9612 Builder.AddPlaceholderChunk(
"object-type");
9613 Builder.AddTextChunk(
" *");
9617 Builder.AddTypedTextChunk(Allocator.
CopyString(SelectorName +
":"));
9619 if (ReturnType.
isNull()) {
9620 Builder.AddPlaceholderChunk(
"object-type");
9621 Builder.AddTextChunk(
" *");
9624 ReturnType, Context, Policy, Builder.getAllocator()));
9627 Builder.AddTextChunk(
"object");
9628 Results.AddResult(
Result(Builder.TakeString(), UnorderedGetterPriority,
9635 if (IsInstanceMethod && ReturnTypeMatchesVoid) {
9636 std::string SelectorName =
9637 (Twine(
"add") + UpperKey + Twine(
"Object")).str();
9638 const IdentifierInfo *SelectorId = &Context.Idents.get(SelectorName);
9639 if (KnownSelectors.insert(Selectors.
getUnarySelector(SelectorId)).second) {
9640 if (ReturnType.
isNull()) {
9642 Builder.AddTextChunk(
"void");
9646 Builder.AddTypedTextChunk(Allocator.
CopyString(SelectorName +
":"));
9648 Builder.AddPlaceholderChunk(
"object-type");
9649 Builder.AddTextChunk(
" *");
9651 Builder.AddTextChunk(
"object");
9652 Results.AddResult(
Result(Builder.TakeString(), UnorderedSetterPriority,
9658 if (IsInstanceMethod && ReturnTypeMatchesVoid) {
9659 std::string SelectorName = (Twine(
"add") + UpperKey).str();
9660 const IdentifierInfo *SelectorId = &Context.Idents.get(SelectorName);
9661 if (KnownSelectors.insert(Selectors.
getUnarySelector(SelectorId)).second) {
9662 if (ReturnType.
isNull()) {
9664 Builder.AddTextChunk(
"void");
9668 Builder.AddTypedTextChunk(Allocator.
CopyString(SelectorName +
":"));
9670 Builder.AddTextChunk(
"NSSet *");
9672 Builder.AddTextChunk(
"objects");
9673 Results.AddResult(
Result(Builder.TakeString(), UnorderedSetterPriority,
9679 if (IsInstanceMethod && ReturnTypeMatchesVoid) {
9680 std::string SelectorName =
9681 (Twine(
"remove") + UpperKey + Twine(
"Object")).str();
9682 const IdentifierInfo *SelectorId = &Context.Idents.get(SelectorName);
9683 if (KnownSelectors.insert(Selectors.
getUnarySelector(SelectorId)).second) {
9684 if (ReturnType.
isNull()) {
9686 Builder.AddTextChunk(
"void");
9690 Builder.AddTypedTextChunk(Allocator.
CopyString(SelectorName +
":"));
9692 Builder.AddPlaceholderChunk(
"object-type");
9693 Builder.AddTextChunk(
" *");
9695 Builder.AddTextChunk(
"object");
9696 Results.AddResult(
Result(Builder.TakeString(), UnorderedSetterPriority,
9702 if (IsInstanceMethod && ReturnTypeMatchesVoid) {
9703 std::string SelectorName = (Twine(
"remove") + UpperKey).str();
9704 const IdentifierInfo *SelectorId = &Context.Idents.get(SelectorName);
9705 if (KnownSelectors.insert(Selectors.
getUnarySelector(SelectorId)).second) {
9706 if (ReturnType.
isNull()) {
9708 Builder.AddTextChunk(
"void");
9712 Builder.AddTypedTextChunk(Allocator.
CopyString(SelectorName +
":"));
9714 Builder.AddTextChunk(
"NSSet *");
9716 Builder.AddTextChunk(
"objects");
9717 Results.AddResult(
Result(Builder.TakeString(), UnorderedSetterPriority,
9723 if (IsInstanceMethod && ReturnTypeMatchesVoid) {
9724 std::string SelectorName = (Twine(
"intersect") + UpperKey).str();
9725 const IdentifierInfo *SelectorId = &Context.Idents.get(SelectorName);
9726 if (KnownSelectors.insert(Selectors.
getUnarySelector(SelectorId)).second) {
9727 if (ReturnType.
isNull()) {
9729 Builder.AddTextChunk(
"void");
9733 Builder.AddTypedTextChunk(Allocator.
CopyString(SelectorName +
":"));
9735 Builder.AddTextChunk(
"NSSet *");
9737 Builder.AddTextChunk(
"objects");
9738 Results.AddResult(
Result(Builder.TakeString(), UnorderedSetterPriority,
9745 if (!IsInstanceMethod &&
9752 std::string SelectorName =
9753 (Twine(
"keyPathsForValuesAffecting") + UpperKey).str();
9754 const IdentifierInfo *SelectorId = &Context.Idents.get(SelectorName);
9757 if (ReturnType.
isNull()) {
9759 Builder.AddTextChunk(
"NSSet<NSString *> *");
9763 Builder.AddTypedTextChunk(Allocator.
CopyString(SelectorName));
9770 if (!IsInstanceMethod &&
9773 std::string SelectorName =
9774 (Twine(
"automaticallyNotifiesObserversOf") + UpperKey).str();
9775 const IdentifierInfo *SelectorId = &Context.Idents.get(SelectorName);
9778 if (ReturnType.
isNull()) {
9780 Builder.AddTextChunk(
"BOOL");
9784 Builder.AddTypedTextChunk(Allocator.
CopyString(SelectorName));
9792 Scope *S, std::optional<bool> IsInstanceMethod,
ParsedType ReturnTy) {
9797 Decl *IDecl =
nullptr;
9798 if (
SemaRef.CurContext->isObjCContainer()) {
9804 bool IsInImplementation =
false;
9805 if (
Decl *D = IDecl) {
9807 SearchDecl = Impl->getClassInterface();
9808 IsInImplementation =
true;
9810 dyn_cast<ObjCCategoryImplDecl>(D)) {
9811 SearchDecl = CatImpl->getCategoryDecl();
9812 IsInImplementation =
true;
9814 SearchDecl = dyn_cast<ObjCContainerDecl>(D);
9817 if (!SearchDecl && S) {
9819 SearchDecl = dyn_cast<ObjCContainerDecl>(DC);
9838 Results.EnterNewScope();
9840 for (KnownMethodsMap::iterator M = KnownMethods.begin(),
9841 MEnd = KnownMethods.end();
9845 Results.getCodeCompletionTUInfo());
9848 if (!IsInstanceMethod) {
9849 Builder.AddTextChunk(
Method->isInstanceMethod() ?
"-" :
"+");
9855 if (ReturnType.
isNull()) {
9856 QualType ResTy =
Method->getSendResultType().stripObjCKindOfType(Context);
9857 AttributedType::stripOuterNullability(ResTy);
9866 Builder.AddTypedTextChunk(
9872 PEnd =
Method->param_end();
9873 P != PEnd; (
void)++P, ++I) {
9876 Builder.AddTypedTextChunk(
9880 Builder.AddTypedTextChunk(
9888 ParamType = (*P)->getType();
9890 ParamType = (*P)->getOriginalType();
9893 AttributedType::stripOuterNullability(ParamType);
9895 Context, Policy, Builder);
9898 Builder.AddTextChunk(
9899 Builder.getAllocator().CopyString(Id->getName()));
9903 if (
Method->isVariadic()) {
9904 if (
Method->param_size() > 0)
9906 Builder.AddTextChunk(
"...");
9909 if (IsInImplementation && Results.includeCodePatterns()) {
9914 if (!
Method->getReturnType()->isVoidType()) {
9916 Builder.AddTextChunk(
"return");
9918 Builder.AddPlaceholderChunk(
"expression");
9921 Builder.AddPlaceholderChunk(
"statements");
9928 auto R =
Result(Builder.TakeString(),
Method, Priority);
9929 if (!M->second.getInt())
9931 Results.AddResult(std::move(R));
9936 if (Context.getLangOpts().ObjC) {
9938 Containers.push_back(SearchDecl);
9941 for (KnownMethodsMap::iterator M = KnownMethods.begin(),
9942 MEnd = KnownMethods.end();
9944 KnownSelectors.insert(M->first);
9949 IFace = Category->getClassInterface();
9954 if (IsInstanceMethod) {
9955 for (
unsigned I = 0, N = Containers.size(); I != N; ++I)
9956 for (
auto *P : Containers[I]->instance_properties())
9958 KnownSelectors, Results);
9962 Results.ExitScope();
9965 Results.getCompletionContext(), Results.data(),
9970 Scope *S,
bool IsInstanceMethod,
bool AtParameterName,
ParsedType ReturnTy,
9975 for (uint32_t I = 0, N =
SemaRef.ExternalSource->GetNumExternalSelectors();
9981 SemaRef.ObjC().ReadMethodPool(Sel);
9992 Results.setPreferredType(
9993 SemaRef.GetTypeFromParser(ReturnTy).getNonReferenceType());
9995 Results.EnterNewScope();
9996 for (SemaObjC::GlobalMethodPool::iterator
9997 M =
SemaRef.ObjC().MethodPool.begin(),
9998 MEnd =
SemaRef.ObjC().MethodPool.end();
10000 for (
ObjCMethodList *MethList = IsInstanceMethod ? &M->second.first
10001 : &M->second.second;
10002 MethList && MethList->getMethod(); MethList = MethList->getNext()) {
10006 if (AtParameterName) {
10008 unsigned NumSelIdents = SelIdents.size();
10009 if (NumSelIdents &&
10010 NumSelIdents <= MethList->getMethod()->param_size()) {
10012 MethList->getMethod()->parameters()[NumSelIdents - 1];
10013 if (Param->getIdentifier()) {
10015 Results.getCodeCompletionTUInfo());
10016 Builder.AddTypedTextChunk(Builder.getAllocator().CopyString(
10017 Param->getIdentifier()->getName()));
10018 Results.AddResult(Builder.TakeString());
10025 Result R(MethList->getMethod(),
10026 Results.getBasePriority(MethList->getMethod()),
10028 R.StartParameter = SelIdents.size();
10029 R.AllParametersAreInformative =
false;
10030 R.DeclaringEntity =
true;
10031 Results.MaybeAddResult(R,
SemaRef.CurContext);
10035 Results.ExitScope();
10037 if (!AtParameterName && !SelIdents.empty() &&
10038 SelIdents.front()->getName().starts_with(
"init")) {
10039 for (
const auto &M :
SemaRef.PP.macros()) {
10040 if (M.first->getName() !=
"NS_DESIGNATED_INITIALIZER")
10042 Results.EnterNewScope();
10044 Results.getCodeCompletionTUInfo());
10045 Builder.AddTypedTextChunk(
10046 Builder.getAllocator().CopyString(M.first->getName()));
10049 Results.ExitScope();
10054 Results.getCompletionContext(), Results.data(),
10062 Results.EnterNewScope();
10066 Results.getCodeCompletionTUInfo());
10067 Builder.AddTypedTextChunk(
"if");
10069 Builder.AddPlaceholderChunk(
"condition");
10070 Results.AddResult(Builder.TakeString());
10073 Builder.AddTypedTextChunk(
"ifdef");
10075 Builder.AddPlaceholderChunk(
"macro");
10076 Results.AddResult(Builder.TakeString());
10079 Builder.AddTypedTextChunk(
"ifndef");
10081 Builder.AddPlaceholderChunk(
"macro");
10082 Results.AddResult(Builder.TakeString());
10084 if (InConditional) {
10086 Builder.AddTypedTextChunk(
"elif");
10088 Builder.AddPlaceholderChunk(
"condition");
10089 Results.AddResult(Builder.TakeString());
10092 Builder.AddTypedTextChunk(
"elifdef");
10094 Builder.AddPlaceholderChunk(
"macro");
10095 Results.AddResult(Builder.TakeString());
10098 Builder.AddTypedTextChunk(
"elifndef");
10100 Builder.AddPlaceholderChunk(
"macro");
10101 Results.AddResult(Builder.TakeString());
10104 Builder.AddTypedTextChunk(
"else");
10105 Results.AddResult(Builder.TakeString());
10108 Builder.AddTypedTextChunk(
"endif");
10109 Results.AddResult(Builder.TakeString());
10113 Builder.AddTypedTextChunk(
"include");
10115 Builder.AddTextChunk(
"\"");
10116 Builder.AddPlaceholderChunk(
"header");
10117 Builder.AddTextChunk(
"\"");
10118 Results.AddResult(Builder.TakeString());
10121 Builder.AddTypedTextChunk(
"include");
10123 Builder.AddTextChunk(
"<");
10124 Builder.AddPlaceholderChunk(
"header");
10125 Builder.AddTextChunk(
">");
10126 Results.AddResult(Builder.TakeString());
10129 Builder.AddTypedTextChunk(
"define");
10131 Builder.AddPlaceholderChunk(
"macro");
10132 Results.AddResult(Builder.TakeString());
10135 Builder.AddTypedTextChunk(
"define");
10137 Builder.AddPlaceholderChunk(
"macro");
10139 Builder.AddPlaceholderChunk(
"args");
10141 Results.AddResult(Builder.TakeString());
10144 Builder.AddTypedTextChunk(
"undef");
10146 Builder.AddPlaceholderChunk(
"macro");
10147 Results.AddResult(Builder.TakeString());
10150 Builder.AddTypedTextChunk(
"line");
10152 Builder.AddPlaceholderChunk(
"number");
10153 Results.AddResult(Builder.TakeString());
10156 Builder.AddTypedTextChunk(
"line");
10158 Builder.AddPlaceholderChunk(
"number");
10160 Builder.AddTextChunk(
"\"");
10161 Builder.AddPlaceholderChunk(
"filename");
10162 Builder.AddTextChunk(
"\"");
10163 Results.AddResult(Builder.TakeString());
10166 Builder.AddTypedTextChunk(
"error");
10168 Builder.AddPlaceholderChunk(
"message");
10169 Results.AddResult(Builder.TakeString());
10172 Builder.AddTypedTextChunk(
"pragma");
10174 Builder.AddPlaceholderChunk(
"arguments");
10175 Results.AddResult(Builder.TakeString());
10179 Builder.AddTypedTextChunk(
"import");
10181 Builder.AddTextChunk(
"\"");
10182 Builder.AddPlaceholderChunk(
"header");
10183 Builder.AddTextChunk(
"\"");
10184 Results.AddResult(Builder.TakeString());
10187 Builder.AddTypedTextChunk(
"import");
10189 Builder.AddTextChunk(
"<");
10190 Builder.AddPlaceholderChunk(
"header");
10191 Builder.AddTextChunk(
">");
10192 Results.AddResult(Builder.TakeString());
10196 Builder.AddTypedTextChunk(
"include_next");
10198 Builder.AddTextChunk(
"\"");
10199 Builder.AddPlaceholderChunk(
"header");
10200 Builder.AddTextChunk(
"\"");
10201 Results.AddResult(Builder.TakeString());
10204 Builder.AddTypedTextChunk(
"include_next");
10206 Builder.AddTextChunk(
"<");
10207 Builder.AddPlaceholderChunk(
"header");
10208 Builder.AddTextChunk(
">");
10209 Results.AddResult(Builder.TakeString());
10212 Builder.AddTypedTextChunk(
"warning");
10214 Builder.AddPlaceholderChunk(
"message");
10215 Results.AddResult(Builder.TakeString());
10219 Builder.AddTypedTextChunk(
"embed");
10221 Builder.AddTextChunk(
"\"");
10222 Builder.AddPlaceholderChunk(
"file");
10223 Builder.AddTextChunk(
"\"");
10224 Results.AddResult(Builder.TakeString());
10227 Builder.AddTypedTextChunk(
"embed");
10229 Builder.AddTextChunk(
"<");
10230 Builder.AddPlaceholderChunk(
"file");
10231 Builder.AddTextChunk(
">");
10232 Results.AddResult(Builder.TakeString());
10240 Results.ExitScope();
10243 Results.getCompletionContext(), Results.data(),
10262 Results.getCodeCompletionTUInfo());
10263 Results.EnterNewScope();
10265 MEnd =
SemaRef.PP.macro_end();
10267 Builder.AddTypedTextChunk(
10268 Builder.getAllocator().CopyString(M->first->getName()));
10272 Results.ExitScope();
10273 }
else if (IsDefinition) {
10278 Results.getCompletionContext(), Results.data(),
10291 Results.EnterNewScope();
10293 Results.getCodeCompletionTUInfo());
10294 Builder.AddTypedTextChunk(
"defined");
10297 Builder.AddPlaceholderChunk(
"macro");
10299 Results.AddResult(Builder.TakeString());
10300 Results.ExitScope();
10303 Results.getCompletionContext(), Results.data(),
10323 std::string RelDir = llvm::sys::path::convert_to_slash(Dir);
10326 llvm::sys::path::native(NativeRelDir);
10327 llvm::vfs::FileSystem &FS =
10328 SemaRef.getSourceManager().getFileManager().getVirtualFileSystem();
10333 llvm::DenseSet<StringRef> SeenResults;
10336 auto AddCompletion = [&](StringRef Filename,
bool IsDirectory) {
10339 TypedChunk.push_back(IsDirectory ?
'/' : Angled ?
'>' :
'"');
10340 auto R = SeenResults.insert(TypedChunk);
10342 const char *InternedTyped = Results.getAllocator().CopyString(TypedChunk);
10343 *R.first = InternedTyped;
10346 Builder.AddTypedTextChunk(InternedTyped);
10354 auto AddFilesFromIncludeDir = [&](StringRef IncludeDir,
10358 if (!NativeRelDir.empty()) {
10362 auto Begin = llvm::sys::path::begin(NativeRelDir);
10363 auto End = llvm::sys::path::end(NativeRelDir);
10365 llvm::sys::path::append(Dir, *Begin +
".framework",
"Headers");
10366 llvm::sys::path::append(Dir, ++Begin, End);
10368 llvm::sys::path::append(Dir, NativeRelDir);
10372 const StringRef &Dirname = llvm::sys::path::filename(Dir);
10373 const bool isQt = Dirname.starts_with(
"Qt") || Dirname ==
"ActiveQt";
10374 const bool ExtensionlessHeaders =
10375 IsSystem || isQt || Dir.ends_with(
".framework/Headers") ||
10376 IncludeDir.ends_with(
"/include") || IncludeDir.ends_with(
"\\include");
10377 std::error_code EC;
10378 unsigned Count = 0;
10379 for (
auto It = FS.dir_begin(Dir, EC);
10380 !EC && It != llvm::vfs::directory_iterator(); It.increment(EC)) {
10381 if (++Count == 2500)
10383 StringRef Filename = llvm::sys::path::filename(It->path());
10388 llvm::sys::fs::file_type
Type = It->type();
10389 if (
Type == llvm::sys::fs::file_type::symlink_file) {
10390 if (
auto FileStatus = FS.status(It->path()))
10391 Type = FileStatus->getType();
10394 case llvm::sys::fs::file_type::directory_file:
10398 NativeRelDir.empty() && !Filename.consume_back(
".framework"))
10401 AddCompletion(Filename,
true);
10403 case llvm::sys::fs::file_type::regular_file: {
10405 const bool IsHeader = Filename.ends_with_insensitive(
".h") ||
10406 Filename.ends_with_insensitive(
".hh") ||
10407 Filename.ends_with_insensitive(
".hpp") ||
10408 Filename.ends_with_insensitive(
".hxx") ||
10409 Filename.ends_with_insensitive(
".inc") ||
10410 (ExtensionlessHeaders && !Filename.contains(
'.'));
10413 AddCompletion(Filename,
false);
10425 switch (IncludeDir.getLookupType()) {
10430 AddFilesFromIncludeDir(IncludeDir.getDirRef()->getName(), IsSystem,
10434 AddFilesFromIncludeDir(IncludeDir.getFrameworkDirRef()->getName(),
10443 const auto &S =
SemaRef.PP.getHeaderSearchInfo();
10444 using llvm::make_range;
10447 if (
auto CurFile =
SemaRef.PP.getCurrentFileLexer()->getFileEntry())
10448 AddFilesFromIncludeDir(CurFile->getDir().getName(),
false,
10450 for (
const auto &D : make_range(S.quoted_dir_begin(), S.quoted_dir_end()))
10451 AddFilesFromDirLookup(D,
false);
10453 for (
const auto &D : make_range(S.angled_dir_begin(), S.angled_dir_end()))
10454 AddFilesFromDirLookup(D,
false);
10455 for (
const auto &D : make_range(S.system_dir_begin(), S.system_dir_end()))
10456 AddFilesFromDirLookup(D,
true);
10459 Results.getCompletionContext(), Results.data(),
10473 Results.EnterNewScope();
10474 static const char *Platforms[] = {
"macOS",
"iOS",
"watchOS",
"tvOS"};
10478 Twine(Platform) +
"ApplicationExtension")));
10480 Results.ExitScope();
10482 Results.getCompletionContext(), Results.data(),
10489 ResultBuilder Builder(
SemaRef, Allocator, CCTUInfo,
10492 CodeCompletionDeclConsumer Consumer(
10504 Results.insert(Results.end(), Builder.data(),
10505 Builder.data() + Builder.size());
This file provides AST data structures related to concepts.
bool TraverseNestedNameSpecifierLoc(NestedNameSpecifierLoc QualifierLoc)
static Decl::Kind getKind(const Decl *D)
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate....
This file defines the classes used to store parsed information about declaration-specifiers and decla...
Defines the C++ template declaration subclasses.
Defines the ExceptionSpecificationType enumeration and various utility functions.
Defines the clang::Expr interface and subclasses for C++ expressions.
Defines Expressions and AST nodes for C++2a concepts.
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 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 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 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 void AddObjCTopLevelResults(ResultBuilder &Results, bool NeedAt)
static void AddFunctionParameterChunks(Preprocessor &PP, const PrintingPolicy &Policy, const FunctionDecl *Function, CodeCompletionBuilder &Result, unsigned Start=0, bool InOptional=false)
Add function parameter chunks to the given code completion string.
llvm::SmallPtrSet< const IdentifierInfo *, 16 > AddedPropertiesSet
The set of properties that have already been added, referenced by property name.
static bool argMatchesTemplateParams(const ParsedTemplateArgument &Arg, unsigned Index, const TemplateParameterList &Params)
static void setInBaseClass(ResultBuilder::Result &R)
static void AddObjCMethods(ObjCContainerDecl *Container, bool WantInstanceMethods, ObjCMethodKind WantKind, ArrayRef< const IdentifierInfo * > SelIdents, DeclContext *CurContext, VisitedSelectorSet &Selectors, bool AllowSameLength, ResultBuilder &Results, bool InOriginalClass=true, bool IsRootClass=false)
Add all of the Objective-C methods in the given Objective-C container to the set of results.
static bool shouldIgnoreDueToReservedName(const NamedDecl *ND, Sema &SemaRef)
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 void AddStorageSpecifiers(SemaCodeCompletion::ParserCompletionContext CCC, const LangOptions &LangOpts, ResultBuilder &Results)
static const NamedDecl * extractFunctorCallOperator(const NamedDecl *ND)
static void AddFunctionSpecifiers(SemaCodeCompletion::ParserCompletionContext CCC, const LangOptions &LangOpts, ResultBuilder &Results)
static QualType ProduceSignatureHelp(Sema &SemaRef, MutableArrayRef< ResultCandidate > Candidates, unsigned CurrentArg, SourceLocation OpenParLoc, bool Braced)
static std::string FormatFunctionParameter(const PrintingPolicy &Policy, const DeclaratorDecl *Param, bool SuppressName=false, bool SuppressBlock=false, std::optional< ArrayRef< QualType > > ObjCSubsts=std::nullopt)
static RecordDecl * getAsRecordDecl(QualType BaseType, HeuristicResolver &Resolver)
static void AddOverrideResults(ResultBuilder &Results, const CodeCompletionContext &CCContext, CodeCompletionBuilder &Builder)
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 AddTypedefResult(ResultBuilder &Results)
static void AddPrettyFunctionResults(const LangOptions &LangOpts, ResultBuilder &Results)
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 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 AddObjCImplementationResults(const LangOptions &LangOpts, ResultBuilder &Results, bool NeedAt)
static ObjCMethodDecl * AddSuperSendCompletion(Sema &S, bool NeedSuperKeyword, ArrayRef< const IdentifierInfo * > SelIdents, ResultBuilder &Results)
static void AddRecordMembersCompletionResults(Sema &SemaRef, ResultBuilder &Results, Scope *S, QualType BaseType, ExprValueKind BaseKind, RecordDecl *RD, std::optional< FixItHint > AccessOpFixIt)
static void AddObjCBlockCall(ASTContext &Context, const PrintingPolicy &Policy, CodeCompletionBuilder &Builder, const NamedDecl *BD, const FunctionTypeLoc &BlockLoc, const FunctionProtoTypeLoc &BlockProtoLoc)
Adds a block invocation code completion result for the given block declaration BD.
static void AddLambdaCompletion(ResultBuilder &Results, llvm::ArrayRef< QualType > Parameters, const LangOptions &LangOpts)
Adds a pattern completion for a lambda expression with the specified parameter types and placeholders...
static void AddFunctionTypeQuals(CodeCompletionBuilder &Result, const Qualifiers Quals)
static void AddTypeSpecifierResults(const LangOptions &LangOpts, ResultBuilder &Results)
Add type specifiers for the current language as keyword results.
static std::optional< unsigned > getNextAggregateIndexAfterDesignatedInit(const ResultCandidate &Aggregate, ArrayRef< Expr * > Args)
static std::string GetDefaultValueString(const ParmVarDecl *Param, const SourceManager &SM, const LangOptions &LangOpts)
static CodeCompletionContext mapCodeCompletionContext(Sema &S, SemaCodeCompletion::ParserCompletionContext PCC)
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 OverloadCompare compareOverloads(const CXXMethodDecl &Candidate, const CXXMethodDecl &Incumbent, const Qualifiers &ObjectQuals, ExprValueKind ObjectKind, const ASTContext &Ctx)
static void FindImplementableMethods(ASTContext &Context, ObjCContainerDecl *Container, std::optional< bool > WantInstanceMethods, QualType ReturnType, KnownMethodsMap &KnownMethods, bool InOriginalClass=true)
Find all of the methods that reside in the given container (and its superclasses, protocols,...
static bool anyNullArguments(ArrayRef< Expr * > Args)
static const char * noUnderscoreAttrScope(llvm::StringRef Scope)
static void AddFunctionTypeQualsToCompletionString(CodeCompletionBuilder &Result, const FunctionDecl *Function)
static void MaybeAddSentinel(Preprocessor &PP, const NamedDecl *FunctionOrMethod, CodeCompletionBuilder &Result)
static void AddOverloadParameterChunks(ASTContext &Context, const PrintingPolicy &Policy, const FunctionDecl *Function, const FunctionProtoType *Prototype, FunctionProtoTypeLoc PrototypeLoc, CodeCompletionBuilder &Result, unsigned CurrentArg, unsigned Start=0, bool InOptional=false)
Add function overload parameter chunks to the given code completion string.
static void AddObjCProperties(const CodeCompletionContext &CCContext, ObjCContainerDecl *Container, bool AllowCategories, bool AllowNullaryMethods, DeclContext *CurContext, AddedPropertiesSet &AddedProperties, ResultBuilder &Results, bool IsBaseExprStatement=false, bool IsClassProperty=false, bool InOriginalClass=true)
static void HandleCodeCompleteResults(Sema *S, CodeCompleteConsumer *CodeCompleter, const CodeCompletionContext &Context, CodeCompletionResult *Results, unsigned NumResults)
static void AddTypeQualifierResults(DeclSpec &DS, ResultBuilder &Results, const LangOptions &LangOpts)
static void MaybeAddOverrideCalls(Sema &S, DeclContext *InContext, ResultBuilder &Results)
If we're in a C++ virtual member function, add completion results that invoke the functions we overri...
static ObjCContainerDecl * getContainerDef(ObjCContainerDecl *Container)
Retrieve the container definition, if any?
static const char * underscoreAttrScope(llvm::StringRef Scope)
static bool isAcceptableObjCMethod(ObjCMethodDecl *Method, ObjCMethodKind WantKind, ArrayRef< const IdentifierInfo * > SelIdents, bool AllowSameLength=true)
static void AddFunctionExceptSpecToCompletionString(std::string &NameAndSignature, const FunctionDecl *Function)
static void AddObjCExpressionResults(ResultBuilder &Results, bool NeedAt)
static bool WantTypesInContext(SemaCodeCompletion::ParserCompletionContext CCC, const LangOptions &LangOpts)
CodeCompleteConsumer::OverloadCandidate ResultCandidate
static std::string templateResultType(const TemplateDecl *TD, const PrintingPolicy &Policy)
static void AddTypedNameChunk(ASTContext &Context, const PrintingPolicy &Policy, const NamedDecl *ND, CodeCompletionBuilder &Result)
Add the name of the given declaration.
static void AddClassMessageCompletions(Sema &SemaRef, Scope *S, ParsedType Receiver, ArrayRef< const IdentifierInfo * > SelIdents, bool AtArgumentExpression, bool IsSuper, ResultBuilder &Results)
static const char * GetCompletionTypeString(QualType T, ASTContext &Context, const PrintingPolicy &Policy, CodeCompletionAllocator &Allocator)
Retrieve the string representation of the given type as a string that has the appropriate lifetime fo...
static bool InheritsFromClassNamed(ObjCInterfaceDecl *Class, StringRef Name)
Determine whether the given class is or inherits from a class by the given name.
#define OBJC_AT_KEYWORD_NAME(NeedAt, Keyword)
Macro that optionally prepends an "@" to the string literal passed in via Keyword,...
static bool isAcceptableObjCSelector(Selector Sel, ObjCMethodKind WantKind, ArrayRef< const IdentifierInfo * > SelIdents, bool AllowSameLength=true)
static QualType getPreferredTypeOfBinaryRHS(Sema &S, Expr *LHS, tok::TokenKind Op)
static void AddOrdinaryNameResults(SemaCodeCompletion::ParserCompletionContext CCC, Scope *S, Sema &SemaRef, ResultBuilder &Results)
Add language constructs that show up for "ordinary" names.
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 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 QualType getDesignatedType(QualType BaseType, const Designation &Desig, HeuristicResolver &Resolver)
static void AddObjCInterfaceResults(const LangOptions &LangOpts, ResultBuilder &Results, bool NeedAt)
static bool isNamespaceScope(Scope *S)
Determine whether this scope denotes a namespace.
static PrintingPolicy getCompletionPrintingPolicy(const ASTContext &Context, const Preprocessor &PP)
This file declares facilities that support code completion.
This file declares semantic analysis for Objective-C.
static TemplateDecl * getDescribedTemplate(Decl *Templated)
Defines various enumerations that describe declaration and type specifiers.
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 ...
static CanQualType getCanonicalType(QualType T)
Return the canonical (structural) type corresponding to the specified potentially non-canonical type ...
QualType getPointerType(QualType T) const
Return the uniqued reference to the type for a pointer to the specified type.
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>.
const RawComment * getRawCommentForAnyRedecl(const Decl *D, const Decl **OriginalDecl=nullptr) const
Return the documentation comment attached to a given declaration.
QualType getTagType(ElaboratedTypeKeyword Keyword, NestedNameSpecifier Qualifier, const TagDecl *TD, bool OwnsTag) const
static bool hasSameUnqualifiedType(QualType T1, QualType T2)
Determine whether the given types are equivalent after cvr-qualifiers have been removed.
QualType getElementType() const
Syntax
The style used to specify an attribute.
Type source information for an attributed type.
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.
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.
Qualifiers getMethodQualifiers() const
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.
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.
CaseStmt - Represent a case statement.
Represents a byte-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 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 AddOptionalChunk(CodeCompletionString *Optional)
Add a new optional 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, functionor 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)
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.
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.
NestedNameSpecifier Qualifier
If the result should have a nested-name-specifier, this is it.
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 ...
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 ('<').
Expr * getConstraintExpr() const
const TypeClass * getTypePtr() const
static DeclAccessPair make(NamedDecl *D, AccessSpecifier AS)
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 isRequiresExprBody() const
bool isFileContext() const
DeclContextLookupResult lookup_result
ASTContext & getParentASTContext() const
bool isDependentContext() const
Determines whether this context is dependent on a template parameter.
bool isTranslationUnit() const
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 semantically 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
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.
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
OverloadedOperatorKind getCXXOverloadedOperator() const
If this name is the name of an overloadable operator in C++ (e.g., operator+), retrieve the kind of o...
@ CXXConversionFunctionName
QualType getCXXNameType() const
If this name is one of the C++ names (of a constructor, destructor, or conversion function),...
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.
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).
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 ...
virtual bool TraverseNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS)
This represents one expression.
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.
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.
ArrayRef< ParmVarDecl * > parameters() const
bool isVariadic() const
Whether this function is variadic.
unsigned getNumParams() const
Return the number of parameters this function must have based on its FunctionType.
Represents a prototype with parameter type info, e.g.
ExceptionSpecInfo getExceptionSpecInfo() const
Return all the available information about this type's exception spec.
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
QualType simplifyType(QualType Type, const Expr *E, bool UnwrapPointer)
TagDecl * resolveTypeToTagDecl(QualType T) const
QualType resolveExprToType(const Expr *E) 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.
A simple pair of identifier info and location.
const TypeClass * getTypePtr() const
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.
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.
ModuleKind Kind
The kind of this module.
llvm::iterator_range< submodule_iterator > submodules()
@ ImplicitGlobalModuleFragment
This is an implicit fragment of the global module which contains only language linkage declarations (...
@ ModulePartitionInterface
This is a C++20 module partition interface.
@ ModuleInterfaceUnit
This is a C++20 module interface unit.
@ PrivateModuleFragment
This is the private module fragment within some C++ module.
@ ExplicitGlobalModuleFragment
This is the explicit Global Module Fragment of a modular TU.
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.
NestedNameSpecifier getNestedNameSpecifier() const
Retrieve the nested-name-specifier to which this instance refers.
Represents a C++ nested name specifier, such as "\::std::vector<int>::".
void print(raw_ostream &OS, const PrintingPolicy &Policy, bool ResolveTemplateArguments=false, bool PrintFinalScopeResOp=true) const
Print this nested name specifier to the given output stream.
bool isDependent() const
Whether this nested name specifier refers to a dependent type or not.
const Type * getAsType() const
@ Type
A type, stored as a Type*.
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.
method_range methods() const
instprop_range instance_properties() const
classprop_range class_properties() const
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.
unsigned param_size() const
param_const_iterator param_end() const
param_const_iterator param_begin() const
const ParmVarDecl *const * param_const_iterator
Selector getSelector() const
bool isInstanceMethod() 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 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_CodeCompletion
When doing overload resolution during code completion, we want to show all viable candidates,...
CandidateSetKind getKind() const
Represents a parameter to a function.
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.
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.
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 substObjCTypeArgs(ASTContext &ctx, ArrayRef< QualType > typeArgs, ObjCSubstitutionContext context) const
Substitute type arguments for the Objective-C type parameters used in the subject type.
static std::string getAsString(SplitQualType split, const PrintingPolicy &Policy)
Wrapper of type source information for a type with non-trivial direct qualifiers.
The collection of all-type qualifiers we support.
bool hasOnlyConst() const
bool compatiblyIncludes(Qualifiers other, const ASTContext &Ctx) const
Determines if these qualifiers compatibly include another set.
bool hasOnlyVolatile() const
bool hasOnlyRestrict() const
Represents a struct/union/class.
bool isLambda() const
Determine whether this record is a class describing a lambda function object.
field_range fields() const
Base for LValueReferenceType and RValueReferenceType.
QualType getPointeeType() const
Scope - A scope is a transient data structure that is used while parsing the program.
bool isClassScope() const
isClassScope - Return true if this scope is a class/struct/union scope.
const Scope * getFnParent() const
getFnParent - Return the closest scope that is a function body.
unsigned getFlags() const
getFlags - Return the flags for this scope.
Scope * getContinueParent()
getContinueParent - Return the closest scope that a continue statement would be affected by.
bool isDeclScope(const Decl *D) const
isDeclScope - Return true if this is the scope that the specified decl is declared in.
DeclContext * getEntity() const
Get the entity corresponding to this scope.
bool isTemplateParamScope() const
isTemplateParamScope - Return true if this scope is a C++ template parameter scope.
Scope * getBreakParent()
getBreakParent - Return the closest scope that a break statement would be affected by.
const Scope * getParent() const
getParent - Return the scope that this is nested in.
bool isClassInheritanceScope() const
Determines whether this scope is between inheritance colon and the real class/struct definition.
@ FunctionPrototypeScope
This is a scope that corresponds to the parameters within a function prototype.
@ AtCatchScope
This is a scope that corresponds to the Objective-C @catch statement.
@ TemplateParamScope
This is a scope that corresponds to the template parameters of a C++ template.
@ ClassScope
The scope of a struct/union/class definition.
@ DeclScope
This is a scope that can contain a declaration.
This table allows us to fully hide how we implement multi-keyword caching.
Selector getNullarySelector(const IdentifierInfo *ID)
Selector getSelector(unsigned NumArgs, const IdentifierInfo **IIV)
Can create any sort of selector.
Selector getUnarySelector(const IdentifierInfo *ID)
Smart pointer class that efficiently represents Objective-C method names.
StringRef getNameForSlot(unsigned argIndex) const
Retrieve the name at a given position in the selector.
const IdentifierInfo * getIdentifierInfoForSlot(unsigned argIndex) const
Retrieve the identifier at a given position in the selector.
bool isUnarySelector() const
bool isNull() const
Determine whether this is the empty selector.
unsigned getNumArgs() const
ASTContext & getASTContext() const
const LangOptions & getLangOpts() const
void CodeCompleteObjCInstanceMessage(Scope *S, Expr *Receiver, ArrayRef< const IdentifierInfo * > SelIdents, bool AtArgumentExpression, ObjCInterfaceDecl *Super=nullptr)
void CodeCompleteObjCPropertySynthesizeIvar(Scope *S, IdentifierInfo *PropertyName)
void CodeCompleteAttribute(AttributeCommonInfo::Syntax Syntax, AttributeCompletion Completion=AttributeCompletion::Attribute, const IdentifierInfo *Scope=nullptr)
QualType ProduceTemplateArgumentSignatureHelp(TemplateTy, ArrayRef< ParsedTemplateArgument >, SourceLocation LAngleLoc)
QualType ProduceCtorInitMemberSignatureHelp(Decl *ConstructorDecl, CXXScopeSpec SS, ParsedType TemplateTypeTy, ArrayRef< Expr * > ArgExprs, IdentifierInfo *II, SourceLocation OpenParLoc, bool Braced)
void CodeCompleteObjCClassForwardDecl(Scope *S)
void CodeCompleteNamespaceAliasDecl(Scope *S)
void GatherGlobalCodeCompletions(CodeCompletionAllocator &Allocator, CodeCompletionTUInfo &CCTUInfo, SmallVectorImpl< CodeCompletionResult > &Results)
void CodeCompleteObjCAtStatement(Scope *S)
void CodeCompleteUsing(Scope *S)
void CodeCompleteObjCMessageReceiver(Scope *S)
void CodeCompleteOperatorName(Scope *S)
void CodeCompleteUsingDirective(Scope *S)
void CodeCompleteObjCProtocolDecl(Scope *S)
void CodeCompleteObjCPropertyFlags(Scope *S, ObjCDeclSpec &ODS)
ParserCompletionContext
Describes the context in which code completion occurs.
@ PCC_LocalDeclarationSpecifiers
Code completion occurs within a sequence of declaration specifiers within a function,...
@ PCC_MemberTemplate
Code completion occurs following one or more template headers within a class.
@ PCC_Condition
Code completion occurs within the condition of an if, while, switch, or for statement.
@ PCC_ParenthesizedExpression
Code completion occurs in a parenthesized expression, which might also be a type cast.
@ PCC_TopLevelOrExpression
Code completion occurs at top-level in a REPL session.
@ PCC_Class
Code completion occurs within a class, struct, or union.
@ PCC_ForInit
Code completion occurs at the beginning of the initialization statement (or expression) in a for loop...
@ PCC_Type
Code completion occurs where only a type is permitted.
@ PCC_ObjCImplementation
Code completion occurs within an Objective-C implementation or category implementation.
@ PCC_ObjCInterface
Code completion occurs within an Objective-C interface, protocol, or category.
@ PCC_Namespace
Code completion occurs at top-level or namespace context.
@ PCC_Expression
Code completion occurs within an expression.
@ PCC_RecoveryInFunction
Code completion occurs within the body of a function on a recovery path, where we do not have a speci...
@ PCC_ObjCInstanceVariableList
Code completion occurs within the list of instance variables in an Objective-C interface,...
@ PCC_Template
Code completion occurs following one or more template headers.
@ PCC_Statement
Code completion occurs within a statement, which may also be an expression or a declaration.
void CodeCompleteObjCAtDirective(Scope *S)
void CodeCompleteObjCPropertySetter(Scope *S)
void CodeCompleteLambdaIntroducer(Scope *S, LambdaIntroducer &Intro, bool AfterAmpersand)
void CodeCompleteCase(Scope *S)
void CodeCompleteObjCImplementationCategory(Scope *S, IdentifierInfo *ClassName, SourceLocation ClassNameLoc)
void CodeCompleteObjCInterfaceDecl(Scope *S)
void CodeCompleteFunctionQualifiers(DeclSpec &DS, Declarator &D, const VirtSpecifiers *VS=nullptr)
void CodeCompletePreprocessorMacroName(bool IsDefinition)
void CodeCompleteInPreprocessorConditionalExclusion(Scope *S)
void CodeCompleteObjCAtExpression(Scope *S)
void CodeCompletePreprocessorExpression()
void CodeCompleteTypeQualifiers(DeclSpec &DS)
void CodeCompleteObjCPropertyDefinition(Scope *S)
void CodeCompleteObjCSuperMessage(Scope *S, SourceLocation SuperLoc, ArrayRef< const IdentifierInfo * > SelIdents, bool AtArgumentExpression)
CodeCompleteConsumer * CodeCompleter
Code-completion consumer.
void CodeCompleteAfterFunctionEquals(Declarator &D)
QualType ProduceConstructorSignatureHelp(QualType Type, SourceLocation Loc, ArrayRef< Expr * > Args, SourceLocation OpenParLoc, bool Braced)
OpaquePtr< TemplateName > TemplateTy
void CodeCompleteExpression(Scope *S, const CodeCompleteExpressionData &Data)
Perform code-completion in an expression context when we know what type we're looking for.
HeuristicResolver Resolver
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 CodeCompleteObjCMethodDeclSelector(Scope *S, bool IsInstanceMethod, bool AtParameterName, ParsedType ReturnType, ArrayRef< const IdentifierInfo * > SelIdents)
void CodeCompleteQualifiedId(Scope *S, CXXScopeSpec &SS, bool EnteringContext, bool IsUsingDeclaration, QualType BaseType, QualType PreferredType)
void CodeCompleteIncludedFile(llvm::StringRef Dir, bool IsAngled)
void CodeCompletePreprocessorMacroArgument(Scope *S, IdentifierInfo *Macro, MacroInfo *MacroInfo, unsigned Argument)
void CodeCompleteModuleImport(SourceLocation ImportLoc, ModuleIdPath Path)
void CodeCompleteObjCInterfaceCategory(Scope *S, IdentifierInfo *ClassName, SourceLocation ClassNameLoc)
void CodeCompleteObjCSelector(Scope *S, ArrayRef< const IdentifierInfo * > SelIdents)
void CodeCompleteConstructorInitializer(Decl *Constructor, ArrayRef< CXXCtorInitializer * > Initializers)
void CodeCompleteObjCImplementationDecl(Scope *S)
void CodeCompleteAfterIf(Scope *S, bool IsBracedThen)
void CodeCompleteObjCMethodDecl(Scope *S, std::optional< bool > IsInstanceMethod, ParsedType ReturnType)
void CodeCompleteOrdinaryName(Scope *S, ParserCompletionContext CompletionContext)
OpaquePtr< DeclGroupRef > DeclGroupPtrTy
void CodeCompleteNaturalLanguage()
void CodeCompleteObjCClassPropertyRefExpr(Scope *S, const IdentifierInfo &ClassName, SourceLocation ClassNameLoc, bool IsBaseExprStatement)
void CodeCompleteInitializer(Scope *S, Decl *D)
void CodeCompleteObjCProtocolReferences(ArrayRef< IdentifierLoc > Protocols)
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 CodeCompletePreprocessorDirective(bool InConditional)
SemaCodeCompletion(Sema &S, CodeCompleteConsumer *CompletionConsumer)
void CodeCompleteBracketDeclarator(Scope *S)
void CodeCompleteObjCSuperclass(Scope *S, IdentifierInfo *ClassName, SourceLocation ClassNameLoc)
void CodeCompleteKeywordAfterIf(bool AfterExclaim) const
void CodeCompleteObjCAtVisibility(Scope *S)
void CodeCompleteTag(Scope *S, unsigned TagSpec)
void CodeCompleteObjCClassMessage(Scope *S, ParsedType Receiver, ArrayRef< const IdentifierInfo * > SelIdents, bool AtArgumentExpression, bool IsSuper=false)
void CodeCompleteObjCForCollection(Scope *S, DeclGroupPtrTy IterationVar)
void CodeCompleteAvailabilityPlatformName()
void CodeCompleteMemberReferenceExpr(Scope *S, Expr *Base, Expr *OtherOpBase, SourceLocation OpLoc, bool IsArrow, bool IsBaseExprStatement, QualType PreferredType)
void CodeCompleteObjCPassingType(Scope *S, ObjCDeclSpec &DS, bool IsParameter)
void CodeCompleteObjCPropertyGetter(Scope *S)
void CodeCompleteDeclSpec(Scope *S, DeclSpec &DS, bool AllowNonIdentifiers, bool AllowNestedNameSpecifiers)
void CodeCompletePostfixExpression(Scope *S, ExprResult LHS, QualType PreferredType)
GlobalMethodPool MethodPool
Method Pool - allows efficient lookup when typechecking messages to "id".
void ReadMethodPool(Selector Sel)
Read the contents of the method pool for a given selector from external storage.
Sema - This implements semantic analysis and AST building for C.
QualType getCurrentThisType()
Try to retrieve the type of the 'this' pointer.
bool IsOverload(FunctionDecl *New, FunctionDecl *Old, bool UseMemberUsingDeclRules, bool ConsiderCudaAttrs=true)
@ LookupOrdinaryName
Ordinary name lookup, which finds ordinary names (functions, variables, typedefs, etc....
@ LookupNestedNameSpecifierName
Look up of a name that precedes the '::' scope resolution operator in C++.
@ LookupMemberName
Member name lookup, which finds the names of class/struct/union members.
@ LookupTagName
Tag name lookup, which finds the names of enums, classes, structs, and unions.
@ LookupAnyName
Look up any declaration with any name.
Preprocessor & getPreprocessor() const
ASTContext & getASTContext() const
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...
const LangOptions & getLangOpts() const
void LookupVisibleDecls(Scope *S, LookupNameKind Kind, VisibleDeclConsumer &Consumer, bool IncludeGlobalScope=true, bool LoadExternal=true)
SemaCodeCompletion & CodeCompletion()
sema::FunctionScopeInfo * getCurFunction() const
Module * getCurrentModule() const
Get the module unit whose scope we are currently within.
sema::BlockScopeInfo * getCurBlock()
Retrieve the current block, if any.
DeclContext * CurContext
CurContext - This is the current declaration context of parsing.
ExternalSemaSource * getExternalSource() const
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...
SourceManager & SourceMgr
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.
Stores a list of template parameters for a TemplateDecl and its derived classes.
NamedDecl * getParam(unsigned Idx)
NamedDecl ** iterator
Iterates through the template parameters in this list.
bool hasParameterPack() const
Determine whether this template parameter list contains a parameter pack.
ArrayRef< NamedDecl * > asArray()
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.
The top declaration context.
const ASTTemplateArgumentListInfo * getTemplateArgsAsWritten() const
void print(llvm::raw_ostream &OS, const PrintingPolicy &Policy) const
TemplateDecl * 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.
bool isBlockPointerType() const
bool isBooleanType() const
const ObjCObjectPointerType * getAsObjCQualifiedIdType() const
CXXRecordDecl * getAsCXXRecordDecl() const
Retrieves the CXXRecordDecl that this type refers to, either because the type is a RecordType or beca...
RecordDecl * getAsRecordDecl() const
Retrieves the RecordDecl this type refers to.
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
NestedNameSpecifier getPrefix() const
If this type represents a qualified-id, this returns its nested name specifier.
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 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...
const T * getAs() const
Member-template getAs<specific type>'.
bool isRecordType() const
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...
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.
@ 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...
const internal::VariadicAllOfMatcher< Type > type
Matches Types in the clang AST.
@ OS
Indicates that the tracking object is a descendant of a referenced-counted OSObject,...
bool Alloc(InterpState &S, CodePtr OpPC, const Descriptor *Desc)
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.
CanQual< Type > CanQualType
Represents a canonical, potentially-qualified type.
@ OO_None
Not an overloaded operator.
@ NUM_OVERLOADED_OPERATORS
bool isa(CodeGen::Address addr)
@ CCP_Type
Priority for a type.
@ CCP_ObjC_cmd
Priority for the Objective-C "_cmd" implicit parameter.
@ CCP_Keyword
Priority for a language keyword (that isn't any of the other categories).
@ 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.
@ Specialization
We are substituting template parameters for template arguments in order to form a template specializa...
bool isBetterOverloadCandidate(Sema &S, const OverloadCandidate &Cand1, const OverloadCandidate &Cand2, SourceLocation Loc, OverloadCandidateSet::CandidateSetKind Kind, bool PartialOverloading=false)
isBetterOverloadCandidate - Determines whether the first overload candidate is a better candidate tha...
bool isReservedInAllContexts(ReservedIdentifierStatus Status)
Determine whether an identifier is reserved in all contexts.
ArrayRef< IdentifierLoc > ModuleIdPath
A sequence of identifier/location pairs used to describe a particular module or submodule,...
@ 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.
@ 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.
@ IK_ConstructorName
A constructor name.
@ IK_DestructorName
A destructor name.
@ IK_OperatorFunctionId
An overloaded operator name, e.g., operator+.
nullptr
This class represents a compute construct, representing a 'Kind' of ‘parallel’, 'serial',...
@ 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.
@ Template
We are parsing a template declaration.
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.
@ NonType
The name was classified as a specific non-type, non-template declaration.
@ Type
The name was classified as a type.
@ OverloadSet
The name was classified as an overload set, and an expression representing that overload set has been...
const RawComment * getCompletionComment(const ASTContext &Ctx, const NamedDecl *Decl)
Get the documentation comment used to produce CodeCompletionString::BriefComment for RK_Declaration.
@ 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....
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.
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)
DynamicRecursiveASTVisitorBase< false > DynamicRecursiveASTVisitor
U cast(CodeGen::Address addr)
@ Enumerator
Enumerator value with fixed underlying type.
QualType getDeclUsageType(ASTContext &C, NestedNameSpecifier Qualifier, const NamedDecl *ND)
Determine the type that this declaration will have if it is used as a type or in an expression.
OpaquePtr< QualType > ParsedType
An opaque type for threading parsed type information through the parser.
@ Interface
The "__interface" keyword introduces the elaborated-type-specifier.
@ None
No keyword precedes the qualified type name.
@ Class
The "class" keyword introduces the elaborated-type-specifier.
@ Enum
The "enum" keyword introduces the elaborated-type-specifier.
@ StartsWithDoubleUnderscore
ActionResult< Expr * > ExprResult
@ EST_BasicNoexcept
noexcept
@ EST_NoexceptTrue
noexcept(expression), evals to 'true'
__UINTPTR_TYPE__ uintptr_t
An unsigned integer type with the property that any valid pointer to void can be converted to this ty...
bool IntegralConstantExpression
SmallVector< Decl *, 4 > IgnoreDecls
CodeCompleteExpressionData(QualType PreferredType=QualType(), bool IsParenthesized=false)
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.
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 CleanUglifiedParameters
Whether to strip underscores when printing reserved parameter names.
unsigned SuppressStrongLifetime
When true, suppress printing of the __strong lifetime qualifier in ARC.
@ Plain
E.g., (anonymous enum)/(unnamed struct)/etc.
unsigned SuppressTemplateArgsInCXXConstructors
When true, suppresses printing template arguments in names of C++ constructors.
unsigned AnonymousTagNameStyle