diff options
author | Daniel Jasper <djasper@google.com> | 2017-03-01 10:47:52 +0000 |
---|---|---|
committer | Daniel Jasper <djasper@google.com> | 2017-03-01 10:47:52 +0000 |
commit | eab6cd474c478942949942d844da0ed51f31e394 (patch) | |
tree | a2e8bfddfca0970e687d6df4b876bd629a2e0b56 | |
parent | 413671507f593a7ce70a61db23e35387579d5f2a (diff) | |
download | bcm5719-llvm-eab6cd474c478942949942d844da0ed51f31e394.tar.gz bcm5719-llvm-eab6cd474c478942949942d844da0ed51f31e394.zip |
clang-format: Ignore contents of #ifdef SWIG .. #endif blocks.
Those blocks are used if C++ code is SWIG-wrapped (see swig.org) and
usually do not contain C++ code. Also cleanup the implementation of for #if 0
and #if false a bit.
llvm-svn: 296605
-rw-r--r-- | clang/lib/Format/UnwrappedLineParser.cpp | 12 | ||||
-rw-r--r-- | clang/unittests/Format/FormatTestComments.cpp | 8 |
2 files changed, 14 insertions, 6 deletions
diff --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp index 9a536ad6019..bd049ef668b 100644 --- a/clang/lib/Format/UnwrappedLineParser.cpp +++ b/clang/lib/Format/UnwrappedLineParser.cpp @@ -590,12 +590,12 @@ void UnwrappedLineParser::conditionalCompilationEnd() { void UnwrappedLineParser::parsePPIf(bool IfDef) { nextToken(); - bool IsLiteralFalse = (FormatTok->Tok.isLiteral() && - FormatTok->Tok.getLiteralData() != nullptr && - StringRef(FormatTok->Tok.getLiteralData(), - FormatTok->Tok.getLength()) == "0") || - FormatTok->Tok.is(tok::kw_false); - conditionalCompilationStart(!IfDef && IsLiteralFalse); + bool Unreachable = false; + if (!IfDef && (FormatTok->is(tok::kw_false) || FormatTok->TokenText == "0")) + Unreachable = true; + if (IfDef && FormatTok->TokenText == "SWIG") + Unreachable = true; + conditionalCompilationStart(Unreachable); parsePPUnknown(); } diff --git a/clang/unittests/Format/FormatTestComments.cpp b/clang/unittests/Format/FormatTestComments.cpp index 049851793c0..cb1cefa47cf 100644 --- a/clang/unittests/Format/FormatTestComments.cpp +++ b/clang/unittests/Format/FormatTestComments.cpp @@ -1683,6 +1683,14 @@ TEST_F(FormatTestComments, IgnoresIf0Contents) { "void f( ) { }\n" "#endif\n" "void g( ) { }\n")); + EXPECT_EQ("#ifdef SWIG\n" + "}{)(&*(^%%#%@! fsadj f;ldjs ,:;| <<<>>>][)(][\n" + "#endif\n" + "void f() {}", + format("#ifdef SWIG\n" + "}{)(&*(^%%#%@! fsadj f;ldjs ,:;| <<<>>>][)(][\n" + "#endif\n" + "void f( ) { }")); EXPECT_EQ("enum E {\n" " One,\n" " Two,\n" |