r192187 - clang-format: Improve indentation when deriving from templated classes.
Daniel Jasper
djasper at google.com
Tue Oct 8 09:24:07 PDT 2013
Author: djasper
Date: Tue Oct 8 11:24:07 2013
New Revision: 192187
URL: http://llvm.org/viewvc/llvm-project?rev=192187&view=rev
Log:
clang-format: Improve indentation when deriving from templated classes.
Before:
struct aaaaaaaaaaaaa : public aaaaaaaaaaaaaaaaaaa< //
aaaaaaaaaaaaaaaa> {};
struct aaaaaaaaaaaaaaaaaaaa : public aaaaaaaaaaaaaaaaaaa<
aaaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaaaa> {};
After:
struct aaaaaaaaaaaaa : public aaaaaaaaaaaaaaaaaaa< //
aaaaaaaaaaaaaaaa> {};
struct aaaaaaaaaaaaaaaaaaaa
: public aaaaaaaaaaaaaaaaaaa<aaaaaaaaaaaaaaaaaaaaa,
aaaaaaaaaaaaaaaaaaaaaa> {};
Modified:
cfe/trunk/lib/Format/ContinuationIndenter.cpp
cfe/trunk/lib/Format/TokenAnnotator.cpp
cfe/trunk/unittests/Format/FormatTest.cpp
Modified: cfe/trunk/lib/Format/ContinuationIndenter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/ContinuationIndenter.cpp?rev=192187&r1=192186&r2=192187&view=diff
==============================================================================
--- cfe/trunk/lib/Format/ContinuationIndenter.cpp (original)
+++ cfe/trunk/lib/Format/ContinuationIndenter.cpp Tue Oct 8 11:24:07 2013
@@ -278,9 +278,10 @@ void ContinuationIndenter::addTokenOnCur
// simple assignment without binary expression on the RHS. Also indent
// relative to unary operators and the colons of constructor initializers.
State.Stack.back().LastSpace = State.Column;
- else if (Previous.Type == TT_InheritanceColon)
+ else if (Previous.Type == TT_InheritanceColon) {
State.Stack.back().Indent = State.Column;
- else if (Previous.opensScope()) {
+ State.Stack.back().LastSpace = State.Column;
+ } else if (Previous.opensScope()) {
// If a function has a trailing call, indent all parameters from the
// opening parenthesis. This avoids confusing indents like:
// OuterFunction(InnerFunctionCall( // break
Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=192187&r1=192186&r2=192187&view=diff
==============================================================================
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Tue Oct 8 11:24:07 2013
@@ -335,7 +335,7 @@ private:
Contexts.back().FirstObjCSelectorName = Tok->Previous;
} else if (Contexts.back().ColonIsForRangeExpr) {
Tok->Type = TT_RangeBasedForLoopColon;
- } else if (Contexts.size() == 1) {
+ } else if (Contexts.size() == 1 && Line.First->isNot(tok::kw_enum)) {
Tok->Type = TT_InheritanceColon;
} else if (Contexts.back().ContextKind == tok::l_paren) {
Tok->Type = TT_InlineASMColon;
Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=192187&r1=192186&r2=192187&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Tue Oct 8 11:24:07 2013
@@ -1530,6 +1530,11 @@ TEST_F(FormatTest, FormatsClasses) {
" int i;\n"
"};",
getLLVMStyleWithColumns(32));
+ verifyFormat("struct aaaaaaaaaaaaa : public aaaaaaaaaaaaaaaaaaa< // break\n"
+ " aaaaaaaaaaaaaaaa> {};");
+ verifyFormat("struct aaaaaaaaaaaaaaaaaaaa\n"
+ " : public aaaaaaaaaaaaaaaaaaa<aaaaaaaaaaaaaaaaaaaaa,\n"
+ " aaaaaaaaaaaaaaaaaaaaaa> {};");
}
TEST_F(FormatTest, FormatsVariableDeclarationsAfterStructOrClass) {
More information about the cfe-commits
mailing list