comparison clang/lib/Format/UnwrappedLineFormatter.cpp @ 173:0572611fdcc8 llvm10 llvm12

reorgnization done
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Mon, 25 May 2020 11:55:54 +0900
parents 1d019706d866
children 2e18cbf3894f
comparison
equal deleted inserted replaced
172:9fbae9c8bf63 173:0572611fdcc8
62 IndentForLevel.resize(Line.Level + 1); 62 IndentForLevel.resize(Line.Level + 1);
63 Indent = getIndent(IndentForLevel, Line.Level); 63 Indent = getIndent(IndentForLevel, Line.Level);
64 } 64 }
65 if (static_cast<int>(Indent) + Offset >= 0) 65 if (static_cast<int>(Indent) + Offset >= 0)
66 Indent += Offset; 66 Indent += Offset;
67 if (Line.First->is(TT_CSharpGenericTypeConstraint))
68 Indent = Line.Level * Style.IndentWidth + Style.ContinuationIndentWidth;
67 } 69 }
68 70
69 /// Update the indent state given that \p Line indent should be 71 /// Update the indent state given that \p Line indent should be
70 /// skipped. 72 /// skipped.
71 void skipLine(const AnnotatedLine &Line) { 73 void skipLine(const AnnotatedLine &Line) {
402 if (TheLine->First->is(tok::kw_if)) { 404 if (TheLine->First->is(tok::kw_if)) {
403 return Style.AllowShortIfStatementsOnASingleLine 405 return Style.AllowShortIfStatementsOnASingleLine
404 ? tryMergeSimpleControlStatement(I, E, Limit) 406 ? tryMergeSimpleControlStatement(I, E, Limit)
405 : 0; 407 : 0;
406 } 408 }
407 if (TheLine->First->isOneOf(tok::kw_for, tok::kw_while)) { 409 if (TheLine->First->isOneOf(tok::kw_for, tok::kw_while, tok::kw_do)) {
408 return Style.AllowShortLoopsOnASingleLine 410 return Style.AllowShortLoopsOnASingleLine
409 ? tryMergeSimpleControlStatement(I, E, Limit) 411 ? tryMergeSimpleControlStatement(I, E, Limit)
410 : 0; 412 : 0;
411 } 413 }
412 if (TheLine->First->isOneOf(tok::kw_case, tok::kw_default)) { 414 if (TheLine->First->isOneOf(tok::kw_case, tok::kw_default)) {
447 if (I[1]->InPPDirective != (*I)->InPPDirective || 449 if (I[1]->InPPDirective != (*I)->InPPDirective ||
448 (I[1]->InPPDirective && I[1]->First->HasUnescapedNewline)) 450 (I[1]->InPPDirective && I[1]->First->HasUnescapedNewline))
449 return 0; 451 return 0;
450 Limit = limitConsideringMacros(I + 1, E, Limit); 452 Limit = limitConsideringMacros(I + 1, E, Limit);
451 AnnotatedLine &Line = **I; 453 AnnotatedLine &Line = **I;
452 if (Line.Last->isNot(tok::r_paren)) 454 if (!Line.First->is(tok::kw_do) && Line.Last->isNot(tok::r_paren))
455 return 0;
456 // Only merge do while if do is the only statement on the line.
457 if (Line.First->is(tok::kw_do) && !Line.Last->is(tok::kw_do))
453 return 0; 458 return 0;
454 if (1 + I[1]->Last->TotalLength > Limit) 459 if (1 + I[1]->Last->TotalLength > Limit)
455 return 0; 460 return 0;
456 if (I[1]->First->isOneOf(tok::semi, tok::kw_if, tok::kw_for, tok::kw_while, 461 if (I[1]->First->isOneOf(tok::semi, tok::kw_if, tok::kw_for, tok::kw_while,
457 TT_LineComment)) 462 TT_LineComment))
816 return false; 821 return false;
817 822
818 if (!DryRun) { 823 if (!DryRun) {
819 Whitespaces->replaceWhitespace( 824 Whitespaces->replaceWhitespace(
820 *Child->First, /*Newlines=*/0, /*Spaces=*/1, 825 *Child->First, /*Newlines=*/0, /*Spaces=*/1,
821 /*StartOfTokenColumn=*/State.Column, State.Line->InPPDirective); 826 /*StartOfTokenColumn=*/State.Column, /*IsAligned=*/false,
827 State.Line->InPPDirective);
822 } 828 }
823 Penalty += 829 Penalty +=
824 formatLine(*Child, State.Column + 1, /*FirstStartColumn=*/0, DryRun); 830 formatLine(*Child, State.Column + 1, /*FirstStartColumn=*/0, DryRun);
825 831
826 State.Column += 1 + Child->Last->TotalLength; 832 State.Column += 1 + Child->Last->TotalLength;
1248 (Line.Type == LT_PreprocessorDirective || 1254 (Line.Type == LT_PreprocessorDirective ||
1249 Line.Type == LT_ImportStatement)) 1255 Line.Type == LT_ImportStatement))
1250 Indent = 0; 1256 Indent = 0;
1251 1257
1252 Whitespaces->replaceWhitespace(RootToken, Newlines, Indent, Indent, 1258 Whitespaces->replaceWhitespace(RootToken, Newlines, Indent, Indent,
1259 /*IsAligned=*/false,
1253 Line.InPPDirective && 1260 Line.InPPDirective &&
1254 !RootToken.HasUnescapedNewline); 1261 !RootToken.HasUnescapedNewline);
1255 } 1262 }
1256 1263
1257 unsigned 1264 unsigned