Please use GitHub pull requests for new patches. Avoid migrating existing patches. Phabricator shutdown timeline
Changeset View
Changeset View
Standalone View
Standalone View
clang/lib/Format/TokenAnnotator.cpp
Show First 20 Lines • Show All 1,619 Lines • ▼ Show 20 Lines | struct Context { | ||||||||
bool ColonIsDictLiteral = false; | bool ColonIsDictLiteral = false; | ||||||||
bool ColonIsObjCMethodExpr = false; | bool ColonIsObjCMethodExpr = false; | ||||||||
FormatToken *FirstObjCSelectorName = nullptr; | FormatToken *FirstObjCSelectorName = nullptr; | ||||||||
FormatToken *FirstStartOfName = nullptr; | FormatToken *FirstStartOfName = nullptr; | ||||||||
bool CanBeExpression = true; | bool CanBeExpression = true; | ||||||||
bool CaretFound = false; | bool CaretFound = false; | ||||||||
bool InCpp11AttributeSpecifier = false; | bool InCpp11AttributeSpecifier = false; | ||||||||
bool InCSharpAttributeSpecifier = false; | bool InCSharpAttributeSpecifier = false; | ||||||||
bool VerilogAssignmentFound = false; | |||||||||
owenpanUnsubmitted Done ReplyInline Actions
owenpan: | |||||||||
enum { | enum { | ||||||||
Unknown, | Unknown, | ||||||||
// Like the part after `:` in a constructor. | // Like the part after `:` in a constructor. | ||||||||
// Context(...) : IsExpression(IsExpression) | // Context(...) : IsExpression(IsExpression) | ||||||||
CtorInitializer, | CtorInitializer, | ||||||||
// Like in the parentheses in a foreach. | // Like in the parentheses in a foreach. | ||||||||
ForEachMacro, | ForEachMacro, | ||||||||
// Like the inheritance list in a class declaration. | // Like the inheritance list in a class declaration. | ||||||||
▲ Show 20 Lines • Show All 281 Lines • ▼ Show 20 Lines | if (Current.is(Keywords.kw_instanceof)) { | ||||||||
Current.setType(TT_JsTypeOptionalQuestion); | Current.setType(TT_JsTypeOptionalQuestion); | ||||||||
} else { | } else { | ||||||||
Current.setType(TT_ConditionalExpr); | Current.setType(TT_ConditionalExpr); | ||||||||
} | } | ||||||||
} else if (Current.isBinaryOperator() && | } else if (Current.isBinaryOperator() && | ||||||||
(!Current.Previous || Current.Previous->isNot(tok::l_square)) && | (!Current.Previous || Current.Previous->isNot(tok::l_square)) && | ||||||||
(!Current.is(tok::greater) && | (!Current.is(tok::greater) && | ||||||||
Style.Language != FormatStyle::LK_TextProto)) { | Style.Language != FormatStyle::LK_TextProto)) { | ||||||||
if (Style.isVerilog()) { | |||||||||
if (Current.is(tok::lessequal) && Contexts.size() == 1 && | |||||||||
!Contexts.back().VerilogAssignmentFound) { | |||||||||
// In Verilog `<=` is assignment if in its own statement. It is a | |||||||||
// statement instead of an expression, that is it can not be chained. | |||||||||
Current.ForcedPrecedence = prec::Assignment; | |||||||||
Current.setFinalizedType(TT_BinaryOperator); | |||||||||
} | |||||||||
if (Current.getPrecedence() == prec::Assignment) | |||||||||
Contexts.back().VerilogAssignmentFound = true; | |||||||||
} | |||||||||
Current.setType(TT_BinaryOperator); | Current.setType(TT_BinaryOperator); | ||||||||
} else if (Current.is(tok::comment)) { | } else if (Current.is(tok::comment)) { | ||||||||
if (Current.TokenText.startswith("/*")) { | if (Current.TokenText.startswith("/*")) { | ||||||||
if (Current.TokenText.endswith("*/")) { | if (Current.TokenText.endswith("*/")) { | ||||||||
Current.setType(TT_BlockComment); | Current.setType(TT_BlockComment); | ||||||||
} else { | } else { | ||||||||
// The lexer has for some reason determined a comment here. But we | // The lexer has for some reason determined a comment here. But we | ||||||||
// cannot really handle it, if it isn't properly terminated. | // cannot really handle it, if it isn't properly terminated. | ||||||||
Current.Tok.setKind(tok::unknown); | Current.Tok.setKind(tok::unknown); | ||||||||
} | } | ||||||||
} else { | } else { | ||||||||
Can you move them into the if statement above? owenpan: Can you move them into the `if` statement above? | |||||||||
Current.setType(TT_LineComment); | Current.setType(TT_LineComment); | ||||||||
} | } | ||||||||
} else if (Current.is(tok::l_paren)) { | } else if (Current.is(tok::l_paren)) { | ||||||||
if (lParenStartsCppCast(Current)) | if (lParenStartsCppCast(Current)) | ||||||||
Current.setType(TT_CppCastLParen); | Current.setType(TT_CppCastLParen); | ||||||||
} else if (Current.is(tok::r_paren)) { | } else if (Current.is(tok::r_paren)) { | ||||||||
if (rParenEndsCast(Current)) | if (rParenEndsCast(Current)) | ||||||||
Current.setType(TT_CastRParen); | Current.setType(TT_CastRParen); | ||||||||
▲ Show 20 Lines • Show All 3,260 Lines • Show Last 20 Lines |