Lines Matching defs:Line

43 static bool startsWithInitStatement(const AnnotatedLine &Line) {
44 return Line.startsWith(tok::kw_for) || Line.startsWith(tok::kw_if) ||
45 Line.startsWith(tok::kw_switch);
125 AnnotatingParser(const FormatStyle &Style, AnnotatedLine &Line,
128 : Style(Style), Line(Line), CurrentToken(Line.First), AutoFound(false),
250 if (MaybeAngles && InExpr && !Line.startsWith(tok::kw_template) &&
356 (Line.startsWith(Keywords.kw_type, tok::identifier) ||
357 Line.startsWith(tok::kw_export, Keywords.kw_type,
389 } else if (Line.InPPDirective &&
405 } else if (!Line.MustBeDeclaration && !Line.InPPDirective) {
505 Line.MustBeDeclaration))) {
701 bool InsideInlineASM = Line.startsWith(tok::kw_asm);
877 } else if (!Style.isVerilog() && !Line.InPragmaDirective &&
1316 if (!Tok->Previous && Line.MustBeDeclaration)
1330 !Line.First->isOneOf(tok::kw_enum, tok::kw_case)) ||
1336 Line.MustBeDeclaration)) { // method/property declaration
1365 if (Line.Level > 1 || (!Line.InPPDirective && Line.Level > 0))
1366 --Line.Level;
1370 if (Line.First->isOneOf(Keywords.kw_module, Keywords.kw_import) ||
1371 Line.First->startsSequence(tok::kw_export, Keywords.kw_module) ||
1372 Line.First->startsSequence(tok::kw_export, Keywords.kw_import)) {
1374 } else if (Line.First->is(tok::kw_asm)) {
1383 Line.startsWith(TT_ObjCMethodSpecifier)) {
1389 Line.startsWith(TT_ObjCMethodSpecifier) &&
1418 !Line.First->isOneOf(tok::kw_enum, tok::kw_case,
1436 Line.Type = LT_AccessModifier;
1556 if (Line.MustBeDeclaration && Contexts.size() == 1 &&
1557 !Contexts.back().IsExpression && !Line.startsWith(TT_ObjCProperty) &&
1558 !Line.startsWith(tok::l_paren) &&
1564 Line.MightBeFunctionDecl = true;
1674 if (Line.MustBeDeclaration && !Contexts.back().IsExpression &&
1699 // Line.MustBeDeclaration will be true for `Type? name;`.
1704 if (!Contexts.back().IsExpression && Line.MustBeDeclaration &&
1731 Line.startsWith(Keywords.kw_assign)) {
1734 (Contexts.size() == 1 || startsWithInitStatement(Line))) {
1736 Line.IsMultiVariableDeclStmt = true;
1746 (Line.Level > 1 || (!Line.InPPDirective && Line.Level > 0))) {
1747 --Line.Level;
1760 Line.IsContinuation = true;
1947 if (!Line.InMacroBody && CurrentToken->is(tok::hash)) {
1973 if (CurrentToken->is(tok::less) && Line.Last->is(tok::greater)) {
1980 if (Style.Language == FormatStyle::LK_Proto && Line.Level == 0 &&
2007 if (Line.First->is(tok::kw_export) &&
2018 if (Line.Type == LT_AccessModifier)
2025 if (Line.startsWith(TT_ObjCMethodSpecifier)) {
2174 if (Line.First->isOneOf(tok::kw_using, tok::kw_return))
2176 if (Line.First->is(tok::kw_template)) {
2184 const FormatToken *Tok = Line.First->getNextNonComment();
2217 (Line.startsWith(Keywords.kw_type, tok::identifier) ||
2218 Line.startsWith(tok::kw_export, Keywords.kw_type,
2228 if (!Line.startsWith(TT_UnaryOperator)) {
2269 if (Line.MustBeDeclaration &&
2371 // Line.MightBeFunctionDecl can only be true after the parentheses of a
2378 (!Line.MightBeFunctionDecl || Current.NestingLevel != 0)) {
2395 Line.MightBeFunctionDecl && Current.NestingLevel == 0 &&
2422 if (Style.isJavaScript() && Line.MustBeDeclaration &&
2538 Line.MightBeFunctionDecl && Contexts.size() == 1) {
2539 // Line.MightBeFunctionDecl can only be true after the parentheses of a
2575 (!NextNonComment && !Line.InMacroBody) ||
2579 (Line.InPragmaDirective && NextNonComment->is(tok::identifier))))) {
2873 (AfterRParen->Next->is(tok::numeric_constant) || Line.InPPDirective)) {
2877 if (Line.InPPDirective && AfterRParen->is(tok::minus))
3108 AnnotatedLine &Line;
3134 AnnotatedLine &Line)
3135 : Style(Style), Keywords(Keywords), Line(Line), Current(Line.First) {}
3256 auto Ret = Current ? Current : Line.Last;
3524 const AnnotatedLine &Line;
3533 for (AnnotatedLine *Line : llvm::reverse(Lines)) {
3534 assert(Line->First);
3539 Line->isComment() && !isClangFormatOff(Line->First->TokenText) &&
3541 Line->First->OriginalColumn) {
3546 Line->Type = LT_CommentAbovePPDirective;
3550 Line->Level = Style.IndentPPDirectives != FormatStyle::PPDIS_BeforeHash &&
3555 NextNonCommentLine = Line->First->isNot(tok::r_brace) ? Line : nullptr;
3558 setCommentLineLevels(Line->Children);
3562 static unsigned maxNestingDepth(const AnnotatedLine &Line) {
3564 for (const auto *Tok = Line.First; Tok; Tok = Tok->Next)
3571 static FormatToken *getFunctionName(const AnnotatedLine &Line,
3573 for (FormatToken *Tok = Line.getFirstNonComment(), *Name = nullptr; Tok;
3646 void TokenAnnotator::annotate(AnnotatedLine &Line) {
3647 AnnotatingParser Parser(Style, Line, Keywords, Scopes);
3648 Line.Type = Parser.parseLine();
3650 for (auto &Child : Line.Children)
3657 if (maxNestingDepth(Line) > 50)
3658 Line.Type = LT_Invalid;
3660 if (Line.Type == LT_Invalid)
3663 ExpressionParser ExprParser(Style, Keywords, Line);
3668 auto *Tok = getFunctionName(Line, OpeningParen);
3670 Line.endsWith(TT_FunctionLBrace) || isCtorOrDtorName(Tok))) {
3677 if (Line.startsWith(TT_ObjCMethodSpecifier))
3678 Line.Type = LT_ObjCMethodDecl;
3679 else if (Line.startsWith(TT_ObjCDecl))
3680 Line.Type = LT_ObjCDecl;
3681 else if (Line.startsWith(TT_ObjCProperty))
3682 Line.Type = LT_ObjCProperty;
3684 auto *First = Line.First;
3693 const AnnotatedLine &Line,
3798 if (Line.Last->is(tok::l_brace))
3817 !Line.endsWith(tok::semi)) {
3839 bool TokenAnnotator::mustBreakForReturnType(const AnnotatedLine &Line) const {
3840 assert(Line.MightBeFunctionDecl);
3844 Line.Level > 0) {
3858 return Line.mightBeFunctionDefinition();
3864 void TokenAnnotator::calculateFormattingInformation(AnnotatedLine &Line) const {
3865 for (AnnotatedLine *ChildLine : Line.Children)
3868 auto *First = Line.First;
3871 : Line.FirstStartColumn + First->ColumnWidth;
3873 bool InFunctionDecl = Line.MightBeFunctionDecl;
3876 Line.Type == LT_ArrayOfStructInitializer);
3878 calculateArrayInitializerColumnList(Line);
3892 isFunctionDeclarationName(LangOpts, *Tok, Line, ClosingParen)) {
3908 Line.endsWith(tok::semi, tok::r_brace)) {
3909 auto *Tok = Line.Last->Previous;
3924 Line.ReturnTypeWrapped = true;
4009 spaceRequiredBefore(Line, *Current)) {
4018 Current->MustBreakBefore || mustBreakBefore(Line, *Current);
4021 Current->MustBreakBefore = mustBreakForReturnType(Line);
4026 Current->MustBreakBefore || canBreakBefore(Line, *Current);
4055 Current->SplitPenalty = splitPenalty(Line, *Current, InFunctionDecl);
4067 calculateUnbreakableTailLengths(Line);
4068 unsigned IndentLevel = Line.Level;
4082 LLVM_DEBUG({ printDebugInfo(Line); });
4086 AnnotatedLine &Line) const {
4088 FormatToken *Current = Line.Last;
4103 AnnotatedLine &Line) const {
4104 if (Line.First == Line.Last)
4106 auto *CurrentToken = Line.First;
4109 while (CurrentToken && CurrentToken != Line.Last) {
4115 calculateInitializerColumnList(Line, CurrentToken->Next, Depth + 1);
4123 AnnotatedLine &Line, FormatToken *CurrentToken, unsigned Depth) const {
4124 while (CurrentToken && CurrentToken != Line.Last) {
4141 unsigned TokenAnnotator::splitPenalty(const AnnotatedLine &Line,
4196 if (Line.startsWith(tok::kw_for) && Right.PartOfMultiVariableDeclStmt)
4251 if (Line.startsWith(TT_ObjCMethodSpecifier))
4263 if (Line.startsWith(tok::kw_for) && Left.is(tok::equal))
4271 return Line.MightBeFunctionDecl ? 50 : 500;
4276 if (Line.Type == LT_ObjCDecl && Left.is(tok::l_paren) && Left.Previous &&
4370 bool TokenAnnotator::spaceRequiredBetween(const AnnotatedLine &Line,
4383 if (Style.ObjCSpaceAfterProperty && Line.Type == LT_ObjCProperty &&
4392 Right.MatchingParen == &Left && Line.Children.empty()) {
4455 if (Right.is(tok::less) && Line.Type == LT_ObjCDecl) {
4495 if (Left.is(tok::r_paren) && Line.MightBeFunctionDecl) {
4523 (Line.IsMultiVariableDeclStmt &&
4525 (Left.NestingLevel == 1 && startsWithInitStatement(Line)))));
4530 !Line.IsMultiVariableDeclStmt))) {
4575 if (Line.IsMultiVariableDeclStmt &&
4576 (Left.NestingLevel == Line.First->NestingLevel ||
4577 ((Left.NestingLevel == Line.First->NestingLevel + 1) &&
4578 startsWithInitStatement(Line)))) {
4724 !(Line.MightBeFunctionDecl && Left.is(TT_FunctionDeclarationName))) {
4727 if (Line.Type == LT_ObjCDecl)
4733 Left.isIf(Line.Type != LT_PreprocessorDirective) ||
4744 if (Line.MightBeFunctionDecl && Right.is(TT_FunctionDeclarationLParen)) {
4748 return Line.mightBeFunctionDefinition()
4753 if (Line.Type != LT_PreprocessorDirective && Left.is(tok::r_square) &&
4764 return ((!Line.MightBeFunctionDecl || !BeforeLeft) &&
4777 if (Line.Type != LT_PreprocessorDirective &&
4844 bool TokenAnnotator::spaceRequiredBefore(const AnnotatedLine &Line,
4893 Line.First->is(Keywords.kw_import)) {
5061 if (Line.MustBeDeclaration && Left.Tok.getIdentifierInfo())
5108 Line.First->isOneOf(Keywords.kw_import, tok::kw_export)) {
5268 if (Line.Type == LT_ObjCMethodDecl) {
5279 if (Line.Type == LT_ObjCProperty &&
5430 Line.Type == LT_ImportStatement) {
5437 return spaceRequiredBetween(Line, Left, Right);
5463 bool TokenAnnotator::mustBreakBefore(const AnnotatedLine &Line,
5469 if (Style.BreakFunctionDefinitionParameters && Line.MightBeFunctionDecl &&
5470 Line.mightBeFunctionDefinition() && Left.MightBeFunctionDeclParen &&
5512 if (Left.is(TT_DictLiteral) && Left.is(tok::l_brace) && Line.Level == 0 &&
5514 Line.First->isOneOf(tok::identifier, Keywords.kw_import, tok::kw_export,
5518 !Line.First->isOneOf(Keywords.kw_var, Keywords.kw_let)) {
5523 if (Left.is(tok::l_brace) && Line.Level == 0 &&
5524 (Line.startsWith(tok::kw_enum) ||
5525 Line.startsWith(tok::kw_const, tok::kw_enum) ||
5526 Line.startsWith(tok::kw_export, tok::kw_enum) ||
5527 Line.startsWith(tok::kw_export, tok::kw_const, tok::kw_enum))) {
5545 return (Left.NestingLevel == 0 && Line.Level == 0) &&
5556 (Left.NestingLevel == 0 && Line.Level == 0 &&
5635 if (Line.startsWith(tok::kw_asm) && Right.is(TT_InlineASMColon) &&
5644 if (Style.JavaScriptWrapImports || Line.Type != LT_ImportStatement) {
5763 auto *FirstNonComment = Line.getFirstNonComment();
5769 if (Line.startsWith(tok::kw_enum) ||
5770 Line.startsWith(tok::kw_typedef, tok::kw_enum)) {
5784 Line.startsWith(Keywords.kw_interface))) {
5790 return (Line.startsWith(tok::kw_class) &&
5792 (Line.startsWith(tok::kw_struct) &&
5831 (Line.Last->is(tok::l_brace) || Style.BreakAfterJavaFieldAnnotations)) {
5925 bool TokenAnnotator::canBreakBefore(const AnnotatedLine &Line,
5935 if (Line.First->is(TT_CSharpGenericTypeConstraint))
6056 return Line.IsMultiVariableDeclStmt ||
6140 if (Left.is(tok::r_paren) && Line.Type == LT_ObjCProperty)
6179 Line.Type == LT_VirtualFunctionDecl && Left.NestingLevel == 0) {
6313 void TokenAnnotator::printDebugInfo(const AnnotatedLine &Line) const {
6314 llvm::errs() << "AnnotatedTokens(L=" << Line.Level << ", P=" << Line.PPLevel
6315 << ", T=" << Line.Type << ", C=" << Line.IsContinuation
6317 const FormatToken *Tok = Line.First;
6333 assert(Tok == Line.Last);