diff options
author | Daniel Jasper <djasper@google.com> | 2013-07-24 13:10:59 +0000 |
---|---|---|
committer | Daniel Jasper <djasper@google.com> | 2013-07-24 13:10:59 +0000 |
commit | ffefb3d1e0b2b5deeee67ec6528371e23b87c623 (patch) | |
tree | 48ded79608569a3364c7c87ffe52c925669b133c /clang/lib/Format | |
parent | c467c94e0bf015100d7d3a9dc900cb35689cd2e8 (diff) | |
download | bcm5719-llvm-ffefb3d1e0b2b5deeee67ec6528371e23b87c623.tar.gz bcm5719-llvm-ffefb3d1e0b2b5deeee67ec6528371e23b87c623.zip |
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
Diffstat (limited to 'clang/lib/Format')
-rw-r--r-- | clang/lib/Format/Format.cpp | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp index a4495ba62ee..2dee5678b71 100644 --- a/clang/lib/Format/Format.cpp +++ b/clang/lib/Format/Format.cpp @@ -219,6 +219,15 @@ FormatStyle getMozillaStyle() { 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 @@ bool getPredefinedStyle(StringRef Name, FormatStyle *Style) { *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 @@ public: // 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 @@ private: } }; + /// \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 @@ private: 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. |