r245043 - clang-format: Don't remove space between #elif and parentheses.
Daniel Jasper via cfe-commits
cfe-commits at lists.llvm.org
Fri Aug 14 05:44:06 PDT 2015
Author: djasper
Date: Fri Aug 14 07:44:06 2015
New Revision: 245043
URL: http://llvm.org/viewvc/llvm-project?rev=245043&view=rev
Log:
clang-format: Don't remove space between #elif and parentheses.
Before:
#elif(AAAA && BBBB)
After:
#elif (AAAA && BBBB)
Modified:
cfe/trunk/lib/Format/FormatToken.h
cfe/trunk/lib/Format/TokenAnnotator.cpp
cfe/trunk/unittests/Format/FormatTest.cpp
Modified: cfe/trunk/lib/Format/FormatToken.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/FormatToken.h?rev=245043&r1=245042&r2=245043&view=diff
==============================================================================
--- cfe/trunk/lib/Format/FormatToken.h (original)
+++ cfe/trunk/lib/Format/FormatToken.h Fri Aug 14 07:44:06 2015
@@ -283,6 +283,10 @@ struct FormatToken {
bool is(const IdentifierInfo *II) const {
return II && II == Tok.getIdentifierInfo();
}
+ bool is(tok::PPKeywordKind Kind) const {
+ return Tok.getIdentifierInfo() &&
+ Tok.getIdentifierInfo()->getPPKeywordID() == Kind;
+ }
template <typename A, typename B> bool isOneOf(A K1, B K2) const {
return is(K1) || is(K2);
}
Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=245043&r1=245042&r2=245043&view=diff
==============================================================================
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Fri Aug 14 07:44:06 2015
@@ -1895,7 +1895,7 @@ bool TokenAnnotator::spaceRequiredBetwee
return true;
return Line.Type == LT_ObjCDecl || Left.is(tok::semi) ||
(Style.SpaceBeforeParens != FormatStyle::SBPO_Never &&
- (Left.isOneOf(tok::kw_if, tok::kw_for, tok::kw_while,
+ (Left.isOneOf(tok::kw_if, tok::pp_elif, tok::kw_for, tok::kw_while,
tok::kw_switch, tok::kw_case, TT_ForEachMacro) ||
(Left.isOneOf(tok::kw_try, Keywords.kw___except, tok::kw_catch,
tok::kw_new, tok::kw_delete) &&
Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=245043&r1=245042&r2=245043&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Fri Aug 14 07:44:06 2015
@@ -6556,6 +6556,8 @@ TEST_F(FormatTest, DoNotInterfereWithErr
TEST_F(FormatTest, FormatHashIfExpressions) {
verifyFormat("#if AAAA && BBBB");
+ verifyFormat("#if (AAAA && BBBB)");
+ verifyFormat("#elif (AAAA && BBBB)");
// FIXME: Come up with a better indentation for #elif.
verifyFormat(
"#if !defined(AAAAAAA) && (defined CCCCCC || defined DDDDDD) && \\\n"
More information about the cfe-commits
mailing list