clang-format: Initial (incomplete) support for the WebKit coding style.

This is far from implementing all the rules given by
http://www.webkit.org/coding/coding-style.html

The important new feature is the support for styles that don't have a
column limit. For such styles, clang-format will (at the moment) simply
respect the input's formatting decisions within statements.

llvm-svn: 187033
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index a4495ba..2dee567 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -219,6 +219,15 @@
   return MozillaStyle;
 }
 
+FormatStyle getWebKitStyle() {
+  FormatStyle Style = getLLVMStyle();
+  Style.ColumnLimit = 0;
+  Style.IndentWidth = 4;
+  Style.BreakBeforeBraces = FormatStyle::BS_Stroustrup;
+  Style.PointerBindsToType = true;
+  return Style;
+}
+
 bool getPredefinedStyle(StringRef Name, FormatStyle *Style) {
   if (Name.equals_lower("llvm"))
     *Style = getLLVMStyle();
@@ -228,6 +237,8 @@
     *Style = getMozillaStyle();
   else if (Name.equals_lower("google"))
     *Style = getGoogleStyle();
+  else if (Name.equals_lower("webkit"))
+    *Style = getWebKitStyle();
   else
     return false;
 
@@ -299,6 +310,11 @@
     // The first token has already been indented and thus consumed.
     moveStateToNextToken(State, /*DryRun=*/false, /*Newline=*/false);
 
+    if (Style.ColumnLimit == 0) {
+      formatWithoutColumnLimit(State);
+      return;
+    }
+
     // If everything fits on a single line, just put it there.
     unsigned ColumnLimit = Style.ColumnLimit;
     if (NextLine && NextLine->InPPDirective &&
@@ -506,6 +522,15 @@
     }
   };
 
+  /// \brief Formats the line starting at \p State, simply keeping all of the
+  /// input's line breaking decisions.
+  void formatWithoutColumnLimit(LineState &State) {
+    while (State.NextToken != NULL) {
+      bool Newline = State.NextToken->NewlinesBefore > 0;
+      addTokenToState(Newline, /*DryRun=*/false, State);
+    }
+  }
+
   /// \brief Appends the next token to \p State and updates information
   /// necessary for indentation.
   ///
@@ -1592,6 +1617,9 @@
     if (I->Last->Type == TT_LineComment)
       return;
 
+    if (Indent > Style.ColumnLimit)
+      return;
+
     unsigned Limit = Style.ColumnLimit - Indent;
     // If we already exceed the column limit, we set 'Limit' to 0. The different
     // tryMerge..() functions can then decide whether to still do merging.