Index: include/clang/Lex/Token.h =================================================================== --- include/clang/Lex/Token.h +++ include/clang/Lex/Token.h @@ -183,6 +183,19 @@ PtrData = const_cast(D); } + /// getCompletionStem - For a code_completion token that + /// has a raw identifier as data, return the data pointer + StringRef getCompletionStem() const { + assert(is(tok::code_completion)); + if (PtrData) + return StringRef(reinterpret_cast(PtrData), getLength()); + return StringRef(); + } + void setCompletionStem(const char *Ptr) { + assert(is(tok::code_completion)); + PtrData = const_cast(Ptr); + } + /// getRawIdentifier - For a raw identifier token (i.e., an identifier /// lexed in raw mode), returns a reference to the text substring in the /// buffer if known. Index: include/clang/Sema/CodeCompleteConsumer.h =================================================================== --- include/clang/Sema/CodeCompleteConsumer.h +++ include/clang/Sema/CodeCompleteConsumer.h @@ -147,6 +147,7 @@ class NamedDecl; class NestedNameSpecifier; class Sema; +class Token; /// \brief The context in which code completion occurred, so that the /// code-completion consumer can process the results accordingly. @@ -929,6 +930,13 @@ CodeCompletionResult *Results, unsigned NumResults) { } + /// \name Code-completion callbacks + //@{ + /// \brief Process the finalized code-completion results. + virtual void ProcessCodeCompleteResults(Token &Tok, Sema &S, + CodeCompletionContext Context, + CodeCompletionResult *Results, + unsigned NumResults) { } /// \param S the semantic-analyzer object for which code-completion is being /// done. /// @@ -970,6 +978,11 @@ CodeCompletionResult *Results, unsigned NumResults) override; + /// \brief Prints the finalized code-completion results. + void ProcessCodeCompleteResults(Token &Tok, Sema &S, CodeCompletionContext Context, + CodeCompletionResult *Results, + unsigned NumResults) override; + void ProcessOverloadCandidates(Sema &S, unsigned CurrentArg, OverloadCandidate *Candidates, unsigned NumCandidates) override; Index: include/clang/Sema/Sema.h =================================================================== --- include/clang/Sema/Sema.h +++ include/clang/Sema/Sema.h @@ -8453,104 +8453,104 @@ PCC_LocalDeclarationSpecifiers }; - void CodeCompleteModuleImport(SourceLocation ImportLoc, ModuleIdPath Path); - void CodeCompleteOrdinaryName(Scope *S, + void CodeCompleteModuleImport(Token Tok, SourceLocation ImportLoc, ModuleIdPath Path); + void CodeCompleteOrdinaryName(Token Tok, Scope *S, ParserCompletionContext CompletionContext); - void CodeCompleteDeclSpec(Scope *S, DeclSpec &DS, + void CodeCompleteDeclSpec(Token Tok, Scope *S, DeclSpec &DS, bool AllowNonIdentifiers, bool AllowNestedNameSpecifiers); struct CodeCompleteExpressionData; - void CodeCompleteExpression(Scope *S, + void CodeCompleteExpression(Token Tok, Scope *S, const CodeCompleteExpressionData &Data); - void CodeCompleteMemberReferenceExpr(Scope *S, Expr *Base, + void CodeCompleteMemberReferenceExpr(Token Tok, Scope *S, Expr *Base, SourceLocation OpLoc, bool IsArrow); - void CodeCompletePostfixExpression(Scope *S, ExprResult LHS); - void CodeCompleteTag(Scope *S, unsigned TagSpec); - void CodeCompleteTypeQualifiers(DeclSpec &DS); - void CodeCompleteCase(Scope *S); - void CodeCompleteCall(Scope *S, Expr *Fn, ArrayRef Args); - void CodeCompleteConstructor(Scope *S, QualType Type, SourceLocation Loc, + void CodeCompletePostfixExpression(Token Tok, Scope *S, ExprResult LHS); + void CodeCompleteTag(Token Tok, Scope *S, unsigned TagSpec); + void CodeCompleteTypeQualifiers(Token Tok, DeclSpec &DS); + void CodeCompleteCase(Token Tok, Scope *S); + void CodeCompleteCall(Token Tok, Scope *S, Expr *Fn, ArrayRef Args); + void CodeCompleteConstructor(Token Tok, Scope *S, QualType Type, SourceLocation Loc, ArrayRef Args); - void CodeCompleteInitializer(Scope *S, Decl *D); - void CodeCompleteReturn(Scope *S); - void CodeCompleteAfterIf(Scope *S); - void CodeCompleteAssignmentRHS(Scope *S, Expr *LHS); + void CodeCompleteInitializer(Token Tok, Scope *S, Decl *D); + void CodeCompleteReturn(Token Tok, Scope *S); + void CodeCompleteAfterIf(Token Tok, Scope *S); + void CodeCompleteAssignmentRHS(Token Tok, Scope *S, Expr *LHS); - void CodeCompleteQualifiedId(Scope *S, CXXScopeSpec &SS, + void CodeCompleteQualifiedId(Token Tok, Scope *S, CXXScopeSpec &SS, bool EnteringContext); - void CodeCompleteUsing(Scope *S); - void CodeCompleteUsingDirective(Scope *S); - void CodeCompleteNamespaceDecl(Scope *S); - void CodeCompleteNamespaceAliasDecl(Scope *S); - void CodeCompleteOperatorName(Scope *S); - void CodeCompleteConstructorInitializer( + void CodeCompleteUsing(Token Tok, Scope *S); + void CodeCompleteUsingDirective(Token Tok, Scope *S); + void CodeCompleteNamespaceDecl(Token Tok, Scope *S); + void CodeCompleteNamespaceAliasDecl(Token Tok, Scope *S); + void CodeCompleteOperatorName(Token Tok, Scope *S); + void CodeCompleteConstructorInitializer(Token Tok, Decl *Constructor, ArrayRef Initializers); - void CodeCompleteLambdaIntroducer(Scope *S, LambdaIntroducer &Intro, + void CodeCompleteLambdaIntroducer(Token Tok, Scope *S, LambdaIntroducer &Intro, bool AfterAmpersand); - void CodeCompleteObjCAtDirective(Scope *S); - void CodeCompleteObjCAtVisibility(Scope *S); - void CodeCompleteObjCAtStatement(Scope *S); - void CodeCompleteObjCAtExpression(Scope *S); - void CodeCompleteObjCPropertyFlags(Scope *S, ObjCDeclSpec &ODS); - void CodeCompleteObjCPropertyGetter(Scope *S); - void CodeCompleteObjCPropertySetter(Scope *S); - void CodeCompleteObjCPassingType(Scope *S, ObjCDeclSpec &DS, + void CodeCompleteObjCAtDirective(Token Tok, Scope *S); + void CodeCompleteObjCAtVisibility(Token Tok, Scope *S); + void CodeCompleteObjCAtStatement(Token Tok, Scope *S); + void CodeCompleteObjCAtExpression(Token Tok, Scope *S); + void CodeCompleteObjCPropertyFlags(Token Tok, Scope *S, ObjCDeclSpec &ODS); + void CodeCompleteObjCPropertyGetter(Token Tok, Scope *S); + void CodeCompleteObjCPropertySetter(Token Tok, Scope *S); + void CodeCompleteObjCPassingType(Token Tok, Scope *S, ObjCDeclSpec &DS, bool IsParameter); - void CodeCompleteObjCMessageReceiver(Scope *S); - void CodeCompleteObjCSuperMessage(Scope *S, SourceLocation SuperLoc, + void CodeCompleteObjCMessageReceiver(Token Tok, Scope *S); + void CodeCompleteObjCSuperMessage(Token Tok, Scope *S, SourceLocation SuperLoc, ArrayRef SelIdents, bool AtArgumentExpression); - void CodeCompleteObjCClassMessage(Scope *S, ParsedType Receiver, + void CodeCompleteObjCClassMessage(Token Tok, Scope *S, ParsedType Receiver, ArrayRef SelIdents, bool AtArgumentExpression, bool IsSuper = false); - void CodeCompleteObjCInstanceMessage(Scope *S, Expr *Receiver, + void CodeCompleteObjCInstanceMessage(Token Tok, Scope *S, Expr *Receiver, ArrayRef SelIdents, bool AtArgumentExpression, ObjCInterfaceDecl *Super = nullptr); - void CodeCompleteObjCForCollection(Scope *S, + void CodeCompleteObjCForCollection(Token Tok, Scope *S, DeclGroupPtrTy IterationVar); - void CodeCompleteObjCSelector(Scope *S, + void CodeCompleteObjCSelector(Token Tok, Scope *S, ArrayRef SelIdents); - void CodeCompleteObjCProtocolReferences(IdentifierLocPair *Protocols, + void CodeCompleteObjCProtocolReferences(Token Tok, IdentifierLocPair *Protocols, unsigned NumProtocols); - void CodeCompleteObjCProtocolDecl(Scope *S); - void CodeCompleteObjCInterfaceDecl(Scope *S); - void CodeCompleteObjCSuperclass(Scope *S, + void CodeCompleteObjCProtocolDecl(Token Tok, Scope *S); + void CodeCompleteObjCInterfaceDecl(Token Tok, Scope *S); + void CodeCompleteObjCSuperclass(Token Tok, Scope *S, IdentifierInfo *ClassName, SourceLocation ClassNameLoc); - void CodeCompleteObjCImplementationDecl(Scope *S); - void CodeCompleteObjCInterfaceCategory(Scope *S, + void CodeCompleteObjCImplementationDecl(Token Tok, Scope *S); + void CodeCompleteObjCInterfaceCategory(Token Tok, Scope *S, IdentifierInfo *ClassName, SourceLocation ClassNameLoc); - void CodeCompleteObjCImplementationCategory(Scope *S, + void CodeCompleteObjCImplementationCategory(Token Tok, Scope *S, IdentifierInfo *ClassName, SourceLocation ClassNameLoc); - void CodeCompleteObjCPropertyDefinition(Scope *S); - void CodeCompleteObjCPropertySynthesizeIvar(Scope *S, + void CodeCompleteObjCPropertyDefinition(Token Tok, Scope *S); + void CodeCompleteObjCPropertySynthesizeIvar(Token Tok, Scope *S, IdentifierInfo *PropertyName); - void CodeCompleteObjCMethodDecl(Scope *S, + void CodeCompleteObjCMethodDecl(Token Tok, Scope *S, bool IsInstanceMethod, ParsedType ReturnType); - void CodeCompleteObjCMethodDeclSelector(Scope *S, + void CodeCompleteObjCMethodDeclSelector(Token Tok, Scope *S, bool IsInstanceMethod, bool AtParameterName, ParsedType ReturnType, ArrayRef SelIdents); - void CodeCompletePreprocessorDirective(bool InConditional); - void CodeCompleteInPreprocessorConditionalExclusion(Scope *S); - void CodeCompletePreprocessorMacroName(bool IsDefinition); - void CodeCompletePreprocessorExpression(); - void CodeCompletePreprocessorMacroArgument(Scope *S, + void CodeCompletePreprocessorDirective(Token Tok, bool InConditional); + void CodeCompleteInPreprocessorConditionalExclusion(Token Tok, Scope *S); + void CodeCompletePreprocessorMacroName(Token Tok, bool IsDefinition); + void CodeCompletePreprocessorExpression(Token Tok); + void CodeCompletePreprocessorMacroArgument(Token Tok, Scope *S, IdentifierInfo *Macro, MacroInfo *MacroInfo, unsigned Argument); - void CodeCompleteNaturalLanguage(); + void CodeCompleteNaturalLanguage(Token Tok); void GatherGlobalCodeCompletions(CodeCompletionAllocator &Allocator, CodeCompletionTUInfo &CCTUInfo, SmallVectorImpl &Results); Index: lib/Lex/Lexer.cpp =================================================================== --- lib/Lex/Lexer.cpp +++ lib/Lex/Lexer.cpp @@ -1487,6 +1487,16 @@ --CurPtr; // Back up over the skipped character. + if (isCodeCompletionPoint(CurPtr)) { + // Return the code-completion token. + const char *IdStart = BufferPtr; + Result.startToken(); + FormTokenWithChars(Result, CurPtr, tok::code_completion); + Result.setCompletionStem(IdStart); + cutOffLexing(); + return true; + } + // Fast path, no $,\,? in identifier found. '\' might be an escaped newline // or UCN, and ? might be a trigraph for '\', an escaped newline or UCN. // Index: lib/Parse/ParseDecl.cpp =================================================================== --- lib/Parse/ParseDecl.cpp +++ lib/Parse/ParseDecl.cpp @@ -1944,7 +1944,7 @@ } if (Tok.is(tok::code_completion)) { - Actions.CodeCompleteInitializer(getCurScope(), ThisDecl); + Actions.CodeCompleteInitializer(Tok, getCurScope(), ThisDecl); Actions.FinalizeDeclaration(ThisDecl); cutOffParsing(); return nullptr; @@ -1994,7 +1994,7 @@ } if (ParseExpressionList(Exprs, CommaLocs, [&] { - Actions.CodeCompleteConstructor(getCurScope(), + Actions.CodeCompleteConstructor(Tok, getCurScope(), cast(ThisDecl)->getType()->getCanonicalTypeInternal(), ThisDecl->getLocation(), Exprs); })) { @@ -2625,7 +2625,7 @@ = DSContext == DSC_top_level || (DSContext == DSC_class && DS.isFriendSpecified()); - Actions.CodeCompleteDeclSpec(getCurScope(), DS, + Actions.CodeCompleteDeclSpec(Tok, getCurScope(), DS, AllowNonIdentifiers, AllowNestedNameSpecifiers); return cutOffParsing(); @@ -2641,7 +2641,7 @@ else if (CurParsedObjCImpl) CCC = Sema::PCC_ObjCImplementation; - Actions.CodeCompleteOrdinaryName(getCurScope(), CCC); + Actions.CodeCompleteOrdinaryName(Tok, getCurScope(), CCC); return cutOffParsing(); } @@ -3590,7 +3590,7 @@ // Parse the tag portion of this. if (Tok.is(tok::code_completion)) { // Code completion for an enum name. - Actions.CodeCompleteTag(getCurScope(), DeclSpec::TST_enum); + Actions.CodeCompleteTag(Tok, getCurScope(), DeclSpec::TST_enum); return cutOffParsing(); } @@ -4542,7 +4542,7 @@ switch (Tok.getKind()) { case tok::code_completion: - Actions.CodeCompleteTypeQualifiers(DS); + Actions.CodeCompleteTypeQualifiers(Tok, DS); return cutOffParsing(); case tok::kw_const: Index: lib/Parse/ParseDeclCXX.cpp =================================================================== --- lib/Parse/ParseDeclCXX.cpp +++ lib/Parse/ParseDeclCXX.cpp @@ -62,7 +62,7 @@ ObjCDeclContextSwitch ObjCDC(*this); if (Tok.is(tok::code_completion)) { - Actions.CodeCompleteNamespaceDecl(getCurScope()); + Actions.CodeCompleteNamespaceDecl(Tok, getCurScope()); cutOffParsing(); return nullptr; } @@ -254,7 +254,7 @@ ConsumeToken(); // eat the '='. if (Tok.is(tok::code_completion)) { - Actions.CodeCompleteNamespaceAliasDecl(getCurScope()); + Actions.CodeCompleteNamespaceAliasDecl(Tok, getCurScope()); cutOffParsing(); return nullptr; } @@ -383,7 +383,7 @@ SourceLocation UsingLoc = ConsumeToken(); if (Tok.is(tok::code_completion)) { - Actions.CodeCompleteUsing(getCurScope()); + Actions.CodeCompleteUsing(Tok, getCurScope()); cutOffParsing(); return nullptr; } @@ -429,7 +429,7 @@ SourceLocation NamespcLoc = ConsumeToken(); if (Tok.is(tok::code_completion)) { - Actions.CodeCompleteUsingDirective(getCurScope()); + Actions.CodeCompleteUsingDirective(Tok, getCurScope()); cutOffParsing(); return nullptr; } @@ -1201,7 +1201,7 @@ if (Tok.is(tok::code_completion)) { // Code completion for a struct, class, or union name. - Actions.CodeCompleteTag(getCurScope(), TagType); + Actions.CodeCompleteTag(Tok, getCurScope(), TagType); return cutOffParsing(); } @@ -2966,7 +2966,7 @@ do { if (Tok.is(tok::code_completion)) { - Actions.CodeCompleteConstructorInitializer(ConstructorDecl, + Actions.CodeCompleteConstructorInitializer(Tok, ConstructorDecl, MemInitializers); return cutOffParsing(); } else { Index: lib/Parse/ParseExpr.cpp =================================================================== --- lib/Parse/ParseExpr.cpp +++ lib/Parse/ParseExpr.cpp @@ -156,7 +156,7 @@ /// \brief Parse an expr that doesn't include (top-level) commas. ExprResult Parser::ParseAssignmentExpression(TypeCastState isTypeCast) { if (Tok.is(tok::code_completion)) { - Actions.CodeCompleteOrdinaryName(getCurScope(), Sema::PCC_Expression); + Actions.CodeCompleteOrdinaryName(Tok, getCurScope(), Sema::PCC_Expression); cutOffParsing(); return ExprError(); } @@ -321,7 +321,7 @@ // Code completion for the right-hand side of an assignment expression // goes through a special hook that takes the left-hand side into account. if (Tok.is(tok::code_completion) && NextTokPrec == prec::Assignment) { - Actions.CodeCompleteAssignmentRHS(getCurScope(), LHS.get()); + Actions.CodeCompleteAssignmentRHS(Tok, getCurScope(), LHS.get()); cutOffParsing(); return ExprError(); } @@ -1262,7 +1262,7 @@ Res = ParseBlockLiteralExpression(); break; case tok::code_completion: { - Actions.CodeCompleteOrdinaryName(getCurScope(), Sema::PCC_Expression); + Actions.CodeCompleteOrdinaryName(Tok, getCurScope(), Sema::PCC_Expression); cutOffParsing(); return ExprError(); } @@ -1327,7 +1327,7 @@ if (InMessageExpression) return LHS; - Actions.CodeCompletePostfixExpression(getCurScope(), LHS); + Actions.CodeCompletePostfixExpression(Tok, getCurScope(), LHS); cutOffParsing(); return ExprError(); @@ -1447,7 +1447,7 @@ CommaLocsTy CommaLocs; if (Tok.is(tok::code_completion)) { - Actions.CodeCompleteCall(getCurScope(), LHS.get(), None); + Actions.CodeCompleteCall(Tok, getCurScope(), LHS.get(), None); cutOffParsing(); return ExprError(); } @@ -1455,7 +1455,7 @@ if (OpKind == tok::l_paren || !LHS.isInvalid()) { if (Tok.isNot(tok::r_paren)) { if (ParseExpressionList(ArgExprs, CommaLocs, [&] { - Actions.CodeCompleteCall(getCurScope(), LHS.get(), ArgExprs); + Actions.CodeCompleteCall(Tok, getCurScope(), LHS.get(), ArgExprs); })) { (void)Actions.CorrectDelayedTyposInExpr(LHS); LHS = ExprError(); @@ -1518,7 +1518,7 @@ if (Tok.is(tok::code_completion)) { // Code completion for a member access expression. - Actions.CodeCompleteMemberReferenceExpr(getCurScope(), LHS.get(), + Actions.CodeCompleteMemberReferenceExpr(Tok, getCurScope(), LHS.get(), OpLoc, OpKind == tok::arrow); cutOffParsing(); @@ -2070,7 +2070,7 @@ CastTy = ParsedType(); if (Tok.is(tok::code_completion)) { - Actions.CodeCompleteOrdinaryName(getCurScope(), + Actions.CodeCompleteOrdinaryName(Tok, getCurScope(), ExprType >= CompoundLiteral? Sema::PCC_ParenthesizedExpression : Sema::PCC_Expression); cutOffParsing(); @@ -2517,7 +2517,7 @@ if (Completer) Completer(); else - Actions.CodeCompleteOrdinaryName(getCurScope(), Sema::PCC_Expression); + Actions.CodeCompleteOrdinaryName(Tok, getCurScope(), Sema::PCC_Expression); cutOffParsing(); return true; } @@ -2588,7 +2588,7 @@ /// \endverbatim void Parser::ParseBlockId(SourceLocation CaretLoc) { if (Tok.is(tok::code_completion)) { - Actions.CodeCompleteOrdinaryName(getCurScope(), Sema::PCC_Type); + Actions.CodeCompleteOrdinaryName(Tok, getCurScope(), Sema::PCC_Type); return cutOffParsing(); } Index: lib/Parse/ParseExprCXX.cpp =================================================================== --- lib/Parse/ParseExprCXX.cpp +++ lib/Parse/ParseExprCXX.cpp @@ -285,7 +285,7 @@ if (Tok.is(tok::code_completion)) { // Code completion for a nested-name-specifier, where the code // code completion token follows the '::'. - Actions.CodeCompleteQualifiedId(getCurScope(), SS, EnteringContext); + Actions.CodeCompleteQualifiedId(Tok, getCurScope(), SS, EnteringContext); // Include code completion token into the range of the scope otherwise // when we try to annotate the scope tokens the dangling code completion // token will cause assertion in @@ -810,7 +810,7 @@ if (Tok.is(tok::code_completion) && !(getLangOpts().ObjC1 && Intro.Default == LCD_None && !Intro.Captures.empty())) { - Actions.CodeCompleteLambdaIntroducer(getCurScope(), Intro, + Actions.CodeCompleteLambdaIntroducer(Tok, getCurScope(), Intro, /*AfterAmpersand=*/false); cutOffParsing(); break; @@ -825,9 +825,9 @@ // If we're in Objective-C++ and we have a bare '[', then this is more // likely to be a message receiver. if (getLangOpts().ObjC1 && first) - Actions.CodeCompleteObjCMessageReceiver(getCurScope()); + Actions.CodeCompleteObjCMessageReceiver(Tok, getCurScope()); else - Actions.CodeCompleteLambdaIntroducer(getCurScope(), Intro, + Actions.CodeCompleteLambdaIntroducer(Tok, getCurScope(), Intro, /*AfterAmpersand=*/false); cutOffParsing(); break; @@ -851,7 +851,7 @@ ConsumeToken(); if (Tok.is(tok::code_completion)) { - Actions.CodeCompleteLambdaIntroducer(getCurScope(), Intro, + Actions.CodeCompleteLambdaIntroducer(Tok, getCurScope(), Intro, /*AfterAmpersand=*/true); cutOffParsing(); break; @@ -1598,7 +1598,7 @@ if (Tok.isNot(tok::r_paren)) { if (ParseExpressionList(Exprs, CommaLocs, [&] { - Actions.CodeCompleteConstructor(getCurScope(), + Actions.CodeCompleteConstructor(Tok, getCurScope(), TypeRep.get()->getCanonicalTypeInternal(), DS.getLocEnd(), Exprs); })) { @@ -1650,7 +1650,7 @@ SourceLocation Loc, bool ConvertToBoolean) { if (Tok.is(tok::code_completion)) { - Actions.CodeCompleteOrdinaryName(getCurScope(), Sema::PCC_Condition); + Actions.CodeCompleteOrdinaryName(Tok, getCurScope(), Sema::PCC_Condition); cutOffParsing(); return true; } @@ -2206,7 +2206,7 @@ case tok::code_completion: { // Code completion for the operator name. - Actions.CodeCompleteOperatorName(getCurScope()); + Actions.CodeCompleteOperatorName(Tok, getCurScope()); cutOffParsing(); // Don't try to parse any further. return true; @@ -2683,7 +2683,7 @@ if (ParseExpressionList(ConstructorArgs, CommaLocs, [&] { ParsedType TypeRep = Actions.ActOnTypeName(getCurScope(), DeclaratorInfo).get(); - Actions.CodeCompleteConstructor(getCurScope(), + Actions.CodeCompleteConstructor(Tok, getCurScope(), TypeRep.get()->getCanonicalTypeInternal(), DeclaratorInfo.getLocEnd(), ConstructorArgs); Index: lib/Parse/ParseObjc.cpp =================================================================== --- lib/Parse/ParseObjc.cpp +++ lib/Parse/ParseObjc.cpp @@ -47,7 +47,7 @@ SourceLocation AtLoc = ConsumeToken(); // the "@" if (Tok.is(tok::code_completion)) { - Actions.CodeCompleteObjCAtDirective(getCurScope()); + Actions.CodeCompleteObjCAtDirective(Tok, getCurScope()); cutOffParsing(); return DeclGroupPtrTy(); } @@ -185,7 +185,7 @@ // Code completion after '@interface'. if (Tok.is(tok::code_completion)) { - Actions.CodeCompleteObjCInterfaceDecl(getCurScope()); + Actions.CodeCompleteObjCInterfaceDecl(Tok, getCurScope()); cutOffParsing(); return nullptr; } @@ -210,7 +210,7 @@ SourceLocation categoryLoc; IdentifierInfo *categoryId = nullptr; if (Tok.is(tok::code_completion)) { - Actions.CodeCompleteObjCInterfaceCategory(getCurScope(), nameId, nameLoc); + Actions.CodeCompleteObjCInterfaceCategory(Tok, getCurScope(), nameId, nameLoc); cutOffParsing(); return nullptr; } @@ -268,7 +268,7 @@ // Code completion of superclass names. if (Tok.is(tok::code_completion)) { - Actions.CodeCompleteObjCSuperclass(getCurScope(), nameId, nameLoc); + Actions.CodeCompleteObjCSuperclass(Tok, getCurScope(), nameId, nameLoc); cutOffParsing(); return nullptr; } @@ -363,7 +363,7 @@ // Code completion within an Objective-C interface. if (Tok.is(tok::code_completion)) { - Actions.CodeCompleteOrdinaryName(getCurScope(), + Actions.CodeCompleteOrdinaryName(Tok, getCurScope(), CurParsedObjCImpl? Sema::PCC_ObjCImplementation : Sema::PCC_ObjCInterface); return cutOffParsing(); @@ -384,7 +384,7 @@ // Otherwise, we have an @ directive, eat the @. SourceLocation AtLoc = ConsumeToken(); // the "@" if (Tok.is(tok::code_completion)) { - Actions.CodeCompleteObjCAtDirective(getCurScope()); + Actions.CodeCompleteObjCAtDirective(Tok, getCurScope()); return cutOffParsing(); } @@ -492,7 +492,7 @@ // We break out of the big loop in two cases: when we see @end or when we see // EOF. In the former case, eat the @end. In the later case, emit an error. if (Tok.is(tok::code_completion)) { - Actions.CodeCompleteObjCAtDirective(getCurScope()); + Actions.CodeCompleteObjCAtDirective(Tok, getCurScope()); return cutOffParsing(); } else if (Tok.isObjCAtKeyword(tok::objc_end)) { ConsumeToken(); // the "end" identifier @@ -537,7 +537,7 @@ while (1) { if (Tok.is(tok::code_completion)) { - Actions.CodeCompleteObjCPropertyFlags(getCurScope(), DS); + Actions.CodeCompleteObjCPropertyFlags(Tok, getCurScope(), DS); return cutOffParsing(); } const IdentifierInfo *II = Tok.getIdentifierInfo(); @@ -584,9 +584,9 @@ if (Tok.is(tok::code_completion)) { if (IsSetter) - Actions.CodeCompleteObjCPropertySetter(getCurScope()); + Actions.CodeCompleteObjCPropertySetter(Tok, getCurScope()); else - Actions.CodeCompleteObjCPropertyGetter(getCurScope()); + Actions.CodeCompleteObjCPropertyGetter(Tok, getCurScope()); return cutOffParsing(); } @@ -786,7 +786,7 @@ while (1) { if (Tok.is(tok::code_completion)) { - Actions.CodeCompleteObjCPassingType(getCurScope(), DS, + Actions.CodeCompleteObjCPassingType(Tok, getCurScope(), DS, Context == Declarator::ObjCParameterContext); return cutOffParsing(); } @@ -958,7 +958,7 @@ ParsingDeclRAIIObject PD(*this, ParsingDeclRAIIObject::NoParent); if (Tok.is(tok::code_completion)) { - Actions.CodeCompleteObjCMethodDecl(getCurScope(), mType == tok::minus, + Actions.CodeCompleteObjCMethodDecl(Tok, getCurScope(), mType == tok::minus, /*ReturnType=*/ ParsedType()); cutOffParsing(); return nullptr; @@ -977,7 +977,7 @@ MaybeParseGNUAttributes(methodAttrs); if (Tok.is(tok::code_completion)) { - Actions.CodeCompleteObjCMethodDecl(getCurScope(), mType == tok::minus, + Actions.CodeCompleteObjCMethodDecl(Tok, getCurScope(), mType == tok::minus, ReturnType); cutOffParsing(); return nullptr; @@ -1046,7 +1046,7 @@ // Code completion for the next piece of the selector. if (Tok.is(tok::code_completion)) { KeyIdents.push_back(SelIdent); - Actions.CodeCompleteObjCMethodDeclSelector(getCurScope(), + Actions.CodeCompleteObjCMethodDeclSelector(Tok, getCurScope(), mType == tok::minus, /*AtParameterName=*/true, ReturnType, KeyIdents); @@ -1073,7 +1073,7 @@ // Code completion for the next piece of the selector. if (Tok.is(tok::code_completion)) { - Actions.CodeCompleteObjCMethodDeclSelector(getCurScope(), + Actions.CodeCompleteObjCMethodDeclSelector(Tok, getCurScope(), mType == tok::minus, /*AtParameterName=*/false, ReturnType, KeyIdents); @@ -1161,7 +1161,7 @@ while (1) { if (Tok.is(tok::code_completion)) { - Actions.CodeCompleteObjCProtocolReferences(ProtocolIdents.data(), + Actions.CodeCompleteObjCProtocolReferences(Tok, ProtocolIdents.data(), ProtocolIdents.size()); cutOffParsing(); return true; @@ -1270,7 +1270,7 @@ // Set the default visibility to private. if (TryConsumeToken(tok::at)) { // parse objc-visibility-spec if (Tok.is(tok::code_completion)) { - Actions.CodeCompleteObjCAtVisibility(getCurScope()); + Actions.CodeCompleteObjCAtVisibility(Tok, getCurScope()); return cutOffParsing(); } @@ -1300,7 +1300,7 @@ } if (Tok.is(tok::code_completion)) { - Actions.CodeCompleteOrdinaryName(getCurScope(), + Actions.CodeCompleteOrdinaryName(Tok, getCurScope(), Sema::PCC_ObjCInstanceVariableList); return cutOffParsing(); } @@ -1358,7 +1358,7 @@ ConsumeToken(); // the "protocol" identifier if (Tok.is(tok::code_completion)) { - Actions.CodeCompleteObjCProtocolDecl(getCurScope()); + Actions.CodeCompleteObjCProtocolDecl(Tok, getCurScope()); cutOffParsing(); return DeclGroupPtrTy(); } @@ -1450,7 +1450,7 @@ // Code completion after '@implementation'. if (Tok.is(tok::code_completion)) { - Actions.CodeCompleteObjCImplementationDecl(getCurScope()); + Actions.CodeCompleteObjCImplementationDecl(Tok, getCurScope()); cutOffParsing(); return DeclGroupPtrTy(); } @@ -1474,7 +1474,7 @@ IdentifierInfo *categoryId = nullptr; if (Tok.is(tok::code_completion)) { - Actions.CodeCompleteObjCImplementationCategory(getCurScope(), nameId, nameLoc); + Actions.CodeCompleteObjCImplementationCategory(Tok, getCurScope(), nameId, nameLoc); cutOffParsing(); return DeclGroupPtrTy(); } @@ -1644,7 +1644,7 @@ while (true) { if (Tok.is(tok::code_completion)) { - Actions.CodeCompleteObjCPropertyDefinition(getCurScope()); + Actions.CodeCompleteObjCPropertyDefinition(Tok, getCurScope()); cutOffParsing(); return nullptr; } @@ -1662,7 +1662,7 @@ if (TryConsumeToken(tok::equal)) { // property '=' ivar-name if (Tok.is(tok::code_completion)) { - Actions.CodeCompleteObjCPropertySynthesizeIvar(getCurScope(), propertyId); + Actions.CodeCompleteObjCPropertySynthesizeIvar(Tok, getCurScope(), propertyId); cutOffParsing(); return nullptr; } @@ -1697,7 +1697,7 @@ ConsumeToken(); // consume dynamic while (true) { if (Tok.is(tok::code_completion)) { - Actions.CodeCompleteObjCPropertyDefinition(getCurScope()); + Actions.CodeCompleteObjCPropertyDefinition(Tok, getCurScope()); cutOffParsing(); return nullptr; } @@ -2008,7 +2008,7 @@ StmtResult Parser::ParseObjCAtStatement(SourceLocation AtLoc) { if (Tok.is(tok::code_completion)) { - Actions.CodeCompleteObjCAtStatement(getCurScope()); + Actions.CodeCompleteObjCAtStatement(Tok, getCurScope()); cutOffParsing(); return StmtError(); } @@ -2048,7 +2048,7 @@ ExprResult Parser::ParseObjCAtExpression(SourceLocation AtLoc) { switch (Tok.getKind()) { case tok::code_completion: - Actions.CodeCompleteObjCAtExpression(getCurScope()); + Actions.CodeCompleteObjCAtExpression(Tok, getCurScope()); cutOffParsing(); return ExprError(); @@ -2289,7 +2289,7 @@ SourceLocation LBracLoc = ConsumeBracket(); // consume '[' if (Tok.is(tok::code_completion)) { - Actions.CodeCompleteObjCMessageReceiver(getCurScope()); + Actions.CodeCompleteObjCMessageReceiver(Tok, getCurScope()); cutOffParsing(); return ExprError(); } @@ -2413,13 +2413,13 @@ if (Tok.is(tok::code_completion)) { if (SuperLoc.isValid()) - Actions.CodeCompleteObjCSuperMessage(getCurScope(), SuperLoc, None, + Actions.CodeCompleteObjCSuperMessage(Tok, getCurScope(), SuperLoc, None, false); else if (ReceiverType) - Actions.CodeCompleteObjCClassMessage(getCurScope(), ReceiverType, None, + Actions.CodeCompleteObjCClassMessage(Tok, getCurScope(), ReceiverType, None, false); else - Actions.CodeCompleteObjCInstanceMessage(getCurScope(), ReceiverExpr, + Actions.CodeCompleteObjCInstanceMessage(Tok, getCurScope(), ReceiverExpr, None, false); cutOffParsing(); return ExprError(); @@ -2451,15 +2451,15 @@ if (Tok.is(tok::code_completion)) { if (SuperLoc.isValid()) - Actions.CodeCompleteObjCSuperMessage(getCurScope(), SuperLoc, + Actions.CodeCompleteObjCSuperMessage(Tok, getCurScope(), SuperLoc, KeyIdents, /*AtArgumentEpression=*/true); else if (ReceiverType) - Actions.CodeCompleteObjCClassMessage(getCurScope(), ReceiverType, + Actions.CodeCompleteObjCClassMessage(Tok, getCurScope(), ReceiverType, KeyIdents, /*AtArgumentEpression=*/true); else - Actions.CodeCompleteObjCInstanceMessage(getCurScope(), ReceiverExpr, + Actions.CodeCompleteObjCInstanceMessage(Tok, getCurScope(), ReceiverExpr, KeyIdents, /*AtArgumentEpression=*/true); @@ -2489,15 +2489,15 @@ // Code completion after each argument. if (Tok.is(tok::code_completion)) { if (SuperLoc.isValid()) - Actions.CodeCompleteObjCSuperMessage(getCurScope(), SuperLoc, + Actions.CodeCompleteObjCSuperMessage(Tok, getCurScope(), SuperLoc, KeyIdents, /*AtArgumentEpression=*/false); else if (ReceiverType) - Actions.CodeCompleteObjCClassMessage(getCurScope(), ReceiverType, + Actions.CodeCompleteObjCClassMessage(Tok, getCurScope(), ReceiverType, KeyIdents, /*AtArgumentEpression=*/false); else - Actions.CodeCompleteObjCInstanceMessage(getCurScope(), ReceiverExpr, + Actions.CodeCompleteObjCInstanceMessage(Tok, getCurScope(), ReceiverExpr, KeyIdents, /*AtArgumentEpression=*/false); cutOffParsing(); @@ -2820,7 +2820,7 @@ ConsumeParen(); if (Tok.is(tok::code_completion)) { - Actions.CodeCompleteObjCSelector(getCurScope(), KeyIdents); + Actions.CodeCompleteObjCSelector(Tok, getCurScope(), KeyIdents); cutOffParsing(); return ExprError(); } @@ -2846,7 +2846,7 @@ break; if (Tok.is(tok::code_completion)) { - Actions.CodeCompleteObjCSelector(getCurScope(), KeyIdents); + Actions.CodeCompleteObjCSelector(Tok, getCurScope(), KeyIdents); cutOffParsing(); return ExprError(); } Index: lib/Parse/ParseStmt.cpp =================================================================== --- lib/Parse/ParseStmt.cpp +++ lib/Parse/ParseStmt.cpp @@ -169,7 +169,7 @@ } case tok::code_completion: - Actions.CodeCompleteOrdinaryName(getCurScope(), Sema::PCC_Statement); + Actions.CodeCompleteOrdinaryName(Tok, getCurScope(), Sema::PCC_Statement); cutOffParsing(); return StmtError(); @@ -636,7 +636,7 @@ ColonLoc = SourceLocation(); if (Tok.is(tok::code_completion)) { - Actions.CodeCompleteCase(getCurScope()); + Actions.CodeCompleteCase(Tok, getCurScope()); cutOffParsing(); return StmtError(); } @@ -1159,7 +1159,7 @@ // Pop the 'else' scope if needed. InnerScope.Exit(); } else if (Tok.is(tok::code_completion)) { - Actions.CodeCompleteAfterIf(getCurScope()); + Actions.CodeCompleteAfterIf(Tok, getCurScope()); cutOffParsing(); return StmtError(); } else if (InnerStatementTrailingElseLoc.isValid()) { @@ -1499,7 +1499,7 @@ Decl *SecondVar = nullptr; if (Tok.is(tok::code_completion)) { - Actions.CodeCompleteOrdinaryName(getCurScope(), + Actions.CodeCompleteOrdinaryName(Tok, getCurScope(), C99orCXXorObjC? Sema::PCC_ForInit : Sema::PCC_Expression); cutOffParsing(); @@ -1562,7 +1562,7 @@ ConsumeToken(); // consume 'in' if (Tok.is(tok::code_completion)) { - Actions.CodeCompleteObjCForCollection(getCurScope(), DG); + Actions.CodeCompleteObjCForCollection(Tok, getCurScope(), DG); cutOffParsing(); return StmtError(); } @@ -1590,7 +1590,7 @@ ConsumeToken(); // consume 'in' if (Tok.is(tok::code_completion)) { - Actions.CodeCompleteObjCForCollection(getCurScope(), DeclGroupPtrTy()); + Actions.CodeCompleteObjCForCollection(Tok, getCurScope(), DeclGroupPtrTy()); cutOffParsing(); return StmtError(); } @@ -1795,7 +1795,7 @@ ExprResult R; if (Tok.isNot(tok::semi)) { if (Tok.is(tok::code_completion)) { - Actions.CodeCompleteReturn(getCurScope()); + Actions.CodeCompleteReturn(Tok, getCurScope()); cutOffParsing(); return StmtError(); } Index: lib/Parse/Parser.cpp =================================================================== --- lib/Parse/Parser.cpp +++ lib/Parse/Parser.cpp @@ -678,7 +678,7 @@ SingleDecl = ParseObjCMethodDefinition(); break; case tok::code_completion: - Actions.CodeCompleteOrdinaryName(getCurScope(), + Actions.CodeCompleteOrdinaryName(Tok, getCurScope(), CurParsedObjCImpl? Sema::PCC_ObjCImplementation : Sema::PCC_Namespace); cutOffParsing(); @@ -1712,20 +1712,20 @@ for (Scope *S = getCurScope(); S; S = S->getParent()) { if (S->getFlags() & Scope::FnScope) { - Actions.CodeCompleteOrdinaryName(getCurScope(), + Actions.CodeCompleteOrdinaryName(Tok, getCurScope(), Sema::PCC_RecoveryInFunction); cutOffParsing(); return PrevTokLocation; } if (S->getFlags() & Scope::ClassScope) { - Actions.CodeCompleteOrdinaryName(getCurScope(), Sema::PCC_Class); + Actions.CodeCompleteOrdinaryName(Tok, getCurScope(), Sema::PCC_Class); cutOffParsing(); return PrevTokLocation; } } - Actions.CodeCompleteOrdinaryName(getCurScope(), Sema::PCC_Namespace); + Actions.CodeCompleteOrdinaryName(Tok, getCurScope(), Sema::PCC_Namespace); cutOffParsing(); return PrevTokLocation; } @@ -1733,30 +1733,30 @@ // Code-completion pass-through functions void Parser::CodeCompleteDirective(bool InConditional) { - Actions.CodeCompletePreprocessorDirective(InConditional); + Actions.CodeCompletePreprocessorDirective(Tok, InConditional); } void Parser::CodeCompleteInConditionalExclusion() { - Actions.CodeCompleteInPreprocessorConditionalExclusion(getCurScope()); + Actions.CodeCompleteInPreprocessorConditionalExclusion(Tok, getCurScope()); } void Parser::CodeCompleteMacroName(bool IsDefinition) { - Actions.CodeCompletePreprocessorMacroName(IsDefinition); + Actions.CodeCompletePreprocessorMacroName(Tok, IsDefinition); } void Parser::CodeCompletePreprocessorExpression() { - Actions.CodeCompletePreprocessorExpression(); + Actions.CodeCompletePreprocessorExpression(Tok); } void Parser::CodeCompleteMacroArgument(IdentifierInfo *Macro, MacroInfo *MacroInfo, unsigned ArgumentIndex) { - Actions.CodeCompletePreprocessorMacroArgument(getCurScope(), Macro, MacroInfo, + Actions.CodeCompletePreprocessorMacroArgument(Tok, getCurScope(), Macro, MacroInfo, ArgumentIndex); } void Parser::CodeCompleteNaturalLanguage() { - Actions.CodeCompleteNaturalLanguage(); + Actions.CodeCompleteNaturalLanguage(Tok); } bool Parser::ParseMicrosoftIfExistsCondition(IfExistsCondition& Result) { @@ -1865,7 +1865,7 @@ do { if (!Tok.is(tok::identifier)) { if (Tok.is(tok::code_completion)) { - Actions.CodeCompleteModuleImport(ImportLoc, Path); + Actions.CodeCompleteModuleImport(Tok, ImportLoc, Path); cutOffParsing(); return DeclGroupPtrTy(); } Index: lib/Sema/CodeCompleteConsumer.cpp =================================================================== --- lib/Sema/CodeCompleteConsumer.cpp +++ lib/Sema/CodeCompleteConsumer.cpp @@ -17,6 +17,7 @@ #include "clang/AST/DeclTemplate.h" #include "clang/Sema/Scope.h" #include "clang/Sema/Sema.h" +#include "clang/Lex/Token.h" #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/SmallString.h" #include "llvm/ADT/Twine.h" @@ -431,55 +432,92 @@ CodeCompleteConsumer::~CodeCompleteConsumer() { } -void +void PrintingCodeCompleteConsumer::ProcessCodeCompleteResults(Sema &SemaRef, CodeCompletionContext Context, CodeCompletionResult *Results, - unsigned NumResults) { + unsigned NumResults) { + Token &&Tok = Token(); + ProcessCodeCompleteResults(Tok, SemaRef, Context, Results, NumResults); +} + +void +PrintingCodeCompleteConsumer::ProcessCodeCompleteResults(Token &Tok, Sema &SemaRef, + CodeCompletionContext Context, + CodeCompletionResult *Results, + unsigned NumResults) { std::stable_sort(Results, Results + NumResults); - + + StringRef Filter; + if (Tok.is(tok::code_completion)) { + Filter = Tok.getCompletionStem(); + } // Print the results. for (unsigned I = 0; I != NumResults; ++I) { - OS << "COMPLETION: "; switch (Results[I].Kind) { - case CodeCompletionResult::RK_Declaration: + case CodeCompletionResult::RK_Declaration: + if (!Filter.empty()) { + if (!(*Results[I].Declaration).getIdentifier()) { + break; + } + else { + StringRef CompletionName = (*Results[I].Declaration).getName(); + if (!CompletionName.startswith(Filter)) + break; + } + } + OS << "COMPLETION: "; OS << *Results[I].Declaration; if (Results[I].Hidden) OS << " (Hidden)"; - if (CodeCompletionString *CCS - = Results[I].CreateCodeCompletionString(SemaRef, getAllocator(), - CCTUInfo, - includeBriefComments())) { + if (CodeCompletionString *CCS + = Results[I].CreateCodeCompletionString(SemaRef, getAllocator(), + CCTUInfo, + includeBriefComments())) { OS << " : " << CCS->getAsString(); if (const char *BriefComment = CCS->getBriefComment()) OS << " : " << BriefComment; } - OS << '\n'; break; - - case CodeCompletionResult::RK_Keyword: + + case CodeCompletionResult::RK_Keyword: + if (!Filter.empty()) { + StringRef CompletionName = Results[I].Keyword; + if (!CompletionName.startswith(Filter)) + break; + } + OS << "COMPLETION: "; OS << Results[I].Keyword << '\n'; break; - - case CodeCompletionResult::RK_Macro: { + + case CodeCompletionResult::RK_Macro: + if (!Filter.empty()) { + StringRef CompletionName = Results[I].Macro->getName(); + if (!CompletionName.startswith(Filter)) + break; + } OS << Results[I].Macro->getName(); - if (CodeCompletionString *CCS - = Results[I].CreateCodeCompletionString(SemaRef, getAllocator(), - CCTUInfo, - includeBriefComments())) { + if (CodeCompletionString *CCS + = Results[I].CreateCodeCompletionString(SemaRef, getAllocator(), + CCTUInfo, + includeBriefComments())) { + OS << "COMPLETION: "; OS << " : " << CCS->getAsString(); } OS << '\n'; break; - } - - case CodeCompletionResult::RK_Pattern: { - OS << "Pattern : " - << Results[I].Pattern->getAsString() << '\n'; + + case CodeCompletionResult::RK_Pattern: + if (!Filter.empty()) { + StringRef CompletionName = Results[I].Pattern->getAsString(); + if (!CompletionName.startswith(Filter)) + break; + } + OS << "COMPLETION: "; + OS << "Pattern : "<< Results[I].Pattern->getAsString() << '\n'; break; } - } } } Index: lib/Sema/SemaCodeComplete.cpp =================================================================== --- lib/Sema/SemaCodeComplete.cpp +++ lib/Sema/SemaCodeComplete.cpp @@ -3065,13 +3065,14 @@ Results.ExitScope(); } -static void HandleCodeCompleteResults(Sema *S, +static void HandleCodeCompleteResults(Token Tok, Sema *S, CodeCompleteConsumer *CodeCompleter, CodeCompletionContext Context, CodeCompletionResult *Results, unsigned NumResults) { - if (CodeCompleter) - CodeCompleter->ProcessCodeCompleteResults(*S, Context, Results, NumResults); + if (CodeCompleter) { + CodeCompleter->ProcessCodeCompleteResults(Tok, *S, Context, Results, NumResults); + } } static enum CodeCompletionContext::Kind mapCodeCompletionContext(Sema &S, @@ -3203,7 +3204,7 @@ } } -void Sema::CodeCompleteModuleImport(SourceLocation ImportLoc, +void Sema::CodeCompleteModuleImport(Token Tok, SourceLocation ImportLoc, ModuleIdPath Path) { typedef CodeCompletionResult Result; ResultBuilder Results(*this, CodeCompleter->getAllocator(), @@ -3250,12 +3251,12 @@ } } } - Results.ExitScope(); - HandleCodeCompleteResults(this, CodeCompleter, Results.getCompletionContext(), - Results.data(),Results.size()); + Results.ExitScope(); + HandleCodeCompleteResults(Tok, this, CodeCompleter, Results.getCompletionContext(), + Results.data(), Results.size()); } -void Sema::CodeCompleteOrdinaryName(Scope *S, +void Sema::CodeCompleteOrdinaryName(Token Tok, Scope *S, ParserCompletionContext CompletionContext) { ResultBuilder Results(*this, CodeCompleter->getAllocator(), CodeCompleter->getCodeCompletionTUInfo(), @@ -3337,7 +3338,7 @@ if (CodeCompleter->includeMacros()) AddMacroResults(PP, Results, false); - HandleCodeCompleteResults(this, CodeCompleter, Results.getCompletionContext(), + HandleCodeCompleteResults(Tok, this, CodeCompleter, Results.getCompletionContext(), Results.data(),Results.size()); } @@ -3348,7 +3349,7 @@ bool IsSuper, ResultBuilder &Results); -void Sema::CodeCompleteDeclSpec(Scope *S, DeclSpec &DS, +void Sema::CodeCompleteDeclSpec(Token Tok, Scope *S, DeclSpec &DS, bool AllowNonIdentifiers, bool AllowNestedNameSpecifiers) { typedef CodeCompletionResult Result; @@ -3405,7 +3406,7 @@ // 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(Tok, this, CodeCompleter, Results.getCompletionContext(), Results.data(), Results.size()); } @@ -3423,7 +3424,7 @@ /// \brief Perform code-completion in an expression context when we know what /// type we're looking for. -void Sema::CodeCompleteExpression(Scope *S, +void Sema::CodeCompleteExpression(Token Tok, Scope *S, const CodeCompleteExpressionData &Data) { ResultBuilder Results(*this, CodeCompleter->getAllocator(), CodeCompleter->getCodeCompletionTUInfo(), @@ -3465,17 +3466,17 @@ if (CodeCompleter->includeMacros()) AddMacroResults(PP, Results, false, PreferredTypeIsPointer); - HandleCodeCompleteResults(this, CodeCompleter, + HandleCodeCompleteResults(Tok, this, CodeCompleter, CodeCompletionContext(CodeCompletionContext::CCC_Expression, Data.PreferredType), Results.data(),Results.size()); } -void Sema::CodeCompletePostfixExpression(Scope *S, ExprResult E) { +void Sema::CodeCompletePostfixExpression(Token Tok, Scope *S, ExprResult E) { if (E.isInvalid()) - CodeCompleteOrdinaryName(S, PCC_RecoveryInFunction); + CodeCompleteOrdinaryName(Tok, S, PCC_RecoveryInFunction); else if (getLangOpts().ObjC1) - CodeCompleteObjCInstanceMessage(S, E.get(), None, false); + CodeCompleteObjCInstanceMessage(Tok, S, E.get(), None, false); } /// \brief The set of properties that have already been added, referenced by @@ -3571,7 +3572,7 @@ } } -void Sema::CodeCompleteMemberReferenceExpr(Scope *S, Expr *Base, +void Sema::CodeCompleteMemberReferenceExpr(Token Tok, Scope *S, Expr *Base, SourceLocation OpLoc, bool IsArrow) { if (!Base || !CodeCompleter) @@ -3685,12 +3686,12 @@ Results.ExitScope(); // Hand off the results found for code completion. - HandleCodeCompleteResults(this, CodeCompleter, + HandleCodeCompleteResults(Tok, this, CodeCompleter, Results.getCompletionContext(), Results.data(),Results.size()); } -void Sema::CodeCompleteTag(Scope *S, unsigned TagSpec) { +void Sema::CodeCompleteTag(Token Tok, Scope *S, unsigned TagSpec) { if (!CodeCompleter) return; @@ -3734,11 +3735,11 @@ LookupVisibleDecls(S, LookupNestedNameSpecifierName, Consumer); } - HandleCodeCompleteResults(this, CodeCompleter, Results.getCompletionContext(), + HandleCodeCompleteResults(Tok, this, CodeCompleter, Results.getCompletionContext(), Results.data(),Results.size()); } -void Sema::CodeCompleteTypeQualifiers(DeclSpec &DS) { +void Sema::CodeCompleteTypeQualifiers(Token Tok, DeclSpec &DS) { ResultBuilder Results(*this, CodeCompleter->getAllocator(), CodeCompleter->getCodeCompletionTUInfo(), CodeCompletionContext::CCC_TypeQualifiers); @@ -3754,12 +3755,12 @@ !(DS.getTypeQualifiers() & DeclSpec::TQ_atomic)) Results.AddResult("_Atomic"); Results.ExitScope(); - HandleCodeCompleteResults(this, CodeCompleter, + HandleCodeCompleteResults(Tok, this, CodeCompleter, Results.getCompletionContext(), Results.data(), Results.size()); } -void Sema::CodeCompleteCase(Scope *S) { +void Sema::CodeCompleteCase(Token Tok, Scope *S) { if (getCurFunction()->SwitchStack.empty() || !CodeCompleter) return; @@ -3768,7 +3769,7 @@ if (!type->isEnumeralType()) { CodeCompleteExpressionData Data(type); Data.IntegralConstantExpression = true; - CodeCompleteExpression(S, Data); + CodeCompleteExpression(Tok, S, Data); return; } @@ -3846,7 +3847,7 @@ kind = CodeCompletionContext::CCC_OtherWithMacros; } - HandleCodeCompleteResults(this, CodeCompleter, + HandleCodeCompleteResults(Tok, this, CodeCompleter, kind, Results.data(),Results.size()); } @@ -3910,7 +3911,7 @@ return ParamType; } -static void CodeCompleteOverloadResults(Sema &SemaRef, Scope *S, +static void CodeCompleteOverloadResults(Token Tok, Sema &SemaRef, Scope *S, MutableArrayRef Candidates, unsigned CurrentArg, bool CompleteExpressionWithCurrentArg = true) { @@ -3919,9 +3920,9 @@ ParamType = getParamType(SemaRef, Candidates, CurrentArg); if (ParamType.isNull()) - SemaRef.CodeCompleteOrdinaryName(S, Sema::PCC_Expression); + SemaRef.CodeCompleteOrdinaryName(Tok, S, Sema::PCC_Expression); else - SemaRef.CodeCompleteExpression(S, ParamType); + SemaRef.CodeCompleteExpression(Tok, S, ParamType); if (!Candidates.empty()) SemaRef.CodeCompleter->ProcessOverloadCandidates(SemaRef, CurrentArg, @@ -3929,7 +3930,7 @@ Candidates.size()); } -void Sema::CodeCompleteCall(Scope *S, Expr *Fn, ArrayRef Args) { +void Sema::CodeCompleteCall(Token Tok, Scope *S, Expr *Fn, ArrayRef Args) { if (!CodeCompleter) return; @@ -3943,7 +3944,7 @@ // Ignore type-dependent call expressions entirely. if (!Fn || Fn->isTypeDependent() || anyNullArguments(Args) || Expr::hasAnyTypeDependentArguments(Args)) { - CodeCompleteOrdinaryName(S, PCC_Expression); + CodeCompleteOrdinaryName(Tok, S, PCC_Expression); return; } @@ -4022,11 +4023,11 @@ } mergeCandidatesWithResults(*this, Results, CandidateSet, Loc); - CodeCompleteOverloadResults(*this, S, Results, Args.size(), + CodeCompleteOverloadResults(Tok, *this, S, Results, Args.size(), !CandidateSet.empty()); } -void Sema::CodeCompleteConstructor(Scope *S, QualType Type, SourceLocation Loc, +void Sema::CodeCompleteConstructor(Token Tok, Scope *S, QualType Type, SourceLocation Loc, ArrayRef Args) { if (!CodeCompleter) return; @@ -4058,20 +4059,20 @@ SmallVector Results; mergeCandidatesWithResults(*this, Results, CandidateSet, Loc); - CodeCompleteOverloadResults(*this, S, Results, Args.size()); + CodeCompleteOverloadResults(Tok, *this, S, Results, Args.size()); } -void Sema::CodeCompleteInitializer(Scope *S, Decl *D) { +void Sema::CodeCompleteInitializer(Token Tok, Scope *S, Decl *D) { ValueDecl *VD = dyn_cast_or_null(D); if (!VD) { - CodeCompleteOrdinaryName(S, PCC_Expression); + CodeCompleteOrdinaryName(Tok, S, PCC_Expression); return; } - CodeCompleteExpression(S, VD->getType()); + CodeCompleteExpression(Tok, S, VD->getType()); } -void Sema::CodeCompleteReturn(Scope *S) { +void Sema::CodeCompleteReturn(Token Tok, Scope *S) { QualType ResultType; if (isa(CurContext)) { if (BlockScopeInfo *BSI = getCurBlock()) @@ -4082,12 +4083,12 @@ ResultType = Method->getReturnType(); if (ResultType.isNull()) - CodeCompleteOrdinaryName(S, PCC_Expression); + CodeCompleteOrdinaryName(Tok, S, PCC_Expression); else - CodeCompleteExpression(S, ResultType); + CodeCompleteExpression(Tok, S, ResultType); } -void Sema::CodeCompleteAfterIf(Scope *S) { +void Sema::CodeCompleteAfterIf(Token Tok, Scope *S) { ResultBuilder Results(*this, CodeCompleter->getAllocator(), CodeCompleter->getCodeCompletionTUInfo(), mapCodeCompletionContext(*this, PCC_Statement)); @@ -4143,18 +4144,18 @@ if (CodeCompleter->includeMacros()) AddMacroResults(PP, Results, false); - HandleCodeCompleteResults(this, CodeCompleter, Results.getCompletionContext(), + HandleCodeCompleteResults(Tok, this, CodeCompleter, Results.getCompletionContext(), Results.data(),Results.size()); } -void Sema::CodeCompleteAssignmentRHS(Scope *S, Expr *LHS) { +void Sema::CodeCompleteAssignmentRHS(Token Tok, Scope *S, Expr *LHS) { if (LHS) - CodeCompleteExpression(S, static_cast(LHS)->getType()); + CodeCompleteExpression(Tok, S, static_cast(LHS)->getType()); else - CodeCompleteOrdinaryName(S, PCC_Expression); + CodeCompleteOrdinaryName(Tok, S, PCC_Expression); } -void Sema::CodeCompleteQualifiedId(Scope *S, CXXScopeSpec &SS, +void Sema::CodeCompleteQualifiedId(Token Tok, Scope *S, CXXScopeSpec &SS, bool EnteringContext) { if (!SS.getScopeRep() || !CodeCompleter) return; @@ -4191,12 +4192,12 @@ CodeCompletionDeclConsumer Consumer(Results, CurContext); LookupVisibleDecls(Ctx, LookupOrdinaryName, Consumer); - HandleCodeCompleteResults(this, CodeCompleter, + HandleCodeCompleteResults(Tok, this, CodeCompleter, Results.getCompletionContext(), Results.data(),Results.size()); } -void Sema::CodeCompleteUsing(Scope *S) { +void Sema::CodeCompleteUsing(Token Tok, Scope *S) { if (!CodeCompleter) return; @@ -4217,12 +4218,12 @@ CodeCompleter->includeGlobals()); Results.ExitScope(); - HandleCodeCompleteResults(this, CodeCompleter, + HandleCodeCompleteResults(Tok, this, CodeCompleter, CodeCompletionContext::CCC_PotentiallyQualifiedName, Results.data(),Results.size()); } -void Sema::CodeCompleteUsingDirective(Scope *S) { +void Sema::CodeCompleteUsingDirective(Token Tok, Scope *S) { if (!CodeCompleter) return; @@ -4237,12 +4238,12 @@ LookupVisibleDecls(S, LookupOrdinaryName, Consumer, CodeCompleter->includeGlobals()); Results.ExitScope(); - HandleCodeCompleteResults(this, CodeCompleter, + HandleCodeCompleteResults(Tok, this, CodeCompleter, CodeCompletionContext::CCC_Namespace, Results.data(),Results.size()); } -void Sema::CodeCompleteNamespaceDecl(Scope *S) { +void Sema::CodeCompleteNamespaceDecl(Token Tok, Scope *S) { if (!CodeCompleter) return; @@ -4285,12 +4286,12 @@ Results.ExitScope(); } - HandleCodeCompleteResults(this, CodeCompleter, + HandleCodeCompleteResults(Tok, this, CodeCompleter, Results.getCompletionContext(), Results.data(),Results.size()); } -void Sema::CodeCompleteNamespaceAliasDecl(Scope *S) { +void Sema::CodeCompleteNamespaceAliasDecl(Token Tok, Scope *S) { if (!CodeCompleter) return; @@ -4302,12 +4303,12 @@ CodeCompletionDeclConsumer Consumer(Results, CurContext); LookupVisibleDecls(S, LookupOrdinaryName, Consumer, CodeCompleter->includeGlobals()); - HandleCodeCompleteResults(this, CodeCompleter, + HandleCodeCompleteResults(Tok, this, CodeCompleter, Results.getCompletionContext(), Results.data(),Results.size()); } -void Sema::CodeCompleteOperatorName(Scope *S) { +void Sema::CodeCompleteOperatorName(Token Tok, Scope *S) { if (!CodeCompleter) return; @@ -4334,12 +4335,12 @@ AddTypeSpecifierResults(getLangOpts(), Results); Results.ExitScope(); - HandleCodeCompleteResults(this, CodeCompleter, + HandleCodeCompleteResults(Tok, this, CodeCompleter, CodeCompletionContext::CCC_Type, Results.data(),Results.size()); } -void Sema::CodeCompleteConstructorInitializer( +void Sema::CodeCompleteConstructorInitializer(Token Tok, Decl *ConstructorD, ArrayRef Initializers) { PrintingPolicy Policy = getCompletionPrintingPolicy(*this); @@ -4446,7 +4447,7 @@ } Results.ExitScope(); - HandleCodeCompleteResults(this, CodeCompleter, Results.getCompletionContext(), + HandleCodeCompleteResults(Tok, this, CodeCompleter, Results.getCompletionContext(), Results.data(), Results.size()); } @@ -4459,7 +4460,7 @@ return DC->isFileContext(); } -void Sema::CodeCompleteLambdaIntroducer(Scope *S, LambdaIntroducer &Intro, +void Sema::CodeCompleteLambdaIntroducer(Token Tok, Scope *S, LambdaIntroducer &Intro, bool AfterAmpersand) { ResultBuilder Results(*this, CodeCompleter->getAllocator(), CodeCompleter->getCodeCompletionTUInfo(), @@ -4499,7 +4500,7 @@ Results.ExitScope(); - HandleCodeCompleteResults(this, CodeCompleter, Results.getCompletionContext(), + HandleCodeCompleteResults(Tok, this, CodeCompleter, Results.getCompletionContext(), Results.data(), Results.size()); } @@ -4601,7 +4602,7 @@ } } -void Sema::CodeCompleteObjCAtDirective(Scope *S) { +void Sema::CodeCompleteObjCAtDirective(Token Tok, Scope *S) { ResultBuilder Results(*this, CodeCompleter->getAllocator(), CodeCompleter->getCodeCompletionTUInfo(), CodeCompletionContext::CCC_Other); @@ -4613,7 +4614,7 @@ else AddObjCTopLevelResults(Results, false); Results.ExitScope(); - HandleCodeCompleteResults(this, CodeCompleter, + HandleCodeCompleteResults(Tok, this, CodeCompleter, CodeCompletionContext::CCC_Other, Results.data(),Results.size()); } @@ -4740,19 +4741,19 @@ Results.AddResult(Result(OBJC_AT_KEYWORD_NAME(NeedAt,"package"))); } -void Sema::CodeCompleteObjCAtVisibility(Scope *S) { +void Sema::CodeCompleteObjCAtVisibility(Token Tok, Scope *S) { ResultBuilder Results(*this, CodeCompleter->getAllocator(), CodeCompleter->getCodeCompletionTUInfo(), CodeCompletionContext::CCC_Other); Results.EnterNewScope(); AddObjCVisibilityResults(getLangOpts(), Results, false); Results.ExitScope(); - HandleCodeCompleteResults(this, CodeCompleter, + HandleCodeCompleteResults(Tok, this, CodeCompleter, CodeCompletionContext::CCC_Other, Results.data(),Results.size()); } -void Sema::CodeCompleteObjCAtStatement(Scope *S) { +void Sema::CodeCompleteObjCAtStatement(Token Tok, Scope *S) { ResultBuilder Results(*this, CodeCompleter->getAllocator(), CodeCompleter->getCodeCompletionTUInfo(), CodeCompletionContext::CCC_Other); @@ -4760,19 +4761,19 @@ AddObjCStatementResults(Results, false); AddObjCExpressionResults(Results, false); Results.ExitScope(); - HandleCodeCompleteResults(this, CodeCompleter, + HandleCodeCompleteResults(Tok, this, CodeCompleter, CodeCompletionContext::CCC_Other, Results.data(),Results.size()); } -void Sema::CodeCompleteObjCAtExpression(Scope *S) { +void Sema::CodeCompleteObjCAtExpression(Token Tok, Scope *S) { ResultBuilder Results(*this, CodeCompleter->getAllocator(), CodeCompleter->getCodeCompletionTUInfo(), CodeCompletionContext::CCC_Other); Results.EnterNewScope(); AddObjCExpressionResults(Results, false); Results.ExitScope(); - HandleCodeCompleteResults(this, CodeCompleter, + HandleCodeCompleteResults(Tok, this, CodeCompleter, CodeCompletionContext::CCC_Other, Results.data(),Results.size()); } @@ -4810,7 +4811,7 @@ return false; } -void Sema::CodeCompleteObjCPropertyFlags(Scope *S, ObjCDeclSpec &ODS) { +void Sema::CodeCompleteObjCPropertyFlags(Token Tok, Scope *S, ObjCDeclSpec &ODS) { if (!CodeCompleter) return; @@ -4862,7 +4863,7 @@ Results.AddResult(CodeCompletionResult(Getter.TakeString())); } Results.ExitScope(); - HandleCodeCompleteResults(this, CodeCompleter, + HandleCodeCompleteResults(Tok, this, CodeCompleter, CodeCompletionContext::CCC_Other, Results.data(),Results.size()); } @@ -5026,7 +5027,7 @@ } -void Sema::CodeCompleteObjCPropertyGetter(Scope *S) { +void Sema::CodeCompleteObjCPropertyGetter(Token Tok, Scope *S) { // Try to find the interface where getters might live. ObjCInterfaceDecl *Class = dyn_cast_or_null(CurContext); if (!Class) { @@ -5048,12 +5049,12 @@ AddObjCMethods(Class, true, MK_ZeroArgSelector, None, CurContext, Selectors, /*AllowSameLength=*/true, Results); Results.ExitScope(); - HandleCodeCompleteResults(this, CodeCompleter, + HandleCodeCompleteResults(Tok, this, CodeCompleter, CodeCompletionContext::CCC_Other, Results.data(),Results.size()); } -void Sema::CodeCompleteObjCPropertySetter(Scope *S) { +void Sema::CodeCompleteObjCPropertySetter(Token Tok, Scope *S) { // Try to find the interface where setters might live. ObjCInterfaceDecl *Class = dyn_cast_or_null(CurContext); @@ -5077,12 +5078,12 @@ Selectors, /*AllowSameLength=*/true, Results); Results.ExitScope(); - HandleCodeCompleteResults(this, CodeCompleter, + HandleCodeCompleteResults(Tok, this, CodeCompleter, CodeCompletionContext::CCC_Other, Results.data(),Results.size()); } -void Sema::CodeCompleteObjCPassingType(Scope *S, ObjCDeclSpec &DS, +void Sema::CodeCompleteObjCPassingType(Token Tok, Scope *S, ObjCDeclSpec &DS, bool IsParameter) { ResultBuilder Results(*this, CodeCompleter->getAllocator(), CodeCompleter->getCodeCompletionTUInfo(), @@ -5149,7 +5150,7 @@ if (CodeCompleter->includeMacros()) AddMacroResults(PP, Results, false); - HandleCodeCompleteResults(this, CodeCompleter, + HandleCodeCompleteResults(Tok, this, CodeCompleter, CodeCompletionContext::CCC_Type, Results.data(), Results.size()); } @@ -5345,7 +5346,7 @@ return SuperMethod; } -void Sema::CodeCompleteObjCMessageReceiver(Scope *S) { +void Sema::CodeCompleteObjCMessageReceiver(Token Tok, Scope *S) { typedef CodeCompletionResult Result; ResultBuilder Results(*this, CodeCompleter->getAllocator(), CodeCompleter->getCodeCompletionTUInfo(), @@ -5376,12 +5377,12 @@ if (CodeCompleter->includeMacros()) AddMacroResults(PP, Results, false); - HandleCodeCompleteResults(this, CodeCompleter, Results.getCompletionContext(), + HandleCodeCompleteResults(Tok, this, CodeCompleter, Results.getCompletionContext(), Results.data(), Results.size()); } -void Sema::CodeCompleteObjCSuperMessage(Scope *S, SourceLocation SuperLoc, +void Sema::CodeCompleteObjCSuperMessage(Token Tok, Scope *S, SourceLocation SuperLoc, ArrayRef SelIdents, bool AtArgumentExpression) { ObjCInterfaceDecl *CDecl = nullptr; @@ -5400,7 +5401,7 @@ // We are inside an instance method, which means that the message // send [super ...] is actually calling an instance method on the // current object. - return CodeCompleteObjCInstanceMessage(S, nullptr, SelIdents, + return CodeCompleteObjCInstanceMessage(Tok, S, nullptr, SelIdents, AtArgumentExpression, CDecl); } @@ -5428,7 +5429,7 @@ id.setIdentifier(Super, SuperLoc); ExprResult SuperExpr = ActOnIdExpression(S, SS, TemplateKWLoc, id, false, false); - return CodeCompleteObjCInstanceMessage(S, (Expr *)SuperExpr.get(), + return CodeCompleteObjCInstanceMessage(Tok, S, (Expr *)SuperExpr.get(), SelIdents, AtArgumentExpression); } @@ -5439,7 +5440,7 @@ ParsedType Receiver; if (CDecl) Receiver = ParsedType::make(Context.getObjCInterfaceType(CDecl)); - return CodeCompleteObjCClassMessage(S, Receiver, SelIdents, + return CodeCompleteObjCClassMessage(Tok, S, Receiver, SelIdents, AtArgumentExpression, /*IsSuper=*/true); } @@ -5556,7 +5557,7 @@ Results.ExitScope(); } -void Sema::CodeCompleteObjCClassMessage(Scope *S, ParsedType Receiver, +void Sema::CodeCompleteObjCClassMessage(Token Tok, Scope *S, ParsedType Receiver, ArrayRef SelIdents, bool AtArgumentExpression, bool IsSuper) { @@ -5580,18 +5581,18 @@ QualType PreferredType = getPreferredArgumentTypeForMessageSend(Results, SelIdents.size()); if (PreferredType.isNull()) - CodeCompleteOrdinaryName(S, PCC_Expression); + CodeCompleteOrdinaryName(Tok, S, PCC_Expression); else - CodeCompleteExpression(S, PreferredType); + CodeCompleteExpression(Tok, S, PreferredType); return; } - HandleCodeCompleteResults(this, CodeCompleter, + HandleCodeCompleteResults(Tok, this, CodeCompleter, Results.getCompletionContext(), Results.data(), Results.size()); } -void Sema::CodeCompleteObjCInstanceMessage(Scope *S, Expr *Receiver, +void Sema::CodeCompleteObjCInstanceMessage(Token Tok, Scope *S, Expr *Receiver, ArrayRef SelIdents, bool AtArgumentExpression, ObjCInterfaceDecl *Super) { @@ -5618,7 +5619,7 @@ if (ReceiverType->isObjCIdType() || ReceiverType->isObjCClassType()) { if (ObjCInterfaceDecl *IFace = GetAssumedMessageSendExprType(RecExpr)) { if (ReceiverType->isObjCClassType()) - return CodeCompleteObjCClassMessage(S, + return CodeCompleteObjCClassMessage(Tok, S, ParsedType::make(Context.getObjCInterfaceType(IFace)), SelIdents, AtArgumentExpression, Super); @@ -5740,18 +5741,18 @@ QualType PreferredType = getPreferredArgumentTypeForMessageSend(Results, SelIdents.size()); if (PreferredType.isNull()) - CodeCompleteOrdinaryName(S, PCC_Expression); + CodeCompleteOrdinaryName(Tok, S, PCC_Expression); else - CodeCompleteExpression(S, PreferredType); + CodeCompleteExpression(Tok, S, PreferredType); return; } - HandleCodeCompleteResults(this, CodeCompleter, + HandleCodeCompleteResults(Tok, this, CodeCompleter, Results.getCompletionContext(), Results.data(),Results.size()); } -void Sema::CodeCompleteObjCForCollection(Scope *S, +void Sema::CodeCompleteObjCForCollection(Token Tok, Scope *S, DeclGroupPtrTy IterationVar) { CodeCompleteExpressionData Data; Data.ObjCCollection = true; @@ -5764,10 +5765,10 @@ } } - CodeCompleteExpression(S, Data); + CodeCompleteExpression(Tok, S, Data); } -void Sema::CodeCompleteObjCSelector(Scope *S, +void Sema::CodeCompleteObjCSelector(Token Tok, Scope *S, ArrayRef SelIdents) { // If we have an external source, load the entire class method // pool from the AST file. @@ -5821,7 +5822,7 @@ } Results.ExitScope(); - HandleCodeCompleteResults(this, CodeCompleter, + HandleCodeCompleteResults(Tok, this, CodeCompleter, CodeCompletionContext::CCC_SelectorName, Results.data(), Results.size()); } @@ -5842,7 +5843,7 @@ } } -void Sema::CodeCompleteObjCProtocolReferences(IdentifierLocPair *Protocols, +void Sema::CodeCompleteObjCProtocolReferences(Token Tok, IdentifierLocPair *Protocols, unsigned NumProtocols) { ResultBuilder Results(*this, CodeCompleter->getAllocator(), CodeCompleter->getCodeCompletionTUInfo(), @@ -5866,12 +5867,12 @@ Results.ExitScope(); } - HandleCodeCompleteResults(this, CodeCompleter, + HandleCodeCompleteResults(Tok, this, CodeCompleter, CodeCompletionContext::CCC_ObjCProtocolName, Results.data(),Results.size()); } -void Sema::CodeCompleteObjCProtocolDecl(Scope *) { +void Sema::CodeCompleteObjCProtocolDecl(Token Tok, Scope *) { ResultBuilder Results(*this, CodeCompleter->getAllocator(), CodeCompleter->getCodeCompletionTUInfo(), CodeCompletionContext::CCC_ObjCProtocolName); @@ -5886,7 +5887,7 @@ Results.ExitScope(); } - HandleCodeCompleteResults(this, CodeCompleter, + HandleCodeCompleteResults(Tok, this, CodeCompleter, CodeCompletionContext::CCC_ObjCProtocolName, Results.data(),Results.size()); } @@ -5909,7 +5910,7 @@ } } -void Sema::CodeCompleteObjCInterfaceDecl(Scope *S) { +void Sema::CodeCompleteObjCInterfaceDecl(Token Tok, Scope *S) { ResultBuilder Results(*this, CodeCompleter->getAllocator(), CodeCompleter->getCodeCompletionTUInfo(), CodeCompletionContext::CCC_Other); @@ -5923,12 +5924,12 @@ Results.ExitScope(); - HandleCodeCompleteResults(this, CodeCompleter, + HandleCodeCompleteResults(Tok, this, CodeCompleter, CodeCompletionContext::CCC_ObjCInterfaceName, Results.data(),Results.size()); } -void Sema::CodeCompleteObjCSuperclass(Scope *S, IdentifierInfo *ClassName, +void Sema::CodeCompleteObjCSuperclass(Token Tok, Scope *S, IdentifierInfo *ClassName, SourceLocation ClassNameLoc) { ResultBuilder Results(*this, CodeCompleter->getAllocator(), CodeCompleter->getCodeCompletionTUInfo(), @@ -5949,12 +5950,12 @@ Results.ExitScope(); - HandleCodeCompleteResults(this, CodeCompleter, + HandleCodeCompleteResults(Tok, this, CodeCompleter, CodeCompletionContext::CCC_ObjCInterfaceName, Results.data(),Results.size()); } -void Sema::CodeCompleteObjCImplementationDecl(Scope *S) { +void Sema::CodeCompleteObjCImplementationDecl(Token Tok, Scope *S) { ResultBuilder Results(*this, CodeCompleter->getAllocator(), CodeCompleter->getCodeCompletionTUInfo(), CodeCompletionContext::CCC_Other); @@ -5968,12 +5969,12 @@ Results.ExitScope(); - HandleCodeCompleteResults(this, CodeCompleter, + HandleCodeCompleteResults(Tok, this, CodeCompleter, CodeCompletionContext::CCC_ObjCInterfaceName, Results.data(),Results.size()); } -void Sema::CodeCompleteObjCInterfaceCategory(Scope *S, +void Sema::CodeCompleteObjCInterfaceCategory(Token Tok, Scope *S, IdentifierInfo *ClassName, SourceLocation ClassNameLoc) { typedef CodeCompletionResult Result; @@ -6003,12 +6004,12 @@ CurContext, nullptr, false); Results.ExitScope(); - HandleCodeCompleteResults(this, CodeCompleter, + HandleCodeCompleteResults(Tok, this, CodeCompleter, CodeCompletionContext::CCC_ObjCCategoryName, Results.data(),Results.size()); } -void Sema::CodeCompleteObjCImplementationCategory(Scope *S, +void Sema::CodeCompleteObjCImplementationCategory(Token Tok, Scope *S, IdentifierInfo *ClassName, SourceLocation ClassNameLoc) { typedef CodeCompletionResult Result; @@ -6020,7 +6021,7 @@ = LookupSingleName(TUScope, ClassName, ClassNameLoc, LookupOrdinaryName); ObjCInterfaceDecl *Class = dyn_cast_or_null(CurClass); if (!Class) - return CodeCompleteObjCInterfaceCategory(S, ClassName, ClassNameLoc); + return CodeCompleteObjCInterfaceCategory(Tok, S, ClassName, ClassNameLoc); ResultBuilder Results(*this, CodeCompleter->getAllocator(), CodeCompleter->getCodeCompletionTUInfo(), @@ -6045,12 +6046,12 @@ } Results.ExitScope(); - HandleCodeCompleteResults(this, CodeCompleter, + HandleCodeCompleteResults(Tok, this, CodeCompleter, CodeCompletionContext::CCC_ObjCCategoryName, Results.data(),Results.size()); } -void Sema::CodeCompleteObjCPropertyDefinition(Scope *S) { +void Sema::CodeCompleteObjCPropertyDefinition(Token Tok, Scope *S) { ResultBuilder Results(*this, CodeCompleter->getAllocator(), CodeCompleter->getCodeCompletionTUInfo(), CodeCompletionContext::CCC_Other); @@ -6083,12 +6084,12 @@ AddedProperties, Results); Results.ExitScope(); - HandleCodeCompleteResults(this, CodeCompleter, + HandleCodeCompleteResults(Tok, this, CodeCompleter, CodeCompletionContext::CCC_Other, Results.data(),Results.size()); } -void Sema::CodeCompleteObjCPropertySynthesizeIvar(Scope *S, +void Sema::CodeCompleteObjCPropertySynthesizeIvar(Token Tok, Scope *S, IdentifierInfo *PropertyName) { typedef CodeCompletionResult Result; ResultBuilder Results(*this, CodeCompleter->getAllocator(), @@ -6176,7 +6177,7 @@ Results.ExitScope(); - HandleCodeCompleteResults(this, CodeCompleter, + HandleCodeCompleteResults(Tok, this, CodeCompleter, CodeCompletionContext::CCC_Other, Results.data(),Results.size()); } @@ -6935,7 +6936,7 @@ } } -void Sema::CodeCompleteObjCMethodDecl(Scope *S, +void Sema::CodeCompleteObjCMethodDecl(Token Tok, Scope *S, bool IsInstanceMethod, ParsedType ReturnTy) { // Determine the return type of the method we're declaring, if @@ -6967,7 +6968,7 @@ } if (!SearchDecl) { - HandleCodeCompleteResults(this, CodeCompleter, + HandleCodeCompleteResults(Tok, this, CodeCompleter, CodeCompletionContext::CCC_Other, nullptr, 0); return; @@ -7091,12 +7092,12 @@ Results.ExitScope(); - HandleCodeCompleteResults(this, CodeCompleter, + HandleCodeCompleteResults(Tok, this, CodeCompleter, CodeCompletionContext::CCC_Other, Results.data(),Results.size()); } -void Sema::CodeCompleteObjCMethodDeclSelector(Scope *S, +void Sema::CodeCompleteObjCMethodDeclSelector(Token Tok, Scope *S, bool IsInstanceMethod, bool AtParameterName, ParsedType ReturnTy, @@ -7163,12 +7164,12 @@ } Results.ExitScope(); - HandleCodeCompleteResults(this, CodeCompleter, + HandleCodeCompleteResults(Tok, this, CodeCompleter, CodeCompletionContext::CCC_Other, Results.data(),Results.size()); } -void Sema::CodeCompletePreprocessorDirective(bool InConditional) { +void Sema::CodeCompletePreprocessorDirective(Token Tok, bool InConditional) { ResultBuilder Results(*this, CodeCompleter->getAllocator(), CodeCompleter->getCodeCompletionTUInfo(), CodeCompletionContext::CCC_PreprocessorDirective); @@ -7322,18 +7323,18 @@ // FIXME: we don't support #assert or #unassert, so don't suggest them. Results.ExitScope(); - HandleCodeCompleteResults(this, CodeCompleter, + HandleCodeCompleteResults(Tok, this, CodeCompleter, CodeCompletionContext::CCC_PreprocessorDirective, Results.data(), Results.size()); } -void Sema::CodeCompleteInPreprocessorConditionalExclusion(Scope *S) { - CodeCompleteOrdinaryName(S, +void Sema::CodeCompleteInPreprocessorConditionalExclusion(Token Tok, Scope *S) { + CodeCompleteOrdinaryName(Tok, S, S->getFnParent()? Sema::PCC_RecoveryInFunction : Sema::PCC_Namespace); } -void Sema::CodeCompletePreprocessorMacroName(bool IsDefinition) { +void Sema::CodeCompletePreprocessorMacroName(Token Tok, bool IsDefinition) { ResultBuilder Results(*this, CodeCompleter->getAllocator(), CodeCompleter->getCodeCompletionTUInfo(), IsDefinition? CodeCompletionContext::CCC_MacroName @@ -7357,11 +7358,11 @@ // FIXME: Can we detect when the user just wrote an include guard above? } - HandleCodeCompleteResults(this, CodeCompleter, Results.getCompletionContext(), + HandleCodeCompleteResults(Tok, this, CodeCompleter, Results.getCompletionContext(), Results.data(), Results.size()); } -void Sema::CodeCompletePreprocessorExpression() { +void Sema::CodeCompletePreprocessorExpression(Token Tok) { ResultBuilder Results(*this, CodeCompleter->getAllocator(), CodeCompleter->getCodeCompletionTUInfo(), CodeCompletionContext::CCC_PreprocessorExpression); @@ -7381,12 +7382,12 @@ Results.AddResult(Builder.TakeString()); Results.ExitScope(); - HandleCodeCompleteResults(this, CodeCompleter, + HandleCodeCompleteResults(Tok, this, CodeCompleter, CodeCompletionContext::CCC_PreprocessorExpression, Results.data(), Results.size()); } -void Sema::CodeCompletePreprocessorMacroArgument(Scope *S, +void Sema::CodeCompletePreprocessorMacroArgument(Token Tok, Scope *S, IdentifierInfo *Macro, MacroInfo *MacroInfo, unsigned Argument) { @@ -7397,8 +7398,8 @@ // for the expanded tokens. } -void Sema::CodeCompleteNaturalLanguage() { - HandleCodeCompleteResults(this, CodeCompleter, +void Sema::CodeCompleteNaturalLanguage(Token Tok) { + HandleCodeCompleteResults(Tok, this, CodeCompleter, CodeCompletionContext::CCC_NaturalLanguage, nullptr, 0); } Index: test/CodeCompletion/Filtering/filter-function-name.cpp =================================================================== --- /dev/null +++ test/CodeCompletion/Filtering/filter-function-name.cpp @@ -0,0 +1,8 @@ +void myFunction(); + +int main() { + myFunc + // RUN: %clang_cc1 -code-completion-at=%s:4:11 %s -o - | FileCheck -check-prefix=CHECK-CC1 %s + // CHECK-CC1: COMPLETION: myFunction : [#void#]myFunction() +} + Index: test/CodeCompletion/Filtering/filter-member-access.cpp =================================================================== --- /dev/null +++ test/CodeCompletion/Filtering/filter-member-access.cpp @@ -0,0 +1,24 @@ +class MyClass { +private: + int anInteger; + double aDouble; + +public: + MyClass(int i, double d) { + anInteger = i; + aDouble = d; + } + int getInt() { return anInteger; } + double getDouble() { return aDouble; } + void setInt(int value) { anInteger = value; } + void setDouble(double value) { aDouble = value; } +}; + +int main() { + MyClass* objectMyClass = new MyClass(5, 1.0); + objectMyClass->set + // RUN: %clang_cc1 -code-completion-at=%s:19:23 %s -o - | FileCheck -check-prefix=CHECK-CC1 %s + // CHECK-CC1: COMPLETION: setDouble : [#void#]setDouble(<#double value#>) + // CHECK-CC1-NEXT: COMPLETION: setInt : [#void#]setInt(<#int value#>) + return 0; +} \ No newline at end of file Index: test/CodeCompletion/Filtering/filter-namespace.cpp =================================================================== --- /dev/null +++ test/CodeCompletion/Filtering/filter-namespace.cpp @@ -0,0 +1,7 @@ +namespace outerspace { + namespace innerspace { } +} + +using namespace outerspace::inner +// RUN: %clang_cc1 -code-completion-at=%s:5:34 %s -o - | FileCheck -check-prefix=CHECK-CC1 %s +// CHECK-CC1: COMPLETION: innerspace : innerspace Index: test/CodeCompletion/Filtering/filter-ordinary-name.cpp =================================================================== --- /dev/null +++ test/CodeCompletion/Filtering/filter-ordinary-name.cpp @@ -0,0 +1,8 @@ +int main() { + int myVariableOne; + int myVariableTwo; + myVar + // RUN: %clang_cc1 -code-completion-at=%s:4:10 %s -o - | FileCheck -check-prefix=CHECK-CC1 %s + // CHECK-CC1: COMPLETION: myVariableOne : [#int#]myVariableOne + // CHECK-CC1-NEXT: COMPLETION: myVariableTwo : [#int#]myVariableTwo +} \ No newline at end of file