From: Douglas Gregor Date: Mon, 20 Sep 2010 23:34:21 +0000 (+0000) Subject: Refactor code completion for expressions that occur as arguments in X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=70c5ac70ace21b011dc2d4001bae26cdcf62ff8d;p=clang Refactor code completion for expressions that occur as arguments in Objective-C message sends. There is no functionality change here; this is prep work for using the parameter types to help guide the expression results when code-completing the argument. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@114375 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Sema/Sema.h b/include/clang/Sema/Sema.h index 7708731947..af0174965f 100644 --- a/include/clang/Sema/Sema.h +++ b/include/clang/Sema/Sema.h @@ -4351,14 +4351,17 @@ public: void CodeCompleteObjCMessageReceiver(Scope *S); void CodeCompleteObjCSuperMessage(Scope *S, SourceLocation SuperLoc, IdentifierInfo **SelIdents, - unsigned NumSelIdents); + unsigned NumSelIdents, + bool AtArgumentExpression); void CodeCompleteObjCClassMessage(Scope *S, ParsedType Receiver, IdentifierInfo **SelIdents, unsigned NumSelIdents, + bool AtArgumentExpression, bool IsSuper = false); void CodeCompleteObjCInstanceMessage(Scope *S, ExprTy *Receiver, IdentifierInfo **SelIdents, unsigned NumSelIdents, + bool AtArgumentExpression, bool IsSuper = false); void CodeCompleteObjCForCollection(Scope *S, DeclGroupPtrTy IterationVar); diff --git a/lib/Parse/ParseObjc.cpp b/lib/Parse/ParseObjc.cpp index a9cab9ec18..3291736acc 100644 --- a/lib/Parse/ParseObjc.cpp +++ b/lib/Parse/ParseObjc.cpp @@ -2030,12 +2030,14 @@ Parser::ParseObjCMessageExpressionBody(SourceLocation LBracLoc, if (Tok.is(tok::code_completion)) { if (SuperLoc.isValid()) - Actions.CodeCompleteObjCSuperMessage(getCurScope(), SuperLoc, 0, 0); + Actions.CodeCompleteObjCSuperMessage(getCurScope(), SuperLoc, 0, 0, + false); else if (ReceiverType) - Actions.CodeCompleteObjCClassMessage(getCurScope(), ReceiverType, 0, 0); + Actions.CodeCompleteObjCClassMessage(getCurScope(), ReceiverType, 0, 0, + false); else Actions.CodeCompleteObjCInstanceMessage(getCurScope(), ReceiverExpr, - 0, 0); + 0, 0, false); ConsumeCodeCompletionToken(); } @@ -2064,6 +2066,29 @@ Parser::ParseObjCMessageExpressionBody(SourceLocation LBracLoc, ConsumeToken(); // Eat the ':'. /// Parse the expression after ':' + + if (Tok.is(tok::code_completion)) { + if (SuperLoc.isValid()) + Actions.CodeCompleteObjCSuperMessage(getCurScope(), SuperLoc, + KeyIdents.data(), + KeyIdents.size(), + /*AtArgumentEpression=*/true); + else if (ReceiverType) + Actions.CodeCompleteObjCClassMessage(getCurScope(), ReceiverType, + KeyIdents.data(), + KeyIdents.size(), + /*AtArgumentEpression=*/true); + else + Actions.CodeCompleteObjCInstanceMessage(getCurScope(), ReceiverExpr, + KeyIdents.data(), + KeyIdents.size(), + /*AtArgumentEpression=*/true); + + ConsumeCodeCompletionToken(); + SkipUntil(tok::r_square); + return ExprError(); + } + ExprResult Res(ParseAssignmentExpression()); if (Res.isInvalid()) { // We must manually skip to a ']', otherwise the expression skipper will @@ -2081,16 +2106,21 @@ Parser::ParseObjCMessageExpressionBody(SourceLocation LBracLoc, if (SuperLoc.isValid()) Actions.CodeCompleteObjCSuperMessage(getCurScope(), SuperLoc, KeyIdents.data(), - KeyIdents.size()); + KeyIdents.size(), + /*AtArgumentEpression=*/false); else if (ReceiverType) Actions.CodeCompleteObjCClassMessage(getCurScope(), ReceiverType, KeyIdents.data(), - KeyIdents.size()); + KeyIdents.size(), + /*AtArgumentEpression=*/false); else Actions.CodeCompleteObjCInstanceMessage(getCurScope(), ReceiverExpr, KeyIdents.data(), - KeyIdents.size()); + KeyIdents.size(), + /*AtArgumentEpression=*/false); ConsumeCodeCompletionToken(); + SkipUntil(tok::r_square); + return ExprError(); } // Check for another keyword selector. diff --git a/lib/Sema/SemaCodeComplete.cpp b/lib/Sema/SemaCodeComplete.cpp index 4c05b15d8b..c3feb3b6a0 100644 --- a/lib/Sema/SemaCodeComplete.cpp +++ b/lib/Sema/SemaCodeComplete.cpp @@ -2645,6 +2645,7 @@ static void AddClassMessageCompletions(Sema &SemaRef, Scope *S, ParsedType Receiver, IdentifierInfo **SelIdents, unsigned NumSelIdents, + bool AtArgumentExpression, bool IsSuper, ResultBuilder &Results); @@ -2694,7 +2695,7 @@ void Sema::CodeCompleteDeclSpec(Scope *S, DeclSpec &DS, Scope::AtCatchScope)) == 0) { ParsedType T = DS.getRepAsType(); if (!T.get().isNull() && T.get()->isObjCObjectOrInterfaceType()) - AddClassMessageCompletions(*this, S, T, 0, 0, false, Results); + AddClassMessageCompletions(*this, S, T, 0, 0, false, false, Results); } // Note that we intentionally suppress macro results here, since we do not @@ -4295,7 +4296,8 @@ void Sema::CodeCompleteObjCMessageReceiver(Scope *S) { void Sema::CodeCompleteObjCSuperMessage(Scope *S, SourceLocation SuperLoc, IdentifierInfo **SelIdents, - unsigned NumSelIdents) { + unsigned NumSelIdents, + bool AtArgumentExpression) { ObjCInterfaceDecl *CDecl = 0; if (ObjCMethodDecl *CurMethod = getCurMethodDecl()) { // Figure out which interface we're in. @@ -4319,6 +4321,7 @@ void Sema::CodeCompleteObjCSuperMessage(Scope *S, SourceLocation SuperLoc, = Owned(new (Context) ObjCSuperExpr(SuperLoc, SuperTy)); return CodeCompleteObjCInstanceMessage(S, (Expr *)Super.get(), SelIdents, NumSelIdents, + AtArgumentExpression, /*IsSuper=*/true); } @@ -4344,7 +4347,8 @@ void Sema::CodeCompleteObjCSuperMessage(Scope *S, SourceLocation SuperLoc, id.setIdentifier(Super, SuperLoc); ExprResult SuperExpr = ActOnIdExpression(S, SS, id, false, false); return CodeCompleteObjCInstanceMessage(S, (Expr *)SuperExpr.get(), - SelIdents, NumSelIdents); + SelIdents, NumSelIdents, + AtArgumentExpression); } // Fall through @@ -4354,13 +4358,15 @@ void Sema::CodeCompleteObjCSuperMessage(Scope *S, SourceLocation SuperLoc, if (CDecl) Receiver = ParsedType::make(Context.getObjCInterfaceType(CDecl)); return CodeCompleteObjCClassMessage(S, Receiver, SelIdents, - NumSelIdents, /*IsSuper=*/true); + NumSelIdents, AtArgumentExpression, + /*IsSuper=*/true); } static void AddClassMessageCompletions(Sema &SemaRef, Scope *S, ParsedType Receiver, IdentifierInfo **SelIdents, unsigned NumSelIdents, + bool AtArgumentExpression, bool IsSuper, ResultBuilder &Results) { typedef CodeCompletionResult Result; @@ -4438,10 +4444,14 @@ static void AddClassMessageCompletions(Sema &SemaRef, Scope *S, void Sema::CodeCompleteObjCClassMessage(Scope *S, ParsedType Receiver, IdentifierInfo **SelIdents, unsigned NumSelIdents, + bool AtArgumentExpression, bool IsSuper) { + if (AtArgumentExpression) + return CodeCompleteOrdinaryName(S, PCC_Expression); + ResultBuilder Results(*this); - AddClassMessageCompletions(*this, S, Receiver, SelIdents, NumSelIdents, IsSuper, - Results); + AddClassMessageCompletions(*this, S, Receiver, SelIdents, NumSelIdents, + AtArgumentExpression, IsSuper, Results); HandleCodeCompleteResults(this, CodeCompleter, CodeCompletionContext::CCC_Other, Results.data(), Results.size()); @@ -4450,7 +4460,11 @@ void Sema::CodeCompleteObjCClassMessage(Scope *S, ParsedType Receiver, void Sema::CodeCompleteObjCInstanceMessage(Scope *S, ExprTy *Receiver, IdentifierInfo **SelIdents, unsigned NumSelIdents, + bool AtArgumentExpression, bool IsSuper) { + if (AtArgumentExpression) + return CodeCompleteOrdinaryName(S, PCC_Expression); + typedef CodeCompletionResult Result; Expr *RecExpr = static_cast(Receiver);