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
diff --git a/lib/Format/BreakableToken.cpp b/lib/Format/BreakableToken.cpp
index b23819d..cbc50f5 100644
--- a/lib/Format/BreakableToken.cpp
+++ b/lib/Format/BreakableToken.cpp
@@ -145,10 +145,10 @@
 }
 
 BreakableSingleLineToken::BreakableSingleLineToken(
-    const FormatToken &Tok, unsigned StartColumn, StringRef Prefix,
-    StringRef Postfix, bool InPPDirective, encoding::Encoding Encoding,
-    const FormatStyle &Style)
-    : BreakableToken(Tok, InPPDirective, Encoding, Style),
+    const FormatToken &Tok, unsigned IndentLevel, unsigned StartColumn,
+    StringRef Prefix, StringRef Postfix, bool InPPDirective,
+    encoding::Encoding Encoding, const FormatStyle &Style)
+    : BreakableToken(Tok, IndentLevel, InPPDirective, Encoding, Style),
       StartColumn(StartColumn), Prefix(Prefix), Postfix(Postfix) {
   assert(Tok.TokenText.startswith(Prefix) && Tok.TokenText.endswith(Postfix));
   Line = Tok.TokenText.substr(
@@ -156,11 +156,11 @@
 }
 
 BreakableStringLiteral::BreakableStringLiteral(
-    const FormatToken &Tok, unsigned StartColumn, StringRef Prefix,
-    StringRef Postfix, bool InPPDirective, encoding::Encoding Encoding,
-    const FormatStyle &Style)
-    : BreakableSingleLineToken(Tok, StartColumn, Prefix, Postfix, InPPDirective,
-                               Encoding, Style) {}
+    const FormatToken &Tok, unsigned IndentLevel, unsigned StartColumn,
+    StringRef Prefix, StringRef Postfix, bool InPPDirective,
+    encoding::Encoding Encoding, const FormatStyle &Style)
+    : BreakableSingleLineToken(Tok, IndentLevel, StartColumn, Prefix, Postfix,
+                               InPPDirective, Encoding, Style) {}
 
 BreakableToken::Split
 BreakableStringLiteral::getSplit(unsigned LineIndex, unsigned TailOffset,
@@ -175,7 +175,7 @@
                                          WhitespaceManager &Whitespaces) {
   Whitespaces.replaceWhitespaceInToken(
       Tok, Prefix.size() + TailOffset + Split.first, Split.second, Postfix,
-      Prefix, InPPDirective, 1, StartColumn);
+      Prefix, InPPDirective, 1, IndentLevel, StartColumn);
 }
 
 static StringRef getLineCommentPrefix(StringRef Comment) {
@@ -186,12 +186,10 @@
   return "";
 }
 
-BreakableLineComment::BreakableLineComment(const FormatToken &Token,
-                                           unsigned StartColumn,
-                                           bool InPPDirective,
-                                           encoding::Encoding Encoding,
-                                           const FormatStyle &Style)
-    : BreakableSingleLineToken(Token, StartColumn,
+BreakableLineComment::BreakableLineComment(
+    const FormatToken &Token, unsigned IndentLevel, unsigned StartColumn,
+    bool InPPDirective, encoding::Encoding Encoding, const FormatStyle &Style)
+    : BreakableSingleLineToken(Token, IndentLevel, StartColumn,
                                getLineCommentPrefix(Token.TokenText), "",
                                InPPDirective, Encoding, Style) {
   OriginalPrefix = Prefix;
@@ -216,7 +214,7 @@
                                        WhitespaceManager &Whitespaces) {
   Whitespaces.replaceWhitespaceInToken(
       Tok, OriginalPrefix.size() + TailOffset + Split.first, Split.second,
-      Postfix, Prefix, InPPDirective, 1, StartColumn);
+      Postfix, Prefix, InPPDirective, 1, IndentLevel, StartColumn);
 }
 
 void
@@ -224,15 +222,15 @@
                                               WhitespaceManager &Whitespaces) {
   if (OriginalPrefix != Prefix) {
     Whitespaces.replaceWhitespaceInToken(Tok, OriginalPrefix.size(), 0, "", "",
-                                         false, 0, 1);
+                                         false, 0, /*IndentLevel=*/0, 1);
   }
 }
 
 BreakableBlockComment::BreakableBlockComment(
-    const FormatToken &Token, unsigned StartColumn,
+    const FormatToken &Token, unsigned IndentLevel, unsigned StartColumn,
     unsigned OriginalStartColumn, bool FirstInLine, bool InPPDirective,
     encoding::Encoding Encoding, const FormatStyle &Style)
-    : BreakableToken(Token, InPPDirective, Encoding, Style) {
+    : BreakableToken(Token, IndentLevel, InPPDirective, Encoding, Style) {
   StringRef TokenText(Token.TokenText);
   assert(TokenText.startswith("/*") && TokenText.endswith("*/"));
   TokenText.substr(2, TokenText.size() - 4).split(Lines, "\n");
@@ -327,12 +325,6 @@
   LeadingWhitespace[LineIndex] =
       Lines[LineIndex].begin() - Lines[LineIndex - 1].end();
 
-  // FIXME: We currently count tabs as 1 character. To solve this, we need to
-  // get the correct indentation width of the start of the comment, which
-  // requires correct counting of the tab expansions before the comment, and
-  // a configurable tab width. Since the current implementation only breaks
-  // if leading tabs are intermixed with spaces, that is not a high priority.
-
   // Adjust the start column uniformly accross all lines.
   StartOfLineColumn[LineIndex] = std::max<int>(
       0,
@@ -376,9 +368,9 @@
       Text.data() - Tok.TokenText.data() + Split.first;
   unsigned CharsToRemove = Split.second;
   assert(IndentAtLineBreak >= Decoration.size());
-  Whitespaces.replaceWhitespaceInToken(Tok, BreakOffsetInToken, CharsToRemove,
-                                       "", Prefix, InPPDirective, 1,
-                                       IndentAtLineBreak - Decoration.size());
+  Whitespaces.replaceWhitespaceInToken(
+      Tok, BreakOffsetInToken, CharsToRemove, "", Prefix, InPPDirective, 1,
+      IndentLevel, IndentAtLineBreak - Decoration.size());
 }
 
 void
@@ -412,7 +404,8 @@
   assert(StartOfLineColumn[LineIndex] >= Prefix.size());
   Whitespaces.replaceWhitespaceInToken(
       Tok, WhitespaceOffsetInToken, LeadingWhitespace[LineIndex], "", Prefix,
-      InPPDirective, 1, StartOfLineColumn[LineIndex] - Prefix.size());
+      InPPDirective, 1, IndentLevel,
+      StartOfLineColumn[LineIndex] - Prefix.size());
 }
 
 unsigned