blob: 2af16fcd0cf7e3a285f59e4a39053f27aa3ec565 [file] [log] [blame]
Daniel Jasper6b2afe42013-08-16 11:20:30 +00001//===--- ContinuationIndenter.cpp - Format C++ code -----------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9///
10/// \file
11/// \brief This file implements the continuation indenter.
12///
13//===----------------------------------------------------------------------===//
14
Daniel Jasper6b2afe42013-08-16 11:20:30 +000015#include "BreakableToken.h"
16#include "ContinuationIndenter.h"
17#include "WhitespaceManager.h"
18#include "clang/Basic/OperatorPrecedence.h"
19#include "clang/Basic/SourceManager.h"
20#include "clang/Format/Format.h"
21#include "llvm/Support/Debug.h"
22#include <string>
23
Stephen Hines6bcf27b2014-05-29 04:14:42 -070024#define DEBUG_TYPE "format-formatter"
25
Daniel Jasper6b2afe42013-08-16 11:20:30 +000026namespace clang {
27namespace format {
28
29// Returns the length of everything up to the first possible line break after
30// the ), ], } or > matching \c Tok.
31static unsigned getLengthToMatchingParen(const FormatToken &Tok) {
Stephen Hines6bcf27b2014-05-29 04:14:42 -070032 if (!Tok.MatchingParen)
Daniel Jasper6b2afe42013-08-16 11:20:30 +000033 return 0;
34 FormatToken *End = Tok.MatchingParen;
35 while (End->Next && !End->Next->CanBreakBefore) {
36 End = End->Next;
37 }
38 return End->TotalLength - Tok.TotalLength + 1;
39}
40
Daniel Jasperd3fef0f2013-08-27 14:24:43 +000041// Returns \c true if \c Tok is the "." or "->" of a call and starts the next
42// segment of a builder type call.
43static bool startsSegmentOfBuilderTypeCall(const FormatToken &Tok) {
44 return Tok.isMemberAccess() && Tok.Previous && Tok.Previous->closesScope();
45}
46
Daniel Jasper19ccb122013-10-08 05:11:18 +000047// Returns \c true if \c Current starts a new parameter.
48static bool startsNextParameter(const FormatToken &Current,
49 const FormatStyle &Style) {
50 const FormatToken &Previous = *Current.Previous;
51 if (Current.Type == TT_CtorInitializerComma &&
52 Style.BreakConstructorInitializersBeforeComma)
53 return true;
54 return Previous.is(tok::comma) && !Current.isTrailingComment() &&
55 (Previous.Type != TT_CtorInitializerComma ||
56 !Style.BreakConstructorInitializersBeforeComma);
57}
58
Daniel Jasper6b2afe42013-08-16 11:20:30 +000059ContinuationIndenter::ContinuationIndenter(const FormatStyle &Style,
60 SourceManager &SourceMgr,
Daniel Jasper6b2afe42013-08-16 11:20:30 +000061 WhitespaceManager &Whitespaces,
62 encoding::Encoding Encoding,
63 bool BinPackInconclusiveFunctions)
Daniel Jasper567dcf92013-09-05 09:29:45 +000064 : Style(Style), SourceMgr(SourceMgr), Whitespaces(Whitespaces),
65 Encoding(Encoding),
Stephen Hines651f13c2014-04-23 16:59:28 -070066 BinPackInconclusiveFunctions(BinPackInconclusiveFunctions),
67 CommentPragmasRegex(Style.CommentPragmas) {}
Daniel Jasper6b2afe42013-08-16 11:20:30 +000068
Daniel Jasper567dcf92013-09-05 09:29:45 +000069LineState ContinuationIndenter::getInitialState(unsigned FirstIndent,
Daniel Jasperb77d7412013-09-06 07:54:20 +000070 const AnnotatedLine *Line,
71 bool DryRun) {
Daniel Jasper6b2afe42013-08-16 11:20:30 +000072 LineState State;
Daniel Jasper567dcf92013-09-05 09:29:45 +000073 State.FirstIndent = FirstIndent;
Daniel Jasper6b2afe42013-08-16 11:20:30 +000074 State.Column = FirstIndent;
Daniel Jasper567dcf92013-09-05 09:29:45 +000075 State.Line = Line;
76 State.NextToken = Line->First;
Alexander Kornienkof0fc89c2013-10-14 00:46:35 +000077 State.Stack.push_back(ParenState(FirstIndent, Line->Level, FirstIndent,
Daniel Jasper6b2afe42013-08-16 11:20:30 +000078 /*AvoidBinPacking=*/false,
79 /*NoLineBreak=*/false));
80 State.LineContainsContinuedForLoopSection = false;
Daniel Jasper6b2afe42013-08-16 11:20:30 +000081 State.StartOfStringLiteral = 0;
Stephen Hines6bcf27b2014-05-29 04:14:42 -070082 State.StartOfLineLevel = 0;
83 State.LowestLevelOnLine = 0;
Daniel Jasper6b2afe42013-08-16 11:20:30 +000084 State.IgnoreStackForComparison = false;
85
86 // The first token has already been indented and thus consumed.
Daniel Jasperb77d7412013-09-06 07:54:20 +000087 moveStateToNextToken(State, DryRun, /*Newline=*/false);
Daniel Jasper6b2afe42013-08-16 11:20:30 +000088 return State;
89}
90
91bool ContinuationIndenter::canBreak(const LineState &State) {
92 const FormatToken &Current = *State.NextToken;
93 const FormatToken &Previous = *Current.Previous;
94 assert(&Previous == Current.Previous);
Daniel Jaspera07aa662013-10-22 15:30:28 +000095 if (!Current.CanBreakBefore && !(State.Stack.back().BreakBeforeClosingBrace &&
96 Current.closesBlockTypeList(Style)))
Daniel Jasper6b2afe42013-08-16 11:20:30 +000097 return false;
98 // The opening "{" of a braced list has to be on the same line as the first
99 // element if it is nested in another braced init list or function call.
100 if (!Current.MustBreakBefore && Previous.is(tok::l_brace) &&
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700101 Previous.Type != TT_DictLiteral && Previous.BlockKind == BK_BracedInit &&
102 Previous.Previous &&
Daniel Jasper6b2afe42013-08-16 11:20:30 +0000103 Previous.Previous->isOneOf(tok::l_brace, tok::l_paren, tok::comma))
104 return false;
105 // This prevents breaks like:
106 // ...
107 // SomeParameter, OtherParameter).DoSomething(
108 // ...
109 // As they hide "DoSomething" and are generally bad for readability.
Stephen Hines651f13c2014-04-23 16:59:28 -0700110 if (Previous.opensScope() && Previous.isNot(tok::l_brace) &&
111 State.LowestLevelOnLine < State.StartOfLineLevel)
Daniel Jasper6b2afe42013-08-16 11:20:30 +0000112 return false;
Daniel Jasperd3fef0f2013-08-27 14:24:43 +0000113 if (Current.isMemberAccess() && State.Stack.back().ContainsUnwrappedBuilder)
114 return false;
Stephen Hinesc568f1e2014-07-21 00:47:37 -0700115
116 // Don't create a 'hanging' indent if there are multiple blocks in a single
117 // statement.
118 if (Style.Language == FormatStyle::LK_JavaScript &&
119 Previous.is(tok::l_brace) && State.Stack.size() > 1 &&
120 State.Stack[State.Stack.size() - 2].JSFunctionInlined &&
121 State.Stack[State.Stack.size() - 2].HasMultipleNestedBlocks)
122 return false;
123
Daniel Jasper6b2afe42013-08-16 11:20:30 +0000124 return !State.Stack.back().NoLineBreak;
125}
126
127bool ContinuationIndenter::mustBreak(const LineState &State) {
128 const FormatToken &Current = *State.NextToken;
129 const FormatToken &Previous = *Current.Previous;
130 if (Current.MustBreakBefore || Current.Type == TT_InlineASMColon)
131 return true;
Daniel Jaspera07aa662013-10-22 15:30:28 +0000132 if (State.Stack.back().BreakBeforeClosingBrace &&
133 Current.closesBlockTypeList(Style))
Daniel Jasper6b2afe42013-08-16 11:20:30 +0000134 return true;
135 if (Previous.is(tok::semi) && State.LineContainsContinuedForLoopSection)
136 return true;
Daniel Jasper19ccb122013-10-08 05:11:18 +0000137 if ((startsNextParameter(Current, Style) || Previous.is(tok::semi) ||
Daniel Jasper1a896a52013-11-08 00:57:11 +0000138 (Style.BreakBeforeTernaryOperators &&
139 (Current.is(tok::question) || (Current.Type == TT_ConditionalExpr &&
140 Previous.isNot(tok::question)))) ||
141 (!Style.BreakBeforeTernaryOperators &&
142 (Previous.is(tok::question) || Previous.Type == TT_ConditionalExpr))) &&
Daniel Jasper6b2afe42013-08-16 11:20:30 +0000143 State.Stack.back().BreakBeforeParameter && !Current.isTrailingComment() &&
144 !Current.isOneOf(tok::r_paren, tok::r_brace))
145 return true;
146 if (Style.AlwaysBreakBeforeMultilineStrings &&
Daniel Jasper4df1ff92013-08-23 11:57:34 +0000147 State.Column > State.Stack.back().Indent && // Breaking saves columns.
Daniel Jaspera7856d02013-11-09 03:08:25 +0000148 !Previous.isOneOf(tok::kw_return, tok::lessless, tok::at) &&
Stephen Hinesc568f1e2014-07-21 00:47:37 -0700149 Previous.Type != TT_InlineASMColon &&
150 Previous.Type != TT_ConditionalExpr && nextIsMultilineString(State))
Daniel Jasper6b2afe42013-08-16 11:20:30 +0000151 return true;
Daniel Jasper3c6aea72013-10-24 10:31:50 +0000152 if (((Previous.Type == TT_DictLiteral && Previous.is(tok::l_brace)) ||
Daniel Jaspera07aa662013-10-22 15:30:28 +0000153 Previous.Type == TT_ArrayInitializerLSquare) &&
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700154 Style.ColumnLimit > 0 &&
Daniel Jaspera53bbae2013-10-20 16:45:46 +0000155 getLengthToMatchingParen(Previous) + State.Column > getColumnLimit(State))
156 return true;
Stephen Hines651f13c2014-04-23 16:59:28 -0700157 if (Current.Type == TT_CtorInitializerColon &&
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700158 ((Style.AllowShortFunctionsOnASingleLine != FormatStyle::SFS_All) ||
Stephen Hines651f13c2014-04-23 16:59:28 -0700159 Style.BreakConstructorInitializersBeforeComma || Style.ColumnLimit != 0))
160 return true;
Daniel Jasper6b2afe42013-08-16 11:20:30 +0000161
Stephen Hines651f13c2014-04-23 16:59:28 -0700162 if (State.Column < getNewLineColumn(State))
163 return false;
Daniel Jasper6b2afe42013-08-16 11:20:30 +0000164 if (!Style.BreakBeforeBinaryOperators) {
165 // If we need to break somewhere inside the LHS of a binary expression, we
166 // should also break after the operator. Otherwise, the formatting would
167 // hide the operator precedence, e.g. in:
168 // if (aaaaaaaaaaaaaa ==
169 // bbbbbbbbbbbbbb && c) {..
170 // For comparisons, we only apply this rule, if the LHS is a binary
171 // expression itself as otherwise, the line breaks seem superfluous.
172 // We need special cases for ">>" which we have split into two ">" while
173 // lexing in order to make template parsing easier.
174 //
175 // FIXME: We'll need something similar for styles that break before binary
176 // operators.
177 bool IsComparison = (Previous.getPrecedence() == prec::Relational ||
178 Previous.getPrecedence() == prec::Equality) &&
179 Previous.Previous &&
180 Previous.Previous->Type != TT_BinaryOperator; // For >>.
181 bool LHSIsBinaryExpr =
Daniel Jasperdb4813a2013-09-06 08:08:14 +0000182 Previous.Previous && Previous.Previous->EndsBinaryExpression;
Daniel Jasper6b2afe42013-08-16 11:20:30 +0000183 if (Previous.Type == TT_BinaryOperator &&
184 (!IsComparison || LHSIsBinaryExpr) &&
185 Current.Type != TT_BinaryOperator && // For >>.
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700186 !Current.isTrailingComment() && !Previous.is(tok::lessless) &&
Daniel Jasper6b2afe42013-08-16 11:20:30 +0000187 Previous.getPrecedence() != prec::Assignment &&
188 State.Stack.back().BreakBeforeParameter)
189 return true;
190 }
191
192 // Same as above, but for the first "<<" operator.
Stephen Hines651f13c2014-04-23 16:59:28 -0700193 if (Current.is(tok::lessless) && Current.Type != TT_OverloadedOperator &&
194 State.Stack.back().BreakBeforeParameter &&
Daniel Jasper6b2afe42013-08-16 11:20:30 +0000195 State.Stack.back().FirstLessLess == 0)
196 return true;
197
Stephen Hinesc568f1e2014-07-21 00:47:37 -0700198 if (Current.Type == TT_SelectorName &&
Stephen Hines651f13c2014-04-23 16:59:28 -0700199 State.Stack.back().ObjCSelectorNameFound &&
Daniel Jasper6b2afe42013-08-16 11:20:30 +0000200 State.Stack.back().BreakBeforeParameter)
201 return true;
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700202 if (Previous.ClosesTemplateDeclaration && Current.NestingLevel == 0 &&
Stephen Hines651f13c2014-04-23 16:59:28 -0700203 !Current.isTrailingComment())
Daniel Jasper6b2afe42013-08-16 11:20:30 +0000204 return true;
205
Stephen Hinesc568f1e2014-07-21 00:47:37 -0700206 // If the return type spans multiple lines, wrap before the function name.
207 if ((Current.Type == TT_FunctionDeclarationName ||
208 Current.is(tok::kw_operator)) &&
209 State.Stack.back().BreakBeforeParameter)
Daniel Jasper6b2afe42013-08-16 11:20:30 +0000210 return true;
Stephen Hinesc568f1e2014-07-21 00:47:37 -0700211
Daniel Jasperd3fef0f2013-08-27 14:24:43 +0000212 if (startsSegmentOfBuilderTypeCall(Current) &&
Daniel Jaspereb331832013-08-30 07:12:40 +0000213 (State.Stack.back().CallContinuation != 0 ||
214 (State.Stack.back().BreakBeforeParameter &&
215 State.Stack.back().ContainsUnwrappedBuilder)))
Daniel Jasperd3fef0f2013-08-27 14:24:43 +0000216 return true;
Stephen Hines651f13c2014-04-23 16:59:28 -0700217
218 // The following could be precomputed as they do not depend on the state.
219 // However, as they should take effect only if the UnwrappedLine does not fit
220 // into the ColumnLimit, they are checked here in the ContinuationIndenter.
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700221 if (Style.ColumnLimit != 0 && Previous.BlockKind == BK_Block &&
222 Previous.is(tok::l_brace) && !Current.isOneOf(tok::r_brace, tok::comment))
Stephen Hines651f13c2014-04-23 16:59:28 -0700223 return true;
224
Daniel Jasper6b2afe42013-08-16 11:20:30 +0000225 return false;
226}
227
228unsigned ContinuationIndenter::addTokenToState(LineState &State, bool Newline,
Daniel Jasperd4a03db2013-08-22 15:00:41 +0000229 bool DryRun,
230 unsigned ExtraSpaces) {
Daniel Jasper6b2afe42013-08-16 11:20:30 +0000231 const FormatToken &Current = *State.NextToken;
Daniel Jasper6b2afe42013-08-16 11:20:30 +0000232
Stephen Hines651f13c2014-04-23 16:59:28 -0700233 assert(!State.Stack.empty());
234 if ((Current.Type == TT_ImplicitStringLiteral &&
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700235 (Current.Previous->Tok.getIdentifierInfo() == nullptr ||
Daniel Jasper84379572013-10-30 13:54:53 +0000236 Current.Previous->Tok.getIdentifierInfo()->getPPKeywordID() ==
237 tok::pp_not_keyword))) {
Daniel Jasper6b2afe42013-08-16 11:20:30 +0000238 // FIXME: Is this correct?
239 int WhitespaceLength = SourceMgr.getSpellingColumnNumber(
240 State.NextToken->WhitespaceRange.getEnd()) -
241 SourceMgr.getSpellingColumnNumber(
242 State.NextToken->WhitespaceRange.getBegin());
Stephen Hines651f13c2014-04-23 16:59:28 -0700243 State.Column += WhitespaceLength;
244 moveStateToNextToken(State, DryRun, /*Newline=*/false);
Daniel Jasper6b2afe42013-08-16 11:20:30 +0000245 return 0;
246 }
247
Alexander Kornienkoe5321c42013-10-01 14:41:18 +0000248 unsigned Penalty = 0;
249 if (Newline)
250 Penalty = addTokenOnNewLine(State, DryRun);
251 else
252 addTokenOnCurrentLine(State, DryRun, ExtraSpaces);
253
254 return moveStateToNextToken(State, DryRun, Newline) + Penalty;
255}
256
257void ContinuationIndenter::addTokenOnCurrentLine(LineState &State, bool DryRun,
258 unsigned ExtraSpaces) {
Manuel Klimekae76f7f2013-10-11 21:25:45 +0000259 FormatToken &Current = *State.NextToken;
Alexander Kornienkoe5321c42013-10-01 14:41:18 +0000260 const FormatToken &Previous = *State.NextToken->Previous;
261 if (Current.is(tok::equal) &&
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700262 (State.Line->First->is(tok::kw_for) || Current.NestingLevel == 0) &&
Alexander Kornienkoe5321c42013-10-01 14:41:18 +0000263 State.Stack.back().VariablePos == 0) {
264 State.Stack.back().VariablePos = State.Column;
265 // Move over * and & if they are bound to the variable name.
266 const FormatToken *Tok = &Previous;
267 while (Tok && State.Stack.back().VariablePos >= Tok->ColumnWidth) {
268 State.Stack.back().VariablePos -= Tok->ColumnWidth;
269 if (Tok->SpacesRequiredBefore != 0)
270 break;
271 Tok = Tok->Previous;
272 }
273 if (Previous.PartOfMultiVariableDeclStmt)
274 State.Stack.back().LastSpace = State.Stack.back().VariablePos;
275 }
276
277 unsigned Spaces = Current.SpacesRequiredBefore + ExtraSpaces;
278
279 if (!DryRun)
280 Whitespaces.replaceWhitespace(Current, /*Newlines=*/0, /*IndentLevel=*/0,
281 Spaces, State.Column + Spaces);
282
Stephen Hinesc568f1e2014-07-21 00:47:37 -0700283 if (Current.Type == TT_SelectorName &&
Stephen Hines651f13c2014-04-23 16:59:28 -0700284 !State.Stack.back().ObjCSelectorNameFound) {
285 if (Current.LongestObjCSelectorName == 0)
286 State.Stack.back().AlignColons = false;
287 else if (State.Stack.back().Indent + Current.LongestObjCSelectorName >
288 State.Column + Spaces + Current.ColumnWidth)
Alexander Kornienkoe5321c42013-10-01 14:41:18 +0000289 State.Stack.back().ColonPos =
290 State.Stack.back().Indent + Current.LongestObjCSelectorName;
291 else
292 State.Stack.back().ColonPos = State.Column + Spaces + Current.ColumnWidth;
293 }
294
295 if (Previous.opensScope() && Previous.Type != TT_ObjCMethodExpr &&
Stephen Hines651f13c2014-04-23 16:59:28 -0700296 (Current.Type != TT_LineComment || Previous.BlockKind == BK_BracedInit))
Alexander Kornienkoe5321c42013-10-01 14:41:18 +0000297 State.Stack.back().Indent = State.Column + Spaces;
Daniel Jasper19ccb122013-10-08 05:11:18 +0000298 if (State.Stack.back().AvoidBinPacking && startsNextParameter(Current, Style))
Alexander Kornienkoe5321c42013-10-01 14:41:18 +0000299 State.Stack.back().NoLineBreak = true;
300 if (startsSegmentOfBuilderTypeCall(Current))
301 State.Stack.back().ContainsUnwrappedBuilder = true;
302
303 State.Column += Spaces;
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700304 if (Current.isNot(tok::comment) && Previous.is(tok::l_paren) &&
305 Previous.Previous && Previous.Previous->isOneOf(tok::kw_if, tok::kw_for))
Alexander Kornienkoe5321c42013-10-01 14:41:18 +0000306 // Treat the condition inside an if as if it was a second function
Daniel Jasperc2827ec2013-10-18 10:38:14 +0000307 // parameter, i.e. let nested calls have a continuation indent.
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700308 State.Stack.back().LastSpace = State.Column;
Stephen Hinesc568f1e2014-07-21 00:47:37 -0700309 else if (!Current.isOneOf(tok::comment, tok::caret) &&
Stephen Hines651f13c2014-04-23 16:59:28 -0700310 (Previous.is(tok::comma) ||
311 (Previous.is(tok::colon) && Previous.Type == TT_ObjCMethodExpr)))
Alexander Kornienkoe5321c42013-10-01 14:41:18 +0000312 State.Stack.back().LastSpace = State.Column;
313 else if ((Previous.Type == TT_BinaryOperator ||
314 Previous.Type == TT_ConditionalExpr ||
Alexander Kornienkoe5321c42013-10-01 14:41:18 +0000315 Previous.Type == TT_CtorInitializerColon) &&
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700316 ((Previous.getPrecedence() != prec::Assignment &&
317 (Previous.isNot(tok::lessless) || Previous.OperatorIndex != 0 ||
318 !Previous.LastOperator)) ||
Alexander Kornienkoe5321c42013-10-01 14:41:18 +0000319 Current.StartsBinaryExpression))
320 // Always indent relative to the RHS of the expression unless this is a
321 // simple assignment without binary expression on the RHS. Also indent
322 // relative to unary operators and the colons of constructor initializers.
323 State.Stack.back().LastSpace = State.Column;
Daniel Jaspercea014b2013-10-08 16:24:07 +0000324 else if (Previous.Type == TT_InheritanceColon) {
Alexander Kornienkoe5321c42013-10-01 14:41:18 +0000325 State.Stack.back().Indent = State.Column;
Daniel Jaspercea014b2013-10-08 16:24:07 +0000326 State.Stack.back().LastSpace = State.Column;
327 } else if (Previous.opensScope()) {
Alexander Kornienkoe5321c42013-10-01 14:41:18 +0000328 // If a function has a trailing call, indent all parameters from the
329 // opening parenthesis. This avoids confusing indents like:
330 // OuterFunction(InnerFunctionCall( // break
331 // ParameterToInnerFunction)) // break
332 // .SecondInnerFunctionCall();
333 bool HasTrailingCall = false;
334 if (Previous.MatchingParen) {
335 const FormatToken *Next = Previous.MatchingParen->getNextNonComment();
336 HasTrailingCall = Next && Next->isMemberAccess();
337 }
338 if (HasTrailingCall &&
339 State.Stack[State.Stack.size() - 2].CallContinuation == 0)
340 State.Stack.back().LastSpace = State.Column;
341 }
342}
343
344unsigned ContinuationIndenter::addTokenOnNewLine(LineState &State,
345 bool DryRun) {
Manuel Klimekae76f7f2013-10-11 21:25:45 +0000346 FormatToken &Current = *State.NextToken;
Alexander Kornienkoe5321c42013-10-01 14:41:18 +0000347 const FormatToken &Previous = *State.NextToken->Previous;
Stephen Hines651f13c2014-04-23 16:59:28 -0700348
Alexander Kornienkoe5321c42013-10-01 14:41:18 +0000349 // Extra penalty that needs to be added because of the way certain line
350 // breaks are chosen.
351 unsigned Penalty = 0;
Daniel Jasperd4a03db2013-08-22 15:00:41 +0000352
Stephen Hines651f13c2014-04-23 16:59:28 -0700353 const FormatToken *PreviousNonComment = Current.getPreviousNonComment();
354 const FormatToken *NextNonComment = Previous.getNextNonComment();
355 if (!NextNonComment)
356 NextNonComment = &Current;
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700357 // The first line break on any NestingLevel causes an extra penalty in order
Alexander Kornienkoe5321c42013-10-01 14:41:18 +0000358 // prefer similar line breaks.
359 if (!State.Stack.back().ContainsLineBreak)
360 Penalty += 15;
361 State.Stack.back().ContainsLineBreak = true;
Daniel Jasperd4a03db2013-08-22 15:00:41 +0000362
Alexander Kornienkoe5321c42013-10-01 14:41:18 +0000363 Penalty += State.NextToken->SplitPenalty;
Daniel Jasper6b2afe42013-08-16 11:20:30 +0000364
Alexander Kornienkoe5321c42013-10-01 14:41:18 +0000365 // Breaking before the first "<<" is generally not desirable if the LHS is
Stephen Hines651f13c2014-04-23 16:59:28 -0700366 // short. Also always add the penalty if the LHS is split over mutliple lines
367 // to avoid unnecessary line breaks that just work around this penalty.
368 if (NextNonComment->is(tok::lessless) &&
369 State.Stack.back().FirstLessLess == 0 &&
370 (State.Column <= Style.ColumnLimit / 3 ||
371 State.Stack.back().BreakBeforeParameter))
Alexander Kornienkoe5321c42013-10-01 14:41:18 +0000372 Penalty += Style.PenaltyBreakFirstLessLess;
373
Stephen Hines651f13c2014-04-23 16:59:28 -0700374 State.Column = getNewLineColumn(State);
375 if (NextNonComment->isMemberAccess()) {
376 if (State.Stack.back().CallContinuation == 0)
Alexander Kornienkoe5321c42013-10-01 14:41:18 +0000377 State.Stack.back().CallContinuation = State.Column;
Stephen Hinesc568f1e2014-07-21 00:47:37 -0700378 } else if (NextNonComment->Type == TT_SelectorName) {
Stephen Hines651f13c2014-04-23 16:59:28 -0700379 if (!State.Stack.back().ObjCSelectorNameFound) {
380 if (NextNonComment->LongestObjCSelectorName == 0) {
381 State.Stack.back().AlignColons = false;
382 } else {
383 State.Stack.back().ColonPos =
384 State.Stack.back().Indent + NextNonComment->LongestObjCSelectorName;
385 }
386 } else if (State.Stack.back().AlignColons &&
387 State.Stack.back().ColonPos <= NextNonComment->ColumnWidth) {
388 State.Stack.back().ColonPos = State.Column + NextNonComment->ColumnWidth;
Alexander Kornienkoe5321c42013-10-01 14:41:18 +0000389 }
Stephen Hines651f13c2014-04-23 16:59:28 -0700390 } else if (PreviousNonComment && PreviousNonComment->is(tok::colon) &&
391 (PreviousNonComment->Type == TT_ObjCMethodExpr ||
392 PreviousNonComment->Type == TT_DictLiteral)) {
393 // FIXME: This is hacky, find a better way. The problem is that in an ObjC
394 // method expression, the block should be aligned to the line starting it,
395 // e.g.:
396 // [aaaaaaaaaaaaaaa aaaaaaaaa: \\ break for some reason
397 // ^(int *i) {
398 // // ...
399 // }];
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700400 // Thus, we set LastSpace of the next higher NestingLevel, to which we move
Stephen Hines651f13c2014-04-23 16:59:28 -0700401 // when we consume all of the "}"'s FakeRParens at the "{".
402 if (State.Stack.size() > 1)
403 State.Stack[State.Stack.size() - 2].LastSpace =
404 std::max(State.Stack.back().LastSpace, State.Stack.back().Indent) +
405 Style.ContinuationIndentWidth;
Daniel Jasper6b2afe42013-08-16 11:20:30 +0000406 }
407
Alexander Kornienkoe5321c42013-10-01 14:41:18 +0000408 if ((Previous.isOneOf(tok::comma, tok::semi) &&
409 !State.Stack.back().AvoidBinPacking) ||
410 Previous.Type == TT_BinaryOperator)
411 State.Stack.back().BreakBeforeParameter = false;
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700412 if (Previous.Type == TT_TemplateCloser && Current.NestingLevel == 0)
Alexander Kornienkoe5321c42013-10-01 14:41:18 +0000413 State.Stack.back().BreakBeforeParameter = false;
Stephen Hines651f13c2014-04-23 16:59:28 -0700414 if (NextNonComment->is(tok::question) ||
Daniel Jasper1a896a52013-11-08 00:57:11 +0000415 (PreviousNonComment && PreviousNonComment->is(tok::question)))
416 State.Stack.back().BreakBeforeParameter = true;
Alexander Kornienkoe5321c42013-10-01 14:41:18 +0000417
418 if (!DryRun) {
Stephen Hinesc568f1e2014-07-21 00:47:37 -0700419 unsigned Newlines = std::max(
420 1u, std::min(Current.NewlinesBefore, Style.MaxEmptyLinesToKeep + 1));
Alexander Kornienkof0fc89c2013-10-14 00:46:35 +0000421 Whitespaces.replaceWhitespace(Current, Newlines,
422 State.Stack.back().IndentLevel, State.Column,
423 State.Column, State.Line->InPPDirective);
Alexander Kornienkoe5321c42013-10-01 14:41:18 +0000424 }
425
426 if (!Current.isTrailingComment())
427 State.Stack.back().LastSpace = State.Column;
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700428 State.StartOfLineLevel = Current.NestingLevel;
429 State.LowestLevelOnLine = Current.NestingLevel;
Alexander Kornienkoe5321c42013-10-01 14:41:18 +0000430
431 // Any break on this level means that the parent level has been broken
432 // and we need to avoid bin packing there.
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700433 bool JavaScriptFormat = Style.Language == FormatStyle::LK_JavaScript &&
434 Current.is(tok::r_brace) &&
435 State.Stack.size() > 1 &&
436 State.Stack[State.Stack.size() - 2].JSFunctionInlined;
437 if (!JavaScriptFormat) {
438 for (unsigned i = 0, e = State.Stack.size() - 1; i != e; ++i) {
439 State.Stack[i].BreakBeforeParameter = true;
440 }
Alexander Kornienkoe5321c42013-10-01 14:41:18 +0000441 }
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700442
Daniel Jasper8b156e22013-11-08 19:56:28 +0000443 if (PreviousNonComment &&
444 !PreviousNonComment->isOneOf(tok::comma, tok::semi) &&
445 PreviousNonComment->Type != TT_TemplateCloser &&
446 PreviousNonComment->Type != TT_BinaryOperator &&
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700447 Current.Type != TT_BinaryOperator && !PreviousNonComment->opensScope())
Alexander Kornienkoe5321c42013-10-01 14:41:18 +0000448 State.Stack.back().BreakBeforeParameter = true;
449
Daniel Jaspera07aa662013-10-22 15:30:28 +0000450 // If we break after { or the [ of an array initializer, we should also break
451 // before the corresponding } or ].
Stephen Hinesc568f1e2014-07-21 00:47:37 -0700452 if (PreviousNonComment &&
453 (PreviousNonComment->is(tok::l_brace) ||
454 PreviousNonComment->Type == TT_ArrayInitializerLSquare))
Alexander Kornienkoe5321c42013-10-01 14:41:18 +0000455 State.Stack.back().BreakBeforeClosingBrace = true;
456
457 if (State.Stack.back().AvoidBinPacking) {
458 // If we are breaking after '(', '{', '<', this is not bin packing
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700459 // unless AllowAllParametersOfDeclarationOnNextLine is false or this is a
460 // dict/object literal.
Alexander Kornienkoe5321c42013-10-01 14:41:18 +0000461 if (!(Previous.isOneOf(tok::l_paren, tok::l_brace) ||
462 Previous.Type == TT_BinaryOperator) ||
463 (!Style.AllowAllParametersOfDeclarationOnNextLine &&
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700464 State.Line->MustBeDeclaration) ||
465 Previous.Type == TT_DictLiteral)
Alexander Kornienkoe5321c42013-10-01 14:41:18 +0000466 State.Stack.back().BreakBeforeParameter = true;
467 }
468
469 return Penalty;
Daniel Jasper6b2afe42013-08-16 11:20:30 +0000470}
471
Stephen Hines651f13c2014-04-23 16:59:28 -0700472unsigned ContinuationIndenter::getNewLineColumn(const LineState &State) {
473 if (!State.NextToken || !State.NextToken->Previous)
474 return 0;
475 FormatToken &Current = *State.NextToken;
476 const FormatToken &Previous = *State.NextToken->Previous;
477 // If we are continuing an expression, we want to use the continuation indent.
478 unsigned ContinuationIndent =
479 std::max(State.Stack.back().LastSpace, State.Stack.back().Indent) +
480 Style.ContinuationIndentWidth;
481 const FormatToken *PreviousNonComment = Current.getPreviousNonComment();
482 const FormatToken *NextNonComment = Previous.getNextNonComment();
483 if (!NextNonComment)
484 NextNonComment = &Current;
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700485 if (NextNonComment->is(tok::l_brace) && NextNonComment->BlockKind == BK_Block)
486 return Current.NestingLevel == 0 ? State.FirstIndent
487 : State.Stack.back().Indent;
Stephen Hines651f13c2014-04-23 16:59:28 -0700488 if (Current.isOneOf(tok::r_brace, tok::r_square)) {
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700489 if (State.Stack.size() > 1 &&
490 State.Stack[State.Stack.size() - 2].JSFunctionInlined)
491 return State.FirstIndent;
Stephen Hines651f13c2014-04-23 16:59:28 -0700492 if (Current.closesBlockTypeList(Style) ||
493 (Current.MatchingParen &&
494 Current.MatchingParen->BlockKind == BK_BracedInit))
495 return State.Stack[State.Stack.size() - 2].LastSpace;
496 else
497 return State.FirstIndent;
498 }
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700499 if (Current.is(tok::identifier) && Current.Next &&
500 Current.Next->Type == TT_DictLiteral)
501 return State.Stack.back().Indent;
Stephen Hines651f13c2014-04-23 16:59:28 -0700502 if (NextNonComment->isStringLiteral() && State.StartOfStringLiteral != 0)
503 return State.StartOfStringLiteral;
504 if (NextNonComment->is(tok::lessless) &&
505 State.Stack.back().FirstLessLess != 0)
506 return State.Stack.back().FirstLessLess;
507 if (NextNonComment->isMemberAccess()) {
508 if (State.Stack.back().CallContinuation == 0) {
509 return ContinuationIndent;
510 } else {
511 return State.Stack.back().CallContinuation;
512 }
513 }
514 if (State.Stack.back().QuestionColumn != 0 &&
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700515 ((NextNonComment->is(tok::colon) &&
516 NextNonComment->Type == TT_ConditionalExpr) ||
Stephen Hines651f13c2014-04-23 16:59:28 -0700517 Previous.Type == TT_ConditionalExpr))
518 return State.Stack.back().QuestionColumn;
519 if (Previous.is(tok::comma) && State.Stack.back().VariablePos != 0)
520 return State.Stack.back().VariablePos;
521 if ((PreviousNonComment && (PreviousNonComment->ClosesTemplateDeclaration ||
522 PreviousNonComment->Type == TT_AttributeParen)) ||
Stephen Hinesc568f1e2014-07-21 00:47:37 -0700523 (!Style.IndentWrappedFunctionNames &&
524 (NextNonComment->is(tok::kw_operator) ||
525 NextNonComment->Type == TT_FunctionDeclarationName)))
Stephen Hines651f13c2014-04-23 16:59:28 -0700526 return std::max(State.Stack.back().LastSpace, State.Stack.back().Indent);
Stephen Hinesc568f1e2014-07-21 00:47:37 -0700527 if (NextNonComment->Type == TT_SelectorName) {
Stephen Hines651f13c2014-04-23 16:59:28 -0700528 if (!State.Stack.back().ObjCSelectorNameFound) {
529 if (NextNonComment->LongestObjCSelectorName == 0) {
530 return State.Stack.back().Indent;
531 } else {
532 return State.Stack.back().Indent +
533 NextNonComment->LongestObjCSelectorName -
534 NextNonComment->ColumnWidth;
535 }
536 } else if (!State.Stack.back().AlignColons) {
537 return State.Stack.back().Indent;
538 } else if (State.Stack.back().ColonPos > NextNonComment->ColumnWidth) {
539 return State.Stack.back().ColonPos - NextNonComment->ColumnWidth;
540 } else {
541 return State.Stack.back().Indent;
542 }
543 }
544 if (NextNonComment->Type == TT_ArraySubscriptLSquare) {
545 if (State.Stack.back().StartOfArraySubscripts != 0)
546 return State.Stack.back().StartOfArraySubscripts;
547 else
548 return ContinuationIndent;
549 }
550 if (NextNonComment->Type == TT_StartOfName ||
551 Previous.isOneOf(tok::coloncolon, tok::equal)) {
552 return ContinuationIndent;
553 }
554 if (PreviousNonComment && PreviousNonComment->is(tok::colon) &&
555 (PreviousNonComment->Type == TT_ObjCMethodExpr ||
556 PreviousNonComment->Type == TT_DictLiteral))
557 return ContinuationIndent;
558 if (NextNonComment->Type == TT_CtorInitializerColon)
559 return State.FirstIndent + Style.ConstructorInitializerIndentWidth;
560 if (NextNonComment->Type == TT_CtorInitializerComma)
561 return State.Stack.back().Indent;
562 if (State.Stack.back().Indent == State.FirstIndent && PreviousNonComment &&
563 PreviousNonComment->isNot(tok::r_brace))
564 // Ensure that we fall back to the continuation indent width instead of
565 // just flushing continuations left.
566 return State.Stack.back().Indent + Style.ContinuationIndentWidth;
567 return State.Stack.back().Indent;
568}
569
Daniel Jasper6b2afe42013-08-16 11:20:30 +0000570unsigned ContinuationIndenter::moveStateToNextToken(LineState &State,
571 bool DryRun, bool Newline) {
Daniel Jasper6b2afe42013-08-16 11:20:30 +0000572 assert(State.Stack.size());
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700573 const FormatToken &Current = *State.NextToken;
Daniel Jasper6b2afe42013-08-16 11:20:30 +0000574
575 if (Current.Type == TT_InheritanceColon)
576 State.Stack.back().AvoidBinPacking = true;
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700577 if (Current.is(tok::lessless) && Current.Type != TT_OverloadedOperator) {
578 if (State.Stack.back().FirstLessLess == 0)
579 State.Stack.back().FirstLessLess = State.Column;
580 else
581 State.Stack.back().LastOperatorWrapped = Newline;
582 }
583 if ((Current.Type == TT_BinaryOperator && Current.isNot(tok::lessless)) ||
584 Current.Type == TT_ConditionalExpr)
585 State.Stack.back().LastOperatorWrapped = Newline;
Daniel Jaspera07aa662013-10-22 15:30:28 +0000586 if (Current.Type == TT_ArraySubscriptLSquare &&
Daniel Jasper6b2afe42013-08-16 11:20:30 +0000587 State.Stack.back().StartOfArraySubscripts == 0)
588 State.Stack.back().StartOfArraySubscripts = State.Column;
Daniel Jasper1a896a52013-11-08 00:57:11 +0000589 if ((Current.is(tok::question) && Style.BreakBeforeTernaryOperators) ||
590 (Current.getPreviousNonComment() && Current.isNot(tok::colon) &&
591 Current.getPreviousNonComment()->is(tok::question) &&
592 !Style.BreakBeforeTernaryOperators))
Daniel Jasper6b2afe42013-08-16 11:20:30 +0000593 State.Stack.back().QuestionColumn = State.Column;
594 if (!Current.opensScope() && !Current.closesScope())
595 State.LowestLevelOnLine =
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700596 std::min(State.LowestLevelOnLine, Current.NestingLevel);
Daniel Jasperd3fef0f2013-08-27 14:24:43 +0000597 if (Current.isMemberAccess())
Daniel Jasper6b2afe42013-08-16 11:20:30 +0000598 State.Stack.back().StartOfFunctionCall =
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700599 Current.LastOperator ? 0 : State.Column + Current.ColumnWidth;
Stephen Hinesc568f1e2014-07-21 00:47:37 -0700600 if (Current.Type == TT_SelectorName)
Stephen Hines651f13c2014-04-23 16:59:28 -0700601 State.Stack.back().ObjCSelectorNameFound = true;
Daniel Jasper6b2afe42013-08-16 11:20:30 +0000602 if (Current.Type == TT_CtorInitializerColon) {
603 // Indent 2 from the column, so:
604 // SomeClass::SomeClass()
605 // : First(...), ...
606 // Next(...)
607 // ^ line up here.
608 State.Stack.back().Indent =
609 State.Column + (Style.BreakConstructorInitializersBeforeComma ? 0 : 2);
610 if (Style.ConstructorInitializerAllOnOneLineOrOnePerLine)
611 State.Stack.back().AvoidBinPacking = true;
612 State.Stack.back().BreakBeforeParameter = false;
613 }
614
Daniel Jasper6b2afe42013-08-16 11:20:30 +0000615 // In ObjC method declaration we align on the ":" of parameters, but we need
Daniel Jasperc2827ec2013-10-18 10:38:14 +0000616 // to ensure that we indent parameters on subsequent lines by at least our
617 // continuation indent width.
Daniel Jasper6b2afe42013-08-16 11:20:30 +0000618 if (Current.Type == TT_ObjCMethodSpecifier)
Daniel Jasperc2827ec2013-10-18 10:38:14 +0000619 State.Stack.back().Indent += Style.ContinuationIndentWidth;
Daniel Jasper6b2afe42013-08-16 11:20:30 +0000620
621 // Insert scopes created by fake parenthesis.
622 const FormatToken *Previous = Current.getPreviousNonComment();
Daniel Jasperf78bf4a2013-09-30 08:29:03 +0000623
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700624 // Add special behavior to support a format commonly used for JavaScript
625 // closures:
626 // SomeFunction(function() {
627 // foo();
628 // bar();
629 // }, a, b, c);
630 if (Style.Language == FormatStyle::LK_JavaScript) {
631 if (Current.isNot(tok::comment) && Previous && Previous->is(tok::l_brace) &&
632 State.Stack.size() > 1) {
633 if (State.Stack[State.Stack.size() - 2].JSFunctionInlined && Newline) {
634 for (unsigned i = 0, e = State.Stack.size() - 1; i != e; ++i) {
635 State.Stack[i].NoLineBreak = true;
Alexander Kornienkof0fc89c2013-10-14 00:46:35 +0000636 }
Daniel Jasper567dcf92013-09-05 09:29:45 +0000637 }
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700638 State.Stack[State.Stack.size() - 2].JSFunctionInlined = false;
Daniel Jasper6b2afe42013-08-16 11:20:30 +0000639 }
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700640 if (Current.TokenText == "function")
641 State.Stack.back().JSFunctionInlined = !Newline;
Daniel Jasper6b2afe42013-08-16 11:20:30 +0000642 }
643
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700644 moveStatePastFakeLParens(State, Newline);
645 moveStatePastScopeOpener(State, Newline);
646 moveStatePastScopeCloser(State);
647 moveStatePastFakeRParens(State);
Daniel Jasper6b2afe42013-08-16 11:20:30 +0000648
Stephen Hines651f13c2014-04-23 16:59:28 -0700649 if (Current.isStringLiteral() && State.StartOfStringLiteral == 0) {
Daniel Jasper6b2afe42013-08-16 11:20:30 +0000650 State.StartOfStringLiteral = State.Column;
Stephen Hines651f13c2014-04-23 16:59:28 -0700651 } else if (!Current.isOneOf(tok::comment, tok::identifier, tok::hash) &&
652 !Current.isStringLiteral()) {
Daniel Jasper6b2afe42013-08-16 11:20:30 +0000653 State.StartOfStringLiteral = 0;
654 }
655
Alexander Kornienko83a7dcd2013-09-10 09:38:25 +0000656 State.Column += Current.ColumnWidth;
Daniel Jasper6b2afe42013-08-16 11:20:30 +0000657 State.NextToken = State.NextToken->Next;
Daniel Jasperd489f8c2013-08-27 11:09:05 +0000658 unsigned Penalty = breakProtrudingToken(Current, State, DryRun);
Daniel Jasper567dcf92013-09-05 09:29:45 +0000659 if (State.Column > getColumnLimit(State)) {
660 unsigned ExcessCharacters = State.Column - getColumnLimit(State);
661 Penalty += Style.PenaltyExcessCharacter * ExcessCharacters;
662 }
Daniel Jasper6b2afe42013-08-16 11:20:30 +0000663
Stephen Hines651f13c2014-04-23 16:59:28 -0700664 if (Current.Role)
665 Current.Role->formatFromToken(State, this, DryRun);
Daniel Jasperd4a03db2013-08-22 15:00:41 +0000666 // If the previous has a special role, let it consume tokens as appropriate.
667 // It is necessary to start at the previous token for the only implemented
668 // role (comma separated list). That way, the decision whether or not to break
669 // after the "{" is already done and both options are tried and evaluated.
670 // FIXME: This is ugly, find a better way.
671 if (Previous && Previous->Role)
Stephen Hines651f13c2014-04-23 16:59:28 -0700672 Penalty += Previous->Role->formatAfterToken(State, this, DryRun);
Daniel Jasperd4a03db2013-08-22 15:00:41 +0000673
674 return Penalty;
Daniel Jasper6b2afe42013-08-16 11:20:30 +0000675}
676
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700677void ContinuationIndenter::moveStatePastFakeLParens(LineState &State,
678 bool Newline) {
679 const FormatToken &Current = *State.NextToken;
680 const FormatToken *Previous = Current.getPreviousNonComment();
681
682 // Don't add extra indentation for the first fake parenthesis after
683 // 'return', assignments or opening <({[. The indentation for these cases
684 // is special cased.
685 bool SkipFirstExtraIndent =
686 (Previous && (Previous->opensScope() || Previous->is(tok::kw_return) ||
687 Previous->getPrecedence() == prec::Assignment ||
688 Previous->Type == TT_ObjCMethodExpr));
689 for (SmallVectorImpl<prec::Level>::const_reverse_iterator
690 I = Current.FakeLParens.rbegin(),
691 E = Current.FakeLParens.rend();
692 I != E; ++I) {
693 ParenState NewParenState = State.Stack.back();
694 NewParenState.ContainsLineBreak = false;
695
696 // Indent from 'LastSpace' unless this the fake parentheses encapsulating a
697 // builder type call after 'return'. If such a call is line-wrapped, we
698 // commonly just want to indent from the start of the line.
699 if (!Previous || Previous->isNot(tok::kw_return) || *I > 0)
700 NewParenState.Indent =
701 std::max(std::max(State.Column, NewParenState.Indent),
702 State.Stack.back().LastSpace);
703
704 // Don't allow the RHS of an operator to be split over multiple lines unless
705 // there is a line-break right after the operator.
706 // Exclude relational operators, as there, it is always more desirable to
707 // have the LHS 'left' of the RHS.
708 if (Previous && Previous->getPrecedence() > prec::Assignment &&
709 (Previous->Type == TT_BinaryOperator ||
710 Previous->Type == TT_ConditionalExpr) &&
711 Previous->getPrecedence() != prec::Relational) {
712 bool BreakBeforeOperator = Previous->is(tok::lessless) ||
713 (Previous->Type == TT_BinaryOperator &&
714 Style.BreakBeforeBinaryOperators) ||
715 (Previous->Type == TT_ConditionalExpr &&
716 Style.BreakBeforeTernaryOperators);
717 if ((!Newline && !BreakBeforeOperator) ||
718 (!State.Stack.back().LastOperatorWrapped && BreakBeforeOperator))
719 NewParenState.NoLineBreak = true;
720 }
721
722 // Do not indent relative to the fake parentheses inserted for "." or "->".
723 // This is a special case to make the following to statements consistent:
724 // OuterFunction(InnerFunctionCall( // break
725 // ParameterToInnerFunction));
726 // OuterFunction(SomeObject.InnerFunctionCall( // break
727 // ParameterToInnerFunction));
728 if (*I > prec::Unknown)
729 NewParenState.LastSpace = std::max(NewParenState.LastSpace, State.Column);
730 NewParenState.StartOfFunctionCall = State.Column;
731
732 // Always indent conditional expressions. Never indent expression where
733 // the 'operator' is ',', ';' or an assignment (i.e. *I <=
734 // prec::Assignment) as those have different indentation rules. Indent
735 // other expression, unless the indentation needs to be skipped.
736 if (*I == prec::Conditional ||
737 (!SkipFirstExtraIndent && *I > prec::Assignment &&
738 !Style.BreakBeforeBinaryOperators))
739 NewParenState.Indent += Style.ContinuationIndentWidth;
740 if ((Previous && !Previous->opensScope()) || *I > prec::Comma)
741 NewParenState.BreakBeforeParameter = false;
742 State.Stack.push_back(NewParenState);
743 SkipFirstExtraIndent = false;
744 }
745}
746
Stephen Hinesc568f1e2014-07-21 00:47:37 -0700747// Remove the fake r_parens after 'Tok'.
748static void consumeRParens(LineState& State, const FormatToken &Tok) {
749 for (unsigned i = 0, e = Tok.FakeRParens; i != e; ++i) {
750 unsigned VariablePos = State.Stack.back().VariablePos;
751 assert(State.Stack.size() > 1);
752 if (State.Stack.size() == 1) {
753 // Do not pop the last element.
754 break;
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700755 }
Stephen Hinesc568f1e2014-07-21 00:47:37 -0700756 State.Stack.pop_back();
757 State.Stack.back().VariablePos = VariablePos;
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700758 }
759}
760
Stephen Hinesc568f1e2014-07-21 00:47:37 -0700761// Returns whether 'Tok' opens or closes a scope requiring special handling
762// of the subsequent fake r_parens.
763//
764// For example, if this is an l_brace starting a nested block, we pretend (wrt.
765// to indentation) that we already consumed the corresponding r_brace. Thus, we
766// remove all ParenStates caused by fake parentheses that end at the r_brace.
767// The net effect of this is that we don't indent relative to the l_brace, if
768// the nested block is the last parameter of a function. This formats:
769//
770// SomeFunction(a, [] {
771// f(); // break
772// });
773//
774// instead of:
775// SomeFunction(a, [] {
776// f(); // break
777// });
778static bool fakeRParenSpecialCase(const LineState &State) {
779 const FormatToken &Tok = *State.NextToken;
780 if (!Tok.MatchingParen)
781 return false;
782 const FormatToken *Left = &Tok;
783 if (Tok.isOneOf(tok::r_brace, tok::r_square))
784 Left = Tok.MatchingParen;
785 return !State.Stack.back().HasMultipleNestedBlocks &&
786 Left->isOneOf(tok::l_brace, tok::l_square) &&
787 (Left->BlockKind == BK_Block ||
788 Left->Type == TT_ArrayInitializerLSquare ||
789 Left->Type == TT_DictLiteral);
790}
791
792void ContinuationIndenter::moveStatePastFakeRParens(LineState &State) {
793 // Don't remove FakeRParens attached to r_braces that surround nested blocks
794 // as they will have been removed early (see above).
795 if (fakeRParenSpecialCase(State))
796 return;
797
798 consumeRParens(State, *State.NextToken);
799}
800
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700801void ContinuationIndenter::moveStatePastScopeOpener(LineState &State,
802 bool Newline) {
803 const FormatToken &Current = *State.NextToken;
804 if (!Current.opensScope())
805 return;
806
807 if (Current.MatchingParen && Current.BlockKind == BK_Block) {
808 moveStateToNewBlock(State);
809 return;
810 }
811
812 unsigned NewIndent;
813 unsigned NewIndentLevel = State.Stack.back().IndentLevel;
814 bool AvoidBinPacking;
815 bool BreakBeforeParameter = false;
816 if (Current.is(tok::l_brace) || Current.Type == TT_ArrayInitializerLSquare) {
Stephen Hinesc568f1e2014-07-21 00:47:37 -0700817 if (fakeRParenSpecialCase(State))
818 consumeRParens(State, *Current.MatchingParen);
819
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700820 NewIndent = State.Stack.back().LastSpace;
821 if (Current.opensBlockTypeList(Style)) {
822 NewIndent += Style.IndentWidth;
823 NewIndent = std::min(State.Column + 2, NewIndent);
824 ++NewIndentLevel;
825 } else {
826 NewIndent += Style.ContinuationIndentWidth;
827 NewIndent = std::min(State.Column + 1, NewIndent);
828 }
829 const FormatToken *NextNoComment = Current.getNextNonComment();
830 AvoidBinPacking = Current.Type == TT_ArrayInitializerLSquare ||
831 Current.Type == TT_DictLiteral ||
832 Style.Language == FormatStyle::LK_Proto ||
833 !Style.BinPackParameters ||
834 (NextNoComment &&
835 NextNoComment->Type == TT_DesignatedInitializerPeriod);
836 } else {
837 NewIndent = Style.ContinuationIndentWidth +
838 std::max(State.Stack.back().LastSpace,
839 State.Stack.back().StartOfFunctionCall);
840 AvoidBinPacking = !Style.BinPackParameters ||
841 (Style.ExperimentalAutoDetectBinPacking &&
842 (Current.PackingKind == PPK_OnePerLine ||
843 (!BinPackInconclusiveFunctions &&
844 Current.PackingKind == PPK_Inconclusive)));
845 // If this '[' opens an ObjC call, determine whether all parameters fit
846 // into one line and put one per line if they don't.
847 if (Current.Type == TT_ObjCMethodExpr && Style.ColumnLimit != 0 &&
848 getLengthToMatchingParen(Current) + State.Column >
849 getColumnLimit(State))
850 BreakBeforeParameter = true;
851 }
852 bool NoLineBreak = State.Stack.back().NoLineBreak ||
853 (Current.Type == TT_TemplateOpener &&
854 State.Stack.back().ContainsUnwrappedBuilder);
855 State.Stack.push_back(ParenState(NewIndent, NewIndentLevel,
856 State.Stack.back().LastSpace,
857 AvoidBinPacking, NoLineBreak));
858 State.Stack.back().BreakBeforeParameter = BreakBeforeParameter;
Stephen Hinesc568f1e2014-07-21 00:47:37 -0700859 State.Stack.back().HasMultipleNestedBlocks = Current.BlockParameterCount > 1;
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700860}
861
862void ContinuationIndenter::moveStatePastScopeCloser(LineState &State) {
863 const FormatToken &Current = *State.NextToken;
864 if (!Current.closesScope())
865 return;
866
867 // If we encounter a closing ), ], } or >, we can remove a level from our
868 // stacks.
869 if (State.Stack.size() > 1 &&
870 (Current.isOneOf(tok::r_paren, tok::r_square) ||
871 (Current.is(tok::r_brace) && State.NextToken != State.Line->First) ||
Stephen Hinesc568f1e2014-07-21 00:47:37 -0700872 State.NextToken->Type == TT_TemplateCloser))
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700873 State.Stack.pop_back();
Stephen Hinesc568f1e2014-07-21 00:47:37 -0700874
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700875 if (Current.is(tok::r_square)) {
876 // If this ends the array subscript expr, reset the corresponding value.
877 const FormatToken *NextNonComment = Current.getNextNonComment();
878 if (NextNonComment && NextNonComment->isNot(tok::l_square))
879 State.Stack.back().StartOfArraySubscripts = 0;
880 }
881}
882
883void ContinuationIndenter::moveStateToNewBlock(LineState &State) {
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700884 // If we have already found more than one lambda introducers on this level, we
885 // opt out of this because similarity between the lambdas is more important.
Stephen Hinesc568f1e2014-07-21 00:47:37 -0700886 if (fakeRParenSpecialCase(State))
887 consumeRParens(State, *State.NextToken->MatchingParen);
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700888
889 // For some reason, ObjC blocks are indented like continuations.
890 unsigned NewIndent = State.Stack.back().LastSpace +
891 (State.NextToken->Type == TT_ObjCBlockLBrace
892 ? Style.ContinuationIndentWidth
893 : Style.IndentWidth);
894 State.Stack.push_back(ParenState(
895 NewIndent, /*NewIndentLevel=*/State.Stack.back().IndentLevel + 1,
896 State.Stack.back().LastSpace, /*AvoidBinPacking=*/true,
897 State.Stack.back().NoLineBreak));
898 State.Stack.back().BreakBeforeParameter = true;
899}
900
Alexander Kornienko6f6154c2013-09-10 12:29:48 +0000901unsigned ContinuationIndenter::addMultilineToken(const FormatToken &Current,
902 LineState &State) {
Alexander Kornienkodcc0c5b2013-08-29 17:32:57 +0000903 // Break before further function parameters on all levels.
904 for (unsigned i = 0, e = State.Stack.size(); i != e; ++i)
905 State.Stack[i].BreakBeforeParameter = true;
906
Alexander Kornienko83a7dcd2013-09-10 09:38:25 +0000907 unsigned ColumnsUsed = State.Column;
Alexander Kornienko4b762a92013-09-02 13:58:14 +0000908 // We can only affect layout of the first and the last line, so the penalty
909 // for all other lines is constant, and we ignore it.
Alexander Kornienko0b62cc32013-09-05 14:08:34 +0000910 State.Column = Current.LastLineColumnWidth;
Alexander Kornienko4b762a92013-09-02 13:58:14 +0000911
Daniel Jasper567dcf92013-09-05 09:29:45 +0000912 if (ColumnsUsed > getColumnLimit(State))
913 return Style.PenaltyExcessCharacter * (ColumnsUsed - getColumnLimit(State));
Alexander Kornienkodcc0c5b2013-08-29 17:32:57 +0000914 return 0;
915}
916
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700917static bool getRawStringLiteralPrefixPostfix(StringRef Text, StringRef &Prefix,
Alexander Kornienko2c2f7292013-09-16 20:20:49 +0000918 StringRef &Postfix) {
919 if (Text.startswith(Prefix = "R\"") || Text.startswith(Prefix = "uR\"") ||
920 Text.startswith(Prefix = "UR\"") || Text.startswith(Prefix = "u8R\"") ||
921 Text.startswith(Prefix = "LR\"")) {
922 size_t ParenPos = Text.find('(');
923 if (ParenPos != StringRef::npos) {
924 StringRef Delimiter =
925 Text.substr(Prefix.size(), ParenPos - Prefix.size());
926 Prefix = Text.substr(0, ParenPos + 1);
927 Postfix = Text.substr(Text.size() - 2 - Delimiter.size());
928 return Postfix.front() == ')' && Postfix.back() == '"' &&
929 Postfix.substr(1).startswith(Delimiter);
930 }
931 }
932 return false;
933}
934
Daniel Jasper6b2afe42013-08-16 11:20:30 +0000935unsigned ContinuationIndenter::breakProtrudingToken(const FormatToken &Current,
936 LineState &State,
937 bool DryRun) {
Alexander Kornienko6f6154c2013-09-10 12:29:48 +0000938 // Don't break multi-line tokens other than block comments. Instead, just
939 // update the state.
940 if (Current.Type != TT_BlockComment && Current.IsMultiline)
941 return addMultilineToken(Current, State);
942
Daniel Jasper84379572013-10-30 13:54:53 +0000943 // Don't break implicit string literals.
944 if (Current.Type == TT_ImplicitStringLiteral)
945 return 0;
946
Stephen Hines651f13c2014-04-23 16:59:28 -0700947 if (!Current.isStringLiteral() && !Current.is(tok::comment))
Daniel Jaspered51c022013-08-23 10:05:49 +0000948 return 0;
949
Stephen Hines651f13c2014-04-23 16:59:28 -0700950 std::unique_ptr<BreakableToken> Token;
Alexander Kornienko83a7dcd2013-09-10 09:38:25 +0000951 unsigned StartColumn = State.Column - Current.ColumnWidth;
Alexander Kornienko5486a422013-11-12 17:30:49 +0000952 unsigned ColumnLimit = getColumnLimit(State);
Daniel Jasper6b2afe42013-08-16 11:20:30 +0000953
Stephen Hines651f13c2014-04-23 16:59:28 -0700954 if (Current.isStringLiteral()) {
Alexander Kornienkob18c2582013-10-11 21:43:05 +0000955 // Don't break string literals inside preprocessor directives (except for
956 // #define directives, as their contents are stored in separate lines and
957 // are not affected by this check).
958 // This way we avoid breaking code with line directives and unknown
959 // preprocessor directives that contain long string literals.
960 if (State.Line->Type == LT_PreprocessorDirective)
961 return 0;
Daniel Jasper6b2afe42013-08-16 11:20:30 +0000962 // Exempts unterminated string literals from line breaking. The user will
963 // likely want to terminate the string before any line breaking is done.
964 if (Current.IsUnterminatedLiteral)
965 return 0;
966
Alexander Kornienko2c2f7292013-09-16 20:20:49 +0000967 StringRef Text = Current.TokenText;
968 StringRef Prefix;
969 StringRef Postfix;
Stephen Hines651f13c2014-04-23 16:59:28 -0700970 bool IsNSStringLiteral = false;
Alexander Kornienko2c2f7292013-09-16 20:20:49 +0000971 // FIXME: Handle whitespace between '_T', '(', '"..."', and ')'.
972 // FIXME: Store Prefix and Suffix (or PrefixLength and SuffixLength to
973 // reduce the overhead) for each FormatToken, which is a string, so that we
974 // don't run multiple checks here on the hot path.
Stephen Hines651f13c2014-04-23 16:59:28 -0700975 if (Text.startswith("\"") && Current.Previous &&
976 Current.Previous->is(tok::at)) {
977 IsNSStringLiteral = true;
978 Prefix = "@\"";
979 }
Alexander Kornienko2c2f7292013-09-16 20:20:49 +0000980 if ((Text.endswith(Postfix = "\"") &&
Stephen Hines651f13c2014-04-23 16:59:28 -0700981 (IsNSStringLiteral || Text.startswith(Prefix = "\"") ||
982 Text.startswith(Prefix = "u\"") || Text.startswith(Prefix = "U\"") ||
983 Text.startswith(Prefix = "u8\"") ||
Alexander Kornienko2c2f7292013-09-16 20:20:49 +0000984 Text.startswith(Prefix = "L\""))) ||
985 (Text.startswith(Prefix = "_T(\"") && Text.endswith(Postfix = "\")")) ||
986 getRawStringLiteralPrefixPostfix(Text, Prefix, Postfix)) {
Alexander Kornienko3d9ffcf2013-09-27 16:14:22 +0000987 Token.reset(new BreakableStringLiteral(
988 Current, State.Line->Level, StartColumn, Prefix, Postfix,
989 State.Line->InPPDirective, Encoding, Style));
Alexander Kornienko2c2f7292013-09-16 20:20:49 +0000990 } else {
991 return 0;
992 }
Daniel Jasper6b2afe42013-08-16 11:20:30 +0000993 } else if (Current.Type == TT_BlockComment && Current.isTrailingComment()) {
Stephen Hines651f13c2014-04-23 16:59:28 -0700994 if (CommentPragmasRegex.match(Current.TokenText.substr(2)))
995 return 0;
Daniel Jasper6b2afe42013-08-16 11:20:30 +0000996 Token.reset(new BreakableBlockComment(
Alexander Kornienko3d9ffcf2013-09-27 16:14:22 +0000997 Current, State.Line->Level, StartColumn, Current.OriginalColumn,
998 !Current.Previous, State.Line->InPPDirective, Encoding, Style));
Daniel Jasper6b2afe42013-08-16 11:20:30 +0000999 } else if (Current.Type == TT_LineComment &&
Stephen Hines6bcf27b2014-05-29 04:14:42 -07001000 (Current.Previous == nullptr ||
Daniel Jasper6b2afe42013-08-16 11:20:30 +00001001 Current.Previous->Type != TT_ImplicitStringLiteral)) {
Stephen Hines651f13c2014-04-23 16:59:28 -07001002 if (CommentPragmasRegex.match(Current.TokenText.substr(2)))
1003 return 0;
Alexander Kornienko3d9ffcf2013-09-27 16:14:22 +00001004 Token.reset(new BreakableLineComment(Current, State.Line->Level,
Alexander Kornienko5486a422013-11-12 17:30:49 +00001005 StartColumn, /*InPPDirective=*/false,
Alexander Kornienko3d9ffcf2013-09-27 16:14:22 +00001006 Encoding, Style));
Alexander Kornienko5486a422013-11-12 17:30:49 +00001007 // We don't insert backslashes when breaking line comments.
1008 ColumnLimit = Style.ColumnLimit;
Daniel Jasper6b2afe42013-08-16 11:20:30 +00001009 } else {
1010 return 0;
1011 }
Alexander Kornienko5486a422013-11-12 17:30:49 +00001012 if (Current.UnbreakableTailLength >= ColumnLimit)
Daniel Jasper6b2afe42013-08-16 11:20:30 +00001013 return 0;
1014
Alexander Kornienko5486a422013-11-12 17:30:49 +00001015 unsigned RemainingSpace = ColumnLimit - Current.UnbreakableTailLength;
Daniel Jasper6b2afe42013-08-16 11:20:30 +00001016 bool BreakInserted = false;
1017 unsigned Penalty = 0;
1018 unsigned RemainingTokenColumns = 0;
1019 for (unsigned LineIndex = 0, EndIndex = Token->getLineCount();
1020 LineIndex != EndIndex; ++LineIndex) {
1021 if (!DryRun)
1022 Token->replaceWhitespaceBefore(LineIndex, Whitespaces);
1023 unsigned TailOffset = 0;
1024 RemainingTokenColumns =
1025 Token->getLineLengthAfterSplit(LineIndex, TailOffset, StringRef::npos);
1026 while (RemainingTokenColumns > RemainingSpace) {
1027 BreakableToken::Split Split =
Alexander Kornienko5486a422013-11-12 17:30:49 +00001028 Token->getSplit(LineIndex, TailOffset, ColumnLimit);
Daniel Jasper6b2afe42013-08-16 11:20:30 +00001029 if (Split.first == StringRef::npos) {
1030 // The last line's penalty is handled in addNextStateToQueue().
1031 if (LineIndex < EndIndex - 1)
1032 Penalty += Style.PenaltyExcessCharacter *
1033 (RemainingTokenColumns - RemainingSpace);
1034 break;
1035 }
1036 assert(Split.first != 0);
1037 unsigned NewRemainingTokenColumns = Token->getLineLengthAfterSplit(
1038 LineIndex, TailOffset + Split.first + Split.second, StringRef::npos);
Alexander Kornienkoa7462b82013-11-12 17:50:13 +00001039
1040 // We can remove extra whitespace instead of breaking the line.
1041 if (RemainingTokenColumns + 1 - Split.second <= RemainingSpace) {
1042 RemainingTokenColumns = 0;
1043 if (!DryRun)
1044 Token->replaceWhitespace(LineIndex, TailOffset, Split, Whitespaces);
1045 break;
1046 }
1047
Stephen Hines6bcf27b2014-05-29 04:14:42 -07001048 // When breaking before a tab character, it may be moved by a few columns,
1049 // but will still be expanded to the next tab stop, so we don't save any
1050 // columns.
1051 if (NewRemainingTokenColumns == RemainingTokenColumns)
1052 break;
1053
Daniel Jasper6b2afe42013-08-16 11:20:30 +00001054 assert(NewRemainingTokenColumns < RemainingTokenColumns);
1055 if (!DryRun)
1056 Token->insertBreak(LineIndex, TailOffset, Split, Whitespaces);
Daniel Jasperf5461782013-08-28 10:03:58 +00001057 Penalty += Current.SplitPenalty;
Daniel Jasper6b2afe42013-08-16 11:20:30 +00001058 unsigned ColumnsUsed =
1059 Token->getLineLengthAfterSplit(LineIndex, TailOffset, Split.first);
Alexander Kornienko5486a422013-11-12 17:30:49 +00001060 if (ColumnsUsed > ColumnLimit) {
1061 Penalty += Style.PenaltyExcessCharacter * (ColumnsUsed - ColumnLimit);
Daniel Jasper6b2afe42013-08-16 11:20:30 +00001062 }
1063 TailOffset += Split.first + Split.second;
1064 RemainingTokenColumns = NewRemainingTokenColumns;
1065 BreakInserted = true;
1066 }
1067 }
1068
1069 State.Column = RemainingTokenColumns;
1070
1071 if (BreakInserted) {
1072 // If we break the token inside a parameter list, we need to break before
1073 // the next parameter on all levels, so that the next parameter is clearly
1074 // visible. Line comments already introduce a break.
1075 if (Current.Type != TT_LineComment) {
1076 for (unsigned i = 0, e = State.Stack.size(); i != e; ++i)
1077 State.Stack[i].BreakBeforeParameter = true;
1078 }
1079
Stephen Hines651f13c2014-04-23 16:59:28 -07001080 Penalty += Current.isStringLiteral() ? Style.PenaltyBreakString
1081 : Style.PenaltyBreakComment;
Daniel Jasperf5461782013-08-28 10:03:58 +00001082
Daniel Jasper6b2afe42013-08-16 11:20:30 +00001083 State.Stack.back().LastSpace = StartColumn;
1084 }
1085 return Penalty;
1086}
1087
Daniel Jasper567dcf92013-09-05 09:29:45 +00001088unsigned ContinuationIndenter::getColumnLimit(const LineState &State) const {
Daniel Jasper6b2afe42013-08-16 11:20:30 +00001089 // In preprocessor directives reserve two chars for trailing " \"
Daniel Jasper567dcf92013-09-05 09:29:45 +00001090 return Style.ColumnLimit - (State.Line->InPPDirective ? 2 : 0);
Daniel Jasper6b2afe42013-08-16 11:20:30 +00001091}
1092
Stephen Hines651f13c2014-04-23 16:59:28 -07001093bool ContinuationIndenter::nextIsMultilineString(const LineState &State) {
Daniel Jasper4df1ff92013-08-23 11:57:34 +00001094 const FormatToken &Current = *State.NextToken;
Stephen Hines6bcf27b2014-05-29 04:14:42 -07001095 if (!Current.isStringLiteral() || Current.Type == TT_ImplicitStringLiteral)
Daniel Jasper4df1ff92013-08-23 11:57:34 +00001096 return false;
Alexander Kornienkodcc0c5b2013-08-29 17:32:57 +00001097 // We never consider raw string literals "multiline" for the purpose of
Stephen Hines651f13c2014-04-23 16:59:28 -07001098 // AlwaysBreakBeforeMultilineStrings implementation as they are special-cased
1099 // (see TokenAnnotator::mustBreakBefore().
Alexander Kornienkodcc0c5b2013-08-29 17:32:57 +00001100 if (Current.TokenText.startswith("R\""))
1101 return false;
Alexander Kornienko83a7dcd2013-09-10 09:38:25 +00001102 if (Current.IsMultiline)
Alexander Kornienkodcc0c5b2013-08-29 17:32:57 +00001103 return true;
Daniel Jasper4df1ff92013-08-23 11:57:34 +00001104 if (Current.getNextNonComment() &&
Stephen Hines651f13c2014-04-23 16:59:28 -07001105 Current.getNextNonComment()->isStringLiteral())
Daniel Jasper4df1ff92013-08-23 11:57:34 +00001106 return true; // Implicit concatenation.
Alexander Kornienko83a7dcd2013-09-10 09:38:25 +00001107 if (State.Column + Current.ColumnWidth + Current.UnbreakableTailLength >
Daniel Jasper4df1ff92013-08-23 11:57:34 +00001108 Style.ColumnLimit)
1109 return true; // String will be split.
Alexander Kornienkodcc0c5b2013-08-29 17:32:57 +00001110 return false;
Daniel Jasper4df1ff92013-08-23 11:57:34 +00001111}
1112
Daniel Jasper6b2afe42013-08-16 11:20:30 +00001113} // namespace format
1114} // namespace clang