diff options
author | Daniel Jasper <djasper@google.com> | 2013-08-13 10:58:30 +0000 |
---|---|---|
committer | Daniel Jasper <djasper@google.com> | 2013-08-13 10:58:30 +0000 |
commit | cdaffa45d440e90430bcc9b33616f086a7de6f03 (patch) | |
tree | e50eeab3df6fca5768bd7245508800cea92398b6 /clang/lib/Format/Format.cpp | |
parent | 5bd3fab9010430f946c5bbc31a523de749195c98 (diff) | |
download | bcm5719-llvm-cdaffa45d440e90430bcc9b33616f086a7de6f03.tar.gz bcm5719-llvm-cdaffa45d440e90430bcc9b33616f086a7de6f03.zip |
clang-format: Add option for the offset of constructor initializers.
Some coding styles use a different indent for constructor initializers.
Patch by Klemens Baum. Thank you.
Review: http://llvm-reviews.chandlerc.com/D1360
Post review changes: Changed data type to unsigned as a negative indent
width does not make sense and added test for configuration parsing.
llvm-svn: 188260
Diffstat (limited to 'clang/lib/Format/Format.cpp')
-rw-r--r-- | clang/lib/Format/Format.cpp | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp index 6fe4d45d1d0..ec1497c87f4 100644 --- a/clang/lib/Format/Format.cpp +++ b/clang/lib/Format/Format.cpp @@ -91,6 +91,8 @@ template <> struct MappingTraits<clang::format::FormatStyle> { } IO.mapOptional("AccessModifierOffset", Style.AccessModifierOffset); + IO.mapOptional("ConstructorInitializerIndentWidth", + Style.ConstructorInitializerIndentWidth); IO.mapOptional("AlignEscapedNewlinesLeft", Style.AlignEscapedNewlinesLeft); IO.mapOptional("AlignTrailingComments", Style.AlignTrailingComments); IO.mapOptional("AllowAllParametersOfDeclarationOnNextLine", @@ -167,6 +169,7 @@ FormatStyle getLLVMStyle() { LLVMStyle.BreakConstructorInitializersBeforeComma = false; LLVMStyle.ColumnLimit = 80; LLVMStyle.ConstructorInitializerAllOnOneLineOrOnePerLine = false; + LLVMStyle.ConstructorInitializerIndentWidth = 4; LLVMStyle.Cpp11BracedListStyle = false; LLVMStyle.DerivePointerBinding = false; LLVMStyle.ExperimentalAutoDetectBinPacking = false; @@ -203,6 +206,7 @@ FormatStyle getGoogleStyle() { GoogleStyle.BreakConstructorInitializersBeforeComma = false; GoogleStyle.ColumnLimit = 80; GoogleStyle.ConstructorInitializerAllOnOneLineOrOnePerLine = true; + GoogleStyle.ConstructorInitializerIndentWidth = 4; GoogleStyle.Cpp11BracedListStyle = true; GoogleStyle.DerivePointerBinding = true; GoogleStyle.ExperimentalAutoDetectBinPacking = false; @@ -651,6 +655,10 @@ private: Previous.isOneOf(tok::coloncolon, tok::equal) || Previous.Type == TT_ObjCMethodExpr) { State.Column = ContinuationIndent; + } else if (Current.Type == TT_CtorInitializerColon) { + State.Column = FirstIndent + Style.ConstructorInitializerIndentWidth; + } else if (Current.Type == TT_CtorInitializerComma) { + State.Column = State.Stack.back().Indent; } else { State.Column = State.Stack.back().Indent; // Ensure that we fall back to indenting 4 spaces instead of just @@ -821,8 +829,9 @@ private: // : First(...), ... // Next(...) // ^ line up here. - if (!Style.BreakConstructorInitializersBeforeComma) - State.Stack.back().Indent = State.Column + 2; + State.Stack.back().Indent = + State.Column + + (Style.BreakConstructorInitializersBeforeComma ? 0 : 2); if (Style.ConstructorInitializerAllOnOneLineOrOnePerLine) State.Stack.back().AvoidBinPacking = true; State.Stack.back().BreakBeforeParameter = false; |