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);
126 AnnotatingParser(const FormatStyle &Style, AnnotatedLine &Line,
129 : Style(Style), Line(Line), CurrentToken(Line.First), AutoFound(false),
254 if (MaybeAngles && InExpr && !Line.startsWith(tok::kw_template) &&
360 (Line.startsWith(Keywords.kw_type, tok::identifier) ||
361 Line.startsWith(tok::kw_export, Keywords.kw_type,
394 } else if (Line.InPPDirective &&
410 } else if (!Line.MustBeDeclaration &&
411 (!Line.InPPDirective || (Line.InMacroBody && !Scopes.empty()))) {
495 (Line.MustBeDeclaration ||
701 bool InsideInlineASM = Line.startsWith(tok::kw_asm);
877 } else if (!Style.isVerilog() && !Line.InPragmaDirective &&
1313 if (!Tok->Previous && Line.MustBeDeclaration)
1327 !Line.First->isOneOf(tok::kw_enum, tok::kw_case)) ||
1333 Line.MustBeDeclaration)) { // method/property declaration
1362 if (Line.Level > 1 || (!Line.InPPDirective && Line.Level > 0))
1363 --Line.Level;
1367 if (Line.First->isOneOf(Keywords.kw_module, Keywords.kw_import) ||
1368 Line.First->startsSequence(tok::kw_export, Keywords.kw_module) ||
1369 Line.First->startsSequence(tok::kw_export, Keywords.kw_import)) {
1371 } else if (Line.First->is(tok::kw_asm)) {
1380 Line.startsWith(TT_ObjCMethodSpecifier)) {
1386 Line.startsWith(TT_ObjCMethodSpecifier) &&
1421 !Line.First->isOneOf(tok::kw_enum, tok::kw_case,
1439 Line.Type = LT_AccessModifier;
1561 if (Line.MustBeDeclaration && Contexts.size() == 1 &&
1562 !Contexts.back().IsExpression && !Line.startsWith(TT_ObjCProperty) &&
1563 !Line.startsWith(tok::l_paren) &&
1569 Line.MightBeFunctionDecl = true;
1583 Line.Type = LT_RequiresExpression;
1682 if (Line.MustBeDeclaration && !Contexts.back().IsExpression &&
1707 // Line.MustBeDeclaration will be true for `Type? name;`.
1712 if (!Contexts.back().IsExpression && Line.MustBeDeclaration &&
1739 Line.startsWith(Keywords.kw_assign)) {
1742 (Contexts.size() == 1 || startsWithInitStatement(Line))) {
1744 Line.IsMultiVariableDeclStmt = true;
1754 (Line.Level > 1 || (!Line.InPPDirective && Line.Level > 0))) {
1755 --Line.Level;
1768 Line.IsContinuation = true;
1955 if (!Line.InMacroBody && CurrentToken->is(tok::hash)) {
1981 if (CurrentToken->is(tok::less) && Line.Last->is(tok::greater)) {
1988 if (Style.Language == FormatStyle::LK_Proto && Line.Level == 0 &&
2015 if (Line.First->is(tok::kw_export) &&
2026 if (const auto Type = Line.Type; Type == LT_AccessModifier ||
2036 if (Line.startsWith(TT_ObjCMethodSpecifier)) {
2185 if (Line.First->isOneOf(tok::kw_using, tok::kw_return))
2187 if (Line.First->is(tok::kw_template)) {
2195 const FormatToken *Tok = Line.First->getNextNonComment();
2228 (Line.startsWith(Keywords.kw_type, tok::identifier) ||
2229 Line.startsWith(tok::kw_export, Keywords.kw_type,
2239 if (!Line.startsWith(TT_UnaryOperator)) {
2280 if (Line.MustBeDeclaration &&
2382 // Line.MightBeFunctionDecl can only be true after the parentheses of a
2389 (!Line.MightBeFunctionDecl || Current.NestingLevel != 0)) {
2406 Line.MightBeFunctionDecl && Current.NestingLevel == 0 &&
2434 if (Style.isJavaScript() && Line.MustBeDeclaration &&
2550 Line.MightBeFunctionDecl && Contexts.size() == 1) {
2551 // Line.MightBeFunctionDecl can only be true after the parentheses of a
2587 (!NextNonComment && !Line.InMacroBody) ||
2591 (Line.InPragmaDirective && NextNonComment->is(tok::identifier))))) {
2899 (AfterRParen->Next->is(tok::numeric_constant) || Line.InPPDirective)) {
2903 if (Line.InPPDirective && AfterRParen->is(tok::minus))
3107 if (Line.Type == LT_SimpleRequirement ||
3144 AnnotatedLine &Line;
3170 AnnotatedLine &Line)
3171 : Style(Style), Keywords(Keywords), Line(Line), Current(Line.First) {}
3301 auto Ret = Current ? Current : Line.Last;
3569 const AnnotatedLine &Line;
3578 for (AnnotatedLine *Line : reverse(Lines)) {
3579 assert(Line->First);
3584 Line->isComment() && !isClangFormatOff(Line->First->TokenText) &&
3586 Line->First->OriginalColumn) {
3591 Line->Type = LT_CommentAbovePPDirective;
3595 Line->Level = Style.IndentPPDirectives != FormatStyle::PPDIS_BeforeHash &&
3600 NextNonCommentLine = Line->First->isNot(tok::r_brace) ? Line : nullptr;
3603 setCommentLineLevels(Line->Children);
3607 static unsigned maxNestingDepth(const AnnotatedLine &Line) {
3609 for (const auto *Tok = Line.First; Tok; Tok = Tok->Next)
3616 static FormatToken *getFunctionName(const AnnotatedLine &Line,
3618 for (FormatToken *Tok = Line.getFirstNonComment(), *Name = nullptr; Tok;
3690 void TokenAnnotator::annotate(AnnotatedLine &Line) {
3691 if (!Line.InMacroBody)
3694 auto &ScopeStack = Line.InMacroBody ? MacroBodyScopes : Scopes;
3695 AnnotatingParser Parser(Style, Line, Keywords, ScopeStack);
3696 Line.Type = Parser.parseLine();
3698 if (!Line.Children.empty()) {
3700 const bool InRequiresExpression = Line.Type == LT_RequiresExpression;
3701 for (auto &Child : Line.Children) {
3718 if (maxNestingDepth(Line) > 50)
3719 Line.Type = LT_Invalid;
3721 if (Line.Type == LT_Invalid)
3724 ExpressionParser ExprParser(Style, Keywords, Line);
3729 auto *Tok = getFunctionName(Line, OpeningParen);
3731 Line.endsWith(TT_FunctionLBrace) || isCtorOrDtorName(Tok))) {
3738 if (Line.startsWith(TT_ObjCMethodSpecifier))
3739 Line.Type = LT_ObjCMethodDecl;
3740 else if (Line.startsWith(TT_ObjCDecl))
3741 Line.Type = LT_ObjCDecl;
3742 else if (Line.startsWith(TT_ObjCProperty))
3743 Line.Type = LT_ObjCProperty;
3745 auto *First = Line.First;
3754 const AnnotatedLine &Line,
3866 if (Line.Last->is(tok::l_brace))
3885 !Line.endsWith(tok::semi)) {
3907 bool TokenAnnotator::mustBreakForReturnType(const AnnotatedLine &Line) const {
3908 assert(Line.MightBeFunctionDecl);
3912 Line.Level > 0) {
3926 return Line.mightBeFunctionDefinition();
3932 void TokenAnnotator::calculateFormattingInformation(AnnotatedLine &Line) const {
3933 if (Line.Computed)
3936 Line.Computed = true;
3938 for (AnnotatedLine *ChildLine : Line.Children)
3941 auto *First = Line.First;
3944 : Line.FirstStartColumn + First->ColumnWidth;
3947 Line.Type == LT_ArrayOfStructInitializer);
3949 calculateArrayInitializerColumnList(Line);
3951 const auto *FirstNonComment = Line.getFirstNonComment();
3965 isFunctionDeclarationName(LangOpts, *Tok, Line, ClosingParen)) {
3983 Line.endsWith(tok::semi, tok::r_brace)) {
3984 auto *Tok = Line.Last->Previous;
3999 Line.ReturnTypeWrapped = true;
4048 bool InFunctionDecl = Line.MightBeFunctionDecl;
4085 spaceRequiredBefore(Line, *Current)) {
4094 Current->MustBreakBefore || mustBreakBefore(Line, *Current);
4097 Current->MustBreakBefore = mustBreakForReturnType(Line);
4102 Current->MustBreakBefore || canBreakBefore(Line, *Current);
4131 Current->SplitPenalty = splitPenalty(Line, *Current, InFunctionDecl);
4141 calculateUnbreakableTailLengths(Line);
4142 unsigned IndentLevel = Line.Level;
4156 LLVM_DEBUG({ printDebugInfo(Line); });
4160 AnnotatedLine &Line) const {
4162 FormatToken *Current = Line.Last;
4177 AnnotatedLine &Line) const {
4178 if (Line.First == Line.Last)
4180 auto *CurrentToken = Line.First;
4183 while (CurrentToken && CurrentToken != Line.Last) {
4189 calculateInitializerColumnList(Line, CurrentToken->Next, Depth + 1);
4197 AnnotatedLine &Line, FormatToken *CurrentToken, unsigned Depth) const {
4198 while (CurrentToken && CurrentToken != Line.Last) {
4215 unsigned TokenAnnotator::splitPenalty(const AnnotatedLine &Line,
4270 if (Line.startsWith(tok::kw_for) && Right.PartOfMultiVariableDeclStmt)
4327 if (Line.startsWith(TT_ObjCMethodSpecifier))
4339 if (Line.startsWith(tok::kw_for) && Left.is(tok::equal))
4347 return Line.MightBeFunctionDecl ? 50 : 500;
4352 if (Line.Type == LT_ObjCDecl && Left.is(tok::l_paren) && Left.Previous &&
4446 bool TokenAnnotator::spaceRequiredBetween(const AnnotatedLine &Line,
4459 if (Style.ObjCSpaceAfterProperty && Line.Type == LT_ObjCProperty &&
4468 Right.MatchingParen == &Left && Line.Children.empty()) {
4529 if (Right.is(tok::less) && Line.Type == LT_ObjCDecl) {
4569 if (Left.is(tok::r_paren) && Line.MightBeFunctionDecl) {
4597 (Line.IsMultiVariableDeclStmt &&
4599 (Left.NestingLevel == 1 && startsWithInitStatement(Line)))));
4604 !Line.IsMultiVariableDeclStmt))) {
4649 if (Line.IsMultiVariableDeclStmt &&
4650 (Left.NestingLevel == Line.First->NestingLevel ||
4651 ((Left.NestingLevel == Line.First->NestingLevel + 1) &&
4652 startsWithInitStatement(Line)))) {
4798 !(Line.MightBeFunctionDecl && Left.is(TT_FunctionDeclarationName))) {
4803 if (Line.Type == LT_ObjCDecl)
4809 Left.isIf(Line.Type != LT_PreprocessorDirective) ||
4820 if (Line.MightBeFunctionDecl && Right.is(TT_FunctionDeclarationLParen)) {
4824 return Line.mightBeFunctionDefinition()
4829 if (Line.Type != LT_PreprocessorDirective && Left.is(tok::r_square) &&
4840 return ((!Line.MightBeFunctionDecl || !BeforeLeft) &&
4853 if (Line.Type != LT_PreprocessorDirective &&
4920 bool TokenAnnotator::spaceRequiredBefore(const AnnotatedLine &Line,
4975 Line.First->is(Keywords.kw_import)) {
5143 if (Line.MustBeDeclaration && Left.Tok.getIdentifierInfo())
5190 Line.First->isOneOf(Keywords.kw_import, tok::kw_export)) {
5350 if (Line.Type == LT_ObjCMethodDecl) {
5361 if (Line.Type == LT_ObjCProperty &&
5516 Line.Type == LT_ImportStatement) {
5523 return spaceRequiredBetween(Line, Left, Right);
5549 bool TokenAnnotator::mustBreakBefore(const AnnotatedLine &Line,
5553 (!Style.RemoveEmptyLinesInUnwrappedLines || &Right == Line.First)) {
5557 if (Style.BreakFunctionDefinitionParameters && Line.MightBeFunctionDecl &&
5558 Line.mightBeFunctionDefinition() && Left.MightBeFunctionDeclParen &&
5566 Line.MightBeFunctionDecl && !Left.opensScope() &&
5608 if (Left.is(TT_DictLiteral) && Left.is(tok::l_brace) && Line.Level == 0 &&
5610 Line.First->isOneOf(tok::identifier, Keywords.kw_import, tok::kw_export,
5614 !Line.First->isOneOf(Keywords.kw_var, Keywords.kw_let)) {
5619 if (Left.is(tok::l_brace) && Line.Level == 0 &&
5620 (Line.startsWith(tok::kw_enum) ||
5621 Line.startsWith(tok::kw_const, tok::kw_enum) ||
5622 Line.startsWith(tok::kw_export, tok::kw_enum) ||
5623 Line.startsWith(tok::kw_export, tok::kw_const, tok::kw_enum))) {
5641 return (Left.NestingLevel == 0 && Line.Level == 0) &&
5652 (Left.NestingLevel == 0 && Line.Level == 0 &&
5731 if (Line.startsWith(tok::kw_asm) && Right.is(TT_InlineASMColon) &&
5740 if (Style.JavaScriptWrapImports || Line.Type != LT_ImportStatement) {
5862 auto *FirstNonComment = Line.getFirstNonComment();
5868 if (Line.startsWith(tok::kw_enum) ||
5869 Line.startsWith(tok::kw_typedef, tok::kw_enum)) {
5883 Line.startsWith(Keywords.kw_interface))) {
5889 return (Line.startsWith(tok::kw_class) &&
5891 (Line.startsWith(tok::kw_struct) &&
5930 (Line.Last->is(tok::l_brace) || Style.BreakAfterJavaFieldAnnotations)) {
6024 bool TokenAnnotator::canBreakBefore(const AnnotatedLine &Line,
6034 if (Line.First->is(TT_CSharpGenericTypeConstraint))
6184 return Line.IsMultiVariableDeclStmt ||
6268 if (Left.is(tok::r_paren) && Line.Type == LT_ObjCProperty)
6307 Line.Type == LT_VirtualFunctionDecl && Left.NestingLevel == 0) {
6419 void TokenAnnotator::printDebugInfo(const AnnotatedLine &Line) const {
6420 llvm::errs() << "AnnotatedTokens(L=" << Line.Level << ", P=" << Line.PPLevel
6421 << ", T=" << Line.Type << ", C=" << Line.IsContinuation
6423 const FormatToken *Tok = Line.First;
6439 assert(Tok == Line.Last);