summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Jasper <djasper@google.com>2013-05-27 12:45:09 +0000
committerDaniel Jasper <djasper@google.com>2013-05-27 12:45:09 +0000
commit7b27a10b1e95804e1272d44f499f81648fb991b8 (patch)
treeba8ceb575b4d01bd652ba00134a4971118d7b8fe
parent75081b5cf86ce3ee2118a54c0854a28b80131a2c (diff)
downloadbcm5719-llvm-7b27a10b1e95804e1272d44f499f81648fb991b8.tar.gz
bcm5719-llvm-7b27a10b1e95804e1272d44f499f81648fb991b8.zip
Improve indentation of assignments.
Before: unsigned OriginalStartColumn = SourceMgr.getSpellingColumnNumber( Current.FormatTok.getStartOfNonWhitespace()) - 1; After: unsigned OriginalStartColumn = SourceMgr.getSpellingColumnNumber( Current.FormatTok.getStartOfNonWhitespace()) - 1; llvm-svn: 182733
-rw-r--r--clang/lib/Format/Format.cpp5
-rw-r--r--clang/unittests/Format/FormatTest.cpp4
2 files changed, 8 insertions, 1 deletions
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index dcb5f8a6eda..b4ea90462a8 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -640,7 +640,10 @@ private:
else if ((Previous.Type == TT_BinaryOperator ||
Previous.Type == TT_ConditionalExpr ||
Previous.Type == TT_CtorInitializerColon) &&
- getPrecedence(Previous) != prec::Assignment)
+ !(getPrecedence(Previous) == prec::Assignment &&
+ Current.FakeLParens.empty()))
+ // Always indent relative to the RHS of the expression unless this is a
+ // simple assignment without binary expression on the RHS.
State.Stack.back().LastSpace = State.Column;
else if (Previous.Type == TT_InheritanceColon)
State.Stack.back().Indent = State.Column;
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index 132dbb5aa21..73fea60519f 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -2336,6 +2336,10 @@ TEST_F(FormatTest, BreaksAfterAssignments) {
verifyFormat(
"aaaaaaaaaaaaaaaaaaaaaaaaaa aaaa = aaaaaaaaaaaaaa(0).aaaa()\n"
" .aaaaaaaaaaaa(aaaaaaaaaaaaaaaaaaa::aaaaaaaaaaaaaaaaaaaaa);");
+ verifyFormat("unsigned OriginalStartColumn =\n"
+ " SourceMgr.getSpellingColumnNumber(\n"
+ " Current.FormatTok.getStartOfNonWhitespace()) -\n"
+ " 1;");
}
TEST_F(FormatTest, AlignsAfterAssignments) {
OpenPOWER on IntegriCloud