aboutsummaryrefslogtreecommitdiff
path: root/lib/Parse/Parser.cpp
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2010-05-25 05:58:43 +0000
committerDouglas Gregor <dgregor@apple.com>2010-05-25 05:58:43 +0000
commitdc8453422bec3bbf70c03920e01498d75783d122 (patch)
treed5b85f0cac85117aee6dba355777536efdb8022f /lib/Parse/Parser.cpp
parentab28099e3bd4859585ccb316f9f571c8c6b035fd (diff)
Improve code completion in failure cases in two ways:
1) Suppress diagnostics as soon as we form the code-completion token, so we don't get any error/warning spew from the early end-of-file. 2) If we consume a code-completion token when we weren't expecting one, go into a code-completion recovery path that produces the best results it can based on the context that the parser is in. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@104585 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Parse/Parser.cpp')
-rw-r--r--lib/Parse/Parser.cpp26
1 files changed, 23 insertions, 3 deletions
diff --git a/lib/Parse/Parser.cpp b/lib/Parse/Parser.cpp
index 37475d23fe..8407db1916 100644
--- a/lib/Parse/Parser.cpp
+++ b/lib/Parse/Parser.cpp
@@ -134,7 +134,7 @@ SourceLocation Parser::MatchRHSPunctuation(tok::TokenKind RHSTok,
/// returned.
bool Parser::ExpectAndConsume(tok::TokenKind ExpectedTok, unsigned DiagID,
const char *Msg, tok::TokenKind SkipToTok) {
- if (Tok.is(ExpectedTok)) {
+ if (Tok.is(ExpectedTok) || Tok.is(tok::code_completion)) {
ConsumeAnyToken();
return false;
}
@@ -189,7 +189,11 @@ bool Parser::SkipUntil(const tok::TokenKind *Toks, unsigned NumToks,
case tok::eof:
// Ran out of tokens.
return false;
-
+
+ case tok::code_completion:
+ ConsumeToken();
+ return false;
+
case tok::l_paren:
// Recursively skip properly-nested parens.
ConsumeParen();
@@ -447,7 +451,7 @@ Parser::DeclGroupPtrTy Parser::ParseExternalDeclaration(CXX0XAttributeList Attr)
Actions.CodeCompleteOrdinaryName(CurScope,
ObjCImpDecl? Action::CCC_ObjCImplementation
: Action::CCC_Namespace);
- ConsumeToken();
+ ConsumeCodeCompletionToken();
return ParseExternalDeclaration(Attr);
case tok::kw_using:
case tok::kw_namespace:
@@ -1072,6 +1076,22 @@ bool Parser::TryAnnotateCXXScopeToken(bool EnteringContext) {
return false;
}
+void Parser::CodeCompletionRecovery() {
+ for (Scope *S = CurScope; S; S = S->getParent()) {
+ if (S->getFlags() & Scope::FnScope) {
+ Actions.CodeCompleteOrdinaryName(CurScope, Action::CCC_RecoveryInFunction);
+ return;
+ }
+
+ if (S->getFlags() & Scope::ClassScope) {
+ Actions.CodeCompleteOrdinaryName(CurScope, Action::CCC_Class);
+ return;
+ }
+ }
+
+ Actions.CodeCompleteOrdinaryName(CurScope, Action::CCC_Namespace);
+}
+
// Anchor the Parser::FieldCallback vtable to this translation unit.
// We use a spurious method instead of the destructor because
// destroying FieldCallbacks can actually be slightly