diff options
| author | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2011-01-03 19:44:02 +0000 |
|---|---|---|
| committer | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2011-01-03 19:44:02 +0000 |
| commit | 76dbe8c800c818d4ebe414999cf9e44834bb31a7 (patch) | |
| tree | 9744d27793db2969e1f6473160b0c0c0dac5cfe5 /clang/lib/Parse | |
| parent | 968f23ab97f1a6ee606c79911eec53c1b5d9f717 (diff) | |
| download | bcm5719-llvm-76dbe8c800c818d4ebe414999cf9e44834bb31a7.tar.gz bcm5719-llvm-76dbe8c800c818d4ebe414999cf9e44834bb31a7.zip | |
Speed up code-completion by skipping function bodies.
When we are in code-completion mode, skip parsing of all function bodies except the one where the
code-completion point resides.
For big .cpp files like 'SemaExpr.cpp' the improvement makes a huge difference, in some cases cutting down
code-completion time -62% !
We don't get diagnostics for the bodies though, so modify the code-completion tests that check for errors.
See rdar://8814203.
llvm-svn: 122765
Diffstat (limited to 'clang/lib/Parse')
| -rw-r--r-- | clang/lib/Parse/ParseStmt.cpp | 13 | ||||
| -rw-r--r-- | clang/lib/Parse/Parser.cpp | 12 |
2 files changed, 20 insertions, 5 deletions
diff --git a/clang/lib/Parse/ParseStmt.cpp b/clang/lib/Parse/ParseStmt.cpp index dafe3737783..d25cc110a8a 100644 --- a/clang/lib/Parse/ParseStmt.cpp +++ b/clang/lib/Parse/ParseStmt.cpp @@ -1466,6 +1466,19 @@ Decl *Parser::ParseFunctionStatementBody(Decl *Decl) { assert(Tok.is(tok::l_brace)); SourceLocation LBraceLoc = Tok.getLocation(); + // When in code-completion, skip parsing for all function bodies unless + // the body contains the code-completion point. + if (PP.isCodeCompletionEnabled()) { + TentativeParsingAction PA(*this); + ConsumeBrace(); + if (SkipUntil(tok::r_brace, /*StopAtSemi=*/false, /*DontConsume=*/false, + /*StopAtCodeCompletion=*/true)) { + PA.Commit(); + return Actions.ActOnFinishFunctionBody(Decl, 0); + } + PA.Revert(); + } + PrettyDeclStackTraceEntry CrashInfo(Actions, Decl, LBraceLoc, "parsing function body"); diff --git a/clang/lib/Parse/Parser.cpp b/clang/lib/Parse/Parser.cpp index 2a569b58d8c..aa0ad795cab 100644 --- a/clang/lib/Parse/Parser.cpp +++ b/clang/lib/Parse/Parser.cpp @@ -214,7 +214,8 @@ bool Parser::ExpectAndConsumeSemi(unsigned DiagID) { /// If SkipUntil finds the specified token, it returns true, otherwise it /// returns false. bool Parser::SkipUntil(const tok::TokenKind *Toks, unsigned NumToks, - bool StopAtSemi, bool DontConsume) { + bool StopAtSemi, bool DontConsume, + bool StopAtCodeCompletion) { // We always want this function to skip at least one token if the first token // isn't T and if not at EOF. bool isFirstTokenSkipped = true; @@ -237,23 +238,24 @@ bool Parser::SkipUntil(const tok::TokenKind *Toks, unsigned NumToks, return false; case tok::code_completion: - ConsumeToken(); + if (!StopAtCodeCompletion) + ConsumeToken(); return false; case tok::l_paren: // Recursively skip properly-nested parens. ConsumeParen(); - SkipUntil(tok::r_paren, false); + SkipUntil(tok::r_paren, false, false, StopAtCodeCompletion); break; case tok::l_square: // Recursively skip properly-nested square brackets. ConsumeBracket(); - SkipUntil(tok::r_square, false); + SkipUntil(tok::r_square, false, false, StopAtCodeCompletion); break; case tok::l_brace: // Recursively skip properly-nested braces. ConsumeBrace(); - SkipUntil(tok::r_brace, false); + SkipUntil(tok::r_brace, false, false, StopAtCodeCompletion); break; // Okay, we found a ']' or '}' or ')', which we think should be balanced. |

