aboutsummaryrefslogtreecommitdiff
path: root/lib/Format/Format.cpp
diff options
context:
space:
mode:
authorNico Weber <nicolasweber@gmx.de>2012-12-23 01:07:46 +0000
committerNico Weber <nicolasweber@gmx.de>2012-12-23 01:07:46 +0000
commit00d5a04dc0eaa0f067656033ab81fc352c5a991a (patch)
tree09f5a5d177cc70be2571cae091dea43413c097ab /lib/Format/Format.cpp
parente6bb76cde5488eca94e087e8929f29f3f3debfd3 (diff)
libFormat: Teach the *& usage heuristic that "return" starts a rhs too.
"return a*b;" was formatted as "return a *b;" and is now formatted as "return a * b;". Fixes PR14687 partially. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@170993 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Format/Format.cpp')
-rw-r--r--lib/Format/Format.cpp13
1 files changed, 8 insertions, 5 deletions
diff --git a/lib/Format/Format.cpp b/lib/Format/Format.cpp
index bb18e9a851..2a8fbd6e5e 100644
--- a/lib/Format/Format.cpp
+++ b/lib/Format/Format.cpp
@@ -716,19 +716,21 @@ public:
private:
void determineTokenTypes() {
- bool AssignmentEncountered = false;
+ bool IsRHS = false;
for (int i = 0, e = Line.Tokens.size(); i != e; ++i) {
TokenAnnotation &Annotation = Annotations[i];
const FormatToken &Tok = Line.Tokens[i];
if (getBinOpPrecedence(Tok.Tok.getKind(), true, true) == prec::Assignment)
- AssignmentEncountered = true;
+ IsRHS = true;
+ else if (Tok.Tok.is(tok::kw_return))
+ IsRHS = true;
if (Annotation.Type != TokenAnnotation::TT_Unknown)
continue;
if (Tok.Tok.is(tok::star) || Tok.Tok.is(tok::amp)) {
- Annotation.Type = determineStarAmpUsage(i, AssignmentEncountered);
+ Annotation.Type = determineStarAmpUsage(i, IsRHS);
} else if (Tok.Tok.is(tok::minus) || Tok.Tok.is(tok::plus)) {
Annotation.Type = determinePlusMinusUsage(i);
} else if (Tok.Tok.is(tok::minusminus) || Tok.Tok.is(tok::plusplus)) {
@@ -754,12 +756,13 @@ private:
}
TokenAnnotation::TokenType determineStarAmpUsage(unsigned Index,
- bool AssignmentEncountered) {
+ bool IsRHS) {
if (Index == Annotations.size())
return TokenAnnotation::TT_Unknown;
if (Index == 0 || Line.Tokens[Index - 1].Tok.is(tok::l_paren) ||
Line.Tokens[Index - 1].Tok.is(tok::comma) ||
+ Line.Tokens[Index - 1].Tok.is(tok::kw_return) ||
Annotations[Index - 1].Type == TokenAnnotation::TT_BinaryOperator)
return TokenAnnotation::TT_UnaryOperator;
@@ -770,7 +773,7 @@ private:
// It is very unlikely that we are going to find a pointer or reference type
// definition on the RHS of an assignment.
- if (AssignmentEncountered)
+ if (IsRHS)
return TokenAnnotation::TT_BinaryOperator;
return TokenAnnotation::TT_PointerOrReference;