blob: 3714088306c8b6b87a0cb218bcdacade14423a5f [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
15#define DEBUG_TYPE "format-formatter"
16
17#include "BreakableToken.h"
18#include "ContinuationIndenter.h"
19#include "WhitespaceManager.h"
20#include "clang/Basic/OperatorPrecedence.h"
21#include "clang/Basic/SourceManager.h"
22#include "clang/Format/Format.h"
23#include "llvm/Support/Debug.h"
24#include <string>
25
26namespace 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) {
32 if (Tok.MatchingParen == NULL)
33 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),
Daniel Jasper6b2afe42013-08-16 11:20:30 +000066 BinPackInconclusiveFunctions(BinPackInconclusiveFunctions) {}
67
Daniel Jasper567dcf92013-09-05 09:29:45 +000068LineState ContinuationIndenter::getInitialState(unsigned FirstIndent,
Daniel Jasperb77d7412013-09-06 07:54:20 +000069 const AnnotatedLine *Line,
70 bool DryRun) {
Daniel Jasper6b2afe42013-08-16 11:20:30 +000071 LineState State;
Daniel Jasper567dcf92013-09-05 09:29:45 +000072 State.FirstIndent = FirstIndent;
Daniel Jasper6b2afe42013-08-16 11:20:30 +000073 State.Column = FirstIndent;
Daniel Jasper567dcf92013-09-05 09:29:45 +000074 State.Line = Line;
75 State.NextToken = Line->First;
Daniel Jasper6b2afe42013-08-16 11:20:30 +000076 State.Stack.push_back(ParenState(FirstIndent, FirstIndent,
77 /*AvoidBinPacking=*/false,
78 /*NoLineBreak=*/false));
79 State.LineContainsContinuedForLoopSection = false;
80 State.ParenLevel = 0;
81 State.StartOfStringLiteral = 0;
82 State.StartOfLineLevel = State.ParenLevel;
83 State.LowestLevelOnLine = State.ParenLevel;
84 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);
95 if (!Current.CanBreakBefore &&
96 !(Current.is(tok::r_brace) && State.Stack.back().BreakBeforeClosingBrace))
97 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) &&
Daniel Jasper567dcf92013-09-05 09:29:45 +0000101 Previous.BlockKind == BK_BracedInit && Previous.Previous &&
Daniel Jasper6b2afe42013-08-16 11:20:30 +0000102 Previous.Previous->isOneOf(tok::l_brace, tok::l_paren, tok::comma))
103 return false;
104 // This prevents breaks like:
105 // ...
106 // SomeParameter, OtherParameter).DoSomething(
107 // ...
108 // As they hide "DoSomething" and are generally bad for readability.
109 if (Previous.opensScope() && State.LowestLevelOnLine < State.StartOfLineLevel)
110 return false;
Daniel Jasperd3fef0f2013-08-27 14:24:43 +0000111 if (Current.isMemberAccess() && State.Stack.back().ContainsUnwrappedBuilder)
112 return false;
Daniel Jasper6b2afe42013-08-16 11:20:30 +0000113 return !State.Stack.back().NoLineBreak;
114}
115
116bool ContinuationIndenter::mustBreak(const LineState &State) {
117 const FormatToken &Current = *State.NextToken;
118 const FormatToken &Previous = *Current.Previous;
119 if (Current.MustBreakBefore || Current.Type == TT_InlineASMColon)
120 return true;
Daniel Jasper57981202013-09-13 09:20:45 +0000121 if ((!Style.Cpp11BracedListStyle ||
122 (Current.MatchingParen &&
123 Current.MatchingParen->BlockKind == BK_Block)) &&
124 Current.is(tok::r_brace) && State.Stack.back().BreakBeforeClosingBrace)
Daniel Jasper6b2afe42013-08-16 11:20:30 +0000125 return true;
126 if (Previous.is(tok::semi) && State.LineContainsContinuedForLoopSection)
127 return true;
Daniel Jasper19ccb122013-10-08 05:11:18 +0000128 if ((startsNextParameter(Current, Style) || Previous.is(tok::semi) ||
129 Current.is(tok::question) ||
130 (Current.Type == TT_ConditionalExpr && Previous.isNot(tok::question))) &&
Daniel Jasper6b2afe42013-08-16 11:20:30 +0000131 State.Stack.back().BreakBeforeParameter && !Current.isTrailingComment() &&
132 !Current.isOneOf(tok::r_paren, tok::r_brace))
133 return true;
134 if (Style.AlwaysBreakBeforeMultilineStrings &&
Daniel Jasper4df1ff92013-08-23 11:57:34 +0000135 State.Column > State.Stack.back().Indent && // Breaking saves columns.
136 Previous.isNot(tok::lessless) && Previous.Type != TT_InlineASMColon &&
137 NextIsMultilineString(State))
Daniel Jasper6b2afe42013-08-16 11:20:30 +0000138 return true;
139
140 if (!Style.BreakBeforeBinaryOperators) {
141 // If we need to break somewhere inside the LHS of a binary expression, we
142 // should also break after the operator. Otherwise, the formatting would
143 // hide the operator precedence, e.g. in:
144 // if (aaaaaaaaaaaaaa ==
145 // bbbbbbbbbbbbbb && c) {..
146 // For comparisons, we only apply this rule, if the LHS is a binary
147 // expression itself as otherwise, the line breaks seem superfluous.
148 // We need special cases for ">>" which we have split into two ">" while
149 // lexing in order to make template parsing easier.
150 //
151 // FIXME: We'll need something similar for styles that break before binary
152 // operators.
153 bool IsComparison = (Previous.getPrecedence() == prec::Relational ||
154 Previous.getPrecedence() == prec::Equality) &&
155 Previous.Previous &&
156 Previous.Previous->Type != TT_BinaryOperator; // For >>.
157 bool LHSIsBinaryExpr =
Daniel Jasperdb4813a2013-09-06 08:08:14 +0000158 Previous.Previous && Previous.Previous->EndsBinaryExpression;
Daniel Jasper6b2afe42013-08-16 11:20:30 +0000159 if (Previous.Type == TT_BinaryOperator &&
160 (!IsComparison || LHSIsBinaryExpr) &&
161 Current.Type != TT_BinaryOperator && // For >>.
162 !Current.isTrailingComment() &&
163 !Previous.isOneOf(tok::lessless, tok::question) &&
164 Previous.getPrecedence() != prec::Assignment &&
165 State.Stack.back().BreakBeforeParameter)
166 return true;
167 }
168
169 // Same as above, but for the first "<<" operator.
170 if (Current.is(tok::lessless) && State.Stack.back().BreakBeforeParameter &&
171 State.Stack.back().FirstLessLess == 0)
172 return true;
173
174 // FIXME: Comparing LongestObjCSelectorName to 0 is a hacky way of finding
175 // out whether it is the first parameter. Clean this up.
176 if (Current.Type == TT_ObjCSelectorName &&
177 Current.LongestObjCSelectorName == 0 &&
178 State.Stack.back().BreakBeforeParameter)
179 return true;
180 if ((Current.Type == TT_CtorInitializerColon ||
181 (Previous.ClosesTemplateDeclaration && State.ParenLevel == 0)))
182 return true;
183
184 if ((Current.Type == TT_StartOfName || Current.is(tok::kw_operator)) &&
Daniel Jasper567dcf92013-09-05 09:29:45 +0000185 State.Line->MightBeFunctionDecl &&
186 State.Stack.back().BreakBeforeParameter && State.ParenLevel == 0)
Daniel Jasper6b2afe42013-08-16 11:20:30 +0000187 return true;
Daniel Jasperd3fef0f2013-08-27 14:24:43 +0000188 if (startsSegmentOfBuilderTypeCall(Current) &&
Daniel Jaspereb331832013-08-30 07:12:40 +0000189 (State.Stack.back().CallContinuation != 0 ||
190 (State.Stack.back().BreakBeforeParameter &&
191 State.Stack.back().ContainsUnwrappedBuilder)))
Daniel Jasperd3fef0f2013-08-27 14:24:43 +0000192 return true;
Daniel Jasper6b2afe42013-08-16 11:20:30 +0000193 return false;
194}
195
196unsigned ContinuationIndenter::addTokenToState(LineState &State, bool Newline,
Daniel Jasperd4a03db2013-08-22 15:00:41 +0000197 bool DryRun,
198 unsigned ExtraSpaces) {
Daniel Jasper6b2afe42013-08-16 11:20:30 +0000199 const FormatToken &Current = *State.NextToken;
Daniel Jasper6b2afe42013-08-16 11:20:30 +0000200
201 if (State.Stack.size() == 0 || Current.Type == TT_ImplicitStringLiteral) {
202 // FIXME: Is this correct?
203 int WhitespaceLength = SourceMgr.getSpellingColumnNumber(
204 State.NextToken->WhitespaceRange.getEnd()) -
205 SourceMgr.getSpellingColumnNumber(
206 State.NextToken->WhitespaceRange.getBegin());
Alexander Kornienko83a7dcd2013-09-10 09:38:25 +0000207 State.Column += WhitespaceLength + State.NextToken->ColumnWidth;
Daniel Jasper6b2afe42013-08-16 11:20:30 +0000208 State.NextToken = State.NextToken->Next;
209 return 0;
210 }
211
Alexander Kornienkoe5321c42013-10-01 14:41:18 +0000212 unsigned Penalty = 0;
213 if (Newline)
214 Penalty = addTokenOnNewLine(State, DryRun);
215 else
216 addTokenOnCurrentLine(State, DryRun, ExtraSpaces);
217
218 return moveStateToNextToken(State, DryRun, Newline) + Penalty;
219}
220
221void ContinuationIndenter::addTokenOnCurrentLine(LineState &State, bool DryRun,
222 unsigned ExtraSpaces) {
223 const FormatToken &Current = *State.NextToken;
224 const FormatToken &Previous = *State.NextToken->Previous;
225 if (Current.is(tok::equal) &&
226 (State.Line->First->is(tok::kw_for) || State.ParenLevel == 0) &&
227 State.Stack.back().VariablePos == 0) {
228 State.Stack.back().VariablePos = State.Column;
229 // Move over * and & if they are bound to the variable name.
230 const FormatToken *Tok = &Previous;
231 while (Tok && State.Stack.back().VariablePos >= Tok->ColumnWidth) {
232 State.Stack.back().VariablePos -= Tok->ColumnWidth;
233 if (Tok->SpacesRequiredBefore != 0)
234 break;
235 Tok = Tok->Previous;
236 }
237 if (Previous.PartOfMultiVariableDeclStmt)
238 State.Stack.back().LastSpace = State.Stack.back().VariablePos;
239 }
240
241 unsigned Spaces = Current.SpacesRequiredBefore + ExtraSpaces;
242
243 if (!DryRun)
244 Whitespaces.replaceWhitespace(Current, /*Newlines=*/0, /*IndentLevel=*/0,
245 Spaces, State.Column + Spaces);
246
247 if (Current.Type == TT_ObjCSelectorName && State.Stack.back().ColonPos == 0) {
248 if (State.Stack.back().Indent + Current.LongestObjCSelectorName >
249 State.Column + Spaces + Current.ColumnWidth)
250 State.Stack.back().ColonPos =
251 State.Stack.back().Indent + Current.LongestObjCSelectorName;
252 else
253 State.Stack.back().ColonPos = State.Column + Spaces + Current.ColumnWidth;
254 }
255
256 if (Previous.opensScope() && Previous.Type != TT_ObjCMethodExpr &&
257 Current.Type != TT_LineComment)
258 State.Stack.back().Indent = State.Column + Spaces;
Daniel Jasper19ccb122013-10-08 05:11:18 +0000259 if (State.Stack.back().AvoidBinPacking && startsNextParameter(Current, Style))
Alexander Kornienkoe5321c42013-10-01 14:41:18 +0000260 State.Stack.back().NoLineBreak = true;
261 if (startsSegmentOfBuilderTypeCall(Current))
262 State.Stack.back().ContainsUnwrappedBuilder = true;
263
264 State.Column += Spaces;
265 if (Current.is(tok::l_paren) && Previous.isOneOf(tok::kw_if, tok::kw_for))
266 // Treat the condition inside an if as if it was a second function
267 // parameter, i.e. let nested calls have an indent of 4.
268 State.Stack.back().LastSpace = State.Column + 1; // 1 is length of "(".
269 else if (Previous.is(tok::comma))
270 State.Stack.back().LastSpace = State.Column;
271 else if ((Previous.Type == TT_BinaryOperator ||
272 Previous.Type == TT_ConditionalExpr ||
273 Previous.Type == TT_UnaryOperator ||
274 Previous.Type == TT_CtorInitializerColon) &&
275 (Previous.getPrecedence() != prec::Assignment ||
276 Current.StartsBinaryExpression))
277 // Always indent relative to the RHS of the expression unless this is a
278 // simple assignment without binary expression on the RHS. Also indent
279 // relative to unary operators and the colons of constructor initializers.
280 State.Stack.back().LastSpace = State.Column;
Daniel Jaspercea014b2013-10-08 16:24:07 +0000281 else if (Previous.Type == TT_InheritanceColon) {
Alexander Kornienkoe5321c42013-10-01 14:41:18 +0000282 State.Stack.back().Indent = State.Column;
Daniel Jaspercea014b2013-10-08 16:24:07 +0000283 State.Stack.back().LastSpace = State.Column;
284 } else if (Previous.opensScope()) {
Alexander Kornienkoe5321c42013-10-01 14:41:18 +0000285 // If a function has a trailing call, indent all parameters from the
286 // opening parenthesis. This avoids confusing indents like:
287 // OuterFunction(InnerFunctionCall( // break
288 // ParameterToInnerFunction)) // break
289 // .SecondInnerFunctionCall();
290 bool HasTrailingCall = false;
291 if (Previous.MatchingParen) {
292 const FormatToken *Next = Previous.MatchingParen->getNextNonComment();
293 HasTrailingCall = Next && Next->isMemberAccess();
294 }
295 if (HasTrailingCall &&
296 State.Stack[State.Stack.size() - 2].CallContinuation == 0)
297 State.Stack.back().LastSpace = State.Column;
298 }
299}
300
301unsigned ContinuationIndenter::addTokenOnNewLine(LineState &State,
302 bool DryRun) {
303 const FormatToken &Current = *State.NextToken;
304 const FormatToken &Previous = *State.NextToken->Previous;
Daniel Jasper6b2afe42013-08-16 11:20:30 +0000305 // If we are continuing an expression, we want to indent an extra 4 spaces.
306 unsigned ContinuationIndent =
307 std::max(State.Stack.back().LastSpace, State.Stack.back().Indent) + 4;
Alexander Kornienkoe5321c42013-10-01 14:41:18 +0000308 // Extra penalty that needs to be added because of the way certain line
309 // breaks are chosen.
310 unsigned Penalty = 0;
Daniel Jasperd4a03db2013-08-22 15:00:41 +0000311
Alexander Kornienkoe5321c42013-10-01 14:41:18 +0000312 const FormatToken *PreviousNonComment =
313 State.NextToken->getPreviousNonComment();
314 // The first line break on any ParenLevel causes an extra penalty in order
315 // prefer similar line breaks.
316 if (!State.Stack.back().ContainsLineBreak)
317 Penalty += 15;
318 State.Stack.back().ContainsLineBreak = true;
Daniel Jasperd4a03db2013-08-22 15:00:41 +0000319
Alexander Kornienkoe5321c42013-10-01 14:41:18 +0000320 Penalty += State.NextToken->SplitPenalty;
Daniel Jasper6b2afe42013-08-16 11:20:30 +0000321
Alexander Kornienkoe5321c42013-10-01 14:41:18 +0000322 // Breaking before the first "<<" is generally not desirable if the LHS is
323 // short.
324 if (Current.is(tok::lessless) && State.Stack.back().FirstLessLess == 0 &&
325 State.Column <= Style.ColumnLimit / 2)
326 Penalty += Style.PenaltyBreakFirstLessLess;
327
328 if (Current.is(tok::l_brace) && Current.BlockKind == BK_Block) {
329 State.Column = State.FirstIndent;
330 } else if (Current.is(tok::r_brace)) {
331 if (Current.MatchingParen &&
332 (Current.MatchingParen->BlockKind == BK_BracedInit ||
333 !Current.MatchingParen->Children.empty()))
334 State.Column = State.Stack[State.Stack.size() - 2].LastSpace;
335 else
Daniel Jasper57981202013-09-13 09:20:45 +0000336 State.Column = State.FirstIndent;
Alexander Kornienkoe5321c42013-10-01 14:41:18 +0000337 } else if (Current.is(tok::string_literal) &&
338 State.StartOfStringLiteral != 0) {
339 State.Column = State.StartOfStringLiteral;
340 State.Stack.back().BreakBeforeParameter = true;
341 } else if (Current.is(tok::lessless) &&
342 State.Stack.back().FirstLessLess != 0) {
343 State.Column = State.Stack.back().FirstLessLess;
344 } else if (Current.isMemberAccess()) {
345 if (State.Stack.back().CallContinuation == 0) {
Daniel Jasper6b2afe42013-08-16 11:20:30 +0000346 State.Column = ContinuationIndent;
Alexander Kornienkoe5321c42013-10-01 14:41:18 +0000347 State.Stack.back().CallContinuation = State.Column;
348 } else {
349 State.Column = State.Stack.back().CallContinuation;
350 }
351 } else if (Current.Type == TT_ConditionalExpr) {
352 State.Column = State.Stack.back().QuestionColumn;
353 } else if (Previous.is(tok::comma) && State.Stack.back().VariablePos != 0) {
354 State.Column = State.Stack.back().VariablePos;
355 } else if ((PreviousNonComment &&
356 PreviousNonComment->ClosesTemplateDeclaration) ||
357 ((Current.Type == TT_StartOfName ||
358 Current.is(tok::kw_operator)) &&
359 State.ParenLevel == 0 &&
360 (!Style.IndentFunctionDeclarationAfterType ||
361 State.Line->StartsDefinition))) {
362 State.Column = State.Stack.back().Indent;
363 } else if (Current.Type == TT_ObjCSelectorName) {
364 if (State.Stack.back().ColonPos > Current.ColumnWidth) {
365 State.Column = State.Stack.back().ColonPos - Current.ColumnWidth;
Daniel Jasper6b2afe42013-08-16 11:20:30 +0000366 } else {
367 State.Column = State.Stack.back().Indent;
Alexander Kornienkoe5321c42013-10-01 14:41:18 +0000368 State.Stack.back().ColonPos = State.Column + Current.ColumnWidth;
Daniel Jasper6b2afe42013-08-16 11:20:30 +0000369 }
Alexander Kornienkoe5321c42013-10-01 14:41:18 +0000370 } else if (Current.is(tok::l_square) && Current.Type != TT_ObjCMethodExpr &&
371 Current.Type != TT_LambdaLSquare) {
372 if (State.Stack.back().StartOfArraySubscripts != 0)
373 State.Column = State.Stack.back().StartOfArraySubscripts;
374 else
375 State.Column = ContinuationIndent;
376 } else if (Current.Type == TT_StartOfName ||
377 Previous.isOneOf(tok::coloncolon, tok::equal) ||
378 Previous.Type == TT_ObjCMethodExpr) {
379 State.Column = ContinuationIndent;
380 } else if (Current.Type == TT_CtorInitializerColon) {
381 State.Column = State.FirstIndent + Style.ConstructorInitializerIndentWidth;
382 } else if (Current.Type == TT_CtorInitializerComma) {
383 State.Column = State.Stack.back().Indent;
Daniel Jasper6b2afe42013-08-16 11:20:30 +0000384 } else {
Alexander Kornienkoe5321c42013-10-01 14:41:18 +0000385 State.Column = State.Stack.back().Indent;
386 // Ensure that we fall back to indenting 4 spaces instead of just
387 // flushing continuations left.
388 if (State.Column == State.FirstIndent)
389 State.Column += 4;
Daniel Jasper6b2afe42013-08-16 11:20:30 +0000390 }
391
Alexander Kornienkoe5321c42013-10-01 14:41:18 +0000392 if (Current.is(tok::question))
393 State.Stack.back().BreakBeforeParameter = true;
394 if ((Previous.isOneOf(tok::comma, tok::semi) &&
395 !State.Stack.back().AvoidBinPacking) ||
396 Previous.Type == TT_BinaryOperator)
397 State.Stack.back().BreakBeforeParameter = false;
398 if (Previous.Type == TT_TemplateCloser && State.ParenLevel == 0)
399 State.Stack.back().BreakBeforeParameter = false;
400
401 if (!DryRun) {
402 unsigned Newlines = 1;
403 if (Current.is(tok::comment))
404 Newlines = std::max(Newlines, std::min(Current.NewlinesBefore,
405 Style.MaxEmptyLinesToKeep + 1));
406 Whitespaces.replaceWhitespace(Current, Newlines, State.Line->Level,
407 State.Column, State.Column,
408 State.Line->InPPDirective);
409 }
410
411 if (!Current.isTrailingComment())
412 State.Stack.back().LastSpace = State.Column;
413 if (Current.isMemberAccess())
414 State.Stack.back().LastSpace += Current.ColumnWidth;
415 State.StartOfLineLevel = State.ParenLevel;
416 State.LowestLevelOnLine = State.ParenLevel;
417
418 // Any break on this level means that the parent level has been broken
419 // and we need to avoid bin packing there.
420 for (unsigned i = 0, e = State.Stack.size() - 1; i != e; ++i) {
421 State.Stack[i].BreakBeforeParameter = true;
422 }
423 const FormatToken *TokenBefore = Current.getPreviousNonComment();
424 if (TokenBefore && !TokenBefore->isOneOf(tok::comma, tok::semi) &&
425 TokenBefore->Type != TT_TemplateCloser &&
426 TokenBefore->Type != TT_BinaryOperator && !TokenBefore->opensScope())
427 State.Stack.back().BreakBeforeParameter = true;
428
429 // If we break after {, we should also break before the corresponding }.
430 if (Previous.is(tok::l_brace))
431 State.Stack.back().BreakBeforeClosingBrace = true;
432
433 if (State.Stack.back().AvoidBinPacking) {
434 // If we are breaking after '(', '{', '<', this is not bin packing
435 // unless AllowAllParametersOfDeclarationOnNextLine is false.
436 if (!(Previous.isOneOf(tok::l_paren, tok::l_brace) ||
437 Previous.Type == TT_BinaryOperator) ||
438 (!Style.AllowAllParametersOfDeclarationOnNextLine &&
439 State.Line->MustBeDeclaration))
440 State.Stack.back().BreakBeforeParameter = true;
441 }
442
443 return Penalty;
Daniel Jasper6b2afe42013-08-16 11:20:30 +0000444}
445
446unsigned ContinuationIndenter::moveStateToNextToken(LineState &State,
447 bool DryRun, bool Newline) {
448 const FormatToken &Current = *State.NextToken;
449 assert(State.Stack.size());
450
451 if (Current.Type == TT_InheritanceColon)
452 State.Stack.back().AvoidBinPacking = true;
453 if (Current.is(tok::lessless) && State.Stack.back().FirstLessLess == 0)
454 State.Stack.back().FirstLessLess = State.Column;
Daniel Jasper567dcf92013-09-05 09:29:45 +0000455 if (Current.is(tok::l_square) && Current.Type != TT_LambdaLSquare &&
Daniel Jasper6b2afe42013-08-16 11:20:30 +0000456 State.Stack.back().StartOfArraySubscripts == 0)
457 State.Stack.back().StartOfArraySubscripts = State.Column;
458 if (Current.is(tok::question))
459 State.Stack.back().QuestionColumn = State.Column;
460 if (!Current.opensScope() && !Current.closesScope())
461 State.LowestLevelOnLine =
462 std::min(State.LowestLevelOnLine, State.ParenLevel);
Daniel Jasperd3fef0f2013-08-27 14:24:43 +0000463 if (Current.isMemberAccess())
Daniel Jasper6b2afe42013-08-16 11:20:30 +0000464 State.Stack.back().StartOfFunctionCall =
Alexander Kornienko83a7dcd2013-09-10 09:38:25 +0000465 Current.LastInChainOfCalls ? 0 : State.Column + Current.ColumnWidth;
Daniel Jasper6b2afe42013-08-16 11:20:30 +0000466 if (Current.Type == TT_CtorInitializerColon) {
467 // Indent 2 from the column, so:
468 // SomeClass::SomeClass()
469 // : First(...), ...
470 // Next(...)
471 // ^ line up here.
472 State.Stack.back().Indent =
473 State.Column + (Style.BreakConstructorInitializersBeforeComma ? 0 : 2);
474 if (Style.ConstructorInitializerAllOnOneLineOrOnePerLine)
475 State.Stack.back().AvoidBinPacking = true;
476 State.Stack.back().BreakBeforeParameter = false;
477 }
478
Daniel Jasper6b2afe42013-08-16 11:20:30 +0000479 // In ObjC method declaration we align on the ":" of parameters, but we need
480 // to ensure that we indent parameters on subsequent lines by at least 4.
481 if (Current.Type == TT_ObjCMethodSpecifier)
482 State.Stack.back().Indent += 4;
483
484 // Insert scopes created by fake parenthesis.
485 const FormatToken *Previous = Current.getPreviousNonComment();
486 // Don't add extra indentation for the first fake parenthesis after
487 // 'return', assignements or opening <({[. The indentation for these cases
488 // is special cased.
489 bool SkipFirstExtraIndent =
Daniel Jasperf78bf4a2013-09-30 08:29:03 +0000490 (Previous && (Previous->opensScope() || Previous->is(tok::kw_return) ||
Daniel Jasper6b2afe42013-08-16 11:20:30 +0000491 Previous->getPrecedence() == prec::Assignment));
492 for (SmallVectorImpl<prec::Level>::const_reverse_iterator
493 I = Current.FakeLParens.rbegin(),
494 E = Current.FakeLParens.rend();
495 I != E; ++I) {
496 ParenState NewParenState = State.Stack.back();
497 NewParenState.ContainsLineBreak = false;
Daniel Jasperf78bf4a2013-09-30 08:29:03 +0000498
499 // Indent from 'LastSpace' unless this the fake parentheses encapsulating a
500 // builder type call after 'return'. If such a call is line-wrapped, we
501 // commonly just want to indent from the start of the line.
502 if (!Previous || Previous->isNot(tok::kw_return) || *I > 0)
503 NewParenState.Indent =
504 std::max(std::max(State.Column, NewParenState.Indent),
505 State.Stack.back().LastSpace);
506
Daniel Jasper567dcf92013-09-05 09:29:45 +0000507 // Do not indent relative to the fake parentheses inserted for "." or "->".
508 // This is a special case to make the following to statements consistent:
509 // OuterFunction(InnerFunctionCall( // break
510 // ParameterToInnerFunction));
511 // OuterFunction(SomeObject.InnerFunctionCall( // break
512 // ParameterToInnerFunction));
513 if (*I > prec::Unknown)
514 NewParenState.LastSpace = std::max(NewParenState.LastSpace, State.Column);
Daniel Jasper6b2afe42013-08-16 11:20:30 +0000515
516 // Always indent conditional expressions. Never indent expression where
517 // the 'operator' is ',', ';' or an assignment (i.e. *I <=
518 // prec::Assignment) as those have different indentation rules. Indent
519 // other expression, unless the indentation needs to be skipped.
520 if (*I == prec::Conditional ||
521 (!SkipFirstExtraIndent && *I > prec::Assignment &&
522 !Style.BreakBeforeBinaryOperators))
523 NewParenState.Indent += 4;
524 if (Previous && !Previous->opensScope())
525 NewParenState.BreakBeforeParameter = false;
526 State.Stack.push_back(NewParenState);
527 SkipFirstExtraIndent = false;
528 }
529
530 // If we encounter an opening (, [, { or <, we add a level to our stacks to
531 // prepare for the following tokens.
532 if (Current.opensScope()) {
533 unsigned NewIndent;
Daniel Jasper6b2afe42013-08-16 11:20:30 +0000534 bool AvoidBinPacking;
535 if (Current.is(tok::l_brace)) {
Daniel Jasper567dcf92013-09-05 09:29:45 +0000536 if (Current.MatchingParen && Current.BlockKind == BK_Block) {
Daniel Jasper1a925bc2013-09-05 10:48:50 +0000537 // If this is an l_brace starting a nested block, we pretend (wrt. to
538 // indentation) that we already consumed the corresponding r_brace.
539 // Thus, we remove all ParenStates caused bake fake parentheses that end
540 // at the r_brace. The net effect of this is that we don't indent
541 // relative to the l_brace, if the nested block is the last parameter of
542 // a function. For example, this formats:
543 //
544 // SomeFunction(a, [] {
545 // f(); // break
546 // });
547 //
548 // instead of:
549 // SomeFunction(a, [] {
550 // f(); // break
551 // });
Daniel Jasper567dcf92013-09-05 09:29:45 +0000552 for (unsigned i = 0; i != Current.MatchingParen->FakeRParens; ++i)
553 State.Stack.pop_back();
Daniel Jasper57981202013-09-13 09:20:45 +0000554 NewIndent = State.Stack.back().LastSpace + Style.IndentWidth;
Daniel Jasper567dcf92013-09-05 09:29:45 +0000555 } else {
556 NewIndent = State.Stack.back().LastSpace +
557 (Style.Cpp11BracedListStyle ? 4 : Style.IndentWidth);
558 }
Daniel Jasper6b2afe42013-08-16 11:20:30 +0000559 const FormatToken *NextNoComment = Current.getNextNonComment();
Daniel Jasper57981202013-09-13 09:20:45 +0000560 AvoidBinPacking = Current.BlockKind == BK_Block ||
561 (NextNoComment &&
562 NextNoComment->Type == TT_DesignatedInitializerPeriod);
Daniel Jasper6b2afe42013-08-16 11:20:30 +0000563 } else {
Daniel Jasper567dcf92013-09-05 09:29:45 +0000564 NewIndent = 4 + std::max(State.Stack.back().LastSpace,
565 State.Stack.back().StartOfFunctionCall);
Daniel Jasper6b2afe42013-08-16 11:20:30 +0000566 AvoidBinPacking = !Style.BinPackParameters ||
567 (Style.ExperimentalAutoDetectBinPacking &&
568 (Current.PackingKind == PPK_OnePerLine ||
569 (!BinPackInconclusiveFunctions &&
570 Current.PackingKind == PPK_Inconclusive)));
571 }
572
Daniel Jasper567dcf92013-09-05 09:29:45 +0000573 State.Stack.push_back(ParenState(NewIndent, State.Stack.back().LastSpace,
574 AvoidBinPacking,
Daniel Jasper6b2afe42013-08-16 11:20:30 +0000575 State.Stack.back().NoLineBreak));
Daniel Jasper57981202013-09-13 09:20:45 +0000576 State.Stack.back().BreakBeforeParameter = Current.BlockKind == BK_Block;
Daniel Jasper6b2afe42013-08-16 11:20:30 +0000577 ++State.ParenLevel;
578 }
579
580 // If this '[' opens an ObjC call, determine whether all parameters fit into
581 // one line and put one per line if they don't.
582 if (Current.is(tok::l_square) && Current.Type == TT_ObjCMethodExpr &&
583 Current.MatchingParen != NULL) {
Daniel Jasper567dcf92013-09-05 09:29:45 +0000584 if (getLengthToMatchingParen(Current) + State.Column >
585 getColumnLimit(State))
Daniel Jasper6b2afe42013-08-16 11:20:30 +0000586 State.Stack.back().BreakBeforeParameter = true;
587 }
588
589 // If we encounter a closing ), ], } or >, we can remove a level from our
590 // stacks.
Daniel Jasper7143a212013-08-28 09:17:37 +0000591 if (State.Stack.size() > 1 &&
592 (Current.isOneOf(tok::r_paren, tok::r_square) ||
Daniel Jasper567dcf92013-09-05 09:29:45 +0000593 (Current.is(tok::r_brace) && State.NextToken != State.Line->First) ||
Daniel Jasper7143a212013-08-28 09:17:37 +0000594 State.NextToken->Type == TT_TemplateCloser)) {
Daniel Jasper6b2afe42013-08-16 11:20:30 +0000595 State.Stack.pop_back();
596 --State.ParenLevel;
597 }
598 if (Current.is(tok::r_square)) {
599 // If this ends the array subscript expr, reset the corresponding value.
600 const FormatToken *NextNonComment = Current.getNextNonComment();
601 if (NextNonComment && NextNonComment->isNot(tok::l_square))
602 State.Stack.back().StartOfArraySubscripts = 0;
603 }
604
605 // Remove scopes created by fake parenthesis.
Daniel Jasper567dcf92013-09-05 09:29:45 +0000606 if (Current.isNot(tok::r_brace) ||
607 (Current.MatchingParen && Current.MatchingParen->BlockKind != BK_Block)) {
Daniel Jasper1a925bc2013-09-05 10:48:50 +0000608 // Don't remove FakeRParens attached to r_braces that surround nested blocks
609 // as they will have been removed early (see above).
Daniel Jasper567dcf92013-09-05 09:29:45 +0000610 for (unsigned i = 0, e = Current.FakeRParens; i != e; ++i) {
611 unsigned VariablePos = State.Stack.back().VariablePos;
612 State.Stack.pop_back();
613 State.Stack.back().VariablePos = VariablePos;
614 }
Daniel Jasper6b2afe42013-08-16 11:20:30 +0000615 }
616
617 if (Current.is(tok::string_literal) && State.StartOfStringLiteral == 0) {
618 State.StartOfStringLiteral = State.Column;
619 } else if (!Current.isOneOf(tok::comment, tok::identifier, tok::hash,
620 tok::string_literal)) {
621 State.StartOfStringLiteral = 0;
622 }
623
Alexander Kornienko83a7dcd2013-09-10 09:38:25 +0000624 State.Column += Current.ColumnWidth;
Daniel Jasper6b2afe42013-08-16 11:20:30 +0000625 State.NextToken = State.NextToken->Next;
Daniel Jasperd489f8c2013-08-27 11:09:05 +0000626 unsigned Penalty = breakProtrudingToken(Current, State, DryRun);
Daniel Jasper567dcf92013-09-05 09:29:45 +0000627 if (State.Column > getColumnLimit(State)) {
628 unsigned ExcessCharacters = State.Column - getColumnLimit(State);
629 Penalty += Style.PenaltyExcessCharacter * ExcessCharacters;
630 }
Daniel Jasper6b2afe42013-08-16 11:20:30 +0000631
Daniel Jasperd4a03db2013-08-22 15:00:41 +0000632 // If the previous has a special role, let it consume tokens as appropriate.
633 // It is necessary to start at the previous token for the only implemented
634 // role (comma separated list). That way, the decision whether or not to break
635 // after the "{" is already done and both options are tried and evaluated.
636 // FIXME: This is ugly, find a better way.
637 if (Previous && Previous->Role)
638 Penalty += Previous->Role->format(State, this, DryRun);
639
640 return Penalty;
Daniel Jasper6b2afe42013-08-16 11:20:30 +0000641}
642
Alexander Kornienko6f6154c2013-09-10 12:29:48 +0000643unsigned ContinuationIndenter::addMultilineToken(const FormatToken &Current,
644 LineState &State) {
Alexander Kornienkodcc0c5b2013-08-29 17:32:57 +0000645 // Break before further function parameters on all levels.
646 for (unsigned i = 0, e = State.Stack.size(); i != e; ++i)
647 State.Stack[i].BreakBeforeParameter = true;
648
Alexander Kornienko83a7dcd2013-09-10 09:38:25 +0000649 unsigned ColumnsUsed = State.Column;
Alexander Kornienko4b762a92013-09-02 13:58:14 +0000650 // We can only affect layout of the first and the last line, so the penalty
651 // for all other lines is constant, and we ignore it.
Alexander Kornienko0b62cc32013-09-05 14:08:34 +0000652 State.Column = Current.LastLineColumnWidth;
Alexander Kornienko4b762a92013-09-02 13:58:14 +0000653
Daniel Jasper567dcf92013-09-05 09:29:45 +0000654 if (ColumnsUsed > getColumnLimit(State))
655 return Style.PenaltyExcessCharacter * (ColumnsUsed - getColumnLimit(State));
Alexander Kornienkodcc0c5b2013-08-29 17:32:57 +0000656 return 0;
657}
658
Alexander Kornienko2c2f7292013-09-16 20:20:49 +0000659static bool getRawStringLiteralPrefixPostfix(StringRef Text,
660 StringRef &Prefix,
661 StringRef &Postfix) {
662 if (Text.startswith(Prefix = "R\"") || Text.startswith(Prefix = "uR\"") ||
663 Text.startswith(Prefix = "UR\"") || Text.startswith(Prefix = "u8R\"") ||
664 Text.startswith(Prefix = "LR\"")) {
665 size_t ParenPos = Text.find('(');
666 if (ParenPos != StringRef::npos) {
667 StringRef Delimiter =
668 Text.substr(Prefix.size(), ParenPos - Prefix.size());
669 Prefix = Text.substr(0, ParenPos + 1);
670 Postfix = Text.substr(Text.size() - 2 - Delimiter.size());
671 return Postfix.front() == ')' && Postfix.back() == '"' &&
672 Postfix.substr(1).startswith(Delimiter);
673 }
674 }
675 return false;
676}
677
Daniel Jasper6b2afe42013-08-16 11:20:30 +0000678unsigned ContinuationIndenter::breakProtrudingToken(const FormatToken &Current,
679 LineState &State,
680 bool DryRun) {
Alexander Kornienko6f6154c2013-09-10 12:29:48 +0000681 // Don't break multi-line tokens other than block comments. Instead, just
682 // update the state.
683 if (Current.Type != TT_BlockComment && Current.IsMultiline)
684 return addMultilineToken(Current, State);
685
Alexander Kornienko2c2f7292013-09-16 20:20:49 +0000686 if (!Current.isOneOf(tok::string_literal, tok::wide_string_literal,
687 tok::utf8_string_literal, tok::utf16_string_literal,
688 tok::utf32_string_literal, tok::comment))
Daniel Jaspered51c022013-08-23 10:05:49 +0000689 return 0;
690
Daniel Jasper6b2afe42013-08-16 11:20:30 +0000691 llvm::OwningPtr<BreakableToken> Token;
Alexander Kornienko83a7dcd2013-09-10 09:38:25 +0000692 unsigned StartColumn = State.Column - Current.ColumnWidth;
Daniel Jasper6b2afe42013-08-16 11:20:30 +0000693
Alexander Kornienko2c2f7292013-09-16 20:20:49 +0000694 if (Current.isOneOf(tok::string_literal, tok::wide_string_literal,
695 tok::utf8_string_literal, tok::utf16_string_literal,
696 tok::utf32_string_literal) &&
Daniel Jasper6b2afe42013-08-16 11:20:30 +0000697 Current.Type != TT_ImplicitStringLiteral) {
Daniel Jasper6b2afe42013-08-16 11:20:30 +0000698 // Exempts unterminated string literals from line breaking. The user will
699 // likely want to terminate the string before any line breaking is done.
700 if (Current.IsUnterminatedLiteral)
701 return 0;
702
Alexander Kornienko2c2f7292013-09-16 20:20:49 +0000703 StringRef Text = Current.TokenText;
704 StringRef Prefix;
705 StringRef Postfix;
706 // FIXME: Handle whitespace between '_T', '(', '"..."', and ')'.
707 // FIXME: Store Prefix and Suffix (or PrefixLength and SuffixLength to
708 // reduce the overhead) for each FormatToken, which is a string, so that we
709 // don't run multiple checks here on the hot path.
710 if ((Text.endswith(Postfix = "\"") &&
711 (Text.startswith(Prefix = "\"") || Text.startswith(Prefix = "u\"") ||
712 Text.startswith(Prefix = "U\"") || Text.startswith(Prefix = "u8\"") ||
713 Text.startswith(Prefix = "L\""))) ||
714 (Text.startswith(Prefix = "_T(\"") && Text.endswith(Postfix = "\")")) ||
715 getRawStringLiteralPrefixPostfix(Text, Prefix, Postfix)) {
Alexander Kornienko3d9ffcf2013-09-27 16:14:22 +0000716 Token.reset(new BreakableStringLiteral(
717 Current, State.Line->Level, StartColumn, Prefix, Postfix,
718 State.Line->InPPDirective, Encoding, Style));
Alexander Kornienko2c2f7292013-09-16 20:20:49 +0000719 } else {
720 return 0;
721 }
Daniel Jasper6b2afe42013-08-16 11:20:30 +0000722 } else if (Current.Type == TT_BlockComment && Current.isTrailingComment()) {
723 Token.reset(new BreakableBlockComment(
Alexander Kornienko3d9ffcf2013-09-27 16:14:22 +0000724 Current, State.Line->Level, StartColumn, Current.OriginalColumn,
725 !Current.Previous, State.Line->InPPDirective, Encoding, Style));
Daniel Jasper6b2afe42013-08-16 11:20:30 +0000726 } else if (Current.Type == TT_LineComment &&
727 (Current.Previous == NULL ||
728 Current.Previous->Type != TT_ImplicitStringLiteral)) {
Alexander Kornienko3d9ffcf2013-09-27 16:14:22 +0000729 Token.reset(new BreakableLineComment(Current, State.Line->Level,
730 StartColumn, State.Line->InPPDirective,
731 Encoding, Style));
Daniel Jasper6b2afe42013-08-16 11:20:30 +0000732 } else {
733 return 0;
734 }
Daniel Jasper567dcf92013-09-05 09:29:45 +0000735 if (Current.UnbreakableTailLength >= getColumnLimit(State))
Daniel Jasper6b2afe42013-08-16 11:20:30 +0000736 return 0;
737
Daniel Jasper567dcf92013-09-05 09:29:45 +0000738 unsigned RemainingSpace =
739 getColumnLimit(State) - Current.UnbreakableTailLength;
Daniel Jasper6b2afe42013-08-16 11:20:30 +0000740 bool BreakInserted = false;
741 unsigned Penalty = 0;
742 unsigned RemainingTokenColumns = 0;
743 for (unsigned LineIndex = 0, EndIndex = Token->getLineCount();
744 LineIndex != EndIndex; ++LineIndex) {
745 if (!DryRun)
746 Token->replaceWhitespaceBefore(LineIndex, Whitespaces);
747 unsigned TailOffset = 0;
748 RemainingTokenColumns =
749 Token->getLineLengthAfterSplit(LineIndex, TailOffset, StringRef::npos);
750 while (RemainingTokenColumns > RemainingSpace) {
751 BreakableToken::Split Split =
Daniel Jasper567dcf92013-09-05 09:29:45 +0000752 Token->getSplit(LineIndex, TailOffset, getColumnLimit(State));
Daniel Jasper6b2afe42013-08-16 11:20:30 +0000753 if (Split.first == StringRef::npos) {
754 // The last line's penalty is handled in addNextStateToQueue().
755 if (LineIndex < EndIndex - 1)
756 Penalty += Style.PenaltyExcessCharacter *
757 (RemainingTokenColumns - RemainingSpace);
758 break;
759 }
760 assert(Split.first != 0);
761 unsigned NewRemainingTokenColumns = Token->getLineLengthAfterSplit(
762 LineIndex, TailOffset + Split.first + Split.second, StringRef::npos);
763 assert(NewRemainingTokenColumns < RemainingTokenColumns);
764 if (!DryRun)
765 Token->insertBreak(LineIndex, TailOffset, Split, Whitespaces);
Daniel Jasperf5461782013-08-28 10:03:58 +0000766 Penalty += Current.SplitPenalty;
Daniel Jasper6b2afe42013-08-16 11:20:30 +0000767 unsigned ColumnsUsed =
768 Token->getLineLengthAfterSplit(LineIndex, TailOffset, Split.first);
Daniel Jasper567dcf92013-09-05 09:29:45 +0000769 if (ColumnsUsed > getColumnLimit(State)) {
770 Penalty += Style.PenaltyExcessCharacter *
771 (ColumnsUsed - getColumnLimit(State));
Daniel Jasper6b2afe42013-08-16 11:20:30 +0000772 }
773 TailOffset += Split.first + Split.second;
774 RemainingTokenColumns = NewRemainingTokenColumns;
775 BreakInserted = true;
776 }
777 }
778
779 State.Column = RemainingTokenColumns;
780
781 if (BreakInserted) {
782 // If we break the token inside a parameter list, we need to break before
783 // the next parameter on all levels, so that the next parameter is clearly
784 // visible. Line comments already introduce a break.
785 if (Current.Type != TT_LineComment) {
786 for (unsigned i = 0, e = State.Stack.size(); i != e; ++i)
787 State.Stack[i].BreakBeforeParameter = true;
788 }
789
Daniel Jasperf5461782013-08-28 10:03:58 +0000790 Penalty += Current.is(tok::string_literal) ? Style.PenaltyBreakString
791 : Style.PenaltyBreakComment;
792
Daniel Jasper6b2afe42013-08-16 11:20:30 +0000793 State.Stack.back().LastSpace = StartColumn;
794 }
795 return Penalty;
796}
797
Daniel Jasper567dcf92013-09-05 09:29:45 +0000798unsigned ContinuationIndenter::getColumnLimit(const LineState &State) const {
Daniel Jasper6b2afe42013-08-16 11:20:30 +0000799 // In preprocessor directives reserve two chars for trailing " \"
Daniel Jasper567dcf92013-09-05 09:29:45 +0000800 return Style.ColumnLimit - (State.Line->InPPDirective ? 2 : 0);
Daniel Jasper6b2afe42013-08-16 11:20:30 +0000801}
802
Daniel Jasper4df1ff92013-08-23 11:57:34 +0000803bool ContinuationIndenter::NextIsMultilineString(const LineState &State) {
804 const FormatToken &Current = *State.NextToken;
805 if (!Current.is(tok::string_literal))
806 return false;
Alexander Kornienkodcc0c5b2013-08-29 17:32:57 +0000807 // We never consider raw string literals "multiline" for the purpose of
808 // AlwaysBreakBeforeMultilineStrings implementation.
809 if (Current.TokenText.startswith("R\""))
810 return false;
Alexander Kornienko83a7dcd2013-09-10 09:38:25 +0000811 if (Current.IsMultiline)
Alexander Kornienkodcc0c5b2013-08-29 17:32:57 +0000812 return true;
Daniel Jasper4df1ff92013-08-23 11:57:34 +0000813 if (Current.getNextNonComment() &&
814 Current.getNextNonComment()->is(tok::string_literal))
815 return true; // Implicit concatenation.
Alexander Kornienko83a7dcd2013-09-10 09:38:25 +0000816 if (State.Column + Current.ColumnWidth + Current.UnbreakableTailLength >
Daniel Jasper4df1ff92013-08-23 11:57:34 +0000817 Style.ColumnLimit)
818 return true; // String will be split.
Alexander Kornienkodcc0c5b2013-08-29 17:32:57 +0000819 return false;
Daniel Jasper4df1ff92013-08-23 11:57:34 +0000820}
821
Daniel Jasper6b2afe42013-08-16 11:20:30 +0000822} // namespace format
823} // namespace clang