diff options
Diffstat (limited to 'clang/lib/Format/FormatTokenLexer.cpp')
-rw-r--r-- | clang/lib/Format/FormatTokenLexer.cpp | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/clang/lib/Format/FormatTokenLexer.cpp b/clang/lib/Format/FormatTokenLexer.cpp index a4c94ac..bff9db2 100644 --- a/clang/lib/Format/FormatTokenLexer.cpp +++ b/clang/lib/Format/FormatTokenLexer.cpp @@ -83,8 +83,43 @@ FormatTokenLexer::FormatTokenLexer( ArrayRef<FormatToken *> FormatTokenLexer::lex() { assert(Tokens.empty()); assert(FirstInLineIndex == 0); + const llvm::Regex FormatOffRegex(Style.OneLineFormatOffRegex); + enum { FO_None, FO_CurrentLine, FO_NextLine } FormatOff = FO_None; do { Tokens.push_back(getNextToken()); + auto &Tok = *Tokens.back(); + const auto NewlinesBefore = Tok.NewlinesBefore; + switch (FormatOff) { + case FO_CurrentLine: + if (NewlinesBefore == 0) + Tok.Finalized = true; + else + FormatOff = FO_None; + break; + case FO_NextLine: + if (NewlinesBefore > 1) { + FormatOff = FO_None; + } else { + Tok.Finalized = true; + FormatOff = FO_CurrentLine; + } + break; + default: + if (!FormattingDisabled && FormatOffRegex.match(Tok.TokenText)) { + if (Tok.is(tok::comment) && + (NewlinesBefore > 0 || &Tok == Tokens.front())) { + Tok.Finalized = true; + FormatOff = FO_NextLine; + } else { + for (auto *Token : reverse(Tokens)) { + Token->Finalized = true; + if (Token->NewlinesBefore > 0) + break; + } + FormatOff = FO_CurrentLine; + } + } + } if (Style.isJavaScript()) { tryParseJSRegexLiteral(); handleTemplateStrings(); |