Home | History | Annotate | Download | only in Format

Lines Matching refs:State

79   LineState State;
80 State.FirstIndent = FirstIndent;
81 State.Column = FirstIndent;
82 State.Line = Line;
83 State.NextToken = Line->First;
84 State.Stack.push_back(ParenState(FirstIndent, Line->Level, FirstIndent,
87 State.LineContainsContinuedForLoopSection = false;
88 State.StartOfStringLiteral = 0;
89 State.StartOfLineLevel = 0;
90 State.LowestLevelOnLine = 0;
91 State.IgnoreStackForComparison = false;
94 moveStateToNextToken(State, DryRun, /*Newline=*/false);
95 return State;
98 bool ContinuationIndenter::canBreak(const LineState &State) {
99 const FormatToken &Current = *State.NextToken;
103 !(State.Stack.back().BreakBeforeClosingBrace &&
119 State.LowestLevelOnLine < State.StartOfLineLevel &&
120 State.LowestLevelOnLine < Current.NestingLevel)
122 if (Current.isMemberAccess() && State.Stack.back().ContainsUnwrappedBuilder)
127 if (Previous.is(tok::l_brace) && State.Stack.size() > 1 &&
128 State.Stack[State.Stack.size() - 2].NestedBlockInlined &&
129 State.Stack[State.Stack.size() - 2].HasMultipleNestedBlocks)
134 if (Current.is(TT_FunctionDeclarationName) && State.Column < 6) {
139 return !State.Stack.back().NoLineBreak;
142 bool ContinuationIndenter::mustBreak(const LineState &State) {
143 const FormatToken &Current = *State.NextToken;
147 if (State.Stack.back().BreakBeforeClosingBrace &&
150 if (Previous.is(tok::semi) && State.LineContainsContinuedForLoopSection)
164 State.Stack.back().BreakBeforeParameter && !Current.isTrailingComment() &&
171 getLengthToMatchingParen(Previous) + State.Column - 1 >
172 getColumnLimit(State))
175 (State.Column + State.Line->Last->TotalLength - Current.TotalLength + 2 >
176 getColumnLimit(State) ||
177 State.Stack.back().BreakBeforeParameter) &&
181 if (Current.is(TT_SelectorName) && State.Stack.back().ObjCSelectorNameFound &&
182 State.Stack.back().BreakBeforeParameter)
185 unsigned NewLineColumn = getNewLineColumn(State);
187 State.Column + getLengthToNextOperator(Current) > Style.ColumnLimit &&
188 (State.Column > NewLineColumn ||
189 Current.NestingLevel < State.StartOfLineLevel))
192 if (State.Column <= NewLineColumn)
196 (NewLineColumn == State.FirstIndent + Style.ContinuationIndentWidth ||
200 nextIsMultilineString(State))
224 State.Stack.back().BreakBeforeParameter)
227 State.Stack.back().BreakBeforeParameter) {
233 State.Stack.back().BreakBeforeParameter &&
234 State.Stack.back().FirstLessLess == 0)
253 !Previous.is(tok::kw_template) && State.Stack.back().BreakBeforeParameter)
257 (State.Stack.back().CallContinuation != 0 ||
258 State.Stack.back().BreakBeforeParameter))
261 // The following could be precomputed as they do not depend on the state.
277 unsigned ContinuationIndenter::addTokenToState(LineState &State, bool Newline,
280 const FormatToken &Current = *State.NextToken;
282 assert(!State.Stack.empty());
292 State.Column = EndColumn;
297 State.Column += EndColumn - StartColumn;
299 moveStateToNextToken(State, DryRun, /*Newline=*/false);
305 Penalty = addTokenOnNewLine(State, DryRun);
307 addTokenOnCurrentLine(State, DryRun, ExtraSpaces);
309 return moveStateToNextToken(State, DryRun, Newline) + Penalty;
312 void ContinuationIndenter::addTokenOnCurrentLine(LineState &State, bool DryRun,
314 FormatToken &Current = *State.NextToken;
315 const FormatToken &Previous = *State.NextToken->Previous;
317 (State.Line->First->is(tok::kw_for) || Current.NestingLevel == 0) &&
318 State.Stack.back().VariablePos == 0) {
319 State.Stack.back().VariablePos = State.Column;
322 while (Tok && State.Stack.back().VariablePos >= Tok->ColumnWidth) {
323 State.Stack.back().VariablePos -= Tok->ColumnWidth;
329 State.Stack.back().LastSpace = State.Stack.back().VariablePos;
336 Spaces, State.Column + Spaces);
339 !State.Stack.back().ObjCSelectorNameFound) {
341 std::max(State.FirstIndent + Style.ContinuationIndentWidth,
342 State.Stack.back().Indent);
343 unsigned FirstColonPos = State.Column + Spaces + Current.ColumnWidth;
345 State.Stack.back().AlignColons = false;
347 State.Stack.back().ColonPos = MinIndent + Current.LongestObjCSelectorName;
349 State.Stack.back().ColonPos = FirstColonPos;
357 State.Column > getNewLineColumn(State) &&
370 State.Stack.back().NoLineBreak = true;
375 State.Stack.back().Indent = State.Column + Spaces;
376 if (State
377 State.Stack.back().NoLineBreak = true;
379 State.Column > getNewLineColumn(State))
380 State.Stack.back().ContainsUnwrappedBuilder = true;
383 State.Stack.back().NoLineBreak = true;
393 State.Stack.back().NoLineBreak = true;
396 State.Column += Spaces;
402 State.Stack.back().LastSpace = State.Column;
403 State.Stack.back().NestedBlockIndent = State.Column;
408 State.Stack.back().LastSpace = State.Column;
418 State.Stack.back().LastSpace = State.Column;
420 State.Stack.back().Indent = State.Column;
421 State.Stack.back().LastSpace = State.Column;
433 if (HasTrailingCall && State.Stack.size() > 1 &&
434 State.Stack[State.Stack.size() - 2].CallContinuation == 0)
435 State.Stack.back().LastSpace = State.Column;
439 unsigned ContinuationIndenter::addTokenOnNewLine(LineState &State,
441 FormatToken &Current = *State.NextToken;
442 const FormatToken &Previous = *State.NextToken->Previous;
454 if (!State.Stack.back().ContainsLineBreak)
456 State.Stack.back().ContainsLineBreak = true;
458 Penalty += State.NextToken->SplitPenalty;
464 State.Stack.back().FirstLessLess == 0 &&
465 (State.Column <= Style.ColumnLimit / 3 ||
466 State.Stack.back().BreakBeforeParameter))
469 State.Column = getNewLineColumn(State);
486 State.Stack.back().NestedBlockIndent = State.Column;
489 if (State.Stack.back().CallContinuation == 0)
490 State.Stack.back().CallContinuation = State.Column;
492 if (!State.Stack.back().ObjCSelectorNameFound) {
494 State.Stack.back().AlignColons = false;
496 State.Stack.back().ColonPos =
498 ? std::max(State.Stack.back().Indent,
499 State.FirstIndent + Style.ContinuationIndentWidth)
500 : State.Stack.back().Indent) +
503 } else if (State.Stack.back().AlignColons &&
504 State.Stack.back().ColonPos <= NextNonComment->ColumnWidth) {
505 State.Stack.back().ColonPos = State.Column + NextNonComment->ColumnWidth;
518 if (State.Stack.size() > 1)
519 State.Stack[State.Stack.size() - 2].LastSpace =
520 std::max(State.Stack.back().LastSpace, State.Stack.back().Indent) +
525 !State.Stack.back().AvoidBinPacking) ||
527 State.Stack.back().BreakBeforeParameter = false;
530 State.Stack.back().BreakBeforeParameter = false;
533 State.Stack.back().BreakBeforeParameter = true;
535 State.Stack.back().BreakBeforeParameter = false;
541 State.Stack.back().IndentLevel, State.Column,
542 State.Column, State.Line->InPPDirective);
546 State.Stack.back().LastSpace = State.Column;
551 State.Stack.back().LastSpace += 3; // 3 -> width of "<< ".
553 State.StartOfLineLevel = Current.NestingLevel;
554 State.LowestLevelOnLine = Current.NestingLevel;
560 Current.is(tok::r_brace) && State.Stack.size() > 1 &&
561 State.Stack[State.Stack.size() - 2].NestedBlockInlined;
563 for (unsigned i = 0, e = State.Stack.size() - 1; i != e; ++i)
564 State.Stack[i].BreakBeforeParameter = true;
574 State.Stack.back().BreakBeforeParameter = true;
580 State.Stack.back().BreakBeforeClosingBrace = true;
582 if (State.Stack.back().AvoidBinPacking) {
588 State.Line->MustBeDeclaration) ||
590 State.Stack.back().BreakBeforeParameter = true;
596 unsigned ContinuationIndenter::getNewLineColumn(const LineState &State) {
597 if (!State.NextToken || !State.NextToken->Previous)
599 FormatToken &Current = *State.NextToken;
603 std::max(State.Stack.back().LastSpace, State.Stack.back().Indent) +
613 return std::max(State.Stack.back().LastSpace,
614 State.Stack.back().Indent + Style.ContinuationIndentWidth);
617 return Current.NestingLevel == 0 ? State.FirstIndent
618 : State.Stack.back().Indent;
619 if (Current.isOneOf(tok::r_brace, tok::r_square) && State.Stack.size() > 1) {
621 return State.Stack[State.Stack.size() - 2].NestedBlockIndent;
624 return State.Stack[State.Stack.size() - 2].LastSpace;
625 return State.FirstIndent;
629 return State.Stack.back().Indent;
630 if (NextNonComment->isStringLiteral() && State.StartOfStringLiteral != 0)
631 return State.StartOfStringLiteral;
633 State.StartOfStringLiteral != 0)
634 return State.StartOfStringLiteral - 1;
636 State.Stack.back().FirstLessLess != 0)
637 return State.Stack.back().FirstLessLess;
639 if (State.Stack.back().CallContinuation == 0)
641 return State.Stack.back().CallContinuation;
643 if (State.Stack.back().QuestionColumn != 0 &&
647 return State.Stack.back().QuestionColumn;
648 if (Previous.is(tok::comma) && State.Stack.back().VariablePos != 0)
649 return State.Stack.back().VariablePos;
657 return std::max(State.Stack.back().LastSpace, State.Stack.back().Indent);
659 if (!State.Stack.back().ObjCSelectorNameFound) {
661 return State.Stack.back().Indent;
663 ? std::max(State.Stack.back().Indent,
664 State.FirstIndent + Style.ContinuationIndentWidth)
665 : State.Stack.back().Indent) +
669 if (!State.Stack.back().AlignColons)
670 return State.Stack.back().Indent;
671 if (State.Stack.back().ColonPos > NextNonComment->ColumnWidth)
672 return State.Stack.back().ColonPos - NextNonComment->ColumnWidth;
673 return State.Stack.back().Indent;
676 if (State.Stack.back().StartOfArraySubscripts != 0)
677 return State.Stack.back().StartOfArraySubscripts;
685 return State.Stack.back().Indent;
694 return State.FirstIndent + Style.ConstructorInitializerIndentWidth;
696 return State.Stack.back().Indent;
700 if (State.Stack.back().Indent == State.FirstIndent && PreviousNonComment &&
704 return State.Stack.back().Indent + Style.ContinuationIndentWidth;
705 return State.Stack.back().Indent;
708 unsigned ContinuationIndenter::moveStateToNextToken(LineState &State,
710 assert(State.Stack.size());
711 const FormatToken &Current = *State.NextToken;
714 State.Stack.back().AvoidBinPacking = true;
716 if (State.Stack.back().FirstLessLess == 0)
717 State.Stack.back().FirstLessLess = State.Column;
719 State.Stack.back().LastOperatorWrapped = Newline;
723 State.Stack.back().LastOperatorWrapped = Newline;
725 State.Stack.back().StartOfArraySubscripts == 0)
726 State.Stack.back().StartOfArraySubscripts = State.Column;
728 State.Stack.back().QuestionColumn = State.Column;
734 State.Stack.back().QuestionColumn = State.Column;
737 State.LowestLevelOnLine =
738 std::min(State.LowestLevelOnLine, Current.NestingLevel);
740 State.Stack.back().StartOfFunctionCall =
741 !Current.NextOperator ? 0 : State.Column;
743 State.Stack.back().ObjCSelectorNameFound = true;
745 State.Stack.back().Indent =
746 State.FirstIndent + Style.ContinuationIndentWidth;
755 State.Stack.back().Indent =
756 State.Column + (Style.BreakConstructorInitializersBeforeComma ? 0 : 2);
757 State.Stack.back().NestedBlockIndent = State.Stack.back().Indent;
759 State.Stack.back().AvoidBinPacking = true;
760 State.Stack.back().BreakBeforeParameter = false;
763 State.Stack.back().NestedBlockIndent =
764 State.Column + Current.ColumnWidth + 1;
777 !Previous->is(TT_DictLiteral) && State.Stack.size() > 1) {
778 if (State.Stack[State.Stack.size() - 2].NestedBlockInlined && Newline)
779 for (unsigned i = 0, e = State.Stack.size() - 1; i != e; ++i)
780 State.Stack[i].NoLineBreak = true;
781 State.Stack[State.Stack.size() - 2].NestedBlockInlined = false;
786 State.Stack.back().NestedBlockInlined =
791 moveStatePastFakeLParens(State, Newline);
792 moveStatePastScopeOpener(State, Newline);
793 moveStatePastScopeCloser(State);
794 moveStatePastFakeRParens(State);
796 if (Current.isStringLiteral() && State.StartOfStringLiteral == 0)
797 State.StartOfStringLiteral = State.Column;
798 if (Current.is(TT_ObjCStringLiteral) && State.StartOfStringLiteral == 0)
799 State.StartOfStringLiteral = State.Column + 1;
802 State.StartOfStringLiteral = 0;
804 State.Column += Current.ColumnWidth;
805 State.NextToken = State.NextToken->Next;
806 unsigned Penalty = breakProtrudingToken(Current, State, DryRun);
807 if (State.Column > getColumnLimit(State)) {
808 unsigned ExcessCharacters = State.Column - getColumnLimit(State);
813 Current.Role->formatFromToken(State, this, DryRun);
820 Penalty += Previous->Role->formatAfterToken(State, this, DryRun);
825 void ContinuationIndenter::moveStatePastFakeLParens(LineState &State,
827 const FormatToken &Current = *State.NextToken;
843 ParenState NewParenState = State.Stack.back();
856 std::max(std::max(State.Column, NewParenState.Indent),
857 State.Stack.back().LastSpace);
873 (!State.Stack.back().LastOperatorWrapped && BreakBeforeOperator))
884 NewParenState.LastSpace = std::max(NewParenState.LastSpace, State.Column);
887 NewParenState.StartOfFunctionCall = State.Column;
899 State.Stack.push_back(NewParenState);
904 void ContinuationIndenter::moveStatePastFakeRParens(LineState &State) {
905 for (unsigned i = 0, e = State.NextToken->FakeRParens; i != e; ++i) {
906 unsigned VariablePos = State.Stack.back().VariablePos;
907 if (State.Stack.size() == 1) {
911 State.Stack.pop_back();
912 State.Stack.back().VariablePos = VariablePos;
916 void ContinuationIndenter::moveStatePastScopeOpener(LineState &State,
918 const FormatToken &Current = *State.NextToken;
923 moveStateToNewBlock(State);
928 unsigned NewIndentLevel = State.Stack.back().IndentLevel;
929 unsigned LastSpace = State.Stack.back().LastSpace;
932 unsigned NestedBlockIndent = std::max(State.Stack.back().StartOfFunctionCall,
933 State.Stack.back().NestedBlockIndent);
936 NewIndent = State.Stack.back().NestedBlockIndent + Style.IndentWidth;
937 NewIndent = std::min(State.Column + 2, NewIndent);
940 NewIndent = State.Stack.back().LastSpace + Style.ContinuationIndentWidth;
952 NestedBlockIndent = std::max(NestedBlockIndent, State.Column + 1);
955 std::max(State.Stack.back().LastSpace,
956 State.Stack.back().StartOfFunctionCall);
965 NewIndent = std::max(NewIndent, State.Stack.back().Indent);
966 LastSpace = std::max(LastSpace, State.Stack.back().Indent);
970 (State.Line->MustBeDeclaration && !Style.BinPackParameters) ||
971 (!State.Line->MustBeDeclaration && !Style.BinPackArguments) ||
980 if (getLengthToMatchingParen(Current) + State.Column >
981 getColumnLimit(State))
1003 (State.Stack.back().NoLineBreak ||
1005 State.Stack.back().ContainsUnwrappedBuilder));
1006 State.Stack.push_back(ParenState(NewIndent, NewIndentLevel, LastSpace,
1008 State.Stack.back().NestedBlockIndent = NestedBlockIndent;
1009 State.Stack.back().BreakBeforeParameter = BreakBeforeParameter;
1010 State.Stack.back().HasMultipleNestedBlocks = Current.BlockParameterCount > 1;
1013 void ContinuationIndenter::moveStatePastScopeCloser(LineState &State) {
1014 const FormatToken &Current = *State.NextToken;
1020 if (State.Stack.size() > 1 &&
1022 (Current.is(tok::r_brace) && State.NextToken != State.Line->First) ||
1023 State.NextToken->is(TT_TemplateCloser)))
1024 State.Stack.pop_back();
1030 State.Stack.back().StartOfArraySubscripts = 0;
1034 void ContinuationIndenter::moveStateToNewBlock(LineState &State) {
1035 unsigned NestedBlockIndent = State.Stack.back().NestedBlockIndent;
1038 NestedBlockIndent + (State.NextToken->is(TT_ObjCBlockLBrace)
1041 State.Stack.push_back(ParenState(
1042 NewIndent, /*NewIndentLevel=*/State.Stack.back().IndentLevel + 1,
1043 State.Stack.back().LastSpace, /*AvoidBinPacking=*/true,
1045 State.Stack.back().NestedBlockIndent = NestedBlockIndent;
1046 State.Stack.back().BreakBeforeParameter = true;
1050 LineState &State) {
1055 for (unsigned i = 0, e = State.Stack.size(); i != e; ++i)
1056 State.Stack[i].BreakBeforeParameter = true;
1058 unsigned ColumnsUsed = State.Column;
1061 State.Column = Current.LastLineColumnWidth;
1063 if (ColumnsUsed > getColumnLimit(State))
1064 return Style.PenaltyExcessCharacter * (ColumnsUsed - getColumnLimit(State));
1069 LineState &State,
1072 // update the state.
1074 return addMultilineToken(Current, State);
1078 State.Line->Type == LT_ImportStatement)
1085 unsigned StartColumn = State.Column - Current.ColumnWidth;
1086 unsigned ColumnLimit = getColumnLimit(State);
1101 if (State.Line->Type == LT_PreprocessorDirective)
1128 Current, State.Line->Level, StartColumn, Prefix, Postfix,
1129 State.Line->InPPDirective, Encoding, Style));
1136 return addMultilineToken(Current, State);
1138 Current, State.Line->Level, StartColumn, Current.OriginalColumn,
1139 !Current.Previous, State.Line->InPPDirective, Encoding, Style));
1146 Token.reset(new BreakableLineComment(Current, State.Line->Level,
1211 State.Column = RemainingTokenColumns;
1218 for (unsigned i = 0, e = State.Stack.size(); i != e; ++i)
1219 State.Stack[i].BreakBeforeParameter = true;
1225 State.Stack.back().LastSpace = StartColumn;
1230 unsigned ContinuationIndenter::getColumnLimit(const LineState &State) const {
1232 return Style.ColumnLimit - (State.Line->InPPDirective ? 2 : 0);
1235 bool ContinuationIndenter::nextIsMultilineString(const LineState &State) {
1236 const FormatToken &Current = *State.NextToken;
1250 State.Column + Current.ColumnWidth + Current.UnbreakableTailLength >