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,
373 bool IsInDeclarationContext,
bool IsAddressOfOperand);
376 void AddResult(Result R);
379 void EnterNewScope();
388 void addVisitedContext(DeclContext *Ctx) {
389 CompletionContext.addVisitedContext(Ctx);
398 bool IsOrdinaryName(
const NamedDecl *ND)
const;
399 bool IsOrdinaryNonTypeName(
const NamedDecl *ND)
const;
400 bool IsIntegralConstantValue(
const NamedDecl *ND)
const;
401 bool IsOrdinaryNonValueName(
const NamedDecl *ND)
const;
402 bool IsNestedNameSpecifier(
const NamedDecl *ND)
const;
403 bool IsEnum(
const NamedDecl *ND)
const;
404 bool IsClassOrStruct(
const NamedDecl *ND)
const;
405 bool IsUnion(
const NamedDecl *ND)
const;
406 bool IsNamespace(
const NamedDecl *ND)
const;
407 bool IsNamespaceOrAlias(
const NamedDecl *ND)
const;
408 bool IsType(
const NamedDecl *ND)
const;
409 bool IsMember(
const NamedDecl *ND)
const;
410 bool IsObjCIvar(
const NamedDecl *ND)
const;
411 bool IsObjCMessageReceiver(
const NamedDecl *ND)
const;
412 bool IsObjCMessageReceiverOrLambdaCapture(
const NamedDecl *ND)
const;
413 bool IsObjCCollection(
const NamedDecl *ND)
const;
414 bool IsImpossibleToSatisfy(
const NamedDecl *ND)
const;
424 ComputeType =
nullptr;
425 Type = BSI->ReturnType;
429 ComputeType =
nullptr;
433 ComputeType =
nullptr;
434 Type =
Method->getReturnType();
442 auto *VD = llvm::dyn_cast_or_null<ValueDecl>(D);
443 ComputeType =
nullptr;
444 Type = VD ? VD->getType() :
QualType();
456 ComputeType =
nullptr;
466 this->ComputeType = ComputeType;
476 if (ExpectedLoc == LParLoc)
487 if (Op == tok::plus || Op == tok::plusequal || Op == tok::minusequal)
490 if (Op == tok::minus)
503 case tok::minusequal:
505 case tok::percentequal:
507 case tok::slashequal:
513 case tok::equalequal:
514 case tok::exclaimequal:
518 case tok::greaterequal:
522 case tok::greatergreater:
523 case tok::greatergreaterequal:
525 case tok::lesslessequal:
538 case tok::caretequal:
546 case tok::periodstar:
564 if (!ContextType.isNull() && ContextType->isPointerType())
565 return ContextType->getPointeeType();
568 if (ContextType.isNull())
574 case tok::minusminus:
576 if (ContextType.isNull())
584 assert(
false &&
"unhandled unary op");
593 ComputeType =
nullptr;
600 if (!Enabled || !
Base)
603 if (ExpectedLoc !=
Base->getBeginLoc())
614 ComputeType =
nullptr;
623 ComputeType =
nullptr;
632 ComputeType =
nullptr;
640 ComputeType =
nullptr;
646 llvm::PointerUnion<const NamedDecl *, const DeclIndexPair *> DeclOrIterator;
647 unsigned SingleDeclIndex;
659 pointer(
const DeclIndexPair &Value) : Value(Value) {}
667 : DeclOrIterator(SingleDecl), SingleDeclIndex(Index) {}
670 : DeclOrIterator(Iterator), SingleDeclIndex(0) {}
692 if (
const NamedDecl *ND = dyn_cast<const NamedDecl *>(DeclOrIterator))
701 return X.DeclOrIterator.getOpaqueValue() ==
702 Y.DeclOrIterator.getOpaqueValue() &&
703 X.SingleDeclIndex == Y.SingleDeclIndex;
712ResultBuilder::ShadowMapEntry::begin()
const {
713 if (DeclOrVector.isNull())
716 if (
const NamedDecl *ND = dyn_cast<const NamedDecl *>(DeclOrVector))
717 return iterator(ND, SingleDeclIndex);
723ResultBuilder::ShadowMapEntry::end()
const {
748 for (
const DeclContext *CommonAncestor = TargetContext;
749 CommonAncestor && !CommonAncestor->
Encloses(CurContext);
750 CommonAncestor = CommonAncestor->getLookupParent()) {
751 if (CommonAncestor->isTransparentContext() ||
752 CommonAncestor->isFunctionOrMethod())
755 TargetParents.push_back(CommonAncestor);
759 while (!TargetParents.empty()) {
760 const DeclContext *Parent = TargetParents.pop_back_val();
762 if (
const auto *Namespace = dyn_cast<NamespaceDecl>(Parent)) {
763 if (!Namespace->getIdentifier())
767 }
else if (
const auto *TD = dyn_cast<TagDecl>(Parent)) {
800bool ResultBuilder::isInterestingDecl(
const NamedDecl *ND,
801 bool &AsNestedNameSpecifier)
const {
802 AsNestedNameSpecifier =
false;
828 if (Filter == &ResultBuilder::IsNestedNameSpecifier ||
830 Filter != &ResultBuilder::IsNamespaceOrAlias && Filter !=
nullptr))
831 AsNestedNameSpecifier =
true;
834 if (Filter && !(this->*Filter)(Named)) {
836 if (AllowNestedNameSpecifiers && SemaRef.
getLangOpts().CPlusPlus &&
837 IsNestedNameSpecifier(ND) &&
838 (Filter != &ResultBuilder::IsMember ||
841 AsNestedNameSpecifier =
true;
860 R.Declaration->getDeclContext()->getRedeclContext();
871 R.QualifierIsInformative =
false;
875 R.Declaration->getDeclContext());
882 switch (T->getTypeClass()) {
885 case BuiltinType::Void:
888 case BuiltinType::NullPtr:
891 case BuiltinType::Overload:
892 case BuiltinType::Dependent:
895 case BuiltinType::ObjCId:
896 case BuiltinType::ObjCClass:
897 case BuiltinType::ObjCSel:
910 case Type::BlockPointer:
913 case Type::LValueReference:
914 case Type::RValueReference:
917 case Type::ConstantArray:
918 case Type::IncompleteArray:
919 case Type::VariableArray:
920 case Type::DependentSizedArray:
923 case Type::DependentSizedExtVector:
925 case Type::ExtVector:
928 case Type::FunctionProto:
929 case Type::FunctionNoProto:
938 case Type::ObjCObject:
939 case Type::ObjCInterface:
940 case Type::ObjCObjectPointer:
954 if (
const auto *
Type = dyn_cast<TypeDecl>(ND))
956 if (
const auto *Iface = dyn_cast<ObjCInterfaceDecl>(ND))
957 return C.getObjCInterfaceType(Iface);
962 else if (
const auto *
Method = dyn_cast<ObjCMethodDecl>(ND))
963 T =
Method->getSendResultType();
964 else if (
const auto *
Enumerator = dyn_cast<EnumConstantDecl>(ND))
968 else if (
const auto *
Property = dyn_cast<ObjCPropertyDecl>(ND))
970 else if (
const auto *
Value = dyn_cast<ValueDecl>(ND))
981 T = Ref->getPointeeType();
986 if (
Pointer->getPointeeType()->isFunctionType()) {
995 T =
Block->getPointeeType();
1010unsigned ResultBuilder::getBasePriority(
const NamedDecl *ND) {
1018 if (
const auto *ImplicitParam = dyn_cast<ImplicitParamDecl>(ND))
1019 if (ImplicitParam->getIdentifier() &&
1020 ImplicitParam->getIdentifier()->isStr(
"_cmd"))
1049 CompletionContext.
getKind() ==
1051 CompletionContext.
getKind() ==
1058void ResultBuilder::AdjustResultPriorityForDecl(
Result &R) {
1061 if (!PreferredSelector.
isNull())
1062 if (
const auto *
Method = dyn_cast<ObjCMethodDecl>(
R.Declaration))
1063 if (PreferredSelector ==
Method->getSelector())
1068 if (!PreferredType.
isNull()) {
1078 !(PreferredType->isEnumeralType() && TC->isEnumeralType()))
1088 Context.DeclarationNames.getCXXConstructorName(RecordTy);
1089 return Record->lookup(ConstructorName);
1092void ResultBuilder::MaybeAddConstructorResults(
Result R) {
1093 if (!SemaRef.
getLangOpts().CPlusPlus || !
R.Declaration ||
1100 Record = ClassTemplate->getTemplatedDecl();
1101 else if ((
Record = dyn_cast<CXXRecordDecl>(D))) {
1115 R.Declaration = Ctor;
1117 Results.push_back(R);
1122 if (
const auto *Tmpl = dyn_cast<FunctionTemplateDecl>(ND))
1123 ND = Tmpl->getTemplatedDecl();
1128 assert(!ShadowMaps.empty() &&
"Must enter into a results scope");
1130 if (
R.Kind != Result::RK_Declaration) {
1132 Results.push_back(R);
1137 if (
const UsingShadowDecl *Using = dyn_cast<UsingShadowDecl>(
R.Declaration)) {
1139 getBasePriority(
Using->getTargetDecl()),
1143 std::move(
R.FixIts));
1145 MaybeAddResult(
Result, CurContext);
1149 const Decl *CanonDecl =
R.Declaration->getCanonicalDecl();
1152 bool AsNestedNameSpecifier =
false;
1153 if (!isInterestingDecl(
R.Declaration, AsNestedNameSpecifier))
1160 ShadowMap &SMap = ShadowMaps.back();
1161 ShadowMapEntry::iterator I, IEnd;
1162 ShadowMap::iterator NamePos = SMap.find(
R.Declaration->getDeclName());
1163 if (NamePos != SMap.end()) {
1164 I = NamePos->second.begin();
1165 IEnd = NamePos->second.end();
1168 for (; I != IEnd; ++I) {
1170 unsigned Index = I->second;
1173 Results[Index].Declaration =
R.Declaration;
1183 std::list<ShadowMap>::iterator
SM, SMEnd = ShadowMaps.end();
1185 for (
SM = ShadowMaps.begin();
SM != SMEnd; ++
SM) {
1186 ShadowMapEntry::iterator I, IEnd;
1187 ShadowMap::iterator NamePos =
SM->find(
R.Declaration->getDeclName());
1188 if (NamePos !=
SM->end()) {
1189 I = NamePos->second.begin();
1190 IEnd = NamePos->second.end();
1192 for (; I != IEnd; ++I) {
1194 if (I->first->hasTagIdentifierNamespace() &&
1202 I->first->getIdentifierNamespace() != IDNS)
1206 if (CheckHiddenResult(R, CurContext, I->first))
1214 if (!AllDeclsFound.insert(CanonDecl).second)
1219 if (AsNestedNameSpecifier) {
1220 R.StartsNestedNameSpecifier =
true;
1223 AdjustResultPriorityForDecl(R);
1226 if (
R.QualifierIsInformative && !
R.Qualifier &&
1227 !
R.StartsNestedNameSpecifier) {
1228 const DeclContext *Ctx =
R.Declaration->getDeclContext();
1229 if (
const NamespaceDecl *Namespace = dyn_cast<NamespaceDecl>(Ctx))
1232 else if (
const TagDecl *Tag = dyn_cast<TagDecl>(Ctx))
1236 std::nullopt, Tag,
false)
1239 R.QualifierIsInformative =
false;
1244 SMap[
R.Declaration->getDeclName()].Add(
R.Declaration, Results.size());
1245 Results.push_back(R);
1247 if (!AsNestedNameSpecifier)
1248 MaybeAddConstructorResults(R);
1253 R.InBaseClass =
true;
1274 for (
unsigned I = 0, E = Candidate.
getNumParams(); I != E; ++I)
1275 if (Candidate.
parameters()[I]->getType().getCanonicalType() !=
1276 Incumbent.
parameters()[I]->getType().getCanonicalType())
1285 if (CandidateRef != IncumbentRef) {
1301 if (CandidateSuperset == IncumbentSuperset)
1313 const auto *CurrentClassScope = [&]() ->
const CXXRecordDecl * {
1315 const auto *CtxMethod = llvm::dyn_cast<CXXMethodDecl>(Ctx);
1316 if (CtxMethod && !CtxMethod->getParent()->isLambda()) {
1317 return CtxMethod->getParent();
1324 bool FunctionCanBeCall =
1325 CurrentClassScope &&
1326 (CurrentClassScope ==
Method->getParent() ||
1327 CurrentClassScope->isDerivedFrom(
Method->getParent()));
1330 if (FunctionCanBeCall)
1335 BaseExprType.
isNull() ?
nullptr
1337 auto *MaybeBase =
Method->getParent();
1339 MaybeDerived == MaybeBase || MaybeDerived->isDerivedFrom(MaybeBase);
1342 return FunctionCanBeCall;
1345bool ResultBuilder::canFunctionBeCalled(
const NamedDecl *ND,
1356 if (
const auto *FuncTmpl = dyn_cast<FunctionTemplateDecl>(ND)) {
1357 ND = FuncTmpl->getTemplatedDecl();
1359 const auto *
Method = dyn_cast<CXXMethodDecl>(ND);
1361 return canCxxMethodBeCalled(
Method, BaseExprType);
1368 NamedDecl *Hiding,
bool InBaseClass =
false,
1370 bool IsInDeclarationContext =
false,
1371 bool IsAddressOfOperand =
false) {
1372 if (
R.Kind != Result::RK_Declaration) {
1374 Results.push_back(R);
1379 if (
const auto *Using = dyn_cast<UsingShadowDecl>(
R.Declaration)) {
1381 getBasePriority(
Using->getTargetDecl()),
1385 std::move(
R.FixIts));
1387 AddResult(
Result, CurContext, Hiding,
false,
1392 bool AsNestedNameSpecifier =
false;
1393 if (!isInterestingDecl(
R.Declaration, AsNestedNameSpecifier))
1400 if (Hiding && CheckHiddenResult(R, CurContext, Hiding))
1404 if (!AllDeclsFound.insert(
R.Declaration->getCanonicalDecl()).second)
1409 if (AsNestedNameSpecifier) {
1410 R.StartsNestedNameSpecifier =
true;
1412 }
else if (Filter == &ResultBuilder::IsMember && !
R.Qualifier &&
1415 R.Declaration->getDeclContext()->getRedeclContext()))
1416 R.QualifierIsInformative =
true;
1419 if (
R.QualifierIsInformative && !
R.Qualifier &&
1420 !
R.StartsNestedNameSpecifier) {
1421 const DeclContext *Ctx =
R.Declaration->getDeclContext();
1422 if (
const auto *Namespace = dyn_cast<NamespaceDecl>(Ctx))
1425 else if (
const auto *Tag = dyn_cast<TagDecl>(Ctx))
1429 std::nullopt, Tag,
false)
1432 R.QualifierIsInformative =
false;
1439 AdjustResultPriorityForDecl(R);
1442 const auto GetQualifiers = [&](
const CXXMethodDecl *MethodDecl) {
1443 if (MethodDecl->isExplicitObjectMemberFunction())
1444 return MethodDecl->getFunctionObjectParameterType().getQualifiers();
1446 return MethodDecl->getMethodQualifiers();
1449 if (IsExplicitObjectMemberFunction &&
1458 if (HasObjectTypeQualifiers)
1459 if (
const auto *
Method = dyn_cast<CXXMethodDecl>(
R.Declaration))
1460 if (
Method->isInstance()) {
1462 if (ObjectTypeQualifiers == MethodQuals)
1464 else if (ObjectTypeQualifiers - MethodQuals) {
1470 switch (
Method->getRefQualifier()) {
1487 CurContext,
Method->getDeclName().getAsOpaqueInteger())];
1489 Result &Incumbent = Results[Entry.second];
1492 ObjectTypeQualifiers, ObjectKind,
1498 Incumbent = std::move(R);
1509 R.DeclaringEntity = IsInDeclarationContext;
1510 R.FunctionCanBeCall =
1511 canFunctionBeCalled(
R.getDeclaration(), BaseExprType) &&
1515 !IsAddressOfOperand;
1518 Results.push_back(R);
1520 if (!AsNestedNameSpecifier)
1521 MaybeAddConstructorResults(R);
1524void ResultBuilder::AddResult(
Result R) {
1525 assert(
R.Kind != Result::RK_Declaration &&
1526 "Declaration results need more context");
1527 Results.push_back(R);
1531void ResultBuilder::EnterNewScope() { ShadowMaps.emplace_back(); }
1534void ResultBuilder::ExitScope() {
1535 ShadowMaps.pop_back();
1540bool ResultBuilder::IsOrdinaryName(
const NamedDecl *ND)
const {
1558bool ResultBuilder::IsOrdinaryNonTypeName(
const NamedDecl *ND)
const {
1565 if (
const auto *ID = dyn_cast<ObjCInterfaceDecl>(ND)) {
1566 if (!
ID->getDefinition())
1581bool ResultBuilder::IsIntegralConstantValue(
const NamedDecl *ND)
const {
1582 if (!IsOrdinaryNonTypeName(ND))
1586 if (VD->getType()->isIntegralOrEnumerationType())
1594bool ResultBuilder::IsOrdinaryNonValueName(
const NamedDecl *ND)
const {
1607bool ResultBuilder::IsNestedNameSpecifier(
const NamedDecl *ND)
const {
1609 if (
const auto *ClassTemplate = dyn_cast<ClassTemplateDecl>(ND))
1610 ND = ClassTemplate->getTemplatedDecl();
1616bool ResultBuilder::IsEnum(
const NamedDecl *ND)
const {
1621bool ResultBuilder::IsClassOrStruct(
const NamedDecl *ND)
const {
1623 if (
const auto *ClassTemplate = dyn_cast<ClassTemplateDecl>(ND))
1624 ND = ClassTemplate->getTemplatedDecl();
1627 if (
const auto *RD = dyn_cast<RecordDecl>(ND))
1636bool ResultBuilder::IsUnion(
const NamedDecl *ND)
const {
1638 if (
const auto *ClassTemplate = dyn_cast<ClassTemplateDecl>(ND))
1639 ND = ClassTemplate->getTemplatedDecl();
1641 if (
const auto *RD = dyn_cast<RecordDecl>(ND))
1648bool ResultBuilder::IsNamespace(
const NamedDecl *ND)
const {
1654bool ResultBuilder::IsNamespaceOrAlias(
const NamedDecl *ND)
const {
1659bool ResultBuilder::IsType(
const NamedDecl *ND)
const {
1667bool ResultBuilder::IsMember(
const NamedDecl *ND)
const {
1674 T =
C.getCanonicalType(T);
1675 switch (T->getTypeClass()) {
1676 case Type::ObjCObject:
1677 case Type::ObjCInterface:
1678 case Type::ObjCObjectPointer:
1683 case BuiltinType::ObjCId:
1684 case BuiltinType::ObjCClass:
1685 case BuiltinType::ObjCSel:
1697 if (!
C.getLangOpts().CPlusPlus)
1703 return T->isDependentType() || T->isRecordType();
1706bool ResultBuilder::IsObjCMessageReceiver(
const NamedDecl *ND)
const {
1716bool ResultBuilder::IsObjCMessageReceiverOrLambdaCapture(
1718 if (IsObjCMessageReceiver(ND))
1721 const auto *Var = dyn_cast<VarDecl>(ND);
1725 return Var->hasLocalStorage() && !Var->hasAttr<BlocksAttr>();
1728bool ResultBuilder::IsObjCCollection(
const NamedDecl *ND)
const {
1729 if ((SemaRef.
getLangOpts().CPlusPlus && !IsOrdinaryName(ND)) ||
1730 (!SemaRef.
getLangOpts().CPlusPlus && !IsOrdinaryNonTypeName(ND)))
1744bool ResultBuilder::IsImpossibleToSatisfy(
const NamedDecl *ND)
const {
1750bool ResultBuilder::IsObjCIvar(
const NamedDecl *ND)
const {
1759 ResultBuilder &Results;
1760 DeclContext *InitialLookupCtx;
1763 CXXRecordDecl *NamingClass;
1765 std::vector<FixItHint> FixIts;
1766 bool IsInDeclarationContext;
1768 bool IsAddressOfOperand;
1771 CodeCompletionDeclConsumer(
1772 ResultBuilder &Results, DeclContext *InitialLookupCtx,
1773 QualType BaseType = QualType(),
1774 std::vector<FixItHint> FixIts = std::vector<FixItHint>())
1775 : Results(Results), InitialLookupCtx(InitialLookupCtx),
1776 FixIts(std::move(FixIts)), IsInDeclarationContext(
false),
1777 IsAddressOfOperand(
false) {
1778 NamingClass = llvm::dyn_cast<CXXRecordDecl>(InitialLookupCtx);
1781 auto ThisType = Results.getSema().getCurrentThisType();
1782 if (!ThisType.isNull()) {
1783 assert(ThisType->isPointerType());
1789 this->BaseType = BaseType;
1792 void setIsInDeclarationContext(
bool IsInDeclarationContext) {
1793 this->IsInDeclarationContext = IsInDeclarationContext;
1796 void setIsAddressOfOperand(
bool IsAddressOfOperand) {
1797 this->IsAddressOfOperand = IsAddressOfOperand;
1800 void FoundDecl(NamedDecl *ND, NamedDecl *Hiding, DeclContext *Ctx,
1801 bool InBaseClass)
override {
1802 ResultBuilder::Result
Result(ND, Results.getBasePriority(ND),
1806 Results.AddResult(
Result, InitialLookupCtx, Hiding, InBaseClass, BaseType,
1807 IsInDeclarationContext, IsAddressOfOperand);
1810 void EnteredContext(DeclContext *Ctx)
override {
1811 Results.addVisitedContext(Ctx);
1820 auto *NamingClass = this->NamingClass;
1821 QualType BaseType = this->BaseType;
1822 if (
auto *Cls = llvm::dyn_cast_or_null<CXXRecordDecl>(Ctx)) {
1831 BaseType = QualType();
1837 NamingClass =
nullptr;
1838 BaseType = QualType();
1840 return Results.getSema().IsSimplyAccessible(ND, NamingClass, BaseType);
1847 ResultBuilder &Results) {
1874 Results.getCodeCompletionTUInfo());
1875 if (LangOpts.CPlusPlus) {
1883 Builder.AddTypedTextChunk(
"typename");
1885 Builder.AddPlaceholderChunk(
"name");
1886 Results.AddResult(
Result(Builder.TakeString()));
1888 if (LangOpts.CPlusPlus11) {
1893 Builder.AddTypedTextChunk(
"decltype");
1895 Builder.AddPlaceholderChunk(
"expression");
1897 Results.AddResult(
Result(Builder.TakeString()));
1900 if (LangOpts.Char8 || LangOpts.CPlusPlus20)
1906 if (LangOpts.GNUKeywords) {
1912 Builder.AddTypedTextChunk(
"typeof");
1914 Builder.AddPlaceholderChunk(
"expression");
1915 Results.AddResult(
Result(Builder.TakeString()));
1917 Builder.AddTypedTextChunk(
"typeof");
1919 Builder.AddPlaceholderChunk(
"type");
1921 Results.AddResult(
Result(Builder.TakeString()));
1932 const LangOptions &LangOpts, ResultBuilder &Results) {
1937 Results.AddResult(
Result(
"extern"));
1938 Results.AddResult(
Result(
"static"));
1940 if (LangOpts.CPlusPlus11) {
1945 Builder.AddTypedTextChunk(
"alignas");
1947 Builder.AddPlaceholderChunk(
"expression");
1949 Results.AddResult(
Result(Builder.TakeString()));
1951 Results.AddResult(
Result(
"constexpr"));
1952 Results.AddResult(
Result(
"thread_local"));
1955 if (LangOpts.CPlusPlus20)
1956 Results.AddResult(
Result(
"constinit"));
1961 const LangOptions &LangOpts, ResultBuilder &Results) {
1966 if (LangOpts.CPlusPlus) {
1967 Results.AddResult(
Result(
"explicit"));
1968 Results.AddResult(
Result(
"friend"));
1969 Results.AddResult(
Result(
"mutable"));
1970 Results.AddResult(
Result(
"virtual"));
1978 if (LangOpts.CPlusPlus || LangOpts.C99)
1979 Results.AddResult(
Result(
"inline"));
1981 if (LangOpts.CPlusPlus20)
1982 Results.AddResult(
Result(
"consteval"));
2002 ResultBuilder &Results,
bool NeedAt);
2004 ResultBuilder &Results,
bool NeedAt);
2006 ResultBuilder &Results,
bool NeedAt);
2011 Results.getCodeCompletionTUInfo());
2012 Builder.AddTypedTextChunk(
"typedef");
2014 Builder.AddPlaceholderChunk(
"type");
2016 Builder.AddPlaceholderChunk(
"name");
2023 ResultBuilder &Results) {
2024 Builder.AddTypedTextChunk(
"using");
2026 Builder.AddPlaceholderChunk(
"name");
2028 Builder.AddPlaceholderChunk(
"type");
2051 return LangOpts.CPlusPlus;
2058 return LangOpts.CPlusPlus || LangOpts.ObjC || LangOpts.C99;
2061 llvm_unreachable(
"Invalid ParserCompletionContext!");
2088 if (!T.getLocalQualifiers()) {
2090 if (
const BuiltinType *BT = dyn_cast<BuiltinType>(T))
2091 return BT->getNameAsCString(Policy);
2094 if (
const TagType *TagT = dyn_cast<TagType>(T))
2095 if (
TagDecl *Tag = TagT->getDecl())
2096 if (!Tag->hasNameForLinkage()) {
2097 switch (Tag->getTagKind()) {
2099 return "struct <anonymous>";
2101 return "__interface <anonymous>";
2103 return "class <anonymous>";
2105 return "union <anonymous>";
2107 return "enum <anonymous>";
2114 T.getAsStringInternal(Result, Policy);
2127 Builder.AddResultTypeChunk(
2129 Builder.AddTypedTextChunk(
"this");
2134 ResultBuilder &Results,
2136 if (!LangOpts.CPlusPlus11)
2139 Builder.AddTypedTextChunk(
"static_assert");
2141 Builder.AddPlaceholderChunk(
"expression");
2143 Builder.AddPlaceholderChunk(
"message");
2152 Sema &S = Results.getSema();
2153 const auto *CR = llvm::dyn_cast<CXXRecordDecl>(S.
CurContext);
2159 llvm::StringMap<std::vector<FunctionDecl *>> Overrides;
2160 for (
auto *Method : CR->methods()) {
2161 if (!Method->isVirtual() || !Method->getIdentifier())
2163 Overrides[Method->getName()].push_back(Method);
2166 for (
const auto &
Base : CR->bases()) {
2167 const auto *BR =
Base.getType().getTypePtr()->getAsCXXRecordDecl();
2170 for (
auto *Method : BR->methods()) {
2171 if (!Method->isVirtual() || !Method->getIdentifier())
2173 const auto it = Overrides.find(Method->getName());
2174 bool IsOverriden =
false;
2175 if (it != Overrides.end()) {
2176 for (
auto *MD : it->second) {
2194 false, CCContext, Policy);
2204 Scope *S,
Sema &SemaRef, ResultBuilder &Results) {
2212 if (Results.includeCodePatterns()) {
2214 Builder.AddTypedTextChunk(
"namespace");
2216 Builder.AddPlaceholderChunk(
"identifier");
2220 Builder.AddPlaceholderChunk(
"declarations");
2223 Results.AddResult(
Result(Builder.TakeString()));
2227 Builder.AddTypedTextChunk(
"namespace");
2229 Builder.AddPlaceholderChunk(
"name");
2231 Builder.AddPlaceholderChunk(
"namespace");
2233 Results.AddResult(
Result(Builder.TakeString()));
2236 Builder.AddTypedTextChunk(
"using namespace");
2238 Builder.AddPlaceholderChunk(
"identifier");
2240 Results.AddResult(
Result(Builder.TakeString()));
2243 Builder.AddTypedTextChunk(
"asm");
2245 Builder.AddPlaceholderChunk(
"string-literal");
2247 Results.AddResult(
Result(Builder.TakeString()));
2249 if (Results.includeCodePatterns()) {
2251 Builder.AddTypedTextChunk(
"template");
2253 Builder.AddPlaceholderChunk(
"declaration");
2254 Results.AddResult(
Result(Builder.TakeString()));
2265 if (!CurrentModule) {
2267 Builder.AddTypedTextChunk(
"module");
2270 Results.AddResult(
Result(Builder.TakeString()));
2275 if (!CurrentModule ||
2280 Builder.AddTypedTextChunk(
"module");
2282 Builder.AddPlaceholderChunk(
"name");
2285 Results.AddResult(
Result(Builder.TakeString()));
2290 if (!CurrentModule ||
2294 Builder.AddTypedTextChunk(
"import");
2296 Builder.AddPlaceholderChunk(
"name");
2299 Results.AddResult(
Result(Builder.TakeString()));
2302 if (CurrentModule &&
2306 Builder.AddTypedTextChunk(
"module");
2309 Builder.AddTypedTextChunk(
"private");
2312 Results.AddResult(
Result(Builder.TakeString()));
2317 if (!CurrentModule ||
2332 Builder.AddTypedTextChunk(
"using");
2334 Builder.AddPlaceholderChunk(
"qualifier");
2335 Builder.AddTextChunk(
"::");
2336 Builder.AddPlaceholderChunk(
"name");
2338 Results.AddResult(
Result(Builder.TakeString()));
2345 Builder.AddTypedTextChunk(
"using typename");
2347 Builder.AddPlaceholderChunk(
"qualifier");
2348 Builder.AddTextChunk(
"::");
2349 Builder.AddPlaceholderChunk(
"name");
2351 Results.AddResult(
Result(Builder.TakeString()));
2361 Builder.AddTypedTextChunk(
"public");
2362 if (IsNotInheritanceScope && Results.includeCodePatterns())
2364 Results.AddResult(
Result(Builder.TakeString()));
2367 Builder.AddTypedTextChunk(
"protected");
2368 if (IsNotInheritanceScope && Results.includeCodePatterns())
2370 Results.AddResult(
Result(Builder.TakeString()));
2373 Builder.AddTypedTextChunk(
"private");
2374 if (IsNotInheritanceScope && Results.includeCodePatterns())
2376 Results.AddResult(
Result(Builder.TakeString()));
2394 if (SemaRef.
getLangOpts().CPlusPlus && Results.includeCodePatterns()) {
2396 Builder.AddTypedTextChunk(
"template");
2398 Builder.AddPlaceholderChunk(
"parameters");
2400 Results.AddResult(
Result(Builder.TakeString()));
2438 if (SemaRef.
getLangOpts().CPlusPlus && Results.includeCodePatterns() &&
2440 Builder.AddTypedTextChunk(
"try");
2444 Builder.AddPlaceholderChunk(
"statements");
2448 Builder.AddTextChunk(
"catch");
2451 Builder.AddPlaceholderChunk(
"declaration");
2456 Builder.AddPlaceholderChunk(
"statements");
2459 Results.AddResult(
Result(Builder.TakeString()));
2464 if (Results.includeCodePatterns()) {
2466 Builder.AddTypedTextChunk(
"if");
2470 Builder.AddPlaceholderChunk(
"condition");
2472 Builder.AddPlaceholderChunk(
"expression");
2477 Builder.AddPlaceholderChunk(
"statements");
2480 Results.AddResult(
Result(Builder.TakeString()));
2483 Builder.AddTypedTextChunk(
"switch");
2487 Builder.AddPlaceholderChunk(
"condition");
2489 Builder.AddPlaceholderChunk(
"expression");
2494 Builder.AddPlaceholderChunk(
"cases");
2497 Results.AddResult(
Result(Builder.TakeString()));
2504 Builder.AddTypedTextChunk(
"case");
2506 Builder.AddPlaceholderChunk(
"expression");
2508 Results.AddResult(
Result(Builder.TakeString()));
2511 Builder.AddTypedTextChunk(
"default");
2513 Results.AddResult(
Result(Builder.TakeString()));
2516 if (Results.includeCodePatterns()) {
2518 Builder.AddTypedTextChunk(
"while");
2522 Builder.AddPlaceholderChunk(
"condition");
2524 Builder.AddPlaceholderChunk(
"expression");
2529 Builder.AddPlaceholderChunk(
"statements");
2532 Results.AddResult(
Result(Builder.TakeString()));
2535 Builder.AddTypedTextChunk(
"do");
2539 Builder.AddPlaceholderChunk(
"statements");
2542 Builder.AddTextChunk(
"while");
2545 Builder.AddPlaceholderChunk(
"expression");
2547 Results.AddResult(
Result(Builder.TakeString()));
2550 Builder.AddTypedTextChunk(
"for");
2554 Builder.AddPlaceholderChunk(
"init-statement");
2556 Builder.AddPlaceholderChunk(
"init-expression");
2559 Builder.AddPlaceholderChunk(
"condition");
2562 Builder.AddPlaceholderChunk(
"inc-expression");
2567 Builder.AddPlaceholderChunk(
"statements");
2570 Results.AddResult(
Result(Builder.TakeString()));
2574 Builder.AddTypedTextChunk(
"for");
2577 Builder.AddPlaceholderChunk(
"range-declaration");
2580 Builder.AddTextChunk(
"in");
2584 Builder.AddPlaceholderChunk(
"range-expression");
2589 Builder.AddPlaceholderChunk(
"statements");
2592 Results.AddResult(
Result(Builder.TakeString()));
2598 Builder.AddTypedTextChunk(
"continue");
2600 Results.AddResult(
Result(Builder.TakeString()));
2605 Builder.AddTypedTextChunk(
"break");
2607 Results.AddResult(
Result(Builder.TakeString()));
2612 if (
const auto *Function = dyn_cast<FunctionDecl>(SemaRef.
CurContext))
2613 ReturnType = Function->getReturnType();
2614 else if (
const auto *Method = dyn_cast<ObjCMethodDecl>(SemaRef.
CurContext))
2615 ReturnType = Method->getReturnType();
2620 Builder.AddTypedTextChunk(
"return");
2622 Results.AddResult(
Result(Builder.TakeString()));
2624 assert(!ReturnType.
isNull());
2626 Builder.AddTypedTextChunk(
"return");
2628 Builder.AddPlaceholderChunk(
"expression");
2630 Results.AddResult(
Result(Builder.TakeString()));
2633 Builder.AddTypedTextChunk(
"co_return");
2635 Builder.AddPlaceholderChunk(
"expression");
2637 Results.AddResult(
Result(Builder.TakeString()));
2641 Builder.AddTypedTextChunk(
"return true");
2643 Results.AddResult(
Result(Builder.TakeString()));
2645 Builder.AddTypedTextChunk(
"return false");
2647 Results.AddResult(
Result(Builder.TakeString()));
2652 Builder.AddTypedTextChunk(
"return nullptr");
2654 Results.AddResult(
Result(Builder.TakeString()));
2659 Builder.AddTypedTextChunk(
"goto");
2661 Builder.AddPlaceholderChunk(
"label");
2663 Results.AddResult(
Result(Builder.TakeString()));
2666 Builder.AddTypedTextChunk(
"using namespace");
2668 Builder.AddPlaceholderChunk(
"identifier");
2670 Results.AddResult(
Result(Builder.TakeString()));
2687 Builder.AddTypedTextChunk(
"__bridge");
2689 Builder.AddPlaceholderChunk(
"type");
2691 Builder.AddPlaceholderChunk(
"expression");
2692 Results.AddResult(
Result(Builder.TakeString()));
2695 Builder.AddTypedTextChunk(
"__bridge_transfer");
2697 Builder.AddPlaceholderChunk(
"Objective-C type");
2699 Builder.AddPlaceholderChunk(
"expression");
2700 Results.AddResult(
Result(Builder.TakeString()));
2703 Builder.AddTypedTextChunk(
"__bridge_retained");
2705 Builder.AddPlaceholderChunk(
"CF type");
2707 Builder.AddPlaceholderChunk(
"expression");
2708 Results.AddResult(
Result(Builder.TakeString()));
2719 Builder.AddResultTypeChunk(
"bool");
2720 Builder.AddTypedTextChunk(
"true");
2721 Results.AddResult(
Result(Builder.TakeString()));
2724 Builder.AddResultTypeChunk(
"bool");
2725 Builder.AddTypedTextChunk(
"false");
2726 Results.AddResult(
Result(Builder.TakeString()));
2730 Builder.AddTypedTextChunk(
"dynamic_cast");
2732 Builder.AddPlaceholderChunk(
"type");
2735 Builder.AddPlaceholderChunk(
"expression");
2737 Results.AddResult(
Result(Builder.TakeString()));
2741 Builder.AddTypedTextChunk(
"static_cast");
2743 Builder.AddPlaceholderChunk(
"type");
2746 Builder.AddPlaceholderChunk(
"expression");
2748 Results.AddResult(
Result(Builder.TakeString()));
2751 Builder.AddTypedTextChunk(
"reinterpret_cast");
2753 Builder.AddPlaceholderChunk(
"type");
2756 Builder.AddPlaceholderChunk(
"expression");
2758 Results.AddResult(
Result(Builder.TakeString()));
2761 Builder.AddTypedTextChunk(
"const_cast");
2763 Builder.AddPlaceholderChunk(
"type");
2766 Builder.AddPlaceholderChunk(
"expression");
2768 Results.AddResult(
Result(Builder.TakeString()));
2772 Builder.AddResultTypeChunk(
"std::type_info");
2773 Builder.AddTypedTextChunk(
"typeid");
2775 Builder.AddPlaceholderChunk(
"expression-or-type");
2777 Results.AddResult(
Result(Builder.TakeString()));
2781 Builder.AddTypedTextChunk(
"new");
2783 Builder.AddPlaceholderChunk(
"type");
2785 Builder.AddPlaceholderChunk(
"expressions");
2787 Results.AddResult(
Result(Builder.TakeString()));
2790 Builder.AddTypedTextChunk(
"new");
2792 Builder.AddPlaceholderChunk(
"type");
2794 Builder.AddPlaceholderChunk(
"size");
2797 Builder.AddPlaceholderChunk(
"expressions");
2799 Results.AddResult(
Result(Builder.TakeString()));
2802 Builder.AddResultTypeChunk(
"void");
2803 Builder.AddTypedTextChunk(
"delete");
2805 Builder.AddPlaceholderChunk(
"expression");
2806 Results.AddResult(
Result(Builder.TakeString()));
2809 Builder.AddResultTypeChunk(
"void");
2810 Builder.AddTypedTextChunk(
"delete");
2815 Builder.AddPlaceholderChunk(
"expression");
2816 Results.AddResult(
Result(Builder.TakeString()));
2820 Builder.AddResultTypeChunk(
"void");
2821 Builder.AddTypedTextChunk(
"throw");
2823 Builder.AddPlaceholderChunk(
"expression");
2824 Results.AddResult(
Result(Builder.TakeString()));
2831 Builder.AddResultTypeChunk(
"std::nullptr_t");
2832 Builder.AddTypedTextChunk(
"nullptr");
2833 Results.AddResult(
Result(Builder.TakeString()));
2836 Builder.AddResultTypeChunk(
"size_t");
2837 Builder.AddTypedTextChunk(
"alignof");
2839 Builder.AddPlaceholderChunk(
"type");
2841 Results.AddResult(
Result(Builder.TakeString()));
2844 Builder.AddResultTypeChunk(
"bool");
2845 Builder.AddTypedTextChunk(
"noexcept");
2847 Builder.AddPlaceholderChunk(
"expression");
2849 Results.AddResult(
Result(Builder.TakeString()));
2852 Builder.AddResultTypeChunk(
"size_t");
2853 Builder.AddTypedTextChunk(
"sizeof...");
2855 Builder.AddPlaceholderChunk(
"parameter-pack");
2857 Results.AddResult(
Result(Builder.TakeString()));
2862 Builder.AddTypedTextChunk(
"co_await");
2864 Builder.AddPlaceholderChunk(
"expression");
2865 Results.AddResult(
Result(Builder.TakeString()));
2868 Builder.AddTypedTextChunk(
"co_yield");
2870 Builder.AddPlaceholderChunk(
"expression");
2871 Results.AddResult(
Result(Builder.TakeString()));
2874 Builder.AddResultTypeChunk(
"bool");
2875 Builder.AddTypedTextChunk(
"requires");
2878 Builder.AddPlaceholderChunk(
"parameters");
2883 Builder.AddPlaceholderChunk(
"requirements");
2886 Results.AddResult(
Result(Builder.TakeString()));
2890 Builder.AddTypedTextChunk(
"requires");
2892 Builder.AddPlaceholderChunk(
"expression");
2894 Results.AddResult(
Result(Builder.TakeString()));
2904 if (ID->getSuperClass()) {
2905 std::string SuperType;
2906 SuperType = ID->getSuperClass()->getNameAsString();
2907 if (Method->isInstanceMethod())
2910 Builder.AddResultTypeChunk(Allocator.
CopyString(SuperType));
2911 Builder.AddTypedTextChunk(
"super");
2912 Results.AddResult(
Result(Builder.TakeString()));
2921 Builder.AddResultTypeChunk(
"size_t");
2923 Builder.AddTypedTextChunk(
"alignof");
2925 Builder.AddTypedTextChunk(
"_Alignof");
2927 Builder.AddPlaceholderChunk(
"type");
2929 Results.AddResult(
Result(Builder.TakeString()));
2934 Builder.AddResultTypeChunk(
"nullptr_t");
2935 Builder.AddTypedTextChunk(
"nullptr");
2936 Results.AddResult(
Result(Builder.TakeString()));
2940 Builder.AddResultTypeChunk(
"size_t");
2941 Builder.AddTypedTextChunk(
"sizeof");
2943 Builder.AddPlaceholderChunk(
"expression-or-type");
2945 Results.AddResult(
Result(Builder.TakeString()));
2958 Results.AddResult(
Result(
"operator"));
2978 T = Function->getReturnType();
2979 else if (
const auto *Method = dyn_cast<ObjCMethodDecl>(ND)) {
2980 if (!BaseType.isNull())
2981 T = Method->getSendResultType(BaseType);
2983 T = Method->getReturnType();
2984 }
else if (
const auto *
Enumerator = dyn_cast<EnumConstantDecl>(ND)) {
2985 T = Context.getCanonicalTagType(
2989 }
else if (
const auto *Ivar = dyn_cast<ObjCIvarDecl>(ND)) {
2990 if (!BaseType.isNull())
2991 T = Ivar->getUsageType(BaseType);
2993 T = Ivar->getType();
2994 }
else if (
const auto *
Value = dyn_cast<ValueDecl>(ND)) {
2996 }
else if (
const auto *Property = dyn_cast<ObjCPropertyDecl>(ND)) {
2997 if (!BaseType.isNull())
2998 T = Property->getUsageType(BaseType);
3000 T = Property->getType();
3003 if (T.isNull() || Context.hasSameType(T, Context.DependentTy))
3006 Result.AddResultTypeChunk(
3013 if (SentinelAttr *Sentinel = FunctionOrMethod->
getAttr<SentinelAttr>())
3014 if (Sentinel->getSentinel() == 0) {
3016 Result.AddTextChunk(
", nil");
3018 Result.AddTextChunk(
", NULL");
3020 Result.AddTextChunk(
", (void*)0");
3034 Result +=
"bycopy ";
3038 Result +=
"oneway ";
3040 if (
auto nullability = AttributedType::stripOuterNullability(
Type)) {
3041 switch (*nullability) {
3043 Result +=
"nonnull ";
3047 Result +=
"nullable ";
3051 Result +=
"null_unspecified ";
3055 llvm_unreachable(
"Not supported as a context-sensitive keyword!");
3072 bool SuppressBlock =
false) {
3078 if (!SuppressBlock) {
3081 TypedefTL.getDecl()->getTypeSourceInfo()) {
3094 TL = AttrTL.getModifiedLoc();
3113 bool SuppressBlockName =
false,
bool SuppressBlock =
false,
3118 bool SuppressName =
false,
bool SuppressBlock =
false,
3126 if (
const auto *PVD = dyn_cast<ParmVarDecl>(Param))
3127 ObjCQual = PVD->getObjCDeclQualifier();
3129 if (Param->getType()->isDependentType() ||
3130 !Param->getType()->isBlockPointerType()) {
3135 if (Param->getIdentifier() && !ObjCMethodParam && !SuppressName)
3136 Result = std::string(Param->getIdentifier()->deuglifiedName());
3140 Type =
Type.substObjCTypeArgs(Param->getASTContext(), *ObjCSubsts,
3142 if (ObjCMethodParam) {
3144 Result +=
Type.getAsString(Policy) +
")";
3145 if (Param->getIdentifier() && !SuppressName)
3146 Result += Param->getIdentifier()->deuglifiedName();
3148 Type.getAsStringInternal(Result, Policy);
3161 if (!
Block && ObjCMethodParam &&
3164 ->findPropertyDecl(
false))
3173 if (!ObjCMethodParam && Param->getIdentifier())
3174 Result = std::string(Param->getIdentifier()->deuglifiedName());
3178 if (ObjCMethodParam) {
3179 Result =
Type.getAsString(Policy);
3182 Result =
"(" + Quals +
" " + Result +
")";
3183 if (Result.back() !=
')')
3185 if (Param->getIdentifier())
3186 Result += Param->getIdentifier()->deuglifiedName();
3188 Type.getAsStringInternal(Result, Policy);
3197 false, SuppressBlock,
3213 bool SuppressBlockName,
bool SuppressBlock,
3221 if (!ResultType->
isVoidType() || SuppressBlock)
3226 if (!BlockProto ||
Block.getNumParams() == 0) {
3233 for (
unsigned I = 0, N =
Block.getNumParams(); I != N; ++I) {
3246 if (SuppressBlock) {
3248 Result = Result +
" (^";
3249 if (!SuppressBlockName &&
BlockDecl->getIdentifier())
3250 Result +=
BlockDecl->getIdentifier()->getName();
3255 Result =
'^' + Result;
3258 if (!SuppressBlockName &&
BlockDecl->getIdentifier())
3259 Result +=
BlockDecl->getIdentifier()->getName();
3268 const SourceRange SrcRange = Param->getDefaultArgRange();
3278 if (srcText.empty() || srcText ==
"=") {
3284 std::string DefValue(srcText.str());
3287 if (DefValue.at(0) !=
'=') {
3291 return " = " + DefValue;
3293 return " " + DefValue;
3300 unsigned Start = 0,
bool InOptional =
false,
bool FunctionCanBeCall =
true,
3301 bool IsInDeclarationContext =
false) {
3302 bool FirstParameter =
true;
3303 bool AsInformativeChunk = !(FunctionCanBeCall || IsInDeclarationContext);
3305 for (
unsigned P = Start, N = Function->getNumParams(); P != N; ++P) {
3306 const ParmVarDecl *Param = Function->getParamDecl(P);
3308 if (Param->hasDefaultArg() && !InOptional && !IsInDeclarationContext &&
3309 !AsInformativeChunk) {
3313 Result.getCodeCompletionTUInfo());
3314 if (!FirstParameter)
3324 if (FirstParameter && Param->isExplicitObjectParameter()) {
3329 FirstParameter =
false;
3331 if (AsInformativeChunk)
3332 Result.AddInformativeChunk(
", ");
3341 std::string DefaultValue;
3342 if (Param->hasDefaultArg()) {
3343 if (IsInDeclarationContext)
3351 if (Function->isVariadic() && P == N - 1)
3352 PlaceholderStr +=
", ...";
3355 if (AsInformativeChunk)
3356 Result.AddInformativeChunk(
3357 Result.getAllocator().CopyString(PlaceholderStr));
3358 else if (IsInDeclarationContext) {
3359 Result.AddTextChunk(Result.getAllocator().CopyString(PlaceholderStr));
3360 if (DefaultValue.length() != 0)
3361 Result.AddInformativeChunk(
3362 Result.getAllocator().CopyString(DefaultValue));
3364 Result.AddPlaceholderChunk(
3365 Result.getAllocator().CopyString(PlaceholderStr));
3369 if (Proto->isVariadic()) {
3370 if (Proto->getNumParams() == 0)
3371 Result.AddPlaceholderChunk(
"...");
3381 unsigned MaxParameters = 0,
unsigned Start = 0,
bool InDefaultArg =
false,
3382 bool AsInformativeChunk =
false) {
3383 bool FirstParameter =
true;
3392 PEnd = Params->
begin() + MaxParameters;
3395 bool HasDefaultArg =
false;
3396 std::string PlaceholderStr;
3398 if (TTP->wasDeclaredWithTypename())
3399 PlaceholderStr =
"typename";
3400 else if (
const auto *TC = TTP->getTypeConstraint()) {
3401 llvm::raw_string_ostream OS(PlaceholderStr);
3402 TC->print(OS, Policy);
3404 PlaceholderStr =
"class";
3406 if (TTP->getIdentifier()) {
3407 PlaceholderStr +=
' ';
3408 PlaceholderStr += TTP->getIdentifier()->deuglifiedName();
3411 HasDefaultArg = TTP->hasDefaultArgument();
3413 dyn_cast<NonTypeTemplateParmDecl>(*P)) {
3414 if (NTTP->getIdentifier())
3415 PlaceholderStr = std::string(NTTP->getIdentifier()->deuglifiedName());
3416 NTTP->getType().getAsStringInternal(PlaceholderStr, Policy);
3417 HasDefaultArg = NTTP->hasDefaultArgument();
3424 PlaceholderStr =
"template<...> class";
3426 PlaceholderStr +=
' ';
3433 if (HasDefaultArg && !InDefaultArg && !AsInformativeChunk) {
3437 Result.getCodeCompletionTUInfo());
3438 if (!FirstParameter)
3441 P - Params->
begin(),
true);
3446 InDefaultArg =
false;
3449 FirstParameter =
false;
3451 if (AsInformativeChunk)
3452 Result.AddInformativeChunk(
", ");
3457 if (AsInformativeChunk)
3458 Result.AddInformativeChunk(
3459 Result.getAllocator().CopyString(PlaceholderStr));
3461 Result.AddPlaceholderChunk(
3462 Result.getAllocator().CopyString(PlaceholderStr));
3470 bool QualifierIsInformative,
3476 std::string PrintedNNS;
3478 llvm::raw_string_ostream OS(PrintedNNS);
3479 Qualifier.print(OS, Policy);
3481 if (QualifierIsInformative)
3482 Result.AddInformativeChunk(Result.getAllocator().CopyString(PrintedNNS));
3484 Result.AddTextChunk(Result.getAllocator().CopyString(PrintedNNS));
3489 bool AsInformativeChunk =
true) {
3494 if (AsInformativeChunk)
3495 Result.AddInformativeChunk(
" const");
3497 Result.AddTextChunk(
" const");
3502 if (AsInformativeChunk)
3503 Result.AddInformativeChunk(
" volatile");
3505 Result.AddTextChunk(
" volatile");
3510 if (AsInformativeChunk)
3511 Result.AddInformativeChunk(
" restrict");
3513 Result.AddTextChunk(
" restrict");
3518 std::string QualsStr;
3520 QualsStr +=
" const";
3522 QualsStr +=
" volatile";
3524 QualsStr +=
" restrict";
3526 if (AsInformativeChunk)
3527 Result.AddInformativeChunk(Result.getAllocator().CopyString(QualsStr));
3529 Result.AddTextChunk(Result.getAllocator().CopyString(QualsStr));
3535 bool AsInformativeChunks =
true) {
3536 if (
auto *CxxMethodDecl = llvm::dyn_cast_if_present<CXXMethodDecl>(Function);
3537 CxxMethodDecl && CxxMethodDecl->hasCXXExplicitFunctionObjectParameter()) {
3539 const auto Quals = CxxMethodDecl->getFunctionObjectParameterType();
3540 if (!Quals.hasQualifiers())
3546 if (!Proto || !Proto->getMethodQuals())
3561 switch (ExceptInfo.Type) {
3564 NameAndSignature +=
" noexcept";
3582 const char *OperatorName =
nullptr;
3585 case OO_Conditional:
3587 OperatorName =
"operator";
3590#define OVERLOADED_OPERATOR(Name, Spelling, Token, Unary, Binary, MemberOnly) \
3592 OperatorName = "operator" Spelling; \
3594#define OVERLOADED_OPERATOR_MULTI(Name, Spelling, Unary, Binary, MemberOnly)
3595#include "clang/Basic/OperatorKinds.def"
3598 OperatorName =
"operator new";
3601 OperatorName =
"operator delete";
3604 OperatorName =
"operator new[]";
3606 case OO_Array_Delete:
3607 OperatorName =
"operator delete[]";
3610 OperatorName =
"operator()";
3613 OperatorName =
"operator[]";
3616 Result.AddTypedTextChunk(OperatorName);
3624 Result.AddTypedTextChunk(
3641 Result.AddTypedTextChunk(
3646 Result.AddTypedTextChunk(
3647 Result.getAllocator().CopyString(
Record->getNameAsString()));
3661 bool IncludeBriefComments) {
3663 CCTUInfo, IncludeBriefComments);
3675 return Result.TakeString();
3686 Result.AddPlaceholderChunk(
"...");
3700 Result.AddPlaceholderChunk(
Result.getAllocator().CopyString(Arg));
3705 Result.AddPlaceholderChunk(
3706 Result.getAllocator().CopyString((*A)->getName()));
3709 return Result.TakeString();
3721 bool IncludeBriefComments) {
3737 Result.addBriefComment(RC->getBriefText(Ctx));
3747 return Result.TakeString();
3751 PP, Ctx,
Result, IncludeBriefComments, CCContext, Policy);
3755 std::string &BeforeName,
3756 std::string &NameAndSignature) {
3757 bool SeenTypedChunk =
false;
3758 for (
auto &Chunk : CCS) {
3760 assert(SeenTypedChunk &&
"optional parameter before name");
3767 NameAndSignature += Chunk.Text;
3769 BeforeName += Chunk.Text;
3781 std::string BeforeName;
3782 std::string NameAndSignature;
3788 const auto *VirtualFunc = dyn_cast<FunctionDecl>(
Declaration);
3789 assert(VirtualFunc &&
"overridden decl must be a function");
3792 NameAndSignature +=
" override";
3794 Result.AddTextChunk(
Result.getAllocator().CopyString(BeforeName));
3796 Result.AddTypedTextChunk(
Result.getAllocator().CopyString(NameAndSignature));
3797 return Result.TakeString();
3803 const auto *VD = dyn_cast<VarDecl>(ND);
3806 const auto *
RecordDecl = VD->getType()->getAsCXXRecordDecl();
3819 if (IncludeBriefComments) {
3822 Result.addBriefComment(RC->getBriefText(Ctx));
3827 Result.AddTypedTextChunk(
3829 Result.AddTextChunk(
"::");
3830 return Result.TakeString();
3834 Result.AddAnnotation(
Result.getAllocator().CopyString(I->getAnnotation()));
3842 if (InsertParameters)
3845 Result.AddInformativeChunk(
"(");
3850 if (InsertParameters)
3853 Result.AddInformativeChunk(
")");
3858 if (
const auto *
Function = dyn_cast<FunctionDecl>(ND)) {
3859 AddFunctionTypeAndResult(
Function);
3860 return Result.TakeString();
3863 if (
const auto *CallOperator =
3865 AddFunctionTypeAndResult(CallOperator);
3866 return Result.TakeString();
3872 dyn_cast<FunctionTemplateDecl>(ND)) {
3883 llvm::SmallBitVector
Deduced(FunTmpl->getTemplateParameters()->size());
3888 unsigned LastDeducibleArgument;
3889 for (LastDeducibleArgument =
Deduced.size(); LastDeducibleArgument > 0;
3890 --LastDeducibleArgument) {
3891 if (!
Deduced[LastDeducibleArgument - 1]) {
3895 bool HasDefaultArg =
false;
3896 NamedDecl *Param = FunTmpl->getTemplateParameters()->getParam(
3897 LastDeducibleArgument - 1);
3899 HasDefaultArg = TTP->hasDefaultArgument();
3901 dyn_cast<NonTypeTemplateParmDecl>(Param))
3902 HasDefaultArg = NTTP->hasDefaultArgument();
3930 Result.AddInformativeChunk(
"<");
3932 Ctx, Policy, FunTmpl,
Result, LastDeducibleArgument, 0,
3939 Result.AddInformativeChunk(
">");
3944 if (InsertParameters)
3947 Result.AddInformativeChunk(
"(");
3952 if (InsertParameters)
3955 Result.AddInformativeChunk(
")");
3957 return Result.TakeString();
3960 if (
const auto *
Template = dyn_cast<TemplateDecl>(ND)) {
3963 Result.AddTypedTextChunk(
3968 return Result.TakeString();
3971 if (
const auto *
Method = dyn_cast<ObjCMethodDecl>(ND)) {
3974 Result.AddTypedTextChunk(
3976 return Result.TakeString();
3982 Result.AddTypedTextChunk(
Result.getAllocator().CopyString(SelName));
3984 Result.AddInformativeChunk(
Result.getAllocator().CopyString(SelName));
3988 if (
Method->param_size() == 1)
3989 Result.AddTypedTextChunk(
"");
3995 PEnd =
Method->param_end();
3996 P != PEnd && Idx < Sel.
getNumArgs(); (
void)++P, ++Idx) {
4015 QualType ParamType = (*P)->getType();
4016 std::optional<ArrayRef<QualType>> ObjCSubsts;
4032 Arg += II->getName();
4035 if (
Method->isVariadic() && (P + 1) == PEnd)
4039 Result.AddTextChunk(
Result.getAllocator().CopyString(Arg));
4041 Result.AddInformativeChunk(
Result.getAllocator().CopyString(Arg));
4043 Result.AddPlaceholderChunk(
Result.getAllocator().CopyString(Arg));
4046 if (
Method->isVariadic()) {
4047 if (
Method->param_size() == 0) {
4049 Result.AddTextChunk(
", ...");
4051 Result.AddInformativeChunk(
", ...");
4053 Result.AddPlaceholderChunk(
", ...");
4059 return Result.TakeString();
4066 Result.AddTypedTextChunk(
4068 return Result.TakeString();
4079 const auto *M = dyn_cast<ObjCMethodDecl>(ND);
4091 const auto *M = dyn_cast_or_null<ObjCMethodDecl>(ND);
4092 if (!M || !M->isPropertyAccessor())
4115 auto FDecl =
Result.getFunction();
4118 if (ArgIndex < FDecl->getNumParams())
4126 unsigned CurrentArg) {
4127 unsigned ChunkIndex = 0;
4128 auto AddChunk = [&](llvm::StringRef Placeholder) {
4131 const char *
Copy = Result.getAllocator().CopyString(Placeholder);
4132 if (ChunkIndex == CurrentArg)
4133 Result.AddCurrentParameterChunk(
Copy);
4135 Result.AddPlaceholderChunk(
Copy);
4140 if (
auto *CRD = llvm::dyn_cast<CXXRecordDecl>(RD)) {
4141 for (
const auto &
Base : CRD->bases())
4142 AddChunk(
Base.getType().getAsString(Policy));
4144 for (
const auto &Field : RD->
fields())
4154 unsigned CurrentArg,
unsigned Start = 0,
bool InOptional =
false) {
4160 bool FirstParameter =
true;
4161 unsigned NumParams =
4162 Function ? Function->getNumParams() :
Prototype->getNumParams();
4164 for (
unsigned P = Start; P != NumParams; ++P) {
4165 if (Function && Function->getParamDecl(P)->hasDefaultArg() && !InOptional) {
4169 Result.getCodeCompletionTUInfo());
4170 if (!FirstParameter)
4174 PrototypeLoc, Opt, CurrentArg, P,
4183 if (Function && FirstParameter &&
4184 Function->getParamDecl(P)->isExplicitObjectParameter()) {
4189 FirstParameter =
false;
4196 std::string Placeholder;
4197 assert(P < Prototype->getNumParams());
4198 if (Function || PrototypeLoc) {
4200 Function ? Function->getParamDecl(P) : PrototypeLoc.
getParam(P);
4202 if (Param->hasDefaultArg())
4204 Context.getLangOpts());
4206 Placeholder =
Prototype->getParamType(P).getAsString(Policy);
4209 if (P == CurrentArg)
4210 Result.AddCurrentParameterChunk(
4211 Result.getAllocator().CopyString(Placeholder));
4213 Result.AddPlaceholderChunk(Result.getAllocator().CopyString(Placeholder));
4218 Result.getCodeCompletionTUInfo());
4219 if (!FirstParameter)
4222 if (CurrentArg < NumParams)
4234 if (
const auto *
Type = dyn_cast<TemplateTypeParmDecl>(Param)) {
4236 }
else if (
const auto *
NonType = dyn_cast<NonTypeTemplateParmDecl>(Param)) {
4238 }
else if (
const auto *
Template = dyn_cast<TemplateTemplateParmDecl>(Param)) {
4242 llvm::raw_string_ostream OS(Result);
4243 Param->print(OS, Policy);
4249 if (
const auto *CTD = dyn_cast<ClassTemplateDecl>(TD))
4250 return CTD->getTemplatedDecl()->getKindName().str();
4251 if (
const auto *VTD = dyn_cast<VarTemplateDecl>(TD))
4252 return VTD->getTemplatedDecl()->getType().getAsString(Policy);
4253 if (
const auto *FTD = dyn_cast<FunctionTemplateDecl>(TD))
4254 return FTD->getTemplatedDecl()->getReturnType().getAsString(Policy);
4269 Builder.getCodeCompletionTUInfo());
4271 if (!ResultType.empty())
4272 Builder.AddResultTypeChunk(Builder.getAllocator().CopyString(ResultType));
4273 Builder.AddTextChunk(
4279 for (
unsigned I = 0; I < Params.size(); ++I) {
4281 std::string Placeholder =
4284 Current = &OptionalBuilder;
4293 if (Current == &OptionalBuilder)
4299 Builder.AddInformativeChunk(
"()");
4300 return Builder.TakeString();
4307 bool Braced)
const {
4331 if (IncludeBriefComments) {
4338 llvm::raw_string_ostream OS(Name);
4340 Result.AddTextChunk(
Result.getAllocator().CopyString(Name));
4343 Result.AddResultTypeChunk(
Result.getAllocator().CopyString(
4358 return Result.TakeString();
4363 bool PreferredTypeIsPointer) {
4367 if (MacroName ==
"nil" || MacroName ==
"NULL" || MacroName ==
"Nil") {
4369 if (PreferredTypeIsPointer)
4373 else if (MacroName ==
"YES" || MacroName ==
"NO" || MacroName ==
"true" ||
4374 MacroName ==
"false")
4377 else if (MacroName ==
"bool")
4390 case Decl::EnumConstant:
4394 case Decl::Function:
4396 case Decl::ObjCCategory:
4398 case Decl::ObjCCategoryImpl:
4400 case Decl::ObjCImplementation:
4403 case Decl::ObjCInterface:
4405 case Decl::ObjCIvar:
4407 case Decl::ObjCMethod:
4411 case Decl::CXXMethod:
4413 case Decl::CXXConstructor:
4415 case Decl::CXXDestructor:
4417 case Decl::CXXConversion:
4419 case Decl::ObjCProperty:
4421 case Decl::ObjCProtocol:
4427 case Decl::TypeAlias:
4429 case Decl::TypeAliasTemplate:
4433 case Decl::Namespace:
4435 case Decl::NamespaceAlias:
4437 case Decl::TemplateTypeParm:
4439 case Decl::NonTypeTemplateParm:
4441 case Decl::TemplateTemplateParm:
4443 case Decl::FunctionTemplate:
4445 case Decl::ClassTemplate:
4447 case Decl::AccessSpec:
4449 case Decl::ClassTemplatePartialSpecialization:
4451 case Decl::UsingDirective:
4453 case Decl::StaticAssert:
4457 case Decl::TranslationUnit:
4461 case Decl::UnresolvedUsingValue:
4462 case Decl::UnresolvedUsingTypename:
4465 case Decl::UsingEnum:
4468 case Decl::ObjCPropertyImpl:
4476 llvm_unreachable(
"Unexpected Kind!");
4481 case Decl::ObjCTypeParam:
4487 case Decl::LinkageSpec:
4491 if (
const auto *TD = dyn_cast<TagDecl>(D)) {
4492 switch (TD->getTagKind()) {
4510 bool LoadExternal,
bool IncludeUndefined,
4511 bool TargetTypeIsPointer =
false) {
4514 Results.EnterNewScope();
4520 if (IncludeUndefined || MD) {
4528 TargetTypeIsPointer)));
4532 Results.ExitScope();
4536 ResultBuilder &Results) {
4539 Results.EnterNewScope();
4543 if (LangOpts.C99 || LangOpts.CPlusPlus11)
4545 Results.ExitScope();
4552 unsigned NumResults) {
4557static CodeCompletionContext
4615 llvm_unreachable(
"Invalid ParserCompletionContext!");
4627 ResultBuilder &Results) {
4633 CXXMethodDecl *Method = dyn_cast<CXXMethodDecl>(CurContext);
4634 if (!Method || !Method->isVirtual())
4639 for (
auto *P : Method->parameters())
4640 if (!P->getDeclName())
4646 Results.getCodeCompletionTUInfo());
4647 if (Overridden->getCanonicalDecl() == Method->getCanonicalDecl())
4653 S.
Context, CurContext, Overridden->getDeclContext());
4656 llvm::raw_string_ostream OS(Str);
4657 NNS.
print(OS, Policy);
4658 Builder.AddTextChunk(Results.getAllocator().CopyString(Str));
4660 }
else if (!InContext->
Equals(Overridden->getDeclContext()))
4663 Builder.AddTypedTextChunk(
4664 Results.getAllocator().CopyString(Overridden->getNameAsString()));
4666 bool FirstParam =
true;
4667 for (
auto *P : Method->parameters()) {
4673 Builder.AddPlaceholderChunk(
4674 Results.getAllocator().CopyString(P->getIdentifier()->getName()));
4680 Results.Ignore(Overridden);
4690 Results.EnterNewScope();
4698 SemaRef.PP.getHeaderSearchInfo().collectAllModules(Modules);
4699 for (
unsigned I = 0, N = Modules.size(); I != N; ++I) {
4700 Builder.AddTypedTextChunk(
4701 Builder.getAllocator().CopyString(Modules[I]->Name));
4702 Results.AddResult(
Result(
4715 Builder.AddTypedTextChunk(
4716 Builder.getAllocator().CopyString(Submodule->Name));
4717 Results.AddResult(
Result(
4724 Results.ExitScope();
4726 Results.getCompletionContext(), Results.data(),
4735 Results.EnterNewScope();
4740 switch (CompletionContext) {
4750 Results.setFilter(&ResultBuilder::IsOrdinaryNonValueName);
4760 Results.setFilter(&ResultBuilder::IsOrdinaryName);
4762 Results.setFilter(&ResultBuilder::IsOrdinaryNonTypeName);
4773 auto ThisType =
SemaRef.getCurrentThisType();
4774 if (ThisType.isNull()) {
4776 if (
auto *MethodDecl = llvm::dyn_cast_if_present<CXXMethodDecl>(
4777 SemaRef.getCurFunctionDecl()))
4778 Results.setExplicitObjectMemberFn(
4779 MethodDecl->isExplicitObjectMemberFunction());
4783 Results.setObjectTypeQualifiers(ThisType->getPointeeType().getQualifiers(),
4787 CodeCompletionDeclConsumer Consumer(Results,
SemaRef.CurContext);
4788 SemaRef.LookupVisibleDecls(S,
SemaRef.LookupOrdinaryName, Consumer,
4793 Results.ExitScope();
4795 switch (CompletionContext) {
4823 Results.getCompletionContext(), Results.data(),
4830 bool AtArgumentExpression,
bool IsSuper,
4831 ResultBuilder &Results);
4834 bool AllowNonIdentifiers,
4835 bool AllowNestedNameSpecifiers) {
4837 ResultBuilder Results(
4840 AllowNestedNameSpecifiers
4845 Results.EnterNewScope();
4848 Results.AddResult(
Result(
"const"));
4849 Results.AddResult(
Result(
"volatile"));
4851 Results.AddResult(
Result(
"restrict"));
4857 Results.AddResult(
"final");
4859 if (AllowNonIdentifiers) {
4860 Results.AddResult(
Result(
"operator"));
4864 if (AllowNestedNameSpecifiers) {
4865 Results.allowNestedNameSpecifiers();
4866 Results.setFilter(&ResultBuilder::IsImpossibleToSatisfy);
4867 CodeCompletionDeclConsumer Consumer(Results,
SemaRef.CurContext);
4871 Results.setFilter(
nullptr);
4874 Results.ExitScope();
4880 if (AllowNonIdentifiers && !AllowNestedNameSpecifiers &&
4891 if (!T.get().isNull() && T.get()->isObjCObjectOrInterfaceType())
4899 Results.getCompletionContext(), Results.data(),
4904 if (
Scope ==
"clang")
4912 if (
Scope ==
"_Clang")
4914 if (
Scope ==
"__gnu__")
4938 llvm::StringRef InScopeName;
4939 bool InScopeUnderscore =
false;
4941 InScopeName = InScope->
getName();
4943 InScopeName = NoUnderscore;
4944 InScopeUnderscore =
true;
4951 llvm::DenseSet<llvm::StringRef> FoundScopes;
4953 if (A.IsTargetSpecific &&
4958 for (
const auto &S : A.Spellings) {
4959 if (S.Syntax != Syntax)
4961 llvm::StringRef Name = S.NormalizedFullName;
4962 llvm::StringRef
Scope;
4965 std::tie(
Scope, Name) = Name.split(
"::");
4967 std::swap(Name,
Scope);
4973 if (!
Scope.empty() && FoundScopes.insert(
Scope).second) {
4984 if (!InScopeName.empty()) {
4985 if (
Scope != InScopeName)
4990 auto Add = [&](llvm::StringRef
Scope, llvm::StringRef Name,
4993 Results.getCodeCompletionTUInfo());
4995 if (!
Scope.empty()) {
5004 Builder.AddTypedTextChunk(Results.getAllocator().CopyString(
Text));
5006 if (!A.ArgNames.empty()) {
5009 for (
const char *Arg : A.ArgNames) {
5013 Builder.AddPlaceholderChunk(Arg);
5018 Results.AddResult(Builder.TakeString());
5025 if (!InScopeUnderscore)
5026 Add(
Scope, Name,
false);
5031 if (!(InScope && !InScopeUnderscore) && SyntaxSupportsGuards) {
5032 if (
Scope.empty()) {
5033 Add(
Scope, Name,
true);
5038 Add(GuardedScope, Name,
true);
5048 for (
const auto &Entry : ParsedAttrInfoRegistry::entries())
5049 AddCompletions(*Entry.instantiate());
5052 Results.getCompletionContext(), Results.data(),
5071struct CoveredEnumerators {
5079 const CoveredEnumerators &Enumerators) {
5081 if (Context.getLangOpts().CPlusPlus && !Qualifier && Enumerators.Seen.empty()) {
5088 Results.EnterNewScope();
5089 for (
auto *E :
Enum->enumerators()) {
5090 if (Enumerators.Seen.count(E))
5094 Results.AddResult(R, CurContext,
nullptr,
false);
5096 Results.ExitScope();
5102 assert(!T.isNull());
5106 if (
auto *
Specialization = T->getAs<TemplateSpecializationType>()) {
5115 if (T->isPointerType())
5116 T = T->getPointeeType();
5125 if (!Results.includeCodePatterns())
5128 Results.getCodeCompletionTUInfo());
5133 if (!Parameters.empty()) {
5142 constexpr llvm::StringLiteral NamePlaceholder =
"!#!NAME_GOES_HERE!#!";
5143 std::string
Type = std::string(NamePlaceholder);
5145 llvm::StringRef Prefix, Suffix;
5146 std::tie(Prefix, Suffix) = llvm::StringRef(
Type).split(NamePlaceholder);
5147 Prefix = Prefix.rtrim();
5148 Suffix = Suffix.ltrim();
5171 ResultBuilder Results(
5175 Data.IsParenthesized
5178 Data.PreferredType));
5181 if (
Data.ObjCCollection)
5182 Results.setFilter(&ResultBuilder::IsObjCCollection);
5183 else if (
Data.IntegralConstantExpression)
5184 Results.setFilter(&ResultBuilder::IsIntegralConstantValue);
5186 Results.setFilter(&ResultBuilder::IsOrdinaryName);
5188 Results.setFilter(&ResultBuilder::IsOrdinaryNonTypeName);
5190 if (!
Data.PreferredType.isNull())
5191 Results.setPreferredType(
Data.PreferredType.getNonReferenceType());
5194 for (
unsigned I = 0, N =
Data.IgnoreDecls.size(); I != N; ++I)
5195 Results.Ignore(
Data.IgnoreDecls[I]);
5197 CodeCompletionDeclConsumer Consumer(Results,
SemaRef.CurContext);
5198 Consumer.setIsAddressOfOperand(IsAddressOfOperand);
5203 Results.EnterNewScope();
5205 Results.ExitScope();
5207 bool PreferredTypeIsPointer =
false;
5208 if (!
Data.PreferredType.isNull()) {
5209 PreferredTypeIsPointer =
Data.PreferredType->isAnyPointerType() ||
5210 Data.PreferredType->isMemberPointerType() ||
5211 Data.PreferredType->isBlockPointerType();
5212 if (
auto *
Enum =
Data.PreferredType->getAsEnumDecl()) {
5216 CoveredEnumerators());
5221 !
Data.IntegralConstantExpression)
5226 PreferredTypeIsPointer);
5236 Results.getCompletionContext(), Results.data(),
5242 bool IsParenthesized,
5243 bool IsAddressOfOperand) {
5246 IsAddressOfOperand);
5271 if (Protocol->hasDefinition())
5272 return Protocol->getDefinition();
5286 Builder.AddResultTypeChunk(
5288 Policy, Builder.getAllocator()));
5294 Builder.AddPlaceholderChunk(
"...");
5296 for (
unsigned I = 0, N = BlockLoc.
getNumParams(); I != N; ++I) {
5301 std::string PlaceholderStr =
5304 if (I == N - 1 && BlockProtoLoc &&
5306 PlaceholderStr +=
", ...";
5309 Builder.AddPlaceholderChunk(
5310 Builder.getAllocator().CopyString(PlaceholderStr));
5320 bool AllowNullaryMethods,
DeclContext *CurContext,
5322 bool IsBaseExprStatement =
false,
5323 bool IsClassProperty =
false,
bool InOriginalClass =
true) {
5331 if (!AddedProperties.insert(P->getIdentifier()).second)
5336 if (!P->getType().getTypePtr()->isBlockPointerType() ||
5337 !IsBaseExprStatement) {
5339 Result(P, Results.getBasePriority(P), std::nullopt);
5340 if (!InOriginalClass)
5342 Results.MaybeAddResult(R, CurContext);
5354 Result(P, Results.getBasePriority(P), std::nullopt);
5355 if (!InOriginalClass)
5357 Results.MaybeAddResult(R, CurContext);
5364 Results.getCodeCompletionTUInfo());
5367 BlockLoc, BlockProtoLoc);
5368 Result R =
Result(Builder.TakeString(), P, Results.getBasePriority(P));
5369 if (!InOriginalClass)
5371 Results.MaybeAddResult(R, CurContext);
5375 if (!P->isReadOnly()) {
5377 Results.getCodeCompletionTUInfo());
5381 Builder.AddTypedTextChunk(
5382 Results.getAllocator().CopyString(P->getName()));
5387 BlockProtoLoc,
true);
5389 Builder.AddPlaceholderChunk(
5390 Builder.getAllocator().CopyString(PlaceholderStr));
5398 Result(Builder.TakeString(), P,
5399 Results.getBasePriority(P) +
5403 if (!InOriginalClass)
5405 Results.MaybeAddResult(R, CurContext);
5409 if (IsClassProperty) {
5418 if (AllowNullaryMethods) {
5423 const IdentifierInfo *Name = M->getSelector().getIdentifierInfoForSlot(0);
5426 if (!AddedProperties.insert(Name).second)
5429 Results.getCodeCompletionTUInfo());
5431 Builder.AddTypedTextChunk(
5432 Results.getAllocator().CopyString(Name->
getName()));
5433 Result R =
Result(Builder.TakeString(), M,
5435 if (!InOriginalClass)
5437 Results.MaybeAddResult(R, CurContext);
5440 if (IsClassProperty) {
5441 for (
const auto *M : Container->
methods()) {
5445 if (!M->getSelector().isUnarySelector() ||
5446 M->getReturnType()->isVoidType() || M->isInstanceMethod())
5451 for (
auto *M : Container->
methods()) {
5452 if (M->getSelector().isUnarySelector())
5460 for (
auto *P : Protocol->protocols())
5462 CurContext, AddedProperties, Results,
5463 IsBaseExprStatement, IsClassProperty,
5466 dyn_cast<ObjCInterfaceDecl>(Container)) {
5467 if (AllowCategories) {
5469 for (
auto *Cat : IFace->known_categories())
5471 CurContext, AddedProperties, Results,
5472 IsBaseExprStatement, IsClassProperty,
5477 for (
auto *I : IFace->all_referenced_protocols())
5479 CurContext, AddedProperties, Results,
5480 IsBaseExprStatement, IsClassProperty,
5484 if (IFace->getSuperClass())
5486 AllowNullaryMethods, CurContext, AddedProperties,
5487 Results, IsBaseExprStatement, IsClassProperty,
5489 }
else if (
const auto *Category =
5490 dyn_cast<ObjCCategoryDecl>(Container)) {
5492 for (
auto *P : Category->protocols())
5494 CurContext, AddedProperties, Results,
5495 IsBaseExprStatement, IsClassProperty,
5504 std::optional<FixItHint> AccessOpFixIt) {
5507 Results.setObjectTypeQualifiers(BaseType.getQualifiers(), BaseKind);
5510 Results.allowNestedNameSpecifiers();
5511 std::vector<FixItHint> FixIts;
5513 FixIts.emplace_back(*AccessOpFixIt);
5514 CodeCompletionDeclConsumer Consumer(Results, RD, BaseType, std::move(FixIts));
5522 if (!Results.empty()) {
5526 bool IsDependent = BaseType->isDependentType();
5528 for (
Scope *DepScope = S; DepScope; DepScope = DepScope->
getParent())
5546 BaseType = Resolver.
simplifyType(BaseType,
nullptr,
false);
5547 return dyn_cast_if_present<RecordDecl>(
5583 const IdentifierInfo *Name =
nullptr;
5588 std::optional<SmallVector<QualType, 1>> ArgTypes;
5590 enum AccessOperator {
5596 const TypeConstraint *ResultType =
nullptr;
5602 CodeCompletionString *render(Sema &S, CodeCompletionAllocator &Alloc,
5603 CodeCompletionTUInfo &Info)
const {
5604 CodeCompletionBuilder B(Alloc, Info);
5607 std::string AsString;
5609 llvm::raw_string_ostream
OS(AsString);
5610 QualType ExactType = deduceType(*ResultType);
5616 B.AddResultTypeChunk(
Alloc.CopyString(AsString));
5619 B.AddTypedTextChunk(
Alloc.CopyString(Name->
getName()));
5624 for (QualType Arg : *ArgTypes) {
5631 B.AddPlaceholderChunk(
Alloc.CopyString(
5636 return B.TakeString();
5643 ConceptInfo(
const TemplateTypeParmType &BaseType, Scope *S) {
5644 auto *TemplatedEntity = getTemplatedEntity(BaseType.getDecl(), S);
5645 for (
const AssociatedConstraint &AC :
5646 constraintsForTemplatedEntity(TemplatedEntity))
5647 believe(AC.ConstraintExpr, &BaseType);
5650 std::vector<Member> members() {
5651 std::vector<Member> Results;
5652 for (
const auto &E : this->Results)
5653 Results.push_back(E.second);
5654 llvm::sort(Results, [](
const Member &L,
const Member &R) {
5655 return L.Name->getName() <
R.Name->getName();
5662 void believe(
const Expr *E,
const TemplateTypeParmType *T) {
5665 if (
auto *CSE = dyn_cast<ConceptSpecializationExpr>(E)) {
5676 ConceptDecl *CD = CSE->getNamedConcept();
5679 for (
const auto &Arg : CSE->getTemplateArguments()) {
5680 if (Index >= Params->
size())
5682 if (isApprox(Arg, T)) {
5683 auto *TTPD = dyn_cast<TemplateTypeParmDecl>(Params->
getParam(Index));
5695 }
else if (
auto *BO = dyn_cast<BinaryOperator>(E)) {
5698 if (BO->getOpcode() == BO_LAnd || BO->getOpcode() == BO_LOr) {
5699 believe(BO->getLHS(), T);
5700 believe(BO->getRHS(), T);
5702 }
else if (
auto *RE = dyn_cast<RequiresExpr>(E)) {
5704 for (
const concepts::Requirement *Req : RE->getRequirements()) {
5705 if (!Req->isDependent())
5709 if (
auto *TR = dyn_cast<concepts::TypeRequirement>(Req)) {
5711 QualType AssertedType = TR->getType()->getType();
5712 ValidVisitor(
this, T).TraverseType(AssertedType);
5713 }
else if (
auto *ER = dyn_cast<concepts::ExprRequirement>(Req)) {
5714 ValidVisitor Visitor(
this, T);
5718 if (ER->getReturnTypeRequirement().isTypeConstraint()) {
5720 ER->getReturnTypeRequirement().getTypeConstraint();
5721 Visitor.OuterExpr = ER->getExpr();
5723 Visitor.TraverseStmt(ER->getExpr());
5724 }
else if (
auto *NR = dyn_cast<concepts::NestedRequirement>(Req)) {
5725 believe(NR->getConstraintExpr(), T);
5735 const TemplateTypeParmType *T;
5737 CallExpr *Caller =
nullptr;
5742 Expr *OuterExpr =
nullptr;
5743 const TypeConstraint *OuterType =
nullptr;
5745 ValidVisitor(ConceptInfo *Outer,
const TemplateTypeParmType *T)
5746 : Outer(Outer), T(T) {
5752 VisitCXXDependentScopeMemberExpr(CXXDependentScopeMemberExpr *E)
override {
5755 if (
Base->isPointerType() && IsArrow) {
5757 Base =
Base->getPointeeType().getTypePtr();
5759 if (isApprox(Base, T))
5760 addValue(E, E->
getMember(), IsArrow ? Member::Arrow : Member::Dot);
5765 bool VisitDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E)
override {
5767 if (
Qualifier.getKind() == NestedNameSpecifier::Kind::Type &&
5774 bool VisitDependentNameType(DependentNameType *DNT)
override {
5775 NestedNameSpecifier Q = DNT->getQualifier();
5776 if (Q.
getKind() == NestedNameSpecifier::Kind::Type &&
5778 addType(DNT->getIdentifier());
5787 if (NNS.
getKind() == NestedNameSpecifier::Kind::Type) {
5789 if (NestedNameSpecifier Q = NNST->
getPrefix();
5790 Q.
getKind() == NestedNameSpecifier::Kind::Type &&
5792 if (
const auto *DNT = dyn_cast_or_null<DependentNameType>(NNST))
5793 addType(DNT->getIdentifier());
5804 bool VisitCallExpr(CallExpr *CE)
override {
5811 void addResult(
Member &&M) {
5812 auto R = Outer->Results.try_emplace(M.Name);
5817 std::make_tuple(M.ArgTypes.has_value(), M.ResultType !=
nullptr,
5818 M.Operator) > std::make_tuple(O.ArgTypes.has_value(),
5819 O.ResultType !=
nullptr,
5824 void addType(
const IdentifierInfo *Name) {
5829 M.Operator = Member::Colons;
5830 addResult(std::move(M));
5833 void addValue(Expr *E, DeclarationName Name,
5834 Member::AccessOperator Operator) {
5839 Result.Operator = Operator;
5842 if (Caller !=
nullptr && Callee == E) {
5843 Result.ArgTypes.emplace();
5844 for (
const auto *Arg : Caller->
arguments())
5845 Result.ArgTypes->push_back(Arg->getType());
5846 if (Caller == OuterExpr) {
5847 Result.ResultType = OuterType;
5851 Result.ResultType = OuterType;
5853 addResult(std::move(
Result));
5857 static bool isApprox(
const TemplateArgument &Arg,
const Type *T) {
5862 static bool isApprox(
const Type *T1,
const Type *T2) {
5871 static DeclContext *getTemplatedEntity(
const TemplateTypeParmDecl *D,
5875 Scope *Inner =
nullptr;
5878 return Inner ? Inner->
getEntity() :
nullptr;
5887 static SmallVector<AssociatedConstraint, 1>
5888 constraintsForTemplatedEntity(DeclContext *DC) {
5889 SmallVector<AssociatedConstraint, 1>
Result;
5894 TD->getAssociatedConstraints(
Result);
5896 if (
const auto *CTPSD =
5897 dyn_cast<ClassTemplatePartialSpecializationDecl>(DC))
5898 CTPSD->getAssociatedConstraints(
Result);
5899 if (
const auto *VTPSD = dyn_cast<VarTemplatePartialSpecializationDecl>(DC))
5900 VTPSD->getAssociatedConstraints(
Result);
5906 static QualType deduceType(
const TypeConstraint &T) {
5912 if (Args->getNumTemplateArgs() == 1) {
5913 const auto &Arg = Args->arguments().front().getArgument();
5920 llvm::DenseMap<const IdentifierInfo *, Member> Results;
5927QualType getApproximateType(
const Expr *E, HeuristicResolver &Resolver) {
5941Expr *unwrapParenList(Expr *Base) {
5942 if (
auto *PLE = llvm::dyn_cast_or_null<ParenListExpr>(Base)) {
5943 if (PLE->getNumExprs() == 0)
5945 Base = PLE->getExpr(PLE->getNumExprs() - 1);
5954 bool IsBaseExprStatement,
QualType PreferredType) {
5956 OtherOpBase = unwrapParenList(OtherOpBase);
5961 SemaRef.PerformMemberExprBaseConversion(
Base, IsArrow);
5965 getApproximateType(ConvertedBase.
get(),
Resolver);
5971 !PointeeType.isNull()) {
5972 ConvertedBaseType = PointeeType;
5991 &ResultBuilder::IsMember);
5993 auto DoCompletion = [&](
Expr *
Base,
bool IsArrow,
5994 std::optional<FixItHint> AccessOpFixIt) ->
bool {
5999 SemaRef.PerformMemberExprBaseConversion(
Base, IsArrow);
6005 if (BaseType.isNull())
6011 !PointeeType.isNull()) {
6012 BaseType = PointeeType;
6014 }
else if (BaseType->isObjCObjectPointerType() ||
6015 BaseType->isTemplateTypeParmType()) {
6024 RD, std::move(AccessOpFixIt));
6025 }
else if (
const auto *TTPT =
6026 dyn_cast<TemplateTypeParmType>(BaseType.getTypePtr())) {
6028 IsArrow ? ConceptInfo::Member::Arrow : ConceptInfo::Member::Dot;
6029 for (
const auto &R : ConceptInfo(*TTPT, S).members()) {
6030 if (R.Operator != Operator)
6036 Result.FixIts.push_back(*AccessOpFixIt);
6037 Results.AddResult(std::move(
Result));
6039 }
else if (!IsArrow && BaseType->isObjCObjectPointerType()) {
6043 if (AccessOpFixIt) {
6051 assert(ObjCPtr &&
"Non-NULL pointer guaranteed above!");
6054 AddedProperties, Results, IsBaseExprStatement);
6060 SemaRef.CurContext, AddedProperties, Results,
6061 IsBaseExprStatement,
false,
6063 }
else if ((IsArrow && BaseType->isObjCObjectPointerType()) ||
6064 (!IsArrow && BaseType->isObjCObjectType())) {
6068 if (AccessOpFixIt) {
6074 Class = ObjCPtr->getInterfaceDecl();
6080 CodeCompletionDeclConsumer Consumer(Results,
Class, BaseType);
6081 Results.setFilter(&ResultBuilder::IsObjCIvar);
6093 Results.EnterNewScope();
6095 bool CompletionSucceded = DoCompletion(
Base, IsArrow, std::nullopt);
6099 CompletionSucceded |= DoCompletion(
6100 OtherOpBase, !IsArrow,
6104 Results.ExitScope();
6106 if (!CompletionSucceded)
6111 Results.getCompletionContext(), Results.data(),
6117 bool IsBaseExprStatement) {
6120 SemaRef.ObjC().getObjCInterfaceDecl(ClassNamePtr, ClassNameLoc);
6127 &ResultBuilder::IsMember);
6128 Results.EnterNewScope();
6132 AddedProperties, Results, IsBaseExprStatement,
6134 Results.ExitScope();
6136 Results.getCompletionContext(), Results.data(),
6144 ResultBuilder::LookupFilter Filter =
nullptr;
6149 Filter = &ResultBuilder::IsEnum;
6154 Filter = &ResultBuilder::IsUnion;
6161 Filter = &ResultBuilder::IsClassOrStruct;
6166 llvm_unreachable(
"Unknown type specifier kind in CodeCompleteTag");
6171 CodeCompletionDeclConsumer Consumer(Results,
SemaRef.CurContext);
6174 Results.setFilter(Filter);
6181 Results.setFilter(&ResultBuilder::IsNestedNameSpecifier);
6188 Results.getCompletionContext(), Results.data(),
6195 Results.AddResult(
"const");
6197 Results.AddResult(
"volatile");
6199 Results.AddResult(
"restrict");
6201 Results.AddResult(
"_Atomic");
6203 Results.AddResult(
"__unaligned");
6210 Results.EnterNewScope();
6212 Results.ExitScope();
6214 Results.getCompletionContext(), Results.data(),
6223 Results.EnterNewScope();
6226 Results.AddResult(
"noexcept");
6230 Results.AddResult(
"final");
6232 Results.AddResult(
"override");
6235 Results.ExitScope();
6237 Results.getCompletionContext(), Results.data(),
6250 SemaRef.getCurFunction()->SwitchStack.back().getPointer();
6258 Data.IntegralConstantExpression =
true;
6267 CoveredEnumerators Enumerators;
6269 SC = SC->getNextSwitchCase()) {
6270 CaseStmt *Case = dyn_cast<CaseStmt>(SC);
6275 if (
auto *DRE = dyn_cast<DeclRefExpr>(CaseVal))
6277 dyn_cast<EnumConstantDecl>(DRE->getDecl())) {
6297 Enumerators.SuggestedQualifier = DRE->getQualifier();
6312 Results.getCompletionContext(), Results.data(),
6317 if (Args.size() && !Args.data())
6320 for (
unsigned I = 0; I != Args.size(); ++I)
6341 if (Candidate.Function) {
6342 if (Candidate.Function->isDeleted())
6345 Candidate.Function) &&
6346 Candidate.Function->getNumParams() <= ArgSize &&
6355 if (Candidate.Viable)
6369 for (
auto &Candidate : Candidates) {
6370 QualType CandidateParamType = Candidate.getParamType(N);
6371 if (CandidateParamType.
isNull())
6373 if (ParamType.
isNull()) {
6374 ParamType = CandidateParamType;
6391 if (Candidates.empty())
6395 SemaRef, CurrentArg, Candidates.data(), Candidates.size(), OpenParLoc,
6403 Fn = unwrapParenList(Fn);
6414 auto ArgsWithoutDependentTypes =
6419 Expr *NakedFn = Fn->IgnoreParenCasts();
6425 if (
auto ULE = dyn_cast<UnresolvedLookupExpr>(NakedFn)) {
6426 SemaRef.AddOverloadedCallCandidates(ULE, ArgsWithoutDependentTypes,
6429 }
else if (
auto UME = dyn_cast<UnresolvedMemberExpr>(NakedFn)) {
6431 if (UME->hasExplicitTemplateArgs()) {
6432 UME->copyTemplateArgumentsInto(TemplateArgsBuffer);
6433 TemplateArgs = &TemplateArgsBuffer;
6438 1, UME->isImplicitAccess() ?
nullptr : UME->getBase());
6439 ArgExprs.append(ArgsWithoutDependentTypes.begin(),
6440 ArgsWithoutDependentTypes.end());
6442 Decls.
append(UME->decls_begin(), UME->decls_end());
6443 const bool FirstArgumentIsBase = !UME->isImplicitAccess() && UME->getBase();
6444 SemaRef.AddFunctionCandidates(Decls, ArgExprs, CandidateSet, TemplateArgs,
6447 FirstArgumentIsBase);
6450 if (
auto *MCE = dyn_cast<MemberExpr>(NakedFn))
6451 FD = dyn_cast<FunctionDecl>(MCE->getMemberDecl());
6452 else if (
auto *DRE = dyn_cast<DeclRefExpr>(NakedFn))
6453 FD = dyn_cast<FunctionDecl>(DRE->getDecl());
6459 SemaRef.AddOverloadCandidate(FD,
6461 ArgsWithoutDependentTypes, CandidateSet,
6471 getASTContext().DeclarationNames.getCXXOperatorName(OO_Call);
6473 SemaRef.LookupQualifiedName(R, DC);
6474 R.suppressDiagnostics();
6476 ArgExprs.append(ArgsWithoutDependentTypes.begin(),
6477 ArgsWithoutDependentTypes.end());
6478 SemaRef.AddFunctionCandidates(R.asUnresolvedSet(), ArgExprs,
6490 if (!T->getPointeeType().isNull())
6494 if (!
SemaRef.TooManyArguments(FP->getNumParams(),
6495 ArgsWithoutDependentTypes.size(),
6531static std::optional<unsigned>
6534 static constexpr unsigned Invalid = std::numeric_limits<unsigned>::max();
6540 unsigned ArgsAfterDesignator = 0;
6541 for (
const Expr *Arg : Args) {
6542 if (
const auto *DIE = dyn_cast<DesignatedInitExpr>(Arg)) {
6543 if (DIE->size() == 1 && DIE->getDesignator(0)->isFieldDesignator()) {
6544 DesignatedFieldName = DIE->getDesignator(0)->getFieldName();
6545 ArgsAfterDesignator = 0;
6552 ++ArgsAfterDesignator;
6555 if (!DesignatedFieldName)
6556 return std::nullopt;
6560 unsigned DesignatedIndex = 0;
6561 const FieldDecl *DesignatedField =
nullptr;
6562 for (
const auto *Field :
Aggregate.getAggregate()->fields()) {
6563 if (Field->getIdentifier() == DesignatedFieldName) {
6564 DesignatedField = Field;
6569 if (!DesignatedField)
6573 unsigned AggregateSize =
Aggregate.getNumParams();
6574 while (DesignatedIndex < AggregateSize &&
6575 Aggregate.getParamDecl(DesignatedIndex) != DesignatedField)
6579 return DesignatedIndex + ArgsAfterDesignator + 1;
6602 if (Braced && !RD->
isUnion() &&
6607 if (
auto NextIndex =
6610 if (*NextIndex >= AggregateSize)
6612 Results.push_back(AggregateSig);
6618 if (Args.size() < AggregateSize)
6619 Results.push_back(AggregateSig);
6629 if (
auto *FD = dyn_cast<FunctionDecl>(
C)) {
6633 SemaRef.isInitListConstructor(FD))
6640 }
else if (
auto *FTD = dyn_cast<FunctionTemplateDecl>(
C)) {
6642 SemaRef.isInitListConstructor(FTD->getTemplatedDecl()))
6645 SemaRef.AddTemplateOverloadCandidate(
6647 nullptr, Args, CandidateSet,
6668 dyn_cast<CXXConstructorDecl>(ConstructorDecl);
6673 Constructor->getParent(), SS, TemplateTypeTy, II))
6675 MemberDecl->getLocation(), ArgExprs,
6676 OpenParLoc, Braced);
6684 if (Index < Params.
size())
6687 Param = Params.
asArray().back();
6693 return llvm::isa<TemplateTypeParmDecl>(Param);
6695 return llvm::isa<NonTypeTemplateParmDecl>(Param);
6697 return llvm::isa<TemplateTemplateParmDecl>(Param);
6699 llvm_unreachable(
"Unhandled switch case");
6711 bool Matches =
true;
6712 for (
unsigned I = 0; I < Args.size(); ++I) {
6719 Results.emplace_back(TD);
6723 if (
const auto *TD =
Template.getAsTemplateDecl()) {
6725 }
else if (
const auto *OTS =
Template.getAsOverloadedTemplate()) {
6727 if (
const auto *TD = llvm::dyn_cast<TemplateDecl>(ND))
6737 if (BaseType.isNull())
6741 if (D.isArrayDesignator() || D.isArrayRangeDesignator()) {
6742 if (BaseType->isArrayType())
6745 assert(D.isFieldDesignator());
6747 if (RD && RD->isCompleteDefinition()) {
6748 for (
const auto *
Member : RD->lookup(D.getFieldDecl()))
6750 NextType = FD->getType();
6755 BaseType = NextType;
6763 if (BaseType.isNull())
6766 if (!RD || RD->fields().empty())
6774 Results.EnterNewScope();
6775 for (
const Decl *D : RD->decls()) {
6777 if (
auto *IFD = dyn_cast<IndirectFieldDecl>(D))
6778 FD = IFD->getAnonField();
6779 else if (
auto *DFD = dyn_cast<FieldDecl>(D))
6786 ResultBuilder::Result
Result(FD, Results.getBasePriority(FD));
6789 Results.ExitScope();
6791 Results.getCompletionContext(), Results.data(),
6796 ValueDecl *VD = dyn_cast_or_null<ValueDecl>(D);
6805 Data.IgnoreDecls.push_back(VD);
6815 Results.getCodeCompletionTUInfo());
6817 if (!AfterExclaim) {
6818 if (Results.includeCodePatterns()) {
6819 Builder.AddTypedTextChunk(
"constexpr");
6822 Builder.AddPlaceholderChunk(
"condition");
6827 Builder.AddPlaceholderChunk(
"statements");
6830 Results.AddResult({Builder.TakeString()});
6832 Results.AddResult({
"constexpr"});
6837 if (Results.includeCodePatterns()) {
6838 Builder.AddTypedTextChunk(
"consteval");
6842 Builder.AddPlaceholderChunk(
"statements");
6845 Results.AddResult({Builder.TakeString()});
6847 Results.AddResult({
"consteval"});
6852 Results.getCompletionContext(), Results.data(),
6860 Results.setFilter(&ResultBuilder::IsOrdinaryName);
6861 Results.EnterNewScope();
6863 CodeCompletionDeclConsumer Consumer(Results,
SemaRef.CurContext);
6872 Results.getCodeCompletionTUInfo());
6874 auto AddElseBodyPattern = [&] {
6879 Builder.AddPlaceholderChunk(
"statements");
6885 Builder.AddPlaceholderChunk(
"statement");
6889 Builder.AddTypedTextChunk(
"else");
6890 if (Results.includeCodePatterns())
6891 AddElseBodyPattern();
6892 Results.AddResult(Builder.TakeString());
6895 Builder.AddTypedTextChunk(
"else if");
6899 Builder.AddPlaceholderChunk(
"condition");
6901 Builder.AddPlaceholderChunk(
"expression");
6903 if (Results.includeCodePatterns()) {
6904 AddElseBodyPattern();
6906 Results.AddResult(Builder.TakeString());
6908 Results.ExitScope();
6917 Results.getCompletionContext(), Results.data(),
6923 bool IsAddressOfOperand,
bool IsInDeclarationContext,
QualType BaseType,
6942 if (!PreferredType.
isNull())
6943 DummyResults.setPreferredType(PreferredType);
6945 CodeCompletionDeclConsumer Consumer(DummyResults, S->
getEntity(),
6952 DummyResults.getCompletionContext(),
nullptr, 0);
6959 std::optional<Sema::ContextRAII> SimulateContext;
6962 if (IsInDeclarationContext && Ctx !=
nullptr)
6963 SimulateContext.emplace(
SemaRef, Ctx);
6969 if (Ctx ==
nullptr ||
SemaRef.RequireCompleteDeclContext(SS, Ctx))
6975 if (!PreferredType.
isNull())
6976 Results.setPreferredType(PreferredType);
6977 Results.EnterNewScope();
6983 Results.AddResult(
"template");
6988 if (
const auto *TTPT = dyn_cast<TemplateTypeParmType>(NNS.
getAsType())) {
6989 for (
const auto &R : ConceptInfo(*TTPT, S).members()) {
6990 if (R.Operator != ConceptInfo::Member::Colons)
7004 if (Ctx && !EnteringContext)
7006 Results.ExitScope();
7010 CodeCompletionDeclConsumer Consumer(Results, Ctx, BaseType);
7011 Consumer.setIsInDeclarationContext(IsInDeclarationContext);
7012 Consumer.setIsAddressOfOperand(IsAddressOfOperand);
7018 SimulateContext.reset();
7020 Results.getCompletionContext(), Results.data(),
7031 Context.setIsUsingDeclaration(
true);
7035 &ResultBuilder::IsNestedNameSpecifier);
7036 Results.EnterNewScope();
7044 CodeCompletionDeclConsumer Consumer(Results,
SemaRef.CurContext);
7048 Results.ExitScope();
7051 Results.getCompletionContext(), Results.data(),
7064 &ResultBuilder::IsNamespaceOrAlias);
7065 Results.EnterNewScope();
7066 CodeCompletionDeclConsumer Consumer(Results,
SemaRef.CurContext);
7070 Results.ExitScope();
7072 Results.getCompletionContext(), Results.data(),
7084 bool SuppressedGlobalResults =
7089 SuppressedGlobalResults
7092 &ResultBuilder::IsNamespace);
7094 if (Ctx && Ctx->
isFileContext() && !SuppressedGlobalResults) {
7099 std::map<NamespaceDecl *, NamespaceDecl *> OrigToLatest;
7104 OrigToLatest[NS->getFirstDecl()] = *NS;
7108 Results.EnterNewScope();
7109 for (std::map<NamespaceDecl *, NamespaceDecl *>::iterator
7110 NS = OrigToLatest.begin(),
7111 NSEnd = OrigToLatest.end();
7116 SemaRef.CurContext,
nullptr,
false);
7117 Results.ExitScope();
7121 Results.getCompletionContext(), Results.data(),
7133 &ResultBuilder::IsNamespaceOrAlias);
7134 CodeCompletionDeclConsumer Consumer(Results,
SemaRef.CurContext);
7139 Results.getCompletionContext(), Results.data(),
7151 &ResultBuilder::IsType);
7152 Results.EnterNewScope();
7156#define OVERLOADED_OPERATOR(Name, Spelling, Token, Unary, Binary, MemberOnly) \
7157 if (OO_##Name != OO_Conditional) \
7158 Results.AddResult(Result(Spelling));
7159#include "clang/Basic/OperatorKinds.def"
7162 Results.allowNestedNameSpecifiers();
7163 CodeCompletionDeclConsumer Consumer(Results,
SemaRef.CurContext);
7170 Results.ExitScope();
7173 Results.getCompletionContext(), Results.data(),
7182 SemaRef.AdjustDeclIfTemplate(ConstructorD);
7184 auto *
Constructor = dyn_cast<CXXConstructorDecl>(ConstructorD);
7191 Results.EnterNewScope();
7196 for (
unsigned I = 0, E = Initializers.size(); I != E; ++I) {
7197 if (Initializers[I]->isBaseInitializer())
7199 QualType(Initializers[I]->getBaseClass(), 0)));
7201 InitializedFields.insert(
7207 bool SawLastInitializer = Initializers.empty();
7210 auto GenerateCCS = [&](
const NamedDecl *ND,
const char *Name) {
7212 Results.getCodeCompletionTUInfo());
7213 Builder.AddTypedTextChunk(Name);
7215 if (
const auto *
Function = dyn_cast<FunctionDecl>(ND))
7217 else if (
const auto *FunTemplDecl = dyn_cast<FunctionTemplateDecl>(ND))
7219 FunTemplDecl->getTemplatedDecl(), Builder);
7221 return Builder.TakeString();
7223 auto AddDefaultCtorInit = [&](
const char *Name,
const char *
Type,
7226 Results.getCodeCompletionTUInfo());
7227 Builder.AddTypedTextChunk(Name);
7229 Builder.AddPlaceholderChunk(
Type);
7233 Builder.TakeString(), ND,
7237 return Results.AddResult(CCR);
7240 Builder.TakeString(),
7243 auto AddCtorsWithName = [&](
const CXXRecordDecl *RD,
unsigned int Priority,
7244 const char *Name,
const FieldDecl *FD) {
7246 return AddDefaultCtorInit(Name,
7247 FD ? Results.getAllocator().CopyString(
7248 FD->getType().getAsString(Policy))
7252 if (Ctors.begin() == Ctors.end())
7253 return AddDefaultCtorInit(Name, Name, RD);
7257 Results.AddResult(CCR);
7261 const char *BaseName =
7262 Results.getAllocator().CopyString(
Base.getType().getAsString(Policy));
7263 const auto *RD =
Base.getType()->getAsCXXRecordDecl();
7268 auto AddField = [&](
const FieldDecl *FD) {
7269 const char *FieldName =
7270 Results.getAllocator().CopyString(FD->getIdentifier()->getName());
7271 const CXXRecordDecl *RD = FD->getType()->getAsCXXRecordDecl();
7277 for (
const auto &
Base : ClassDecl->
bases()) {
7278 if (!InitializedBases
7281 SawLastInitializer =
7282 !Initializers.empty() && Initializers.back()->isBaseInitializer() &&
7284 Base.getType(),
QualType(Initializers.back()->getBaseClass(), 0));
7289 SawLastInitializer =
false;
7293 for (
const auto &
Base : ClassDecl->
vbases()) {
7294 if (!InitializedBases
7297 SawLastInitializer =
7298 !Initializers.empty() && Initializers.back()->isBaseInitializer() &&
7300 Base.getType(),
QualType(Initializers.back()->getBaseClass(), 0));
7305 SawLastInitializer =
false;
7309 for (
auto *Field : ClassDecl->
fields()) {
7310 if (!InitializedFields.insert(
cast<FieldDecl>(Field->getCanonicalDecl()))
7312 SawLastInitializer = !Initializers.empty() &&
7313 Initializers.back()->isAnyMemberInitializer() &&
7314 Initializers.back()->getAnyMember() == Field;
7318 if (!Field->getDeclName())
7322 SawLastInitializer =
false;
7324 Results.ExitScope();
7327 Results.getCompletionContext(), Results.data(),
7342 bool AfterAmpersand) {
7346 Results.EnterNewScope();
7350 bool IncludedThis =
false;
7353 IncludedThis =
true;
7362 for (
const auto *D : S->
decls()) {
7363 const auto *Var = dyn_cast<VarDecl>(D);
7364 if (!Var || !Var->hasLocalStorage() || Var->hasAttr<BlocksAttr>())
7367 if (Known.insert(Var->getIdentifier()).second)
7369 SemaRef.CurContext,
nullptr,
false);
7377 Results.ExitScope();
7380 Results.getCompletionContext(), Results.data(),
7390 auto ShouldAddDefault = [&D,
this]() {
7402 auto Op = Id.OperatorFunctionId.Operator;
7405 if (Op == OverloadedOperatorKind::OO_Equal)
7408 (Op == OverloadedOperatorKind::OO_EqualEqual ||
7409 Op == OverloadedOperatorKind::OO_ExclaimEqual ||
7410 Op == OverloadedOperatorKind::OO_Less ||
7411 Op == OverloadedOperatorKind::OO_LessEqual ||
7412 Op == OverloadedOperatorKind::OO_Greater ||
7413 Op == OverloadedOperatorKind::OO_GreaterEqual ||
7414 Op == OverloadedOperatorKind::OO_Spaceship))
7420 Results.EnterNewScope();
7421 if (ShouldAddDefault())
7422 Results.AddResult(
"default");
7425 Results.AddResult(
"delete");
7426 Results.ExitScope();
7428 Results.getCompletionContext(), Results.data(),
7434#define OBJC_AT_KEYWORD_NAME(NeedAt, Keyword) ((NeedAt) ? "@" Keyword : Keyword)
7437 ResultBuilder &Results,
bool NeedAt) {
7443 Results.getCodeCompletionTUInfo());
7444 if (LangOpts.ObjC) {
7448 Builder.AddPlaceholderChunk(
"property");
7449 Results.AddResult(
Result(Builder.TakeString()));
7454 Builder.AddPlaceholderChunk(
"property");
7455 Results.AddResult(
Result(Builder.TakeString()));
7460 ResultBuilder &Results,
bool NeedAt) {
7466 if (LangOpts.ObjC) {
7481 Results.getCodeCompletionTUInfo());
7486 Builder.AddPlaceholderChunk(
"name");
7487 Results.AddResult(
Result(Builder.TakeString()));
7489 if (Results.includeCodePatterns()) {
7495 Builder.AddPlaceholderChunk(
"class");
7496 Results.AddResult(
Result(Builder.TakeString()));
7501 Builder.AddPlaceholderChunk(
"protocol");
7502 Results.AddResult(
Result(Builder.TakeString()));
7507 Builder.AddPlaceholderChunk(
"class");
7508 Results.AddResult(
Result(Builder.TakeString()));
7512 Builder.AddTypedTextChunk(
7515 Builder.AddPlaceholderChunk(
"alias");
7517 Builder.AddPlaceholderChunk(
"class");
7518 Results.AddResult(
Result(Builder.TakeString()));
7520 if (Results.getSema().getLangOpts().Modules) {
7524 Builder.AddPlaceholderChunk(
"module");
7525 Results.AddResult(
Result(Builder.TakeString()));
7533 Results.EnterNewScope();
7536 else if (
SemaRef.CurContext->isObjCContainer())
7540 Results.ExitScope();
7542 Results.getCompletionContext(), Results.data(),
7549 Results.getCodeCompletionTUInfo());
7552 const char *EncodeType =
"char[]";
7553 if (Results.getSema().getLangOpts().CPlusPlus ||
7554 Results.getSema().getLangOpts().ConstStrings)
7555 EncodeType =
"const char[]";
7556 Builder.AddResultTypeChunk(EncodeType);
7559 Builder.AddPlaceholderChunk(
"type-name");
7561 Results.AddResult(
Result(Builder.TakeString()));
7564 Builder.AddResultTypeChunk(
"Protocol *");
7567 Builder.AddPlaceholderChunk(
"protocol-name");
7569 Results.AddResult(
Result(Builder.TakeString()));
7572 Builder.AddResultTypeChunk(
"SEL");
7575 Builder.AddPlaceholderChunk(
"selector");
7577 Results.AddResult(
Result(Builder.TakeString()));
7580 Builder.AddResultTypeChunk(
"NSString *");
7582 Builder.AddPlaceholderChunk(
"string");
7583 Builder.AddTextChunk(
"\"");
7584 Results.AddResult(
Result(Builder.TakeString()));
7587 Builder.AddResultTypeChunk(
"NSArray *");
7589 Builder.AddPlaceholderChunk(
"objects, ...");
7591 Results.AddResult(
Result(Builder.TakeString()));
7594 Builder.AddResultTypeChunk(
"NSDictionary *");
7596 Builder.AddPlaceholderChunk(
"key");
7599 Builder.AddPlaceholderChunk(
"object, ...");
7601 Results.AddResult(
Result(Builder.TakeString()));
7604 Builder.AddResultTypeChunk(
"id");
7606 Builder.AddPlaceholderChunk(
"expression");
7608 Results.AddResult(
Result(Builder.TakeString()));
7614 Results.getCodeCompletionTUInfo());
7616 if (Results.includeCodePatterns()) {
7621 Builder.AddPlaceholderChunk(
"statements");
7623 Builder.AddTextChunk(
"@catch");
7625 Builder.AddPlaceholderChunk(
"parameter");
7628 Builder.AddPlaceholderChunk(
"statements");
7630 Builder.AddTextChunk(
"@finally");
7632 Builder.AddPlaceholderChunk(
"statements");
7634 Results.AddResult(
Result(Builder.TakeString()));
7640 Builder.AddPlaceholderChunk(
"expression");
7641 Results.AddResult(
Result(Builder.TakeString()));
7643 if (Results.includeCodePatterns()) {
7648 Builder.AddPlaceholderChunk(
"expression");
7651 Builder.AddPlaceholderChunk(
"statements");
7653 Results.AddResult(
Result(Builder.TakeString()));
7658 ResultBuilder &Results,
bool NeedAt) {
7671 Results.EnterNewScope();
7673 Results.ExitScope();
7675 Results.getCompletionContext(), Results.data(),
7683 Results.EnterNewScope();
7686 Results.ExitScope();
7688 Results.getCompletionContext(), Results.data(),
7696 Results.EnterNewScope();
7698 Results.ExitScope();
7700 Results.getCompletionContext(), Results.data(),
7708 if (Attributes & NewFlag)
7711 Attributes |= NewFlag;
7719 unsigned AssignCopyRetMask =
7725 if (AssignCopyRetMask &&
7747 Results.EnterNewScope();
7784 Results.getCodeCompletionTUInfo());
7793 Results.getCodeCompletionTUInfo());
7806 Results.ExitScope();
7808 Results.getCompletionContext(), Results.data(),
7822 bool AllowSameLength =
true) {
7823 unsigned NumSelIdents = SelIdents.size();
7836 if (!AllowSameLength && NumSelIdents && NumSelIdents == Sel.
getNumArgs())
7839 for (
unsigned I = 0; I != NumSelIdents; ++I)
7849 bool AllowSameLength =
true) {
7883 ResultBuilder &Results,
bool InOriginalClass =
true,
7884 bool IsRootClass =
false) {
7888 IsRootClass = IsRootClass || (IFace && !IFace->
getSuperClass());
7892 if (M->isInstanceMethod() == WantInstanceMethods ||
7893 (IsRootClass && !WantInstanceMethods)) {
7899 if (!Selectors.insert(M->getSelector()).second)
7903 Result(M, Results.getBasePriority(M), std::nullopt);
7904 R.StartParameter = SelIdents.size();
7905 R.AllParametersAreInformative = (WantKind !=
MK_Any);
7906 if (!InOriginalClass)
7908 Results.MaybeAddResult(R, CurContext);
7913 if (
const auto *Protocol = dyn_cast<ObjCProtocolDecl>(Container)) {
7914 if (Protocol->hasDefinition()) {
7916 Protocol->getReferencedProtocols();
7918 E = Protocols.
end();
7920 AddObjCMethods(*I, WantInstanceMethods, WantKind, SelIdents, CurContext,
7921 Selectors, AllowSameLength, Results,
false, IsRootClass);
7930 AddObjCMethods(I, WantInstanceMethods, WantKind, SelIdents, CurContext,
7931 Selectors, AllowSameLength, Results,
false, IsRootClass);
7935 AddObjCMethods(CatDecl, WantInstanceMethods, WantKind, SelIdents,
7936 CurContext, Selectors, AllowSameLength, Results,
7937 InOriginalClass, IsRootClass);
7941 CatDecl->getReferencedProtocols();
7943 E = Protocols.
end();
7945 AddObjCMethods(*I, WantInstanceMethods, WantKind, SelIdents, CurContext,
7946 Selectors, AllowSameLength, Results,
false, IsRootClass);
7950 AddObjCMethods(Impl, WantInstanceMethods, WantKind, SelIdents, CurContext,
7951 Selectors, AllowSameLength, Results, InOriginalClass,
7959 SelIdents, CurContext, Selectors, AllowSameLength, Results,
7964 AddObjCMethods(Impl, WantInstanceMethods, WantKind, SelIdents, CurContext,
7965 Selectors, AllowSameLength, Results, InOriginalClass,
7972 dyn_cast_or_null<ObjCInterfaceDecl>(
SemaRef.CurContext);
7975 dyn_cast_or_null<ObjCCategoryDecl>(
SemaRef.CurContext))
7976 Class = Category->getClassInterface();
7986 Results.EnterNewScope();
7992 Results.ExitScope();
7994 Results.getCompletionContext(), Results.data(),
8001 dyn_cast_or_null<ObjCInterfaceDecl>(
SemaRef.CurContext);
8004 dyn_cast_or_null<ObjCCategoryDecl>(
SemaRef.CurContext))
8005 Class = Category->getClassInterface();
8015 Results.EnterNewScope();
8022 Results.ExitScope();
8024 Results.getCompletionContext(), Results.data(),
8033 Results.EnterNewScope();
8036 bool AddedInOut =
false;
8039 Results.AddResult(
"in");
8040 Results.AddResult(
"inout");
8045 Results.AddResult(
"out");
8047 Results.AddResult(
"inout");
8052 Results.AddResult(
"bycopy");
8053 Results.AddResult(
"byref");
8054 Results.AddResult(
"oneway");
8057 Results.AddResult(
"nonnull");
8058 Results.AddResult(
"nullable");
8059 Results.AddResult(
"null_unspecified");
8067 SemaRef.PP.isMacroDefined(
"IBAction")) {
8069 Results.getCodeCompletionTUInfo(),
8071 Builder.AddTypedTextChunk(
"IBAction");
8073 Builder.AddPlaceholderChunk(
"selector");
8076 Builder.AddTextChunk(
"id");
8078 Builder.AddTextChunk(
"sender");
8089 Results.ExitScope();
8092 Results.setFilter(&ResultBuilder::IsOrdinaryNonValueName);
8093 CodeCompletionDeclConsumer Consumer(Results,
SemaRef.CurContext);
8102 Results.getCompletionContext(), Results.data(),
8111 auto *Msg = dyn_cast_or_null<ObjCMessageExpr>(E);
8129 switch (Msg->getReceiverKind()) {
8133 IFace = ObjType->getInterface();
8137 QualType T = Msg->getInstanceReceiver()->getType();
8139 IFace = Ptr->getInterfaceDecl();
8152 if (Method->isInstanceMethod())
8153 return llvm::StringSwitch<ObjCInterfaceDecl *>(Id->
getName())
8154 .Case(
"retain", IFace)
8155 .Case(
"strong", IFace)
8156 .Case(
"autorelease", IFace)
8157 .Case(
"copy", IFace)
8158 .Case(
"copyWithZone", IFace)
8159 .Case(
"mutableCopy", IFace)
8160 .Case(
"mutableCopyWithZone", IFace)
8161 .Case(
"awakeFromCoder", IFace)
8162 .Case(
"replacementObjectFromCoder", IFace)
8163 .Case(
"class", IFace)
8164 .Case(
"classForCoder", IFace)
8165 .Case(
"superclass", Super)
8168 return llvm::StringSwitch<ObjCInterfaceDecl *>(Id->
getName())
8170 .Case(
"alloc", IFace)
8171 .Case(
"allocWithZone", IFace)
8172 .Case(
"class", IFace)
8173 .Case(
"superclass", Super)
8193static ObjCMethodDecl *
8196 ResultBuilder &Results) {
8207 while ((Class = Class->getSuperClass()) && !SuperMethod) {
8209 SuperMethod = Class->getMethod(CurMethod->
getSelector(),
8214 for (
const auto *Cat : Class->known_categories()) {
8215 if ((SuperMethod = Cat->getMethod(CurMethod->
getSelector(),
8233 CurP != CurPEnd; ++CurP, ++SuperP) {
8236 (*SuperP)->getType()))
8240 if (!(*CurP)->getIdentifier())
8246 Results.getCodeCompletionTUInfo());
8250 Results.getCompletionContext().getBaseType(), Builder);
8253 if (NeedSuperKeyword) {
8254 Builder.AddTypedTextChunk(
"super");
8260 if (NeedSuperKeyword)
8261 Builder.AddTextChunk(
8264 Builder.AddTypedTextChunk(
8268 for (
unsigned I = 0, N = Sel.
getNumArgs(); I != N; ++I, ++CurP) {
8269 if (I > SelIdents.size())
8272 if (I < SelIdents.size())
8273 Builder.AddInformativeChunk(
8275 else if (NeedSuperKeyword || I > SelIdents.size()) {
8276 Builder.AddTextChunk(
8278 Builder.AddPlaceholderChunk(Builder.getAllocator().CopyString(
8279 (*CurP)->getIdentifier()->getName()));
8281 Builder.AddTypedTextChunk(
8283 Builder.AddPlaceholderChunk(Builder.getAllocator().CopyString(
8284 (*CurP)->getIdentifier()->getName()));
8296 ResultBuilder Results(
8301 ? &ResultBuilder::IsObjCMessageReceiverOrLambdaCapture
8302 : &ResultBuilder::IsObjCMessageReceiver);
8304 CodeCompletionDeclConsumer Consumer(Results,
SemaRef.CurContext);
8305 Results.EnterNewScope();
8314 if (Iface->getSuperClass()) {
8315 Results.AddResult(
Result(
"super"));
8323 Results.ExitScope();
8328 Results.getCompletionContext(), Results.data(),
8338 CDecl = CurMethod->getClassInterface();
8347 if (CurMethod->isInstanceMethod()) {
8352 AtArgumentExpression, CDecl);
8362 if ((CDecl = dyn_cast_or_null<ObjCInterfaceDecl>(ND))) {
8364 }
else if (
TypeDecl *TD = dyn_cast_or_null<TypeDecl>(ND)) {
8366 getASTContext().getTypeDeclType(TD)->getAs<ObjCObjectType>())
8367 CDecl = Iface->getInterface();
8377 SemaRef.ActOnIdExpression(S, SS, TemplateKWLoc,
id,
8381 SelIdents, AtArgumentExpression);
8391 AtArgumentExpression,
8398 unsigned NumSelIdents) {
8400 ASTContext &Context = Results.getSema().Context;
8404 Result *ResultsData = Results.data();
8405 for (
unsigned I = 0, N = Results.size(); I != N; ++I) {
8406 Result &R = ResultsData[I];
8407 if (R.Kind == Result::RK_Declaration &&
8409 if (R.Priority <= BestPriority) {
8411 if (NumSelIdents <= Method->param_size()) {
8413 Method->parameters()[NumSelIdents - 1]->getType();
8414 if (R.Priority < BestPriority || PreferredType.
isNull()) {
8415 BestPriority = R.Priority;
8416 PreferredType = MyPreferredType;
8417 }
else if (!Context.hasSameUnqualifiedType(PreferredType,
8426 return PreferredType;
8432 bool AtArgumentExpression,
bool IsSuper,
8433 ResultBuilder &Results) {
8448 Results.EnterNewScope();
8455 Results.Ignore(SuperMethod);
8461 Results.setPreferredSelector(CurMethod->getSelector());
8466 Selectors, AtArgumentExpression, Results);
8473 for (uint32_t I = 0,
8484 for (SemaObjC::GlobalMethodPool::iterator
8489 MethList && MethList->getMethod(); MethList = MethList->getNext()) {
8493 Result R(MethList->getMethod(),
8494 Results.getBasePriority(MethList->getMethod()),
8496 R.StartParameter = SelIdents.size();
8497 R.AllParametersAreInformative =
false;
8498 Results.MaybeAddResult(R, SemaRef.
CurContext);
8503 Results.ExitScope();
8508 bool AtArgumentExpression,
bool IsSuper) {
8512 ResultBuilder Results(
8519 AtArgumentExpression, IsSuper, Results);
8526 if (AtArgumentExpression) {
8529 if (PreferredType.
isNull())
8537 Results.getCompletionContext(), Results.data(),
8558 RecExpr = Conv.
get();
8562 : Super ? Context.getObjCObjectPointerType(
8563 Context.getObjCInterfaceType(Super))
8564 : Context.getObjCIdType();
8574 AtArgumentExpression, Super);
8577 Context.getObjCObjectPointerType(Context.getObjCInterfaceType(IFace));
8582 RecExpr = Conv.
get();
8583 ReceiverType = RecExpr->
getType();
8588 ResultBuilder Results(
8592 ReceiverType, SelIdents));
8594 Results.EnterNewScope();
8601 Results.Ignore(SuperMethod);
8607 Results.setPreferredSelector(CurMethod->getSelector());
8620 Selectors, AtArgumentExpression, Results);
8627 for (
auto *I : QualID->quals())
8629 AtArgumentExpression, Results);
8636 SemaRef.CurContext, Selectors, AtArgumentExpression,
8640 for (
auto *I : IFacePtr->quals())
8642 AtArgumentExpression, Results);
8652 for (uint32_t I = 0,
8653 N =
SemaRef.ExternalSource->GetNumExternalSelectors();
8659 SemaRef.ObjC().ReadMethodPool(Sel);
8663 for (SemaObjC::GlobalMethodPool::iterator
8664 M =
SemaRef.ObjC().MethodPool.begin(),
8665 MEnd =
SemaRef.ObjC().MethodPool.end();
8668 MethList && MethList->getMethod(); MethList = MethList->getNext()) {
8672 if (!Selectors.insert(MethList->getMethod()->getSelector()).second)
8675 Result R(MethList->getMethod(),
8676 Results.getBasePriority(MethList->getMethod()),
8678 R.StartParameter = SelIdents.size();
8679 R.AllParametersAreInformative =
false;
8680 Results.MaybeAddResult(R,
SemaRef.CurContext);
8684 Results.ExitScope();
8691 if (AtArgumentExpression) {
8694 if (PreferredType.
isNull())
8702 Results.getCompletionContext(), Results.data(),
8709 Data.ObjCCollection =
true;
8715 Data.IgnoreDecls.push_back(*I);
8727 for (uint32_t I = 0, N =
SemaRef.ExternalSource->GetNumExternalSelectors();
8733 SemaRef.ObjC().ReadMethodPool(Sel);
8740 Results.EnterNewScope();
8741 for (SemaObjC::GlobalMethodPool::iterator
8742 M =
SemaRef.ObjC().MethodPool.begin(),
8743 MEnd =
SemaRef.ObjC().MethodPool.end();
8751 Results.getCodeCompletionTUInfo());
8753 Builder.AddTypedTextChunk(
8755 Results.AddResult(Builder.TakeString());
8759 std::string Accumulator;
8760 for (
unsigned I = 0, N = Sel.
getNumArgs(); I != N; ++I) {
8761 if (I == SelIdents.size()) {
8762 if (!Accumulator.empty()) {
8763 Builder.AddInformativeChunk(
8764 Builder.getAllocator().CopyString(Accumulator));
8765 Accumulator.clear();
8772 Builder.AddTypedTextChunk(Builder.getAllocator().CopyString(Accumulator));
8773 Results.AddResult(Builder.TakeString());
8775 Results.ExitScope();
8778 Results.getCompletionContext(), Results.data(),
8785 bool OnlyForwardDeclarations,
8786 ResultBuilder &Results) {
8789 for (
const auto *D : Ctx->
decls()) {
8791 if (
const auto *Proto = dyn_cast<ObjCProtocolDecl>(D))
8792 if (!OnlyForwardDeclarations || !Proto->hasDefinition())
8793 Results.AddResult(
Result(Proto, Results.getBasePriority(Proto),
8795 CurContext,
nullptr,
false);
8806 Results.EnterNewScope();
8813 Pair.getIdentifierInfo(), Pair.getLoc()))
8814 Results.Ignore(Protocol);
8818 SemaRef.CurContext,
false, Results);
8820 Results.ExitScope();
8824 Results.getCompletionContext(), Results.data(),
8834 Results.EnterNewScope();
8838 SemaRef.CurContext,
true, Results);
8840 Results.ExitScope();
8844 Results.getCompletionContext(), Results.data(),
8851 bool OnlyForwardDeclarations,
8852 bool OnlyUnimplemented,
8853 ResultBuilder &Results) {
8856 for (
const auto *D : Ctx->
decls()) {
8858 if (
const auto *Class = dyn_cast<ObjCInterfaceDecl>(D))
8859 if ((!OnlyForwardDeclarations || !Class->hasDefinition()) &&
8860 (!OnlyUnimplemented || !Class->getImplementation()))
8861 Results.AddResult(
Result(Class, Results.getBasePriority(Class),
8863 CurContext,
nullptr,
false);
8871 Results.EnterNewScope();
8876 SemaRef.CurContext,
false,
false, Results);
8879 Results.ExitScope();
8882 Results.getCompletionContext(), Results.data(),
8890 Results.EnterNewScope();
8895 SemaRef.CurContext,
false,
false, Results);
8898 Results.ExitScope();
8901 Results.getCompletionContext(), Results.data(),
8910 Results.EnterNewScope();
8916 Results.Ignore(CurClass);
8921 SemaRef.CurContext,
false,
false, Results);
8924 Results.ExitScope();
8927 Results.getCompletionContext(), Results.data(),
8935 Results.EnterNewScope();
8940 SemaRef.CurContext,
false,
true, Results);
8943 Results.ExitScope();
8946 Results.getCompletionContext(), Results.data(),
8964 dyn_cast_or_null<ObjCInterfaceDecl>(CurClass)) {
8965 for (
const auto *Cat :
Class->visible_categories())
8966 CategoryNames.insert(Cat->getIdentifier());
8970 Results.EnterNewScope();
8972 for (
const auto *D : TU->
decls())
8973 if (
const auto *Category = dyn_cast<ObjCCategoryDecl>(D))
8974 if (CategoryNames.insert(Category->getIdentifier()).second)
8975 Results.AddResult(
Result(Category, Results.getBasePriority(Category),
8977 SemaRef.CurContext,
nullptr,
false);
8978 Results.ExitScope();
8981 Results.getCompletionContext(), Results.data(),
9006 Results.EnterNewScope();
9007 bool IgnoreImplemented =
true;
9009 for (
const auto *Cat :
Class->visible_categories()) {
9010 if ((!IgnoreImplemented || !Cat->getImplementation()) &&
9011 CategoryNames.insert(Cat->getIdentifier()).second)
9012 Results.AddResult(
Result(Cat, Results.getBasePriority(Cat),
9014 SemaRef.CurContext,
nullptr,
false);
9018 IgnoreImplemented =
false;
9020 Results.ExitScope();
9023 Results.getCompletionContext(), Results.data(),
9034 dyn_cast_or_null<ObjCContainerDecl>(
SemaRef.CurContext);
9041 for (
const auto *D : Container->
decls())
9042 if (
const auto *PropertyImpl = dyn_cast<ObjCPropertyImplDecl>(D))
9043 Results.Ignore(PropertyImpl->getPropertyDecl());
9047 Results.EnterNewScope();
9049 dyn_cast<ObjCImplementationDecl>(Container))
9052 AddedProperties, Results);
9056 false,
false,
SemaRef.CurContext,
9057 AddedProperties, Results);
9058 Results.ExitScope();
9061 Results.getCompletionContext(), Results.data(),
9074 dyn_cast_or_null<ObjCContainerDecl>(
SemaRef.CurContext);
9082 dyn_cast<ObjCImplementationDecl>(Container))
9083 Class = ClassImpl->getClassInterface();
9087 ->getClassInterface();
9095 Property->getType().getNonReferenceType().getUnqualifiedType();
9098 Results.setPreferredType(PropertyType);
9103 Results.EnterNewScope();
9104 bool SawSimilarlyNamedIvar =
false;
9105 std::string NameWithPrefix;
9106 NameWithPrefix +=
'_';
9107 NameWithPrefix += PropertyName->getName();
9108 std::string NameWithSuffix = PropertyName->getName().str();
9109 NameWithSuffix +=
'_';
9112 Ivar = Ivar->getNextIvar()) {
9113 Results.AddResult(
Result(Ivar, Results.getBasePriority(Ivar),
9115 SemaRef.CurContext,
nullptr,
false);
9119 if ((PropertyName == Ivar->getIdentifier() ||
9120 NameWithPrefix == Ivar->getName() ||
9121 NameWithSuffix == Ivar->getName())) {
9122 SawSimilarlyNamedIvar =
true;
9126 if (Results.size() &&
9127 Results.data()[Results.size() - 1].Kind ==
9129 Results.data()[Results.size() - 1].Declaration == Ivar)
9130 Results.data()[Results.size() - 1].Priority--;
9135 if (!SawSimilarlyNamedIvar) {
9147 Builder.AddTypedTextChunk(Allocator.
CopyString(NameWithPrefix));
9152 Results.ExitScope();
9155 Results.getCompletionContext(), Results.data(),
9162 llvm::PointerIntPair<ObjCMethodDecl *, 1, bool>>
9171 std::optional<bool> WantInstanceMethods,
9174 bool InOriginalClass =
true) {
9177 if (!IFace->hasDefinition())
9180 IFace = IFace->getDefinition();
9184 IFace->getReferencedProtocols();
9186 E = Protocols.
end();
9189 KnownMethods, InOriginalClass);
9192 for (
auto *Cat : IFace->visible_categories()) {
9194 KnownMethods,
false);
9198 if (IFace->getSuperClass())
9200 WantInstanceMethods, ReturnType, KnownMethods,
9207 Category->getReferencedProtocols();
9209 E = Protocols.
end();
9212 KnownMethods, InOriginalClass);
9215 if (InOriginalClass && Category->getClassInterface())
9217 WantInstanceMethods, ReturnType, KnownMethods,
9223 if (!Protocol->hasDefinition())
9225 Protocol = Protocol->getDefinition();
9226 Container = Protocol;
9230 Protocol->getReferencedProtocols();
9232 E = Protocols.
end();
9235 KnownMethods,
false);
9241 for (
auto *M : Container->
methods()) {
9242 if (!WantInstanceMethods || M->isInstanceMethod() == *WantInstanceMethods) {
9243 if (!ReturnType.
isNull() &&
9244 !Context.hasSameUnqualifiedType(ReturnType, M->getReturnType()))
9247 KnownMethods[M->getSelector()] =
9248 KnownMethodsMap::mapped_type(M, InOriginalClass);
9262 Builder.AddTextChunk(Builder.getAllocator().CopyString(Quals));
9263 Builder.AddTextChunk(
9274 if (Class->getIdentifier() && Class->getIdentifier()->getName() == Name)
9283 bool IsInstanceMethod,
9286 ResultBuilder &Results) {
9288 if (!PropName || PropName->
getLength() == 0)
9306 const char *CopiedKey;
9309 : Allocator(Allocator), Key(Key), CopiedKey(
nullptr) {}
9311 operator const char *() {
9315 return CopiedKey = Allocator.
CopyString(Key);
9317 } Key(Allocator, PropName->
getName());
9320 std::string UpperKey = std::string(PropName->
getName());
9321 if (!UpperKey.empty())
9324 bool ReturnTypeMatchesProperty =
9327 Property->getType());
9328 bool ReturnTypeMatchesVoid = ReturnType.
isNull() || ReturnType->
isVoidType();
9331 if (IsInstanceMethod &&
9333 ReturnTypeMatchesProperty && !Property->getGetterMethodDecl()) {
9338 Builder.AddTypedTextChunk(Key);
9345 if (IsInstanceMethod &&
9346 ((!ReturnType.
isNull() &&
9348 (ReturnType.
isNull() && (Property->getType()->isIntegerType() ||
9349 Property->getType()->isBooleanType())))) {
9350 std::string SelectorName = (Twine(
"is") + UpperKey).str();
9354 if (ReturnType.
isNull()) {
9356 Builder.AddTextChunk(
"BOOL");
9367 if (IsInstanceMethod && ReturnTypeMatchesVoid &&
9368 !Property->getSetterMethodDecl()) {
9369 std::string SelectorName = (Twine(
"set") + UpperKey).str();
9371 if (KnownSelectors.insert(Selectors.
getUnarySelector(SelectorId)).second) {
9372 if (ReturnType.
isNull()) {
9374 Builder.AddTextChunk(
"void");
9378 Builder.AddTypedTextChunk(
9382 Builder.AddTextChunk(Key);
9393 if (
const auto *ObjCPointer =
9418 if (IsInstanceMethod &&
9420 std::string SelectorName = (Twine(
"countOf") + UpperKey).str();
9424 if (ReturnType.
isNull()) {
9426 Builder.AddTextChunk(
"NSUInteger");
9432 Result(Builder.TakeString(),
9433 std::min(IndexedGetterPriority, UnorderedGetterPriority),
9440 if (IsInstanceMethod &&
9442 std::string SelectorName = (Twine(
"objectIn") + UpperKey +
"AtIndex").str();
9444 if (KnownSelectors.insert(Selectors.
getUnarySelector(SelectorId)).second) {
9445 if (ReturnType.
isNull()) {
9447 Builder.AddTextChunk(
"id");
9451 Builder.AddTypedTextChunk(Allocator.
CopyString(SelectorName +
":"));
9453 Builder.AddTextChunk(
"NSUInteger");
9455 Builder.AddTextChunk(
"index");
9456 Results.AddResult(
Result(Builder.TakeString(), IndexedGetterPriority,
9462 if (IsInstanceMethod &&
9469 std::string SelectorName = (Twine(Property->getName()) +
"AtIndexes").str();
9471 if (KnownSelectors.insert(Selectors.
getUnarySelector(SelectorId)).second) {
9472 if (ReturnType.
isNull()) {
9474 Builder.AddTextChunk(
"NSArray *");
9478 Builder.AddTypedTextChunk(Allocator.
CopyString(SelectorName +
":"));
9480 Builder.AddTextChunk(
"NSIndexSet *");
9482 Builder.AddTextChunk(
"indexes");
9483 Results.AddResult(
Result(Builder.TakeString(), IndexedGetterPriority,
9489 if (IsInstanceMethod && ReturnTypeMatchesVoid) {
9490 std::string SelectorName = (Twine(
"get") + UpperKey).str();
9491 const IdentifierInfo *SelectorIds[2] = {&Context.Idents.get(SelectorName),
9492 &Context.Idents.get(
"range")};
9494 if (KnownSelectors.insert(Selectors.
getSelector(2, SelectorIds)).second) {
9495 if (ReturnType.
isNull()) {
9497 Builder.AddTextChunk(
"void");
9501 Builder.AddTypedTextChunk(Allocator.
CopyString(SelectorName +
":"));
9503 Builder.AddPlaceholderChunk(
"object-type");
9504 Builder.AddTextChunk(
" **");
9506 Builder.AddTextChunk(
"buffer");
9508 Builder.AddTypedTextChunk(
"range:");
9510 Builder.AddTextChunk(
"NSRange");
9512 Builder.AddTextChunk(
"inRange");
9513 Results.AddResult(
Result(Builder.TakeString(), IndexedGetterPriority,
9521 if (IsInstanceMethod && ReturnTypeMatchesVoid) {
9522 std::string SelectorName = (Twine(
"in") + UpperKey +
"AtIndex").str();
9523 const IdentifierInfo *SelectorIds[2] = {&Context.Idents.get(
"insertObject"),
9524 &Context.Idents.get(SelectorName)};
9526 if (KnownSelectors.insert(Selectors.
getSelector(2, SelectorIds)).second) {
9527 if (ReturnType.
isNull()) {
9529 Builder.AddTextChunk(
"void");
9533 Builder.AddTypedTextChunk(
"insertObject:");
9535 Builder.AddPlaceholderChunk(
"object-type");
9536 Builder.AddTextChunk(
" *");
9538 Builder.AddTextChunk(
"object");
9540 Builder.AddTypedTextChunk(Allocator.
CopyString(SelectorName +
":"));
9542 Builder.AddPlaceholderChunk(
"NSUInteger");
9544 Builder.AddTextChunk(
"index");
9545 Results.AddResult(
Result(Builder.TakeString(), IndexedSetterPriority,
9551 if (IsInstanceMethod && ReturnTypeMatchesVoid) {
9552 std::string SelectorName = (Twine(
"insert") + UpperKey).str();
9553 const IdentifierInfo *SelectorIds[2] = {&Context.Idents.get(SelectorName),
9554 &Context.Idents.get(
"atIndexes")};
9556 if (KnownSelectors.insert(Selectors.
getSelector(2, SelectorIds)).second) {
9557 if (ReturnType.
isNull()) {
9559 Builder.AddTextChunk(
"void");
9563 Builder.AddTypedTextChunk(Allocator.
CopyString(SelectorName +
":"));
9565 Builder.AddTextChunk(
"NSArray *");
9567 Builder.AddTextChunk(
"array");
9569 Builder.AddTypedTextChunk(
"atIndexes:");
9571 Builder.AddPlaceholderChunk(
"NSIndexSet *");
9573 Builder.AddTextChunk(
"indexes");
9574 Results.AddResult(
Result(Builder.TakeString(), IndexedSetterPriority,
9580 if (IsInstanceMethod && ReturnTypeMatchesVoid) {
9581 std::string SelectorName =
9582 (Twine(
"removeObjectFrom") + UpperKey +
"AtIndex").str();
9583 const IdentifierInfo *SelectorId = &Context.Idents.get(SelectorName);
9584 if (KnownSelectors.insert(Selectors.
getUnarySelector(SelectorId)).second) {
9585 if (ReturnType.
isNull()) {
9587 Builder.AddTextChunk(
"void");
9591 Builder.AddTypedTextChunk(Allocator.
CopyString(SelectorName +
":"));
9593 Builder.AddTextChunk(
"NSUInteger");
9595 Builder.AddTextChunk(
"index");
9596 Results.AddResult(
Result(Builder.TakeString(), IndexedSetterPriority,
9602 if (IsInstanceMethod && ReturnTypeMatchesVoid) {
9603 std::string SelectorName = (Twine(
"remove") + UpperKey +
"AtIndexes").str();
9604 const IdentifierInfo *SelectorId = &Context.Idents.get(SelectorName);
9605 if (KnownSelectors.insert(Selectors.
getUnarySelector(SelectorId)).second) {
9606 if (ReturnType.
isNull()) {
9608 Builder.AddTextChunk(
"void");
9612 Builder.AddTypedTextChunk(Allocator.
CopyString(SelectorName +
":"));
9614 Builder.AddTextChunk(
"NSIndexSet *");
9616 Builder.AddTextChunk(
"indexes");
9617 Results.AddResult(
Result(Builder.TakeString(), IndexedSetterPriority,
9623 if (IsInstanceMethod && ReturnTypeMatchesVoid) {
9624 std::string SelectorName =
9625 (Twine(
"replaceObjectIn") + UpperKey +
"AtIndex").str();
9626 const IdentifierInfo *SelectorIds[2] = {&Context.Idents.get(SelectorName),
9627 &Context.Idents.get(
"withObject")};
9629 if (KnownSelectors.insert(Selectors.
getSelector(2, SelectorIds)).second) {
9630 if (ReturnType.
isNull()) {
9632 Builder.AddTextChunk(
"void");
9636 Builder.AddTypedTextChunk(Allocator.
CopyString(SelectorName +
":"));
9638 Builder.AddPlaceholderChunk(
"NSUInteger");
9640 Builder.AddTextChunk(
"index");
9642 Builder.AddTypedTextChunk(
"withObject:");
9644 Builder.AddTextChunk(
"id");
9646 Builder.AddTextChunk(
"object");
9647 Results.AddResult(
Result(Builder.TakeString(), IndexedSetterPriority,
9653 if (IsInstanceMethod && ReturnTypeMatchesVoid) {
9654 std::string SelectorName1 =
9655 (Twine(
"replace") + UpperKey +
"AtIndexes").str();
9656 std::string SelectorName2 = (Twine(
"with") + UpperKey).str();
9657 const IdentifierInfo *SelectorIds[2] = {&Context.Idents.get(SelectorName1),
9658 &Context.Idents.get(SelectorName2)};
9660 if (KnownSelectors.insert(Selectors.
getSelector(2, SelectorIds)).second) {
9661 if (ReturnType.
isNull()) {
9663 Builder.AddTextChunk(
"void");
9667 Builder.AddTypedTextChunk(Allocator.
CopyString(SelectorName1 +
":"));
9669 Builder.AddPlaceholderChunk(
"NSIndexSet *");
9671 Builder.AddTextChunk(
"indexes");
9673 Builder.AddTypedTextChunk(Allocator.
CopyString(SelectorName2 +
":"));
9675 Builder.AddTextChunk(
"NSArray *");
9677 Builder.AddTextChunk(
"array");
9678 Results.AddResult(
Result(Builder.TakeString(), IndexedSetterPriority,
9685 if (IsInstanceMethod &&
9691 ->
getName() ==
"NSEnumerator"))) {
9692 std::string SelectorName = (Twine(
"enumeratorOf") + UpperKey).str();
9693 const IdentifierInfo *SelectorId = &Context.Idents.get(SelectorName);
9696 if (ReturnType.
isNull()) {
9698 Builder.AddTextChunk(
"NSEnumerator *");
9702 Builder.AddTypedTextChunk(Allocator.
CopyString(SelectorName));
9703 Results.AddResult(
Result(Builder.TakeString(), UnorderedGetterPriority,
9709 if (IsInstanceMethod &&
9711 std::string SelectorName = (Twine(
"memberOf") + UpperKey).str();
9712 const IdentifierInfo *SelectorId = &Context.Idents.get(SelectorName);
9713 if (KnownSelectors.insert(Selectors.
getUnarySelector(SelectorId)).second) {
9714 if (ReturnType.
isNull()) {
9716 Builder.AddPlaceholderChunk(
"object-type");
9717 Builder.AddTextChunk(
" *");
9721 Builder.AddTypedTextChunk(Allocator.
CopyString(SelectorName +
":"));
9723 if (ReturnType.
isNull()) {
9724 Builder.AddPlaceholderChunk(
"object-type");
9725 Builder.AddTextChunk(
" *");
9728 ReturnType, Context, Policy, Builder.getAllocator()));
9731 Builder.AddTextChunk(
"object");
9732 Results.AddResult(
Result(Builder.TakeString(), UnorderedGetterPriority,
9739 if (IsInstanceMethod && ReturnTypeMatchesVoid) {
9740 std::string SelectorName =
9741 (Twine(
"add") + UpperKey + Twine(
"Object")).str();
9742 const IdentifierInfo *SelectorId = &Context.Idents.get(SelectorName);
9743 if (KnownSelectors.insert(Selectors.
getUnarySelector(SelectorId)).second) {
9744 if (ReturnType.
isNull()) {
9746 Builder.AddTextChunk(
"void");
9750 Builder.AddTypedTextChunk(Allocator.
CopyString(SelectorName +
":"));
9752 Builder.AddPlaceholderChunk(
"object-type");
9753 Builder.AddTextChunk(
" *");
9755 Builder.AddTextChunk(
"object");
9756 Results.AddResult(
Result(Builder.TakeString(), UnorderedSetterPriority,
9762 if (IsInstanceMethod && ReturnTypeMatchesVoid) {
9763 std::string SelectorName = (Twine(
"add") + UpperKey).str();
9764 const IdentifierInfo *SelectorId = &Context.Idents.get(SelectorName);
9765 if (KnownSelectors.insert(Selectors.
getUnarySelector(SelectorId)).second) {
9766 if (ReturnType.
isNull()) {
9768 Builder.AddTextChunk(
"void");
9772 Builder.AddTypedTextChunk(Allocator.
CopyString(SelectorName +
":"));
9774 Builder.AddTextChunk(
"NSSet *");
9776 Builder.AddTextChunk(
"objects");
9777 Results.AddResult(
Result(Builder.TakeString(), UnorderedSetterPriority,
9783 if (IsInstanceMethod && ReturnTypeMatchesVoid) {
9784 std::string SelectorName =
9785 (Twine(
"remove") + UpperKey + Twine(
"Object")).str();
9786 const IdentifierInfo *SelectorId = &Context.Idents.get(SelectorName);
9787 if (KnownSelectors.insert(Selectors.
getUnarySelector(SelectorId)).second) {
9788 if (ReturnType.
isNull()) {
9790 Builder.AddTextChunk(
"void");
9794 Builder.AddTypedTextChunk(Allocator.
CopyString(SelectorName +
":"));
9796 Builder.AddPlaceholderChunk(
"object-type");
9797 Builder.AddTextChunk(
" *");
9799 Builder.AddTextChunk(
"object");
9800 Results.AddResult(
Result(Builder.TakeString(), UnorderedSetterPriority,
9806 if (IsInstanceMethod && ReturnTypeMatchesVoid) {
9807 std::string SelectorName = (Twine(
"remove") + UpperKey).str();
9808 const IdentifierInfo *SelectorId = &Context.Idents.get(SelectorName);
9809 if (KnownSelectors.insert(Selectors.
getUnarySelector(SelectorId)).second) {
9810 if (ReturnType.
isNull()) {
9812 Builder.AddTextChunk(
"void");
9816 Builder.AddTypedTextChunk(Allocator.
CopyString(SelectorName +
":"));
9818 Builder.AddTextChunk(
"NSSet *");
9820 Builder.AddTextChunk(
"objects");
9821 Results.AddResult(
Result(Builder.TakeString(), UnorderedSetterPriority,
9827 if (IsInstanceMethod && ReturnTypeMatchesVoid) {
9828 std::string SelectorName = (Twine(
"intersect") + UpperKey).str();
9829 const IdentifierInfo *SelectorId = &Context.Idents.get(SelectorName);
9830 if (KnownSelectors.insert(Selectors.
getUnarySelector(SelectorId)).second) {
9831 if (ReturnType.
isNull()) {
9833 Builder.AddTextChunk(
"void");
9837 Builder.AddTypedTextChunk(Allocator.
CopyString(SelectorName +
":"));
9839 Builder.AddTextChunk(
"NSSet *");
9841 Builder.AddTextChunk(
"objects");
9842 Results.AddResult(
Result(Builder.TakeString(), UnorderedSetterPriority,
9849 if (!IsInstanceMethod &&
9856 std::string SelectorName =
9857 (Twine(
"keyPathsForValuesAffecting") + UpperKey).str();
9858 const IdentifierInfo *SelectorId = &Context.Idents.get(SelectorName);
9861 if (ReturnType.
isNull()) {
9863 Builder.AddTextChunk(
"NSSet<NSString *> *");
9867 Builder.AddTypedTextChunk(Allocator.
CopyString(SelectorName));
9874 if (!IsInstanceMethod &&
9877 std::string SelectorName =
9878 (Twine(
"automaticallyNotifiesObserversOf") + UpperKey).str();
9879 const IdentifierInfo *SelectorId = &Context.Idents.get(SelectorName);
9882 if (ReturnType.
isNull()) {
9884 Builder.AddTextChunk(
"BOOL");
9888 Builder.AddTypedTextChunk(Allocator.
CopyString(SelectorName));
9896 Scope *S, std::optional<bool> IsInstanceMethod,
ParsedType ReturnTy) {
9901 Decl *IDecl =
nullptr;
9902 if (
SemaRef.CurContext->isObjCContainer()) {
9908 bool IsInImplementation =
false;
9909 if (
Decl *D = IDecl) {
9911 SearchDecl = Impl->getClassInterface();
9912 IsInImplementation =
true;
9914 dyn_cast<ObjCCategoryImplDecl>(D)) {
9915 SearchDecl = CatImpl->getCategoryDecl();
9916 IsInImplementation =
true;
9918 SearchDecl = dyn_cast<ObjCContainerDecl>(D);
9921 if (!SearchDecl && S) {
9923 SearchDecl = dyn_cast<ObjCContainerDecl>(DC);
9942 Results.EnterNewScope();
9944 for (KnownMethodsMap::iterator M = KnownMethods.begin(),
9945 MEnd = KnownMethods.end();
9949 Results.getCodeCompletionTUInfo());
9952 if (!IsInstanceMethod) {
9953 Builder.AddTextChunk(
Method->isInstanceMethod() ?
"-" :
"+");
9959 if (ReturnType.
isNull()) {
9960 QualType ResTy =
Method->getSendResultType().stripObjCKindOfType(Context);
9961 AttributedType::stripOuterNullability(ResTy);
9970 Builder.AddTypedTextChunk(
9976 PEnd =
Method->param_end();
9977 P != PEnd; (
void)++P, ++I) {
9980 Builder.AddTypedTextChunk(
9984 Builder.AddTypedTextChunk(
9992 ParamType = (*P)->getType();
9994 ParamType = (*P)->getOriginalType();
9997 AttributedType::stripOuterNullability(ParamType);
9999 Context, Policy, Builder);
10002 Builder.AddTextChunk(
10003 Builder.getAllocator().CopyString(Id->getName()));
10007 if (
Method->isVariadic()) {
10008 if (
Method->param_size() > 0)
10010 Builder.AddTextChunk(
"...");
10013 if (IsInImplementation && Results.includeCodePatterns()) {
10018 if (!
Method->getReturnType()->isVoidType()) {
10020 Builder.AddTextChunk(
"return");
10022 Builder.AddPlaceholderChunk(
"expression");
10025 Builder.AddPlaceholderChunk(
"statements");
10032 auto R =
Result(Builder.TakeString(),
Method, Priority);
10033 if (!M->second.getInt())
10035 Results.AddResult(std::move(R));
10040 if (Context.getLangOpts().ObjC) {
10042 Containers.push_back(SearchDecl);
10045 for (KnownMethodsMap::iterator M = KnownMethods.begin(),
10046 MEnd = KnownMethods.end();
10048 KnownSelectors.insert(M->first);
10053 IFace = Category->getClassInterface();
10058 if (IsInstanceMethod) {
10059 for (
unsigned I = 0, N = Containers.size(); I != N; ++I)
10060 for (
auto *P : Containers[I]->instance_properties())
10062 KnownSelectors, Results);
10066 Results.ExitScope();
10069 Results.getCompletionContext(), Results.data(),
10074 Scope *S,
bool IsInstanceMethod,
bool AtParameterName,
ParsedType ReturnTy,
10078 if (
SemaRef.ExternalSource) {
10079 for (uint32_t I = 0, N =
SemaRef.ExternalSource->GetNumExternalSelectors();
10085 SemaRef.ObjC().ReadMethodPool(Sel);
10096 Results.setPreferredType(
10097 SemaRef.GetTypeFromParser(ReturnTy).getNonReferenceType());
10099 Results.EnterNewScope();
10100 for (SemaObjC::GlobalMethodPool::iterator
10101 M =
SemaRef.ObjC().MethodPool.begin(),
10102 MEnd =
SemaRef.ObjC().MethodPool.end();
10104 for (
ObjCMethodList *MethList = IsInstanceMethod ? &M->second.first
10105 : &M->second.second;
10106 MethList && MethList->getMethod(); MethList = MethList->getNext()) {
10110 if (AtParameterName) {
10112 unsigned NumSelIdents = SelIdents.size();
10113 if (NumSelIdents &&
10114 NumSelIdents <= MethList->getMethod()->param_size()) {
10116 MethList->getMethod()->parameters()[NumSelIdents - 1];
10117 if (Param->getIdentifier()) {
10119 Results.getCodeCompletionTUInfo());
10120 Builder.AddTypedTextChunk(Builder.getAllocator().CopyString(
10121 Param->getIdentifier()->getName()));
10122 Results.AddResult(Builder.TakeString());
10129 Result R(MethList->getMethod(),
10130 Results.getBasePriority(MethList->getMethod()),
10132 R.StartParameter = SelIdents.size();
10133 R.AllParametersAreInformative =
false;
10134 R.DeclaringEntity =
true;
10135 Results.MaybeAddResult(R,
SemaRef.CurContext);
10139 Results.ExitScope();
10141 if (!AtParameterName && !SelIdents.empty() &&
10142 SelIdents.front()->getName().starts_with(
"init")) {
10143 for (
const auto &M :
SemaRef.PP.macros()) {
10144 if (M.first->getName() !=
"NS_DESIGNATED_INITIALIZER")
10146 Results.EnterNewScope();
10148 Results.getCodeCompletionTUInfo());
10149 Builder.AddTypedTextChunk(
10150 Builder.getAllocator().CopyString(M.first->getName()));
10153 Results.ExitScope();
10158 Results.getCompletionContext(), Results.data(),
10166 Results.EnterNewScope();
10170 Results.getCodeCompletionTUInfo());
10171 Builder.AddTypedTextChunk(
"if");
10173 Builder.AddPlaceholderChunk(
"condition");
10174 Results.AddResult(Builder.TakeString());
10177 Builder.AddTypedTextChunk(
"ifdef");
10179 Builder.AddPlaceholderChunk(
"macro");
10180 Results.AddResult(Builder.TakeString());
10183 Builder.AddTypedTextChunk(
"ifndef");
10185 Builder.AddPlaceholderChunk(
"macro");
10186 Results.AddResult(Builder.TakeString());
10188 if (InConditional) {
10190 Builder.AddTypedTextChunk(
"elif");
10192 Builder.AddPlaceholderChunk(
"condition");
10193 Results.AddResult(Builder.TakeString());
10196 Builder.AddTypedTextChunk(
"elifdef");
10198 Builder.AddPlaceholderChunk(
"macro");
10199 Results.AddResult(Builder.TakeString());
10202 Builder.AddTypedTextChunk(
"elifndef");
10204 Builder.AddPlaceholderChunk(
"macro");
10205 Results.AddResult(Builder.TakeString());
10208 Builder.AddTypedTextChunk(
"else");
10209 Results.AddResult(Builder.TakeString());
10212 Builder.AddTypedTextChunk(
"endif");
10213 Results.AddResult(Builder.TakeString());
10217 Builder.AddTypedTextChunk(
"include");
10219 Builder.AddTextChunk(
"\"");
10220 Builder.AddPlaceholderChunk(
"header");
10221 Builder.AddTextChunk(
"\"");
10222 Results.AddResult(Builder.TakeString());
10225 Builder.AddTypedTextChunk(
"include");
10227 Builder.AddTextChunk(
"<");
10228 Builder.AddPlaceholderChunk(
"header");
10229 Builder.AddTextChunk(
">");
10230 Results.AddResult(Builder.TakeString());
10233 Builder.AddTypedTextChunk(
"define");
10235 Builder.AddPlaceholderChunk(
"macro");
10236 Results.AddResult(Builder.TakeString());
10239 Builder.AddTypedTextChunk(
"define");
10241 Builder.AddPlaceholderChunk(
"macro");
10243 Builder.AddPlaceholderChunk(
"args");
10245 Results.AddResult(Builder.TakeString());
10248 Builder.AddTypedTextChunk(
"undef");
10250 Builder.AddPlaceholderChunk(
"macro");
10251 Results.AddResult(Builder.TakeString());
10254 Builder.AddTypedTextChunk(
"line");
10256 Builder.AddPlaceholderChunk(
"number");
10257 Results.AddResult(Builder.TakeString());
10260 Builder.AddTypedTextChunk(
"line");
10262 Builder.AddPlaceholderChunk(
"number");
10264 Builder.AddTextChunk(
"\"");
10265 Builder.AddPlaceholderChunk(
"filename");
10266 Builder.AddTextChunk(
"\"");
10267 Results.AddResult(Builder.TakeString());
10270 Builder.AddTypedTextChunk(
"error");
10272 Builder.AddPlaceholderChunk(
"message");
10273 Results.AddResult(Builder.TakeString());
10276 Builder.AddTypedTextChunk(
"pragma");
10278 Builder.AddPlaceholderChunk(
"arguments");
10279 Results.AddResult(Builder.TakeString());
10283 Builder.AddTypedTextChunk(
"import");
10285 Builder.AddTextChunk(
"\"");
10286 Builder.AddPlaceholderChunk(
"header");
10287 Builder.AddTextChunk(
"\"");
10288 Results.AddResult(Builder.TakeString());
10291 Builder.AddTypedTextChunk(
"import");
10293 Builder.AddTextChunk(
"<");
10294 Builder.AddPlaceholderChunk(
"header");
10295 Builder.AddTextChunk(
">");
10296 Results.AddResult(Builder.TakeString());
10300 Builder.AddTypedTextChunk(
"include_next");
10302 Builder.AddTextChunk(
"\"");
10303 Builder.AddPlaceholderChunk(
"header");
10304 Builder.AddTextChunk(
"\"");
10305 Results.AddResult(Builder.TakeString());
10308 Builder.AddTypedTextChunk(
"include_next");
10310 Builder.AddTextChunk(
"<");
10311 Builder.AddPlaceholderChunk(
"header");
10312 Builder.AddTextChunk(
">");
10313 Results.AddResult(Builder.TakeString());
10316 Builder.AddTypedTextChunk(
"warning");
10318 Builder.AddPlaceholderChunk(
"message");
10319 Results.AddResult(Builder.TakeString());
10323 Builder.AddTypedTextChunk(
"embed");
10325 Builder.AddTextChunk(
"\"");
10326 Builder.AddPlaceholderChunk(
"file");
10327 Builder.AddTextChunk(
"\"");
10328 Results.AddResult(Builder.TakeString());
10331 Builder.AddTypedTextChunk(
"embed");
10333 Builder.AddTextChunk(
"<");
10334 Builder.AddPlaceholderChunk(
"file");
10335 Builder.AddTextChunk(
">");
10336 Results.AddResult(Builder.TakeString());
10344 Results.ExitScope();
10347 Results.getCompletionContext(), Results.data(),
10366 Results.getCodeCompletionTUInfo());
10367 Results.EnterNewScope();
10369 MEnd =
SemaRef.PP.macro_end();
10371 Builder.AddTypedTextChunk(
10372 Builder.getAllocator().CopyString(M->first->getName()));
10376 Results.ExitScope();
10377 }
else if (IsDefinition) {
10382 Results.getCompletionContext(), Results.data(),
10395 Results.EnterNewScope();
10397 Results.getCodeCompletionTUInfo());
10398 Builder.AddTypedTextChunk(
"defined");
10401 Builder.AddPlaceholderChunk(
"macro");
10403 Results.AddResult(Builder.TakeString());
10404 Results.ExitScope();
10407 Results.getCompletionContext(), Results.data(),
10427 std::string RelDir = llvm::sys::path::convert_to_slash(Dir);
10430 llvm::sys::path::native(NativeRelDir);
10431 llvm::vfs::FileSystem &FS =
10432 SemaRef.getSourceManager().getFileManager().getVirtualFileSystem();
10437 llvm::DenseSet<StringRef> SeenResults;
10440 auto AddCompletion = [&](StringRef Filename,
bool IsDirectory) {
10443 TypedChunk.push_back(IsDirectory ?
'/' : Angled ?
'>' :
'"');
10444 auto R = SeenResults.insert(TypedChunk);
10446 const char *InternedTyped = Results.getAllocator().CopyString(TypedChunk);
10447 *R.first = InternedTyped;
10450 Builder.AddTypedTextChunk(InternedTyped);
10458 auto AddFilesFromIncludeDir = [&](StringRef IncludeDir,
10462 if (!NativeRelDir.empty()) {
10466 auto Begin = llvm::sys::path::begin(NativeRelDir);
10467 auto End = llvm::sys::path::end(NativeRelDir);
10469 llvm::sys::path::append(Dir, *Begin +
".framework",
"Headers");
10470 llvm::sys::path::append(Dir, ++Begin, End);
10472 llvm::sys::path::append(Dir, NativeRelDir);
10476 const StringRef &Dirname = llvm::sys::path::filename(Dir);
10477 const bool isQt = Dirname.starts_with(
"Qt") || Dirname ==
"ActiveQt";
10478 const bool ExtensionlessHeaders =
10479 IsSystem || isQt || Dir.ends_with(
".framework/Headers") ||
10480 IncludeDir.ends_with(
"/include") || IncludeDir.ends_with(
"\\include");
10481 std::error_code EC;
10482 unsigned Count = 0;
10483 for (
auto It = FS.dir_begin(Dir, EC);
10484 !EC && It != llvm::vfs::directory_iterator(); It.increment(EC)) {
10485 if (++Count == 2500)
10487 StringRef Filename = llvm::sys::path::filename(It->path());
10492 llvm::sys::fs::file_type
Type = It->type();
10493 if (
Type == llvm::sys::fs::file_type::symlink_file) {
10494 if (
auto FileStatus = FS.status(It->path()))
10495 Type = FileStatus->getType();
10498 case llvm::sys::fs::file_type::directory_file:
10502 NativeRelDir.empty() && !Filename.consume_back(
".framework"))
10505 AddCompletion(Filename,
true);
10507 case llvm::sys::fs::file_type::regular_file: {
10509 const bool IsHeader = Filename.ends_with_insensitive(
".h") ||
10510 Filename.ends_with_insensitive(
".hh") ||
10511 Filename.ends_with_insensitive(
".hpp") ||
10512 Filename.ends_with_insensitive(
".hxx") ||
10513 Filename.ends_with_insensitive(
".inc") ||
10514 (ExtensionlessHeaders && !Filename.contains(
'.'));
10517 AddCompletion(Filename,
false);
10529 switch (IncludeDir.getLookupType()) {
10534 AddFilesFromIncludeDir(IncludeDir.getDirRef()->getName(), IsSystem,
10538 AddFilesFromIncludeDir(IncludeDir.getFrameworkDirRef()->getName(),
10547 const auto &S =
SemaRef.PP.getHeaderSearchInfo();
10548 using llvm::make_range;
10551 if (
auto CurFile =
SemaRef.PP.getCurrentFileLexer()->getFileEntry())
10552 AddFilesFromIncludeDir(CurFile->getDir().getName(),
false,
10554 for (
const auto &D : make_range(S.quoted_dir_begin(), S.quoted_dir_end()))
10555 AddFilesFromDirLookup(D,
false);
10557 for (
const auto &D : make_range(S.angled_dir_begin(), S.angled_dir_end()))
10558 AddFilesFromDirLookup(D,
false);
10559 for (
const auto &D : make_range(S.system_dir_begin(), S.system_dir_end()))
10560 AddFilesFromDirLookup(D,
true);
10563 Results.getCompletionContext(), Results.data(),
10577 Results.EnterNewScope();
10578 static const char *Platforms[] = {
"macOS",
"iOS",
"watchOS",
"tvOS"};
10582 Twine(Platform) +
"ApplicationExtension")));
10584 Results.ExitScope();
10586 Results.getCompletionContext(), Results.data(),
10593 ResultBuilder Builder(
SemaRef, Allocator, CCTUInfo,
10596 CodeCompletionDeclConsumer Consumer(
10608 Results.insert(Results.end(), Builder.data(),
10609 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 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)
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 void AddFunctionParameterChunks(Preprocessor &PP, const PrintingPolicy &Policy, const FunctionDecl *Function, CodeCompletionBuilder &Result, unsigned Start=0, bool InOptional=false, bool FunctionCanBeCall=true, bool IsInDeclarationContext=false)
Add function parameter chunks to the given code completion string.
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 AddTypeSpecifierResults(const LangOptions &LangOpts, ResultBuilder &Results)
Add type specifiers for the current language as keyword results.
static std::optional< unsigned > getNextAggregateIndexAfterDesignatedInit(const ResultCandidate &Aggregate, ArrayRef< Expr * > Args)
static std::string GetDefaultValueString(const ParmVarDecl *Param, const SourceManager &SM, const LangOptions &LangOpts)
static void AddFunctionTypeQualsToCompletionString(CodeCompletionBuilder &Result, const FunctionDecl *Function, bool AsInformativeChunks=true)
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 AddTemplateParameterChunks(ASTContext &Context, const PrintingPolicy &Policy, const TemplateDecl *Template, CodeCompletionBuilder &Result, unsigned MaxParameters=0, unsigned Start=0, bool InDefaultArg=false, bool AsInformativeChunk=false)
Add template parameter chunks to the given code completion string.
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 AddFunctionTypeQuals(CodeCompletionBuilder &Result, const Qualifiers Quals, bool AsInformativeChunk=true)
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 CodeCompleteQualifiedId(Scope *S, CXXScopeSpec &SS, bool EnteringContext, bool IsUsingDeclaration, bool IsAddressOfOperand, bool IsInDeclarationContext, QualType BaseType, QualType PreferredType)
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 CodeCompleteExpression(Scope *S, const CodeCompleteExpressionData &Data, bool IsAddressOfOperand=false)
Perform code-completion in an expression context when we know what type we're looking for.
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
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 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.
@ Deduced
The normal deduced case.
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