From b302c500135157be705b4765b2e4c6274615a513 Mon Sep 17 00:00:00 2001 From: Chandler Carruth Date: Mon, 22 Feb 2021 17:16:27 -0800 Subject: [PATCH] Run clang-format over these inputs with the correct style configuration. (#278) --- lexer/tokenized_buffer.cpp | 44 ++++++++++++++------------------- lexer/tokenized_buffer_test.cpp | 43 ++++++++++++++++---------------- 2 files changed, 40 insertions(+), 47 deletions(-) diff --git a/lexer/tokenized_buffer.cpp b/lexer/tokenized_buffer.cpp index 67431ce4a367..3406e23625c3 100644 --- a/lexer/tokenized_buffer.cpp +++ b/lexer/tokenized_buffer.cpp @@ -31,9 +31,8 @@ static auto TakeLeadingIntegerLiteral(llvm::StringRef source_text) // // TODO(zygoloid): Update lexical rules to specify that an integer literal // cannot be immediately followed by another integer literal or a word. - return source_text.take_while([](char c) { - return llvm::isAlnum(c) || c == '_'; - }); + return source_text.take_while( + [](char c) { return llvm::isAlnum(c) || c == '_'; }); } struct UnmatchedClosing { @@ -59,27 +58,24 @@ struct MismatchedClosing { }; struct EmptyDigitSequence { - static constexpr llvm::StringLiteral ShortName = - "syntax-invalid-number"; + static constexpr llvm::StringLiteral ShortName = "syntax-invalid-number"; static constexpr llvm::StringLiteral Message = "Empty digit sequence in numeric literal."; - struct Substitutions { - }; + struct Substitutions {}; static auto Format(const Substitutions&) -> std::string { return Message.str(); } }; struct InvalidDigit { - static constexpr llvm::StringLiteral ShortName = - "syntax-invalid-number"; + static constexpr llvm::StringLiteral ShortName = "syntax-invalid-number"; struct Substitutions { char digit; unsigned radix; }; - static auto Format(const Substitutions &subst) -> std::string { + static auto Format(const Substitutions& subst) -> std::string { // TODO: Switch Format to using raw_ostream so we can easily use // llvm::format here. llvm::StringRef digit_str(&subst.digit, 1); @@ -92,13 +88,11 @@ struct InvalidDigit { }; struct InvalidDigitSeparator { - static constexpr llvm::StringLiteral ShortName = - "syntax-invalid-number"; + static constexpr llvm::StringLiteral ShortName = "syntax-invalid-number"; static constexpr llvm::StringLiteral Message = "Misplaced digit separator in numeric literal."; - struct Substitutions { - }; + struct Substitutions {}; static auto Format(const Substitutions&) -> std::string { return Message.str(); } @@ -111,7 +105,7 @@ struct IrregularDigitSeparators { struct Substitutions { unsigned radix; }; - static auto Format(const Substitutions &subst) -> std::string { + static auto Format(const Substitutions& subst) -> std::string { assert((subst.radix == 10 || subst.radix == 16) && "unexpected radix"); return (llvm::Twine("Digit separators in ") + (subst.radix == 10 ? "decimal" : "hexadecimal") + @@ -122,8 +116,7 @@ struct IrregularDigitSeparators { }; struct UnknownBaseSpecifier { - static constexpr llvm::StringLiteral ShortName = - "syntax-invalid-number"; + static constexpr llvm::StringLiteral ShortName = "syntax-invalid-number"; static constexpr llvm::StringLiteral Message = "Unknown base specifier in numeric literal."; @@ -250,7 +243,7 @@ class TokenizedBuffer::Lexer { auto diagnose_irregular_digit_separators = [&] { emitter.EmitError( - [&](IrregularDigitSeparators::Substitutions &subst) { + [&](IrregularDigitSeparators::Substitutions& subst) { subst.radix = radix; }); buffer.has_errors = true; @@ -284,7 +277,7 @@ class TokenizedBuffer::Lexer { if (text.empty()) { emitter.EmitError( - [&](EmptyDigitSequence::Substitutions &) {}); + [&](EmptyDigitSequence::Substitutions&) {}); return {.ok = false}; } @@ -313,18 +306,17 @@ class TokenizedBuffer::Lexer { // next to another digit separator, or at the end. if (i == 0 || text[i - 1] == '_' || i + 1 == n) { emitter.EmitError( - [&](InvalidDigitSeparator::Substitutions &) {}); + [&](InvalidDigitSeparator::Substitutions&) {}); buffer.has_errors = true; } ++num_digit_separators; continue; } - emitter.EmitError( - [&](InvalidDigit::Substitutions &subst) { - subst.digit = c; - subst.radix = radix; - }); + emitter.EmitError([&](InvalidDigit::Substitutions& subst) { + subst.digit = c; + subst.radix = radix; + }); return {.ok = false}; } @@ -373,7 +365,7 @@ class TokenizedBuffer::Lexer { digits = digits.drop_front(2); } else { emitter.EmitError( - [&](UnknownBaseSpecifier::Substitutions &subst) {}); + [&](UnknownBaseSpecifier::Substitutions& subst) {}); return add_error_token_and_continue_lexing(); } } diff --git a/lexer/tokenized_buffer_test.cpp b/lexer/tokenized_buffer_test.cpp index 39c2756eecab..f9f743c1c064 100644 --- a/lexer/tokenized_buffer_test.cpp +++ b/lexer/tokenized_buffer_test.cpp @@ -155,11 +155,11 @@ TEST_F(LexerTest, ValidatesBaseSpecifier) { auto buffer = Lex(literal); EXPECT_FALSE(buffer.HasErrors()) << literal; ASSERT_THAT(buffer, HasTokens(llvm::ArrayRef{ - {.kind = TokenKind::IntegerLiteral(), - .line = 1, - .column = 1, - .indent_column = 1, - .text = literal}})); + {.kind = TokenKind::IntegerLiteral(), + .line = 1, + .column = 1, + .indent_column = 1, + .text = literal}})); } llvm::StringLiteral invalid[] = { @@ -170,12 +170,13 @@ TEST_F(LexerTest, ValidatesBaseSpecifier) { for (llvm::StringLiteral literal : invalid) { auto buffer = Lex(literal); EXPECT_TRUE(buffer.HasErrors()) << literal; - ASSERT_THAT(buffer, HasTokens(llvm::ArrayRef{ - {.kind = TokenKind::Error(), - .line = 1, - .column = 1, - .indent_column = 1, - .text = literal}})); + ASSERT_THAT( + buffer, + HasTokens(llvm::ArrayRef{{.kind = TokenKind::Error(), + .line = 1, + .column = 1, + .indent_column = 1, + .text = literal}})); } } @@ -199,11 +200,11 @@ TEST_F(LexerTest, ValidatesIntegerDigitSeparators) { auto buffer = Lex(literal); EXPECT_FALSE(buffer.HasErrors()) << literal; ASSERT_THAT(buffer, HasTokens(llvm::ArrayRef{ - {.kind = TokenKind::IntegerLiteral(), - .line = 1, - .column = 1, - .indent_column = 1, - .text = literal}})); + {.kind = TokenKind::IntegerLiteral(), + .line = 1, + .column = 1, + .indent_column = 1, + .text = literal}})); } llvm::StringLiteral invalid[] = { @@ -233,11 +234,11 @@ TEST_F(LexerTest, ValidatesIntegerDigitSeparators) { // We expect to produce a token even for a literal containing invalid digit // separators, for better error recovery. ASSERT_THAT(buffer, HasTokens(llvm::ArrayRef{ - {.kind = TokenKind::IntegerLiteral(), - .line = 1, - .column = 1, - .indent_column = 1, - .text = literal}})); + {.kind = TokenKind::IntegerLiteral(), + .line = 1, + .column = 1, + .indent_column = 1, + .text = literal}})); } }