[cfe-commits] r114375 - in /cfe/trunk: include/clang/Sema/Sema.h lib/Parse/ParseObjc.cpp lib/Sema/SemaCodeComplete.cpp
Douglas Gregor
dgregor at apple.com
Mon Sep 20 16:34:21 PDT 2010
Author: dgregor
Date: Mon Sep 20 18:34:21 2010
New Revision: 114375
URL: http://llvm.org/viewvc/llvm-project?rev=114375&view=rev
Log:
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.
Modified:
cfe/trunk/include/clang/Sema/Sema.h
cfe/trunk/lib/Parse/ParseObjc.cpp
cfe/trunk/lib/Sema/SemaCodeComplete.cpp
Modified: cfe/trunk/include/clang/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=114375&r1=114374&r2=114375&view=diff
==============================================================================
--- cfe/trunk/include/clang/Sema/Sema.h (original)
+++ cfe/trunk/include/clang/Sema/Sema.h Mon Sep 20 18:34:21 2010
@@ -4351,14 +4351,17 @@
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);
Modified: cfe/trunk/lib/Parse/ParseObjc.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseObjc.cpp?rev=114375&r1=114374&r2=114375&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseObjc.cpp (original)
+++ cfe/trunk/lib/Parse/ParseObjc.cpp Mon Sep 20 18:34:21 2010
@@ -2030,12 +2030,14 @@
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 @@
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 @@
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.
Modified: cfe/trunk/lib/Sema/SemaCodeComplete.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaCodeComplete.cpp?rev=114375&r1=114374&r2=114375&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaCodeComplete.cpp (original)
+++ cfe/trunk/lib/Sema/SemaCodeComplete.cpp Mon Sep 20 18:34:21 2010
@@ -2645,6 +2645,7 @@
ParsedType Receiver,
IdentifierInfo **SelIdents,
unsigned NumSelIdents,
+ bool AtArgumentExpression,
bool IsSuper,
ResultBuilder &Results);
@@ -2694,7 +2695,7 @@
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::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 @@
= Owned(new (Context) ObjCSuperExpr(SuperLoc, SuperTy));
return CodeCompleteObjCInstanceMessage(S, (Expr *)Super.get(),
SelIdents, NumSelIdents,
+ AtArgumentExpression,
/*IsSuper=*/true);
}
@@ -4344,7 +4347,8 @@
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 @@
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 @@
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::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<Expr *>(Receiver);
More information about the cfe-commits
mailing list