r182733 - Improve indentation of assignments.
Daniel Jasper
djasper at google.com
Mon May 27 05:45:09 PDT 2013
Author: djasper
Date: Mon May 27 07:45:09 2013
New Revision: 182733
URL: http://llvm.org/viewvc/llvm-project?rev=182733&view=rev
Log:
Improve indentation of assignments.
Before:
unsigned OriginalStartColumn = SourceMgr.getSpellingColumnNumber(
Current.FormatTok.getStartOfNonWhitespace()) -
1;
After:
unsigned OriginalStartColumn =
SourceMgr.getSpellingColumnNumber(
Current.FormatTok.getStartOfNonWhitespace()) -
1;
Modified:
cfe/trunk/lib/Format/Format.cpp
cfe/trunk/unittests/Format/FormatTest.cpp
Modified: cfe/trunk/lib/Format/Format.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/Format.cpp?rev=182733&r1=182732&r2=182733&view=diff
==============================================================================
--- cfe/trunk/lib/Format/Format.cpp (original)
+++ cfe/trunk/lib/Format/Format.cpp Mon May 27 07:45:09 2013
@@ -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;
Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=182733&r1=182732&r2=182733&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Mon May 27 07:45:09 2013
@@ -2336,6 +2336,10 @@ TEST_F(FormatTest, BreaksAfterAssignment
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) {
More information about the cfe-commits
mailing list