diff options
author | Owen Pan <owenpiano@gmail.com> | 2025-04-09 17:49:26 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-04-09 17:49:26 -0700 |
commit | 75cbb1f0fa734efb79c1a1233f1aba377dfad9e1 (patch) | |
tree | c258f9c8fa2769125ac679e5dd91063993cfae65 /clang/lib/Format/UnwrappedLineParser.cpp | |
parent | 56b792322aaaa82883d56a322a94448de519f789 (diff) | |
download | llvm-75cbb1f0fa734efb79c1a1233f1aba377dfad9e1.zip llvm-75cbb1f0fa734efb79c1a1233f1aba377dfad9e1.tar.gz llvm-75cbb1f0fa734efb79c1a1233f1aba377dfad9e1.tar.bz2 |
[clang-format][NFC] Add FormatToken::is(tok::ObjCKeywordKind) (#134973)
This allows simplification of code that checks if a token is an
Objective-C keyword.
Also, delete the following in
UnwrappedLineParser::parseStructuralElement():
- an else-after-break in the tok::at case
- the copypasted code in the tok::objc_autoreleasepool case
Diffstat (limited to 'clang/lib/Format/UnwrappedLineParser.cpp')
-rw-r--r-- | clang/lib/Format/UnwrappedLineParser.cpp | 43 |
1 files changed, 15 insertions, 28 deletions
diff --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp index 9641da1..b49e80b 100644 --- a/clang/lib/Format/UnwrappedLineParser.cpp +++ b/clang/lib/Format/UnwrappedLineParser.cpp @@ -1719,12 +1719,13 @@ void UnwrappedLineParser::parseStructuralElement( nextToken(); parseBracedList(); break; - } else if (Style.Language == FormatStyle::LK_Java && - FormatTok->is(Keywords.kw_interface)) { + } + if (Style.Language == FormatStyle::LK_Java && + FormatTok->is(Keywords.kw_interface)) { nextToken(); break; } - switch (FormatTok->Tok.getObjCKeywordID()) { + switch (bool IsAutoRelease = false; FormatTok->Tok.getObjCKeywordID()) { case tok::objc_public: case tok::objc_protected: case tok::objc_package: @@ -1745,19 +1746,11 @@ void UnwrappedLineParser::parseStructuralElement( addUnwrappedLine(); return; case tok::objc_autoreleasepool: - nextToken(); - if (FormatTok->is(tok::l_brace)) { - if (Style.BraceWrapping.AfterControlStatement == - FormatStyle::BWACS_Always) { - addUnwrappedLine(); - } - parseBlock(); - } - addUnwrappedLine(); - return; + IsAutoRelease = true; + [[fallthrough]]; case tok::objc_synchronized: nextToken(); - if (FormatTok->is(tok::l_paren)) { + if (!IsAutoRelease && FormatTok->is(tok::l_paren)) { // Skip synchronization object parseParens(); } @@ -3086,11 +3079,10 @@ void UnwrappedLineParser::parseTryCatch() { if (FormatTok->is(tok::at)) nextToken(); if (!(FormatTok->isOneOf(tok::kw_catch, Keywords.kw___except, - tok::kw___finally) || + tok::kw___finally, tok::objc_catch, + tok::objc_finally) || ((Style.Language == FormatStyle::LK_Java || Style.isJavaScript()) && - FormatTok->is(Keywords.kw_finally)) || - (FormatTok->isObjCAtKeyword(tok::objc_catch) || - FormatTok->isObjCAtKeyword(tok::objc_finally)))) { + FormatTok->is(Keywords.kw_finally)))) { break; } nextToken(); @@ -4162,17 +4154,15 @@ void UnwrappedLineParser::parseObjCProtocolList() { do { nextToken(); // Early exit in case someone forgot a close angle. - if (FormatTok->isOneOf(tok::semi, tok::l_brace) || - FormatTok->isObjCAtKeyword(tok::objc_end)) { + if (FormatTok->isOneOf(tok::semi, tok::l_brace, tok::objc_end)) return; - } } while (!eof() && FormatTok->isNot(tok::greater)); nextToken(); // Skip '>'. } void UnwrappedLineParser::parseObjCUntilAtEnd() { do { - if (FormatTok->isObjCAtKeyword(tok::objc_end)) { + if (FormatTok->is(tok::objc_end)) { nextToken(); addUnwrappedLine(); break; @@ -4195,8 +4185,7 @@ void UnwrappedLineParser::parseObjCUntilAtEnd() { } void UnwrappedLineParser::parseObjCInterfaceOrImplementation() { - assert(FormatTok->Tok.getObjCKeywordID() == tok::objc_interface || - FormatTok->Tok.getObjCKeywordID() == tok::objc_implementation); + assert(FormatTok->isOneOf(tok::objc_interface, tok::objc_implementation)); nextToken(); nextToken(); // interface name @@ -4244,10 +4233,8 @@ void UnwrappedLineParser::parseObjCLightweightGenerics() { do { nextToken(); // Early exit in case someone forgot a close angle. - if (FormatTok->isOneOf(tok::semi, tok::l_brace) || - FormatTok->isObjCAtKeyword(tok::objc_end)) { + if (FormatTok->isOneOf(tok::semi, tok::l_brace, tok::objc_end)) break; - } if (FormatTok->is(tok::less)) { ++NumOpenAngles; } else if (FormatTok->is(tok::greater)) { @@ -4261,7 +4248,7 @@ void UnwrappedLineParser::parseObjCLightweightGenerics() { // Returns true for the declaration/definition form of @protocol, // false for the expression form. bool UnwrappedLineParser::parseObjCProtocol() { - assert(FormatTok->Tok.getObjCKeywordID() == tok::objc_protocol); + assert(FormatTok->is(tok::objc_protocol)); nextToken(); if (FormatTok->is(tok::l_paren)) { |