Changeset View
Changeset View
Standalone View
Standalone View
clang/lib/Format/TokenAnnotator.cpp
Show First 20 Lines • Show All 316 Lines • ▼ Show 20 Lines | if (OpeningParen.is(TT_OverloadedOperatorLParen)) { | ||||||||
OpeningParen.Previous->is(TT_JsTypeColon)) { | OpeningParen.Previous->is(TT_JsTypeColon)) { | ||||||||
// let x: (SomeType); | // let x: (SomeType); | ||||||||
Contexts.back().IsExpression = false; | Contexts.back().IsExpression = false; | ||||||||
} else if (isLambdaParameterList(&OpeningParen)) { | } else if (isLambdaParameterList(&OpeningParen)) { | ||||||||
// This is a parameter list of a lambda expression. | // This is a parameter list of a lambda expression. | ||||||||
Contexts.back().IsExpression = false; | Contexts.back().IsExpression = false; | ||||||||
} else if (OpeningParen.is(TT_RequiresExpressionLParen)) { | } else if (OpeningParen.is(TT_RequiresExpressionLParen)) { | ||||||||
Contexts.back().IsExpression = false; | Contexts.back().IsExpression = false; | ||||||||
} else if (OpeningParen.Previous && | |||||||||
OpeningParen.Previous->is(tok::kw__Generic)) { | |||||||||
Contexts.back().ContextType = Context::C11GenericSelection; | |||||||||
Contexts.back().IsExpression = true; | |||||||||
} else if (Line.InPPDirective && | } else if (Line.InPPDirective && | ||||||||
(!OpeningParen.Previous || | (!OpeningParen.Previous || | ||||||||
!OpeningParen.Previous->is(tok::identifier))) { | !OpeningParen.Previous->is(tok::identifier))) { | ||||||||
Contexts.back().IsExpression = true; | Contexts.back().IsExpression = true; | ||||||||
} else if (Contexts[Contexts.size() - 2].CaretFound) { | } else if (Contexts[Contexts.size() - 2].CaretFound) { | ||||||||
// This is the parameter list of an ObjC block. | // This is the parameter list of an ObjC block. | ||||||||
Contexts.back().IsExpression = false; | Contexts.back().IsExpression = false; | ||||||||
} else if (OpeningParen.Previous && | } else if (OpeningParen.Previous && | ||||||||
▲ Show 20 Lines • Show All 689 Lines • ▼ Show 20 Lines | case tok::colon: | ||||||||
Tok->Previous->ColumnWidth; | Tok->Previous->ColumnWidth; | ||||||||
} | } | ||||||||
Tok->Previous->ParameterIndex = | Tok->Previous->ParameterIndex = | ||||||||
Contexts.back().FirstObjCSelectorName->ObjCSelectorNameParts; | Contexts.back().FirstObjCSelectorName->ObjCSelectorNameParts; | ||||||||
++Contexts.back().FirstObjCSelectorName->ObjCSelectorNameParts; | ++Contexts.back().FirstObjCSelectorName->ObjCSelectorNameParts; | ||||||||
} | } | ||||||||
} else if (Contexts.back().ColonIsForRangeExpr) { | } else if (Contexts.back().ColonIsForRangeExpr) { | ||||||||
Tok->setType(TT_RangeBasedForLoopColon); | Tok->setType(TT_RangeBasedForLoopColon); | ||||||||
} else if (Contexts.back().ContextType == Context::C11GenericSelection) { | |||||||||
Tok->setType(TT_GenericSelectionColon); | |||||||||
} else if (CurrentToken && CurrentToken->is(tok::numeric_constant)) { | } else if (CurrentToken && CurrentToken->is(tok::numeric_constant)) { | ||||||||
Tok->setType(TT_BitFieldColon); | Tok->setType(TT_BitFieldColon); | ||||||||
} else if (Contexts.size() == 1 && | } else if (Contexts.size() == 1 && | ||||||||
!Line.First->isOneOf(tok::kw_enum, tok::kw_case, | !Line.First->isOneOf(tok::kw_enum, tok::kw_case, | ||||||||
tok::kw_default)) { | tok::kw_default)) { | ||||||||
FormatToken *Prev = Tok->getPreviousNonComment(); | FormatToken *Prev = Tok->getPreviousNonComment(); | ||||||||
if (!Prev) | if (!Prev) | ||||||||
break; | break; | ||||||||
▲ Show 20 Lines • Show All 583 Lines • ▼ Show 20 Lines | enum { | ||||||||
// Like the inheritance list in a class declaration. | // Like the inheritance list in a class declaration. | ||||||||
// class Input : public IO | // class Input : public IO | ||||||||
InheritanceList, | InheritanceList, | ||||||||
// Like in the braced list. | // Like in the braced list. | ||||||||
// int x[] = {}; | // int x[] = {}; | ||||||||
StructArrayInitializer, | StructArrayInitializer, | ||||||||
// Like in `static_cast<int>`. | // Like in `static_cast<int>`. | ||||||||
TemplateArgument, | TemplateArgument, | ||||||||
// C11 _Generic selection. | |||||||||
HazardyKnusperkeksUnsubmitted Done ReplyInline Actions
HazardyKnusperkeks: | |||||||||
C11GenericSelection, | |||||||||
} ContextType = Unknown; | } ContextType = Unknown; | ||||||||
}; | }; | ||||||||
/// Puts a new \c Context onto the stack \c Contexts for the lifetime | /// Puts a new \c Context onto the stack \c Contexts for the lifetime | ||||||||
/// of each instance. | /// of each instance. | ||||||||
struct ScopedContextCreator { | struct ScopedContextCreator { | ||||||||
AnnotatingParser &P; | AnnotatingParser &P; | ||||||||
▲ Show 20 Lines • Show All 1,612 Lines • ▼ Show 20 Lines | unsigned TokenAnnotator::splitPenalty(const AnnotatedLine &Line, | ||||||||
if (Left.is(tok::l_paren) && Style.PenaltyBreakOpenParenthesis != 0) | if (Left.is(tok::l_paren) && Style.PenaltyBreakOpenParenthesis != 0) | ||||||||
return Style.PenaltyBreakOpenParenthesis; | return Style.PenaltyBreakOpenParenthesis; | ||||||||
if (Left.is(tok::l_paren) && InFunctionDecl && | if (Left.is(tok::l_paren) && InFunctionDecl && | ||||||||
Style.AlignAfterOpenBracket != FormatStyle::BAS_DontAlign) { | Style.AlignAfterOpenBracket != FormatStyle::BAS_DontAlign) { | ||||||||
return 100; | return 100; | ||||||||
} | } | ||||||||
if (Left.is(tok::l_paren) && Left.Previous && | if (Left.is(tok::l_paren) && Left.Previous && | ||||||||
(Left.Previous->is(tok::kw_for) || Left.Previous->isIf())) { | (Left.Previous->isOneOf(tok::kw_for, tok::kw__Generic) || | ||||||||
Left.Previous->isIf())) { | |||||||||
return 1000; | return 1000; | ||||||||
} | } | ||||||||
if (Left.is(tok::equal) && InFunctionDecl) | if (Left.is(tok::equal) && InFunctionDecl) | ||||||||
return 110; | return 110; | ||||||||
if (Right.is(tok::r_brace)) | if (Right.is(tok::r_brace)) | ||||||||
return 1; | return 1; | ||||||||
if (Left.is(TT_TemplateOpener)) | if (Left.is(TT_TemplateOpener)) | ||||||||
return 100; | return 100; | ||||||||
▲ Show 20 Lines • Show All 892 Lines • ▼ Show 20 Lines | if (Right.is(tok::colon)) { | ||||||||
if (Right.is(TT_InlineASMColon) && Left.is(tok::coloncolon)) | if (Right.is(TT_InlineASMColon) && Left.is(tok::coloncolon)) | ||||||||
return false; | return false; | ||||||||
if (Right.is(TT_DictLiteral)) | if (Right.is(TT_DictLiteral)) | ||||||||
return Style.SpacesInContainerLiterals; | return Style.SpacesInContainerLiterals; | ||||||||
if (Right.is(TT_AttributeColon)) | if (Right.is(TT_AttributeColon)) | ||||||||
return false; | return false; | ||||||||
if (Right.is(TT_CSharpNamedArgumentColon)) | if (Right.is(TT_CSharpNamedArgumentColon)) | ||||||||
return false; | return false; | ||||||||
if (Right.is(TT_GenericSelectionColon)) | |||||||||
return false; | |||||||||
if (Right.is(TT_BitFieldColon)) { | if (Right.is(TT_BitFieldColon)) { | ||||||||
return Style.BitFieldColonSpacing == FormatStyle::BFCS_Both || | return Style.BitFieldColonSpacing == FormatStyle::BFCS_Both || | ||||||||
Style.BitFieldColonSpacing == FormatStyle::BFCS_Before; | Style.BitFieldColonSpacing == FormatStyle::BFCS_Before; | ||||||||
} | } | ||||||||
return true; | return true; | ||||||||
} | } | ||||||||
// Do not merge "- -" into "--". | // Do not merge "- -" into "--". | ||||||||
if ((Left.isOneOf(tok::minus, tok::minusminus) && | if ((Left.isOneOf(tok::minus, tok::minusminus) && | ||||||||
▲ Show 20 Lines • Show All 986 Lines • Show Last 20 Lines |