diff options
| author | Daniel Jasper <djasper@google.com> | 2014-06-10 14:44:02 +0000 |
|---|---|---|
| committer | Daniel Jasper <djasper@google.com> | 2014-06-10 14:44:02 +0000 |
| commit | 17062ff5509495c41645155247241749e0f19a33 (patch) | |
| tree | 9d7ae0af807eb05430cc7529eccd35b4081cfd03 /clang/lib/Format/TokenAnnotator.cpp | |
| parent | f910a0650eb4aad5e50e997c9438d7eef60dc901 (diff) | |
| download | bcm5719-llvm-17062ff5509495c41645155247241749e0f19a33.tar.gz bcm5719-llvm-17062ff5509495c41645155247241749e0f19a33.zip | |
clang-format: [JS] Treat dict literals similar to objc method exprs.
Before:
return {
link:
function() {
f(); //
}
};
return {
a: a,
link: function() {
f(); //
}
}
After:
return {
link: function() {
f(); //
}
};
return {
a: a,
link: function() {
f(); //
}
};
llvm-svn: 210537
Diffstat (limited to 'clang/lib/Format/TokenAnnotator.cpp')
| -rw-r--r-- | clang/lib/Format/TokenAnnotator.cpp | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index 516aaebe6a2..66060f0b834 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -314,8 +314,11 @@ private: return false; updateParameterCount(Left, CurrentToken); if (CurrentToken->is(tok::colon) && - Style.Language != FormatStyle::LK_Proto) + Style.Language != FormatStyle::LK_Proto) { + if (CurrentToken->getPreviousNonComment()->is(tok::identifier)) + CurrentToken->getPreviousNonComment()->Type = TT_SelectorName; Left->Type = TT_DictLiteral; + } if (!consumeToken()) return false; } @@ -389,7 +392,7 @@ private: } else if (Contexts.back().ColonIsObjCMethodExpr || Line.First->Type == TT_ObjCMethodSpecifier) { Tok->Type = TT_ObjCMethodExpr; - Tok->Previous->Type = TT_ObjCSelectorName; + Tok->Previous->Type = TT_SelectorName; if (Tok->Previous->ColumnWidth > Contexts.back().LongestObjCSelectorName) { Contexts.back().LongestObjCSelectorName = Tok->Previous->ColumnWidth; @@ -1006,7 +1009,8 @@ public: // expression. while (Current && (Current->is(tok::kw_return) || - (Current->is(tok::colon) && Current->Type == TT_ObjCMethodExpr))) + (Current->is(tok::colon) && (Current->Type == TT_ObjCMethodExpr || + Current->Type == TT_DictLiteral)))) next(); if (!Current || Precedence > PrecedenceArrowAndPeriod) @@ -1035,7 +1039,7 @@ public: int CurrentPrecedence = getCurrentPrecedence(); - if (Current && Current->Type == TT_ObjCSelectorName && + if (Current && Current->Type == TT_SelectorName && Precedence == CurrentPrecedence) { if (LatestOperator) addFakeParenthesis(Start, prec::Level(Precedence)); @@ -1086,7 +1090,7 @@ private: if (Current->Type == TT_ConditionalExpr) return prec::Conditional; else if (Current->is(tok::semi) || Current->Type == TT_InlineASMColon || - Current->Type == TT_ObjCSelectorName) + Current->Type == TT_SelectorName) return 0; else if (Current->Type == TT_RangeBasedForLoopColon) return prec::Comma; @@ -1358,7 +1362,7 @@ unsigned TokenAnnotator::splitPenalty(const AnnotatedLine &Line, // In Objective-C method expressions, prefer breaking before "param:" over // breaking after it. - if (Right.Type == TT_ObjCSelectorName) + if (Right.Type == TT_SelectorName) return 0; if (Left.is(tok::colon) && Left.Type == TT_ObjCMethodExpr) return Line.MightBeFunctionDecl ? 50 : 500; @@ -1684,7 +1688,7 @@ bool TokenAnnotator::canBreakBefore(const AnnotatedLine &Line, if (Left.is(tok::colon) && (Left.Type == TT_DictLiteral || Left.Type == TT_ObjCMethodExpr)) return true; - if (Right.Type == TT_ObjCSelectorName) + if (Right.Type == TT_SelectorName) return true; if (Left.is(tok::r_paren) && Line.Type == LT_ObjCProperty) return true; @@ -1767,6 +1771,7 @@ void TokenAnnotator::printDebugInfo(const AnnotatedLine &Line) { llvm::errs() << " M=" << Tok->MustBreakBefore << " C=" << Tok->CanBreakBefore << " T=" << Tok->Type << " S=" << Tok->SpacesRequiredBefore + << " B=" << Tok->BlockParameterCount << " P=" << Tok->SplitPenalty << " Name=" << Tok->Tok.getName() << " L=" << Tok->TotalLength << " PPK=" << Tok->PackingKind << " FakeLParens="; |

