r184078 - Fix a problem in ExpressionParser leading to trailing comments affecting indentation of an expression after a line break.
Alexander Kornienko
alexfh at google.com
Mon Jun 17 06:19:53 PDT 2013
Author: alexfh
Date: Mon Jun 17 08:19:53 2013
New Revision: 184078
URL: http://llvm.org/viewvc/llvm-project?rev=184078&view=rev
Log:
Fix a problem in ExpressionParser leading to trailing comments affecting indentation of an expression after a line break.
Summary:
E.g. the second line in
return aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +
b; //
is indented 4 characters more than in
return aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +
b;
Reviewers: klimek
Reviewed By: klimek
CC: cfe-commits
Differential Revision: http://llvm-reviews.chandlerc.com/D984
Modified:
cfe/trunk/lib/Format/TokenAnnotator.cpp
cfe/trunk/unittests/Format/FormatTest.cpp
Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=184078&r1=184077&r2=184078&view=diff
==============================================================================
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Mon Jun 17 08:19:53 2013
@@ -151,7 +151,7 @@ private:
if (!CurrentToken)
return false;
- // A '[' could be an index subscript (after an indentifier or after
+ // A '[' could be an index subscript (after an identifier or after
// ')' or ']'), it could be the start of an Objective-C method
// expression, or it could the the start of an Objective-C array literal.
FormatToken *Left = CurrentToken->Previous;
@@ -792,11 +792,6 @@ public:
if (Precedence > prec::PointerToMember || Current == NULL)
return;
- // Eagerly consume trailing comments.
- while (Current && Current->isTrailingComment()) {
- next();
- }
-
FormatToken *Start = Current;
bool OperatorFound = false;
@@ -862,7 +857,9 @@ private:
}
void next() {
- if (Current != NULL)
+ if (Current)
+ Current = Current->Next;
+ while (Current && Current->isTrailingComment())
Current = Current->Next;
}
Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=184078&r1=184077&r2=184078&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Mon Jun 17 08:19:53 2013
@@ -2150,6 +2150,13 @@ TEST_F(FormatTest, ExpressionIndentation
"} else if (aaaaa && bbbbb > // break\n"
" ccccc) {\n"
"}");
+
+ // Presence of a trailing comment used to change indentation of b.
+ verifyFormat("return aaaaaaaaaaaaaaaaaaa +\n"
+ " b;\n"
+ "return aaaaaaaaaaaaaaaaaaa +\n"
+ " b; //",
+ getLLVMStyleWithColumns(30));
}
TEST_F(FormatTest, ConstructorInitializers) {
More information about the cfe-commits
mailing list