From 7cf29bc028b11cd0a2e4d2047813ce46e2423fbd Mon Sep 17 00:00:00 2001 From: Kirill Bobyrev Date: Thu, 5 Jul 2018 09:37:26 +0000 Subject: [PATCH] [NFS] Wipe trailing whitespaces This patch is a preparation for another one containing meaningful changes. This patch simply removes trailing whitespaces in few files affected by the upcoming patch and reformats llvm-svn: 336330 --- clang-tools-extra/clangd/Quality.cpp | 125 +- clang/include/clang/Sema/CodeCompleteConsumer.h | 16 +- clang/lib/Sema/SemaCodeComplete.cpp | 1480 +++++++++++------------ 3 files changed, 811 insertions(+), 810 deletions(-) diff --git a/clang-tools-extra/clangd/Quality.cpp b/clang-tools-extra/clangd/Quality.cpp index be02365..13ba899 100644 --- a/clang-tools-extra/clangd/Quality.cpp +++ b/clang-tools-extra/clangd/Quality.cpp @@ -64,7 +64,8 @@ static SymbolQualitySignals::SymbolCategory categorize(const NamedDecl &ND) { return Switch().Visit(&ND); } -static SymbolQualitySignals::SymbolCategory categorize(const CodeCompletionResult &R) { +static SymbolQualitySignals::SymbolCategory +categorize(const CodeCompletionResult &R) { if (R.Declaration) return categorize(*R.Declaration); if (R.Kind == CodeCompletionResult::RK_Macro) @@ -72,57 +73,57 @@ static SymbolQualitySignals::SymbolCategory categorize(const CodeCompletionResul // Everything else is a keyword or a pattern. Patterns are mostly keywords // too, except a few which we recognize by cursor kind. switch (R.CursorKind) { - case CXCursor_CXXMethod: - return SymbolQualitySignals::Function; - case CXCursor_ModuleImportDecl: - return SymbolQualitySignals::Namespace; - case CXCursor_MacroDefinition: - return SymbolQualitySignals::Macro; - case CXCursor_TypeRef: - return SymbolQualitySignals::Type; - case CXCursor_MemberRef: - return SymbolQualitySignals::Variable; - default: - return SymbolQualitySignals::Keyword; + case CXCursor_CXXMethod: + return SymbolQualitySignals::Function; + case CXCursor_ModuleImportDecl: + return SymbolQualitySignals::Namespace; + case CXCursor_MacroDefinition: + return SymbolQualitySignals::Macro; + case CXCursor_TypeRef: + return SymbolQualitySignals::Type; + case CXCursor_MemberRef: + return SymbolQualitySignals::Variable; + default: + return SymbolQualitySignals::Keyword; } } static SymbolQualitySignals::SymbolCategory categorize(const index::SymbolInfo &D) { switch (D.Kind) { - case index::SymbolKind::Namespace: - case index::SymbolKind::NamespaceAlias: - return SymbolQualitySignals::Namespace; - case index::SymbolKind::Macro: - return SymbolQualitySignals::Macro; - case index::SymbolKind::Enum: - case index::SymbolKind::Struct: - case index::SymbolKind::Class: - case index::SymbolKind::Protocol: - case index::SymbolKind::Extension: - case index::SymbolKind::Union: - case index::SymbolKind::TypeAlias: - return SymbolQualitySignals::Type; - case index::SymbolKind::Function: - case index::SymbolKind::ClassMethod: - case index::SymbolKind::InstanceMethod: - case index::SymbolKind::StaticMethod: - case index::SymbolKind::InstanceProperty: - case index::SymbolKind::ClassProperty: - case index::SymbolKind::StaticProperty: - case index::SymbolKind::Constructor: - case index::SymbolKind::Destructor: - case index::SymbolKind::ConversionFunction: - return SymbolQualitySignals::Function; - case index::SymbolKind::Variable: - case index::SymbolKind::Field: - case index::SymbolKind::EnumConstant: - case index::SymbolKind::Parameter: - return SymbolQualitySignals::Variable; - case index::SymbolKind::Using: - case index::SymbolKind::Module: - case index::SymbolKind::Unknown: - return SymbolQualitySignals::Unknown; + case index::SymbolKind::Namespace: + case index::SymbolKind::NamespaceAlias: + return SymbolQualitySignals::Namespace; + case index::SymbolKind::Macro: + return SymbolQualitySignals::Macro; + case index::SymbolKind::Enum: + case index::SymbolKind::Struct: + case index::SymbolKind::Class: + case index::SymbolKind::Protocol: + case index::SymbolKind::Extension: + case index::SymbolKind::Union: + case index::SymbolKind::TypeAlias: + return SymbolQualitySignals::Type; + case index::SymbolKind::Function: + case index::SymbolKind::ClassMethod: + case index::SymbolKind::InstanceMethod: + case index::SymbolKind::StaticMethod: + case index::SymbolKind::InstanceProperty: + case index::SymbolKind::ClassProperty: + case index::SymbolKind::StaticProperty: + case index::SymbolKind::Constructor: + case index::SymbolKind::Destructor: + case index::SymbolKind::ConversionFunction: + return SymbolQualitySignals::Function; + case index::SymbolKind::Variable: + case index::SymbolKind::Field: + case index::SymbolKind::EnumConstant: + case index::SymbolKind::Parameter: + return SymbolQualitySignals::Variable; + case index::SymbolKind::Using: + case index::SymbolKind::Module: + case index::SymbolKind::Unknown: + return SymbolQualitySignals::Unknown; } llvm_unreachable("Unknown index::SymbolKind"); } @@ -160,22 +161,22 @@ float SymbolQualitySignals::evaluate() const { Score *= 0.1f; switch (Category) { - case Keyword: // Often relevant, but misses most signals. - Score *= 4; // FIXME: important keywords should have specific boosts. - break; - case Type: - case Function: - case Variable: - Score *= 1.1f; - break; - case Namespace: - Score *= 0.8f; - break; - case Macro: - Score *= 0.2f; - break; - case Unknown: - break; + case Keyword: // Often relevant, but misses most signals. + Score *= 4; // FIXME: important keywords should have specific boosts. + break; + case Type: + case Function: + case Variable: + Score *= 1.1f; + break; + case Namespace: + Score *= 0.8f; + break; + case Macro: + Score *= 0.2f; + break; + case Unknown: + break; } return Score; diff --git a/clang/include/clang/Sema/CodeCompleteConsumer.h b/clang/include/clang/Sema/CodeCompleteConsumer.h index 86e52f40..d3f6b65 100644 --- a/clang/include/clang/Sema/CodeCompleteConsumer.h +++ b/clang/include/clang/Sema/CodeCompleteConsumer.h @@ -554,14 +554,14 @@ private: /// The availability of this code-completion result. unsigned Availability : 2; - + /// The name of the parent context. StringRef ParentName; /// A brief documentation comment attached to the declaration of /// entity being completed by this result. const char *BriefComment; - + CodeCompletionString(const Chunk *Chunks, unsigned NumChunks, unsigned Priority, CXAvailabilityKind Availability, const char **Annotations, unsigned NumAnnotations, @@ -599,7 +599,7 @@ public: /// Retrieve the annotation string specified by \c AnnotationNr. const char *getAnnotation(unsigned AnnotationNr) const; - + /// Retrieve the name of the parent context. StringRef getParentContextName() const { return ParentName; @@ -608,7 +608,7 @@ public: const char *getBriefComment() const { return BriefComment; } - + /// Retrieve a string representation of the code completion string, /// which is mainly useful for debugging. std::string getAsString() const; @@ -669,7 +669,7 @@ private: CXAvailabilityKind Availability = CXAvailability_Available; StringRef ParentName; const char *BriefComment = nullptr; - + /// The chunks stored in this string. SmallVector Chunks; @@ -728,7 +728,7 @@ public: const char *getBriefComment() const { return BriefComment; } void addBriefComment(StringRef Comment); - + StringRef getParentName() const { return ParentName; } }; @@ -886,8 +886,8 @@ public: StartsNestedNameSpecifier(false), AllParametersAreInformative(false), DeclaringEntity(false) { computeCursorKindAndAvailability(); - } - + } + /// Retrieve the declaration stored in this result. const NamedDecl *getDeclaration() const { assert(Kind == RK_Declaration && "Not a declaration result"); diff --git a/clang/lib/Sema/SemaCodeComplete.cpp b/clang/lib/Sema/SemaCodeComplete.cpp index c56df52..a2252f2 100644 --- a/clang/lib/Sema/SemaCodeComplete.cpp +++ b/clang/lib/Sema/SemaCodeComplete.cpp @@ -50,16 +50,16 @@ namespace { typedef bool (ResultBuilder::*LookupFilter)(const NamedDecl *) const; typedef CodeCompletionResult Result; - + private: /// The actual results we have found. std::vector Results; - + /// A record of all of the declarations we have found and placed /// into the result set, used to ensure that no declaration ever gets into /// the result set twice. llvm::SmallPtrSet AllDeclsFound; - + typedef std::pair DeclIndexPair; /// An entry in the shadow map, which is optimized to store @@ -119,8 +119,8 @@ namespace { /// this name within a particular scope and their index within the list of /// results. typedef llvm::DenseMap ShadowMap; - - /// The semantic analysis object for which results are being + + /// The semantic analysis object for which results are being /// produced. Sema &SemaRef; @@ -128,7 +128,7 @@ namespace { CodeCompletionAllocator &Allocator; CodeCompletionTUInfo &CCTUInfo; - + /// If non-NULL, a filter function used to remove any code-completion /// results that are not desirable. LookupFilter Filter; @@ -140,27 +140,27 @@ namespace { /// If set, the type that we would prefer our resulting value /// declarations to have. /// - /// Closely matching the preferred type gives a boost to a result's + /// Closely matching the preferred type gives a boost to a result's /// priority. CanQualType PreferredType; - + /// A list of shadow maps, which is used to model name hiding at /// different levels of, e.g., the inheritance hierarchy. std::list ShadowMaps; - + /// If we're potentially referring to a C++ member function, the set /// of qualifiers applied to the object type. Qualifiers ObjectTypeQualifiers; - + /// Whether the \p ObjectTypeQualifiers field is active. bool HasObjectTypeQualifiers; - + /// The selector that we prefer. Selector PreferredSelector; - + /// The completion context in which we are gathering results. CodeCompletionContext CompletionContext; - + /// If we are in an instance method definition, the \@implementation /// object. ObjCImplementationDecl *ObjCImplementation; @@ -168,19 +168,19 @@ namespace { void AdjustResultPriorityForDecl(Result &R); void MaybeAddConstructorResults(Result R); - + public: explicit ResultBuilder(Sema &SemaRef, CodeCompletionAllocator &Allocator, CodeCompletionTUInfo &CCTUInfo, const CodeCompletionContext &CompletionContext, LookupFilter Filter = nullptr) : SemaRef(SemaRef), Allocator(Allocator), CCTUInfo(CCTUInfo), - Filter(Filter), - AllowNestedNameSpecifiers(false), HasObjectTypeQualifiers(false), + Filter(Filter), + AllowNestedNameSpecifiers(false), HasObjectTypeQualifiers(false), CompletionContext(CompletionContext), ObjCImplementation(nullptr) - { - // If this is an Objective-C instance method definition, dig out the + { + // If this is an Objective-C instance method definition, dig out the // corresponding implementation. switch (CompletionContext.getKind()) { case CodeCompletionContext::CCC_Expression: @@ -193,7 +193,7 @@ namespace { if (ObjCInterfaceDecl *Interface = Method->getClassInterface()) ObjCImplementation = Interface->getImplementation(); break; - + default: break; } @@ -205,10 +205,10 @@ namespace { /// Whether we should include code patterns in the completion /// results. bool includeCodePatterns() const { - return SemaRef.CodeCompleter && + return SemaRef.CodeCompleter && SemaRef.CodeCompleter->includeCodePatterns(); } - + /// Set the filter used for code-completion results. void setFilter(LookupFilter Filter) { this->Filter = Filter; @@ -217,24 +217,24 @@ namespace { Result *data() { return Results.empty()? nullptr : &Results.front(); } unsigned size() const { return Results.size(); } bool empty() const { return Results.empty(); } - + /// Specify the preferred type. - void setPreferredType(QualType T) { - PreferredType = SemaRef.Context.getCanonicalType(T); + void setPreferredType(QualType T) { + PreferredType = SemaRef.Context.getCanonicalType(T); } - + /// Set the cv-qualifiers on the object type, for us in filtering /// calls to member functions. /// /// When there are qualifiers in this set, they will be used to filter - /// out member functions that aren't available (because there will be a + /// out member functions that aren't available (because there will be a /// cv-qualifier mismatch) or prefer functions with an exact qualifier /// match. void setObjectTypeQualifiers(Qualifiers Quals) { ObjectTypeQualifiers = Quals; HasObjectTypeQualifiers = true; } - + /// Set the preferred selector. /// /// When an Objective-C method declaration result is added, and that @@ -243,13 +243,13 @@ namespace { void setPreferredSelector(Selector Sel) { PreferredSelector = Sel; } - + /// Retrieve the code-completion context for which results are /// being collected. - const CodeCompletionContext &getCompletionContext() const { - return CompletionContext; + const CodeCompletionContext &getCompletionContext() const { + return CompletionContext; } - + /// Specify whether nested-name-specifiers are allowed. void allowNestedNameSpecifiers(bool Allow = true) { AllowNestedNameSpecifiers = Allow; @@ -258,12 +258,12 @@ namespace { /// Return the semantic analysis object for which we are collecting /// code completion results. Sema &getSema() const { return SemaRef; } - + /// Retrieve the allocator used to allocate code completion strings. CodeCompletionAllocator &getAllocator() const { return Allocator; } CodeCompletionTUInfo &getCodeCompletionTUInfo() const { return CCTUInfo; } - + /// Determine whether the given declaration is at all interesting /// as a code-completion result. /// @@ -273,7 +273,7 @@ namespace { /// only interesting when it is a nested-name-specifier. bool isInterestingDecl(const NamedDecl *ND, bool &AsNestedNameSpecifier) const; - + /// Check whether the result is hidden by the Hiding declaration. /// /// \returns true if the result is hidden and cannot be found, false if @@ -282,9 +282,9 @@ namespace { /// qualification). bool CheckHiddenResult(Result &R, DeclContext *CurContext, const NamedDecl *Hiding); - + /// Add a new result to this result set (if it isn't already in one - /// of the shadow maps), or replace an existing result (for, e.g., a + /// of the shadow maps), or replace an existing result (for, e.g., a /// redeclaration). /// /// \param R the result to add (if it is unique). @@ -305,16 +305,16 @@ namespace { /// class of the searched context. void AddResult(Result R, DeclContext *CurContext, NamedDecl *Hiding, bool InBaseClass); - + /// Add a new non-declaration result to this result set. void AddResult(Result R); /// Enter into a new scope. void EnterNewScope(); - + /// Exit from the current scope. void ExitScope(); - + /// Ignore this declaration, if it is seen again. void Ignore(const Decl *D) { AllDeclsFound.insert(D->getCanonicalDecl()); } @@ -327,7 +327,7 @@ namespace { /// /// These predicates can be passed to the name lookup functions to filter the /// results of name lookup. All of the predicates have the same type, so that - /// + /// //@{ bool IsOrdinaryName(const NamedDecl *ND) const; bool IsOrdinaryNonTypeName(const NamedDecl *ND) const; @@ -346,8 +346,8 @@ namespace { bool IsObjCMessageReceiverOrLambdaCapture(const NamedDecl *ND) const; bool IsObjCCollection(const NamedDecl *ND) const; bool IsImpossibleToSatisfy(const NamedDecl *ND) const; - //@} - }; + //@} + }; } class ResultBuilder::ShadowMapEntry::iterator { @@ -359,7 +359,7 @@ public: typedef value_type reference; typedef std::ptrdiff_t difference_type; typedef std::input_iterator_tag iterator_category; - + class pointer { DeclIndexPair Value; @@ -420,7 +420,7 @@ public: } }; -ResultBuilder::ShadowMapEntry::iterator +ResultBuilder::ShadowMapEntry::iterator ResultBuilder::ShadowMapEntry::begin() const { if (DeclOrVector.isNull()) return iterator(); @@ -431,7 +431,7 @@ ResultBuilder::ShadowMapEntry::begin() const { return iterator(DeclOrVector.get()->begin()); } -ResultBuilder::ShadowMapEntry::iterator +ResultBuilder::ShadowMapEntry::iterator ResultBuilder::ShadowMapEntry::end() const { if (DeclOrVector.is() || DeclOrVector.isNull()) return iterator(); @@ -447,7 +447,7 @@ ResultBuilder::ShadowMapEntry::end() const { /// \param CurContext the context where an entity is being named, which is /// typically based on the current scope. /// -/// \param TargetContext the context in which the named entity actually +/// \param TargetContext the context in which the named entity actually /// resides. /// /// \returns a nested name specifier that refers into the target context, or @@ -457,14 +457,14 @@ getRequiredQualification(ASTContext &Context, const DeclContext *CurContext, const DeclContext *TargetContext) { SmallVector TargetParents; - + for (const DeclContext *CommonAncestor = TargetContext; CommonAncestor && !CommonAncestor->Encloses(CurContext); CommonAncestor = CommonAncestor->getLookupParent()) { if (CommonAncestor->isTransparentContext() || CommonAncestor->isFunctionOrMethod()) continue; - + TargetParents.push_back(CommonAncestor); } @@ -482,7 +482,7 @@ getRequiredQualification(ASTContext &Context, Result = NestedNameSpecifier::Create(Context, Result, false, Context.getTypeDeclType(TD).getTypePtr()); - } + } return Result; } @@ -531,17 +531,17 @@ bool ResultBuilder::isInterestingDecl(const NamedDecl *ND, // Skip unnamed entities. if (!ND->getDeclName()) return false; - + // Friend declarations and declarations introduced due to friends are never // added as results. if (ND->getFriendObjectKind() == Decl::FOK_Undeclared) return false; - + // Class template (partial) specializations are never added as results. if (isa(ND) || isa(ND)) return false; - + // Using declarations themselves are never added as results. if (isa(ND)) return false; @@ -559,17 +559,17 @@ bool ResultBuilder::isInterestingDecl(const NamedDecl *ND, // Filter out any unwanted results. if (Filter && !(this->*Filter)(Named)) { // Check whether it is interesting as a nested-name-specifier. - if (AllowNestedNameSpecifiers && SemaRef.getLangOpts().CPlusPlus && + if (AllowNestedNameSpecifiers && SemaRef.getLangOpts().CPlusPlus && IsNestedNameSpecifier(ND) && (Filter != &ResultBuilder::IsMember || - (isa(ND) && + (isa(ND) && cast(ND)->isInjectedClassName()))) { AsNestedNameSpecifier = true; return true; } return false; - } + } // ... then it must be interesting! return true; } @@ -581,24 +581,24 @@ bool ResultBuilder::CheckHiddenResult(Result &R, DeclContext *CurContext, // name if we introduce the tag type. if (!SemaRef.getLangOpts().CPlusPlus) return true; - + const DeclContext *HiddenCtx = R.Declaration->getDeclContext()->getRedeclContext(); - + // There is no way to qualify a name declared in a function or method. if (HiddenCtx->isFunctionOrMethod()) return true; - + if (HiddenCtx == Hiding->getDeclContext()->getRedeclContext()) return true; - + // We can refer to the result with the appropriate qualification. Do it. R.Hidden = true; R.QualifierIsInformative = false; - + if (!R.Qualifier) - R.Qualifier = getRequiredQualification(SemaRef.Context, - CurContext, + R.Qualifier = getRequiredQualification(SemaRef.Context, + CurContext, R.Declaration->getDeclContext()); return false; } @@ -611,62 +611,62 @@ SimplifiedTypeClass clang::getSimplifiedTypeClass(CanQualType T) { switch (cast(T)->getKind()) { case BuiltinType::Void: return STC_Void; - + case BuiltinType::NullPtr: return STC_Pointer; - + case BuiltinType::Overload: case BuiltinType::Dependent: return STC_Other; - + case BuiltinType::ObjCId: case BuiltinType::ObjCClass: case BuiltinType::ObjCSel: return STC_ObjectiveC; - + default: return STC_Arithmetic; } case Type::Complex: return STC_Arithmetic; - + case Type::Pointer: return STC_Pointer; - + case Type::BlockPointer: return STC_Block; - + case Type::LValueReference: case Type::RValueReference: return getSimplifiedTypeClass(T->getAs()->getPointeeType()); - + case Type::ConstantArray: case Type::IncompleteArray: case Type::VariableArray: case Type::DependentSizedArray: return STC_Array; - + case Type::DependentSizedExtVector: case Type::Vector: case Type::ExtVector: return STC_Arithmetic; - + case Type::FunctionProto: case Type::FunctionNoProto: return STC_Function; - + case Type::Record: return STC_Record; - + case Type::Enum: return STC_Arithmetic; - + case Type::ObjCObject: case Type::ObjCInterface: case Type::ObjCObjectPointer: return STC_ObjectiveC; - + default: return STC_Other; } @@ -676,12 +676,12 @@ SimplifiedTypeClass clang::getSimplifiedTypeClass(CanQualType T) { /// is used as an expression in its "typical" code-completion form. QualType clang::getDeclUsageType(ASTContext &C, const NamedDecl *ND) { ND = ND->getUnderlyingDecl(); - + if (const TypeDecl *Type = dyn_cast(ND)) return C.getTypeDeclType(Type); if (const ObjCInterfaceDecl *Iface = dyn_cast(ND)) return C.getObjCInterfaceType(Iface); - + QualType T; if (const FunctionDecl *Function = ND->getAsFunction()) T = Function->getCallResultType(); @@ -726,7 +726,7 @@ QualType clang::getDeclUsageType(ASTContext &C, const NamedDecl *ND) { break; } while (true); - + return T; } @@ -786,7 +786,7 @@ void ResultBuilder::AdjustResultPriorityForDecl(Result &R) { if (const ObjCMethodDecl *Method = dyn_cast(R.Declaration)) if (PreferredSelector == Method->getSelector()) R.Priority += CCD_SelectorMatch; - + // If we have a preferred type, adjust the priority for results with exactly- // matching or nearly-matching types. if (!PreferredType.isNull()) { @@ -800,16 +800,16 @@ void ResultBuilder::AdjustResultPriorityForDecl(Result &R) { else if ((getSimplifiedTypeClass(PreferredType) == getSimplifiedTypeClass(TC)) && !(PreferredType->isEnumeralType() && TC->isEnumeralType())) - R.Priority /= CCF_SimilarTypeMatch; + R.Priority /= CCF_SimilarTypeMatch; } - } + } } void ResultBuilder::MaybeAddConstructorResults(Result R) { if (!SemaRef.getLangOpts().CPlusPlus || !R.Declaration || !CompletionContext.wantConstructorResults()) return; - + ASTContext &Context = SemaRef.Context; const NamedDecl *D = R.Declaration; const CXXRecordDecl *Record = nullptr; @@ -823,12 +823,12 @@ void ResultBuilder::MaybeAddConstructorResults(Result R) { // There are no constructors here. return; } - + Record = Record->getDefinition(); if (!Record) return; - + QualType RecordTy = Context.getTypeDeclType(Record); DeclarationName ConstructorName = Context.DeclarationNames.getCXXConstructorName( @@ -851,7 +851,7 @@ static bool isConstructor(const Decl *ND) { void ResultBuilder::MaybeAddResult(Result R, DeclContext *CurContext) { assert(!ShadowMaps.empty() && "Must enter into a results scope"); - + if (R.Kind != Result::RK_Declaration) { // For non-declaration results, just add the result. Results.push_back(R); @@ -867,14 +867,14 @@ void ResultBuilder::MaybeAddResult(Result R, DeclContext *CurContext) { CurContext); return; } - + const Decl *CanonDecl = R.Declaration->getCanonicalDecl(); unsigned IDNS = CanonDecl->getIdentifierNamespace(); bool AsNestedNameSpecifier = false; if (!isInterestingDecl(R.Declaration, AsNestedNameSpecifier)) return; - + // C++ constructors are never found by name lookup. if (isConstructor(R.Declaration)) return; @@ -893,12 +893,12 @@ void ResultBuilder::MaybeAddResult(Result R, DeclContext *CurContext) { if (ND->getCanonicalDecl() == CanonDecl) { // This is a redeclaration. Always pick the newer declaration. Results[Index].Declaration = R.Declaration; - + // We're done. return; } } - + // This is a new declaration in this scope. However, check whether this // declaration name is hidden by a similarly-named declaration in an outer // scope. @@ -917,21 +917,21 @@ void ResultBuilder::MaybeAddResult(Result R, DeclContext *CurContext) { (IDNS & (Decl::IDNS_Member | Decl::IDNS_Ordinary | Decl::IDNS_LocalExtern | Decl::IDNS_ObjCProtocol))) continue; - + // Protocols are in distinct namespaces from everything else. if (((I->first->getIdentifierNamespace() & Decl::IDNS_ObjCProtocol) || (IDNS & Decl::IDNS_ObjCProtocol)) && I->first->getIdentifierNamespace() != IDNS) continue; - + // The newly-added result is hidden by an entry in the shadow map. if (CheckHiddenResult(R, CurContext, I->first)) return; - + break; } } - + // Make sure that any given declaration only shows up in the result set once. if (!AllDeclsFound.insert(CanonDecl).second) return; @@ -941,9 +941,9 @@ void ResultBuilder::MaybeAddResult(Result R, DeclContext *CurContext) { if (AsNestedNameSpecifier) { R.StartsNestedNameSpecifier = true; R.Priority = CCP_NestedNameSpecifier; - } else + } else AdjustResultPriorityForDecl(R); - + // If this result is supposed to have an informative qualifier, add one. if (R.QualifierIsInformative && !R.Qualifier && !R.StartsNestedNameSpecifier) { @@ -957,17 +957,17 @@ void ResultBuilder::MaybeAddResult(Result R, DeclContext *CurContext) { else R.QualifierIsInformative = false; } - + // Insert this result into the set of results and into the current shadow // map. SMap[R.Declaration->getDeclName()].Add(R.Declaration, Results.size()); Results.push_back(R); - + if (!AsNestedNameSpecifier) MaybeAddConstructorResults(R); } -void ResultBuilder::AddResult(Result R, DeclContext *CurContext, +void ResultBuilder::AddResult(Result R, DeclContext *CurContext, NamedDecl *Hiding, bool InBaseClass = false) { if (R.Kind != Result::RK_Declaration) { // For non-declaration results, just add the result. @@ -983,11 +983,11 @@ void ResultBuilder::AddResult(Result R, DeclContext *CurContext, CurContext, Hiding); return; } - + bool AsNestedNameSpecifier = false; if (!isInterestingDecl(R.Declaration, AsNestedNameSpecifier)) return; - + // C++ constructors are never found by name lookup. if (isConstructor(R.Declaration)) return; @@ -998,7 +998,7 @@ void ResultBuilder::AddResult(Result R, DeclContext *CurContext, // Make sure that any given declaration only shows up in the result set once. if (!AllDeclsFound.insert(R.Declaration->getCanonicalDecl()).second) return; - + // If the filter is for nested-name-specifiers, then this result starts a // nested-name-specifier. if (AsNestedNameSpecifier) { @@ -1023,13 +1023,13 @@ void ResultBuilder::AddResult(Result R, DeclContext *CurContext, else R.QualifierIsInformative = false; } - + // Adjust the priority if this result comes from a base class. if (InBaseClass) R.Priority += CCD_InBaseClass; - + AdjustResultPriorityForDecl(R); - + if (HasObjectTypeQualifiers) if (const CXXMethodDecl *Method = dyn_cast(R.Declaration)) if (Method->isInstance()) { @@ -1038,21 +1038,21 @@ void ResultBuilder::AddResult(Result R, DeclContext *CurContext, if (ObjectTypeQualifiers == MethodQuals) R.Priority += CCD_ObjectQualifierMatch; else if (ObjectTypeQualifiers - MethodQuals) { - // The method cannot be invoked, because doing so would drop + // The method cannot be invoked, because doing so would drop // qualifiers. return; } } - + // Insert this result into the set of results. Results.push_back(R); - + if (!AsNestedNameSpecifier) MaybeAddConstructorResults(R); } void ResultBuilder::AddResult(Result R) { - assert(R.Kind != Result::RK_Declaration && + assert(R.Kind != Result::RK_Declaration && "Declaration results need more context"); Results.push_back(R); } @@ -1067,7 +1067,7 @@ void ResultBuilder::ExitScope() { E != EEnd; ++E) E->second.Destroy(); - + ShadowMaps.pop_back(); } @@ -1085,7 +1085,7 @@ bool ResultBuilder::IsOrdinaryName(const NamedDecl *ND) const { if (isa(ND)) return true; } - + return ND->getIdentifierNamespace() & IDNS; } @@ -1110,18 +1110,18 @@ bool ResultBuilder::IsOrdinaryNonTypeName(const NamedDecl *ND) const { if (isa(ND)) return true; } - + return ND->getIdentifierNamespace() & IDNS; } bool ResultBuilder::IsIntegralConstantValue(const NamedDecl *ND) const { if (!IsOrdinaryNonTypeName(ND)) return 0; - + if (const ValueDecl *VD = dyn_cast(ND->getUnderlyingDecl())) if (VD->getType()->isIntegralOrEnumerationType()) return true; - + return false; } @@ -1133,19 +1133,19 @@ bool ResultBuilder::IsOrdinaryNonValueName(const NamedDecl *ND) const { unsigned IDNS = Decl::IDNS_Ordinary | Decl::IDNS_LocalExtern; if (SemaRef.getLangOpts().CPlusPlus) IDNS |= Decl::IDNS_Tag | Decl::IDNS_Namespace; - - return (ND->getIdentifierNamespace() & IDNS) && - !isa(ND) && !isa(ND) && + + return (ND->getIdentifierNamespace() & IDNS) && + !isa(ND) && !isa(ND) && !isa(ND); } -/// Determines whether the given declaration is suitable as the +/// Determines whether the given declaration is suitable as the /// start of a C++ nested-name-specifier, e.g., a class or namespace. bool ResultBuilder::IsNestedNameSpecifier(const NamedDecl *ND) const { // Allow us to find class templates, too. if (const ClassTemplateDecl *ClassTemplate = dyn_cast(ND)) ND = ClassTemplate->getTemplatedDecl(); - + return SemaRef.isAcceptableNestedNameSpecifier(ND); } @@ -1165,7 +1165,7 @@ bool ResultBuilder::IsClassOrStruct(const NamedDecl *ND) const { return RD->getTagKind() == TTK_Class || RD->getTagKind() == TTK_Struct || RD->getTagKind() == TTK_Interface; - + return false; } @@ -1174,10 +1174,10 @@ bool ResultBuilder::IsUnion(const NamedDecl *ND) const { // Allow us to find class templates, too. if (const ClassTemplateDecl *ClassTemplate = dyn_cast(ND)) ND = ClassTemplate->getTemplatedDecl(); - + if (const RecordDecl *RD = dyn_cast(ND)) return RD->getTagKind() == TTK_Union; - + return false; } @@ -1186,7 +1186,7 @@ bool ResultBuilder::IsNamespace(const NamedDecl *ND) const { return isa(ND); } -/// Determines whether the given declaration is a namespace or +/// Determines whether the given declaration is a namespace or /// namespace alias. bool ResultBuilder::IsNamespaceOrAlias(const NamedDecl *ND) const { return isa(ND->getUnderlyingDecl()); @@ -1210,31 +1210,31 @@ bool ResultBuilder::IsMember(const NamedDecl *ND) const { static bool isObjCReceiverType(ASTContext &C, QualType T) { T = C.getCanonicalType(T); switch (T->getTypeClass()) { - case Type::ObjCObject: + case Type::ObjCObject: case Type::ObjCInterface: case Type::ObjCObjectPointer: return true; - + case Type::Builtin: switch (cast(T)->getKind()) { case BuiltinType::ObjCId: case BuiltinType::ObjCClass: case BuiltinType::ObjCSel: return true; - + default: break; } return false; - + default: break; } - + if (!C.getLangOpts().CPlusPlus) return false; - // FIXME: We could perform more analysis here to determine whether a + // FIXME: We could perform more analysis here to determine whether a // particular class type has any conversions to Objective-C types. For now, // just accept all class types. return T->isDependentType() || T->isRecordType(); @@ -1244,7 +1244,7 @@ bool ResultBuilder::IsObjCMessageReceiver(const NamedDecl *ND) const { QualType T = getDeclUsageType(SemaRef.Context, ND); if (T.isNull()) return false; - + T = SemaRef.Context.getBaseElementType(T); return isObjCReceiverType(SemaRef.Context, T); } @@ -1252,11 +1252,11 @@ bool ResultBuilder::IsObjCMessageReceiver(const NamedDecl *ND) const { bool ResultBuilder::IsObjCMessageReceiverOrLambdaCapture(const NamedDecl *ND) const { if (IsObjCMessageReceiver(ND)) return true; - + const VarDecl *Var = dyn_cast(ND); if (!Var) return false; - + return Var->hasLocalStorage() && !Var->hasAttr(); } @@ -1264,14 +1264,14 @@ bool ResultBuilder::IsObjCCollection(const NamedDecl *ND) const { if ((SemaRef.getLangOpts().CPlusPlus && !IsOrdinaryName(ND)) || (!SemaRef.getLangOpts().CPlusPlus && !IsOrdinaryNonTypeName(ND))) return false; - + QualType T = getDeclUsageType(SemaRef.Context, ND); if (T.isNull()) return false; - + T = SemaRef.Context.getBaseElementType(T); return T->isObjCObjectType() || T->isObjCObjectPointerType() || - T->isObjCIdType() || + T->isObjCIdType() || (SemaRef.getLangOpts().CPlusPlus && T->isRecordType()); } @@ -1342,16 +1342,16 @@ static void AddTypeSpecifierResults(const LangOptions &LangOpts, Results.AddResult(Result("_Bool", CCP_Type)); Results.AddResult(Result("restrict", CCP_Type)); } - + CodeCompletionBuilder Builder(Results.getAllocator(), Results.getCodeCompletionTUInfo()); if (LangOpts.CPlusPlus) { // C++-specific - Results.AddResult(Result("bool", CCP_Type + + Results.AddResult(Result("bool", CCP_Type + (LangOpts.ObjC1? CCD_bool_in_ObjC : 0))); Results.AddResult(Result("class", CCP_Type)); Results.AddResult(Result("wchar_t", CCP_Type)); - + // typename qualified-id Builder.AddTypedTextChunk("typename"); Builder.AddChunk(CodeCompletionString::CK_HorizontalSpace); @@ -1359,12 +1359,12 @@ static void AddTypeSpecifierResults(const LangOptions &LangOpts, Builder.AddTextChunk("::"); Builder.AddPlaceholderChunk("name"); Results.AddResult(Result(Builder.TakeString())); - + if (LangOpts.CPlusPlus11) { Results.AddResult(Result("auto", CCP_Type)); Results.AddResult(Result("char16_t", CCP_Type)); Results.AddResult(Result("char32_t", CCP_Type)); - + Builder.AddTypedTextChunk("decltype"); Builder.AddChunk(CodeCompletionString::CK_LeftParen); Builder.AddPlaceholderChunk("expression"); @@ -1380,7 +1380,7 @@ static void AddTypeSpecifierResults(const LangOptions &LangOpts, // Results.AddResult(Result("_Decimal32")); // Results.AddResult(Result("_Decimal64")); // Results.AddResult(Result("_Decimal128")); - + Builder.AddTypedTextChunk("typeof"); Builder.AddChunk(CodeCompletionString::CK_HorizontalSpace); Builder.AddPlaceholderChunk("expression"); @@ -1400,7 +1400,7 @@ static void AddTypeSpecifierResults(const LangOptions &LangOpts, } static void AddStorageSpecifiers(Sema::ParserCompletionContext CCC, - const LangOptions &LangOpts, + const LangOptions &LangOpts, ResultBuilder &Results) { typedef CodeCompletionResult Result; // Note: we don't suggest either "auto" or "register", because both @@ -1426,7 +1426,7 @@ static void AddStorageSpecifiers(Sema::ParserCompletionContext CCC, } static void AddFunctionSpecifiers(Sema::ParserCompletionContext CCC, - const LangOptions &LangOpts, + const LangOptions &LangOpts, ResultBuilder &Results) { typedef CodeCompletionResult Result; switch (CCC) { @@ -1437,7 +1437,7 @@ static void AddFunctionSpecifiers(Sema::ParserCompletionContext CCC, Results.AddResult(Result("friend")); Results.AddResult(Result("mutable")); Results.AddResult(Result("virtual")); - } + } LLVM_FALLTHROUGH; case Sema::PCC_ObjCInterface: @@ -1465,7 +1465,7 @@ static void AddObjCExpressionResults(ResultBuilder &Results, bool NeedAt); static void AddObjCStatementResults(ResultBuilder &Results, bool NeedAt); static void AddObjCVisibilityResults(const LangOptions &LangOpts, ResultBuilder &Results, - bool NeedAt); + bool NeedAt); static void AddObjCImplementationResults(const LangOptions &LangOpts, ResultBuilder &Results, bool NeedAt); @@ -1482,7 +1482,7 @@ static void AddTypedefResult(ResultBuilder &Results) { Builder.AddPlaceholderChunk("type"); Builder.AddChunk(CodeCompletionString::CK_HorizontalSpace); Builder.AddPlaceholderChunk("name"); - Results.AddResult(CodeCompletionResult(Builder.TakeString())); + Results.AddResult(CodeCompletionResult(Builder.TakeString())); } static bool WantTypesInContext(Sema::ParserCompletionContext CCC, @@ -1499,15 +1499,15 @@ static bool WantTypesInContext(Sema::ParserCompletionContext CCC, case Sema::PCC_ParenthesizedExpression: case Sema::PCC_LocalDeclarationSpecifiers: return true; - + case Sema::PCC_Expression: case Sema::PCC_Condition: return LangOpts.CPlusPlus; - + case Sema::PCC_ObjCInterface: case Sema::PCC_ObjCImplementation: return false; - + case Sema::PCC_ForInit: return LangOpts.CPlusPlus || LangOpts.ObjC1 || LangOpts.C99; } @@ -1543,7 +1543,7 @@ static const char *GetCompletionTypeString(QualType T, // Built-in type names are constant strings. if (const BuiltinType *BT = dyn_cast(T)) return BT->getNameAsCString(Policy); - + // Anonymous tag types are constant strings. if (const TagType *TagT = dyn_cast(T)) if (TagDecl *Tag = TagT->getDecl()) @@ -1557,7 +1557,7 @@ static const char *GetCompletionTypeString(QualType T, } } } - + // Slow path: format the type as a string. std::string Result; T.getAsStringInternal(Result, Policy); @@ -1569,12 +1569,12 @@ static void addThisCompletion(Sema &S, ResultBuilder &Results) { QualType ThisTy = S.getCurrentThisType(); if (ThisTy.isNull()) return; - + CodeCompletionAllocator &Allocator = Results.getAllocator(); CodeCompletionBuilder Builder(Allocator, Results.getCodeCompletionTUInfo()); PrintingPolicy Policy = getCompletionPrintingPolicy(S); - Builder.AddResultTypeChunk(GetCompletionTypeString(ThisTy, - S.Context, + Builder.AddResultTypeChunk(GetCompletionTypeString(ThisTy, + S.Context, Policy, Allocator)); Builder.AddTypedTextChunk("this"); @@ -1603,7 +1603,7 @@ static void AddOrdinaryNameResults(Sema::ParserCompletionContext CCC, ResultBuilder &Results) { CodeCompletionAllocator &Allocator = Results.getAllocator(); CodeCompletionBuilder Builder(Allocator, Results.getCodeCompletionTUInfo()); - + typedef CodeCompletionResult Result; switch (CCC) { case Sema::PCC_Namespace: @@ -1619,7 +1619,7 @@ static void AddOrdinaryNameResults(Sema::ParserCompletionContext CCC, Builder.AddChunk(CodeCompletionString::CK_RightBrace); Results.AddResult(Result(Builder.TakeString())); } - + // namespace identifier = identifier ; Builder.AddTypedTextChunk("namespace"); Builder.AddChunk(CodeCompletionString::CK_HorizontalSpace); @@ -1636,7 +1636,7 @@ static void AddOrdinaryNameResults(Sema::ParserCompletionContext CCC, Builder.AddPlaceholderChunk("identifier"); Results.AddResult(Result(Builder.TakeString())); - // asm(string-literal) + // asm(string-literal) Builder.AddTypedTextChunk("asm"); Builder.AddChunk(CodeCompletionString::CK_LeftParen); Builder.AddPlaceholderChunk("string-literal"); @@ -1651,10 +1651,10 @@ static void AddOrdinaryNameResults(Sema::ParserCompletionContext CCC, Results.AddResult(Result(Builder.TakeString())); } } - + if (SemaRef.getLangOpts().ObjC1) AddObjCTopLevelResults(Results, true); - + AddTypedefResult(Results); LLVM_FALLTHROUGH; @@ -1667,7 +1667,7 @@ static void AddOrdinaryNameResults(Sema::ParserCompletionContext CCC, Builder.AddTextChunk("::"); Builder.AddPlaceholderChunk("name"); Results.AddResult(Result(Builder.TakeString())); - + // using typename qualifier::name (only in a dependent context) if (SemaRef.CurContext->isDependentContext()) { Builder.AddTypedTextChunk("using"); @@ -1728,17 +1728,17 @@ static void AddOrdinaryNameResults(Sema::ParserCompletionContext CCC, AddStorageSpecifiers(CCC, SemaRef.getLangOpts(), Results); AddFunctionSpecifiers(CCC, SemaRef.getLangOpts(), Results); break; - + case Sema::PCC_ObjCImplementation: AddObjCImplementationResults(SemaRef.getLangOpts(), Results, true); AddStorageSpecifiers(CCC, SemaRef.getLangOpts(), Results); AddFunctionSpecifiers(CCC, SemaRef.getLangOpts(), Results); break; - + case Sema::PCC_ObjCInstanceVariableList: AddObjCVisibilityResults(SemaRef.getLangOpts(), Results, true); break; - + case Sema::PCC_RecoveryInFunction: case Sema::PCC_Statement: { AddTypedefResult(Results); @@ -1762,7 +1762,7 @@ static void AddOrdinaryNameResults(Sema::ParserCompletionContext CCC, } if (SemaRef.getLangOpts().ObjC1) AddObjCStatementResults(Results, true); - + if (Results.includeCodePatterns()) { // if (condition) { statements } Builder.AddTypedTextChunk("if"); @@ -1791,7 +1791,7 @@ static void AddOrdinaryNameResults(Sema::ParserCompletionContext CCC, Builder.AddChunk(CodeCompletionString::CK_RightBrace); Results.AddResult(Result(Builder.TakeString())); } - + // Switch-specific statements. if (!SemaRef.getCurFunction()->SwitchStack.empty()) { // case expression: @@ -1853,7 +1853,7 @@ static void AddOrdinaryNameResults(Sema::ParserCompletionContext CCC, Builder.AddChunk(CodeCompletionString::CK_RightBrace); Results.AddResult(Result(Builder.TakeString())); } - + if (S->getContinueParent()) { // continue ; Builder.AddTypedTextChunk("continue"); @@ -1874,7 +1874,7 @@ static void AddOrdinaryNameResults(Sema::ParserCompletionContext CCC, else if (ObjCMethodDecl *Method = dyn_cast(SemaRef.CurContext)) isVoid = Method->getReturnType()->isVoidType(); - else if (SemaRef.getCurBlock() && + else if (SemaRef.getCurBlock() && !SemaRef.getCurBlock()->ReturnType.isNull()) isVoid = SemaRef.getCurBlock()->ReturnType->isVoidType(); Builder.AddTypedTextChunk("return"); @@ -1888,7 +1888,7 @@ static void AddOrdinaryNameResults(Sema::ParserCompletionContext CCC, Builder.AddTypedTextChunk("goto"); Builder.AddChunk(CodeCompletionString::CK_HorizontalSpace); Builder.AddPlaceholderChunk("label"); - Results.AddResult(Result(Builder.TakeString())); + Results.AddResult(Result(Builder.TakeString())); // Using directives Builder.AddTypedTextChunk("using"); @@ -1918,7 +1918,7 @@ static void AddOrdinaryNameResults(Sema::ParserCompletionContext CCC, Builder.AddPlaceholderChunk("type"); Builder.AddChunk(CodeCompletionString::CK_RightParen); Builder.AddPlaceholderChunk("expression"); - Results.AddResult(Result(Builder.TakeString())); + Results.AddResult(Result(Builder.TakeString())); // (__bridge_transfer ) Builder.AddTypedTextChunk("__bridge_transfer"); @@ -1926,7 +1926,7 @@ static void AddOrdinaryNameResults(Sema::ParserCompletionContext CCC, Builder.AddPlaceholderChunk("Objective-C type"); Builder.AddChunk(CodeCompletionString::CK_RightParen); Builder.AddPlaceholderChunk("expression"); - Results.AddResult(Result(Builder.TakeString())); + Results.AddResult(Result(Builder.TakeString())); // (__bridge_retained ) Builder.AddTypedTextChunk("__bridge_retained"); @@ -1934,7 +1934,7 @@ static void AddOrdinaryNameResults(Sema::ParserCompletionContext CCC, Builder.AddPlaceholderChunk("CF type"); Builder.AddChunk(CodeCompletionString::CK_RightParen); Builder.AddPlaceholderChunk("expression"); - Results.AddResult(Result(Builder.TakeString())); + Results.AddResult(Result(Builder.TakeString())); } // Fall through LLVM_FALLTHROUGH; @@ -1943,12 +1943,12 @@ static void AddOrdinaryNameResults(Sema::ParserCompletionContext CCC, if (SemaRef.getLangOpts().CPlusPlus) { // 'this', if we're in a non-static member function. addThisCompletion(SemaRef, Results); - + // true Builder.AddResultTypeChunk("bool"); Builder.AddTypedTextChunk("true"); Results.AddResult(Result(Builder.TakeString())); - + // false Builder.AddResultTypeChunk("bool"); Builder.AddTypedTextChunk("false"); @@ -1963,9 +1963,9 @@ static void AddOrdinaryNameResults(Sema::ParserCompletionContext CCC, Builder.AddChunk(CodeCompletionString::CK_LeftParen); Builder.AddPlaceholderChunk("expression"); Builder.AddChunk(CodeCompletionString::CK_RightParen); - Results.AddResult(Result(Builder.TakeString())); + Results.AddResult(Result(Builder.TakeString())); } - + // static_cast < type-id > ( expression ) Builder.AddTypedTextChunk("static_cast"); Builder.AddChunk(CodeCompletionString::CK_LeftAngle); @@ -1974,7 +1974,7 @@ static void AddOrdinaryNameResults(Sema::ParserCompletionContext CCC, Builder.AddChunk(CodeCompletionString::CK_LeftParen); Builder.AddPlaceholderChunk("expression"); Builder.AddChunk(CodeCompletionString::CK_RightParen); - Results.AddResult(Result(Builder.TakeString())); + Results.AddResult(Result(Builder.TakeString())); // reinterpret_cast < type-id > ( expression ) Builder.AddTypedTextChunk("reinterpret_cast"); @@ -1984,7 +1984,7 @@ static void AddOrdinaryNameResults(Sema::ParserCompletionContext CCC, Builder.AddChunk(CodeCompletionString::CK_LeftParen); Builder.AddPlaceholderChunk("expression"); Builder.AddChunk(CodeCompletionString::CK_RightParen); - Results.AddResult(Result(Builder.TakeString())); + Results.AddResult(Result(Builder.TakeString())); // const_cast < type-id > ( expression ) Builder.AddTypedTextChunk("const_cast"); @@ -1994,7 +1994,7 @@ static void AddOrdinaryNameResults(Sema::ParserCompletionContext CCC, Builder.AddChunk(CodeCompletionString::CK_LeftParen); Builder.AddPlaceholderChunk("expression"); Builder.AddChunk(CodeCompletionString::CK_RightParen); - Results.AddResult(Result(Builder.TakeString())); + Results.AddResult(Result(Builder.TakeString())); if (SemaRef.getLangOpts().RTTI) { // typeid ( expression-or-type ) @@ -2003,9 +2003,9 @@ static void AddOrdinaryNameResults(Sema::ParserCompletionContext CCC, Builder.AddChunk(CodeCompletionString::CK_LeftParen); Builder.AddPlaceholderChunk("expression-or-type"); Builder.AddChunk(CodeCompletionString::CK_RightParen); - Results.AddResult(Result(Builder.TakeString())); + Results.AddResult(Result(Builder.TakeString())); } - + // new T ( ... ) Builder.AddTypedTextChunk("new"); Builder.AddChunk(CodeCompletionString::CK_HorizontalSpace); @@ -2013,7 +2013,7 @@ static void AddOrdinaryNameResults(Sema::ParserCompletionContext CCC, Builder.AddChunk(CodeCompletionString::CK_LeftParen); Builder.AddPlaceholderChunk("expressions"); Builder.AddChunk(CodeCompletionString::CK_RightParen); - Results.AddResult(Result(Builder.TakeString())); + Results.AddResult(Result(Builder.TakeString())); // new T [ ] ( ... ) Builder.AddTypedTextChunk("new"); @@ -2025,14 +2025,14 @@ static void AddOrdinaryNameResults(Sema::ParserCompletionContext CCC, Builder.AddChunk(CodeCompletionString::CK_LeftParen); Builder.AddPlaceholderChunk("expressions"); Builder.AddChunk(CodeCompletionString::CK_RightParen); - Results.AddResult(Result(Builder.TakeString())); + Results.AddResult(Result(Builder.TakeString())); // delete expression Builder.AddResultTypeChunk("void"); Builder.AddTypedTextChunk("delete"); Builder.AddChunk(CodeCompletionString::CK_HorizontalSpace); Builder.AddPlaceholderChunk("expression"); - Results.AddResult(Result(Builder.TakeString())); + Results.AddResult(Result(Builder.TakeString())); // delete [] expression Builder.AddResultTypeChunk("void"); @@ -2052,7 +2052,7 @@ static void AddOrdinaryNameResults(Sema::ParserCompletionContext CCC, Builder.AddPlaceholderChunk("expression"); Results.AddResult(Result(Builder.TakeString())); } - + // FIXME: Rethrow? if (SemaRef.getLangOpts().CPlusPlus11) { @@ -2097,7 +2097,7 @@ static void AddOrdinaryNameResults(Sema::ParserCompletionContext CCC, SuperType = ID->getSuperClass()->getNameAsString(); if (Method->isInstanceMethod()) SuperType += " *"; - + Builder.AddResultTypeChunk(Allocator.CopyString(SuperType)); Builder.AddTypedTextChunk("super"); Results.AddResult(Result(Builder.TakeString())); @@ -2129,7 +2129,7 @@ static void AddOrdinaryNameResults(Sema::ParserCompletionContext CCC, Results.AddResult(Result(Builder.TakeString())); break; } - + case Sema::PCC_Type: case Sema::PCC_LocalDeclarationSpecifiers: break; @@ -2142,7 +2142,7 @@ static void AddOrdinaryNameResults(Sema::ParserCompletionContext CCC, Results.AddResult(Result("operator")); } -/// If the given declaration has an associated type, add it as a result +/// If the given declaration has an associated type, add it as a result /// type chunk. static void AddResultTypeChunk(ASTContext &Context, const PrintingPolicy &Policy, @@ -2184,10 +2184,10 @@ static void AddResultTypeChunk(ASTContext &Context, else T = Property->getType(); } - + if (T.isNull() || Context.hasSameType(T, Context.DependentTy)) return; - + Result.AddResultTypeChunk(GetCompletionTypeString(T, Context, Policy, Result.getAllocator())); } @@ -2206,7 +2206,7 @@ static void MaybeAddSentinel(Preprocessor &PP, } } -static std::string formatObjCParamQualifiers(unsigned ObjCQuals, +static std::string formatObjCParamQualifiers(unsigned ObjCQuals, QualType &Type) { std::string Result; if (ObjCQuals & Decl::OBJC_TQ_In) @@ -2303,13 +2303,13 @@ static std::string FormatFunctionParameter(const PrintingPolicy &Policy, bool ObjCMethodParam = isa(Param->getDeclContext()); if (Param->getType()->isDependentType() || !Param->getType()->isBlockPointerType()) { - // The argument for a dependent or non-block parameter is a placeholder + // The argument for a dependent or non-block parameter is a placeholder // containing that parameter's type. std::string Result; - + if (Param->getIdentifier() && !ObjCMethodParam && !SuppressName) Result = Param->getIdentifier()->getName(); - + QualType Type = Param->getType(); if (ObjCSubsts) Type = Type.substObjCTypeArgs(Param->getASTContext(), *ObjCSubsts, @@ -2350,7 +2350,7 @@ static std::string FormatFunctionParameter(const PrintingPolicy &Policy, Result = Param->getIdentifier()->getName(); QualType Type = Param->getType().getUnqualifiedType(); - + if (ObjCMethodParam) { Result = Type.getAsString(Policy); std::string Quals = @@ -2364,7 +2364,7 @@ static std::string FormatFunctionParameter(const PrintingPolicy &Policy, } else { Type.getAsStringInternal(Result, Policy); } - + return Result; } @@ -2475,10 +2475,10 @@ static void AddFunctionParameterChunks(Preprocessor &PP, unsigned Start = 0, bool InOptional = false) { bool FirstParameter = true; - + for (unsigned P = Start, N = Function->getNumParams(); P != N; ++P) { const ParmVarDecl *Param = Function->getParamDecl(P); - + if (Param->hasDefaultArg() && !InOptional) { // When we see an optional default argument, put that argument and // the remaining default arguments into a new, optional string. @@ -2490,14 +2490,14 @@ static void AddFunctionParameterChunks(Preprocessor &PP, Result.AddOptionalChunk(Opt.TakeString()); break; } - + if (FirstParameter) FirstParameter = false; else Result.AddChunk(CodeCompletionString::CK_Comma); - + InOptional = false; - + // Format the placeholder string. std::string PlaceholderStr = FormatFunctionParameter(Policy, Param); if (Param->hasDefaultArg()) @@ -2510,8 +2510,8 @@ static void AddFunctionParameterChunks(Preprocessor &PP, Result.AddPlaceholderChunk( Result.getAllocator().CopyString(PlaceholderStr)); } - - if (const FunctionProtoType *Proto + + if (const FunctionProtoType *Proto = Function->getType()->getAs()) if (Proto->isVariadic()) { if (Proto->getNumParams() == 0) @@ -2539,7 +2539,7 @@ static void AddTemplateParameterChunks(ASTContext &Context, TemplateParameterList::iterator PEnd = Params->end(); if (MaxParameters) PEnd = Params->begin() + MaxParameters; - for (TemplateParameterList::iterator P = Params->begin() + Start; + for (TemplateParameterList::iterator P = Params->begin() + Start; P != PEnd; ++P) { bool HasDefaultArg = false; std::string PlaceholderStr; @@ -2548,14 +2548,14 @@ static void AddTemplateParameterChunks(ASTContext &Context, PlaceholderStr = "typename"; else PlaceholderStr = "class"; - + if (TTP->getIdentifier()) { PlaceholderStr += ' '; PlaceholderStr += TTP->getIdentifier()->getName(); } - + HasDefaultArg = TTP->hasDefaultArgument(); - } else if (NonTypeTemplateParmDecl *NTTP + } else if (NonTypeTemplateParmDecl *NTTP = dyn_cast(*P)) { if (NTTP->getIdentifier()) PlaceholderStr = NTTP->getIdentifier()->getName(); @@ -2564,7 +2564,7 @@ static void AddTemplateParameterChunks(ASTContext &Context, } else { assert(isa(*P)); TemplateTemplateParmDecl *TTP = cast(*P); - + // Since putting the template argument list into the placeholder would // be very, very long, we just use an abbreviation. PlaceholderStr = "template<...> class"; @@ -2572,10 +2572,10 @@ static void AddTemplateParameterChunks(ASTContext &Context, PlaceholderStr += ' '; PlaceholderStr += TTP->getIdentifier()->getName(); } - + HasDefaultArg = TTP->hasDefaultArgument(); } - + if (HasDefaultArg && !InDefaultArg) { // When we see an optional default argument, put that argument and // the remaining default arguments into a new, optional string. @@ -2588,31 +2588,31 @@ static void AddTemplateParameterChunks(ASTContext &Context, Result.AddOptionalChunk(Opt.TakeString()); break; } - + InDefaultArg = false; - + if (FirstParameter) FirstParameter = false; else Result.AddChunk(CodeCompletionString::CK_Comma); - + // Add the placeholder string. Result.AddPlaceholderChunk( Result.getAllocator().CopyString(PlaceholderStr)); - } + } } /// Add a qualifier to the given code-completion string, if the /// provided nested-name-specifier is non-NULL. -static void -AddQualifierToCompletionString(CodeCompletionBuilder &Result, - NestedNameSpecifier *Qualifier, +static void +AddQualifierToCompletionString(CodeCompletionBuilder &Result, + NestedNameSpecifier *Qualifier, bool QualifierIsInformative, ASTContext &Context, const PrintingPolicy &Policy) { if (!Qualifier) return; - + std::string PrintedNNS; { llvm::raw_string_ostream OS(PrintedNNS); @@ -2624,7 +2624,7 @@ AddQualifierToCompletionString(CodeCompletionBuilder &Result, Result.AddTextChunk(Result.getAllocator().CopyString(PrintedNNS)); } -static void +static void AddFunctionTypeQualsToCompletionString(CodeCompletionBuilder &Result, const FunctionDecl *Function) { const FunctionProtoType *Proto @@ -2633,7 +2633,7 @@ AddFunctionTypeQualsToCompletionString(CodeCompletionBuilder &Result, return; // FIXME: Add ref-qualifier! - + // Handle single qualifiers without copying if (Proto->getTypeQuals() == Qualifiers::Const) { Result.AddInformativeChunk(" const"); @@ -2661,29 +2661,29 @@ AddFunctionTypeQualsToCompletionString(CodeCompletionBuilder &Result, Result.AddInformativeChunk(Result.getAllocator().CopyString(QualsStr)); } -/// Add the name of the given declaration +/// Add the name of the given declaration static void AddTypedNameChunk(ASTContext &Context, const PrintingPolicy &Policy, const NamedDecl *ND, CodeCompletionBuilder &Result) { DeclarationName Name = ND->getDeclName(); if (!Name) return; - + switch (Name.getNameKind()) { case DeclarationName::CXXOperatorName: { const char *OperatorName = nullptr; switch (Name.getCXXOverloadedOperator()) { - case OO_None: + case OO_None: case OO_Conditional: case NUM_OVERLOADED_OPERATORS: - OperatorName = "operator"; + OperatorName = "operator"; break; - + #define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \ case OO_##Name: OperatorName = "operator" Spelling; break; #define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly) #include "clang/Basic/OperatorKinds.def" - + case OO_New: OperatorName = "operator new"; break; case OO_Delete: OperatorName = "operator delete"; break; case OO_Array_New: OperatorName = "operator new[]"; break; @@ -2694,7 +2694,7 @@ static void AddTypedNameChunk(ASTContext &Context, const PrintingPolicy &Policy, Result.AddTypedTextChunk(OperatorName); break; } - + case DeclarationName::Identifier: case DeclarationName::CXXConversionFunctionName: case DeclarationName::CXXDestructorName: @@ -2702,14 +2702,14 @@ static void AddTypedNameChunk(ASTContext &Context, const PrintingPolicy &Policy, Result.AddTypedTextChunk( Result.getAllocator().CopyString(ND->getNameAsString())); break; - + case DeclarationName::CXXDeductionGuideName: case DeclarationName::CXXUsingDirective: case DeclarationName::ObjCZeroArgSelector: case DeclarationName::ObjCOneArgSelector: case DeclarationName::ObjCMultiArgSelector: break; - + case DeclarationName::CXXConstructorName: { CXXRecordDecl *Record = nullptr; QualType Ty = Name.getCXXNameType(); @@ -2723,7 +2723,7 @@ static void AddTypedNameChunk(ASTContext &Context, const PrintingPolicy &Policy, Result.getAllocator().CopyString(ND->getNameAsString())); break; } - + Result.AddTypedTextChunk( Result.getAllocator().CopyString(Record->getNameAsString())); if (ClassTemplateDecl *Template = Record->getDescribedClassTemplate()) { @@ -2759,12 +2759,12 @@ CodeCompletionResult::CreateCodeCompletionString(ASTContext &Ctx, CodeCompletionTUInfo &CCTUInfo, bool IncludeBriefComments) { CodeCompletionBuilder Result(Allocator, CCTUInfo, Priority, Availability); - + PrintingPolicy Policy = getCompletionPrintingPolicy(Ctx, PP); if (Kind == RK_Pattern) { Pattern->Priority = Priority; Pattern->Availability = Availability; - + if (Declaration) { Result.addParentContext(Declaration->getDeclContext()); Pattern->ParentName = Result.getParentName(); @@ -2774,15 +2774,15 @@ CodeCompletionResult::CreateCodeCompletionString(ASTContext &Ctx, Pattern->BriefComment = Result.getBriefComment(); } } - + return Pattern; } - + if (Kind == RK_Keyword) { Result.AddTypedTextChunk(Keyword); return Result.TakeString(); } - + if (Kind == RK_Macro) { const MacroInfo *MI = PP.getMacroInfo(Macro); Result.AddTypedTextChunk( @@ -2790,20 +2790,20 @@ CodeCompletionResult::CreateCodeCompletionString(ASTContext &Ctx, if (!MI || !MI->isFunctionLike()) return Result.TakeString(); - + // Format a function-like macro with placeholders for the arguments. Result.AddChunk(CodeCompletionString::CK_LeftParen); MacroInfo::param_iterator A = MI->param_begin(), AEnd = MI->param_end(); - + // C99 variadic macros add __VA_ARGS__ at the end. Skip it. if (MI->isC99Varargs()) { --AEnd; - + if (A == AEnd) { Result.AddPlaceholderChunk("..."); } } - + for (MacroInfo::param_iterator A = MI->param_begin(); A != AEnd; ++A) { if (A != MI->param_begin()) Result.AddChunk(CodeCompletionString::CK_Comma); @@ -2825,7 +2825,7 @@ CodeCompletionResult::CreateCodeCompletionString(ASTContext &Ctx, Result.AddChunk(CodeCompletionString::CK_RightParen); return Result.TakeString(); } - + assert(Kind == RK_Declaration && "Missed a result kind?"); const NamedDecl *ND = Declaration; Result.addParentContext(ND->getDeclContext()); @@ -2834,7 +2834,7 @@ CodeCompletionResult::CreateCodeCompletionString(ASTContext &Ctx, // Add documentation comment, if it exists. if (const RawComment *RC = getCompletionComment(Ctx, Declaration)) { Result.addBriefComment(RC->getBriefText(Ctx)); - } + } } if (StartsNestedNameSpecifier) { @@ -2848,9 +2848,9 @@ CodeCompletionResult::CreateCodeCompletionString(ASTContext &Ctx, Result.AddAnnotation(Result.getAllocator().CopyString(I->getAnnotation())); AddResultTypeChunk(Ctx, Policy, ND, CCContext.getBaseType(), Result); - + if (const FunctionDecl *Function = dyn_cast(ND)) { - AddQualifierToCompletionString(Result, Qualifier, QualifierIsInformative, + AddQualifierToCompletionString(Result, Qualifier, QualifierIsInformative, Ctx, Policy); AddTypedNameChunk(Ctx, Policy, ND, Result); Result.AddChunk(CodeCompletionString::CK_LeftParen); @@ -2859,9 +2859,9 @@ CodeCompletionResult::CreateCodeCompletionString(ASTContext &Ctx, AddFunctionTypeQualsToCompletionString(Result, Function); return Result.TakeString(); } - + if (const FunctionTemplateDecl *FunTmpl = dyn_cast(ND)) { - AddQualifierToCompletionString(Result, Qualifier, QualifierIsInformative, + AddQualifierToCompletionString(Result, Qualifier, QualifierIsInformative, Ctx, Policy); FunctionDecl *Function = FunTmpl->getTemplatedDecl(); AddTypedNameChunk(Ctx, Policy, Function, Result); @@ -2882,30 +2882,30 @@ CodeCompletionResult::CreateCodeCompletionString(ASTContext &Ctx, LastDeducibleArgument - 1); if (TemplateTypeParmDecl *TTP = dyn_cast(Param)) HasDefaultArg = TTP->hasDefaultArgument(); - else if (NonTypeTemplateParmDecl *NTTP + else if (NonTypeTemplateParmDecl *NTTP = dyn_cast(Param)) HasDefaultArg = NTTP->hasDefaultArgument(); else { assert(isa(Param)); - HasDefaultArg + HasDefaultArg = cast(Param)->hasDefaultArgument(); } - + if (!HasDefaultArg) break; } } - + if (LastDeducibleArgument) { // Some of the function template arguments cannot be deduced from a // function call, so we introduce an explicit template argument list // containing all of the arguments up to the first deducible argument. Result.AddChunk(CodeCompletionString::CK_LeftAngle); - AddTemplateParameterChunks(Ctx, Policy, FunTmpl, Result, + AddTemplateParameterChunks(Ctx, Policy, FunTmpl, Result, LastDeducibleArgument); Result.AddChunk(CodeCompletionString::CK_RightAngle); } - + // Add the function parameters Result.AddChunk(CodeCompletionString::CK_LeftParen); AddFunctionParameterChunks(PP, Policy, Function, Result); @@ -2913,9 +2913,9 @@ CodeCompletionResult::CreateCodeCompletionString(ASTContext &Ctx, AddFunctionTypeQualsToCompletionString(Result, Function); return Result.TakeString(); } - + if (const TemplateDecl *Template = dyn_cast(ND)) { - AddQualifierToCompletionString(Result, Qualifier, QualifierIsInformative, + AddQualifierToCompletionString(Result, Qualifier, QualifierIsInformative, Ctx, Policy); Result.AddTypedTextChunk( Result.getAllocator().CopyString(Template->getNameAsString())); @@ -2924,7 +2924,7 @@ CodeCompletionResult::CreateCodeCompletionString(ASTContext &Ctx, Result.AddChunk(CodeCompletionString::CK_RightAngle); return Result.TakeString(); } - + if (const ObjCMethodDecl *Method = dyn_cast(ND)) { Selector Sel = Method->getSelector(); if (Sel.isUnarySelector()) { @@ -2939,7 +2939,7 @@ CodeCompletionResult::CreateCodeCompletionString(ASTContext &Ctx, Result.AddTypedTextChunk(Result.getAllocator().CopyString(SelName)); else { Result.AddInformativeChunk(Result.getAllocator().CopyString(SelName)); - + // If there is only one parameter, and we're past it, add an empty // typed-text chunk since there is nothing to type. if (Method->param_size() == 1) @@ -2958,10 +2958,10 @@ CodeCompletionResult::CreateCodeCompletionString(ASTContext &Ctx, Keyword += ":"; if (Idx < StartParameter || AllParametersAreInformative) Result.AddInformativeChunk(Result.getAllocator().CopyString(Keyword)); - else + else Result.AddTypedTextChunk(Result.getAllocator().CopyString(Keyword)); } - + // If we're before the starting parameter, skip the placeholder. if (Idx < StartParameter) continue; @@ -2987,10 +2987,10 @@ CodeCompletionResult::CreateCodeCompletionString(ASTContext &Ctx, if (DeclaringEntity || AllParametersAreInformative) Arg += II->getName(); } - + if (Method->isVariadic() && (P + 1) == PEnd) Arg += ", ..."; - + if (DeclaringEntity) Result.AddTextChunk(Result.getAllocator().CopyString(Arg)); else if (AllParametersAreInformative) @@ -3008,15 +3008,15 @@ CodeCompletionResult::CreateCodeCompletionString(ASTContext &Ctx, else Result.AddPlaceholderChunk(", ..."); } - + MaybeAddSentinel(PP, Method, Result); } - + return Result.TakeString(); } if (Qualifier) - AddQualifierToCompletionString(Result, Qualifier, QualifierIsInformative, + AddQualifierToCompletionString(Result, Qualifier, QualifierIsInformative, Ctx, Policy); Result.AddTypedTextChunk( @@ -3160,7 +3160,7 @@ CodeCompleteConsumer::OverloadCandidate::CreateSignatureString( const FunctionProtoType *Proto = dyn_cast(getFunctionType()); if (!FDecl && !Proto) { - // Function without a prototype. Just give the return type and a + // Function without a prototype. Just give the return type and a // highlighted ellipsis. const FunctionType *FT = getFunctionType(); Result.AddResultTypeChunk(Result.getAllocator().CopyString( @@ -3193,18 +3193,18 @@ CodeCompleteConsumer::OverloadCandidate::CreateSignatureString( return Result.TakeString(); } -unsigned clang::getMacroUsagePriority(StringRef MacroName, +unsigned clang::getMacroUsagePriority(StringRef MacroName, const LangOptions &LangOpts, bool PreferredTypeIsPointer) { unsigned Priority = CCP_Macro; - + // Treat the "nil", "Nil" and "NULL" macros as null pointer constants. - if (MacroName.equals("nil") || MacroName.equals("NULL") || + if (MacroName.equals("nil") || MacroName.equals("NULL") || MacroName.equals("Nil")) { Priority = CCP_Constant; if (PreferredTypeIsPointer) Priority = Priority / CCF_SimilarTypeMatch; - } + } // Treat "YES", "NO", "true", and "false" as constants. else if (MacroName.equals("YES") || MacroName.equals("NO") || MacroName.equals("true") || MacroName.equals("false")) @@ -3212,27 +3212,27 @@ unsigned clang::getMacroUsagePriority(StringRef MacroName, // Treat "bool" as a type. else if (MacroName.equals("bool")) Priority = CCP_Type + (LangOpts.ObjC1? CCD_bool_in_ObjC : 0); - - + + return Priority; } CXCursorKind clang::getCursorKindForDecl(const Decl *D) { if (!D) return CXCursor_UnexposedDecl; - + switch (D->getKind()) { case Decl::Enum: return CXCursor_EnumDecl; case Decl::EnumConstant: return CXCursor_EnumConstantDecl; case Decl::Field: return CXCursor_FieldDecl; - case Decl::Function: + case Decl::Function: return CXCursor_FunctionDecl; case Decl::ObjCCategory: return CXCursor_ObjCCategoryDecl; case Decl::ObjCCategoryImpl: return CXCursor_ObjCCategoryImplDecl; case Decl::ObjCImplementation: return CXCursor_ObjCImplementationDecl; case Decl::ObjCInterface: return CXCursor_ObjCInterfaceDecl; - case Decl::ObjCIvar: return CXCursor_ObjCIvarDecl; + case Decl::ObjCIvar: return CXCursor_ObjCIvarDecl; case Decl::ObjCMethod: return cast(D)->isInstanceMethod() ? CXCursor_ObjCInstanceMethodDecl : CXCursor_ObjCClassMethodDecl; @@ -3261,17 +3261,17 @@ CXCursorKind clang::getCursorKindForDecl(const Decl *D) { case Decl::StaticAssert: return CXCursor_StaticAssert; case Decl::Friend: return CXCursor_FriendDecl; case Decl::TranslationUnit: return CXCursor_TranslationUnit; - + case Decl::Using: case Decl::UnresolvedUsingValue: - case Decl::UnresolvedUsingTypename: + case Decl::UnresolvedUsingTypename: return CXCursor_UsingDeclaration; - + case Decl::ObjCPropertyImpl: switch (cast(D)->getPropertyImplementation()) { case ObjCPropertyImplDecl::Dynamic: return CXCursor_ObjCDynamicDecl; - + case ObjCPropertyImplDecl::Synthesize: return CXCursor_ObjCSynthesizeDecl; } @@ -3292,7 +3292,7 @@ CXCursorKind clang::getCursorKindForDecl(const Decl *D) { } } } - + return CXCursor_UnexposedDecl; } @@ -3300,10 +3300,10 @@ static void AddMacroResults(Preprocessor &PP, ResultBuilder &Results, bool IncludeUndefined, bool TargetTypeIsPointer = false) { typedef CodeCompletionResult Result; - + Results.EnterNewScope(); - - for (Preprocessor::macro_iterator M = PP.macro_begin(), + + for (Preprocessor::macro_iterator M = PP.macro_begin(), MEnd = PP.macro_end(); M != MEnd; ++M) { auto MD = PP.getMacroDefinition(M->first); @@ -3318,17 +3318,17 @@ static void AddMacroResults(Preprocessor &PP, ResultBuilder &Results, TargetTypeIsPointer))); } } - + Results.ExitScope(); - + } -static void AddPrettyFunctionResults(const LangOptions &LangOpts, +static void AddPrettyFunctionResults(const LangOptions &LangOpts, ResultBuilder &Results) { typedef CodeCompletionResult Result; - + Results.EnterNewScope(); - + Results.AddResult(Result("__PRETTY_FUNCTION__", CCP_Constant)); Results.AddResult(Result("__FUNCTION__", CCP_Constant)); if (LangOpts.C99 || LangOpts.CPlusPlus11) @@ -3345,24 +3345,24 @@ static void HandleCodeCompleteResults(Sema *S, CodeCompleter->ProcessCodeCompleteResults(*S, Context, Results, NumResults); } -static enum CodeCompletionContext::Kind mapCodeCompletionContext(Sema &S, +static enum CodeCompletionContext::Kind mapCodeCompletionContext(Sema &S, Sema::ParserCompletionContext PCC) { switch (PCC) { case Sema::PCC_Namespace: return CodeCompletionContext::CCC_TopLevel; - + case Sema::PCC_Class: return CodeCompletionContext::CCC_ClassStructUnion; case Sema::PCC_ObjCInterface: return CodeCompletionContext::CCC_ObjCInterface; - + case Sema::PCC_ObjCImplementation: return CodeCompletionContext::CCC_ObjCImplementation; case Sema::PCC_ObjCInstanceVariableList: return CodeCompletionContext::CCC_ObjCIvarList; - + case Sema::PCC_Template: case Sema::PCC_MemberTemplate: if (S.CurContext->isFileContext()) @@ -3370,7 +3370,7 @@ static enum CodeCompletionContext::Kind mapCodeCompletionContext(Sema &S, if (S.CurContext->isRecord()) return CodeCompletionContext::CCC_ClassStructUnion; return CodeCompletionContext::CCC_Other; - + case Sema::PCC_RecoveryInFunction: return CodeCompletionContext::CCC_Recovery; @@ -3384,7 +3384,7 @@ static enum CodeCompletionContext::Kind mapCodeCompletionContext(Sema &S, case Sema::PCC_Expression: case Sema::PCC_Condition: return CodeCompletionContext::CCC_Expression; - + case Sema::PCC_Statement: return CodeCompletionContext::CCC_Statement; @@ -3393,7 +3393,7 @@ static enum CodeCompletionContext::Kind mapCodeCompletionContext(Sema &S, case Sema::PCC_ParenthesizedExpression: return CodeCompletionContext::CCC_ParenthesizedExpression; - + case Sema::PCC_LocalDeclarationSpecifiers: return CodeCompletionContext::CCC_Type; } @@ -3402,26 +3402,26 @@ static enum CodeCompletionContext::Kind mapCodeCompletionContext(Sema &S, } /// If we're in a C++ virtual member function, add completion results -/// that invoke the functions we override, since it's common to invoke the +/// that invoke the functions we override, since it's common to invoke the /// overridden function as well as adding new functionality. /// /// \param S The semantic analysis object for which we are generating results. /// /// \param InContext This context in which the nested-name-specifier preceding -/// the code-completion point +/// the code-completion point static void MaybeAddOverrideCalls(Sema &S, DeclContext *InContext, ResultBuilder &Results) { // Look through blocks. DeclContext *CurContext = S.CurContext; while (isa(CurContext)) CurContext = CurContext->getParent(); - - + + CXXMethodDecl *Method = dyn_cast(CurContext); if (!Method || !Method->isVirtual()) return; - - // We need to have names for all of the parameters, if we're going to + + // We need to have names for all of the parameters, if we're going to // generate a forwarding call. for (auto P : Method->parameters()) if (!P->getDeclName()) @@ -3433,7 +3433,7 @@ static void MaybeAddOverrideCalls(Sema &S, DeclContext *InContext, Results.getCodeCompletionTUInfo()); if (Overridden->getCanonicalDecl() == Method->getCanonicalDecl()) continue; - + // If we need a nested-name-specifier, add one now. if (!InContext) { NestedNameSpecifier *NNS @@ -3447,8 +3447,8 @@ static void MaybeAddOverrideCalls(Sema &S, DeclContext *InContext, } } else if (!InContext->Equals(Overridden->getDeclContext())) continue; - - Builder.AddTypedTextChunk(Results.getAllocator().CopyString( + + Builder.AddTypedTextChunk(Results.getAllocator().CopyString( Overridden->getNameAsString())); Builder.AddChunk(CodeCompletionString::CK_LeftParen); bool FirstParam = true; @@ -3471,14 +3471,14 @@ static void MaybeAddOverrideCalls(Sema &S, DeclContext *InContext, } } -void Sema::CodeCompleteModuleImport(SourceLocation ImportLoc, +void Sema::CodeCompleteModuleImport(SourceLocation ImportLoc, ModuleIdPath Path) { typedef CodeCompletionResult Result; ResultBuilder Results(*this, CodeCompleter->getAllocator(), CodeCompleter->getCodeCompletionTUInfo(), CodeCompletionContext::CCC_Other); Results.EnterNewScope(); - + CodeCompletionAllocator &Allocator = Results.getAllocator(); CodeCompletionBuilder Builder(Allocator, Results.getCodeCompletionTUInfo()); typedef CodeCompletionResult Result; @@ -3490,7 +3490,7 @@ void Sema::CodeCompleteModuleImport(SourceLocation ImportLoc, Builder.AddTypedTextChunk( Builder.getAllocator().CopyString(Modules[I]->Name)); Results.AddResult(Result(Builder.TakeString(), - CCP_Declaration, + CCP_Declaration, CXCursor_ModuleImportDecl, Modules[I]->isAvailable() ? CXAvailability_Available @@ -3503,14 +3503,14 @@ void Sema::CodeCompleteModuleImport(SourceLocation ImportLoc, /*IsInclusionDirective=*/false); // Enumerate submodules. if (Mod) { - for (Module::submodule_iterator Sub = Mod->submodule_begin(), + for (Module::submodule_iterator Sub = Mod->submodule_begin(), SubEnd = Mod->submodule_end(); Sub != SubEnd; ++Sub) { - + Builder.AddTypedTextChunk( Builder.getAllocator().CopyString((*Sub)->Name)); Results.AddResult(Result(Builder.TakeString(), - CCP_Declaration, + CCP_Declaration, CXCursor_ModuleImportDecl, (*Sub)->isAvailable() ? CXAvailability_Available @@ -3518,18 +3518,18 @@ void Sema::CodeCompleteModuleImport(SourceLocation ImportLoc, } } } - Results.ExitScope(); + Results.ExitScope(); HandleCodeCompleteResults(this, CodeCompleter, Results.getCompletionContext(), Results.data(),Results.size()); } -void Sema::CodeCompleteOrdinaryName(Scope *S, +void Sema::CodeCompleteOrdinaryName(Scope *S, ParserCompletionContext CompletionContext) { ResultBuilder Results(*this, CodeCompleter->getAllocator(), CodeCompleter->getCodeCompletionTUInfo(), mapCodeCompletionContext(*this, CompletionContext)); Results.EnterNewScope(); - + // Determine how to filter results, e.g., so that the names of // values (functions, enumerators, function templates, etc.) are // only allowed where we can have an expression. @@ -3555,11 +3555,11 @@ void Sema::CodeCompleteOrdinaryName(Scope *S, Results.setFilter(&ResultBuilder::IsOrdinaryName); else Results.setFilter(&ResultBuilder::IsOrdinaryNonTypeName); - + if (getLangOpts().CPlusPlus) MaybeAddOverrideCalls(*this, /*InContext=*/nullptr, Results); break; - + case PCC_RecoveryInFunction: // Unfiltered break; @@ -3571,7 +3571,7 @@ void Sema::CodeCompleteOrdinaryName(Scope *S, if (CurMethod->isInstance()) Results.setObjectTypeQualifiers( Qualifiers::fromCVRMask(CurMethod->getTypeQualifiers())); - + CodeCompletionDeclConsumer Consumer(Results, CurContext); LookupVisibleDecls(S, LookupOrdinaryName, Consumer, CodeCompleter->includeGlobals(), @@ -3588,7 +3588,7 @@ void Sema::CodeCompleteOrdinaryName(Scope *S, if (S->getFnParent()) AddPrettyFunctionResults(getLangOpts(), Results); break; - + case PCC_Namespace: case PCC_Class: case PCC_ObjCInterface: @@ -3602,15 +3602,15 @@ void Sema::CodeCompleteOrdinaryName(Scope *S, case PCC_LocalDeclarationSpecifiers: break; } - + if (CodeCompleter->includeMacros()) AddMacroResults(PP, Results, false); - + HandleCodeCompleteResults(this, CodeCompleter, Results.getCompletionContext(), Results.data(),Results.size()); } -static void AddClassMessageCompletions(Sema &SemaRef, Scope *S, +static void AddClassMessageCompletions(Sema &SemaRef, Scope *S, ParsedType Receiver, ArrayRef SelIdents, bool AtArgumentExpression, @@ -3627,7 +3627,7 @@ void Sema::CodeCompleteDeclSpec(Scope *S, DeclSpec &DS, ? CodeCompletionContext::CCC_PotentiallyQualifiedName : CodeCompletionContext::CCC_Name); Results.EnterNewScope(); - + // Type qualifiers can come after names. Results.AddResult(Result("const")); Results.AddResult(Result("volatile")); @@ -3641,9 +3641,9 @@ void Sema::CodeCompleteDeclSpec(Scope *S, DeclSpec &DS, Results.AddResult("final"); if (AllowNonIdentifiers) { - Results.AddResult(Result("operator")); + Results.AddResult(Result("operator")); } - + // Add nested-name-specifiers. if (AllowNestedNameSpecifiers) { Results.allowNestedNameSpecifiers(); @@ -3670,7 +3670,7 @@ void Sema::CodeCompleteDeclSpec(Scope *S, DeclSpec &DS, S && (S->getFlags() & Scope::DeclScope) != 0 && (S->getFlags() & (Scope::ClassScope | Scope::TemplateParamScope | - Scope::FunctionPrototypeScope | + Scope::FunctionPrototypeScope | Scope::AtCatchScope)) == 0) { ParsedType T = DS.getRepAsType(); if (!T.get().isNull() && T.get()->isObjCObjectOrInterfaceType()) @@ -3680,16 +3680,16 @@ void Sema::CodeCompleteDeclSpec(Scope *S, DeclSpec &DS, // Note that we intentionally suppress macro results here, since we do not // encourage using macros to produce the names of entities. - HandleCodeCompleteResults(this, CodeCompleter, + HandleCodeCompleteResults(this, CodeCompleter, Results.getCompletionContext(), Results.data(), Results.size()); } struct Sema::CodeCompleteExpressionData { - CodeCompleteExpressionData(QualType PreferredType = QualType()) + CodeCompleteExpressionData(QualType PreferredType = QualType()) : PreferredType(PreferredType), IntegralConstantExpression(false), ObjCCollection(false) { } - + QualType PreferredType; bool IntegralConstantExpression; bool ObjCCollection; @@ -3698,7 +3698,7 @@ struct Sema::CodeCompleteExpressionData { /// Perform code-completion in an expression context when we know what /// type we're looking for. -void Sema::CodeCompleteExpression(Scope *S, +void Sema::CodeCompleteExpression(Scope *S, const CodeCompleteExpressionData &Data) { ResultBuilder Results( *this, CodeCompleter->getAllocator(), @@ -3716,11 +3716,11 @@ void Sema::CodeCompleteExpression(Scope *S, if (!Data.PreferredType.isNull()) Results.setPreferredType(Data.PreferredType.getNonReferenceType()); - + // Ignore any declarations that we were told that we don't care about. for (unsigned I = 0, N = Data.IgnoreDecls.size(); I != N; ++I) Results.Ignore(Data.IgnoreDecls[I]); - + CodeCompletionDeclConsumer Consumer(Results, CurContext); LookupVisibleDecls(S, LookupOrdinaryName, Consumer, CodeCompleter->includeGlobals(), @@ -3729,15 +3729,15 @@ void Sema::CodeCompleteExpression(Scope *S, Results.EnterNewScope(); AddOrdinaryNameResults(PCC_Expression, S, *this, Results); Results.ExitScope(); - + bool PreferredTypeIsPointer = false; if (!Data.PreferredType.isNull()) PreferredTypeIsPointer = Data.PreferredType->isAnyPointerType() - || Data.PreferredType->isMemberPointerType() + || Data.PreferredType->isMemberPointerType() || Data.PreferredType->isBlockPointerType(); - - if (S->getFnParent() && - !Data.ObjCCollection && + + if (S->getFnParent() && + !Data.ObjCCollection && !Data.IntegralConstantExpression) AddPrettyFunctionResults(getLangOpts(), Results); @@ -3763,14 +3763,14 @@ static ObjCContainerDecl *getContainerDef(ObjCContainerDecl *Container) { if (ObjCInterfaceDecl *Interface = dyn_cast(Container)) { if (Interface->hasDefinition()) return Interface->getDefinition(); - + return Interface; } - + if (ObjCProtocolDecl *Protocol = dyn_cast(Container)) { if (Protocol->hasDefinition()) return Protocol->getDefinition(); - + return Protocol; } return Container; @@ -3823,7 +3823,7 @@ static void AddObjCProperties( // Retrieve the definition. Container = getContainerDef(Container); - + // Add properties in this container. const auto AddProperty = [&](const ObjCPropertyDecl *P) { if (!AddedProperties.insert(P->getIdentifier()).second) @@ -3942,7 +3942,7 @@ static void AddObjCProperties( } } } - + // Add properties in referenced protocols. if (ObjCProtocolDecl *Protocol = dyn_cast(Container)) { for (auto *P : Protocol->protocols()) @@ -4190,23 +4190,23 @@ void Sema::CodeCompleteTag(Scope *S, unsigned TagSpec) { Filter = &ResultBuilder::IsEnum; ContextKind = CodeCompletionContext::CCC_EnumTag; break; - + case DeclSpec::TST_union: Filter = &ResultBuilder::IsUnion; ContextKind = CodeCompletionContext::CCC_UnionTag; break; - + case DeclSpec::TST_struct: case DeclSpec::TST_class: case DeclSpec::TST_interface: Filter = &ResultBuilder::IsClassOrStruct; ContextKind = CodeCompletionContext::CCC_ClassOrStructTag; break; - + default: llvm_unreachable("Unknown type specifier kind in CodeCompleteTag"); } - + ResultBuilder Results(*this, CodeCompleter->getAllocator(), CodeCompleter->getCodeCompletionTUInfo(), ContextKind); CodeCompletionDeclConsumer Consumer(Results, CurContext); @@ -4224,7 +4224,7 @@ void Sema::CodeCompleteTag(Scope *S, unsigned TagSpec) { CodeCompleter->includeGlobals(), CodeCompleter->loadExternal()); } - + HandleCodeCompleteResults(this, CodeCompleter, Results.getCompletionContext(), Results.data(),Results.size()); } @@ -4250,7 +4250,7 @@ void Sema::CodeCompleteTypeQualifiers(DeclSpec &DS) { Results.EnterNewScope(); AddTypeQualifierResults(DS, Results, LangOpts); Results.ExitScope(); - HandleCodeCompleteResults(this, CodeCompleter, + HandleCodeCompleteResults(this, CodeCompleter, Results.getCompletionContext(), Results.data(), Results.size()); } @@ -4293,20 +4293,20 @@ void Sema::CodeCompleteCase(Scope *S) { CodeCompleteExpression(S, Data); return; } - + // Code-complete the cases of a switch statement over an enumeration type - // by providing the list of + // by providing the list of EnumDecl *Enum = type->castAs()->getDecl(); if (EnumDecl *Def = Enum->getDefinition()) Enum = Def; - + // Determine which enumerators we have already seen in the switch statement. // FIXME: Ideally, we would also be able to look *past* the code-completion // token, in case we are code-completing in the middle of the switch and not // at the end. However, we aren't able to do so at the moment. llvm::SmallPtrSet EnumeratorsSeen; NestedNameSpecifier *Qualifier = nullptr; - for (SwitchCase *SC = Switch->getSwitchCaseList(); SC; + for (SwitchCase *SC = Switch->getSwitchCaseList(); SC; SC = SC->getNextSwitchCase()) { CaseStmt *Case = dyn_cast(SC); if (!Case) @@ -4314,16 +4314,16 @@ void Sema::CodeCompleteCase(Scope *S) { Expr *CaseVal = Case->getLHS()->IgnoreParenCasts(); if (DeclRefExpr *DRE = dyn_cast(CaseVal)) - if (EnumConstantDecl *Enumerator + if (EnumConstantDecl *Enumerator = dyn_cast(DRE->getDecl())) { - // We look into the AST of the case statement to determine which - // enumerator was named. Alternatively, we could compute the value of + // We look into the AST of the case statement to determine which + // enumerator was named. Alternatively, we could compute the value of // the integral constant expression, then compare it against the - // values of each enumerator. However, value-based approach would not - // work as well with C++ templates where enumerators declared within a + // values of each enumerator. However, value-based approach would not + // work as well with C++ templates where enumerators declared within a // template are type- and value-dependent. EnumeratorsSeen.insert(Enumerator); - + // If this is a qualified-id, keep track of the nested-name-specifier // so that we can reproduce it as part of code completion, e.g., // @@ -4338,14 +4338,14 @@ void Sema::CodeCompleteCase(Scope *S) { Qualifier = DRE->getQualifier(); } } - + if (getLangOpts().CPlusPlus && !Qualifier && EnumeratorsSeen.empty()) { - // If there are no prior enumerators in C++, check whether we have to + // If there are no prior enumerators in C++, check whether we have to // qualify the names of the enumerators that we suggest, because they // may not be visible in this scope. Qualifier = getRequiredQualification(Context, CurContext, Enum); } - + // Add any enumerators that have not yet been mentioned. ResultBuilder Results(*this, CodeCompleter->getAllocator(), CodeCompleter->getCodeCompletionTUInfo(), @@ -4354,7 +4354,7 @@ void Sema::CodeCompleteCase(Scope *S) { for (auto *E : Enum->enumerators()) { if (EnumeratorsSeen.count(E)) continue; - + CodeCompletionResult R(E, CCP_EnumInCase, Qualifier); Results.AddResult(R, CurContext, nullptr, false); } @@ -4596,7 +4596,7 @@ void Sema::CodeCompleteInitializer(Scope *S, Decl *D) { CodeCompleteOrdinaryName(S, PCC_Expression); return; } - + CodeCompleteExpression(S, VD->getType()); } @@ -4622,14 +4622,14 @@ void Sema::CodeCompleteAfterIf(Scope *S) { mapCodeCompletionContext(*this, PCC_Statement)); Results.setFilter(&ResultBuilder::IsOrdinaryName); Results.EnterNewScope(); - + CodeCompletionDeclConsumer Consumer(Results, CurContext); LookupVisibleDecls(S, LookupOrdinaryName, Consumer, CodeCompleter->includeGlobals(), CodeCompleter->loadExternal()); AddOrdinaryNameResults(PCC_Statement, S, *this, Results); - + // "else" block CodeCompletionBuilder Builder(Results.getAllocator(), Results.getCodeCompletionTUInfo()); @@ -4666,13 +4666,13 @@ void Sema::CodeCompleteAfterIf(Scope *S) { Results.AddResult(Builder.TakeString()); Results.ExitScope(); - + if (S->getFnParent()) AddPrettyFunctionResults(getLangOpts(), Results); - + if (CodeCompleter->includeMacros()) AddMacroResults(PP, Results, false); - + HandleCodeCompleteResults(this, CodeCompleter, Results.getCompletionContext(), Results.data(),Results.size()); } @@ -4749,18 +4749,18 @@ void Sema::CodeCompleteQualifiedId(Scope *S, CXXScopeSpec &SS, void Sema::CodeCompleteUsing(Scope *S) { if (!CodeCompleter) return; - + ResultBuilder Results(*this, CodeCompleter->getAllocator(), CodeCompleter->getCodeCompletionTUInfo(), CodeCompletionContext::CCC_PotentiallyQualifiedName, &ResultBuilder::IsNestedNameSpecifier); Results.EnterNewScope(); - + // If we aren't in class scope, we could see the "namespace" keyword. if (!S->isClassScope()) Results.AddResult(CodeCompletionResult("namespace")); - - // After "using", we can see anything that would start a + + // After "using", we can see anything that would start a // nested-name-specifier. CodeCompletionDeclConsumer Consumer(Results, CurContext); LookupVisibleDecls(S, LookupOrdinaryName, Consumer, @@ -4775,7 +4775,7 @@ void Sema::CodeCompleteUsing(Scope *S) { void Sema::CodeCompleteUsingDirective(Scope *S) { if (!CodeCompleter) return; - + // After "using namespace", we expect to see a namespace name or namespace // alias. ResultBuilder Results(*this, CodeCompleter->getAllocator(), @@ -4795,36 +4795,36 @@ void Sema::CodeCompleteUsingDirective(Scope *S) { void Sema::CodeCompleteNamespaceDecl(Scope *S) { if (!CodeCompleter) return; - + DeclContext *Ctx = S->getEntity(); if (!S->getParent()) Ctx = Context.getTranslationUnitDecl(); - + bool SuppressedGlobalResults = Ctx && !CodeCompleter->includeGlobals() && isa(Ctx); - + ResultBuilder Results(*this, CodeCompleter->getAllocator(), CodeCompleter->getCodeCompletionTUInfo(), SuppressedGlobalResults ? CodeCompletionContext::CCC_Namespace : CodeCompletionContext::CCC_Other, &ResultBuilder::IsNamespace); - + if (Ctx && Ctx->isFileContext() && !SuppressedGlobalResults) { // We only want to see those namespaces that have already been defined // within this scope, because its likely that the user is creating an - // extended namespace declaration. Keep track of the most recent + // extended namespace declaration. Keep track of the most recent // definition of each namespace. std::map OrigToLatest; - for (DeclContext::specific_decl_iterator + for (DeclContext::specific_decl_iterator NS(Ctx->decls_begin()), NSEnd(Ctx->decls_end()); NS != NSEnd; ++NS) OrigToLatest[NS->getOriginalNamespace()] = *NS; - - // Add the most recent definition (or extended definition) of each + + // Add the most recent definition (or extended definition) of each // namespace to the list of results. Results.EnterNewScope(); - for (std::map::iterator + for (std::map::iterator NS = OrigToLatest.begin(), NSEnd = OrigToLatest.end(); NS != NSEnd; ++NS) @@ -4834,8 +4834,8 @@ void Sema::CodeCompleteNamespaceDecl(Scope *S) { CurContext, nullptr, false); Results.ExitScope(); } - - HandleCodeCompleteResults(this, CodeCompleter, + + HandleCodeCompleteResults(this, CodeCompleter, Results.getCompletionContext(), Results.data(),Results.size()); } @@ -4843,7 +4843,7 @@ void Sema::CodeCompleteNamespaceDecl(Scope *S) { void Sema::CodeCompleteNamespaceAliasDecl(Scope *S) { if (!CodeCompleter) return; - + // After "namespace", we expect to see a namespace or alias. ResultBuilder Results(*this, CodeCompleter->getAllocator(), CodeCompleter->getCodeCompletionTUInfo(), @@ -4853,7 +4853,7 @@ void Sema::CodeCompleteNamespaceAliasDecl(Scope *S) { LookupVisibleDecls(S, LookupOrdinaryName, Consumer, CodeCompleter->includeGlobals(), CodeCompleter->loadExternal()); - HandleCodeCompleteResults(this, CodeCompleter, + HandleCodeCompleteResults(this, CodeCompleter, Results.getCompletionContext(), Results.data(),Results.size()); } @@ -4868,13 +4868,13 @@ void Sema::CodeCompleteOperatorName(Scope *S) { CodeCompletionContext::CCC_Type, &ResultBuilder::IsType); Results.EnterNewScope(); - + // Add the names of overloadable operators. #define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \ if (std::strcmp(Spelling, "?")) \ Results.AddResult(Result(Spelling)); #include "clang/Basic/OperatorKinds.def" - + // Add any type names visible from the current scope Results.allowNestedNameSpecifiers(); CodeCompletionDeclConsumer Consumer(Results, CurContext); @@ -4901,12 +4901,12 @@ void Sema::CodeCompleteConstructorInitializer( CXXConstructorDecl *Constructor = dyn_cast(ConstructorD); if (!Constructor) return; - + ResultBuilder Results(*this, CodeCompleter->getAllocator(), CodeCompleter->getCodeCompletionTUInfo(), CodeCompletionContext::CCC_PotentiallyQualifiedName); Results.EnterNewScope(); - + // Fill in any already-initialized fields or base classes. llvm::SmallPtrSet InitializedFields; llvm::SmallPtrSet InitializedBases; @@ -4918,7 +4918,7 @@ void Sema::CodeCompleteConstructorInitializer( InitializedFields.insert(cast( Initializers[I]->getAnyMember())); } - + // Add completions for base classes. CodeCompletionBuilder Builder(Results.getAllocator(), Results.getCodeCompletionTUInfo()); @@ -4929,69 +4929,69 @@ void Sema::CodeCompleteConstructorInitializer( if (!InitializedBases.insert(Context.getCanonicalType(Base.getType())) .second) { SawLastInitializer - = !Initializers.empty() && + = !Initializers.empty() && Initializers.back()->isBaseInitializer() && Context.hasSameUnqualifiedType(Base.getType(), QualType(Initializers.back()->getBaseClass(), 0)); continue; } - + Builder.AddTypedTextChunk( Results.getAllocator().CopyString( Base.getType().getAsString(Policy))); Builder.AddChunk(CodeCompletionString::CK_LeftParen); Builder.AddPlaceholderChunk("args"); Builder.AddChunk(CodeCompletionString::CK_RightParen); - Results.AddResult(CodeCompletionResult(Builder.TakeString(), + Results.AddResult(CodeCompletionResult(Builder.TakeString(), SawLastInitializer? CCP_NextInitializer : CCP_MemberDeclaration)); SawLastInitializer = false; } - + // Add completions for virtual base classes. for (const auto &Base : ClassDecl->vbases()) { if (!InitializedBases.insert(Context.getCanonicalType(Base.getType())) .second) { SawLastInitializer - = !Initializers.empty() && + = !Initializers.empty() && Initializers.back()->isBaseInitializer() && Context.hasSameUnqualifiedType(Base.getType(), QualType(Initializers.back()->getBaseClass(), 0)); continue; } - + Builder.AddTypedTextChunk( Builder.getAllocator().CopyString( Base.getType().getAsString(Policy))); Builder.AddChunk(CodeCompletionString::CK_LeftParen); Builder.AddPlaceholderChunk("args"); Builder.AddChunk(CodeCompletionString::CK_RightParen); - Results.AddResult(CodeCompletionResult(Builder.TakeString(), + Results.AddResult(CodeCompletionResult(Builder.TakeString(), SawLastInitializer? CCP_NextInitializer : CCP_MemberDeclaration)); SawLastInitializer = false; } - + // Add completions for members. for (auto *Field : ClassDecl->fields()) { if (!InitializedFields.insert(cast(Field->getCanonicalDecl())) .second) { SawLastInitializer - = !Initializers.empty() && + = !Initializers.empty() && Initializers.back()->isAnyMemberInitializer() && Initializers.back()->getAnyMember() == Field; continue; } - + if (!Field->getDeclName()) continue; - + Builder.AddTypedTextChunk(Builder.getAllocator().CopyString( Field->getIdentifier()->getName())); Builder.AddChunk(CodeCompletionString::CK_LeftParen); Builder.AddPlaceholderChunk("args"); Builder.AddChunk(CodeCompletionString::CK_RightParen); - Results.AddResult(CodeCompletionResult(Builder.TakeString(), + Results.AddResult(CodeCompletionResult(Builder.TakeString(), SawLastInitializer? CCP_NextInitializer : CCP_MemberDeclaration, CXCursor_MemberRef, @@ -5000,7 +5000,7 @@ void Sema::CodeCompleteConstructorInitializer( SawLastInitializer = false; } Results.ExitScope(); - + HandleCodeCompleteResults(this, CodeCompleter, Results.getCompletionContext(), Results.data(), Results.size()); } @@ -5029,10 +5029,10 @@ void Sema::CodeCompleteLambdaIntroducer(Scope *S, LambdaIntroducer &Intro, IncludedThis = true; continue; } - + Known.insert(C.Id); } - + // Look for other capturable variables. for (; S && !isNamespaceScope(S); S = S->getParent()) { for (const auto *D : S->decls()) { @@ -5041,7 +5041,7 @@ void Sema::CodeCompleteLambdaIntroducer(Scope *S, LambdaIntroducer &Intro, !Var->hasLocalStorage() || Var->hasAttr()) continue; - + if (Known.insert(Var->getIdentifier()).second) Results.AddResult(CodeCompletionResult(Var, CCP_LocalDeclaration), CurContext, nullptr, false); @@ -5051,9 +5051,9 @@ void Sema::CodeCompleteLambdaIntroducer(Scope *S, LambdaIntroducer &Intro, // Add 'this', if it would be valid. if (!IncludedThis && !AfterAmpersand && Intro.Default != LCD_ByCopy) addThisCompletion(*this, Results); - + Results.ExitScope(); - + HandleCodeCompleteResults(this, CodeCompleter, Results.getCompletionContext(), Results.data(), Results.size()); } @@ -5068,7 +5068,7 @@ static void AddObjCImplementationResults(const LangOptions &LangOpts, typedef CodeCompletionResult Result; // Since we have an implementation, we can end it. Results.AddResult(Result(OBJC_AT_KEYWORD_NAME(NeedAt,"end"))); - + CodeCompletionBuilder Builder(Results.getAllocator(), Results.getCodeCompletionTUInfo()); if (LangOpts.ObjC2) { @@ -5077,30 +5077,30 @@ static void AddObjCImplementationResults(const LangOptions &LangOpts, Builder.AddChunk(CodeCompletionString::CK_HorizontalSpace); Builder.AddPlaceholderChunk("property"); Results.AddResult(Result(Builder.TakeString())); - + // @synthesize Builder.AddTypedTextChunk(OBJC_AT_KEYWORD_NAME(NeedAt,"synthesize")); Builder.AddChunk(CodeCompletionString::CK_HorizontalSpace); Builder.AddPlaceholderChunk("property"); Results.AddResult(Result(Builder.TakeString())); - } + } } static void AddObjCInterfaceResults(const LangOptions &LangOpts, ResultBuilder &Results, bool NeedAt) { typedef CodeCompletionResult Result; - + // Since we have an interface or protocol, we can end it. Results.AddResult(Result(OBJC_AT_KEYWORD_NAME(NeedAt,"end"))); - + if (LangOpts.ObjC2) { // @property Results.AddResult(Result(OBJC_AT_KEYWORD_NAME(NeedAt,"property"))); - + // @required Results.AddResult(Result(OBJC_AT_KEYWORD_NAME(NeedAt,"required"))); - + // @optional Results.AddResult(Result(OBJC_AT_KEYWORD_NAME(NeedAt,"optional"))); } @@ -5110,35 +5110,35 @@ static void AddObjCTopLevelResults(ResultBuilder &Results, bool NeedAt) { typedef CodeCompletionResult Result; CodeCompletionBuilder Builder(Results.getAllocator(), Results.getCodeCompletionTUInfo()); - + // @class name ; Builder.AddTypedTextChunk(OBJC_AT_KEYWORD_NAME(NeedAt,"class")); Builder.AddChunk(CodeCompletionString::CK_HorizontalSpace); Builder.AddPlaceholderChunk("name"); Results.AddResult(Result(Builder.TakeString())); - + if (Results.includeCodePatterns()) { - // @interface name - // FIXME: Could introduce the whole pattern, including superclasses and + // @interface name + // FIXME: Could introduce the whole pattern, including superclasses and // such. Builder.AddTypedTextChunk(OBJC_AT_KEYWORD_NAME(NeedAt,"interface")); Builder.AddChunk(CodeCompletionString::CK_HorizontalSpace); Builder.AddPlaceholderChunk("class"); Results.AddResult(Result(Builder.TakeString())); - + // @protocol name Builder.AddTypedTextChunk(OBJC_AT_KEYWORD_NAME(NeedAt,"protocol")); Builder.AddChunk(CodeCompletionString::CK_HorizontalSpace); Builder.AddPlaceholderChunk("protocol"); Results.AddResult(Result(Builder.TakeString())); - + // @implementation name Builder.AddTypedTextChunk(OBJC_AT_KEYWORD_NAME(NeedAt,"implementation")); Builder.AddChunk(CodeCompletionString::CK_HorizontalSpace); Builder.AddPlaceholderChunk("class"); Results.AddResult(Result(Builder.TakeString())); } - + // @compatibility_alias name Builder.AddTypedTextChunk(OBJC_AT_KEYWORD_NAME(NeedAt,"compatibility_alias")); Builder.AddChunk(CodeCompletionString::CK_HorizontalSpace); @@ -5188,7 +5188,7 @@ static void AddObjCExpressionResults(ResultBuilder &Results, bool NeedAt) { Builder.AddPlaceholderChunk("type-name"); Builder.AddChunk(CodeCompletionString::CK_RightParen); Results.AddResult(Result(Builder.TakeString())); - + // @protocol ( protocol-name ) Builder.AddResultTypeChunk("Protocol *"); Builder.AddTypedTextChunk(OBJC_AT_KEYWORD_NAME(NeedAt,"protocol")); @@ -5241,7 +5241,7 @@ static void AddObjCStatementResults(ResultBuilder &Results, bool NeedAt) { typedef CodeCompletionResult Result; CodeCompletionBuilder Builder(Results.getAllocator(), Results.getCodeCompletionTUInfo()); - + if (Results.includeCodePatterns()) { // @try { statements } @catch ( declaration ) { statements } @finally // { statements } @@ -5262,13 +5262,13 @@ static void AddObjCStatementResults(ResultBuilder &Results, bool NeedAt) { Builder.AddChunk(CodeCompletionString::CK_RightBrace); Results.AddResult(Result(Builder.TakeString())); } - + // @throw Builder.AddTypedTextChunk(OBJC_AT_KEYWORD_NAME(NeedAt,"throw")); Builder.AddChunk(CodeCompletionString::CK_HorizontalSpace); Builder.AddPlaceholderChunk("expression"); Results.AddResult(Result(Builder.TakeString())); - + if (Results.includeCodePatterns()) { // @synchronized ( expression ) { statements } Builder.AddTypedTextChunk(OBJC_AT_KEYWORD_NAME(NeedAt,"synchronized")); @@ -5334,14 +5334,14 @@ static bool ObjCPropertyFlagConflicts(unsigned Attributes, unsigned NewFlag) { // Check if we've already added this flag. if (Attributes & NewFlag) return true; - + Attributes |= NewFlag; - + // Check for collisions with "readonly". if ((Attributes & ObjCDeclSpec::DQ_PR_readonly) && (Attributes & ObjCDeclSpec::DQ_PR_readwrite)) return true; - + // Check for more than one of { assign, copy, retain, strong, weak }. unsigned AssignCopyRetMask = Attributes & (ObjCDeclSpec::DQ_PR_assign | ObjCDeclSpec::DQ_PR_unsafe_unretained | @@ -5357,16 +5357,16 @@ static bool ObjCPropertyFlagConflicts(unsigned Attributes, unsigned NewFlag) { AssignCopyRetMask != ObjCDeclSpec::DQ_PR_strong && AssignCopyRetMask != ObjCDeclSpec::DQ_PR_weak) return true; - + return false; } -void Sema::CodeCompleteObjCPropertyFlags(Scope *S, ObjCDeclSpec &ODS) { +void Sema::CodeCompleteObjCPropertyFlags(Scope *S, ObjCDeclSpec &ODS) { if (!CodeCompleter) return; - + unsigned Attributes = ODS.getPropertyAttributes(); - + ResultBuilder Results(*this, CodeCompleter->getAllocator(), CodeCompleter->getCodeCompletionTUInfo(), CodeCompletionContext::CCC_Other); @@ -5438,20 +5438,20 @@ static bool isAcceptableObjCSelector(Selector Sel, unsigned NumSelIdents = SelIdents.size(); if (NumSelIdents > Sel.getNumArgs()) return false; - + switch (WantKind) { case MK_Any: break; case MK_ZeroArgSelector: return Sel.isUnarySelector(); case MK_OneArgSelector: return Sel.getNumArgs() == 1; } - + if (!AllowSameLength && NumSelIdents && NumSelIdents == Sel.getNumArgs()) return false; - + for (unsigned I = 0; I != NumSelIdents; ++I) if (SelIdents[I] != Sel.getIdentifierInfoForSlot(I)) return false; - + return true; } @@ -5464,16 +5464,16 @@ static bool isAcceptableObjCMethod(ObjCMethodDecl *Method, } namespace { - /// A set of selectors, which is used to avoid introducing multiple + /// A set of selectors, which is used to avoid introducing multiple /// completions with the same selector into the result set. typedef llvm::SmallPtrSet VisitedSelectorSet; } -/// Add all of the Objective-C methods in the given Objective-C +/// Add all of the Objective-C methods in the given Objective-C /// container to the set of results. /// -/// The container will be a class, protocol, category, or implementation of -/// any of the above. This mether will recurse to include methods from +/// The container will be a class, protocol, category, or implementation of +/// any of the above. This mether will recurse to include methods from /// the superclasses of classes along with their categories, protocols, and /// implementations. /// @@ -5505,7 +5505,7 @@ static void AddObjCMethods(ObjCContainerDecl *Container, // metaclass. if (M->isInstanceMethod() == WantInstanceMethods || (IsRootClass && !WantInstanceMethods)) { - // Check whether the selector identifiers we've been given are a + // Check whether the selector identifiers we've been given are a // subset of the identifiers for this particular method. if (!isAcceptableObjCMethod(M, WantKind, SelIdents, AllowSameLength)) continue; @@ -5521,23 +5521,23 @@ static void AddObjCMethods(ObjCContainerDecl *Container, Results.MaybeAddResult(R, CurContext); } } - + // Visit the protocols of protocols. if (ObjCProtocolDecl *Protocol = dyn_cast(Container)) { if (Protocol->hasDefinition()) { const ObjCList &Protocols = Protocol->getReferencedProtocols(); for (ObjCList::iterator I = Protocols.begin(), - E = Protocols.end(); + E = Protocols.end(); I != E; ++I) AddObjCMethods(*I, WantInstanceMethods, WantKind, SelIdents, CurContext, Selectors, AllowSameLength, Results, false, IsRootClass); } } - + if (!IFace || !IFace->hasDefinition()) return; - + // Add methods in protocols. for (auto *I : IFace->protocols()) AddObjCMethods(I, WantInstanceMethods, WantKind, SelIdents, CurContext, @@ -5550,7 +5550,7 @@ static void AddObjCMethods(ObjCContainerDecl *Container, InOriginalClass, IsRootClass); // Add a categories protocol methods. - const ObjCList &Protocols + const ObjCList &Protocols = CatDecl->getReferencedProtocols(); for (ObjCList::iterator I = Protocols.begin(), E = Protocols.end(); @@ -5564,7 +5564,7 @@ static void AddObjCMethods(ObjCContainerDecl *Container, Selectors, AllowSameLength, Results, InOriginalClass, IsRootClass); } - + // Add methods in superclass. // Avoid passing in IsRootClass since root classes won't have super classes. if (IFace->getSuperClass()) @@ -5640,22 +5640,22 @@ void Sema::CodeCompleteObjCPassingType(Scope *S, ObjCDeclSpec &DS, CodeCompleter->getCodeCompletionTUInfo(), CodeCompletionContext::CCC_Type); Results.EnterNewScope(); - + // Add context-sensitive, Objective-C parameter-passing keywords. bool AddedInOut = false; - if ((DS.getObjCDeclQualifier() & + if ((DS.getObjCDeclQualifier() & (ObjCDeclSpec::DQ_In | ObjCDeclSpec::DQ_Inout)) == 0) { Results.AddResult("in"); Results.AddResult("inout"); AddedInOut = true; } - if ((DS.getObjCDeclQualifier() & + if ((DS.getObjCDeclQualifier() & (ObjCDeclSpec::DQ_Out | ObjCDeclSpec::DQ_Inout)) == 0) { Results.AddResult("out"); if (!AddedInOut) Results.AddResult("inout"); } - if ((DS.getObjCDeclQualifier() & + if ((DS.getObjCDeclQualifier() & (ObjCDeclSpec::DQ_Bycopy | ObjCDeclSpec::DQ_Byref | ObjCDeclSpec::DQ_Oneway)) == 0) { Results.AddResult("bycopy"); @@ -5667,8 +5667,8 @@ void Sema::CodeCompleteObjCPassingType(Scope *S, ObjCDeclSpec &DS, Results.AddResult("nullable"); Results.AddResult("null_unspecified"); } - - // If we're completing the return type of an Objective-C method and the + + // If we're completing the return type of an Objective-C method and the // identifier IBAction refers to a macro, provide a completion item for // an action, e.g., // IBAction)<#selector#>:(id)sender @@ -5692,11 +5692,11 @@ void Sema::CodeCompleteObjCPassingType(Scope *S, ObjCDeclSpec &DS, if (!IsParameter) { Results.AddResult(CodeCompletionResult("instancetype")); } - + // Add various builtin type names and specifiers. AddOrdinaryNameResults(PCC_Type, S, *this, Results); Results.ExitScope(); - + // Add the various type names Results.setFilter(&ResultBuilder::IsOrdinaryNonValueName); CodeCompletionDeclConsumer Consumer(Results, CurContext); @@ -5783,7 +5783,7 @@ static ObjCInterfaceDecl *GetAssumedMessageSendExprType(Expr *E) { } // Add a special completion for a message send to "super", which fills in the -// most likely case of forwarding all of our arguments to the superclass +// most likely case of forwarding all of our arguments to the superclass // function. /// /// \param S The semantic analysis object. @@ -5796,7 +5796,7 @@ static ObjCInterfaceDecl *GetAssumedMessageSendExprType(Expr *E) { /// /// \param Results The set of results to augment. /// -/// \returns the Objective-C method declaration that would be invoked by +/// \returns the Objective-C method declaration that would be invoked by /// this "super" completion. If NULL, no completion was added. static ObjCMethodDecl *AddSuperSendCompletion( Sema &S, bool NeedSuperKeyword, @@ -5814,7 +5814,7 @@ static ObjCMethodDecl *AddSuperSendCompletion( ObjCMethodDecl *SuperMethod = nullptr; while ((Class = Class->getSuperClass()) && !SuperMethod) { // Check in the class - SuperMethod = Class->getMethod(CurMethod->getSelector(), + SuperMethod = Class->getMethod(CurMethod->getSelector(), CurMethod->isInstanceMethod()); // Check in categories or class extensions. @@ -5840,7 +5840,7 @@ static ObjCMethodDecl *AddSuperSendCompletion( SuperP = SuperMethod->param_begin(); CurP != CurPEnd; ++CurP, ++SuperP) { // Make sure the parameter types are compatible. - if (!S.Context.hasSameUnqualifiedType((*CurP)->getType(), + if (!S.Context.hasSameUnqualifiedType((*CurP)->getType(), (*SuperP)->getType())) return nullptr; @@ -5848,11 +5848,11 @@ static ObjCMethodDecl *AddSuperSendCompletion( if (!(*CurP)->getIdentifier()) return nullptr; } - + // We have a superclass method. Now, form the send-to-super completion. CodeCompletionBuilder Builder(Results.getAllocator(), Results.getCodeCompletionTUInfo()); - + // Give this completion a return type. AddResultTypeChunk(S.Context, getCompletionPrintingPolicy(S), SuperMethod, Results.getCompletionContext().getBaseType(), @@ -5863,7 +5863,7 @@ static ObjCMethodDecl *AddSuperSendCompletion( Builder.AddTypedTextChunk("super"); Builder.AddChunk(CodeCompletionString::CK_HorizontalSpace); } - + Selector Sel = CurMethod->getSelector(); if (Sel.isUnarySelector()) { if (NeedSuperKeyword) @@ -5877,7 +5877,7 @@ static ObjCMethodDecl *AddSuperSendCompletion( for (unsigned I = 0, N = Sel.getNumArgs(); I != N; ++I, ++CurP) { if (I > SelIdents.size()) Builder.AddChunk(CodeCompletionString::CK_HorizontalSpace); - + if (I < SelIdents.size()) Builder.AddInformativeChunk( Builder.getAllocator().CopyString( @@ -5893,16 +5893,16 @@ static ObjCMethodDecl *AddSuperSendCompletion( Builder.getAllocator().CopyString( Sel.getNameForSlot(I) + ":")); Builder.AddPlaceholderChunk(Builder.getAllocator().CopyString( - (*CurP)->getIdentifier()->getName())); + (*CurP)->getIdentifier()->getName())); } } } - + Results.AddResult(CodeCompletionResult(Builder.TakeString(), SuperMethod, CCP_SuperCompletion)); return SuperMethod; } - + void Sema::CodeCompleteObjCMessageReceiver(Scope *S) { typedef CodeCompletionResult Result; ResultBuilder Results(*this, CodeCompleter->getAllocator(), @@ -5911,7 +5911,7 @@ void Sema::CodeCompleteObjCMessageReceiver(Scope *S) { getLangOpts().CPlusPlus11 ? &ResultBuilder::IsObjCMessageReceiverOrLambdaCapture : &ResultBuilder::IsObjCMessageReceiver); - + CodeCompletionDeclConsumer Consumer(Results, CurContext); Results.EnterNewScope(); LookupVisibleDecls(S, LookupOrdinaryName, Consumer, @@ -5924,20 +5924,20 @@ void Sema::CodeCompleteObjCMessageReceiver(Scope *S) { if (ObjCInterfaceDecl *Iface = Method->getClassInterface()) if (Iface->getSuperClass()) { Results.AddResult(Result("super")); - + AddSuperSendCompletion(*this, /*NeedSuperKeyword=*/true, None, Results); } - + if (getLangOpts().CPlusPlus11) addThisCompletion(*this, Results); - + Results.ExitScope(); - + if (CodeCompleter->includeMacros()) AddMacroResults(PP, Results, false); HandleCodeCompleteResults(this, CodeCompleter, Results.getCompletionContext(), Results.data(), Results.size()); - + } void Sema::CodeCompleteObjCSuperMessage(Scope *S, SourceLocation SuperLoc, @@ -5949,7 +5949,7 @@ void Sema::CodeCompleteObjCSuperMessage(Scope *S, SourceLocation SuperLoc, CDecl = CurMethod->getClassInterface(); if (!CDecl) return; - + // Find the superclass of this class. CDecl = CDecl->getSuperClass(); if (!CDecl) @@ -5969,7 +5969,7 @@ void Sema::CodeCompleteObjCSuperMessage(Scope *S, SourceLocation SuperLoc, // "super" may be the name of a type or variable. Figure out which // it is. IdentifierInfo *Super = getSuperIdentifier(); - NamedDecl *ND = LookupSingleName(S, Super, SuperLoc, + NamedDecl *ND = LookupSingleName(S, Super, SuperLoc, LookupOrdinaryName); if ((CDecl = dyn_cast_or_null(ND))) { // "super" names an interface. Use it. @@ -5998,7 +5998,7 @@ void Sema::CodeCompleteObjCSuperMessage(Scope *S, SourceLocation SuperLoc, ParsedType Receiver; if (CDecl) Receiver = ParsedType::make(Context.getObjCInterfaceType(CDecl)); - return CodeCompleteObjCClassMessage(S, Receiver, SelIdents, + return CodeCompleteObjCClassMessage(S, Receiver, SelIdents, AtArgumentExpression, /*IsSuper=*/true); } @@ -6007,15 +6007,15 @@ void Sema::CodeCompleteObjCSuperMessage(Scope *S, SourceLocation SuperLoc, /// send, determine the preferred type (if any) for that argument expression. static QualType getPreferredArgumentTypeForMessageSend(ResultBuilder &Results, unsigned NumSelIdents) { - typedef CodeCompletionResult Result; + typedef CodeCompletionResult Result; ASTContext &Context = Results.getSema().Context; - + QualType PreferredType; unsigned BestPriority = CCP_Unlikely * 2; Result *ResultsData = Results.data(); for (unsigned I = 0, N = Results.size(); I != N; ++I) { Result &R = ResultsData[I]; - if (R.Kind == Result::RK_Declaration && + if (R.Kind == Result::RK_Declaration && isa(R.Declaration)) { if (R.Priority <= BestPriority) { const ObjCMethodDecl *Method = cast(R.Declaration); @@ -6037,7 +6037,7 @@ static QualType getPreferredArgumentTypeForMessageSend(ResultBuilder &Results, return PreferredType; } -static void AddClassMessageCompletions(Sema &SemaRef, Scope *S, +static void AddClassMessageCompletions(Sema &SemaRef, Scope *S, ParsedType Receiver, ArrayRef SelIdents, bool AtArgumentExpression, @@ -6050,55 +6050,55 @@ static void AddClassMessageCompletions(Sema &SemaRef, Scope *S, // corresponding declaration. if (Receiver) { QualType T = SemaRef.GetTypeFromParser(Receiver, nullptr); - if (!T.isNull()) + if (!T.isNull()) if (const ObjCObjectType *Interface = T->getAs()) CDecl = Interface->getInterface(); } - + // Add all of the factory methods in this Objective-C class, its protocols, // superclasses, categories, implementation, etc. Results.EnterNewScope(); - - // If this is a send-to-super, try to add the special "super" send + + // If this is a send-to-super, try to add the special "super" send // completion. if (IsSuper) { if (ObjCMethodDecl *SuperMethod = AddSuperSendCompletion(SemaRef, false, SelIdents, Results)) Results.Ignore(SuperMethod); } - + // If we're inside an Objective-C method definition, prefer its selector to // others. if (ObjCMethodDecl *CurMethod = SemaRef.getCurMethodDecl()) Results.setPreferredSelector(CurMethod->getSelector()); - + VisitedSelectorSet Selectors; - if (CDecl) + if (CDecl) AddObjCMethods(CDecl, false, MK_Any, SelIdents, SemaRef.CurContext, Selectors, AtArgumentExpression, - Results); + Results); else { // We're messaging "id" as a type; provide all class/factory methods. - + // If we have an external source, load the entire class method // pool from the AST file. if (SemaRef.getExternalSource()) { - for (uint32_t I = 0, + for (uint32_t I = 0, N = SemaRef.getExternalSource()->GetNumExternalSelectors(); I != N; ++I) { Selector Sel = SemaRef.getExternalSource()->GetExternalSelector(I); if (Sel.isNull() || SemaRef.MethodPool.count(Sel)) continue; - + SemaRef.ReadMethodPool(Sel); } } - + for (Sema::GlobalMethodPool::iterator M = SemaRef.MethodPool.begin(), MEnd = SemaRef.MethodPool.end(); M != MEnd; ++M) { for (ObjCMethodList *MethList = &M->second.second; - MethList && MethList->getMethod(); + MethList && MethList->getMethod(); MethList = MethList->getNext()) { if (!isAcceptableObjCMethod(MethList->getMethod(), MK_Any, SelIdents)) continue; @@ -6111,32 +6111,32 @@ static void AddClassMessageCompletions(Sema &SemaRef, Scope *S, } } } - - Results.ExitScope(); + + Results.ExitScope(); } void Sema::CodeCompleteObjCClassMessage(Scope *S, ParsedType Receiver, ArrayRef SelIdents, bool AtArgumentExpression, bool IsSuper) { - + QualType T = this->GetTypeFromParser(Receiver); - + ResultBuilder Results(*this, CodeCompleter->getAllocator(), CodeCompleter->getCodeCompletionTUInfo(), CodeCompletionContext(CodeCompletionContext::CCC_ObjCClassMessage, T, SelIdents)); - + AddClassMessageCompletions(*this, S, Receiver, SelIdents, AtArgumentExpression, IsSuper, Results); - - // If we're actually at the argument expression (rather than prior to the + + // If we're actually at the argument expression (rather than prior to the // selector), we're actually performing code completion for an expression. - // Determine whether we have a single, best method. If so, we can + // Determine whether we have a single, best method. If so, we can // code-complete the expression using the corresponding parameter type as // our preferred type, improving completion results. if (AtArgumentExpression) { - QualType PreferredType = getPreferredArgumentTypeForMessageSend(Results, + QualType PreferredType = getPreferredArgumentTypeForMessageSend(Results, SelIdents.size()); if (PreferredType.isNull()) CodeCompleteOrdinaryName(S, PCC_Expression); @@ -6145,7 +6145,7 @@ void Sema::CodeCompleteObjCClassMessage(Scope *S, ParsedType Receiver, return; } - HandleCodeCompleteResults(this, CodeCompleter, + HandleCodeCompleteResults(this, CodeCompleter, Results.getCompletionContext(), Results.data(), Results.size()); } @@ -6155,9 +6155,9 @@ void Sema::CodeCompleteObjCInstanceMessage(Scope *S, Expr *Receiver, bool AtArgumentExpression, ObjCInterfaceDecl *Super) { typedef CodeCompletionResult Result; - + Expr *RecExpr = static_cast(Receiver); - + // If necessary, apply function/array conversion to the receiver. // C99 6.7.5.3p[7,8]. if (RecExpr) { @@ -6166,18 +6166,18 @@ void Sema::CodeCompleteObjCInstanceMessage(Scope *S, Expr *Receiver, return; RecExpr = Conv.get(); } - QualType ReceiverType = RecExpr? RecExpr->getType() + QualType ReceiverType = RecExpr? RecExpr->getType() : Super? Context.getObjCObjectPointerType( Context.getObjCInterfaceType(Super)) : Context.getObjCIdType(); - + // If we're messaging an expression with type "id" or "Class", check // whether we know something special about the receiver that allows // us to assume a more-specific receiver type. if (ReceiverType->isObjCIdType() || ReceiverType->isObjCClassType()) { if (ObjCInterfaceDecl *IFace = GetAssumedMessageSendExprType(RecExpr)) { if (ReceiverType->isObjCClassType()) - return CodeCompleteObjCClassMessage(S, + return CodeCompleteObjCClassMessage(S, ParsedType::make(Context.getObjCInterfaceType(IFace)), SelIdents, AtArgumentExpression, Super); @@ -6198,36 +6198,36 @@ void Sema::CodeCompleteObjCInstanceMessage(Scope *S, Expr *Receiver, CodeCompleter->getCodeCompletionTUInfo(), CodeCompletionContext(CodeCompletionContext::CCC_ObjCInstanceMessage, ReceiverType, SelIdents)); - + Results.EnterNewScope(); - // If this is a send-to-super, try to add the special "super" send + // If this is a send-to-super, try to add the special "super" send // completion. if (Super) { if (ObjCMethodDecl *SuperMethod = AddSuperSendCompletion(*this, false, SelIdents, Results)) Results.Ignore(SuperMethod); } - + // If we're inside an Objective-C method definition, prefer its selector to // others. if (ObjCMethodDecl *CurMethod = getCurMethodDecl()) Results.setPreferredSelector(CurMethod->getSelector()); - + // Keep track of the selectors we've already added. VisitedSelectorSet Selectors; - + // Handle messages to Class. This really isn't a message to an instance // method, so we treat it the same way we would treat a message send to a // class method. - if (ReceiverType->isObjCClassType() || + if (ReceiverType->isObjCClassType() || ReceiverType->isObjCQualifiedClassType()) { if (ObjCMethodDecl *CurMethod = getCurMethodDecl()) { if (ObjCInterfaceDecl *ClassDecl = CurMethod->getClassInterface()) AddObjCMethods(ClassDecl, false, MK_Any, SelIdents, CurContext, Selectors, AtArgumentExpression, Results); } - } + } // Handle messages to a qualified ID ("id"). else if (const ObjCObjectPointerType *QualID = ReceiverType->getAsObjCQualifiedIdType()) { @@ -6243,7 +6243,7 @@ void Sema::CodeCompleteObjCInstanceMessage(Scope *S, Expr *Receiver, AddObjCMethods(IFacePtr->getInterfaceDecl(), true, MK_Any, SelIdents, CurContext, Selectors, AtArgumentExpression, Results); - + // Search protocols for instance methods. for (auto *I : IFacePtr->quals()) AddObjCMethods(I, true, MK_Any, SelIdents, CurContext, @@ -6271,11 +6271,11 @@ void Sema::CodeCompleteObjCInstanceMessage(Scope *S, Expr *Receiver, MEnd = MethodPool.end(); M != MEnd; ++M) { for (ObjCMethodList *MethList = &M->second.first; - MethList && MethList->getMethod(); + MethList && MethList->getMethod(); MethList = MethList->getNext()) { if (!isAcceptableObjCMethod(MethList->getMethod(), MK_Any, SelIdents)) continue; - + if (!Selectors.insert(MethList->getMethod()->getSelector()).second) continue; @@ -6288,15 +6288,15 @@ void Sema::CodeCompleteObjCInstanceMessage(Scope *S, Expr *Receiver, } } Results.ExitScope(); - - - // If we're actually at the argument expression (rather than prior to the + + + // If we're actually at the argument expression (rather than prior to the // selector), we're actually performing code completion for an expression. - // Determine whether we have a single, best method. If so, we can + // Determine whether we have a single, best method. If so, we can // code-complete the expression using the corresponding parameter type as // our preferred type, improving completion results. if (AtArgumentExpression) { - QualType PreferredType = getPreferredArgumentTypeForMessageSend(Results, + QualType PreferredType = getPreferredArgumentTypeForMessageSend(Results, SelIdents.size()); if (PreferredType.isNull()) CodeCompleteOrdinaryName(S, PCC_Expression); @@ -6304,17 +6304,17 @@ void Sema::CodeCompleteObjCInstanceMessage(Scope *S, Expr *Receiver, CodeCompleteExpression(S, PreferredType); return; } - - HandleCodeCompleteResults(this, CodeCompleter, + + HandleCodeCompleteResults(this, CodeCompleter, Results.getCompletionContext(), Results.data(),Results.size()); } -void Sema::CodeCompleteObjCForCollection(Scope *S, +void Sema::CodeCompleteObjCForCollection(Scope *S, DeclGroupPtrTy IterationVar) { CodeCompleteExpressionData Data; Data.ObjCCollection = true; - + if (IterationVar.getAsOpaquePtr()) { DeclGroupRef DG = IterationVar.get(); for (DeclGroupRef::iterator I = DG.begin(), End = DG.end(); I != End; ++I) { @@ -6322,7 +6322,7 @@ void Sema::CodeCompleteObjCForCollection(Scope *S, Data.IgnoreDecls.push_back(*I); } } - + CodeCompleteExpression(S, Data); } @@ -6336,11 +6336,11 @@ void Sema::CodeCompleteObjCSelector(Scope *S, Selector Sel = ExternalSource->GetExternalSelector(I); if (Sel.isNull() || MethodPool.count(Sel)) continue; - + ReadMethodPool(Sel); } } - + ResultBuilder Results(*this, CodeCompleter->getAllocator(), CodeCompleter->getCodeCompletionTUInfo(), CodeCompletionContext::CCC_SelectorName); @@ -6348,7 +6348,7 @@ void Sema::CodeCompleteObjCSelector(Scope *S, for (GlobalMethodPool::iterator M = MethodPool.begin(), MEnd = MethodPool.end(); M != MEnd; ++M) { - + Selector Sel = M->first; if (!isAcceptableObjCSelector(Sel, MK_Any, SelIdents)) continue; @@ -6361,7 +6361,7 @@ void Sema::CodeCompleteObjCSelector(Scope *S, Results.AddResult(Builder.TakeString()); continue; } - + std::string Accumulator; for (unsigned I = 0, N = Sel.getNumArgs(); I != N; ++I) { if (I == SelIdents.size()) { @@ -6371,7 +6371,7 @@ void Sema::CodeCompleteObjCSelector(Scope *S, Accumulator.clear(); } } - + Accumulator += Sel.getNameForSlot(I); Accumulator += ':'; } @@ -6390,7 +6390,7 @@ static void AddProtocolResults(DeclContext *Ctx, DeclContext *CurContext, bool OnlyForwardDeclarations, ResultBuilder &Results) { typedef CodeCompletionResult Result; - + for (const auto *D : Ctx->decls()) { // Record any protocols we find. if (const auto *Proto = dyn_cast(D)) @@ -6405,10 +6405,10 @@ void Sema::CodeCompleteObjCProtocolReferences( ResultBuilder Results(*this, CodeCompleter->getAllocator(), CodeCompleter->getCodeCompletionTUInfo(), CodeCompletionContext::CCC_ObjCProtocolName); - + if (CodeCompleter->includeGlobals()) { Results.EnterNewScope(); - + // Tell the result set to ignore all of the protocols we have // already seen. // FIXME: This doesn't work when caching code-completion results. @@ -6432,10 +6432,10 @@ void Sema::CodeCompleteObjCProtocolDecl(Scope *) { ResultBuilder Results(*this, CodeCompleter->getAllocator(), CodeCompleter->getCodeCompletionTUInfo(), CodeCompletionContext::CCC_ObjCProtocolName); - + if (CodeCompleter->includeGlobals()) { Results.EnterNewScope(); - + // Add all protocols. AddProtocolResults(Context.getTranslationUnitDecl(), CurContext, true, Results); @@ -6454,7 +6454,7 @@ static void AddInterfaceResults(DeclContext *Ctx, DeclContext *CurContext, bool OnlyUnimplemented, ResultBuilder &Results) { typedef CodeCompletionResult Result; - + for (const auto *D : Ctx->decls()) { // Record any interfaces we find. if (const auto *Class = dyn_cast(D)) @@ -6476,7 +6476,7 @@ void Sema::CodeCompleteObjCInterfaceDecl(Scope *S) { AddInterfaceResults(Context.getTranslationUnitDecl(), CurContext, false, false, Results); } - + Results.ExitScope(); HandleCodeCompleteResults(this, CodeCompleter, Results.getCompletionContext(), @@ -6484,12 +6484,12 @@ void Sema::CodeCompleteObjCInterfaceDecl(Scope *S) { } void Sema::CodeCompleteObjCSuperclass(Scope *S, IdentifierInfo *ClassName, - SourceLocation ClassNameLoc) { + SourceLocation ClassNameLoc) { ResultBuilder Results(*this, CodeCompleter->getAllocator(), CodeCompleter->getCodeCompletionTUInfo(), CodeCompletionContext::CCC_ObjCInterfaceName); Results.EnterNewScope(); - + // Make sure that we ignore the class we're currently defining. NamedDecl *CurClass = LookupSingleName(TUScope, ClassName, ClassNameLoc, LookupOrdinaryName); @@ -6501,7 +6501,7 @@ void Sema::CodeCompleteObjCSuperclass(Scope *S, IdentifierInfo *ClassName, AddInterfaceResults(Context.getTranslationUnitDecl(), CurContext, false, false, Results); } - + Results.ExitScope(); HandleCodeCompleteResults(this, CodeCompleter, Results.getCompletionContext(), @@ -6519,22 +6519,22 @@ void Sema::CodeCompleteObjCImplementationDecl(Scope *S) { AddInterfaceResults(Context.getTranslationUnitDecl(), CurContext, false, true, Results); } - + Results.ExitScope(); HandleCodeCompleteResults(this, CodeCompleter, Results.getCompletionContext(), Results.data(), Results.size()); } -void Sema::CodeCompleteObjCInterfaceCategory(Scope *S, +void Sema::CodeCompleteObjCInterfaceCategory(Scope *S, IdentifierInfo *ClassName, SourceLocation ClassNameLoc) { typedef CodeCompletionResult Result; - + ResultBuilder Results(*this, CodeCompleter->getAllocator(), CodeCompleter->getCodeCompletionTUInfo(), CodeCompletionContext::CCC_ObjCCategoryName); - + // Ignore any categories we find that have already been implemented by this // interface. llvm::SmallPtrSet CategoryNames; @@ -6548,7 +6548,7 @@ void Sema::CodeCompleteObjCInterfaceCategory(Scope *S, // Add all of the categories we know about. Results.EnterNewScope(); TranslationUnitDecl *TU = Context.getTranslationUnitDecl(); - for (const auto *D : TU->decls()) + for (const auto *D : TU->decls()) if (const auto *Category = dyn_cast(D)) if (CategoryNames.insert(Category->getIdentifier()).second) Results.AddResult(Result(Category, Results.getBasePriority(Category), @@ -6560,11 +6560,11 @@ void Sema::CodeCompleteObjCInterfaceCategory(Scope *S, Results.data(), Results.size()); } -void Sema::CodeCompleteObjCImplementationCategory(Scope *S, +void Sema::CodeCompleteObjCImplementationCategory(Scope *S, IdentifierInfo *ClassName, SourceLocation ClassNameLoc) { typedef CodeCompletionResult Result; - + // Find the corresponding interface. If we couldn't find the interface, the // program itself is ill-formed. However, we'll try to be helpful still by // providing the list of all of the categories we know about. @@ -6573,12 +6573,12 @@ void Sema::CodeCompleteObjCImplementationCategory(Scope *S, ObjCInterfaceDecl *Class = dyn_cast_or_null(CurClass); if (!Class) return CodeCompleteObjCInterfaceCategory(S, ClassName, ClassNameLoc); - + ResultBuilder Results(*this, CodeCompleter->getAllocator(), CodeCompleter->getCodeCompletionTUInfo(), CodeCompletionContext::CCC_ObjCCategoryName); - - // Add all of the categories that have have corresponding interface + + // Add all of the categories that have have corresponding interface // declarations in this class and any of its superclasses, except for // already-implemented categories in the class itself. llvm::SmallPtrSet CategoryNames; @@ -6591,7 +6591,7 @@ void Sema::CodeCompleteObjCImplementationCategory(Scope *S, Results.AddResult(Result(Cat, Results.getBasePriority(Cat), nullptr), CurContext, nullptr, false); } - + Class = Class->getSuperClass(); IgnoreImplemented = false; } @@ -6610,29 +6610,29 @@ void Sema::CodeCompleteObjCPropertyDefinition(Scope *S) { // Figure out where this @synthesize lives. ObjCContainerDecl *Container = dyn_cast_or_null(CurContext); - if (!Container || - (!isa(Container) && + if (!Container || + (!isa(Container) && !isa(Container))) - return; + return; // Ignore any properties that have already been implemented. Container = getContainerDef(Container); for (const auto *D : Container->decls()) if (const auto *PropertyImpl = dyn_cast(D)) Results.Ignore(PropertyImpl->getPropertyDecl()); - + // Add any properties that we find. AddedPropertiesSet AddedProperties; Results.EnterNewScope(); if (ObjCImplementationDecl *ClassImpl = dyn_cast(Container)) AddObjCProperties(CCContext, ClassImpl->getClassInterface(), false, - /*AllowNullaryMethods=*/false, CurContext, + /*AllowNullaryMethods=*/false, CurContext, AddedProperties, Results); else AddObjCProperties(CCContext, cast(Container)->getCategoryDecl(), - false, /*AllowNullaryMethods=*/false, CurContext, + false, /*AllowNullaryMethods=*/false, CurContext, AddedProperties, Results); Results.ExitScope(); @@ -6640,7 +6640,7 @@ void Sema::CodeCompleteObjCPropertyDefinition(Scope *S) { Results.data(), Results.size()); } -void Sema::CodeCompleteObjCPropertySynthesizeIvar(Scope *S, +void Sema::CodeCompleteObjCPropertySynthesizeIvar(Scope *S, IdentifierInfo *PropertyName) { typedef CodeCompletionResult Result; ResultBuilder Results(*this, CodeCompleter->getAllocator(), @@ -6650,11 +6650,11 @@ void Sema::CodeCompleteObjCPropertySynthesizeIvar(Scope *S, // Figure out where this @synthesize lives. ObjCContainerDecl *Container = dyn_cast_or_null(CurContext); - if (!Container || - (!isa(Container) && + if (!Container || + (!isa(Container) && !isa(Container))) - return; - + return; + // Figure out which interface we're looking into. ObjCInterfaceDecl *Class = nullptr; if (ObjCImplementationDecl *ClassImpl @@ -6669,10 +6669,10 @@ void Sema::CodeCompleteObjCPropertySynthesizeIvar(Scope *S, if (Class) { if (ObjCPropertyDecl *Property = Class->FindPropertyDeclaration( PropertyName, ObjCPropertyQueryKind::OBJC_PR_query_instance)) { - PropertyType + PropertyType = Property->getType().getNonReferenceType().getUnqualifiedType(); - - // Give preference to ivars + + // Give preference to ivars Results.setPreferredType(PropertyType); } } @@ -6686,32 +6686,32 @@ void Sema::CodeCompleteObjCPropertySynthesizeIvar(Scope *S, std::string NameWithSuffix = PropertyName->getName().str(); NameWithSuffix += '_'; for(; Class; Class = Class->getSuperClass()) { - for (ObjCIvarDecl *Ivar = Class->all_declared_ivar_begin(); Ivar; + for (ObjCIvarDecl *Ivar = Class->all_declared_ivar_begin(); Ivar; Ivar = Ivar->getNextIvar()) { Results.AddResult(Result(Ivar, Results.getBasePriority(Ivar), nullptr), CurContext, nullptr, false); - // Determine whether we've seen an ivar with a name similar to the + // Determine whether we've seen an ivar with a name similar to the // property. if ((PropertyName == Ivar->getIdentifier() || NameWithPrefix == Ivar->getName() || NameWithSuffix == Ivar->getName())) { SawSimilarlyNamedIvar = true; - + // Reduce the priority of this result by one, to give it a slight // advantage over other results whose names don't match so closely. - if (Results.size() && - Results.data()[Results.size() - 1].Kind + if (Results.size() && + Results.data()[Results.size() - 1].Kind == CodeCompletionResult::RK_Declaration && Results.data()[Results.size() - 1].Declaration == Ivar) Results.data()[Results.size() - 1].Priority--; } } } - + if (!SawSimilarlyNamedIvar) { // Create ivar result _propName, that the user can use to synthesize - // an ivar of the appropriate type. + // an ivar of the appropriate type. unsigned Priority = CCP_MemberDeclaration + 1; typedef CodeCompletionResult Result; CodeCompletionAllocator &Allocator = Results.getAllocator(); @@ -6722,10 +6722,10 @@ void Sema::CodeCompleteObjCPropertySynthesizeIvar(Scope *S, Builder.AddResultTypeChunk(GetCompletionTypeString(PropertyType, Context, Policy, Allocator)); Builder.AddTypedTextChunk(Allocator.CopyString(NameWithPrefix)); - Results.AddResult(Result(Builder.TakeString(), Priority, + Results.AddResult(Result(Builder.TakeString(), Priority, CXCursor_ObjCIvarDecl)); } - + Results.ExitScope(); HandleCodeCompleteResults(this, CodeCompleter, Results.getCompletionContext(), @@ -6754,11 +6754,11 @@ static void FindImplementableMethods(ASTContext &Context, IFace = IFace->getDefinition(); Container = IFace; - + const ObjCList &Protocols = IFace->getReferencedProtocols(); for (ObjCList::iterator I = Protocols.begin(), - E = Protocols.end(); + E = Protocols.end(); I != E; ++I) FindImplementableMethods(Context, *I, WantInstanceMethods, ReturnType, KnownMethods, InOriginalClass); @@ -6766,12 +6766,12 @@ static void FindImplementableMethods(ASTContext &Context, // Add methods from any class extensions and categories. for (auto *Cat : IFace->visible_categories()) { FindImplementableMethods(Context, Cat, WantInstanceMethods, ReturnType, - KnownMethods, false); + KnownMethods, false); } // Visit the superclass. if (IFace->getSuperClass()) - FindImplementableMethods(Context, IFace->getSuperClass(), + FindImplementableMethods(Context, IFace->getSuperClass(), WantInstanceMethods, ReturnType, KnownMethods, false); } @@ -6781,14 +6781,14 @@ static void FindImplementableMethods(ASTContext &Context, const ObjCList &Protocols = Category->getReferencedProtocols(); for (ObjCList::iterator I = Protocols.begin(), - E = Protocols.end(); + E = Protocols.end(); I != E; ++I) FindImplementableMethods(Context, *I, WantInstanceMethods, ReturnType, KnownMethods, InOriginalClass); - + // If this category is the original class, jump to the interface. if (InOriginalClass && Category->getClassInterface()) - FindImplementableMethods(Context, Category->getClassInterface(), + FindImplementableMethods(Context, Category->getClassInterface(), WantInstanceMethods, ReturnType, KnownMethods, false); } @@ -6799,12 +6799,12 @@ static void FindImplementableMethods(ASTContext &Context, return; Protocol = Protocol->getDefinition(); Container = Protocol; - + // Recurse into protocols. const ObjCList &Protocols = Protocol->getReferencedProtocols(); for (ObjCList::iterator I = Protocols.begin(), - E = Protocols.end(); + E = Protocols.end(); I != E; ++I) FindImplementableMethods(Context, *I, WantInstanceMethods, ReturnType, KnownMethods, false); @@ -6825,7 +6825,7 @@ static void FindImplementableMethods(ASTContext &Context, } } -/// Add the parenthesized return or parameter type chunk to a code +/// Add the parenthesized return or parameter type chunk to a code /// completion string. static void AddObjCPassingTypeChunk(QualType Type, unsigned ObjCDeclQuals, @@ -6843,17 +6843,17 @@ static void AddObjCPassingTypeChunk(QualType Type, /// Determine whether the given class is or inherits from a class by /// the given name. -static bool InheritsFromClassNamed(ObjCInterfaceDecl *Class, +static bool InheritsFromClassNamed(ObjCInterfaceDecl *Class, StringRef Name) { if (!Class) return false; - + if (Class->getIdentifier() && Class->getIdentifier()->getName() == Name) return true; - + return InheritsFromClassNamed(Class->getSuperClass(), Name); } - + /// Add code completions for Objective-C Key-Value Coding (KVC) and /// Key-Value Observing (KVO). static void AddObjCKeyValueCompletions(ObjCPropertyDecl *Property, @@ -6865,17 +6865,17 @@ static void AddObjCKeyValueCompletions(ObjCPropertyDecl *Property, IdentifierInfo *PropName = Property->getIdentifier(); if (!PropName || PropName->getLength() == 0) return; - + PrintingPolicy Policy = getCompletionPrintingPolicy(Results.getSema()); // Builder that will create each code completion. typedef CodeCompletionResult Result; CodeCompletionAllocator &Allocator = Results.getAllocator(); CodeCompletionBuilder Builder(Allocator, Results.getCodeCompletionTUInfo()); - + // The selector table. SelectorTable &Selectors = Context.Selectors; - + // The property name, copied into the code completion allocation region // on demand. struct KeyHolder { @@ -6889,22 +6889,22 @@ static void AddObjCKeyValueCompletions(ObjCPropertyDecl *Property, operator const char *() { if (CopiedKey) return CopiedKey; - + return CopiedKey = Allocator.CopyString(Key); } } Key(Allocator, PropName->getName()); - + // The uppercased name of the property name. std::string UpperKey = PropName->getName(); if (!UpperKey.empty()) UpperKey[0] = toUppercase(UpperKey[0]); - + bool ReturnTypeMatchesProperty = ReturnType.isNull() || - Context.hasSameUnqualifiedType(ReturnType.getNonReferenceType(), + Context.hasSameUnqualifiedType(ReturnType.getNonReferenceType(), Property->getType()); - bool ReturnTypeMatchesVoid + bool ReturnTypeMatchesVoid = ReturnType.isNull() || ReturnType->isVoidType(); - + // Add the normal accessor -(type)key. if (IsInstanceMethod && KnownSelectors.insert(Selectors.getNullarySelector(PropName)).second && @@ -6912,19 +6912,19 @@ static void AddObjCKeyValueCompletions(ObjCPropertyDecl *Property, if (ReturnType.isNull()) AddObjCPassingTypeChunk(Property->getType(), /*Quals=*/0, Context, Policy, Builder); - + Builder.AddTypedTextChunk(Key); - Results.AddResult(Result(Builder.TakeString(), CCP_CodePattern, + Results.AddResult(Result(Builder.TakeString(), CCP_CodePattern, CXCursor_ObjCInstanceMethodDecl)); } - + // If we have an integral or boolean property (or the user has provided // an integral or boolean return type), add the accessor -(type)isKey. if (IsInstanceMethod && - ((!ReturnType.isNull() && + ((!ReturnType.isNull() && (ReturnType->isIntegerType() || ReturnType->isBooleanType())) || - (ReturnType.isNull() && - (Property->getType()->isIntegerType() || + (ReturnType.isNull() && + (Property->getType()->isIntegerType() || Property->getType()->isBooleanType())))) { std::string SelectorName = (Twine("is") + UpperKey).str(); IdentifierInfo *SelectorId = &Context.Idents.get(SelectorName); @@ -6935,16 +6935,16 @@ static void AddObjCKeyValueCompletions(ObjCPropertyDecl *Property, Builder.AddTextChunk("BOOL"); Builder.AddChunk(CodeCompletionString::CK_RightParen); } - + Builder.AddTypedTextChunk( Allocator.CopyString(SelectorId->getName())); - Results.AddResult(Result(Builder.TakeString(), CCP_CodePattern, + Results.AddResult(Result(Builder.TakeString(), CCP_CodePattern, CXCursor_ObjCInstanceMethodDecl)); } } - + // Add the normal mutator. - if (IsInstanceMethod && ReturnTypeMatchesVoid && + if (IsInstanceMethod && ReturnTypeMatchesVoid && !Property->getSetterMethodDecl()) { std::string SelectorName = (Twine("set") + UpperKey).str(); IdentifierInfo *SelectorId = &Context.Idents.get(SelectorName); @@ -6954,36 +6954,36 @@ static void AddObjCKeyValueCompletions(ObjCPropertyDecl *Property, Builder.AddTextChunk("void"); Builder.AddChunk(CodeCompletionString::CK_RightParen); } - + Builder.AddTypedTextChunk( Allocator.CopyString(SelectorId->getName())); Builder.AddTypedTextChunk(":"); AddObjCPassingTypeChunk(Property->getType(), /*Quals=*/0, Context, Policy, Builder); Builder.AddTextChunk(Key); - Results.AddResult(Result(Builder.TakeString(), CCP_CodePattern, + Results.AddResult(Result(Builder.TakeString(), CCP_CodePattern, CXCursor_ObjCInstanceMethodDecl)); } } - + // Indexed and unordered accessors unsigned IndexedGetterPriority = CCP_CodePattern; unsigned IndexedSetterPriority = CCP_CodePattern; unsigned UnorderedGetterPriority = CCP_CodePattern; unsigned UnorderedSetterPriority = CCP_CodePattern; - if (const ObjCObjectPointerType *ObjCPointer + if (const ObjCObjectPointerType *ObjCPointer = Property->getType()->getAs()) { if (ObjCInterfaceDecl *IFace = ObjCPointer->getInterfaceDecl()) { // If this interface type is not provably derived from a known // collection, penalize the corresponding completions. if (!InheritsFromClassNamed(IFace, "NSMutableArray")) { - IndexedSetterPriority += CCD_ProbablyNotObjCCollection; + IndexedSetterPriority += CCD_ProbablyNotObjCCollection; if (!InheritsFromClassNamed(IFace, "NSArray")) IndexedGetterPriority += CCD_ProbablyNotObjCCollection; } if (!InheritsFromClassNamed(IFace, "NSMutableSet")) { - UnorderedSetterPriority += CCD_ProbablyNotObjCCollection; + UnorderedSetterPriority += CCD_ProbablyNotObjCCollection; if (!InheritsFromClassNamed(IFace, "NSSet")) UnorderedGetterPriority += CCD_ProbablyNotObjCCollection; } @@ -6994,9 +6994,9 @@ static void AddObjCKeyValueCompletions(ObjCPropertyDecl *Property, UnorderedGetterPriority += CCD_ProbablyNotObjCCollection; UnorderedSetterPriority += CCD_ProbablyNotObjCCollection; } - + // Add -(NSUInteger)countOf - if (IsInstanceMethod && + if (IsInstanceMethod && (ReturnType.isNull() || ReturnType->isIntegerType())) { std::string SelectorName = (Twine("countOf") + UpperKey).str(); IdentifierInfo *SelectorId = &Context.Idents.get(SelectorName); @@ -7007,16 +7007,16 @@ static void AddObjCKeyValueCompletions(ObjCPropertyDecl *Property, Builder.AddTextChunk("NSUInteger"); Builder.AddChunk(CodeCompletionString::CK_RightParen); } - + Builder.AddTypedTextChunk( Allocator.CopyString(SelectorId->getName())); - Results.AddResult(Result(Builder.TakeString(), - std::min(IndexedGetterPriority, + Results.AddResult(Result(Builder.TakeString(), + std::min(IndexedGetterPriority, UnorderedGetterPriority), CXCursor_ObjCInstanceMethodDecl)); } } - + // Indexed getters // Add -(id)objectInKeyAtIndex:(NSUInteger)index if (IsInstanceMethod && @@ -7030,20 +7030,20 @@ static void AddObjCKeyValueCompletions(ObjCPropertyDecl *Property, Builder.AddTextChunk("id"); Builder.AddChunk(CodeCompletionString::CK_RightParen); } - + Builder.AddTypedTextChunk(Allocator.CopyString(SelectorName + ":")); Builder.AddChunk(CodeCompletionString::CK_LeftParen); Builder.AddTextChunk("NSUInteger"); Builder.AddChunk(CodeCompletionString::CK_RightParen); Builder.AddTextChunk("index"); - Results.AddResult(Result(Builder.TakeString(), IndexedGetterPriority, + Results.AddResult(Result(Builder.TakeString(), IndexedGetterPriority, CXCursor_ObjCInstanceMethodDecl)); } } - + // Add -(NSArray *)keyAtIndexes:(NSIndexSet *)indexes if (IsInstanceMethod && - (ReturnType.isNull() || + (ReturnType.isNull() || (ReturnType->isObjCObjectPointerType() && ReturnType->getAs()->getInterfaceDecl() && ReturnType->getAs()->getInterfaceDecl() @@ -7057,17 +7057,17 @@ static void AddObjCKeyValueCompletions(ObjCPropertyDecl *Property, Builder.AddTextChunk("NSArray *"); Builder.AddChunk(CodeCompletionString::CK_RightParen); } - + Builder.AddTypedTextChunk(Allocator.CopyString(SelectorName + ":")); Builder.AddChunk(CodeCompletionString::CK_LeftParen); Builder.AddTextChunk("NSIndexSet *"); Builder.AddChunk(CodeCompletionString::CK_RightParen); Builder.AddTextChunk("indexes"); - Results.AddResult(Result(Builder.TakeString(), IndexedGetterPriority, + Results.AddResult(Result(Builder.TakeString(), IndexedGetterPriority, CXCursor_ObjCInstanceMethodDecl)); } } - + // Add -(void)getKey:(type **)buffer range:(NSRange)inRange if (IsInstanceMethod && ReturnTypeMatchesVoid) { std::string SelectorName = (Twine("get") + UpperKey).str(); @@ -7075,14 +7075,14 @@ static void AddObjCKeyValueCompletions(ObjCPropertyDecl *Property, &Context.Idents.get(SelectorName), &Context.Idents.get("range") }; - + if (KnownSelectors.insert(Selectors.getSelector(2, SelectorIds)).second) { if (ReturnType.isNull()) { Builder.AddChunk(CodeCompletionString::CK_LeftParen); Builder.AddTextChunk("void"); Builder.AddChunk(CodeCompletionString::CK_RightParen); } - + Builder.AddTypedTextChunk(Allocator.CopyString(SelectorName + ":")); Builder.AddChunk(CodeCompletionString::CK_LeftParen); Builder.AddPlaceholderChunk("object-type"); @@ -7095,13 +7095,13 @@ static void AddObjCKeyValueCompletions(ObjCPropertyDecl *Property, Builder.AddTextChunk("NSRange"); Builder.AddChunk(CodeCompletionString::CK_RightParen); Builder.AddTextChunk("inRange"); - Results.AddResult(Result(Builder.TakeString(), IndexedGetterPriority, + Results.AddResult(Result(Builder.TakeString(), IndexedGetterPriority, CXCursor_ObjCInstanceMethodDecl)); } } - + // Mutable indexed accessors - + // - (void)insertObject:(type *)object inKeyAtIndex:(NSUInteger)index if (IsInstanceMethod && ReturnTypeMatchesVoid) { std::string SelectorName = (Twine("in") + UpperKey + "AtIndex").str(); @@ -7109,14 +7109,14 @@ static void AddObjCKeyValueCompletions(ObjCPropertyDecl *Property, &Context.Idents.get("insertObject"), &Context.Idents.get(SelectorName) }; - + if (KnownSelectors.insert(Selectors.getSelector(2, SelectorIds)).second) { if (ReturnType.isNull()) { Builder.AddChunk(CodeCompletionString::CK_LeftParen); Builder.AddTextChunk("void"); Builder.AddChunk(CodeCompletionString::CK_RightParen); } - + Builder.AddTypedTextChunk("insertObject:"); Builder.AddChunk(CodeCompletionString::CK_LeftParen); Builder.AddPlaceholderChunk("object-type"); @@ -7129,11 +7129,11 @@ static void AddObjCKeyValueCompletions(ObjCPropertyDecl *Property, Builder.AddPlaceholderChunk("NSUInteger"); Builder.AddChunk(CodeCompletionString::CK_RightParen); Builder.AddTextChunk("index"); - Results.AddResult(Result(Builder.TakeString(), IndexedSetterPriority, + Results.AddResult(Result(Builder.TakeString(), IndexedSetterPriority, CXCursor_ObjCInstanceMethodDecl)); } } - + // - (void)insertKey:(NSArray *)array atIndexes:(NSIndexSet *)indexes if (IsInstanceMethod && ReturnTypeMatchesVoid) { std::string SelectorName = (Twine("insert") + UpperKey).str(); @@ -7141,14 +7141,14 @@ static void AddObjCKeyValueCompletions(ObjCPropertyDecl *Property, &Context.Idents.get(SelectorName), &Context.Idents.get("atIndexes") }; - + if (KnownSelectors.insert(Selectors.getSelector(2, SelectorIds)).second) { if (ReturnType.isNull()) { Builder.AddChunk(CodeCompletionString::CK_LeftParen); Builder.AddTextChunk("void"); Builder.AddChunk(CodeCompletionString::CK_RightParen); } - + Builder.AddTypedTextChunk(Allocator.CopyString(SelectorName + ":")); Builder.AddChunk(CodeCompletionString::CK_LeftParen); Builder.AddTextChunk("NSArray *"); @@ -7160,55 +7160,55 @@ static void AddObjCKeyValueCompletions(ObjCPropertyDecl *Property, Builder.AddPlaceholderChunk("NSIndexSet *"); Builder.AddChunk(CodeCompletionString::CK_RightParen); Builder.AddTextChunk("indexes"); - Results.AddResult(Result(Builder.TakeString(), IndexedSetterPriority, + Results.AddResult(Result(Builder.TakeString(), IndexedSetterPriority, CXCursor_ObjCInstanceMethodDecl)); } } - + // -(void)removeObjectFromKeyAtIndex:(NSUInteger)index if (IsInstanceMethod && ReturnTypeMatchesVoid) { std::string SelectorName = (Twine("removeObjectFrom") + UpperKey + "AtIndex").str(); - IdentifierInfo *SelectorId = &Context.Idents.get(SelectorName); + IdentifierInfo *SelectorId = &Context.Idents.get(SelectorName); if (KnownSelectors.insert(Selectors.getUnarySelector(SelectorId)).second) { if (ReturnType.isNull()) { Builder.AddChunk(CodeCompletionString::CK_LeftParen); Builder.AddTextChunk("void"); Builder.AddChunk(CodeCompletionString::CK_RightParen); } - + Builder.AddTypedTextChunk(Allocator.CopyString(SelectorName + ":")); Builder.AddChunk(CodeCompletionString::CK_LeftParen); Builder.AddTextChunk("NSUInteger"); Builder.AddChunk(CodeCompletionString::CK_RightParen); Builder.AddTextChunk("index"); - Results.AddResult(Result(Builder.TakeString(), IndexedSetterPriority, + Results.AddResult(Result(Builder.TakeString(), IndexedSetterPriority, CXCursor_ObjCInstanceMethodDecl)); } } - + // -(void)removeKeyAtIndexes:(NSIndexSet *)indexes if (IsInstanceMethod && ReturnTypeMatchesVoid) { std::string SelectorName = (Twine("remove") + UpperKey + "AtIndexes").str(); - IdentifierInfo *SelectorId = &Context.Idents.get(SelectorName); + IdentifierInfo *SelectorId = &Context.Idents.get(SelectorName); if (KnownSelectors.insert(Selectors.getUnarySelector(SelectorId)).second) { if (ReturnType.isNull()) { Builder.AddChunk(CodeCompletionString::CK_LeftParen); Builder.AddTextChunk("void"); Builder.AddChunk(CodeCompletionString::CK_RightParen); } - + Builder.AddTypedTextChunk(Allocator.CopyString(SelectorName + ":")); Builder.AddChunk(CodeCompletionString::CK_LeftParen); Builder.AddTextChunk("NSIndexSet *"); Builder.AddChunk(CodeCompletionString::CK_RightParen); Builder.AddTextChunk("indexes"); - Results.AddResult(Result(Builder.TakeString(), IndexedSetterPriority, + Results.AddResult(Result(Builder.TakeString(), IndexedSetterPriority, CXCursor_ObjCInstanceMethodDecl)); } } - + // - (void)replaceObjectInKeyAtIndex:(NSUInteger)index withObject:(id)object if (IsInstanceMethod && ReturnTypeMatchesVoid) { std::string SelectorName @@ -7217,14 +7217,14 @@ static void AddObjCKeyValueCompletions(ObjCPropertyDecl *Property, &Context.Idents.get(SelectorName), &Context.Idents.get("withObject") }; - + if (KnownSelectors.insert(Selectors.getSelector(2, SelectorIds)).second) { if (ReturnType.isNull()) { Builder.AddChunk(CodeCompletionString::CK_LeftParen); Builder.AddTextChunk("void"); Builder.AddChunk(CodeCompletionString::CK_RightParen); } - + Builder.AddTypedTextChunk(Allocator.CopyString(SelectorName + ":")); Builder.AddChunk(CodeCompletionString::CK_LeftParen); Builder.AddPlaceholderChunk("NSUInteger"); @@ -7236,28 +7236,28 @@ static void AddObjCKeyValueCompletions(ObjCPropertyDecl *Property, Builder.AddTextChunk("id"); Builder.AddChunk(CodeCompletionString::CK_RightParen); Builder.AddTextChunk("object"); - Results.AddResult(Result(Builder.TakeString(), IndexedSetterPriority, + Results.AddResult(Result(Builder.TakeString(), IndexedSetterPriority, CXCursor_ObjCInstanceMethodDecl)); } } - + // - (void)replaceKeyAtIndexes:(NSIndexSet *)indexes withKey:(NSArray *)array if (IsInstanceMethod && ReturnTypeMatchesVoid) { - std::string SelectorName1 + std::string SelectorName1 = (Twine("replace") + UpperKey + "AtIndexes").str(); std::string SelectorName2 = (Twine("with") + UpperKey).str(); IdentifierInfo *SelectorIds[2] = { &Context.Idents.get(SelectorName1), &Context.Idents.get(SelectorName2) }; - + if (KnownSelectors.insert(Selectors.getSelector(2, SelectorIds)).second) { if (ReturnType.isNull()) { Builder.AddChunk(CodeCompletionString::CK_LeftParen); Builder.AddTextChunk("void"); Builder.AddChunk(CodeCompletionString::CK_RightParen); } - + Builder.AddTypedTextChunk(Allocator.CopyString(SelectorName1 + ":")); Builder.AddChunk(CodeCompletionString::CK_LeftParen); Builder.AddPlaceholderChunk("NSIndexSet *"); @@ -7269,15 +7269,15 @@ static void AddObjCKeyValueCompletions(ObjCPropertyDecl *Property, Builder.AddTextChunk("NSArray *"); Builder.AddChunk(CodeCompletionString::CK_RightParen); Builder.AddTextChunk("array"); - Results.AddResult(Result(Builder.TakeString(), IndexedSetterPriority, + Results.AddResult(Result(Builder.TakeString(), IndexedSetterPriority, CXCursor_ObjCInstanceMethodDecl)); } - } - + } + // Unordered getters // - (NSEnumerator *)enumeratorOfKey - if (IsInstanceMethod && - (ReturnType.isNull() || + if (IsInstanceMethod && + (ReturnType.isNull() || (ReturnType->isObjCObjectPointerType() && ReturnType->getAs()->getInterfaceDecl() && ReturnType->getAs()->getInterfaceDecl() @@ -7291,15 +7291,15 @@ static void AddObjCKeyValueCompletions(ObjCPropertyDecl *Property, Builder.AddTextChunk("NSEnumerator *"); Builder.AddChunk(CodeCompletionString::CK_RightParen); } - + Builder.AddTypedTextChunk(Allocator.CopyString(SelectorName)); - Results.AddResult(Result(Builder.TakeString(), UnorderedGetterPriority, + Results.AddResult(Result(Builder.TakeString(), UnorderedGetterPriority, CXCursor_ObjCInstanceMethodDecl)); } } // - (type *)memberOfKey:(type *)object - if (IsInstanceMethod && + if (IsInstanceMethod && (ReturnType.isNull() || ReturnType->isObjCObjectPointerType())) { std::string SelectorName = (Twine("memberOf") + UpperKey).str(); IdentifierInfo *SelectorId = &Context.Idents.get(SelectorName); @@ -7310,24 +7310,24 @@ static void AddObjCKeyValueCompletions(ObjCPropertyDecl *Property, Builder.AddTextChunk(" *"); Builder.AddChunk(CodeCompletionString::CK_RightParen); } - + Builder.AddTypedTextChunk(Allocator.CopyString(SelectorName + ":")); Builder.AddChunk(CodeCompletionString::CK_LeftParen); if (ReturnType.isNull()) { Builder.AddPlaceholderChunk("object-type"); Builder.AddTextChunk(" *"); } else { - Builder.AddTextChunk(GetCompletionTypeString(ReturnType, Context, + Builder.AddTextChunk(GetCompletionTypeString(ReturnType, Context, Policy, Builder.getAllocator())); } Builder.AddChunk(CodeCompletionString::CK_RightParen); Builder.AddTextChunk("object"); - Results.AddResult(Result(Builder.TakeString(), UnorderedGetterPriority, + Results.AddResult(Result(Builder.TakeString(), UnorderedGetterPriority, CXCursor_ObjCInstanceMethodDecl)); } } - + // Mutable unordered accessors // - (void)addKeyObject:(type *)object if (IsInstanceMethod && ReturnTypeMatchesVoid) { @@ -7340,17 +7340,17 @@ static void AddObjCKeyValueCompletions(ObjCPropertyDecl *Property, Builder.AddTextChunk("void"); Builder.AddChunk(CodeCompletionString::CK_RightParen); } - + Builder.AddTypedTextChunk(Allocator.CopyString(SelectorName + ":")); Builder.AddChunk(CodeCompletionString::CK_LeftParen); Builder.AddPlaceholderChunk("object-type"); Builder.AddTextChunk(" *"); Builder.AddChunk(CodeCompletionString::CK_RightParen); Builder.AddTextChunk("object"); - Results.AddResult(Result(Builder.TakeString(), UnorderedSetterPriority, + Results.AddResult(Result(Builder.TakeString(), UnorderedSetterPriority, CXCursor_ObjCInstanceMethodDecl)); } - } + } // - (void)addKey:(NSSet *)objects if (IsInstanceMethod && ReturnTypeMatchesVoid) { @@ -7362,17 +7362,17 @@ static void AddObjCKeyValueCompletions(ObjCPropertyDecl *Property, Builder.AddTextChunk("void"); Builder.AddChunk(CodeCompletionString::CK_RightParen); } - + Builder.AddTypedTextChunk(Allocator.CopyString(SelectorName + ":")); Builder.AddChunk(CodeCompletionString::CK_LeftParen); Builder.AddTextChunk("NSSet *"); Builder.AddChunk(CodeCompletionString::CK_RightParen); Builder.AddTextChunk("objects"); - Results.AddResult(Result(Builder.TakeString(), UnorderedSetterPriority, + Results.AddResult(Result(Builder.TakeString(), UnorderedSetterPriority, CXCursor_ObjCInstanceMethodDecl)); } - } - + } + // - (void)removeKeyObject:(type *)object if (IsInstanceMethod && ReturnTypeMatchesVoid) { std::string SelectorName @@ -7384,18 +7384,18 @@ static void AddObjCKeyValueCompletions(ObjCPropertyDecl *Property, Builder.AddTextChunk("void"); Builder.AddChunk(CodeCompletionString::CK_RightParen); } - + Builder.AddTypedTextChunk(Allocator.CopyString(SelectorName + ":")); Builder.AddChunk(CodeCompletionString::CK_LeftParen); Builder.AddPlaceholderChunk("object-type"); Builder.AddTextChunk(" *"); Builder.AddChunk(CodeCompletionString::CK_RightParen); Builder.AddTextChunk("object"); - Results.AddResult(Result(Builder.TakeString(), UnorderedSetterPriority, + Results.AddResult(Result(Builder.TakeString(), UnorderedSetterPriority, CXCursor_ObjCInstanceMethodDecl)); } - } - + } + // - (void)removeKey:(NSSet *)objects if (IsInstanceMethod && ReturnTypeMatchesVoid) { std::string SelectorName = (Twine("remove") + UpperKey).str(); @@ -7406,16 +7406,16 @@ static void AddObjCKeyValueCompletions(ObjCPropertyDecl *Property, Builder.AddTextChunk("void"); Builder.AddChunk(CodeCompletionString::CK_RightParen); } - + Builder.AddTypedTextChunk(Allocator.CopyString(SelectorName + ":")); Builder.AddChunk(CodeCompletionString::CK_LeftParen); Builder.AddTextChunk("NSSet *"); Builder.AddChunk(CodeCompletionString::CK_RightParen); Builder.AddTextChunk("objects"); - Results.AddResult(Result(Builder.TakeString(), UnorderedSetterPriority, + Results.AddResult(Result(Builder.TakeString(), UnorderedSetterPriority, CXCursor_ObjCInstanceMethodDecl)); } - } + } // - (void)intersectKey:(NSSet *)objects if (IsInstanceMethod && ReturnTypeMatchesVoid) { @@ -7427,26 +7427,26 @@ static void AddObjCKeyValueCompletions(ObjCPropertyDecl *Property, Builder.AddTextChunk("void"); Builder.AddChunk(CodeCompletionString::CK_RightParen); } - + Builder.AddTypedTextChunk(Allocator.CopyString(SelectorName + ":")); Builder.AddChunk(CodeCompletionString::CK_LeftParen); Builder.AddTextChunk("NSSet *"); Builder.AddChunk(CodeCompletionString::CK_RightParen); Builder.AddTextChunk("objects"); - Results.AddResult(Result(Builder.TakeString(), UnorderedSetterPriority, + Results.AddResult(Result(Builder.TakeString(), UnorderedSetterPriority, CXCursor_ObjCInstanceMethodDecl)); } - } - + } + // Key-Value Observing // + (NSSet *)keyPathsForValuesAffectingKey - if (!IsInstanceMethod && - (ReturnType.isNull() || + if (!IsInstanceMethod && + (ReturnType.isNull() || (ReturnType->isObjCObjectPointerType() && ReturnType->getAs()->getInterfaceDecl() && ReturnType->getAs()->getInterfaceDecl() ->getName() == "NSSet"))) { - std::string SelectorName + std::string SelectorName = (Twine("keyPathsForValuesAffecting") + UpperKey).str(); IdentifierInfo *SelectorId = &Context.Idents.get(SelectorName); if (KnownSelectors.insert(Selectors.getNullarySelector(SelectorId)) @@ -7456,9 +7456,9 @@ static void AddObjCKeyValueCompletions(ObjCPropertyDecl *Property, Builder.AddTextChunk("NSSet *"); Builder.AddChunk(CodeCompletionString::CK_RightParen); } - + Builder.AddTypedTextChunk(Allocator.CopyString(SelectorName)); - Results.AddResult(Result(Builder.TakeString(), CCP_CodePattern, + Results.AddResult(Result(Builder.TakeString(), CCP_CodePattern, CXCursor_ObjCClassMethodDecl)); } } @@ -7466,9 +7466,9 @@ static void AddObjCKeyValueCompletions(ObjCPropertyDecl *Property, // + (BOOL)automaticallyNotifiesObserversForKey if (!IsInstanceMethod && (ReturnType.isNull() || - ReturnType->isIntegerType() || + ReturnType->isIntegerType() || ReturnType->isBooleanType())) { - std::string SelectorName + std::string SelectorName = (Twine("automaticallyNotifiesObserversOf") + UpperKey).str(); IdentifierInfo *SelectorId = &Context.Idents.get(SelectorName); if (KnownSelectors.insert(Selectors.getNullarySelector(SelectorId)) @@ -7478,9 +7478,9 @@ static void AddObjCKeyValueCompletions(ObjCPropertyDecl *Property, Builder.AddTextChunk("BOOL"); Builder.AddChunk(CodeCompletionString::CK_RightParen); } - + Builder.AddTypedTextChunk(Allocator.CopyString(SelectorName)); - Results.AddResult(Result(Builder.TakeString(), CCP_CodePattern, + Results.AddResult(Result(Builder.TakeString(), CCP_CodePattern, CXCursor_ObjCClassMethodDecl)); } } @@ -7503,7 +7503,7 @@ void Sema::CodeCompleteObjCMethodDecl(Scope *S, Optional IsInstanceMethod, if (ObjCImplementationDecl *Impl = dyn_cast(D)) { SearchDecl = Impl->getClassInterface(); IsInImplementation = true; - } else if (ObjCCategoryImplDecl *CatImpl + } else if (ObjCCategoryImplDecl *CatImpl = dyn_cast(D)) { SearchDecl = CatImpl->getCategoryDecl(); IsInImplementation = true; @@ -7517,17 +7517,17 @@ void Sema::CodeCompleteObjCMethodDecl(Scope *S, Optional IsInstanceMethod, } if (!SearchDecl) { - HandleCodeCompleteResults(this, CodeCompleter, + HandleCodeCompleteResults(this, CodeCompleter, CodeCompletionContext::CCC_Other, nullptr, 0); return; } - + // Find all of the methods that we could declare/implement here. KnownMethodsMap KnownMethods; - FindImplementableMethods(Context, SearchDecl, IsInstanceMethod, + FindImplementableMethods(Context, SearchDecl, IsInstanceMethod, ReturnType, KnownMethods); - + // Add declarations or definitions for each of the known methods. typedef CodeCompletionResult Result; ResultBuilder Results(*this, CodeCompleter->getAllocator(), @@ -7535,7 +7535,7 @@ void Sema::CodeCompleteObjCMethodDecl(Scope *S, Optional IsInstanceMethod, CodeCompletionContext::CCC_Other); Results.EnterNewScope(); PrintingPolicy Policy = getCompletionPrintingPolicy(*this); - for (KnownMethodsMap::iterator M = KnownMethods.begin(), + for (KnownMethodsMap::iterator M = KnownMethods.begin(), MEnd = KnownMethods.end(); M != MEnd; ++M) { ObjCMethodDecl *Method = M->second.getPointer(); @@ -7566,7 +7566,7 @@ void Sema::CodeCompleteObjCMethodDecl(Scope *S, Optional IsInstanceMethod, // Add parameters to the pattern. unsigned I = 0; - for (ObjCMethodDecl::param_iterator P = Method->param_begin(), + for (ObjCMethodDecl::param_iterator P = Method->param_begin(), PEnd = Method->param_end(); P != PEnd; (void)++P, ++I) { // Add the part of the selector name. @@ -7592,16 +7592,16 @@ void Sema::CodeCompleteObjCMethodDecl(Scope *S, Optional IsInstanceMethod, (*P)->getObjCDeclQualifier(), Context, Policy, Builder); - + if (IdentifierInfo *Id = (*P)->getIdentifier()) - Builder.AddTextChunk(Builder.getAllocator().CopyString( Id->getName())); + Builder.AddTextChunk(Builder.getAllocator().CopyString( Id->getName())); } if (Method->isVariadic()) { if (Method->param_size() > 0) Builder.AddChunk(CodeCompletionString::CK_Comma); Builder.AddTextChunk("..."); - } + } if (IsInImplementation && Results.includeCodePatterns()) { // We will be defining the method here, so add a compound statement. @@ -7616,7 +7616,7 @@ void Sema::CodeCompleteObjCMethodDecl(Scope *S, Optional IsInstanceMethod, Builder.AddChunk(CodeCompletionString::CK_SemiColon); } else Builder.AddPlaceholderChunk("statements"); - + Builder.AddChunk(CodeCompletionString::CK_VerticalSpace); Builder.AddChunk(CodeCompletionString::CK_RightBrace); } @@ -7624,28 +7624,28 @@ void Sema::CodeCompleteObjCMethodDecl(Scope *S, Optional IsInstanceMethod, unsigned Priority = CCP_CodePattern; if (!M->second.getInt()) Priority += CCD_InBaseClass; - + Results.AddResult(Result(Builder.TakeString(), Method, Priority)); } - // Add Key-Value-Coding and Key-Value-Observing accessor methods for all of + // Add Key-Value-Coding and Key-Value-Observing accessor methods for all of // the properties in this class and its categories. if (Context.getLangOpts().ObjC2) { SmallVector Containers; Containers.push_back(SearchDecl); - + VisitedSelectorSet KnownSelectors; - for (KnownMethodsMap::iterator M = KnownMethods.begin(), + for (KnownMethodsMap::iterator M = KnownMethods.begin(), MEnd = KnownMethods.end(); M != MEnd; ++M) KnownSelectors.insert(M->first); - + ObjCInterfaceDecl *IFace = dyn_cast(SearchDecl); if (!IFace) if (ObjCCategoryDecl *Category = dyn_cast(SearchDecl)) IFace = Category->getClassInterface(); - + if (IFace) for (auto *Cat : IFace->visible_categories()) Containers.push_back(Cat); @@ -7657,14 +7657,14 @@ void Sema::CodeCompleteObjCMethodDecl(Scope *S, Optional IsInstanceMethod, KnownSelectors, Results); } } - + Results.ExitScope(); HandleCodeCompleteResults(this, CodeCompleter, Results.getCompletionContext(), Results.data(), Results.size()); } -void Sema::CodeCompleteObjCMethodDeclSelector(Scope *S, +void Sema::CodeCompleteObjCMethodDeclSelector(Scope *S, bool IsInstanceMethod, bool AtParameterName, ParsedType ReturnTy, @@ -7687,21 +7687,21 @@ void Sema::CodeCompleteObjCMethodDeclSelector(Scope *S, ResultBuilder Results(*this, CodeCompleter->getAllocator(), CodeCompleter->getCodeCompletionTUInfo(), CodeCompletionContext::CCC_Other); - + if (ReturnTy) Results.setPreferredType(GetTypeFromParser(ReturnTy).getNonReferenceType()); - Results.EnterNewScope(); + Results.EnterNewScope(); for (GlobalMethodPool::iterator M = MethodPool.begin(), MEnd = MethodPool.end(); M != MEnd; ++M) { for (ObjCMethodList *MethList = IsInstanceMethod ? &M->second.first : &M->second.second; - MethList && MethList->getMethod(); + MethList && MethList->getMethod(); MethList = MethList->getNext()) { if (!isAcceptableObjCMethod(MethList->getMethod(), MK_Any, SelIdents)) continue; - + if (AtParameterName) { // Suggest parameter names we've seen before. unsigned NumSelIdents = SelIdents.size(); @@ -7717,7 +7717,7 @@ void Sema::CodeCompleteObjCMethodDeclSelector(Scope *S, Results.AddResult(Builder.TakeString()); } } - + continue; } @@ -7729,7 +7729,7 @@ void Sema::CodeCompleteObjCMethodDeclSelector(Scope *S, Results.MaybeAddResult(R, CurContext); } } - + Results.ExitScope(); if (!AtParameterName && !SelIdents.empty() && @@ -7757,7 +7757,7 @@ void Sema::CodeCompletePreprocessorDirective(bool InConditional) { CodeCompleter->getCodeCompletionTUInfo(), CodeCompletionContext::CCC_PreprocessorDirective); Results.EnterNewScope(); - + // #if CodeCompletionBuilder Builder(Results.getAllocator(), Results.getCodeCompletionTUInfo()); @@ -7765,13 +7765,13 @@ void Sema::CodeCompletePreprocessorDirective(bool InConditional) { Builder.AddChunk(CodeCompletionString::CK_HorizontalSpace); Builder.AddPlaceholderChunk("condition"); Results.AddResult(Builder.TakeString()); - + // #ifdef Builder.AddTypedTextChunk("ifdef"); Builder.AddChunk(CodeCompletionString::CK_HorizontalSpace); Builder.AddPlaceholderChunk("macro"); Results.AddResult(Builder.TakeString()); - + // #ifndef Builder.AddTypedTextChunk("ifndef"); Builder.AddChunk(CodeCompletionString::CK_HorizontalSpace); @@ -7793,7 +7793,7 @@ void Sema::CodeCompletePreprocessorDirective(bool InConditional) { Builder.AddTypedTextChunk("endif"); Results.AddResult(Builder.TakeString()); } - + // #include "header" Builder.AddTypedTextChunk("include"); Builder.AddChunk(CodeCompletionString::CK_HorizontalSpace); @@ -7809,13 +7809,13 @@ void Sema::CodeCompletePreprocessorDirective(bool InConditional) { Builder.AddPlaceholderChunk("header"); Builder.AddTextChunk(">"); Results.AddResult(Builder.TakeString()); - + // #define Builder.AddTypedTextChunk("define"); Builder.AddChunk(CodeCompletionString::CK_HorizontalSpace); Builder.AddPlaceholderChunk("macro"); Results.AddResult(Builder.TakeString()); - + // #define () Builder.AddTypedTextChunk("define"); Builder.AddChunk(CodeCompletionString::CK_HorizontalSpace); @@ -7824,7 +7824,7 @@ void Sema::CodeCompletePreprocessorDirective(bool InConditional) { Builder.AddPlaceholderChunk("args"); Builder.AddChunk(CodeCompletionString::CK_RightParen); Results.AddResult(Builder.TakeString()); - + // #undef Builder.AddTypedTextChunk("undef"); Builder.AddChunk(CodeCompletionString::CK_HorizontalSpace); @@ -7836,7 +7836,7 @@ void Sema::CodeCompletePreprocessorDirective(bool InConditional) { Builder.AddChunk(CodeCompletionString::CK_HorizontalSpace); Builder.AddPlaceholderChunk("number"); Results.AddResult(Builder.TakeString()); - + // #line "filename" Builder.AddTypedTextChunk("line"); Builder.AddChunk(CodeCompletionString::CK_HorizontalSpace); @@ -7846,7 +7846,7 @@ void Sema::CodeCompletePreprocessorDirective(bool InConditional) { Builder.AddPlaceholderChunk("filename"); Builder.AddTextChunk("\""); Results.AddResult(Builder.TakeString()); - + // #error Builder.AddTypedTextChunk("error"); Builder.AddChunk(CodeCompletionString::CK_HorizontalSpace); @@ -7867,7 +7867,7 @@ void Sema::CodeCompletePreprocessorDirective(bool InConditional) { Builder.AddPlaceholderChunk("header"); Builder.AddTextChunk("\""); Results.AddResult(Builder.TakeString()); - + // #import
Builder.AddTypedTextChunk("import"); Builder.AddChunk(CodeCompletionString::CK_HorizontalSpace); @@ -7876,7 +7876,7 @@ void Sema::CodeCompletePreprocessorDirective(bool InConditional) { Builder.AddTextChunk(">"); Results.AddResult(Builder.TakeString()); } - + // #include_next "header" Builder.AddTypedTextChunk("include_next"); Builder.AddChunk(CodeCompletionString::CK_HorizontalSpace); @@ -7884,7 +7884,7 @@ void Sema::CodeCompletePreprocessorDirective(bool InConditional) { Builder.AddPlaceholderChunk("header"); Builder.AddTextChunk("\""); Results.AddResult(Builder.TakeString()); - + // #include_next
Builder.AddTypedTextChunk("include_next"); Builder.AddChunk(CodeCompletionString::CK_HorizontalSpace); @@ -7912,7 +7912,7 @@ void Sema::CodeCompletePreprocessorDirective(bool InConditional) { void Sema::CodeCompleteInPreprocessorConditionalExclusion(Scope *S) { CodeCompleteOrdinaryName(S, - S->getFnParent()? Sema::PCC_RecoveryInFunction + S->getFnParent()? Sema::PCC_RecoveryInFunction : Sema::PCC_Namespace); } @@ -7922,11 +7922,11 @@ void Sema::CodeCompletePreprocessorMacroName(bool IsDefinition) { IsDefinition? CodeCompletionContext::CCC_MacroName : CodeCompletionContext::CCC_MacroNameUse); if (!IsDefinition && (!CodeCompleter || CodeCompleter->includeMacros())) { - // Add just the names of macros, not their arguments. + // Add just the names of macros, not their arguments. CodeCompletionBuilder Builder(Results.getAllocator(), Results.getCodeCompletionTUInfo()); Results.EnterNewScope(); - for (Preprocessor::macro_iterator M = PP.macro_begin(), + for (Preprocessor::macro_iterator M = PP.macro_begin(), MEnd = PP.macro_end(); M != MEnd; ++M) { Builder.AddTypedTextChunk(Builder.getAllocator().CopyString( @@ -7939,19 +7939,19 @@ void Sema::CodeCompletePreprocessorMacroName(bool IsDefinition) { } else if (IsDefinition) { // FIXME: Can we detect when the user just wrote an include guard above? } - + HandleCodeCompleteResults(this, CodeCompleter, Results.getCompletionContext(), - Results.data(), Results.size()); + Results.data(), Results.size()); } void Sema::CodeCompletePreprocessorExpression() { ResultBuilder Results(*this, CodeCompleter->getAllocator(), CodeCompleter->getCodeCompletionTUInfo(), CodeCompletionContext::CCC_PreprocessorExpression); - + if (!CodeCompleter || CodeCompleter->includeMacros()) AddMacroResults(PP, Results, true); - + // defined () Results.EnterNewScope(); CodeCompletionBuilder Builder(Results.getAllocator(), @@ -7974,7 +7974,7 @@ void Sema::CodeCompletePreprocessorMacroArgument(Scope *S, unsigned Argument) { // FIXME: In the future, we could provide "overload" results, much like we // do for function calls. - + // Now just ignore this. There will be another code-completion callback // for the expanded tokens. } @@ -8007,17 +8007,17 @@ void Sema::GatherGlobalCodeCompletions(CodeCompletionAllocator &Allocator, ResultBuilder Builder(*this, Allocator, CCTUInfo, CodeCompletionContext::CCC_Recovery); if (!CodeCompleter || CodeCompleter->includeGlobals()) { - CodeCompletionDeclConsumer Consumer(Builder, + CodeCompletionDeclConsumer Consumer(Builder, Context.getTranslationUnitDecl()); LookupVisibleDecls(Context.getTranslationUnitDecl(), LookupAnyName, Consumer, !CodeCompleter || CodeCompleter->loadExternal()); } - + if (!CodeCompleter || CodeCompleter->includeMacros()) AddMacroResults(PP, Builder, true); - + Results.clear(); - Results.insert(Results.end(), + Results.insert(Results.end(), Builder.data(), Builder.data() + Builder.size()); } -- 2.7.4