From 3d9ffcf3aa0ed84fa297e3c461bb84e48221aa2d Mon Sep 17 00:00:00 2001 From: Alexander Kornienko Date: Fri, 27 Sep 2013 16:14:22 +0000 Subject: Implemented tab usage only for indentation (http://llvm.org/PR17363) Summary: Changed UseTab to be a enum with three options: Never, Always, ForIndentation (true/false are still supported when reading .clang-format). IndentLevel should currently be propagated correctly for all tokens, except for block comments. Please take a look at the general idea before I start dealing with block comments. Reviewers: klimek, djasper Reviewed By: klimek CC: cfe-commits Differential Revision: http://llvm-reviews.chandlerc.com/D1770 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@191527 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Format/Format.cpp | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) (limited to 'lib/Format/Format.cpp') diff --git a/lib/Format/Format.cpp b/lib/Format/Format.cpp index 6166ecc1b3..d616769061 100644 --- a/lib/Format/Format.cpp +++ b/lib/Format/Format.cpp @@ -44,6 +44,19 @@ struct ScalarEnumerationTraits { } }; +template <> +struct ScalarEnumerationTraits { + static void + enumeration(IO &IO, clang::format::FormatStyle::UseTabStyle &Value) { + IO.enumCase(Value, "Never", clang::format::FormatStyle::UT_Never); + IO.enumCase(Value, "false", clang::format::FormatStyle::UT_Never); + IO.enumCase(Value, "Always", clang::format::FormatStyle::UT_Always); + IO.enumCase(Value, "true", clang::format::FormatStyle::UT_Always); + IO.enumCase(Value, "ForIndentation", + clang::format::FormatStyle::UT_ForIndentation); + } +}; + template <> struct ScalarEnumerationTraits { static void @@ -194,7 +207,7 @@ FormatStyle getLLVMStyle() { LLVMStyle.PointerBindsToType = false; LLVMStyle.SpacesBeforeTrailingComments = 1; LLVMStyle.Standard = FormatStyle::LS_Cpp03; - LLVMStyle.UseTab = false; + LLVMStyle.UseTab = FormatStyle::UT_Never; LLVMStyle.SpacesInParentheses = false; LLVMStyle.SpaceInEmptyParentheses = false; LLVMStyle.SpacesInCStyleCastParentheses = false; @@ -237,7 +250,7 @@ FormatStyle getGoogleStyle() { GoogleStyle.PointerBindsToType = true; GoogleStyle.SpacesBeforeTrailingComments = 2; GoogleStyle.Standard = FormatStyle::LS_Auto; - GoogleStyle.UseTab = false; + GoogleStyle.UseTab = FormatStyle::UT_Never; GoogleStyle.SpacesInParentheses = false; GoogleStyle.SpaceInEmptyParentheses = false; GoogleStyle.SpacesInCStyleCastParentheses = false; @@ -539,7 +552,7 @@ private: Style.MaxEmptyLinesToKeep + 1); Newlines = std::max(1u, Newlines); Whitespaces->replaceWhitespace( - *(*I)->First, Newlines, /*Spaces=*/Indent, + *(*I)->First, Newlines, (*I)->Level, /*Spaces=*/Indent, /*StartOfTokenColumn=*/Indent, Line.InPPDirective); } UnwrappedLineFormatter Formatter(Indenter, Whitespaces, Style, **I); @@ -556,10 +569,10 @@ private: return false; if (!DryRun) { - Whitespaces->replaceWhitespace(*LBrace.Children[0]->First, - /*Newlines=*/0, /*Spaces=*/1, - /*StartOfTokenColumn=*/State.Column, - State.Line->InPPDirective); + Whitespaces->replaceWhitespace( + *LBrace.Children[0]->First, + /*Newlines=*/0, /*IndentLevel=*/1, /*Spaces=*/1, + /*StartOfTokenColumn=*/State.Column, State.Line->InPPDirective); UnwrappedLineFormatter Formatter(Indenter, Whitespaces, Style, *LBrace.Children[0]); Penalty += Formatter.format(State.Column + 1, DryRun); @@ -847,8 +860,9 @@ public: if (TheLine.First->is(tok::eof)) { if (PreviousLineWasTouched) { unsigned NewLines = std::min(FirstTok->NewlinesBefore, 1u); - Whitespaces.replaceWhitespace(*TheLine.First, NewLines, /*Indent*/ 0, - /*TargetColumn*/ 0); + Whitespaces.replaceWhitespace(*TheLine.First, NewLines, + /*IndentLevel=*/0, /*Spaces=*/0, + /*TargetColumn=*/0); } } else if (TheLine.Type != LT_Invalid && (WasMoved || FormatPPDirective || touchesLine(TheLine))) { @@ -1225,7 +1239,7 @@ private: ++Newlines; Whitespaces.replaceWhitespace( - RootToken, Newlines, Indent, Indent, + RootToken, Newlines, Indent / Style.IndentWidth, Indent, Indent, InPPDirective && !RootToken.HasUnescapedNewline); } -- cgit v1.2.3