[PATCH] D118844: [clang-format] Avoid adding space after the name of a function-like macro when the name is a keyword.
Marek Kurdej via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Feb 3 09:46:01 PST 2022
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG529aa4b011c4: [clang-format] Avoid adding space after the name of a function-like macro when… (authored by curdeius).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D118844/new/
https://reviews.llvm.org/D118844
Files:
clang/lib/Format/UnwrappedLineParser.cpp
clang/unittests/Format/FormatTest.cpp
Index: clang/unittests/Format/FormatTest.cpp
===================================================================
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -1795,6 +1795,18 @@
AllowSimpleBracedStatements);
}
+TEST_F(FormatTest, UnderstandsMacros) {
+ verifyFormat("#define A (parentheses)");
+ verifyFormat("#define true ((int)1)");
+ verifyFormat("#define and(x)");
+ verifyFormat("#define if(x) x");
+ verifyFormat("#define return(x) (x)");
+ verifyFormat("#define while(x) for (; x;)");
+ verifyFormat("#define xor(x) (^(x))");
+ verifyFormat("#define __except(x)");
+ verifyFormat("#define __try(x)");
+}
+
TEST_F(FormatTest, ShortBlocksInMacrosDontMergeWithCodeAfterMacro) {
FormatStyle Style = getLLVMStyleWithColumns(60);
Style.AllowShortBlocksOnASingleLine = FormatStyle::SBS_Always;
Index: clang/lib/Format/UnwrappedLineParser.cpp
===================================================================
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -1007,6 +1007,12 @@
}
}
+ // In the context of a define, even keywords should be treated as normal
+ // identifiers. Setting the kind to identifier is not enough, because we need
+ // to treat additional keywords like __except as well, which are already
+ // identifiers.
+ FormatTok->Tok.setKind(tok::identifier);
+ FormatTok->Tok.setIdentifierInfo(nullptr);
nextToken();
if (FormatTok->Tok.getKind() == tok::l_paren &&
!FormatTok->hasWhitespaceBefore())
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D118844.405690.patch
Type: text/x-patch
Size: 1565 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220203/e1a09056/attachment.bin>
More information about the cfe-commits
mailing list