diff options
| author | 2017-01-24 08:32:59 +0000 | |
|---|---|---|
| committer | 2017-01-24 08:32:59 +0000 | |
| commit | 53d771aafdbe5b919f264f53cba3788e2c4cffd2 (patch) | |
| tree | 7eca39498be0ff1e3a6daf583cd9ca5886bb2636 /gnu/llvm/tools/clang/lib/Format/UnwrappedLineParser.cpp | |
| parent | In preparation of compiling our kernels with -ffreestanding, explicitly map (diff) | |
| download | wireguard-openbsd-53d771aafdbe5b919f264f53cba3788e2c4cffd2.tar.xz wireguard-openbsd-53d771aafdbe5b919f264f53cba3788e2c4cffd2.zip | |
Import LLVM 4.0.0 rc1 including clang and lld to help the current
development effort on OpenBSD/arm64.
Diffstat (limited to 'gnu/llvm/tools/clang/lib/Format/UnwrappedLineParser.cpp')
| -rw-r--r-- | gnu/llvm/tools/clang/lib/Format/UnwrappedLineParser.cpp | 69 |
1 files changed, 45 insertions, 24 deletions
diff --git a/gnu/llvm/tools/clang/lib/Format/UnwrappedLineParser.cpp b/gnu/llvm/tools/clang/lib/Format/UnwrappedLineParser.cpp index 2fe72987bc7..8fc3b78aee0 100644 --- a/gnu/llvm/tools/clang/lib/Format/UnwrappedLineParser.cpp +++ b/gnu/llvm/tools/clang/lib/Format/UnwrappedLineParser.cpp @@ -360,14 +360,15 @@ void UnwrappedLineParser::calculateBraceTypes(bool ExpectClassBody) { // BlockKind later if we parse a braced list (where all blocks // inside are by default braced lists), or when we explicitly detect // blocks (for example while parsing lambdas). - // - // We exclude + and - as they can be ObjC visibility modifiers. ProbablyBracedList = (Style.Language == FormatStyle::LK_JavaScript && - NextTok->isOneOf(Keywords.kw_of, Keywords.kw_in)) || + NextTok->isOneOf(Keywords.kw_of, Keywords.kw_in, + Keywords.kw_as)) || NextTok->isOneOf(tok::comma, tok::period, tok::colon, tok::r_paren, tok::r_square, tok::l_brace, tok::l_square, tok::l_paren, tok::ellipsis) || + (NextTok->is(tok::identifier) && + !PrevTok->isOneOf(tok::semi, tok::r_brace, tok::l_brace)) || (NextTok->is(tok::semi) && (!ExpectClassBody || LBraceStack.size() != 1)) || (NextTok->isBinaryOperator() && !NextIsObjCMethod); @@ -668,19 +669,21 @@ static bool mustBeJSIdent(const AdditionalKeywords &Keywords, // FIXME: This returns true for C/C++ keywords like 'struct'. return FormatTok->is(tok::identifier) && (FormatTok->Tok.getIdentifierInfo() == nullptr || - !FormatTok->isOneOf(Keywords.kw_in, Keywords.kw_of, Keywords.kw_as, - Keywords.kw_async, Keywords.kw_await, - Keywords.kw_yield, Keywords.kw_finally, - Keywords.kw_function, Keywords.kw_import, - Keywords.kw_is, Keywords.kw_let, Keywords.kw_var, - Keywords.kw_abstract, Keywords.kw_extends, - Keywords.kw_implements, Keywords.kw_instanceof, - Keywords.kw_interface, Keywords.kw_throws)); + !FormatTok->isOneOf( + Keywords.kw_in, Keywords.kw_of, Keywords.kw_as, Keywords.kw_async, + Keywords.kw_await, Keywords.kw_yield, Keywords.kw_finally, + Keywords.kw_function, Keywords.kw_import, Keywords.kw_is, + Keywords.kw_let, Keywords.kw_var, tok::kw_const, + Keywords.kw_abstract, Keywords.kw_extends, Keywords.kw_implements, + Keywords.kw_instanceof, Keywords.kw_interface, + Keywords.kw_throws)); } static bool mustBeJSIdentOrValue(const AdditionalKeywords &Keywords, const FormatToken *FormatTok) { - return FormatTok->Tok.isLiteral() || mustBeJSIdent(Keywords, FormatTok); + return FormatTok->Tok.isLiteral() || + FormatTok->isOneOf(tok::kw_true, tok::kw_false) || + mustBeJSIdent(Keywords, FormatTok); } // isJSDeclOrStmt returns true if |FormatTok| starts a declaration or statement @@ -724,6 +727,8 @@ void UnwrappedLineParser::readTokenWithJavaScriptASI() { return; bool PreviousMustBeValue = mustBeJSIdentOrValue(Keywords, Previous); + bool PreviousStartsTemplateExpr = + Previous->is(TT_TemplateString) && Previous->TokenText.endswith("${"); if (PreviousMustBeValue && Line && Line->Tokens.size() > 1) { // If the token before the previous one is an '@', the previous token is an // annotation and can precede another identifier/value. @@ -732,14 +737,18 @@ void UnwrappedLineParser::readTokenWithJavaScriptASI() { return; } if (Next->is(tok::exclaim) && PreviousMustBeValue) - addUnwrappedLine(); + return addUnwrappedLine(); bool NextMustBeValue = mustBeJSIdentOrValue(Keywords, Next); - if (NextMustBeValue && (PreviousMustBeValue || - Previous->isOneOf(tok::r_square, tok::r_paren, - tok::plusplus, tok::minusminus))) - addUnwrappedLine(); - if (PreviousMustBeValue && isJSDeclOrStmt(Keywords, Next)) - addUnwrappedLine(); + bool NextEndsTemplateExpr = + Next->is(TT_TemplateString) && Next->TokenText.startswith("}"); + if (NextMustBeValue && !NextEndsTemplateExpr && !PreviousStartsTemplateExpr && + (PreviousMustBeValue || + Previous->isOneOf(tok::r_square, tok::r_paren, tok::plusplus, + tok::minusminus))) + return addUnwrappedLine(); + if ((PreviousMustBeValue || Previous->is(tok::r_brace)) && + isJSDeclOrStmt(Keywords, Next)) + return addUnwrappedLine(); } void UnwrappedLineParser::parseStructuralElement() { @@ -906,8 +915,8 @@ void UnwrappedLineParser::parseStructuralElement() { if (FormatTok->is(tok::colon)) { nextToken(); addUnwrappedLine(); + return; } - return; } // In all other cases, parse the declaration. break; @@ -1222,9 +1231,11 @@ void UnwrappedLineParser::tryToParseJSFunction() { // Consume "function". nextToken(); - // Consume * (generator function). - if (FormatTok->is(tok::star)) + // Consume * (generator function). Treat it like C++'s overloaded operators. + if (FormatTok->is(tok::star)) { + FormatTok->Type = TT_OverloadedOperator; nextToken(); + } // Consume function name. if (FormatTok->is(tok::identifier)) @@ -1245,10 +1256,13 @@ void UnwrappedLineParser::tryToParseJSFunction() { if (FormatTok->is(tok::l_brace)) tryToParseBracedList(); else - while (FormatTok->isNot(tok::l_brace) && !eof()) + while (!FormatTok->isOneOf(tok::l_brace, tok::semi) && !eof()) nextToken(); } + if (FormatTok->is(tok::semi)) + return; + parseChildBlock(); } @@ -1961,7 +1975,14 @@ void UnwrappedLineParser::parseJavaScriptEs6ImportExport() { !FormatTok->isStringLiteral()) return; - while (!eof() && FormatTok->isNot(tok::semi)) { + while (!eof()) { + if (FormatTok->is(tok::semi)) + return; + if (Line->Tokens.size() == 0) { + // Common issue: Automatic Semicolon Insertion wrapped the line, so the + // import statement should terminate. + return; + } if (FormatTok->is(tok::l_brace)) { FormatTok->BlockKind = BK_Block; parseBracedList(); |
