diff options
author | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2013-03-27 23:58:17 +0000 |
---|---|---|
committer | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2013-03-27 23:58:17 +0000 |
commit | ab2d09b6287a5dc6fa94d78739444f46f9a78bfb (patch) | |
tree | 7a62b8c92f336d0f808511786548b3247fdbc3da | |
parent | 9807a2e0ddb1eafb8725dbf0247271a4a694037b (diff) |
[Parser] Don't code-complete twice.
When we are consuming the current token just to enter a new token stream, we push
the current token in the back of the stream so that we get it again.
Unfortunately this had the effect where if the current token is a code-completion one,
we would code-complete once during consuming it and another time after the stream ended.
Fix this by making sure that, in this case, ConsumeAnyToken() will consume a code-completion
token without invoking code-completion.
rdar://12842503
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@178199 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | include/clang/Parse/Parser.h | 8 | ||||
-rw-r--r-- | lib/Parse/ParseCXXInlineMethods.cpp | 4 | ||||
-rw-r--r-- | lib/Parse/ParseDecl.cpp | 2 | ||||
-rw-r--r-- | lib/Parse/ParseObjc.cpp | 2 | ||||
-rw-r--r-- | lib/Parse/ParseTemplate.cpp | 2 | ||||
-rw-r--r-- | test/Index/complete-declarators.m | 6 |
6 files changed, 15 insertions, 9 deletions
diff --git a/include/clang/Parse/Parser.h b/include/clang/Parse/Parser.h index de18b86da0..1ac0f3be5e 100644 --- a/include/clang/Parse/Parser.h +++ b/include/clang/Parse/Parser.h @@ -247,12 +247,12 @@ public: /// This does not work with all kinds of tokens: strings and specific other /// tokens must be consumed with custom methods below. This returns the /// location of the consumed token. - SourceLocation ConsumeToken() { + SourceLocation ConsumeToken(bool ConsumeCodeCompletionTok = false) { assert(!isTokenStringLiteral() && !isTokenParen() && !isTokenBracket() && !isTokenBrace() && "Should consume special tokens with Consume*Token"); - if (Tok.is(tok::code_completion)) + if (!ConsumeCodeCompletionTok && Tok.is(tok::code_completion)) return handleUnexpectedCodeCompletionToken(); PrevTokLocation = Tok.getLocation(); @@ -291,7 +291,7 @@ private: /// ConsumeAnyToken - Dispatch to the right Consume* method based on the /// current token type. This should only be used in cases where the type of /// the token really isn't known, e.g. in error recovery. - SourceLocation ConsumeAnyToken() { + SourceLocation ConsumeAnyToken(bool ConsumeCodeCompletionTok = false) { if (isTokenParen()) return ConsumeParen(); else if (isTokenBracket()) @@ -301,7 +301,7 @@ private: else if (isTokenStringLiteral()) return ConsumeStringToken(); else - return ConsumeToken(); + return ConsumeToken(ConsumeCodeCompletionTok); } /// ConsumeParen - This consume method keeps the paren count up-to-date. diff --git a/lib/Parse/ParseCXXInlineMethods.cpp b/lib/Parse/ParseCXXInlineMethods.cpp index 30aee20b26..bc634b57d9 100644 --- a/lib/Parse/ParseCXXInlineMethods.cpp +++ b/lib/Parse/ParseCXXInlineMethods.cpp @@ -407,7 +407,7 @@ void Parser::ParseLexedMethodDef(LexedMethod &LM) { PP.EnterTokenStream(LM.Toks.data(), LM.Toks.size(), true, false); // Consume the previously pushed token. - ConsumeAnyToken(); + ConsumeAnyToken(/*ConsumeCodeCompletionTok=*/true); assert((Tok.is(tok::l_brace) || Tok.is(tok::colon) || Tok.is(tok::kw_try)) && "Inline method not starting with '{', ':' or 'try'"); @@ -510,7 +510,7 @@ void Parser::ParseLexedMemberInitializer(LateParsedMemberInitializer &MI) { PP.EnterTokenStream(MI.Toks.data(), MI.Toks.size(), true, false); // Consume the previously pushed token. - ConsumeAnyToken(); + ConsumeAnyToken(/*ConsumeCodeCompletionTok=*/true); SourceLocation EqualLoc; diff --git a/lib/Parse/ParseDecl.cpp b/lib/Parse/ParseDecl.cpp index 4d1147b5df..7dfbf5ff86 100644 --- a/lib/Parse/ParseDecl.cpp +++ b/lib/Parse/ParseDecl.cpp @@ -931,7 +931,7 @@ void Parser::ParseLexedAttribute(LateParsedAttribute &LA, LA.Toks.push_back(Tok); PP.EnterTokenStream(LA.Toks.data(), LA.Toks.size(), true, false); // Consume the previously pushed token. - ConsumeAnyToken(); + ConsumeAnyToken(/*ConsumeCodeCompletionTok=*/true); if (OnDefinition && !IsThreadSafetyAttribute(LA.AttrName.getName())) { // FIXME: Do not warn on C++11 attributes, once we start supporting diff --git a/lib/Parse/ParseObjc.cpp b/lib/Parse/ParseObjc.cpp index e4a880e89a..fb0237ac05 100644 --- a/lib/Parse/ParseObjc.cpp +++ b/lib/Parse/ParseObjc.cpp @@ -2896,7 +2896,7 @@ void Parser::ParseLexedObjCMethodDefs(LexedMethod &LM, bool parseMethod) { PP.EnterTokenStream(LM.Toks.data(), LM.Toks.size(), true, false); // Consume the previously pushed token. - ConsumeAnyToken(); + ConsumeAnyToken(/*ConsumeCodeCompletionTok=*/true); assert((Tok.is(tok::l_brace) || Tok.is(tok::kw_try) || Tok.is(tok::colon)) && diff --git a/lib/Parse/ParseTemplate.cpp b/lib/Parse/ParseTemplate.cpp index 1327dd59e5..f14666922b 100644 --- a/lib/Parse/ParseTemplate.cpp +++ b/lib/Parse/ParseTemplate.cpp @@ -1305,7 +1305,7 @@ void Parser::ParseLateTemplatedFuncDef(LateParsedTemplatedFunction &LMT) { PP.EnterTokenStream(LMT.Toks.data(), LMT.Toks.size(), true, false); // Consume the previously pushed token. - ConsumeAnyToken(); + ConsumeAnyToken(/*ConsumeCodeCompletionTok=*/true); assert((Tok.is(tok::l_brace) || Tok.is(tok::colon) || Tok.is(tok::kw_try)) && "Inline method not starting with '{', ':' or 'try'"); diff --git a/test/Index/complete-declarators.m b/test/Index/complete-declarators.m index d42a3c7a6c..b3a60ded11 100644 --- a/test/Index/complete-declarators.m +++ b/test/Index/complete-declarators.m @@ -22,6 +22,7 @@ static P *p = 0; } +- (boid)method2 {} @end // RUN: c-index-test -code-completion-at=%s:7:4 %s | FileCheck -check-prefix=CHECK-CC0 %s @@ -81,3 +82,8 @@ // CHECK-CC5: NotImplemented:{TypedText unsigned} (50) // CHECK-CC5: NotImplemented:{TypedText void} (50) // CHECK-CC5: NotImplemented:{TypedText volatile} (50) + +// Check that there are no duplicate entries if we code-complete after an @implementation +// RUN: c-index-test -code-completion-at=%s:27:1 %s | FileCheck -check-prefix=CHECK-CC6 %s +// CHECK-CC6: ObjCInterfaceDecl:{TypedText A} +// CHECK-CC6-NOT: ObjCInterfaceDecl:{TypedText A} |