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 IsOffsetofField(
const NamedDecl *ND)
const;
411 bool IsObjCIvar(
const NamedDecl *ND)
const;
412 bool IsObjCMessageReceiver(
const NamedDecl *ND)
const;
413 bool IsObjCMessageReceiverOrLambdaCapture(
const NamedDecl *ND)
const;
414 bool IsObjCCollection(
const NamedDecl *ND)
const;
415 bool IsImpossibleToSatisfy(
const NamedDecl *ND)
const;
425 ComputeType =
nullptr;
426 Type = BSI->ReturnType;
430 ComputeType =
nullptr;
434 ComputeType =
nullptr;
435 Type =
Method->getReturnType();
443 auto *VD = llvm::dyn_cast_or_null<ValueDecl>(D);
444 ComputeType =
nullptr;
445 Type = VD ? VD->getType() :
QualType();
461 ComputeType =
nullptr;
471 this->ComputeType = ComputeType;
481 if (ExpectedLoc == LParLoc)
492 if (Op == tok::plus || Op == tok::plusequal || Op == tok::minusequal)
495 if (Op == tok::minus)
508 case tok::minusequal:
510 case tok::percentequal:
512 case tok::slashequal:
518 case tok::equalequal:
519 case tok::exclaimequal:
523 case tok::greaterequal:
527 case tok::greatergreater:
528 case tok::greatergreaterequal:
530 case tok::lesslessequal:
543 case tok::caretequal:
551 case tok::periodstar:
569 if (!ContextType.isNull() && ContextType->isPointerType())
570 return ContextType->getPointeeType();
573 if (ContextType.isNull())
579 case tok::minusminus:
581 if (ContextType.isNull())
589 assert(
false &&
"unhandled unary op");
598 ComputeType =
nullptr;
605 if (!Enabled || !
Base)
608 if (ExpectedLoc !=
Base->getBeginLoc())
619 ComputeType =
nullptr;
628 ComputeType =
nullptr;
637 ComputeType =
nullptr;
645 ComputeType =
nullptr;
651 llvm::PointerUnion<const NamedDecl *, const DeclIndexPair *> DeclOrIterator;
652 unsigned SingleDeclIndex;
664 pointer(
const DeclIndexPair &Value) : Value(Value) {}
672 : DeclOrIterator(SingleDecl), SingleDeclIndex(Index) {}
675 : DeclOrIterator(Iterator), SingleDeclIndex(0) {}
697 if (
const NamedDecl *ND = dyn_cast<const NamedDecl *>(DeclOrIterator))
706 return X.DeclOrIterator.getOpaqueValue() ==
707 Y.DeclOrIterator.getOpaqueValue() &&
708 X.SingleDeclIndex == Y.SingleDeclIndex;
717ResultBuilder::ShadowMapEntry::begin()
const {
718 if (DeclOrVector.isNull())
721 if (
const NamedDecl *ND = dyn_cast<const NamedDecl *>(DeclOrVector))
722 return iterator(ND, SingleDeclIndex);
728ResultBuilder::ShadowMapEntry::end()
const {
753 for (
const DeclContext *CommonAncestor = TargetContext;
754 CommonAncestor && !CommonAncestor->
Encloses(CurContext);
755 CommonAncestor = CommonAncestor->getLookupParent()) {
756 if (CommonAncestor->isTransparentContext() ||
757 CommonAncestor->isFunctionOrMethod())
760 TargetParents.push_back(CommonAncestor);
764 while (!TargetParents.empty()) {
765 const DeclContext *Parent = TargetParents.pop_back_val();
767 if (
const auto *Namespace = dyn_cast<NamespaceDecl>(Parent)) {
768 if (!Namespace->getIdentifier())
772 }
else if (
const auto *TD = dyn_cast<TagDecl>(Parent)) {
805bool ResultBuilder::isInterestingDecl(
const NamedDecl *ND,
806 bool &AsNestedNameSpecifier)
const {
807 AsNestedNameSpecifier =
false;
833 if (Filter == &ResultBuilder::IsNestedNameSpecifier ||
835 Filter != &ResultBuilder::IsNamespaceOrAlias && Filter !=
nullptr))
836 AsNestedNameSpecifier =
true;
839 if (Filter && !(this->*Filter)(Named)) {
841 if (AllowNestedNameSpecifiers && SemaRef.
getLangOpts().CPlusPlus &&
842 IsNestedNameSpecifier(ND) &&
843 (Filter != &ResultBuilder::IsMember ||
846 AsNestedNameSpecifier =
true;
865 R.Declaration->getDeclContext()->getRedeclContext();
876 R.QualifierIsInformative =
false;
880 R.Declaration->getDeclContext());
887 switch (T->getTypeClass()) {
890 case BuiltinType::Void:
893 case BuiltinType::NullPtr:
896 case BuiltinType::Overload:
897 case BuiltinType::Dependent:
900 case BuiltinType::ObjCId:
901 case BuiltinType::ObjCClass:
902 case BuiltinType::ObjCSel:
915 case Type::BlockPointer:
918 case Type::LValueReference:
919 case Type::RValueReference:
922 case Type::ConstantArray:
923 case Type::IncompleteArray:
924 case Type::VariableArray:
925 case Type::DependentSizedArray:
928 case Type::DependentSizedExtVector:
930 case Type::ExtVector:
933 case Type::FunctionProto:
934 case Type::FunctionNoProto:
943 case Type::ObjCObject:
944 case Type::ObjCInterface:
945 case Type::ObjCObjectPointer:
959 if (
const auto *
Type = dyn_cast<TypeDecl>(ND))
961 if (
const auto *Iface = dyn_cast<ObjCInterfaceDecl>(ND))
962 return C.getObjCInterfaceType(Iface);
967 else if (
const auto *
Method = dyn_cast<ObjCMethodDecl>(ND))
968 T =
Method->getSendResultType();
969 else if (
const auto *
Enumerator = dyn_cast<EnumConstantDecl>(ND))
973 else if (
const auto *
Property = dyn_cast<ObjCPropertyDecl>(ND))
975 else if (
const auto *
Value = dyn_cast<ValueDecl>(ND))
986 T = Ref->getPointeeType();
991 if (
Pointer->getPointeeType()->isFunctionType()) {
1000 T =
Block->getPointeeType();
1015unsigned ResultBuilder::getBasePriority(
const NamedDecl *ND) {
1023 if (
const auto *ImplicitParam = dyn_cast<ImplicitParamDecl>(ND))
1024 if (ImplicitParam->getIdentifier() &&
1025 ImplicitParam->getIdentifier()->isStr(
"_cmd"))
1054 CompletionContext.
getKind() ==
1056 CompletionContext.
getKind() ==
1063void ResultBuilder::AdjustResultPriorityForDecl(
Result &R) {
1066 if (!PreferredSelector.
isNull())
1067 if (
const auto *
Method = dyn_cast<ObjCMethodDecl>(
R.Declaration))
1068 if (PreferredSelector ==
Method->getSelector())
1073 if (!PreferredType.
isNull()) {
1083 !(PreferredType->isEnumeralType() && TC->isEnumeralType()))
1093 Context.DeclarationNames.getCXXConstructorName(RecordTy);
1094 return Record->lookup(ConstructorName);
1097void ResultBuilder::MaybeAddConstructorResults(
Result R) {
1098 if (!SemaRef.
getLangOpts().CPlusPlus || !
R.Declaration ||
1105 Record = ClassTemplate->getTemplatedDecl();
1106 else if ((
Record = dyn_cast<CXXRecordDecl>(D))) {
1120 R.Declaration = Ctor;
1122 Results.push_back(R);
1127 if (
const auto *Tmpl = dyn_cast<FunctionTemplateDecl>(ND))
1128 ND = Tmpl->getTemplatedDecl();
1133 assert(!ShadowMaps.empty() &&
"Must enter into a results scope");
1135 if (
R.Kind != Result::RK_Declaration) {
1137 Results.push_back(R);
1142 if (
const UsingShadowDecl *Using = dyn_cast<UsingShadowDecl>(
R.Declaration)) {
1144 getBasePriority(
Using->getTargetDecl()),
1148 std::move(
R.FixIts));
1150 MaybeAddResult(
Result, CurContext);
1154 const Decl *CanonDecl =
R.Declaration->getCanonicalDecl();
1157 bool AsNestedNameSpecifier =
false;
1158 if (!isInterestingDecl(
R.Declaration, AsNestedNameSpecifier))
1165 ShadowMap &SMap = ShadowMaps.back();
1166 ShadowMapEntry::iterator I, IEnd;
1167 ShadowMap::iterator NamePos = SMap.find(
R.Declaration->getDeclName());
1168 if (NamePos != SMap.end()) {
1169 I = NamePos->second.begin();
1170 IEnd = NamePos->second.end();
1173 for (; I != IEnd; ++I) {
1175 unsigned Index = I->second;
1178 Results[Index].Declaration =
R.Declaration;
1188 std::list<ShadowMap>::iterator
SM, SMEnd = ShadowMaps.end();
1190 for (
SM = ShadowMaps.begin();
SM != SMEnd; ++
SM) {
1191 ShadowMapEntry::iterator I, IEnd;
1192 ShadowMap::iterator NamePos =
SM->find(
R.Declaration->getDeclName());
1193 if (NamePos !=
SM->end()) {
1194 I = NamePos->second.begin();
1195 IEnd = NamePos->second.end();
1197 for (; I != IEnd; ++I) {
1199 if (I->first->hasTagIdentifierNamespace() &&
1207 I->first->getIdentifierNamespace() != IDNS)
1211 if (CheckHiddenResult(R, CurContext, I->first))
1219 if (!AllDeclsFound.insert(CanonDecl).second)
1224 if (AsNestedNameSpecifier) {
1225 R.StartsNestedNameSpecifier =
true;
1228 AdjustResultPriorityForDecl(R);
1231 if (
R.QualifierIsInformative && !
R.Qualifier &&
1232 !
R.StartsNestedNameSpecifier) {
1233 const DeclContext *Ctx =
R.Declaration->getDeclContext();
1234 if (
const NamespaceDecl *Namespace = dyn_cast<NamespaceDecl>(Ctx))
1237 else if (
const TagDecl *Tag = dyn_cast<TagDecl>(Ctx))
1241 std::nullopt, Tag,
false)
1244 R.QualifierIsInformative =
false;
1249 SMap[
R.Declaration->getDeclName()].Add(
R.Declaration, Results.size());
1250 Results.push_back(R);
1252 if (!AsNestedNameSpecifier)
1253 MaybeAddConstructorResults(R);
1258 R.InBaseClass =
true;
1279 for (
unsigned I = 0, E = Candidate.
getNumParams(); I != E; ++I)
1280 if (Candidate.
parameters()[I]->getType().getCanonicalType() !=
1281 Incumbent.
parameters()[I]->getType().getCanonicalType())
1290 if (CandidateRef != IncumbentRef) {
1306 if (CandidateSuperset == IncumbentSuperset)
1318 const auto *CurrentClassScope = [&]() ->
const CXXRecordDecl * {
1320 const auto *CtxMethod = llvm::dyn_cast<CXXMethodDecl>(Ctx);
1321 if (CtxMethod && !CtxMethod->getParent()->isLambda()) {
1322 return CtxMethod->getParent();
1329 bool FunctionCanBeCall =
1330 CurrentClassScope &&
1331 (CurrentClassScope ==
Method->getParent() ||
1332 CurrentClassScope->isDerivedFrom(
Method->getParent()));
1335 if (FunctionCanBeCall)
1340 BaseExprType.
isNull() ?
nullptr
1342 auto *MaybeBase =
Method->getParent();
1344 MaybeDerived == MaybeBase || MaybeDerived->isDerivedFrom(MaybeBase);
1347 return FunctionCanBeCall;
1350bool ResultBuilder::canFunctionBeCalled(
const NamedDecl *ND,
1361 if (
const auto *FuncTmpl = dyn_cast<FunctionTemplateDecl>(ND)) {
1362 ND = FuncTmpl->getTemplatedDecl();
1364 const auto *
Method = dyn_cast<CXXMethodDecl>(ND);
1366 return canCxxMethodBeCalled(
Method, BaseExprType);
1373 NamedDecl *Hiding,
bool InBaseClass =
false,
1375 bool IsInDeclarationContext =
false,
1376 bool IsAddressOfOperand =
false) {
1377 if (
R.Kind != Result::RK_Declaration) {
1379 Results.push_back(R);
1384 if (
const auto *Using = dyn_cast<UsingShadowDecl>(
R.Declaration)) {
1386 getBasePriority(
Using->getTargetDecl()),
1390 std::move(
R.FixIts));
1392 AddResult(
Result, CurContext, Hiding,
false,
1397 bool AsNestedNameSpecifier =
false;
1398 if (!isInterestingDecl(
R.Declaration, AsNestedNameSpecifier))
1405 if (Hiding && CheckHiddenResult(R, CurContext, Hiding))
1409 if (!AllDeclsFound.insert(
R.Declaration->getCanonicalDecl()).second)
1414 if (AsNestedNameSpecifier) {
1415 R.StartsNestedNameSpecifier =
true;
1417 }
else if (Filter == &ResultBuilder::IsMember && !
R.Qualifier &&
1420 R.Declaration->getDeclContext()->getRedeclContext()))
1421 R.QualifierIsInformative =
true;
1424 if (
R.QualifierIsInformative && !
R.Qualifier &&
1425 !
R.StartsNestedNameSpecifier) {
1426 const DeclContext *Ctx =
R.Declaration->getDeclContext();
1427 if (
const auto *Namespace = dyn_cast<NamespaceDecl>(Ctx))
1430 else if (
const auto *Tag = dyn_cast<TagDecl>(Ctx))
1434 std::nullopt, Tag,
false)
1437 R.QualifierIsInformative =
false;
1444 AdjustResultPriorityForDecl(R);
1447 const auto GetQualifiers = [&](
const CXXMethodDecl *MethodDecl) {
1448 if (MethodDecl->isExplicitObjectMemberFunction())
1449 return MethodDecl->getFunctionObjectParameterType().getQualifiers();
1451 return MethodDecl->getMethodQualifiers();
1454 if (IsExplicitObjectMemberFunction &&
1463 if (HasObjectTypeQualifiers)
1464 if (
const auto *
Method = dyn_cast<CXXMethodDecl>(
R.Declaration))
1465 if (
Method->isInstance()) {
1467 if (ObjectTypeQualifiers == MethodQuals)
1469 else if (ObjectTypeQualifiers - MethodQuals) {
1475 switch (
Method->getRefQualifier()) {
1492 CurContext,
Method->getDeclName().getAsOpaqueInteger())];
1494 Result &Incumbent = Results[Entry.second];
1497 ObjectTypeQualifiers, ObjectKind,
1503 Incumbent = std::move(R);
1514 R.DeclaringEntity = IsInDeclarationContext;
1515 R.FunctionCanBeCall =
1516 canFunctionBeCalled(
R.getDeclaration(), BaseExprType) &&
1520 !IsAddressOfOperand;
1523 Results.push_back(R);
1525 if (!AsNestedNameSpecifier)
1526 MaybeAddConstructorResults(R);
1529void ResultBuilder::AddResult(
Result R) {
1530 assert(
R.Kind != Result::RK_Declaration &&
1531 "Declaration results need more context");
1532 Results.push_back(R);
1536void ResultBuilder::EnterNewScope() { ShadowMaps.emplace_back(); }
1539void ResultBuilder::ExitScope() {
1540 ShadowMaps.pop_back();
1545bool ResultBuilder::IsOrdinaryName(
const NamedDecl *ND)
const {
1563bool ResultBuilder::IsOrdinaryNonTypeName(
const NamedDecl *ND)
const {
1570 if (
const auto *ID = dyn_cast<ObjCInterfaceDecl>(ND)) {
1571 if (!
ID->getDefinition())
1586bool ResultBuilder::IsIntegralConstantValue(
const NamedDecl *ND)
const {
1587 if (!IsOrdinaryNonTypeName(ND))
1591 if (VD->getType()->isIntegralOrEnumerationType())
1599bool ResultBuilder::IsOrdinaryNonValueName(
const NamedDecl *ND)
const {
1612bool ResultBuilder::IsNestedNameSpecifier(
const NamedDecl *ND)
const {
1614 if (
const auto *ClassTemplate = dyn_cast<ClassTemplateDecl>(ND))
1615 ND = ClassTemplate->getTemplatedDecl();
1621bool ResultBuilder::IsEnum(
const NamedDecl *ND)
const {
1626bool ResultBuilder::IsClassOrStruct(
const NamedDecl *ND)
const {
1628 if (
const auto *ClassTemplate = dyn_cast<ClassTemplateDecl>(ND))
1629 ND = ClassTemplate->getTemplatedDecl();
1632 if (
const auto *RD = dyn_cast<RecordDecl>(ND))
1641bool ResultBuilder::IsUnion(
const NamedDecl *ND)
const {
1643 if (
const auto *ClassTemplate = dyn_cast<ClassTemplateDecl>(ND))
1644 ND = ClassTemplate->getTemplatedDecl();
1646 if (
const auto *RD = dyn_cast<RecordDecl>(ND))
1653bool ResultBuilder::IsNamespace(
const NamedDecl *ND)
const {
1659bool ResultBuilder::IsNamespaceOrAlias(
const NamedDecl *ND)
const {
1664bool ResultBuilder::IsType(
const NamedDecl *ND)
const {
1672bool ResultBuilder::IsMember(
const NamedDecl *ND)
const {
1680bool ResultBuilder::IsOffsetofField(
const NamedDecl *ND)
const {
1682 if (
const auto *FD = dyn_cast<FieldDecl>(ND))
1683 return !FD->isBitField();
1684 if (
const auto *IFD = dyn_cast<IndirectFieldDecl>(ND))
1685 return !IFD->getAnonField()->isBitField();
1690 T =
C.getCanonicalType(T);
1691 switch (T->getTypeClass()) {
1692 case Type::ObjCObject:
1693 case Type::ObjCInterface:
1694 case Type::ObjCObjectPointer:
1699 case BuiltinType::ObjCId:
1700 case BuiltinType::ObjCClass:
1701 case BuiltinType::ObjCSel:
1713 if (!
C.getLangOpts().CPlusPlus)
1719 return T->isDependentType() || T->isRecordType();
1722bool ResultBuilder::IsObjCMessageReceiver(
const NamedDecl *ND)
const {
1732bool ResultBuilder::IsObjCMessageReceiverOrLambdaCapture(
1734 if (IsObjCMessageReceiver(ND))
1737 const auto *Var = dyn_cast<VarDecl>(ND);
1741 return Var->hasLocalStorage() && !Var->hasAttr<BlocksAttr>();
1744bool ResultBuilder::IsObjCCollection(
const NamedDecl *ND)
const {
1745 if ((SemaRef.
getLangOpts().CPlusPlus && !IsOrdinaryName(ND)) ||
1746 (!SemaRef.
getLangOpts().CPlusPlus && !IsOrdinaryNonTypeName(ND)))
1760bool ResultBuilder::IsImpossibleToSatisfy(
const NamedDecl *ND)
const {
1766bool ResultBuilder::IsObjCIvar(
const NamedDecl *ND)
const {
1775 ResultBuilder &Results;
1776 DeclContext *InitialLookupCtx;
1779 CXXRecordDecl *NamingClass;
1781 std::vector<FixItHint> FixIts;
1782 bool IsInDeclarationContext;
1784 bool IsAddressOfOperand;
1787 CodeCompletionDeclConsumer(
1788 ResultBuilder &Results, DeclContext *InitialLookupCtx,
1789 QualType BaseType = QualType(),
1790 std::vector<FixItHint> FixIts = std::vector<FixItHint>())
1791 : Results(Results), InitialLookupCtx(InitialLookupCtx),
1792 FixIts(std::move(FixIts)), IsInDeclarationContext(
false),
1793 IsAddressOfOperand(
false) {
1794 NamingClass = llvm::dyn_cast<CXXRecordDecl>(InitialLookupCtx);
1797 auto ThisType = Results.getSema().getCurrentThisType();
1798 if (!ThisType.isNull()) {
1799 assert(ThisType->isPointerType());
1805 this->BaseType = BaseType;
1808 void setIsInDeclarationContext(
bool IsInDeclarationContext) {
1809 this->IsInDeclarationContext = IsInDeclarationContext;
1812 void setIsAddressOfOperand(
bool IsAddressOfOperand) {
1813 this->IsAddressOfOperand = IsAddressOfOperand;
1816 void FoundDecl(NamedDecl *ND, NamedDecl *Hiding, DeclContext *Ctx,
1817 bool InBaseClass)
override {
1818 ResultBuilder::Result
Result(ND, Results.getBasePriority(ND),
1822 Results.AddResult(
Result, InitialLookupCtx, Hiding, InBaseClass, BaseType,
1823 IsInDeclarationContext, IsAddressOfOperand);
1826 void EnteredContext(DeclContext *Ctx)
override {
1827 Results.addVisitedContext(Ctx);
1836 auto *NamingClass = this->NamingClass;
1837 QualType BaseType = this->BaseType;
1838 if (
auto *Cls = llvm::dyn_cast_or_null<CXXRecordDecl>(Ctx)) {
1847 BaseType = QualType();
1853 NamingClass =
nullptr;
1854 BaseType = QualType();
1856 return Results.getSema().IsSimplyAccessible(ND, NamingClass, BaseType);
1863 ResultBuilder &Results) {
1890 Results.getCodeCompletionTUInfo());
1891 if (LangOpts.CPlusPlus) {
1899 Builder.AddTypedTextChunk(
"typename");
1901 Builder.AddPlaceholderChunk(
"name");
1902 Results.AddResult(
Result(Builder.TakeString()));
1904 if (LangOpts.CPlusPlus11) {
1909 Builder.AddTypedTextChunk(
"decltype");
1911 Builder.AddPlaceholderChunk(
"expression");
1913 Results.AddResult(
Result(Builder.TakeString()));
1916 if (LangOpts.Char8 || LangOpts.CPlusPlus20)
1922 if (LangOpts.GNUKeywords) {
1928 Builder.AddTypedTextChunk(
"typeof");
1930 Builder.AddPlaceholderChunk(
"expression");
1931 Results.AddResult(
Result(Builder.TakeString()));
1933 Builder.AddTypedTextChunk(
"typeof");
1935 Builder.AddPlaceholderChunk(
"type");
1937 Results.AddResult(
Result(Builder.TakeString()));
1948 const LangOptions &LangOpts, ResultBuilder &Results) {
1953 Results.AddResult(
Result(
"extern"));
1954 Results.AddResult(
Result(
"static"));
1956 if (LangOpts.CPlusPlus11) {
1961 Builder.AddTypedTextChunk(
"alignas");
1963 Builder.AddPlaceholderChunk(
"expression");
1965 Results.AddResult(
Result(Builder.TakeString()));
1967 Results.AddResult(
Result(
"constexpr"));
1968 Results.AddResult(
Result(
"thread_local"));
1971 if (LangOpts.CPlusPlus20)
1972 Results.AddResult(
Result(
"constinit"));
1977 const LangOptions &LangOpts, ResultBuilder &Results) {
1982 if (LangOpts.CPlusPlus) {
1983 Results.AddResult(
Result(
"explicit"));
1984 Results.AddResult(
Result(
"friend"));
1985 Results.AddResult(
Result(
"mutable"));
1986 Results.AddResult(
Result(
"virtual"));
1994 if (LangOpts.CPlusPlus || LangOpts.C99)
1995 Results.AddResult(
Result(
"inline"));
1997 if (LangOpts.CPlusPlus20)
1998 Results.AddResult(
Result(
"consteval"));
2018 ResultBuilder &Results,
bool NeedAt);
2020 ResultBuilder &Results,
bool NeedAt);
2022 ResultBuilder &Results,
bool NeedAt);
2027 Results.getCodeCompletionTUInfo());
2028 Builder.AddTypedTextChunk(
"typedef");
2030 Builder.AddPlaceholderChunk(
"type");
2032 Builder.AddPlaceholderChunk(
"name");
2039 ResultBuilder &Results) {
2040 Builder.AddTypedTextChunk(
"using");
2042 Builder.AddPlaceholderChunk(
"name");
2044 Builder.AddPlaceholderChunk(
"type");
2067 return LangOpts.CPlusPlus;
2074 return LangOpts.CPlusPlus || LangOpts.ObjC || LangOpts.C99;
2077 llvm_unreachable(
"Invalid ParserCompletionContext!");
2104 if (!T.getLocalQualifiers()) {
2106 if (
const BuiltinType *BT = dyn_cast<BuiltinType>(T))
2107 return BT->getNameAsCString(Policy);
2110 if (
const TagType *TagT = dyn_cast<TagType>(T))
2111 if (
TagDecl *Tag = TagT->getDecl())
2112 if (!Tag->hasNameForLinkage()) {
2113 switch (Tag->getTagKind()) {
2115 return "struct <anonymous>";
2117 return "__interface <anonymous>";
2119 return "class <anonymous>";
2121 return "union <anonymous>";
2123 return "enum <anonymous>";
2130 T.getAsStringInternal(
Result, Policy);
2143 Builder.AddResultTypeChunk(
2145 Builder.AddTypedTextChunk(
"this");
2150 ResultBuilder &Results,
2152 if (!LangOpts.CPlusPlus11)
2155 Builder.AddTypedTextChunk(
"static_assert");
2157 Builder.AddPlaceholderChunk(
"expression");
2159 Builder.AddPlaceholderChunk(
"message");
2168 Sema &S = Results.getSema();
2169 const auto *CR = llvm::dyn_cast<CXXRecordDecl>(S.
CurContext);
2175 llvm::StringMap<std::vector<FunctionDecl *>> Overrides;
2176 for (
auto *Method : CR->methods()) {
2177 if (!Method->isVirtual() || !Method->getIdentifier())
2179 Overrides[Method->getName()].push_back(Method);
2182 for (
const auto &
Base : CR->bases()) {
2183 const auto *BR =
Base.getType().getTypePtr()->getAsCXXRecordDecl();
2186 for (
auto *Method : BR->methods()) {
2187 if (!Method->isVirtual() || !Method->getIdentifier())
2189 const auto it = Overrides.find(Method->getName());
2190 bool IsOverriden =
false;
2191 if (it != Overrides.end()) {
2192 for (
auto *MD : it->second) {
2210 false, CCContext, Policy);
2220 Scope *S,
Sema &SemaRef, ResultBuilder &Results) {
2228 if (Results.includeCodePatterns()) {
2230 Builder.AddTypedTextChunk(
"namespace");
2232 Builder.AddPlaceholderChunk(
"identifier");
2236 Builder.AddPlaceholderChunk(
"declarations");
2239 Results.AddResult(
Result(Builder.TakeString()));
2243 Builder.AddTypedTextChunk(
"namespace");
2245 Builder.AddPlaceholderChunk(
"name");
2247 Builder.AddPlaceholderChunk(
"namespace");
2249 Results.AddResult(
Result(Builder.TakeString()));
2252 Builder.AddTypedTextChunk(
"using namespace");
2254 Builder.AddPlaceholderChunk(
"identifier");
2256 Results.AddResult(
Result(Builder.TakeString()));
2259 Builder.AddTypedTextChunk(
"asm");
2261 Builder.AddPlaceholderChunk(
"string-literal");
2263 Results.AddResult(
Result(Builder.TakeString()));
2265 if (Results.includeCodePatterns()) {
2267 Builder.AddTypedTextChunk(
"template");
2269 Builder.AddPlaceholderChunk(
"declaration");
2270 Results.AddResult(
Result(Builder.TakeString()));
2281 if (!CurrentModule) {
2283 Builder.AddTypedTextChunk(
"module");
2286 Results.AddResult(
Result(Builder.TakeString()));
2291 if (!CurrentModule ||
2296 Builder.AddTypedTextChunk(
"module");
2298 Builder.AddPlaceholderChunk(
"name");
2301 Results.AddResult(
Result(Builder.TakeString()));
2306 if (!CurrentModule ||
2310 Builder.AddTypedTextChunk(
"import");
2312 Builder.AddPlaceholderChunk(
"name");
2315 Results.AddResult(
Result(Builder.TakeString()));
2318 if (CurrentModule &&
2322 Builder.AddTypedTextChunk(
"module");
2325 Builder.AddTypedTextChunk(
"private");
2328 Results.AddResult(
Result(Builder.TakeString()));
2333 if (!CurrentModule ||
2348 Builder.AddTypedTextChunk(
"using");
2350 Builder.AddPlaceholderChunk(
"qualifier");
2351 Builder.AddTextChunk(
"::");
2352 Builder.AddPlaceholderChunk(
"name");
2354 Results.AddResult(
Result(Builder.TakeString()));
2361 Builder.AddTypedTextChunk(
"using typename");
2363 Builder.AddPlaceholderChunk(
"qualifier");
2364 Builder.AddTextChunk(
"::");
2365 Builder.AddPlaceholderChunk(
"name");
2367 Results.AddResult(
Result(Builder.TakeString()));
2377 Builder.AddTypedTextChunk(
"public");
2378 if (IsNotInheritanceScope && Results.includeCodePatterns())
2380 Results.AddResult(
Result(Builder.TakeString()));
2383 Builder.AddTypedTextChunk(
"protected");
2384 if (IsNotInheritanceScope && Results.includeCodePatterns())
2386 Results.AddResult(
Result(Builder.TakeString()));
2389 Builder.AddTypedTextChunk(
"private");
2390 if (IsNotInheritanceScope && Results.includeCodePatterns())
2392 Results.AddResult(
Result(Builder.TakeString()));
2410 if (SemaRef.
getLangOpts().CPlusPlus && Results.includeCodePatterns()) {
2412 Builder.AddTypedTextChunk(
"template");
2414 Builder.AddPlaceholderChunk(
"parameters");
2416 Results.AddResult(
Result(Builder.TakeString()));
2454 if (SemaRef.
getLangOpts().CPlusPlus && Results.includeCodePatterns() &&
2456 Builder.AddTypedTextChunk(
"try");
2460 Builder.AddPlaceholderChunk(
"statements");
2464 Builder.AddTextChunk(
"catch");
2467 Builder.AddPlaceholderChunk(
"declaration");
2472 Builder.AddPlaceholderChunk(
"statements");
2475 Results.AddResult(
Result(Builder.TakeString()));
2480 if (Results.includeCodePatterns()) {
2482 Builder.AddTypedTextChunk(
"if");
2486 Builder.AddPlaceholderChunk(
"condition");
2488 Builder.AddPlaceholderChunk(
"expression");
2493 Builder.AddPlaceholderChunk(
"statements");
2496 Results.AddResult(
Result(Builder.TakeString()));
2499 Builder.AddTypedTextChunk(
"switch");
2503 Builder.AddPlaceholderChunk(
"condition");
2505 Builder.AddPlaceholderChunk(
"expression");
2510 Builder.AddPlaceholderChunk(
"cases");
2513 Results.AddResult(
Result(Builder.TakeString()));
2520 Builder.AddTypedTextChunk(
"case");
2522 Builder.AddPlaceholderChunk(
"expression");
2524 Results.AddResult(
Result(Builder.TakeString()));
2527 Builder.AddTypedTextChunk(
"default");
2529 Results.AddResult(
Result(Builder.TakeString()));
2532 if (Results.includeCodePatterns()) {
2534 Builder.AddTypedTextChunk(
"while");
2538 Builder.AddPlaceholderChunk(
"condition");
2540 Builder.AddPlaceholderChunk(
"expression");
2545 Builder.AddPlaceholderChunk(
"statements");
2548 Results.AddResult(
Result(Builder.TakeString()));
2551 Builder.AddTypedTextChunk(
"do");
2555 Builder.AddPlaceholderChunk(
"statements");
2558 Builder.AddTextChunk(
"while");
2561 Builder.AddPlaceholderChunk(
"expression");
2563 Results.AddResult(
Result(Builder.TakeString()));
2566 Builder.AddTypedTextChunk(
"for");
2570 Builder.AddPlaceholderChunk(
"init-statement");
2572 Builder.AddPlaceholderChunk(
"init-expression");
2575 Builder.AddPlaceholderChunk(
"condition");
2578 Builder.AddPlaceholderChunk(
"inc-expression");
2583 Builder.AddPlaceholderChunk(
"statements");
2586 Results.AddResult(
Result(Builder.TakeString()));
2590 Builder.AddTypedTextChunk(
"for");
2593 Builder.AddPlaceholderChunk(
"range-declaration");
2596 Builder.AddTextChunk(
"in");
2600 Builder.AddPlaceholderChunk(
"range-expression");
2605 Builder.AddPlaceholderChunk(
"statements");
2608 Results.AddResult(
Result(Builder.TakeString()));
2614 Builder.AddTypedTextChunk(
"continue");
2616 Results.AddResult(
Result(Builder.TakeString()));
2621 Builder.AddTypedTextChunk(
"break");
2623 Results.AddResult(
Result(Builder.TakeString()));
2628 if (
const auto *Function = dyn_cast<FunctionDecl>(SemaRef.
CurContext))
2629 ReturnType = Function->getReturnType();
2630 else if (
const auto *Method = dyn_cast<ObjCMethodDecl>(SemaRef.
CurContext))
2631 ReturnType = Method->getReturnType();
2636 Builder.AddTypedTextChunk(
"return");
2638 Results.AddResult(
Result(Builder.TakeString()));
2640 assert(!ReturnType.
isNull());
2642 Builder.AddTypedTextChunk(
"return");
2644 Builder.AddPlaceholderChunk(
"expression");
2646 Results.AddResult(
Result(Builder.TakeString()));
2649 Builder.AddTypedTextChunk(
"co_return");
2651 Builder.AddPlaceholderChunk(
"expression");
2653 Results.AddResult(
Result(Builder.TakeString()));
2657 Builder.AddTypedTextChunk(
"return true");
2659 Results.AddResult(
Result(Builder.TakeString()));
2661 Builder.AddTypedTextChunk(
"return false");
2663 Results.AddResult(
Result(Builder.TakeString()));
2668 Builder.AddTypedTextChunk(
"return nullptr");
2670 Results.AddResult(
Result(Builder.TakeString()));
2675 Builder.AddTypedTextChunk(
"goto");
2677 Builder.AddPlaceholderChunk(
"label");
2679 Results.AddResult(
Result(Builder.TakeString()));
2682 Builder.AddTypedTextChunk(
"using namespace");
2684 Builder.AddPlaceholderChunk(
"identifier");
2686 Results.AddResult(
Result(Builder.TakeString()));
2703 Builder.AddTypedTextChunk(
"__bridge");
2705 Builder.AddPlaceholderChunk(
"type");
2707 Builder.AddPlaceholderChunk(
"expression");
2708 Results.AddResult(
Result(Builder.TakeString()));
2711 Builder.AddTypedTextChunk(
"__bridge_transfer");
2713 Builder.AddPlaceholderChunk(
"Objective-C type");
2715 Builder.AddPlaceholderChunk(
"expression");
2716 Results.AddResult(
Result(Builder.TakeString()));
2719 Builder.AddTypedTextChunk(
"__bridge_retained");
2721 Builder.AddPlaceholderChunk(
"CF type");
2723 Builder.AddPlaceholderChunk(
"expression");
2724 Results.AddResult(
Result(Builder.TakeString()));
2735 Builder.AddResultTypeChunk(
"bool");
2736 Builder.AddTypedTextChunk(
"true");
2737 Results.AddResult(
Result(Builder.TakeString()));
2740 Builder.AddResultTypeChunk(
"bool");
2741 Builder.AddTypedTextChunk(
"false");
2742 Results.AddResult(
Result(Builder.TakeString()));
2746 Builder.AddTypedTextChunk(
"dynamic_cast");
2748 Builder.AddPlaceholderChunk(
"type");
2751 Builder.AddPlaceholderChunk(
"expression");
2753 Results.AddResult(
Result(Builder.TakeString()));
2757 Builder.AddTypedTextChunk(
"static_cast");
2759 Builder.AddPlaceholderChunk(
"type");
2762 Builder.AddPlaceholderChunk(
"expression");
2764 Results.AddResult(
Result(Builder.TakeString()));
2767 Builder.AddTypedTextChunk(
"reinterpret_cast");
2769 Builder.AddPlaceholderChunk(
"type");
2772 Builder.AddPlaceholderChunk(
"expression");
2774 Results.AddResult(
Result(Builder.TakeString()));
2777 Builder.AddTypedTextChunk(
"const_cast");
2779 Builder.AddPlaceholderChunk(
"type");
2782 Builder.AddPlaceholderChunk(
"expression");
2784 Results.AddResult(
Result(Builder.TakeString()));
2788 Builder.AddResultTypeChunk(
"std::type_info");
2789 Builder.AddTypedTextChunk(
"typeid");
2791 Builder.AddPlaceholderChunk(
"expression-or-type");
2793 Results.AddResult(
Result(Builder.TakeString()));
2797 Builder.AddTypedTextChunk(
"new");
2799 Builder.AddPlaceholderChunk(
"type");
2801 Builder.AddPlaceholderChunk(
"expressions");
2803 Results.AddResult(
Result(Builder.TakeString()));
2806 Builder.AddTypedTextChunk(
"new");
2808 Builder.AddPlaceholderChunk(
"type");
2810 Builder.AddPlaceholderChunk(
"size");
2813 Builder.AddPlaceholderChunk(
"expressions");
2815 Results.AddResult(
Result(Builder.TakeString()));
2818 Builder.AddResultTypeChunk(
"void");
2819 Builder.AddTypedTextChunk(
"delete");
2821 Builder.AddPlaceholderChunk(
"expression");
2822 Results.AddResult(
Result(Builder.TakeString()));
2825 Builder.AddResultTypeChunk(
"void");
2826 Builder.AddTypedTextChunk(
"delete");
2831 Builder.AddPlaceholderChunk(
"expression");
2832 Results.AddResult(
Result(Builder.TakeString()));
2836 Builder.AddResultTypeChunk(
"void");
2837 Builder.AddTypedTextChunk(
"throw");
2839 Builder.AddPlaceholderChunk(
"expression");
2840 Results.AddResult(
Result(Builder.TakeString()));
2847 Builder.AddResultTypeChunk(
"std::nullptr_t");
2848 Builder.AddTypedTextChunk(
"nullptr");
2849 Results.AddResult(
Result(Builder.TakeString()));
2852 Builder.AddResultTypeChunk(
"size_t");
2853 Builder.AddTypedTextChunk(
"alignof");
2855 Builder.AddPlaceholderChunk(
"type");
2857 Results.AddResult(
Result(Builder.TakeString()));
2860 Builder.AddResultTypeChunk(
"bool");
2861 Builder.AddTypedTextChunk(
"noexcept");
2863 Builder.AddPlaceholderChunk(
"expression");
2865 Results.AddResult(
Result(Builder.TakeString()));
2868 Builder.AddResultTypeChunk(
"size_t");
2869 Builder.AddTypedTextChunk(
"sizeof...");
2871 Builder.AddPlaceholderChunk(
"parameter-pack");
2873 Results.AddResult(
Result(Builder.TakeString()));
2878 Builder.AddTypedTextChunk(
"co_await");
2880 Builder.AddPlaceholderChunk(
"expression");
2881 Results.AddResult(
Result(Builder.TakeString()));
2884 Builder.AddTypedTextChunk(
"co_yield");
2886 Builder.AddPlaceholderChunk(
"expression");
2887 Results.AddResult(
Result(Builder.TakeString()));
2890 Builder.AddResultTypeChunk(
"bool");
2891 Builder.AddTypedTextChunk(
"requires");
2894 Builder.AddPlaceholderChunk(
"parameters");
2899 Builder.AddPlaceholderChunk(
"requirements");
2902 Results.AddResult(
Result(Builder.TakeString()));
2906 Builder.AddTypedTextChunk(
"requires");
2908 Builder.AddPlaceholderChunk(
"expression");
2910 Results.AddResult(
Result(Builder.TakeString()));
2920 if (ID->getSuperClass()) {
2921 std::string SuperType;
2922 SuperType = ID->getSuperClass()->getNameAsString();
2923 if (Method->isInstanceMethod())
2926 Builder.AddResultTypeChunk(Allocator.
CopyString(SuperType));
2927 Builder.AddTypedTextChunk(
"super");
2928 Results.AddResult(
Result(Builder.TakeString()));
2937 Builder.AddResultTypeChunk(
"size_t");
2939 Builder.AddTypedTextChunk(
"alignof");
2941 Builder.AddTypedTextChunk(
"_Alignof");
2943 Builder.AddPlaceholderChunk(
"type");
2945 Results.AddResult(
Result(Builder.TakeString()));
2950 Builder.AddResultTypeChunk(
"nullptr_t");
2951 Builder.AddTypedTextChunk(
"nullptr");
2952 Results.AddResult(
Result(Builder.TakeString()));
2956 Builder.AddResultTypeChunk(
"size_t");
2957 Builder.AddTypedTextChunk(
"sizeof");
2959 Builder.AddPlaceholderChunk(
"expression-or-type");
2961 Results.AddResult(
Result(Builder.TakeString()));
2974 Results.AddResult(
Result(
"operator"));
2994 T = Function->getReturnType();
2995 else if (
const auto *Method = dyn_cast<ObjCMethodDecl>(ND)) {
2996 if (!BaseType.isNull())
2997 T = Method->getSendResultType(BaseType);
2999 T = Method->getReturnType();
3000 }
else if (
const auto *
Enumerator = dyn_cast<EnumConstantDecl>(ND)) {
3001 T = Context.getCanonicalTagType(
3005 }
else if (
const auto *Ivar = dyn_cast<ObjCIvarDecl>(ND)) {
3006 if (!BaseType.isNull())
3007 T = Ivar->getUsageType(BaseType);
3009 T = Ivar->getType();
3010 }
else if (
const auto *
Value = dyn_cast<ValueDecl>(ND)) {
3012 }
else if (
const auto *Property = dyn_cast<ObjCPropertyDecl>(ND)) {
3013 if (!BaseType.isNull())
3014 T = Property->getUsageType(BaseType);
3016 T = Property->getType();
3019 if (T.isNull() || Context.hasSameType(T, Context.DependentTy))
3022 Result.AddResultTypeChunk(
3029 if (SentinelAttr *Sentinel = FunctionOrMethod->
getAttr<SentinelAttr>())
3030 if (Sentinel->getSentinel() == 0) {
3032 Result.AddTextChunk(
", nil");
3034 Result.AddTextChunk(
", NULL");
3036 Result.AddTextChunk(
", (void*)0");
3056 if (
auto nullability = AttributedType::stripOuterNullability(
Type)) {
3057 switch (*nullability) {
3067 Result +=
"null_unspecified ";
3071 llvm_unreachable(
"Not supported as a context-sensitive keyword!");
3088 bool SuppressBlock =
false) {
3094 if (!SuppressBlock) {
3097 TypedefTL.getDecl()->getTypeSourceInfo()) {
3110 TL = AttrTL.getModifiedLoc();
3129 bool SuppressBlockName =
false,
bool SuppressBlock =
false,
3134 bool SuppressName =
false,
bool SuppressBlock =
false,
3142 if (
const auto *PVD = dyn_cast<ParmVarDecl>(Param))
3143 ObjCQual = PVD->getObjCDeclQualifier();
3145 if (Param->getType()->isDependentType() ||
3146 !Param->getType()->isBlockPointerType()) {
3151 if (Param->getIdentifier() && !ObjCMethodParam && !SuppressName)
3152 Result = std::string(Param->getIdentifier()->deuglifiedName());
3156 Type =
Type.substObjCTypeArgs(Param->getASTContext(), *ObjCSubsts,
3158 if (ObjCMethodParam) {
3161 if (Param->getIdentifier() && !SuppressName)
3162 Result += Param->getIdentifier()->deuglifiedName();
3177 if (!
Block && ObjCMethodParam &&
3180 ->findPropertyDecl(
false))
3189 if (!ObjCMethodParam && Param->getIdentifier())
3190 Result = std::string(Param->getIdentifier()->deuglifiedName());
3194 if (ObjCMethodParam) {
3199 if (
Result.back() !=
')')
3201 if (Param->getIdentifier())
3202 Result += Param->getIdentifier()->deuglifiedName();
3213 false, SuppressBlock,
3229 bool SuppressBlockName,
bool SuppressBlock,
3237 if (!ResultType->
isVoidType() || SuppressBlock)
3242 if (!BlockProto ||
Block.getNumParams() == 0) {
3249 for (
unsigned I = 0, N =
Block.getNumParams(); I != N; ++I) {
3262 if (SuppressBlock) {
3265 if (!SuppressBlockName &&
BlockDecl->getIdentifier())
3274 if (!SuppressBlockName &&
BlockDecl->getIdentifier())
3284 const SourceRange SrcRange = Param->getDefaultArgRange();
3294 if (srcText.empty() || srcText ==
"=") {
3300 std::string DefValue(srcText.str());
3303 if (DefValue.at(0) !=
'=') {
3307 return " = " + DefValue;
3309 return " " + DefValue;
3316 unsigned Start = 0,
bool InOptional =
false,
bool FunctionCanBeCall =
true,
3317 bool IsInDeclarationContext =
false) {
3318 bool FirstParameter =
true;
3319 bool AsInformativeChunk = !(FunctionCanBeCall || IsInDeclarationContext);
3321 for (
unsigned P = Start, N = Function->getNumParams(); P != N; ++P) {
3322 const ParmVarDecl *Param = Function->getParamDecl(P);
3324 if (Param->hasDefaultArg() && !InOptional && !IsInDeclarationContext &&
3325 !AsInformativeChunk) {
3329 Result.getCodeCompletionTUInfo());
3330 if (!FirstParameter)
3340 if (FirstParameter && Param->isExplicitObjectParameter()) {
3345 FirstParameter =
false;
3347 if (AsInformativeChunk)
3348 Result.AddInformativeChunk(
", ");
3357 std::string DefaultValue;
3358 if (Param->hasDefaultArg()) {
3359 if (IsInDeclarationContext)
3367 if (Function->isVariadic() && P == N - 1)
3368 PlaceholderStr +=
", ...";
3371 if (AsInformativeChunk)
3372 Result.AddInformativeChunk(
3373 Result.getAllocator().CopyString(PlaceholderStr));
3374 else if (IsInDeclarationContext) {
3375 Result.AddTextChunk(
Result.getAllocator().CopyString(PlaceholderStr));
3376 if (DefaultValue.length() != 0)
3377 Result.AddInformativeChunk(
3378 Result.getAllocator().CopyString(DefaultValue));
3380 Result.AddPlaceholderChunk(
3381 Result.getAllocator().CopyString(PlaceholderStr));
3385 if (Proto->isVariadic()) {
3386 if (Proto->getNumParams() == 0)
3387 Result.AddPlaceholderChunk(
"...");
3397 unsigned MaxParameters = 0,
unsigned Start = 0,
bool InDefaultArg =
false,
3398 bool AsInformativeChunk =
false) {
3399 bool FirstParameter =
true;
3408 PEnd = Params->
begin() + MaxParameters;
3411 bool HasDefaultArg =
false;
3412 std::string PlaceholderStr;
3414 if (TTP->wasDeclaredWithTypename())
3415 PlaceholderStr =
"typename";
3416 else if (
const auto *TC = TTP->getTypeConstraint()) {
3417 llvm::raw_string_ostream OS(PlaceholderStr);
3418 TC->print(OS, Policy);
3420 PlaceholderStr =
"class";
3422 if (TTP->getIdentifier()) {
3423 PlaceholderStr +=
' ';
3424 PlaceholderStr += TTP->getIdentifier()->deuglifiedName();
3427 HasDefaultArg = TTP->hasDefaultArgument();
3429 dyn_cast<NonTypeTemplateParmDecl>(*P)) {
3430 if (NTTP->getIdentifier())
3431 PlaceholderStr = std::string(NTTP->getIdentifier()->deuglifiedName());
3432 NTTP->getType().getAsStringInternal(PlaceholderStr, Policy);
3433 HasDefaultArg = NTTP->hasDefaultArgument();
3440 PlaceholderStr =
"template<...> class";
3442 PlaceholderStr +=
' ';
3449 if (HasDefaultArg && !InDefaultArg && !AsInformativeChunk) {
3453 Result.getCodeCompletionTUInfo());
3454 if (!FirstParameter)
3457 P - Params->
begin(),
true);
3462 InDefaultArg =
false;
3465 FirstParameter =
false;
3467 if (AsInformativeChunk)
3468 Result.AddInformativeChunk(
", ");
3473 if (AsInformativeChunk)
3474 Result.AddInformativeChunk(
3475 Result.getAllocator().CopyString(PlaceholderStr));
3477 Result.AddPlaceholderChunk(
3478 Result.getAllocator().CopyString(PlaceholderStr));
3486 bool QualifierIsInformative,
3492 std::string PrintedNNS;
3494 llvm::raw_string_ostream OS(PrintedNNS);
3495 Qualifier.print(OS, Policy);
3497 if (QualifierIsInformative)
3498 Result.AddInformativeChunk(
Result.getAllocator().CopyString(PrintedNNS));
3500 Result.AddTextChunk(
Result.getAllocator().CopyString(PrintedNNS));
3505 bool AsInformativeChunk =
true) {
3510 if (AsInformativeChunk)
3511 Result.AddInformativeChunk(
" const");
3513 Result.AddTextChunk(
" const");
3518 if (AsInformativeChunk)
3519 Result.AddInformativeChunk(
" volatile");
3521 Result.AddTextChunk(
" volatile");
3526 if (AsInformativeChunk)
3527 Result.AddInformativeChunk(
" restrict");
3529 Result.AddTextChunk(
" restrict");
3534 std::string QualsStr;
3536 QualsStr +=
" const";
3538 QualsStr +=
" volatile";
3540 QualsStr +=
" restrict";
3542 if (AsInformativeChunk)
3543 Result.AddInformativeChunk(
Result.getAllocator().CopyString(QualsStr));
3545 Result.AddTextChunk(
Result.getAllocator().CopyString(QualsStr));
3551 bool AsInformativeChunks =
true) {
3552 if (
auto *CxxMethodDecl = llvm::dyn_cast_if_present<CXXMethodDecl>(Function);
3553 CxxMethodDecl && CxxMethodDecl->hasCXXExplicitFunctionObjectParameter()) {
3555 const auto Quals = CxxMethodDecl->getFunctionObjectParameterType();
3556 if (!Quals.hasQualifiers())
3562 if (!Proto || !Proto->getMethodQuals())
3577 switch (ExceptInfo.Type) {
3580 NameAndSignature +=
" noexcept";
3598 const char *OperatorName =
nullptr;
3601 case OO_Conditional:
3603 OperatorName =
"operator";
3606#define OVERLOADED_OPERATOR(Name, Spelling, Token, Unary, Binary, MemberOnly) \
3608 OperatorName = "operator" Spelling; \
3610#define OVERLOADED_OPERATOR_MULTI(Name, Spelling, Unary, Binary, MemberOnly)
3611#include "clang/Basic/OperatorKinds.def"
3614 OperatorName =
"operator new";
3617 OperatorName =
"operator delete";
3620 OperatorName =
"operator new[]";
3622 case OO_Array_Delete:
3623 OperatorName =
"operator delete[]";
3626 OperatorName =
"operator()";
3629 OperatorName =
"operator[]";
3632 Result.AddTypedTextChunk(OperatorName);
3640 Result.AddTypedTextChunk(
3657 Result.AddTypedTextChunk(
3662 Result.AddTypedTextChunk(
3663 Result.getAllocator().CopyString(
Record->getNameAsString()));
3677 bool IncludeBriefComments) {
3679 CCTUInfo, IncludeBriefComments);
3691 return Result.TakeString();
3702 Result.AddPlaceholderChunk(
"...");
3716 Result.AddPlaceholderChunk(
Result.getAllocator().CopyString(Arg));
3721 Result.AddPlaceholderChunk(
3722 Result.getAllocator().CopyString((*A)->getName()));
3725 return Result.TakeString();
3737 bool IncludeBriefComments) {
3753 Result.addBriefComment(RC->getBriefText(Ctx));
3763 return Result.TakeString();
3767 PP, Ctx,
Result, IncludeBriefComments, CCContext, Policy);
3771 std::string &BeforeName,
3772 std::string &NameAndSignature) {
3773 bool SeenTypedChunk =
false;
3774 for (
auto &Chunk : CCS) {
3776 assert(SeenTypedChunk &&
"optional parameter before name");
3783 NameAndSignature += Chunk.Text;
3785 BeforeName += Chunk.Text;
3797 std::string BeforeName;
3798 std::string NameAndSignature;
3804 const auto *VirtualFunc = dyn_cast<FunctionDecl>(
Declaration);
3805 assert(VirtualFunc &&
"overridden decl must be a function");
3808 NameAndSignature +=
" override";
3810 Result.AddTextChunk(
Result.getAllocator().CopyString(BeforeName));
3812 Result.AddTypedTextChunk(
Result.getAllocator().CopyString(NameAndSignature));
3813 return Result.TakeString();
3819 const auto *VD = dyn_cast<VarDecl>(ND);
3822 const auto *
RecordDecl = VD->getType()->getAsCXXRecordDecl();
3835 if (IncludeBriefComments) {
3838 Result.addBriefComment(RC->getBriefText(Ctx));
3843 Result.AddTypedTextChunk(
3845 Result.AddTextChunk(
"::");
3846 return Result.TakeString();
3850 Result.AddAnnotation(
Result.getAllocator().CopyString(I->getAnnotation()));
3858 if (InsertParameters)
3861 Result.AddInformativeChunk(
"(");
3866 if (InsertParameters)
3869 Result.AddInformativeChunk(
")");
3874 if (
const auto *
Function = dyn_cast<FunctionDecl>(ND)) {
3875 AddFunctionTypeAndResult(
Function);
3876 return Result.TakeString();
3879 if (
const auto *CallOperator =
3881 AddFunctionTypeAndResult(CallOperator);
3882 return Result.TakeString();
3888 dyn_cast<FunctionTemplateDecl>(ND)) {
3899 llvm::SmallBitVector
Deduced(FunTmpl->getTemplateParameters()->size());
3904 unsigned LastDeducibleArgument;
3905 for (LastDeducibleArgument =
Deduced.size(); LastDeducibleArgument > 0;
3906 --LastDeducibleArgument) {
3907 if (!
Deduced[LastDeducibleArgument - 1]) {
3911 bool HasDefaultArg =
false;
3912 NamedDecl *Param = FunTmpl->getTemplateParameters()->getParam(
3913 LastDeducibleArgument - 1);
3915 HasDefaultArg = TTP->hasDefaultArgument();
3917 dyn_cast<NonTypeTemplateParmDecl>(Param))
3918 HasDefaultArg = NTTP->hasDefaultArgument();
3946 Result.AddInformativeChunk(
"<");
3948 Ctx, Policy, FunTmpl,
Result, LastDeducibleArgument, 0,
3955 Result.AddInformativeChunk(
">");
3960 if (InsertParameters)
3963 Result.AddInformativeChunk(
"(");
3968 if (InsertParameters)
3971 Result.AddInformativeChunk(
")");
3973 return Result.TakeString();
3976 if (
const auto *
Template = dyn_cast<TemplateDecl>(ND)) {
3979 Result.AddTypedTextChunk(
3984 return Result.TakeString();
3987 if (
const auto *
Method = dyn_cast<ObjCMethodDecl>(ND)) {
3990 Result.AddTypedTextChunk(
3992 return Result.TakeString();
3998 Result.AddTypedTextChunk(
Result.getAllocator().CopyString(SelName));
4000 Result.AddInformativeChunk(
Result.getAllocator().CopyString(SelName));
4004 if (
Method->param_size() == 1)
4005 Result.AddTypedTextChunk(
"");
4011 PEnd =
Method->param_end();
4012 P != PEnd && Idx < Sel.
getNumArgs(); (
void)++P, ++Idx) {
4031 QualType ParamType = (*P)->getType();
4032 std::optional<ArrayRef<QualType>> ObjCSubsts;
4048 Arg += II->getName();
4051 if (
Method->isVariadic() && (P + 1) == PEnd)
4055 Result.AddTextChunk(
Result.getAllocator().CopyString(Arg));
4057 Result.AddInformativeChunk(
Result.getAllocator().CopyString(Arg));
4059 Result.AddPlaceholderChunk(
Result.getAllocator().CopyString(Arg));
4062 if (
Method->isVariadic()) {
4063 if (
Method->param_size() == 0) {
4065 Result.AddTextChunk(
", ...");
4067 Result.AddInformativeChunk(
", ...");
4069 Result.AddPlaceholderChunk(
", ...");
4075 return Result.TakeString();
4082 Result.AddTypedTextChunk(
4084 return Result.TakeString();
4095 const auto *M = dyn_cast<ObjCMethodDecl>(ND);
4107 const auto *M = dyn_cast_or_null<ObjCMethodDecl>(ND);
4108 if (!M || !M->isPropertyAccessor())
4131 auto FDecl =
Result.getFunction();
4134 if (ArgIndex < FDecl->getNumParams())
4142 unsigned CurrentArg) {
4143 unsigned ChunkIndex = 0;
4144 auto AddChunk = [&](llvm::StringRef Placeholder) {
4147 const char *
Copy =
Result.getAllocator().CopyString(Placeholder);
4148 if (ChunkIndex == CurrentArg)
4156 if (
auto *CRD = llvm::dyn_cast<CXXRecordDecl>(RD)) {
4157 for (
const auto &
Base : CRD->bases())
4158 AddChunk(
Base.getType().getAsString(Policy));
4160 for (
const auto &Field : RD->
fields())
4170 unsigned CurrentArg,
unsigned Start = 0,
bool InOptional =
false) {
4176 bool FirstParameter =
true;
4177 unsigned NumParams =
4178 Function ? Function->getNumParams() :
Prototype->getNumParams();
4180 for (
unsigned P = Start; P != NumParams; ++P) {
4181 if (Function && Function->getParamDecl(P)->hasDefaultArg() && !InOptional) {
4185 Result.getCodeCompletionTUInfo());
4186 if (!FirstParameter)
4190 PrototypeLoc, Opt, CurrentArg, P,
4199 if (Function && FirstParameter &&
4200 Function->getParamDecl(P)->isExplicitObjectParameter()) {
4205 FirstParameter =
false;
4212 std::string Placeholder;
4213 assert(P < Prototype->getNumParams());
4214 if (Function || PrototypeLoc) {
4216 Function ? Function->getParamDecl(P) : PrototypeLoc.
getParam(P);
4218 if (Param->hasDefaultArg())
4220 Context.getLangOpts());
4222 Placeholder =
Prototype->getParamType(P).getAsString(Policy);
4225 if (P == CurrentArg)
4226 Result.AddCurrentParameterChunk(
4227 Result.getAllocator().CopyString(Placeholder));
4229 Result.AddPlaceholderChunk(
Result.getAllocator().CopyString(Placeholder));
4234 Result.getCodeCompletionTUInfo());
4235 if (!FirstParameter)
4238 if (CurrentArg < NumParams)
4250 if (
const auto *
Type = dyn_cast<TemplateTypeParmDecl>(Param)) {
4252 }
else if (
const auto *
NonType = dyn_cast<NonTypeTemplateParmDecl>(Param)) {
4254 }
else if (
const auto *
Template = dyn_cast<TemplateTemplateParmDecl>(Param)) {
4258 llvm::raw_string_ostream OS(
Result);
4259 Param->print(OS, Policy);
4265 if (
const auto *CTD = dyn_cast<ClassTemplateDecl>(TD))
4266 return CTD->getTemplatedDecl()->getKindName().str();
4267 if (
const auto *VTD = dyn_cast<VarTemplateDecl>(TD))
4268 return VTD->getTemplatedDecl()->getType().getAsString(Policy);
4269 if (
const auto *FTD = dyn_cast<FunctionTemplateDecl>(TD))
4270 return FTD->getTemplatedDecl()->getReturnType().getAsString(Policy);
4285 Builder.getCodeCompletionTUInfo());
4287 if (!ResultType.empty())
4288 Builder.AddResultTypeChunk(Builder.getAllocator().CopyString(ResultType));
4289 Builder.AddTextChunk(
4295 for (
unsigned I = 0; I < Params.size(); ++I) {
4297 std::string Placeholder =
4300 Current = &OptionalBuilder;
4309 if (Current == &OptionalBuilder)
4315 Builder.AddInformativeChunk(
"()");
4316 return Builder.TakeString();
4323 bool Braced)
const {
4347 if (IncludeBriefComments) {
4354 llvm::raw_string_ostream OS(Name);
4356 Result.AddTextChunk(
Result.getAllocator().CopyString(Name));
4359 Result.AddResultTypeChunk(
Result.getAllocator().CopyString(
4374 return Result.TakeString();
4379 bool PreferredTypeIsPointer) {
4383 if (MacroName ==
"nil" || MacroName ==
"NULL" || MacroName ==
"Nil") {
4385 if (PreferredTypeIsPointer)
4389 else if (MacroName ==
"YES" || MacroName ==
"NO" || MacroName ==
"true" ||
4390 MacroName ==
"false")
4393 else if (MacroName ==
"bool")
4406 case Decl::EnumConstant:
4410 case Decl::Function:
4412 case Decl::ObjCCategory:
4414 case Decl::ObjCCategoryImpl:
4416 case Decl::ObjCImplementation:
4419 case Decl::ObjCInterface:
4421 case Decl::ObjCIvar:
4423 case Decl::ObjCMethod:
4427 case Decl::CXXMethod:
4429 case Decl::CXXConstructor:
4431 case Decl::CXXDestructor:
4433 case Decl::CXXConversion:
4435 case Decl::ObjCProperty:
4437 case Decl::ObjCProtocol:
4443 case Decl::TypeAlias:
4445 case Decl::TypeAliasTemplate:
4449 case Decl::Namespace:
4451 case Decl::NamespaceAlias:
4453 case Decl::TemplateTypeParm:
4455 case Decl::NonTypeTemplateParm:
4457 case Decl::TemplateTemplateParm:
4459 case Decl::FunctionTemplate:
4461 case Decl::ClassTemplate:
4463 case Decl::AccessSpec:
4465 case Decl::ClassTemplatePartialSpecialization:
4467 case Decl::UsingDirective:
4469 case Decl::StaticAssert:
4473 case Decl::TranslationUnit:
4477 case Decl::UnresolvedUsingValue:
4478 case Decl::UnresolvedUsingTypename:
4481 case Decl::UsingEnum:
4484 case Decl::ObjCPropertyImpl:
4492 llvm_unreachable(
"Unexpected Kind!");
4497 case Decl::ObjCTypeParam:
4503 case Decl::LinkageSpec:
4507 if (
const auto *TD = dyn_cast<TagDecl>(D)) {
4508 switch (TD->getTagKind()) {
4526 bool LoadExternal,
bool IncludeUndefined,
4527 bool TargetTypeIsPointer =
false) {
4530 Results.EnterNewScope();
4532 for (
const auto &M : PP.
macros(LoadExternal)) {
4534 if (IncludeUndefined || MD) {
4542 TargetTypeIsPointer)));
4546 Results.ExitScope();
4550 ResultBuilder &Results) {
4553 Results.EnterNewScope();
4557 if (LangOpts.C99 || LangOpts.CPlusPlus11)
4559 Results.ExitScope();
4566 unsigned NumResults) {
4571static CodeCompletionContext
4629 llvm_unreachable(
"Invalid ParserCompletionContext!");
4641 ResultBuilder &Results) {
4647 CXXMethodDecl *Method = dyn_cast<CXXMethodDecl>(CurContext);
4648 if (!Method || !Method->isVirtual())
4653 for (
auto *P : Method->parameters())
4654 if (!P->getDeclName())
4660 Results.getCodeCompletionTUInfo());
4661 if (Overridden->getCanonicalDecl() == Method->getCanonicalDecl())
4667 S.
Context, CurContext, Overridden->getDeclContext());
4670 llvm::raw_string_ostream OS(Str);
4671 NNS.
print(OS, Policy);
4672 Builder.AddTextChunk(Results.getAllocator().CopyString(Str));
4674 }
else if (!InContext->
Equals(Overridden->getDeclContext()))
4677 Builder.AddTypedTextChunk(
4678 Results.getAllocator().CopyString(Overridden->getNameAsString()));
4680 bool FirstParam =
true;
4681 for (
auto *P : Method->parameters()) {
4687 Builder.AddPlaceholderChunk(
4688 Results.getAllocator().CopyString(P->getIdentifier()->getName()));
4694 Results.Ignore(Overridden);
4704 Results.EnterNewScope();
4712 SemaRef.PP.getHeaderSearchInfo().collectAllModules(Modules);
4713 for (
unsigned I = 0, N = Modules.size(); I != N; ++I) {
4714 Builder.AddTypedTextChunk(
4715 Builder.getAllocator().CopyString(Modules[I]->Name));
4716 Results.AddResult(
Result(
4729 Builder.AddTypedTextChunk(
4730 Builder.getAllocator().CopyString(Submodule->Name));
4731 Results.AddResult(
Result(
4738 Results.ExitScope();
4740 Results.getCompletionContext(), Results.data(),
4749 Results.EnterNewScope();
4754 switch (CompletionContext) {
4764 Results.setFilter(&ResultBuilder::IsOrdinaryNonValueName);
4774 Results.setFilter(&ResultBuilder::IsOrdinaryName);
4776 Results.setFilter(&ResultBuilder::IsOrdinaryNonTypeName);
4787 auto ThisType =
SemaRef.getCurrentThisType();
4788 if (ThisType.isNull()) {
4790 if (
auto *MethodDecl = llvm::dyn_cast_if_present<CXXMethodDecl>(
4791 SemaRef.getCurFunctionDecl()))
4792 Results.setExplicitObjectMemberFn(
4793 MethodDecl->isExplicitObjectMemberFunction());
4797 Results.setObjectTypeQualifiers(ThisType->getPointeeType().getQualifiers(),
4801 CodeCompletionDeclConsumer Consumer(Results,
SemaRef.CurContext);
4802 SemaRef.LookupVisibleDecls(S,
SemaRef.LookupOrdinaryName, Consumer,
4807 Results.ExitScope();
4809 switch (CompletionContext) {
4837 Results.getCompletionContext(), Results.data(),
4844 bool AtArgumentExpression,
bool IsSuper,
4845 ResultBuilder &Results);
4848 bool AllowNonIdentifiers,
4849 bool AllowNestedNameSpecifiers) {
4851 ResultBuilder Results(
4854 AllowNestedNameSpecifiers
4859 Results.EnterNewScope();
4862 Results.AddResult(
Result(
"const"));
4863 Results.AddResult(
Result(
"volatile"));
4865 Results.AddResult(
Result(
"restrict"));
4871 Results.AddResult(
"final");
4873 if (AllowNonIdentifiers) {
4874 Results.AddResult(
Result(
"operator"));
4878 if (AllowNestedNameSpecifiers) {
4879 Results.allowNestedNameSpecifiers();
4880 Results.setFilter(&ResultBuilder::IsImpossibleToSatisfy);
4881 CodeCompletionDeclConsumer Consumer(Results,
SemaRef.CurContext);
4885 Results.setFilter(
nullptr);
4888 Results.ExitScope();
4894 if (AllowNonIdentifiers && !AllowNestedNameSpecifiers &&
4905 if (!T.get().isNull() && T.get()->isObjCObjectOrInterfaceType())
4913 Results.getCompletionContext(), Results.data(),
4918 if (
Scope ==
"clang")
4926 if (
Scope ==
"_Clang")
4928 if (
Scope ==
"__gnu__")
4952 llvm::StringRef InScopeName;
4953 bool InScopeUnderscore =
false;
4955 InScopeName = InScope->
getName();
4957 InScopeName = NoUnderscore;
4958 InScopeUnderscore =
true;
4965 llvm::DenseSet<llvm::StringRef> FoundScopes;
4967 if (A.IsTargetSpecific &&
4972 for (
const auto &S : A.Spellings) {
4973 if (S.Syntax != Syntax)
4975 llvm::StringRef Name = S.NormalizedFullName;
4976 llvm::StringRef
Scope;
4979 std::tie(
Scope, Name) = Name.split(
"::");
4981 std::swap(Name,
Scope);
4987 if (!
Scope.empty() && FoundScopes.insert(
Scope).second) {
4998 if (!InScopeName.empty()) {
4999 if (
Scope != InScopeName)
5004 auto Add = [&](llvm::StringRef
Scope, llvm::StringRef Name,
5007 Results.getCodeCompletionTUInfo());
5009 if (!
Scope.empty()) {
5018 Builder.AddTypedTextChunk(Results.getAllocator().CopyString(
Text));
5020 if (!A.ArgNames.empty()) {
5023 for (
const char *Arg : A.ArgNames) {
5027 Builder.AddPlaceholderChunk(Arg);
5032 Results.AddResult(Builder.TakeString());
5039 if (!InScopeUnderscore)
5040 Add(
Scope, Name,
false);
5045 if (!(InScope && !InScopeUnderscore) && SyntaxSupportsGuards) {
5046 if (
Scope.empty()) {
5047 Add(
Scope, Name,
true);
5052 Add(GuardedScope, Name,
true);
5062 for (
const auto &Entry : ParsedAttrInfoRegistry::entries())
5063 AddCompletions(*Entry.instantiate());
5066 Results.getCompletionContext(), Results.data(),
5085struct CoveredEnumerators {
5093 const CoveredEnumerators &Enumerators) {
5095 if (Context.getLangOpts().CPlusPlus && !Qualifier && Enumerators.Seen.empty()) {
5102 Results.EnterNewScope();
5103 for (
auto *E :
Enum->enumerators()) {
5104 if (Enumerators.Seen.count(E))
5108 Results.AddResult(R, CurContext,
nullptr,
false);
5110 Results.ExitScope();
5116 assert(!T.isNull());
5120 if (
auto *
Specialization = T->getAs<TemplateSpecializationType>()) {
5129 if (T->isPointerType())
5130 T = T->getPointeeType();
5139 if (!Results.includeCodePatterns())
5142 Results.getCodeCompletionTUInfo());
5147 if (!Parameters.empty()) {
5156 constexpr llvm::StringLiteral NamePlaceholder =
"!#!NAME_GOES_HERE!#!";
5157 std::string
Type = std::string(NamePlaceholder);
5159 llvm::StringRef Prefix, Suffix;
5160 std::tie(Prefix, Suffix) = llvm::StringRef(
Type).split(NamePlaceholder);
5161 Prefix = Prefix.rtrim();
5162 Suffix = Suffix.ltrim();
5185 ResultBuilder Results(
5189 Data.IsParenthesized
5192 Data.PreferredType));
5195 if (
Data.ObjCCollection)
5196 Results.setFilter(&ResultBuilder::IsObjCCollection);
5197 else if (
Data.IntegralConstantExpression)
5198 Results.setFilter(&ResultBuilder::IsIntegralConstantValue);
5200 Results.setFilter(&ResultBuilder::IsOrdinaryName);
5202 Results.setFilter(&ResultBuilder::IsOrdinaryNonTypeName);
5204 if (!
Data.PreferredType.isNull())
5205 Results.setPreferredType(
Data.PreferredType.getNonReferenceType());
5208 for (
unsigned I = 0, N =
Data.IgnoreDecls.size(); I != N; ++I)
5209 Results.Ignore(
Data.IgnoreDecls[I]);
5211 CodeCompletionDeclConsumer Consumer(Results,
SemaRef.CurContext);
5212 Consumer.setIsAddressOfOperand(IsAddressOfOperand);
5217 Results.EnterNewScope();
5219 Results.ExitScope();
5221 bool PreferredTypeIsPointer =
false;
5222 if (!
Data.PreferredType.isNull()) {
5223 PreferredTypeIsPointer =
Data.PreferredType->isAnyPointerType() ||
5224 Data.PreferredType->isMemberPointerType() ||
5225 Data.PreferredType->isBlockPointerType();
5226 if (
auto *
Enum =
Data.PreferredType->getAsEnumDecl()) {
5230 CoveredEnumerators());
5235 !
Data.IntegralConstantExpression)
5240 PreferredTypeIsPointer);
5250 Results.getCompletionContext(), Results.data(),
5256 bool IsParenthesized,
5257 bool IsAddressOfOperand) {
5260 IsAddressOfOperand);
5285 if (Protocol->hasDefinition())
5286 return Protocol->getDefinition();
5300 Builder.AddResultTypeChunk(
5302 Policy, Builder.getAllocator()));
5308 Builder.AddPlaceholderChunk(
"...");
5310 for (
unsigned I = 0, N = BlockLoc.
getNumParams(); I != N; ++I) {
5315 std::string PlaceholderStr =
5318 if (I == N - 1 && BlockProtoLoc &&
5320 PlaceholderStr +=
", ...";
5323 Builder.AddPlaceholderChunk(
5324 Builder.getAllocator().CopyString(PlaceholderStr));
5334 bool AllowNullaryMethods,
DeclContext *CurContext,
5336 bool IsBaseExprStatement =
false,
5337 bool IsClassProperty =
false,
bool InOriginalClass =
true) {
5345 if (!AddedProperties.insert(P->getIdentifier()).second)
5350 if (!P->getType().getTypePtr()->isBlockPointerType() ||
5351 !IsBaseExprStatement) {
5353 Result(P, Results.getBasePriority(P), std::nullopt);
5354 if (!InOriginalClass)
5356 Results.MaybeAddResult(R, CurContext);
5368 Result(P, Results.getBasePriority(P), std::nullopt);
5369 if (!InOriginalClass)
5371 Results.MaybeAddResult(R, CurContext);
5378 Results.getCodeCompletionTUInfo());
5381 BlockLoc, BlockProtoLoc);
5382 Result R =
Result(Builder.TakeString(), P, Results.getBasePriority(P));
5383 if (!InOriginalClass)
5385 Results.MaybeAddResult(R, CurContext);
5389 if (!P->isReadOnly()) {
5391 Results.getCodeCompletionTUInfo());
5395 Builder.AddTypedTextChunk(
5396 Results.getAllocator().CopyString(P->getName()));
5401 BlockProtoLoc,
true);
5403 Builder.AddPlaceholderChunk(
5404 Builder.getAllocator().CopyString(PlaceholderStr));
5412 Result(Builder.TakeString(), P,
5413 Results.getBasePriority(P) +
5417 if (!InOriginalClass)
5419 Results.MaybeAddResult(R, CurContext);
5423 if (IsClassProperty) {
5432 if (AllowNullaryMethods) {
5437 const IdentifierInfo *Name = M->getSelector().getIdentifierInfoForSlot(0);
5440 if (!AddedProperties.insert(Name).second)
5443 Results.getCodeCompletionTUInfo());
5445 Builder.AddTypedTextChunk(
5446 Results.getAllocator().CopyString(Name->
getName()));
5449 if (!InOriginalClass)
5451 Results.MaybeAddResult(R, CurContext);
5454 if (IsClassProperty) {
5455 for (
const auto *M : Container->
methods()) {
5459 if (!M->getSelector().isUnarySelector() ||
5460 M->getReturnType()->isVoidType() || M->isInstanceMethod())
5465 for (
auto *M : Container->
methods()) {
5466 if (M->getSelector().isUnarySelector())
5474 for (
auto *P : Protocol->protocols())
5476 CurContext, AddedProperties, Results,
5477 IsBaseExprStatement, IsClassProperty,
5480 dyn_cast<ObjCInterfaceDecl>(Container)) {
5481 if (AllowCategories) {
5483 for (
auto *Cat : IFace->known_categories())
5485 CurContext, AddedProperties, Results,
5486 IsBaseExprStatement, IsClassProperty,
5491 for (
auto *I : IFace->all_referenced_protocols())
5493 CurContext, AddedProperties, Results,
5494 IsBaseExprStatement, IsClassProperty,
5498 if (IFace->getSuperClass())
5500 AllowNullaryMethods, CurContext, AddedProperties,
5501 Results, IsBaseExprStatement, IsClassProperty,
5503 }
else if (
const auto *Category =
5504 dyn_cast<ObjCCategoryDecl>(Container)) {
5506 for (
auto *P : Category->protocols())
5508 CurContext, AddedProperties, Results,
5509 IsBaseExprStatement, IsClassProperty,
5518 std::optional<FixItHint> AccessOpFixIt) {
5521 Results.setObjectTypeQualifiers(BaseType.getQualifiers(), BaseKind);
5524 Results.allowNestedNameSpecifiers();
5525 std::vector<FixItHint> FixIts;
5527 FixIts.emplace_back(*AccessOpFixIt);
5528 CodeCompletionDeclConsumer Consumer(Results, RD, BaseType, std::move(FixIts));
5536 if (!Results.empty()) {
5540 bool IsDependent = BaseType->isDependentType();
5542 for (
Scope *DepScope = S; DepScope; DepScope = DepScope->
getParent())
5560 BaseType = Resolver.
simplifyType(BaseType,
nullptr,
false);
5561 return dyn_cast_if_present<RecordDecl>(
5597 const IdentifierInfo *Name =
nullptr;
5602 std::optional<SmallVector<QualType, 1>> ArgTypes;
5604 enum AccessOperator {
5610 const TypeConstraint *ResultType =
nullptr;
5616 CodeCompletionString *render(Sema &S, CodeCompletionAllocator &Alloc,
5617 CodeCompletionTUInfo &Info)
const {
5618 CodeCompletionBuilder B(Alloc, Info);
5621 std::string AsString;
5623 llvm::raw_string_ostream
OS(AsString);
5624 QualType ExactType = deduceType(*ResultType);
5630 B.AddResultTypeChunk(
Alloc.CopyString(AsString));
5633 B.AddTypedTextChunk(
Alloc.CopyString(Name->
getName()));
5638 for (QualType Arg : *ArgTypes) {
5645 B.AddPlaceholderChunk(
Alloc.CopyString(
5650 return B.TakeString();
5657 ConceptInfo(
const TemplateTypeParmType &BaseType, Scope *S) {
5658 auto *TemplatedEntity = getTemplatedEntity(BaseType.getDecl(), S);
5659 for (
const AssociatedConstraint &AC :
5660 constraintsForTemplatedEntity(TemplatedEntity))
5661 believe(AC.ConstraintExpr, &BaseType);
5664 std::vector<Member> members() {
5665 std::vector<Member> Results;
5666 for (
const auto &E : this->Results)
5667 Results.push_back(E.second);
5668 llvm::sort(Results, [](
const Member &L,
const Member &R) {
5669 return L.Name->getName() <
R.Name->getName();
5676 void believe(
const Expr *E,
const TemplateTypeParmType *T) {
5679 if (
auto *CSE = dyn_cast<ConceptSpecializationExpr>(E)) {
5690 ConceptDecl *CD = CSE->getNamedConcept();
5693 for (
const auto &Arg : CSE->getTemplateArguments()) {
5694 if (Index >= Params->
size())
5696 if (isApprox(Arg, T)) {
5697 auto *TTPD = dyn_cast<TemplateTypeParmDecl>(Params->
getParam(Index));
5709 }
else if (
auto *BO = dyn_cast<BinaryOperator>(E)) {
5712 if (BO->getOpcode() == BO_LAnd || BO->getOpcode() == BO_LOr) {
5713 believe(BO->getLHS(), T);
5714 believe(BO->getRHS(), T);
5716 }
else if (
auto *RE = dyn_cast<RequiresExpr>(E)) {
5718 for (
const concepts::Requirement *Req : RE->getRequirements()) {
5719 if (!Req->isDependent())
5723 if (
auto *TR = dyn_cast<concepts::TypeRequirement>(Req)) {
5725 QualType AssertedType = TR->getType()->getType();
5726 ValidVisitor(
this, T).TraverseType(AssertedType);
5727 }
else if (
auto *ER = dyn_cast<concepts::ExprRequirement>(Req)) {
5728 ValidVisitor Visitor(
this, T);
5732 if (ER->getReturnTypeRequirement().isTypeConstraint()) {
5734 ER->getReturnTypeRequirement().getTypeConstraint();
5735 Visitor.OuterExpr = ER->getExpr();
5737 Visitor.TraverseStmt(ER->getExpr());
5738 }
else if (
auto *NR = dyn_cast<concepts::NestedRequirement>(Req)) {
5739 believe(NR->getConstraintExpr(), T);
5749 const TemplateTypeParmType *T;
5751 CallExpr *Caller =
nullptr;
5756 Expr *OuterExpr =
nullptr;
5757 const TypeConstraint *OuterType =
nullptr;
5759 ValidVisitor(ConceptInfo *Outer,
const TemplateTypeParmType *T)
5760 : Outer(Outer), T(T) {
5766 VisitCXXDependentScopeMemberExpr(CXXDependentScopeMemberExpr *E)
override {
5769 if (
Base->isPointerType() && IsArrow) {
5771 Base =
Base->getPointeeType().getTypePtr();
5773 if (isApprox(Base, T))
5774 addValue(E, E->
getMember(), IsArrow ? Member::Arrow : Member::Dot);
5779 bool VisitDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E)
override {
5781 if (
Qualifier.getKind() == NestedNameSpecifier::Kind::Type &&
5788 bool VisitDependentNameType(DependentNameType *DNT)
override {
5789 NestedNameSpecifier Q = DNT->getQualifier();
5790 if (Q.
getKind() == NestedNameSpecifier::Kind::Type &&
5792 addType(DNT->getIdentifier());
5801 if (NNS.
getKind() == NestedNameSpecifier::Kind::Type) {
5803 if (NestedNameSpecifier Q = NNST->
getPrefix();
5804 Q.
getKind() == NestedNameSpecifier::Kind::Type &&
5806 if (
const auto *DNT = dyn_cast_or_null<DependentNameType>(NNST))
5807 addType(DNT->getIdentifier());
5818 bool VisitCallExpr(CallExpr *CE)
override {
5825 void addResult(
Member &&M) {
5826 auto R = Outer->Results.try_emplace(M.Name);
5831 std::make_tuple(M.ArgTypes.has_value(), M.ResultType !=
nullptr,
5832 M.Operator) > std::make_tuple(O.ArgTypes.has_value(),
5833 O.ResultType !=
nullptr,
5838 void addType(
const IdentifierInfo *Name) {
5843 M.Operator = Member::Colons;
5844 addResult(std::move(M));
5847 void addValue(Expr *E, DeclarationName Name,
5848 Member::AccessOperator Operator) {
5853 Result.Operator = Operator;
5856 if (Caller !=
nullptr && Callee == E) {
5857 Result.ArgTypes.emplace();
5858 for (
const auto *Arg : Caller->
arguments())
5859 Result.ArgTypes->push_back(Arg->getType());
5860 if (Caller == OuterExpr) {
5861 Result.ResultType = OuterType;
5865 Result.ResultType = OuterType;
5867 addResult(std::move(
Result));
5871 static bool isApprox(
const TemplateArgument &Arg,
const Type *T) {
5876 static bool isApprox(
const Type *T1,
const Type *T2) {
5885 static DeclContext *getTemplatedEntity(
const TemplateTypeParmDecl *D,
5889 Scope *Inner =
nullptr;
5892 return Inner ? Inner->
getEntity() :
nullptr;
5901 static SmallVector<AssociatedConstraint, 1>
5902 constraintsForTemplatedEntity(DeclContext *DC) {
5903 SmallVector<AssociatedConstraint, 1>
Result;
5908 TD->getAssociatedConstraints(
Result);
5910 if (
const auto *CTPSD =
5911 dyn_cast<ClassTemplatePartialSpecializationDecl>(DC))
5912 CTPSD->getAssociatedConstraints(
Result);
5913 if (
const auto *VTPSD = dyn_cast<VarTemplatePartialSpecializationDecl>(DC))
5914 VTPSD->getAssociatedConstraints(
Result);
5920 static QualType deduceType(
const TypeConstraint &T) {
5926 if (Args->getNumTemplateArgs() == 1) {
5927 const auto &Arg = Args->arguments().front().getArgument();
5934 llvm::DenseMap<const IdentifierInfo *, Member> Results;
5941QualType getApproximateType(
const Expr *E, HeuristicResolver &Resolver) {
5955Expr *unwrapParenList(Expr *Base) {
5956 if (
auto *PLE = llvm::dyn_cast_or_null<ParenListExpr>(Base)) {
5957 if (PLE->getNumExprs() == 0)
5959 Base = PLE->getExpr(PLE->getNumExprs() - 1);
5968 bool IsBaseExprStatement,
QualType PreferredType) {
5970 OtherOpBase = unwrapParenList(OtherOpBase);
5975 SemaRef.PerformMemberExprBaseConversion(
Base, IsArrow);
5979 getApproximateType(ConvertedBase.
get(),
Resolver);
5985 !PointeeType.isNull()) {
5986 ConvertedBaseType = PointeeType;
6005 &ResultBuilder::IsMember);
6007 auto DoCompletion = [&](
Expr *
Base,
bool IsArrow,
6008 std::optional<FixItHint> AccessOpFixIt) ->
bool {
6013 SemaRef.PerformMemberExprBaseConversion(
Base, IsArrow);
6019 if (BaseType.isNull())
6025 !PointeeType.isNull()) {
6026 BaseType = PointeeType;
6028 }
else if (BaseType->isObjCObjectPointerType() ||
6029 BaseType->isTemplateTypeParmType()) {
6038 RD, std::move(AccessOpFixIt));
6039 }
else if (
const auto *TTPT =
6040 dyn_cast<TemplateTypeParmType>(BaseType.getTypePtr())) {
6042 IsArrow ? ConceptInfo::Member::Arrow : ConceptInfo::Member::Dot;
6043 for (
const auto &R : ConceptInfo(*TTPT, S).members()) {
6044 if (R.Operator != Operator)
6050 Result.FixIts.push_back(*AccessOpFixIt);
6051 Results.AddResult(std::move(
Result));
6053 }
else if (!IsArrow && BaseType->isObjCObjectPointerType()) {
6057 if (AccessOpFixIt) {
6065 assert(ObjCPtr &&
"Non-NULL pointer guaranteed above!");
6068 AddedProperties, Results, IsBaseExprStatement);
6074 SemaRef.CurContext, AddedProperties, Results,
6075 IsBaseExprStatement,
false,
6077 }
else if ((IsArrow && BaseType->isObjCObjectPointerType()) ||
6078 (!IsArrow && BaseType->isObjCObjectType())) {
6082 if (AccessOpFixIt) {
6088 Class = ObjCPtr->getInterfaceDecl();
6094 CodeCompletionDeclConsumer Consumer(Results,
Class, BaseType);
6095 Results.setFilter(&ResultBuilder::IsObjCIvar);
6107 Results.EnterNewScope();
6109 bool CompletionSucceded = DoCompletion(
Base, IsArrow, std::nullopt);
6113 CompletionSucceded |= DoCompletion(
6114 OtherOpBase, !IsArrow,
6118 Results.ExitScope();
6120 if (!CompletionSucceded)
6125 Results.getCompletionContext(), Results.data(),
6131 bool IsBaseExprStatement) {
6134 SemaRef.ObjC().getObjCInterfaceDecl(ClassNamePtr, ClassNameLoc);
6141 &ResultBuilder::IsMember);
6142 Results.EnterNewScope();
6146 AddedProperties, Results, IsBaseExprStatement,
6148 Results.ExitScope();
6150 Results.getCompletionContext(), Results.data(),
6158 ResultBuilder::LookupFilter Filter =
nullptr;
6163 Filter = &ResultBuilder::IsEnum;
6168 Filter = &ResultBuilder::IsUnion;
6175 Filter = &ResultBuilder::IsClassOrStruct;
6180 llvm_unreachable(
"Unknown type specifier kind in CodeCompleteTag");
6185 CodeCompletionDeclConsumer Consumer(Results,
SemaRef.CurContext);
6188 Results.setFilter(Filter);
6195 Results.setFilter(&ResultBuilder::IsNestedNameSpecifier);
6202 Results.getCompletionContext(), Results.data(),
6209 Results.AddResult(
"const");
6211 Results.AddResult(
"volatile");
6213 Results.AddResult(
"restrict");
6215 Results.AddResult(
"_Atomic");
6217 Results.AddResult(
"__unaligned");
6224 Results.EnterNewScope();
6226 Results.ExitScope();
6228 Results.getCompletionContext(), Results.data(),
6237 Results.EnterNewScope();
6240 Results.AddResult(
"noexcept");
6244 Results.AddResult(
"final");
6246 Results.AddResult(
"override");
6249 Results.ExitScope();
6251 Results.getCompletionContext(), Results.data(),
6264 SemaRef.getCurFunction()->SwitchStack.back().getPointer();
6272 Data.IntegralConstantExpression =
true;
6281 CoveredEnumerators Enumerators;
6283 SC = SC->getNextSwitchCase()) {
6284 CaseStmt *Case = dyn_cast<CaseStmt>(SC);
6289 if (
auto *DRE = dyn_cast<DeclRefExpr>(CaseVal))
6291 dyn_cast<EnumConstantDecl>(DRE->getDecl())) {
6311 Enumerators.SuggestedQualifier = DRE->getQualifier();
6326 Results.getCompletionContext(), Results.data(),
6331 if (Args.size() && !Args.data())
6334 for (
unsigned I = 0; I != Args.size(); ++I)
6355 if (Candidate.Function) {
6356 if (Candidate.Function->isDeleted())
6359 Candidate.Function) &&
6360 Candidate.Function->getNumParams() <= ArgSize &&
6369 if (Candidate.Viable)
6383 for (
auto &Candidate : Candidates) {
6384 QualType CandidateParamType = Candidate.getParamType(N);
6385 if (CandidateParamType.
isNull())
6387 if (ParamType.
isNull()) {
6388 ParamType = CandidateParamType;
6405 if (Candidates.empty())
6409 SemaRef, CurrentArg, Candidates.data(), Candidates.size(), OpenParLoc,
6417 Fn = unwrapParenList(Fn);
6428 auto ArgsWithoutDependentTypes =
6433 Expr *NakedFn = Fn->IgnoreParenCasts();
6439 if (
auto ULE = dyn_cast<UnresolvedLookupExpr>(NakedFn)) {
6440 SemaRef.AddOverloadedCallCandidates(ULE, ArgsWithoutDependentTypes,
6443 }
else if (
auto UME = dyn_cast<UnresolvedMemberExpr>(NakedFn)) {
6445 if (UME->hasExplicitTemplateArgs()) {
6446 UME->copyTemplateArgumentsInto(TemplateArgsBuffer);
6447 TemplateArgs = &TemplateArgsBuffer;
6452 1, UME->isImplicitAccess() ?
nullptr : UME->getBase());
6453 ArgExprs.append(ArgsWithoutDependentTypes.begin(),
6454 ArgsWithoutDependentTypes.end());
6456 Decls.
append(UME->decls_begin(), UME->decls_end());
6457 const bool FirstArgumentIsBase = !UME->isImplicitAccess() && UME->getBase();
6458 SemaRef.AddFunctionCandidates(Decls, ArgExprs, CandidateSet, TemplateArgs,
6461 FirstArgumentIsBase);
6464 if (
auto *MCE = dyn_cast<MemberExpr>(NakedFn))
6465 FD = dyn_cast<FunctionDecl>(MCE->getMemberDecl());
6466 else if (
auto *DRE = dyn_cast<DeclRefExpr>(NakedFn))
6467 FD = dyn_cast<FunctionDecl>(DRE->getDecl());
6473 SemaRef.AddOverloadCandidate(FD,
6475 ArgsWithoutDependentTypes, CandidateSet,
6485 getASTContext().DeclarationNames.getCXXOperatorName(OO_Call);
6487 SemaRef.LookupQualifiedName(R, DC);
6488 R.suppressDiagnostics();
6490 ArgExprs.append(ArgsWithoutDependentTypes.begin(),
6491 ArgsWithoutDependentTypes.end());
6492 SemaRef.AddFunctionCandidates(R.asUnresolvedSet(), ArgExprs,
6504 if (!T->getPointeeType().isNull())
6508 if (!
SemaRef.TooManyArguments(FP->getNumParams(),
6509 ArgsWithoutDependentTypes.size(),
6545static std::optional<unsigned>
6548 static constexpr unsigned Invalid = std::numeric_limits<unsigned>::max();
6554 unsigned ArgsAfterDesignator = 0;
6555 for (
const Expr *Arg : Args) {
6556 if (
const auto *DIE = dyn_cast<DesignatedInitExpr>(Arg)) {
6557 if (DIE->size() == 1 && DIE->getDesignator(0)->isFieldDesignator()) {
6558 DesignatedFieldName = DIE->getDesignator(0)->getFieldName();
6559 ArgsAfterDesignator = 0;
6566 ++ArgsAfterDesignator;
6569 if (!DesignatedFieldName)
6570 return std::nullopt;
6574 unsigned DesignatedIndex = 0;
6575 const FieldDecl *DesignatedField =
nullptr;
6576 for (
const auto *Field :
Aggregate.getAggregate()->fields()) {
6577 if (Field->getIdentifier() == DesignatedFieldName) {
6578 DesignatedField = Field;
6583 if (!DesignatedField)
6587 unsigned AggregateSize =
Aggregate.getNumParams();
6588 while (DesignatedIndex < AggregateSize &&
6589 Aggregate.getParamDecl(DesignatedIndex) != DesignatedField)
6593 return DesignatedIndex + ArgsAfterDesignator + 1;
6616 if (Braced && !RD->
isUnion() &&
6621 if (
auto NextIndex =
6624 if (*NextIndex >= AggregateSize)
6626 Results.push_back(AggregateSig);
6632 if (Args.size() < AggregateSize)
6633 Results.push_back(AggregateSig);
6643 if (
auto *FD = dyn_cast<FunctionDecl>(
C)) {
6647 SemaRef.isInitListConstructor(FD))
6654 }
else if (
auto *FTD = dyn_cast<FunctionTemplateDecl>(
C)) {
6656 SemaRef.isInitListConstructor(FTD->getTemplatedDecl()))
6659 SemaRef.AddTemplateOverloadCandidate(
6661 nullptr, Args, CandidateSet,
6682 dyn_cast<CXXConstructorDecl>(ConstructorDecl);
6687 Constructor->getParent(), SS, TemplateTypeTy, II))
6689 MemberDecl->getLocation(), ArgExprs,
6690 OpenParLoc, Braced);
6698 if (Index < Params.
size())
6701 Param = Params.
asArray().back();
6707 return llvm::isa<TemplateTypeParmDecl>(Param);
6709 return llvm::isa<NonTypeTemplateParmDecl>(Param);
6711 return llvm::isa<TemplateTemplateParmDecl>(Param);
6713 llvm_unreachable(
"Unhandled switch case");
6725 bool Matches =
true;
6726 for (
unsigned I = 0; I < Args.size(); ++I) {
6733 Results.emplace_back(TD);
6737 if (
const auto *TD =
Template.getAsTemplateDecl()) {
6739 }
else if (
const auto *OTS =
Template.getAsOverloadedTemplate()) {
6741 if (
const auto *TD = llvm::dyn_cast<TemplateDecl>(ND))
6752 if (
const auto *FD = llvm::dyn_cast<FieldDecl>(
Member))
6754 if (
const auto *IFD = llvm::dyn_cast<IndirectFieldDecl>(
Member))
6755 return IFD->getAnonField();
6766 if (BaseType.isNull())
6770 if (D.isArrayDesignator() || D.isArrayRangeDesignator()) {
6771 if (BaseType->isDependentType()) {
6772 BaseType = Context.DependentTy;
6775 const ArrayType *AT = Context.getAsArrayType(BaseType);
6782 assert(D.isFieldDesignator());
6783 if (BaseType->isDependentType()) {
6784 BaseType = Context.DependentTy;
6792 const FieldDecl *MemberDecl = LookupField(RD, D);
6805 if (BaseType.isNull())
6808 if (!RD || RD->fields().empty())
6816 Results.EnterNewScope();
6817 for (
const Decl *D : RD->decls()) {
6819 if (
auto *IFD = dyn_cast<IndirectFieldDecl>(D))
6820 FD = IFD->getAnonField();
6821 else if (
auto *DFD = dyn_cast<FieldDecl>(D))
6828 ResultBuilder::Result
Result(FD, Results.getBasePriority(FD));
6831 Results.ExitScope();
6833 Results.getCompletionContext(), Results.data(),
6845 SemaRef.LookupQualifiedName(R, RD);
6850 if (
auto *FD = dyn_cast<FieldDecl>(ND))
6852 if (
auto *IFD = dyn_cast<IndirectFieldDecl>(ND))
6853 return IFD->getAnonField();
6859 if (BaseType.isNull())
6870 &ResultBuilder::IsOffsetofField);
6872 Results.EnterNewScope();
6873 CodeCompletionDeclConsumer Consumer(Results, RD, BaseType);
6881 Results.ExitScope();
6884 Results.getCompletionContext(), Results.data(),
6889 ValueDecl *VD = dyn_cast_or_null<ValueDecl>(D);
6898 Data.IgnoreDecls.push_back(VD);
6908 Results.getCodeCompletionTUInfo());
6910 if (!AfterExclaim) {
6911 if (Results.includeCodePatterns()) {
6912 Builder.AddTypedTextChunk(
"constexpr");
6915 Builder.AddPlaceholderChunk(
"condition");
6920 Builder.AddPlaceholderChunk(
"statements");
6923 Results.AddResult({Builder.TakeString()});
6925 Results.AddResult({
"constexpr"});
6930 if (Results.includeCodePatterns()) {
6931 Builder.AddTypedTextChunk(
"consteval");
6935 Builder.AddPlaceholderChunk(
"statements");
6938 Results.AddResult({Builder.TakeString()});
6940 Results.AddResult({
"consteval"});
6945 Results.getCompletionContext(), Results.data(),
6953 Results.setFilter(&ResultBuilder::IsOrdinaryName);
6954 Results.EnterNewScope();
6956 CodeCompletionDeclConsumer Consumer(Results,
SemaRef.CurContext);
6965 Results.getCodeCompletionTUInfo());
6967 auto AddElseBodyPattern = [&] {
6972 Builder.AddPlaceholderChunk(
"statements");
6978 Builder.AddPlaceholderChunk(
"statement");
6982 Builder.AddTypedTextChunk(
"else");
6983 if (Results.includeCodePatterns())
6984 AddElseBodyPattern();
6985 Results.AddResult(Builder.TakeString());
6988 Builder.AddTypedTextChunk(
"else if");
6992 Builder.AddPlaceholderChunk(
"condition");
6994 Builder.AddPlaceholderChunk(
"expression");
6996 if (Results.includeCodePatterns()) {
6997 AddElseBodyPattern();
6999 Results.AddResult(Builder.TakeString());
7001 Results.ExitScope();
7010 Results.getCompletionContext(), Results.data(),
7016 bool IsAddressOfOperand,
bool IsInDeclarationContext,
QualType BaseType,
7035 if (!PreferredType.
isNull())
7036 DummyResults.setPreferredType(PreferredType);
7038 CodeCompletionDeclConsumer Consumer(DummyResults, S->
getEntity(),
7045 DummyResults.getCompletionContext(),
nullptr, 0);
7052 std::optional<Sema::ContextRAII> SimulateContext;
7055 if (IsInDeclarationContext && Ctx !=
nullptr)
7056 SimulateContext.emplace(
SemaRef, Ctx);
7062 if (Ctx ==
nullptr ||
SemaRef.RequireCompleteDeclContext(SS, Ctx))
7068 if (!PreferredType.
isNull())
7069 Results.setPreferredType(PreferredType);
7070 Results.EnterNewScope();
7076 Results.AddResult(
"template");
7081 if (
const auto *TTPT = dyn_cast<TemplateTypeParmType>(NNS.
getAsType())) {
7082 for (
const auto &R : ConceptInfo(*TTPT, S).members()) {
7083 if (R.Operator != ConceptInfo::Member::Colons)
7097 if (Ctx && !EnteringContext)
7099 Results.ExitScope();
7103 CodeCompletionDeclConsumer Consumer(Results, Ctx, BaseType);
7104 Consumer.setIsInDeclarationContext(IsInDeclarationContext);
7105 Consumer.setIsAddressOfOperand(IsAddressOfOperand);
7111 SimulateContext.reset();
7113 Results.getCompletionContext(), Results.data(),
7124 Context.setIsUsingDeclaration(
true);
7128 &ResultBuilder::IsNestedNameSpecifier);
7129 Results.EnterNewScope();
7137 CodeCompletionDeclConsumer Consumer(Results,
SemaRef.CurContext);
7141 Results.ExitScope();
7144 Results.getCompletionContext(), Results.data(),
7157 &ResultBuilder::IsNamespaceOrAlias);
7158 Results.EnterNewScope();
7159 CodeCompletionDeclConsumer Consumer(Results,
SemaRef.CurContext);
7163 Results.ExitScope();
7165 Results.getCompletionContext(), Results.data(),
7177 bool SuppressedGlobalResults =
7182 SuppressedGlobalResults
7185 &ResultBuilder::IsNamespace);
7187 if (Ctx && Ctx->
isFileContext() && !SuppressedGlobalResults) {
7192 std::map<NamespaceDecl *, NamespaceDecl *> OrigToLatest;
7197 OrigToLatest[NS->getFirstDecl()] = *NS;
7201 Results.EnterNewScope();
7202 for (std::map<NamespaceDecl *, NamespaceDecl *>::iterator
7203 NS = OrigToLatest.begin(),
7204 NSEnd = OrigToLatest.end();
7209 SemaRef.CurContext,
nullptr,
false);
7210 Results.ExitScope();
7214 Results.getCompletionContext(), Results.data(),
7226 &ResultBuilder::IsNamespaceOrAlias);
7227 CodeCompletionDeclConsumer Consumer(Results,
SemaRef.CurContext);
7232 Results.getCompletionContext(), Results.data(),
7244 &ResultBuilder::IsType);
7245 Results.EnterNewScope();
7249#define OVERLOADED_OPERATOR(Name, Spelling, Token, Unary, Binary, MemberOnly) \
7250 if (OO_##Name != OO_Conditional) \
7251 Results.AddResult(Result(Spelling));
7252#include "clang/Basic/OperatorKinds.def"
7255 Results.allowNestedNameSpecifiers();
7256 CodeCompletionDeclConsumer Consumer(Results,
SemaRef.CurContext);
7263 Results.ExitScope();
7266 Results.getCompletionContext(), Results.data(),
7275 SemaRef.AdjustDeclIfTemplate(ConstructorD);
7277 auto *
Constructor = dyn_cast<CXXConstructorDecl>(ConstructorD);
7284 Results.EnterNewScope();
7289 for (
unsigned I = 0, E = Initializers.size(); I != E; ++I) {
7290 if (Initializers[I]->isBaseInitializer())
7292 QualType(Initializers[I]->getBaseClass(), 0)));
7294 InitializedFields.insert(
7300 bool SawLastInitializer = Initializers.empty();
7303 auto GenerateCCS = [&](
const NamedDecl *ND,
const char *Name) {
7305 Results.getCodeCompletionTUInfo());
7306 Builder.AddTypedTextChunk(Name);
7308 if (
const auto *
Function = dyn_cast<FunctionDecl>(ND))
7310 else if (
const auto *FunTemplDecl = dyn_cast<FunctionTemplateDecl>(ND))
7312 FunTemplDecl->getTemplatedDecl(), Builder);
7314 return Builder.TakeString();
7316 auto AddDefaultCtorInit = [&](
const char *Name,
const char *
Type,
7319 Results.getCodeCompletionTUInfo());
7320 Builder.AddTypedTextChunk(Name);
7322 Builder.AddPlaceholderChunk(
Type);
7326 Builder.TakeString(), ND,
7330 return Results.AddResult(CCR);
7333 Builder.TakeString(),
7336 auto AddCtorsWithName = [&](
const CXXRecordDecl *RD,
unsigned int Priority,
7337 const char *Name,
const FieldDecl *FD) {
7339 return AddDefaultCtorInit(Name,
7340 FD ? Results.getAllocator().CopyString(
7341 FD->getType().getAsString(Policy))
7345 if (Ctors.begin() == Ctors.end())
7346 return AddDefaultCtorInit(Name, Name, RD);
7350 Results.AddResult(CCR);
7354 const char *BaseName =
7355 Results.getAllocator().CopyString(
Base.getType().getAsString(Policy));
7356 const auto *RD =
Base.getType()->getAsCXXRecordDecl();
7361 auto AddField = [&](
const FieldDecl *FD) {
7362 const char *FieldName =
7363 Results.getAllocator().CopyString(FD->getIdentifier()->getName());
7364 const CXXRecordDecl *RD = FD->getType()->getAsCXXRecordDecl();
7370 for (
const auto &
Base : ClassDecl->
bases()) {
7371 if (!InitializedBases
7374 SawLastInitializer =
7375 !Initializers.empty() && Initializers.back()->isBaseInitializer() &&
7377 Base.getType(),
QualType(Initializers.back()->getBaseClass(), 0));
7382 SawLastInitializer =
false;
7386 for (
const auto &
Base : ClassDecl->
vbases()) {
7387 if (!InitializedBases
7390 SawLastInitializer =
7391 !Initializers.empty() && Initializers.back()->isBaseInitializer() &&
7393 Base.getType(),
QualType(Initializers.back()->getBaseClass(), 0));
7398 SawLastInitializer =
false;
7402 for (
auto *Field : ClassDecl->
fields()) {
7403 if (!InitializedFields.insert(
cast<FieldDecl>(Field->getCanonicalDecl()))
7405 SawLastInitializer = !Initializers.empty() &&
7406 Initializers.back()->isAnyMemberInitializer() &&
7407 Initializers.back()->getAnyMember() == Field;
7411 if (!Field->getDeclName())
7415 SawLastInitializer =
false;
7417 Results.ExitScope();
7420 Results.getCompletionContext(), Results.data(),
7435 bool AfterAmpersand) {
7439 Results.EnterNewScope();
7443 bool IncludedThis =
false;
7446 IncludedThis =
true;
7455 for (
const auto *D : S->
decls()) {
7456 const auto *Var = dyn_cast<VarDecl>(D);
7457 if (!Var || !Var->hasLocalStorage() || Var->hasAttr<BlocksAttr>())
7460 if (Known.insert(Var->getIdentifier()).second)
7462 SemaRef.CurContext,
nullptr,
false);
7470 Results.ExitScope();
7473 Results.getCompletionContext(), Results.data(),
7483 auto ShouldAddDefault = [&D,
this]() {
7495 auto Op = Id.OperatorFunctionId.Operator;
7498 if (Op == OverloadedOperatorKind::OO_Equal)
7501 (Op == OverloadedOperatorKind::OO_EqualEqual ||
7502 Op == OverloadedOperatorKind::OO_ExclaimEqual ||
7503 Op == OverloadedOperatorKind::OO_Less ||
7504 Op == OverloadedOperatorKind::OO_LessEqual ||
7505 Op == OverloadedOperatorKind::OO_Greater ||
7506 Op == OverloadedOperatorKind::OO_GreaterEqual ||
7507 Op == OverloadedOperatorKind::OO_Spaceship))
7513 Results.EnterNewScope();
7514 if (ShouldAddDefault())
7515 Results.AddResult(
"default");
7518 Results.AddResult(
"delete");
7519 Results.ExitScope();
7521 Results.getCompletionContext(), Results.data(),
7527#define OBJC_AT_KEYWORD_NAME(NeedAt, Keyword) ((NeedAt) ? "@" Keyword : Keyword)
7530 ResultBuilder &Results,
bool NeedAt) {
7536 Results.getCodeCompletionTUInfo());
7537 if (LangOpts.ObjC) {
7541 Builder.AddPlaceholderChunk(
"property");
7542 Results.AddResult(
Result(Builder.TakeString()));
7547 Builder.AddPlaceholderChunk(
"property");
7548 Results.AddResult(
Result(Builder.TakeString()));
7553 ResultBuilder &Results,
bool NeedAt) {
7559 if (LangOpts.ObjC) {
7574 Results.getCodeCompletionTUInfo());
7579 Builder.AddPlaceholderChunk(
"name");
7580 Results.AddResult(
Result(Builder.TakeString()));
7582 if (Results.includeCodePatterns()) {
7588 Builder.AddPlaceholderChunk(
"class");
7589 Results.AddResult(
Result(Builder.TakeString()));
7594 Builder.AddPlaceholderChunk(
"protocol");
7595 Results.AddResult(
Result(Builder.TakeString()));
7600 Builder.AddPlaceholderChunk(
"class");
7601 Results.AddResult(
Result(Builder.TakeString()));
7605 Builder.AddTypedTextChunk(
7608 Builder.AddPlaceholderChunk(
"alias");
7610 Builder.AddPlaceholderChunk(
"class");
7611 Results.AddResult(
Result(Builder.TakeString()));
7613 if (Results.getSema().getLangOpts().Modules) {
7617 Builder.AddPlaceholderChunk(
"module");
7618 Results.AddResult(
Result(Builder.TakeString()));
7626 Results.EnterNewScope();
7629 else if (
SemaRef.CurContext->isObjCContainer())
7633 Results.ExitScope();
7635 Results.getCompletionContext(), Results.data(),
7642 Results.getCodeCompletionTUInfo());
7645 const char *EncodeType =
"char[]";
7646 if (Results.getSema().getLangOpts().CPlusPlus ||
7647 Results.getSema().getLangOpts().ConstStrings)
7648 EncodeType =
"const char[]";
7649 Builder.AddResultTypeChunk(EncodeType);
7652 Builder.AddPlaceholderChunk(
"type-name");
7654 Results.AddResult(
Result(Builder.TakeString()));
7657 Builder.AddResultTypeChunk(
"Protocol *");
7660 Builder.AddPlaceholderChunk(
"protocol-name");
7662 Results.AddResult(
Result(Builder.TakeString()));
7665 Builder.AddResultTypeChunk(
"SEL");
7668 Builder.AddPlaceholderChunk(
"selector");
7670 Results.AddResult(
Result(Builder.TakeString()));
7673 Builder.AddResultTypeChunk(
"NSString *");
7675 Builder.AddPlaceholderChunk(
"string");
7676 Builder.AddTextChunk(
"\"");
7677 Results.AddResult(
Result(Builder.TakeString()));
7680 Builder.AddResultTypeChunk(
"NSArray *");
7682 Builder.AddPlaceholderChunk(
"objects, ...");
7684 Results.AddResult(
Result(Builder.TakeString()));
7687 Builder.AddResultTypeChunk(
"NSDictionary *");
7689 Builder.AddPlaceholderChunk(
"key");
7692 Builder.AddPlaceholderChunk(
"object, ...");
7694 Results.AddResult(
Result(Builder.TakeString()));
7697 Builder.AddResultTypeChunk(
"id");
7699 Builder.AddPlaceholderChunk(
"expression");
7701 Results.AddResult(
Result(Builder.TakeString()));
7707 Results.getCodeCompletionTUInfo());
7709 if (Results.includeCodePatterns()) {
7714 Builder.AddPlaceholderChunk(
"statements");
7716 Builder.AddTextChunk(
"@catch");
7718 Builder.AddPlaceholderChunk(
"parameter");
7721 Builder.AddPlaceholderChunk(
"statements");
7723 Builder.AddTextChunk(
"@finally");
7725 Builder.AddPlaceholderChunk(
"statements");
7727 Results.AddResult(
Result(Builder.TakeString()));
7733 Builder.AddPlaceholderChunk(
"expression");
7734 Results.AddResult(
Result(Builder.TakeString()));
7736 if (Results.includeCodePatterns()) {
7741 Builder.AddPlaceholderChunk(
"expression");
7744 Builder.AddPlaceholderChunk(
"statements");
7746 Results.AddResult(
Result(Builder.TakeString()));
7751 ResultBuilder &Results,
bool NeedAt) {
7764 Results.EnterNewScope();
7766 Results.ExitScope();
7768 Results.getCompletionContext(), Results.data(),
7776 Results.EnterNewScope();
7779 Results.ExitScope();
7781 Results.getCompletionContext(), Results.data(),
7789 Results.EnterNewScope();
7791 Results.ExitScope();
7793 Results.getCompletionContext(), Results.data(),
7801 if (Attributes & NewFlag)
7804 Attributes |= NewFlag;
7812 unsigned AssignCopyRetMask =
7818 if (AssignCopyRetMask &&
7840 Results.EnterNewScope();
7877 Results.getCodeCompletionTUInfo());
7886 Results.getCodeCompletionTUInfo());
7899 Results.ExitScope();
7901 Results.getCompletionContext(), Results.data(),
7915 bool AllowSameLength =
true) {
7916 unsigned NumSelIdents = SelIdents.size();
7929 if (!AllowSameLength && NumSelIdents && NumSelIdents == Sel.
getNumArgs())
7932 for (
unsigned I = 0; I != NumSelIdents; ++I)
7942 bool AllowSameLength =
true) {
7976 ResultBuilder &Results,
bool InOriginalClass =
true,
7977 bool IsRootClass =
false) {
7981 IsRootClass = IsRootClass || (IFace && !IFace->
getSuperClass());
7985 if (M->isInstanceMethod() == WantInstanceMethods ||
7986 (IsRootClass && !WantInstanceMethods)) {
7992 if (!Selectors.insert(M->getSelector()).second)
7996 Result(M, Results.getBasePriority(M), std::nullopt);
7997 R.StartParameter = SelIdents.size();
7998 R.AllParametersAreInformative = (WantKind !=
MK_Any);
7999 if (!InOriginalClass)
8001 Results.MaybeAddResult(R, CurContext);
8006 if (
const auto *Protocol = dyn_cast<ObjCProtocolDecl>(Container)) {
8007 if (Protocol->hasDefinition()) {
8009 Protocol->getReferencedProtocols();
8011 E = Protocols.
end();
8013 AddObjCMethods(*I, WantInstanceMethods, WantKind, SelIdents, CurContext,
8014 Selectors, AllowSameLength, Results,
false, IsRootClass);
8023 AddObjCMethods(I, WantInstanceMethods, WantKind, SelIdents, CurContext,
8024 Selectors, AllowSameLength, Results,
false, IsRootClass);
8028 AddObjCMethods(CatDecl, WantInstanceMethods, WantKind, SelIdents,
8029 CurContext, Selectors, AllowSameLength, Results,
8030 InOriginalClass, IsRootClass);
8034 CatDecl->getReferencedProtocols();
8036 E = Protocols.
end();
8038 AddObjCMethods(*I, WantInstanceMethods, WantKind, SelIdents, CurContext,
8039 Selectors, AllowSameLength, Results,
false, IsRootClass);
8043 AddObjCMethods(Impl, WantInstanceMethods, WantKind, SelIdents, CurContext,
8044 Selectors, AllowSameLength, Results, InOriginalClass,
8052 SelIdents, CurContext, Selectors, AllowSameLength, Results,
8057 AddObjCMethods(Impl, WantInstanceMethods, WantKind, SelIdents, CurContext,
8058 Selectors, AllowSameLength, Results, InOriginalClass,
8065 dyn_cast_or_null<ObjCInterfaceDecl>(
SemaRef.CurContext);
8068 dyn_cast_or_null<ObjCCategoryDecl>(
SemaRef.CurContext))
8069 Class = Category->getClassInterface();
8079 Results.EnterNewScope();
8085 Results.ExitScope();
8087 Results.getCompletionContext(), Results.data(),
8094 dyn_cast_or_null<ObjCInterfaceDecl>(
SemaRef.CurContext);
8097 dyn_cast_or_null<ObjCCategoryDecl>(
SemaRef.CurContext))
8098 Class = Category->getClassInterface();
8108 Results.EnterNewScope();
8115 Results.ExitScope();
8117 Results.getCompletionContext(), Results.data(),
8126 Results.EnterNewScope();
8129 bool AddedInOut =
false;
8132 Results.AddResult(
"in");
8133 Results.AddResult(
"inout");
8138 Results.AddResult(
"out");
8140 Results.AddResult(
"inout");
8145 Results.AddResult(
"bycopy");
8146 Results.AddResult(
"byref");
8147 Results.AddResult(
"oneway");
8150 Results.AddResult(
"nonnull");
8151 Results.AddResult(
"nullable");
8152 Results.AddResult(
"null_unspecified");
8160 SemaRef.PP.isMacroDefined(
"IBAction")) {
8162 Results.getCodeCompletionTUInfo(),
8164 Builder.AddTypedTextChunk(
"IBAction");
8166 Builder.AddPlaceholderChunk(
"selector");
8169 Builder.AddTextChunk(
"id");
8171 Builder.AddTextChunk(
"sender");
8182 Results.ExitScope();
8185 Results.setFilter(&ResultBuilder::IsOrdinaryNonValueName);
8186 CodeCompletionDeclConsumer Consumer(Results,
SemaRef.CurContext);
8195 Results.getCompletionContext(), Results.data(),
8204 auto *Msg = dyn_cast_or_null<ObjCMessageExpr>(E);
8222 switch (Msg->getReceiverKind()) {
8226 IFace = ObjType->getInterface();
8230 QualType T = Msg->getInstanceReceiver()->getType();
8232 IFace = Ptr->getInterfaceDecl();
8245 if (Method->isInstanceMethod())
8246 return llvm::StringSwitch<ObjCInterfaceDecl *>(Id->
getName())
8247 .Case(
"retain", IFace)
8248 .Case(
"strong", IFace)
8249 .Case(
"autorelease", IFace)
8250 .Case(
"copy", IFace)
8251 .Case(
"copyWithZone", IFace)
8252 .Case(
"mutableCopy", IFace)
8253 .Case(
"mutableCopyWithZone", IFace)
8254 .Case(
"awakeFromCoder", IFace)
8255 .Case(
"replacementObjectFromCoder", IFace)
8256 .Case(
"class", IFace)
8257 .Case(
"classForCoder", IFace)
8258 .Case(
"superclass", Super)
8261 return llvm::StringSwitch<ObjCInterfaceDecl *>(Id->
getName())
8263 .Case(
"alloc", IFace)
8264 .Case(
"allocWithZone", IFace)
8265 .Case(
"class", IFace)
8266 .Case(
"superclass", Super)
8286static ObjCMethodDecl *
8289 ResultBuilder &Results) {
8300 while ((Class = Class->getSuperClass()) && !SuperMethod) {
8302 SuperMethod = Class->getMethod(CurMethod->
getSelector(),
8307 for (
const auto *Cat : Class->known_categories()) {
8308 if ((SuperMethod = Cat->getMethod(CurMethod->
getSelector(),
8326 CurP != CurPEnd; ++CurP, ++SuperP) {
8329 (*SuperP)->getType()))
8333 if (!(*CurP)->getIdentifier())
8339 Results.getCodeCompletionTUInfo());
8343 Results.getCompletionContext().getBaseType(), Builder);
8346 if (NeedSuperKeyword) {
8347 Builder.AddTypedTextChunk(
"super");
8353 if (NeedSuperKeyword)
8354 Builder.AddTextChunk(
8357 Builder.AddTypedTextChunk(
8361 for (
unsigned I = 0, N = Sel.
getNumArgs(); I != N; ++I, ++CurP) {
8362 if (I > SelIdents.size())
8365 if (I < SelIdents.size())
8366 Builder.AddInformativeChunk(
8368 else if (NeedSuperKeyword || I > SelIdents.size()) {
8369 Builder.AddTextChunk(
8371 Builder.AddPlaceholderChunk(Builder.getAllocator().CopyString(
8372 (*CurP)->getIdentifier()->getName()));
8374 Builder.AddTypedTextChunk(
8376 Builder.AddPlaceholderChunk(Builder.getAllocator().CopyString(
8377 (*CurP)->getIdentifier()->getName()));
8389 ResultBuilder Results(
8394 ? &ResultBuilder::IsObjCMessageReceiverOrLambdaCapture
8395 : &ResultBuilder::IsObjCMessageReceiver);
8397 CodeCompletionDeclConsumer Consumer(Results,
SemaRef.CurContext);
8398 Results.EnterNewScope();
8407 if (Iface->getSuperClass()) {
8408 Results.AddResult(
Result(
"super"));
8416 Results.ExitScope();
8421 Results.getCompletionContext(), Results.data(),
8431 CDecl = CurMethod->getClassInterface();
8440 if (CurMethod->isInstanceMethod()) {
8445 AtArgumentExpression, CDecl);
8455 if ((CDecl = dyn_cast_or_null<ObjCInterfaceDecl>(ND))) {
8457 }
else if (
TypeDecl *TD = dyn_cast_or_null<TypeDecl>(ND)) {
8459 getASTContext().getTypeDeclType(TD)->getAs<ObjCObjectType>())
8460 CDecl = Iface->getInterface();
8470 SemaRef.ActOnIdExpression(S, SS, TemplateKWLoc,
id,
8474 SelIdents, AtArgumentExpression);
8484 AtArgumentExpression,
8491 unsigned NumSelIdents) {
8493 ASTContext &Context = Results.getSema().Context;
8497 Result *ResultsData = Results.data();
8498 for (
unsigned I = 0, N = Results.size(); I != N; ++I) {
8499 Result &R = ResultsData[I];
8500 if (R.Kind == Result::RK_Declaration &&
8502 if (R.Priority <= BestPriority) {
8504 if (NumSelIdents <= Method->param_size()) {
8506 Method->parameters()[NumSelIdents - 1]->getType();
8507 if (R.Priority < BestPriority || PreferredType.
isNull()) {
8508 BestPriority = R.Priority;
8509 PreferredType = MyPreferredType;
8510 }
else if (!Context.hasSameUnqualifiedType(PreferredType,
8519 return PreferredType;
8525 bool AtArgumentExpression,
bool IsSuper,
8526 ResultBuilder &Results) {
8541 Results.EnterNewScope();
8548 Results.Ignore(SuperMethod);
8554 Results.setPreferredSelector(CurMethod->getSelector());
8559 Selectors, AtArgumentExpression, Results);
8566 for (uint32_t I = 0,
8577 for (SemaObjC::GlobalMethodPool::iterator
8582 MethList && MethList->getMethod(); MethList = MethList->getNext()) {
8586 Result R(MethList->getMethod(),
8587 Results.getBasePriority(MethList->getMethod()),
8589 R.StartParameter = SelIdents.size();
8590 R.AllParametersAreInformative =
false;
8591 Results.MaybeAddResult(R, SemaRef.
CurContext);
8596 Results.ExitScope();
8601 bool AtArgumentExpression,
bool IsSuper) {
8605 ResultBuilder Results(
8612 AtArgumentExpression, IsSuper, Results);
8619 if (AtArgumentExpression) {
8622 if (PreferredType.
isNull())
8630 Results.getCompletionContext(), Results.data(),
8651 RecExpr = Conv.
get();
8655 : Super ? Context.getObjCObjectPointerType(
8656 Context.getObjCInterfaceType(Super))
8657 : Context.getObjCIdType();
8667 AtArgumentExpression, Super);
8670 Context.getObjCObjectPointerType(Context.getObjCInterfaceType(IFace));
8675 RecExpr = Conv.
get();
8676 ReceiverType = RecExpr->
getType();
8681 ResultBuilder Results(
8685 ReceiverType, SelIdents));
8687 Results.EnterNewScope();
8694 Results.Ignore(SuperMethod);
8700 Results.setPreferredSelector(CurMethod->getSelector());
8713 Selectors, AtArgumentExpression, Results);
8720 for (
auto *I : QualID->quals())
8722 AtArgumentExpression, Results);
8729 SemaRef.CurContext, Selectors, AtArgumentExpression,
8733 for (
auto *I : IFacePtr->quals())
8735 AtArgumentExpression, Results);
8745 for (uint32_t I = 0,
8746 N =
SemaRef.ExternalSource->GetNumExternalSelectors();
8752 SemaRef.ObjC().ReadMethodPool(Sel);
8756 for (SemaObjC::GlobalMethodPool::iterator
8757 M =
SemaRef.ObjC().MethodPool.begin(),
8758 MEnd =
SemaRef.ObjC().MethodPool.end();
8761 MethList && MethList->getMethod(); MethList = MethList->getNext()) {
8765 if (!Selectors.insert(MethList->getMethod()->getSelector()).second)
8768 Result R(MethList->getMethod(),
8769 Results.getBasePriority(MethList->getMethod()),
8771 R.StartParameter = SelIdents.size();
8772 R.AllParametersAreInformative =
false;
8773 Results.MaybeAddResult(R,
SemaRef.CurContext);
8777 Results.ExitScope();
8784 if (AtArgumentExpression) {
8787 if (PreferredType.
isNull())
8795 Results.getCompletionContext(), Results.data(),
8802 Data.ObjCCollection =
true;
8808 Data.IgnoreDecls.push_back(*I);
8820 for (uint32_t I = 0, N =
SemaRef.ExternalSource->GetNumExternalSelectors();
8826 SemaRef.ObjC().ReadMethodPool(Sel);
8833 Results.EnterNewScope();
8834 for (SemaObjC::GlobalMethodPool::iterator
8835 M =
SemaRef.ObjC().MethodPool.begin(),
8836 MEnd =
SemaRef.ObjC().MethodPool.end();
8844 Results.getCodeCompletionTUInfo());
8846 Builder.AddTypedTextChunk(
8848 Results.AddResult(Builder.TakeString());
8852 std::string Accumulator;
8853 for (
unsigned I = 0, N = Sel.
getNumArgs(); I != N; ++I) {
8854 if (I == SelIdents.size()) {
8855 if (!Accumulator.empty()) {
8856 Builder.AddInformativeChunk(
8857 Builder.getAllocator().CopyString(Accumulator));
8858 Accumulator.clear();
8865 Builder.AddTypedTextChunk(Builder.getAllocator().CopyString(Accumulator));
8866 Results.AddResult(Builder.TakeString());
8868 Results.ExitScope();
8871 Results.getCompletionContext(), Results.data(),
8878 bool OnlyForwardDeclarations,
8879 ResultBuilder &Results) {
8882 for (
const auto *D : Ctx->
decls()) {
8884 if (
const auto *Proto = dyn_cast<ObjCProtocolDecl>(D))
8885 if (!OnlyForwardDeclarations || !Proto->hasDefinition())
8886 Results.AddResult(
Result(Proto, Results.getBasePriority(Proto),
8888 CurContext,
nullptr,
false);
8899 Results.EnterNewScope();
8906 Pair.getIdentifierInfo(), Pair.getLoc()))
8907 Results.Ignore(Protocol);
8911 SemaRef.CurContext,
false, Results);
8913 Results.ExitScope();
8917 Results.getCompletionContext(), Results.data(),
8927 Results.EnterNewScope();
8931 SemaRef.CurContext,
true, Results);
8933 Results.ExitScope();
8937 Results.getCompletionContext(), Results.data(),
8944 bool OnlyForwardDeclarations,
8945 bool OnlyUnimplemented,
8946 ResultBuilder &Results) {
8949 for (
const auto *D : Ctx->
decls()) {
8951 if (
const auto *Class = dyn_cast<ObjCInterfaceDecl>(D))
8952 if ((!OnlyForwardDeclarations || !Class->hasDefinition()) &&
8953 (!OnlyUnimplemented || !Class->getImplementation()))
8954 Results.AddResult(
Result(Class, Results.getBasePriority(Class),
8956 CurContext,
nullptr,
false);
8964 Results.EnterNewScope();
8969 SemaRef.CurContext,
false,
false, Results);
8972 Results.ExitScope();
8975 Results.getCompletionContext(), Results.data(),
8983 Results.EnterNewScope();
8988 SemaRef.CurContext,
false,
false, Results);
8991 Results.ExitScope();
8994 Results.getCompletionContext(), Results.data(),
9003 Results.EnterNewScope();
9009 Results.Ignore(CurClass);
9014 SemaRef.CurContext,
false,
false, Results);
9017 Results.ExitScope();
9020 Results.getCompletionContext(), Results.data(),
9028 Results.EnterNewScope();
9033 SemaRef.CurContext,
false,
true, Results);
9036 Results.ExitScope();
9039 Results.getCompletionContext(), Results.data(),
9057 dyn_cast_or_null<ObjCInterfaceDecl>(CurClass)) {
9058 for (
const auto *Cat :
Class->visible_categories())
9059 CategoryNames.insert(Cat->getIdentifier());
9063 Results.EnterNewScope();
9065 for (
const auto *D : TU->
decls())
9066 if (
const auto *Category = dyn_cast<ObjCCategoryDecl>(D))
9067 if (CategoryNames.insert(Category->getIdentifier()).second)
9068 Results.AddResult(
Result(Category, Results.getBasePriority(Category),
9070 SemaRef.CurContext,
nullptr,
false);
9071 Results.ExitScope();
9074 Results.getCompletionContext(), Results.data(),
9099 Results.EnterNewScope();
9100 bool IgnoreImplemented =
true;
9102 for (
const auto *Cat :
Class->visible_categories()) {
9103 if ((!IgnoreImplemented || !Cat->getImplementation()) &&
9104 CategoryNames.insert(Cat->getIdentifier()).second)
9105 Results.AddResult(
Result(Cat, Results.getBasePriority(Cat),
9107 SemaRef.CurContext,
nullptr,
false);
9111 IgnoreImplemented =
false;
9113 Results.ExitScope();
9116 Results.getCompletionContext(), Results.data(),
9127 dyn_cast_or_null<ObjCContainerDecl>(
SemaRef.CurContext);
9134 for (
const auto *D : Container->
decls())
9135 if (
const auto *PropertyImpl = dyn_cast<ObjCPropertyImplDecl>(D))
9136 Results.Ignore(PropertyImpl->getPropertyDecl());
9140 Results.EnterNewScope();
9142 dyn_cast<ObjCImplementationDecl>(Container))
9145 AddedProperties, Results);
9149 false,
false,
SemaRef.CurContext,
9150 AddedProperties, Results);
9151 Results.ExitScope();
9154 Results.getCompletionContext(), Results.data(),
9167 dyn_cast_or_null<ObjCContainerDecl>(
SemaRef.CurContext);
9175 dyn_cast<ObjCImplementationDecl>(Container))
9176 Class = ClassImpl->getClassInterface();
9180 ->getClassInterface();
9188 Property->getType().getNonReferenceType().getUnqualifiedType();
9191 Results.setPreferredType(PropertyType);
9196 Results.EnterNewScope();
9197 bool SawSimilarlyNamedIvar =
false;
9198 std::string NameWithPrefix;
9199 NameWithPrefix +=
'_';
9200 NameWithPrefix += PropertyName->getName();
9201 std::string NameWithSuffix = PropertyName->getName().str();
9202 NameWithSuffix +=
'_';
9205 Ivar = Ivar->getNextIvar()) {
9206 Results.AddResult(
Result(Ivar, Results.getBasePriority(Ivar),
9208 SemaRef.CurContext,
nullptr,
false);
9212 if ((PropertyName == Ivar->getIdentifier() ||
9213 NameWithPrefix == Ivar->getName() ||
9214 NameWithSuffix == Ivar->getName())) {
9215 SawSimilarlyNamedIvar =
true;
9219 if (Results.size() &&
9220 Results.data()[Results.size() - 1].Kind ==
9222 Results.data()[Results.size() - 1].Declaration == Ivar)
9223 Results.data()[Results.size() - 1].Priority--;
9228 if (!SawSimilarlyNamedIvar) {
9240 Builder.AddTypedTextChunk(Allocator.
CopyString(NameWithPrefix));
9245 Results.ExitScope();
9248 Results.getCompletionContext(), Results.data(),
9255 llvm::PointerIntPair<ObjCMethodDecl *, 1, bool>>
9264 std::optional<bool> WantInstanceMethods,
9267 bool InOriginalClass =
true) {
9270 if (!IFace->hasDefinition())
9273 IFace = IFace->getDefinition();
9277 IFace->getReferencedProtocols();
9279 E = Protocols.
end();
9282 KnownMethods, InOriginalClass);
9285 for (
auto *Cat : IFace->visible_categories()) {
9287 KnownMethods,
false);
9291 if (IFace->getSuperClass())
9293 WantInstanceMethods, ReturnType, KnownMethods,
9300 Category->getReferencedProtocols();
9302 E = Protocols.
end();
9305 KnownMethods, InOriginalClass);
9308 if (InOriginalClass && Category->getClassInterface())
9310 WantInstanceMethods, ReturnType, KnownMethods,
9316 if (!Protocol->hasDefinition())
9318 Protocol = Protocol->getDefinition();
9319 Container = Protocol;
9323 Protocol->getReferencedProtocols();
9325 E = Protocols.
end();
9328 KnownMethods,
false);
9334 for (
auto *M : Container->
methods()) {
9335 if (!WantInstanceMethods || M->isInstanceMethod() == *WantInstanceMethods) {
9336 if (!ReturnType.
isNull() &&
9337 !Context.hasSameUnqualifiedType(ReturnType, M->getReturnType()))
9340 KnownMethods[M->getSelector()] =
9341 KnownMethodsMap::mapped_type(M, InOriginalClass);
9355 Builder.AddTextChunk(Builder.getAllocator().CopyString(Quals));
9356 Builder.AddTextChunk(
9367 if (Class->getIdentifier() && Class->getIdentifier()->getName() == Name)
9376 bool IsInstanceMethod,
9379 ResultBuilder &Results) {
9381 if (!PropName || PropName->
getLength() == 0)
9399 const char *CopiedKey;
9402 : Allocator(Allocator), Key(Key), CopiedKey(
nullptr) {}
9404 operator const char *() {
9408 return CopiedKey = Allocator.
CopyString(Key);
9410 } Key(Allocator, PropName->
getName());
9413 std::string UpperKey = std::string(PropName->
getName());
9414 if (!UpperKey.empty())
9417 bool ReturnTypeMatchesProperty =
9420 Property->getType());
9421 bool ReturnTypeMatchesVoid = ReturnType.
isNull() || ReturnType->
isVoidType();
9424 if (IsInstanceMethod &&
9426 ReturnTypeMatchesProperty && !Property->getGetterMethodDecl()) {
9431 Builder.AddTypedTextChunk(Key);
9438 if (IsInstanceMethod &&
9439 ((!ReturnType.
isNull() &&
9441 (ReturnType.
isNull() && (Property->getType()->isIntegerType() ||
9442 Property->getType()->isBooleanType())))) {
9443 std::string SelectorName = (Twine(
"is") + UpperKey).str();
9447 if (ReturnType.
isNull()) {
9449 Builder.AddTextChunk(
"BOOL");
9460 if (IsInstanceMethod && ReturnTypeMatchesVoid &&
9461 !Property->getSetterMethodDecl()) {
9462 std::string SelectorName = (Twine(
"set") + UpperKey).str();
9464 if (KnownSelectors.insert(Selectors.
getUnarySelector(SelectorId)).second) {
9465 if (ReturnType.
isNull()) {
9467 Builder.AddTextChunk(
"void");
9471 Builder.AddTypedTextChunk(
9475 Builder.AddTextChunk(Key);
9486 if (
const auto *ObjCPointer =
9511 if (IsInstanceMethod &&
9513 std::string SelectorName = (Twine(
"countOf") + UpperKey).str();
9517 if (ReturnType.
isNull()) {
9519 Builder.AddTextChunk(
"NSUInteger");
9525 Result(Builder.TakeString(),
9526 std::min(IndexedGetterPriority, UnorderedGetterPriority),
9533 if (IsInstanceMethod &&
9535 std::string SelectorName = (Twine(
"objectIn") + UpperKey +
"AtIndex").str();
9537 if (KnownSelectors.insert(Selectors.
getUnarySelector(SelectorId)).second) {
9538 if (ReturnType.
isNull()) {
9540 Builder.AddTextChunk(
"id");
9544 Builder.AddTypedTextChunk(Allocator.
CopyString(SelectorName +
":"));
9546 Builder.AddTextChunk(
"NSUInteger");
9548 Builder.AddTextChunk(
"index");
9549 Results.AddResult(
Result(Builder.TakeString(), IndexedGetterPriority,
9555 if (IsInstanceMethod &&
9562 std::string SelectorName = (Twine(Property->getName()) +
"AtIndexes").str();
9564 if (KnownSelectors.insert(Selectors.
getUnarySelector(SelectorId)).second) {
9565 if (ReturnType.
isNull()) {
9567 Builder.AddTextChunk(
"NSArray *");
9571 Builder.AddTypedTextChunk(Allocator.
CopyString(SelectorName +
":"));
9573 Builder.AddTextChunk(
"NSIndexSet *");
9575 Builder.AddTextChunk(
"indexes");
9576 Results.AddResult(
Result(Builder.TakeString(), IndexedGetterPriority,
9582 if (IsInstanceMethod && ReturnTypeMatchesVoid) {
9583 std::string SelectorName = (Twine(
"get") + UpperKey).str();
9584 const IdentifierInfo *SelectorIds[2] = {&Context.Idents.get(SelectorName),
9585 &Context.Idents.get(
"range")};
9587 if (KnownSelectors.insert(Selectors.
getSelector(2, SelectorIds)).second) {
9588 if (ReturnType.
isNull()) {
9590 Builder.AddTextChunk(
"void");
9594 Builder.AddTypedTextChunk(Allocator.
CopyString(SelectorName +
":"));
9596 Builder.AddPlaceholderChunk(
"object-type");
9597 Builder.AddTextChunk(
" **");
9599 Builder.AddTextChunk(
"buffer");
9601 Builder.AddTypedTextChunk(
"range:");
9603 Builder.AddTextChunk(
"NSRange");
9605 Builder.AddTextChunk(
"inRange");
9606 Results.AddResult(
Result(Builder.TakeString(), IndexedGetterPriority,
9614 if (IsInstanceMethod && ReturnTypeMatchesVoid) {
9615 std::string SelectorName = (Twine(
"in") + UpperKey +
"AtIndex").str();
9616 const IdentifierInfo *SelectorIds[2] = {&Context.Idents.get(
"insertObject"),
9617 &Context.Idents.get(SelectorName)};
9619 if (KnownSelectors.insert(Selectors.
getSelector(2, SelectorIds)).second) {
9620 if (ReturnType.
isNull()) {
9622 Builder.AddTextChunk(
"void");
9626 Builder.AddTypedTextChunk(
"insertObject:");
9628 Builder.AddPlaceholderChunk(
"object-type");
9629 Builder.AddTextChunk(
" *");
9631 Builder.AddTextChunk(
"object");
9633 Builder.AddTypedTextChunk(Allocator.
CopyString(SelectorName +
":"));
9635 Builder.AddPlaceholderChunk(
"NSUInteger");
9637 Builder.AddTextChunk(
"index");
9638 Results.AddResult(
Result(Builder.TakeString(), IndexedSetterPriority,
9644 if (IsInstanceMethod && ReturnTypeMatchesVoid) {
9645 std::string SelectorName = (Twine(
"insert") + UpperKey).str();
9646 const IdentifierInfo *SelectorIds[2] = {&Context.Idents.get(SelectorName),
9647 &Context.Idents.get(
"atIndexes")};
9649 if (KnownSelectors.insert(Selectors.
getSelector(2, SelectorIds)).second) {
9650 if (ReturnType.
isNull()) {
9652 Builder.AddTextChunk(
"void");
9656 Builder.AddTypedTextChunk(Allocator.
CopyString(SelectorName +
":"));
9658 Builder.AddTextChunk(
"NSArray *");
9660 Builder.AddTextChunk(
"array");
9662 Builder.AddTypedTextChunk(
"atIndexes:");
9664 Builder.AddPlaceholderChunk(
"NSIndexSet *");
9666 Builder.AddTextChunk(
"indexes");
9667 Results.AddResult(
Result(Builder.TakeString(), IndexedSetterPriority,
9673 if (IsInstanceMethod && ReturnTypeMatchesVoid) {
9674 std::string SelectorName =
9675 (Twine(
"removeObjectFrom") + UpperKey +
"AtIndex").str();
9676 const IdentifierInfo *SelectorId = &Context.Idents.get(SelectorName);
9677 if (KnownSelectors.insert(Selectors.
getUnarySelector(SelectorId)).second) {
9678 if (ReturnType.
isNull()) {
9680 Builder.AddTextChunk(
"void");
9684 Builder.AddTypedTextChunk(Allocator.
CopyString(SelectorName +
":"));
9686 Builder.AddTextChunk(
"NSUInteger");
9688 Builder.AddTextChunk(
"index");
9689 Results.AddResult(
Result(Builder.TakeString(), IndexedSetterPriority,
9695 if (IsInstanceMethod && ReturnTypeMatchesVoid) {
9696 std::string SelectorName = (Twine(
"remove") + UpperKey +
"AtIndexes").str();
9697 const IdentifierInfo *SelectorId = &Context.Idents.get(SelectorName);
9698 if (KnownSelectors.insert(Selectors.
getUnarySelector(SelectorId)).second) {
9699 if (ReturnType.
isNull()) {
9701 Builder.AddTextChunk(
"void");
9705 Builder.AddTypedTextChunk(Allocator.
CopyString(SelectorName +
":"));
9707 Builder.AddTextChunk(
"NSIndexSet *");
9709 Builder.AddTextChunk(
"indexes");
9710 Results.AddResult(
Result(Builder.TakeString(), IndexedSetterPriority,
9716 if (IsInstanceMethod && ReturnTypeMatchesVoid) {
9717 std::string SelectorName =
9718 (Twine(
"replaceObjectIn") + UpperKey +
"AtIndex").str();
9719 const IdentifierInfo *SelectorIds[2] = {&Context.Idents.get(SelectorName),
9720 &Context.Idents.get(
"withObject")};
9722 if (KnownSelectors.insert(Selectors.
getSelector(2, SelectorIds)).second) {
9723 if (ReturnType.
isNull()) {
9725 Builder.AddTextChunk(
"void");
9729 Builder.AddTypedTextChunk(Allocator.
CopyString(SelectorName +
":"));
9731 Builder.AddPlaceholderChunk(
"NSUInteger");
9733 Builder.AddTextChunk(
"index");
9735 Builder.AddTypedTextChunk(
"withObject:");
9737 Builder.AddTextChunk(
"id");
9739 Builder.AddTextChunk(
"object");
9740 Results.AddResult(
Result(Builder.TakeString(), IndexedSetterPriority,
9746 if (IsInstanceMethod && ReturnTypeMatchesVoid) {
9747 std::string SelectorName1 =
9748 (Twine(
"replace") + UpperKey +
"AtIndexes").str();
9749 std::string SelectorName2 = (Twine(
"with") + UpperKey).str();
9750 const IdentifierInfo *SelectorIds[2] = {&Context.Idents.get(SelectorName1),
9751 &Context.Idents.get(SelectorName2)};
9753 if (KnownSelectors.insert(Selectors.
getSelector(2, SelectorIds)).second) {
9754 if (ReturnType.
isNull()) {
9756 Builder.AddTextChunk(
"void");
9760 Builder.AddTypedTextChunk(Allocator.
CopyString(SelectorName1 +
":"));
9762 Builder.AddPlaceholderChunk(
"NSIndexSet *");
9764 Builder.AddTextChunk(
"indexes");
9766 Builder.AddTypedTextChunk(Allocator.
CopyString(SelectorName2 +
":"));
9768 Builder.AddTextChunk(
"NSArray *");
9770 Builder.AddTextChunk(
"array");
9771 Results.AddResult(
Result(Builder.TakeString(), IndexedSetterPriority,
9778 if (IsInstanceMethod &&
9784 ->
getName() ==
"NSEnumerator"))) {
9785 std::string SelectorName = (Twine(
"enumeratorOf") + UpperKey).str();
9786 const IdentifierInfo *SelectorId = &Context.Idents.get(SelectorName);
9789 if (ReturnType.
isNull()) {
9791 Builder.AddTextChunk(
"NSEnumerator *");
9795 Builder.AddTypedTextChunk(Allocator.
CopyString(SelectorName));
9796 Results.AddResult(
Result(Builder.TakeString(), UnorderedGetterPriority,
9802 if (IsInstanceMethod &&
9804 std::string SelectorName = (Twine(
"memberOf") + UpperKey).str();
9805 const IdentifierInfo *SelectorId = &Context.Idents.get(SelectorName);
9806 if (KnownSelectors.insert(Selectors.
getUnarySelector(SelectorId)).second) {
9807 if (ReturnType.
isNull()) {
9809 Builder.AddPlaceholderChunk(
"object-type");
9810 Builder.AddTextChunk(
" *");
9814 Builder.AddTypedTextChunk(Allocator.
CopyString(SelectorName +
":"));
9816 if (ReturnType.
isNull()) {
9817 Builder.AddPlaceholderChunk(
"object-type");
9818 Builder.AddTextChunk(
" *");
9821 ReturnType, Context, Policy, Builder.getAllocator()));
9824 Builder.AddTextChunk(
"object");
9825 Results.AddResult(
Result(Builder.TakeString(), UnorderedGetterPriority,
9832 if (IsInstanceMethod && ReturnTypeMatchesVoid) {
9833 std::string SelectorName =
9834 (Twine(
"add") + UpperKey + Twine(
"Object")).str();
9835 const IdentifierInfo *SelectorId = &Context.Idents.get(SelectorName);
9836 if (KnownSelectors.insert(Selectors.
getUnarySelector(SelectorId)).second) {
9837 if (ReturnType.
isNull()) {
9839 Builder.AddTextChunk(
"void");
9843 Builder.AddTypedTextChunk(Allocator.
CopyString(SelectorName +
":"));
9845 Builder.AddPlaceholderChunk(
"object-type");
9846 Builder.AddTextChunk(
" *");
9848 Builder.AddTextChunk(
"object");
9849 Results.AddResult(
Result(Builder.TakeString(), UnorderedSetterPriority,
9855 if (IsInstanceMethod && ReturnTypeMatchesVoid) {
9856 std::string SelectorName = (Twine(
"add") + UpperKey).str();
9857 const IdentifierInfo *SelectorId = &Context.Idents.get(SelectorName);
9858 if (KnownSelectors.insert(Selectors.
getUnarySelector(SelectorId)).second) {
9859 if (ReturnType.
isNull()) {
9861 Builder.AddTextChunk(
"void");
9865 Builder.AddTypedTextChunk(Allocator.
CopyString(SelectorName +
":"));
9867 Builder.AddTextChunk(
"NSSet *");
9869 Builder.AddTextChunk(
"objects");
9870 Results.AddResult(
Result(Builder.TakeString(), UnorderedSetterPriority,
9876 if (IsInstanceMethod && ReturnTypeMatchesVoid) {
9877 std::string SelectorName =
9878 (Twine(
"remove") + UpperKey + Twine(
"Object")).str();
9879 const IdentifierInfo *SelectorId = &Context.Idents.get(SelectorName);
9880 if (KnownSelectors.insert(Selectors.
getUnarySelector(SelectorId)).second) {
9881 if (ReturnType.
isNull()) {
9883 Builder.AddTextChunk(
"void");
9887 Builder.AddTypedTextChunk(Allocator.
CopyString(SelectorName +
":"));
9889 Builder.AddPlaceholderChunk(
"object-type");
9890 Builder.AddTextChunk(
" *");
9892 Builder.AddTextChunk(
"object");
9893 Results.AddResult(
Result(Builder.TakeString(), UnorderedSetterPriority,
9899 if (IsInstanceMethod && ReturnTypeMatchesVoid) {
9900 std::string SelectorName = (Twine(
"remove") + UpperKey).str();
9901 const IdentifierInfo *SelectorId = &Context.Idents.get(SelectorName);
9902 if (KnownSelectors.insert(Selectors.
getUnarySelector(SelectorId)).second) {
9903 if (ReturnType.
isNull()) {
9905 Builder.AddTextChunk(
"void");
9909 Builder.AddTypedTextChunk(Allocator.
CopyString(SelectorName +
":"));
9911 Builder.AddTextChunk(
"NSSet *");
9913 Builder.AddTextChunk(
"objects");
9914 Results.AddResult(
Result(Builder.TakeString(), UnorderedSetterPriority,
9920 if (IsInstanceMethod && ReturnTypeMatchesVoid) {
9921 std::string SelectorName = (Twine(
"intersect") + UpperKey).str();
9922 const IdentifierInfo *SelectorId = &Context.Idents.get(SelectorName);
9923 if (KnownSelectors.insert(Selectors.
getUnarySelector(SelectorId)).second) {
9924 if (ReturnType.
isNull()) {
9926 Builder.AddTextChunk(
"void");
9930 Builder.AddTypedTextChunk(Allocator.
CopyString(SelectorName +
":"));
9932 Builder.AddTextChunk(
"NSSet *");
9934 Builder.AddTextChunk(
"objects");
9935 Results.AddResult(
Result(Builder.TakeString(), UnorderedSetterPriority,
9942 if (!IsInstanceMethod &&
9949 std::string SelectorName =
9950 (Twine(
"keyPathsForValuesAffecting") + UpperKey).str();
9951 const IdentifierInfo *SelectorId = &Context.Idents.get(SelectorName);
9954 if (ReturnType.
isNull()) {
9956 Builder.AddTextChunk(
"NSSet<NSString *> *");
9960 Builder.AddTypedTextChunk(Allocator.
CopyString(SelectorName));
9967 if (!IsInstanceMethod &&
9970 std::string SelectorName =
9971 (Twine(
"automaticallyNotifiesObserversOf") + UpperKey).str();
9972 const IdentifierInfo *SelectorId = &Context.Idents.get(SelectorName);
9975 if (ReturnType.
isNull()) {
9977 Builder.AddTextChunk(
"BOOL");
9981 Builder.AddTypedTextChunk(Allocator.
CopyString(SelectorName));
9989 Scope *S, std::optional<bool> IsInstanceMethod,
ParsedType ReturnTy) {
9994 Decl *IDecl =
nullptr;
9995 if (
SemaRef.CurContext->isObjCContainer()) {
10001 bool IsInImplementation =
false;
10002 if (
Decl *D = IDecl) {
10004 SearchDecl = Impl->getClassInterface();
10005 IsInImplementation =
true;
10007 dyn_cast<ObjCCategoryImplDecl>(D)) {
10008 SearchDecl = CatImpl->getCategoryDecl();
10009 IsInImplementation =
true;
10011 SearchDecl = dyn_cast<ObjCContainerDecl>(D);
10014 if (!SearchDecl && S) {
10016 SearchDecl = dyn_cast<ObjCContainerDecl>(DC);
10035 Results.EnterNewScope();
10037 for (KnownMethodsMap::iterator M = KnownMethods.begin(),
10038 MEnd = KnownMethods.end();
10042 Results.getCodeCompletionTUInfo());
10045 if (!IsInstanceMethod) {
10046 Builder.AddTextChunk(
Method->isInstanceMethod() ?
"-" :
"+");
10052 if (ReturnType.
isNull()) {
10053 QualType ResTy =
Method->getSendResultType().stripObjCKindOfType(Context);
10054 AttributedType::stripOuterNullability(ResTy);
10063 Builder.AddTypedTextChunk(
10069 PEnd =
Method->param_end();
10070 P != PEnd; (
void)++P, ++I) {
10073 Builder.AddTypedTextChunk(
10074 Builder.getAllocator().CopyString(Sel.
getNameForSlot(I) +
":"));
10077 Builder.AddTypedTextChunk(
10078 Builder.getAllocator().CopyString(Sel.
getNameForSlot(I) +
":"));
10085 ParamType = (*P)->getType();
10087 ParamType = (*P)->getOriginalType();
10090 AttributedType::stripOuterNullability(ParamType);
10092 Context, Policy, Builder);
10095 Builder.AddTextChunk(
10096 Builder.getAllocator().CopyString(Id->getName()));
10100 if (
Method->isVariadic()) {
10101 if (
Method->param_size() > 0)
10103 Builder.AddTextChunk(
"...");
10106 if (IsInImplementation && Results.includeCodePatterns()) {
10111 if (!
Method->getReturnType()->isVoidType()) {
10113 Builder.AddTextChunk(
"return");
10115 Builder.AddPlaceholderChunk(
"expression");
10118 Builder.AddPlaceholderChunk(
"statements");
10125 auto R =
Result(Builder.TakeString(),
Method, Priority);
10126 if (!M->second.getInt())
10128 Results.AddResult(std::move(R));
10133 if (Context.getLangOpts().ObjC) {
10135 Containers.push_back(SearchDecl);
10138 for (KnownMethodsMap::iterator M = KnownMethods.begin(),
10139 MEnd = KnownMethods.end();
10141 KnownSelectors.insert(M->first);
10146 IFace = Category->getClassInterface();
10151 if (IsInstanceMethod) {
10152 for (
unsigned I = 0, N = Containers.size(); I != N; ++I)
10153 for (
auto *P : Containers[I]->instance_properties())
10155 KnownSelectors, Results);
10159 Results.ExitScope();
10162 Results.getCompletionContext(), Results.data(),
10167 Scope *S,
bool IsInstanceMethod,
bool AtParameterName,
ParsedType ReturnTy,
10171 if (
SemaRef.ExternalSource) {
10172 for (uint32_t I = 0, N =
SemaRef.ExternalSource->GetNumExternalSelectors();
10178 SemaRef.ObjC().ReadMethodPool(Sel);
10189 Results.setPreferredType(
10190 SemaRef.GetTypeFromParser(ReturnTy).getNonReferenceType());
10192 Results.EnterNewScope();
10193 for (SemaObjC::GlobalMethodPool::iterator
10194 M =
SemaRef.ObjC().MethodPool.begin(),
10195 MEnd =
SemaRef.ObjC().MethodPool.end();
10197 for (
ObjCMethodList *MethList = IsInstanceMethod ? &M->second.first
10198 : &M->second.second;
10199 MethList && MethList->getMethod(); MethList = MethList->getNext()) {
10203 if (AtParameterName) {
10205 unsigned NumSelIdents = SelIdents.size();
10206 if (NumSelIdents &&
10207 NumSelIdents <= MethList->getMethod()->param_size()) {
10209 MethList->getMethod()->parameters()[NumSelIdents - 1];
10210 if (Param->getIdentifier()) {
10212 Results.getCodeCompletionTUInfo());
10213 Builder.AddTypedTextChunk(Builder.getAllocator().CopyString(
10214 Param->getIdentifier()->getName()));
10215 Results.AddResult(Builder.TakeString());
10222 Result R(MethList->getMethod(),
10223 Results.getBasePriority(MethList->getMethod()),
10225 R.StartParameter = SelIdents.size();
10226 R.AllParametersAreInformative =
false;
10227 R.DeclaringEntity =
true;
10228 Results.MaybeAddResult(R,
SemaRef.CurContext);
10232 Results.ExitScope();
10234 if (!AtParameterName && !SelIdents.empty() &&
10235 SelIdents.front()->getName().starts_with(
"init")) {
10236 for (
const auto &M :
SemaRef.PP.macros()) {
10237 if (M.first->getName() !=
"NS_DESIGNATED_INITIALIZER")
10239 Results.EnterNewScope();
10241 Results.getCodeCompletionTUInfo());
10242 Builder.AddTypedTextChunk(
10243 Builder.getAllocator().CopyString(M.first->getName()));
10246 Results.ExitScope();
10251 Results.getCompletionContext(), Results.data(),
10259 Results.EnterNewScope();
10263 Results.getCodeCompletionTUInfo());
10264 Builder.AddTypedTextChunk(
"if");
10266 Builder.AddPlaceholderChunk(
"condition");
10267 Results.AddResult(Builder.TakeString());
10270 Builder.AddTypedTextChunk(
"ifdef");
10272 Builder.AddPlaceholderChunk(
"macro");
10273 Results.AddResult(Builder.TakeString());
10276 Builder.AddTypedTextChunk(
"ifndef");
10278 Builder.AddPlaceholderChunk(
"macro");
10279 Results.AddResult(Builder.TakeString());
10281 if (InConditional) {
10283 Builder.AddTypedTextChunk(
"elif");
10285 Builder.AddPlaceholderChunk(
"condition");
10286 Results.AddResult(Builder.TakeString());
10289 Builder.AddTypedTextChunk(
"elifdef");
10291 Builder.AddPlaceholderChunk(
"macro");
10292 Results.AddResult(Builder.TakeString());
10295 Builder.AddTypedTextChunk(
"elifndef");
10297 Builder.AddPlaceholderChunk(
"macro");
10298 Results.AddResult(Builder.TakeString());
10301 Builder.AddTypedTextChunk(
"else");
10302 Results.AddResult(Builder.TakeString());
10305 Builder.AddTypedTextChunk(
"endif");
10306 Results.AddResult(Builder.TakeString());
10310 Builder.AddTypedTextChunk(
"include");
10312 Builder.AddTextChunk(
"\"");
10313 Builder.AddPlaceholderChunk(
"header");
10314 Builder.AddTextChunk(
"\"");
10315 Results.AddResult(Builder.TakeString());
10318 Builder.AddTypedTextChunk(
"include");
10320 Builder.AddTextChunk(
"<");
10321 Builder.AddPlaceholderChunk(
"header");
10322 Builder.AddTextChunk(
">");
10323 Results.AddResult(Builder.TakeString());
10326 Builder.AddTypedTextChunk(
"define");
10328 Builder.AddPlaceholderChunk(
"macro");
10329 Results.AddResult(Builder.TakeString());
10332 Builder.AddTypedTextChunk(
"define");
10334 Builder.AddPlaceholderChunk(
"macro");
10336 Builder.AddPlaceholderChunk(
"args");
10338 Results.AddResult(Builder.TakeString());
10341 Builder.AddTypedTextChunk(
"undef");
10343 Builder.AddPlaceholderChunk(
"macro");
10344 Results.AddResult(Builder.TakeString());
10347 Builder.AddTypedTextChunk(
"line");
10349 Builder.AddPlaceholderChunk(
"number");
10350 Results.AddResult(Builder.TakeString());
10353 Builder.AddTypedTextChunk(
"line");
10355 Builder.AddPlaceholderChunk(
"number");
10357 Builder.AddTextChunk(
"\"");
10358 Builder.AddPlaceholderChunk(
"filename");
10359 Builder.AddTextChunk(
"\"");
10360 Results.AddResult(Builder.TakeString());
10363 Builder.AddTypedTextChunk(
"error");
10365 Builder.AddPlaceholderChunk(
"message");
10366 Results.AddResult(Builder.TakeString());
10369 Builder.AddTypedTextChunk(
"pragma");
10371 Builder.AddPlaceholderChunk(
"arguments");
10372 Results.AddResult(Builder.TakeString());
10376 Builder.AddTypedTextChunk(
"import");
10378 Builder.AddTextChunk(
"\"");
10379 Builder.AddPlaceholderChunk(
"header");
10380 Builder.AddTextChunk(
"\"");
10381 Results.AddResult(Builder.TakeString());
10384 Builder.AddTypedTextChunk(
"import");
10386 Builder.AddTextChunk(
"<");
10387 Builder.AddPlaceholderChunk(
"header");
10388 Builder.AddTextChunk(
">");
10389 Results.AddResult(Builder.TakeString());
10393 Builder.AddTypedTextChunk(
"include_next");
10395 Builder.AddTextChunk(
"\"");
10396 Builder.AddPlaceholderChunk(
"header");
10397 Builder.AddTextChunk(
"\"");
10398 Results.AddResult(Builder.TakeString());
10401 Builder.AddTypedTextChunk(
"include_next");
10403 Builder.AddTextChunk(
"<");
10404 Builder.AddPlaceholderChunk(
"header");
10405 Builder.AddTextChunk(
">");
10406 Results.AddResult(Builder.TakeString());
10409 Builder.AddTypedTextChunk(
"warning");
10411 Builder.AddPlaceholderChunk(
"message");
10412 Results.AddResult(Builder.TakeString());
10416 Builder.AddTypedTextChunk(
"embed");
10418 Builder.AddTextChunk(
"\"");
10419 Builder.AddPlaceholderChunk(
"file");
10420 Builder.AddTextChunk(
"\"");
10421 Results.AddResult(Builder.TakeString());
10424 Builder.AddTypedTextChunk(
"embed");
10426 Builder.AddTextChunk(
"<");
10427 Builder.AddPlaceholderChunk(
"file");
10428 Builder.AddTextChunk(
">");
10429 Results.AddResult(Builder.TakeString());
10437 Results.ExitScope();
10440 Results.getCompletionContext(), Results.data(),
10459 Results.getCodeCompletionTUInfo());
10460 Results.EnterNewScope();
10461 for (
const auto &M :
SemaRef.PP.macros()) {
10462 Builder.AddTypedTextChunk(
10463 Builder.getAllocator().CopyString(M.first->getName()));
10467 Results.ExitScope();
10468 }
else if (IsDefinition) {
10473 Results.getCompletionContext(), Results.data(),
10486 Results.EnterNewScope();
10488 Results.getCodeCompletionTUInfo());
10489 Builder.AddTypedTextChunk(
"defined");
10492 Builder.AddPlaceholderChunk(
"macro");
10494 Results.AddResult(Builder.TakeString());
10495 Results.ExitScope();
10498 Results.getCompletionContext(), Results.data(),
10518 std::string RelDir = llvm::sys::path::convert_to_slash(Dir);
10521 llvm::sys::path::native(NativeRelDir);
10522 llvm::vfs::FileSystem &FS =
10523 SemaRef.getSourceManager().getFileManager().getVirtualFileSystem();
10528 llvm::DenseSet<StringRef> SeenResults;
10531 auto AddCompletion = [&](StringRef Filename,
bool IsDirectory) {
10534 TypedChunk.push_back(IsDirectory ?
'/' : Angled ?
'>' :
'"');
10535 auto R = SeenResults.insert(TypedChunk);
10537 const char *InternedTyped = Results.getAllocator().CopyString(TypedChunk);
10538 *R.first = InternedTyped;
10541 Builder.AddTypedTextChunk(InternedTyped);
10549 auto AddFilesFromIncludeDir = [&](StringRef IncludeDir,
10553 if (!NativeRelDir.empty()) {
10557 auto Begin = llvm::sys::path::begin(NativeRelDir);
10558 auto End = llvm::sys::path::end(NativeRelDir);
10560 llvm::sys::path::append(Dir, *Begin +
".framework",
"Headers");
10561 llvm::sys::path::append(Dir, ++Begin, End);
10563 llvm::sys::path::append(Dir, NativeRelDir);
10567 const StringRef &Dirname = llvm::sys::path::filename(Dir);
10568 const bool isQt = Dirname.starts_with(
"Qt") || Dirname ==
"ActiveQt";
10569 const bool ExtensionlessHeaders =
10570 IsSystem || isQt || Dir.ends_with(
".framework/Headers") ||
10571 IncludeDir.ends_with(
"/include") || IncludeDir.ends_with(
"\\include");
10572 std::error_code EC;
10573 unsigned Count = 0;
10574 for (
auto It = FS.dir_begin(Dir, EC);
10575 !EC && It != llvm::vfs::directory_iterator(); It.increment(EC)) {
10576 if (++Count == 2500)
10578 StringRef Filename = llvm::sys::path::filename(It->path());
10583 llvm::sys::fs::file_type
Type = It->type();
10584 if (
Type == llvm::sys::fs::file_type::symlink_file) {
10585 if (
auto FileStatus = FS.status(It->path()))
10586 Type = FileStatus->getType();
10589 case llvm::sys::fs::file_type::directory_file:
10593 NativeRelDir.empty() && !Filename.consume_back(
".framework"))
10596 AddCompletion(Filename,
true);
10598 case llvm::sys::fs::file_type::regular_file: {
10600 const bool IsHeader = Filename.ends_with_insensitive(
".h") ||
10601 Filename.ends_with_insensitive(
".hh") ||
10602 Filename.ends_with_insensitive(
".hpp") ||
10603 Filename.ends_with_insensitive(
".hxx") ||
10604 Filename.ends_with_insensitive(
".inc") ||
10605 (ExtensionlessHeaders && !Filename.contains(
'.'));
10608 AddCompletion(Filename,
false);
10620 switch (IncludeDir.getLookupType()) {
10625 AddFilesFromIncludeDir(IncludeDir.getDirRef()->getName(), IsSystem,
10629 AddFilesFromIncludeDir(IncludeDir.getFrameworkDirRef()->getName(),
10638 const auto &S =
SemaRef.PP.getHeaderSearchInfo();
10639 using llvm::make_range;
10642 if (
auto CurFile =
SemaRef.PP.getCurrentFileLexer()->getFileEntry())
10643 AddFilesFromIncludeDir(CurFile->getDir().getName(),
false,
10645 for (
const auto &D : make_range(S.quoted_dir_begin(), S.quoted_dir_end()))
10646 AddFilesFromDirLookup(D,
false);
10648 for (
const auto &D : make_range(S.angled_dir_begin(), S.angled_dir_end()))
10649 AddFilesFromDirLookup(D,
false);
10650 for (
const auto &D : make_range(S.system_dir_begin(), S.system_dir_end()))
10651 AddFilesFromDirLookup(D,
true);
10654 Results.getCompletionContext(), Results.data(),
10668 Results.EnterNewScope();
10669 static const char *Platforms[] = {
"macOS",
"iOS",
"watchOS",
"tvOS"};
10673 Twine(Platform) +
"ApplicationExtension")));
10675 Results.ExitScope();
10677 Results.getCompletionContext(), Results.data(),
10684 ResultBuilder Builder(
SemaRef, Allocator, CCTUInfo,
10687 CodeCompletionDeclConsumer Consumer(
10699 Results.insert(Results.end(), Builder.data(),
10700 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.
Result
Implement __builtin_bit_cast and related operations.
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 QualType getDesignatedType(ASTContext &Context, QualType BaseType, const Designation &Desig, HeuristicResolver &Resolver, llvm::function_ref< const FieldDecl *(RecordDecl *, const Designator &)> LookupField)
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 const FieldDecl * lookupDirectField(RecordDecl *RD, const Designator &D)
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 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>.
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.
const RawComment * getRawCommentForAnyRedecl(RawCommentLookupKey Key, const Decl **OriginalDecl=nullptr) const
Return the documentation comment attached to a given declaration or macro.
Represents an array type, per C99 6.7.5.2 - Array Declarators.
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.
lookup_result lookup(DeclarationName Name) const
lookup - Find the declarations (if any) with the given Name in this context.
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
Designator - A designator in a C99 designated initializer.
const IdentifierInfo * getFieldDecl() 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
llvm::iterator_range< macro_iterator > macros(bool IncludeExternalMacros=true) const
SourceManager & getSourceManager() const
MacroDefinition getMacroDefinition(const IdentifierInfo *II)
bool isMacroDefined(StringRef Id)
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 CodeCompleteOffsetOfDesignator(QualType BaseType, const Designation &D)
Trigger code completion for a position inside a __builtin_offsetof member designator (after the type'...
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.
bool isCompleteDefinition() const
Return true if this decl has its body fully specified.
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
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