diff options
Diffstat (limited to 'clang/lib/Format/Format.cpp')
-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. |