diff options
Diffstat (limited to 'lib/Format/UnwrappedLineParser.cpp')
-rw-r--r-- | lib/Format/UnwrappedLineParser.cpp | 51 |
1 files changed, 17 insertions, 34 deletions
diff --git a/lib/Format/UnwrappedLineParser.cpp b/lib/Format/UnwrappedLineParser.cpp index 939528fbffe5..6ad43294ca97 100644 --- a/lib/Format/UnwrappedLineParser.cpp +++ b/lib/Format/UnwrappedLineParser.cpp @@ -887,9 +887,8 @@ void UnwrappedLineParser::parseStructuralElement() { // followed by a curly. if (FormatTok->is(TT_JsFatArrow)) { nextToken(); - if (FormatTok->is(tok::l_brace)) { + if (FormatTok->is(tok::l_brace)) parseChildBlock(); - } break; } @@ -912,6 +911,10 @@ void UnwrappedLineParser::parseStructuralElement() { } bool UnwrappedLineParser::tryToParseLambda() { + if (Style.Language != FormatStyle::LK_Cpp) { + nextToken(); + return false; + } // FIXME: This is a dirty way to access the previous token. Find a better // solution. if (!Line->Tokens.empty() && @@ -950,7 +953,7 @@ bool UnwrappedLineParser::tryToParseLambda() { nextToken(); break; case tok::arrow: - FormatTok->Type = TT_TrailingReturnArrow; + FormatTok->Type = TT_LambdaArrow; nextToken(); break; default: @@ -1019,7 +1022,7 @@ void UnwrappedLineParser::tryToParseJSFunction() { return; // Parse formal parameter list. - parseBalanced(tok::l_paren, tok::r_paren); + parseParens(); if (FormatTok->is(tok::colon)) { // Parse a type definition. @@ -1027,34 +1030,16 @@ void UnwrappedLineParser::tryToParseJSFunction() { // Eat the type declaration. For braced inline object types, balance braces, // otherwise just parse until finding an l_brace for the function body. - if (FormatTok->is(tok::l_brace)) { - parseBalanced(tok::l_brace, tok::r_brace); - } else { - while(FormatTok->isNot(tok::l_brace) && !eof()) { + if (FormatTok->is(tok::l_brace)) + tryToParseBracedList(); + else + while(FormatTok->isNot(tok::l_brace) && !eof()) nextToken(); - } - } } parseChildBlock(); } -void UnwrappedLineParser::parseBalanced(tok::TokenKind OpenKind, - tok::TokenKind CloseKind) { - assert(FormatTok->is(OpenKind)); - nextToken(); - int Depth = 1; - while (Depth > 0 && !eof()) { - // Parse the formal parameter list. - if (FormatTok->is(OpenKind)) { - ++Depth; - } else if (FormatTok->is(CloseKind)) { - --Depth; - } - nextToken(); - } -} - bool UnwrappedLineParser::tryToParseBracedList() { if (FormatTok->BlockKind == BK_Unknown) calculateBraceTypes(); @@ -1076,7 +1061,8 @@ bool UnwrappedLineParser::parseBracedList(bool ContinueOnSemicolons) { if (FormatTok->is(Keywords.kw_function)) { tryToParseJSFunction(); continue; - } else if (FormatTok->is(TT_JsFatArrow)) { + } + if (FormatTok->is(TT_JsFatArrow)) { nextToken(); // Fat arrows can be followed by simple expressions or by child blocks // in curly braces. @@ -1780,15 +1766,12 @@ void UnwrappedLineParser::addUnwrappedLine() { if (CurrentLines == &Lines) printDebugInfo(*Line); }); - CurrentLines->push_back(*Line); + CurrentLines->push_back(std::move(*Line)); Line->Tokens.clear(); if (CurrentLines == &Lines && !PreprocessorDirectives.empty()) { - for (SmallVectorImpl<UnwrappedLine>::iterator - I = PreprocessorDirectives.begin(), - E = PreprocessorDirectives.end(); - I != E; ++I) { - CurrentLines->push_back(*I); - } + CurrentLines->append( + std::make_move_iterator(PreprocessorDirectives.begin()), + std::make_move_iterator(PreprocessorDirectives.end())); PreprocessorDirectives.clear(); } } |