diff options
author | Daniel Jasper <djasper@google.com> | 2013-01-23 12:10:53 +0000 |
---|---|---|
committer | Daniel Jasper <djasper@google.com> | 2013-01-23 12:10:53 +0000 |
commit | 5b49f47835e89ffc6dbf8468322febe66ebb6ecf (patch) | |
tree | 10f354391e789dadb90c58c1607ef3b81d3d3683 /clang/lib/Format | |
parent | 228921d71e253a5bf65593020d52b588674f3510 (diff) | |
download | bcm5719-llvm-5b49f47835e89ffc6dbf8468322febe66ebb6ecf.tar.gz bcm5719-llvm-5b49f47835e89ffc6dbf8468322febe66ebb6ecf.zip |
Fix another regression for pointer types.
Before: if (int * a = &b) ...
After: if (int *a = &b) ...
Also changed all the existing tests to test the expressions in question
both in a declaration and in an expression context.
llvm-svn: 173256
Diffstat (limited to 'clang/lib/Format')
-rw-r--r-- | clang/lib/Format/Format.cpp | 30 |
1 files changed, 19 insertions, 11 deletions
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp index 36bf53d9a7a..2d9bd2cc061 100644 --- a/clang/lib/Format/Format.cpp +++ b/clang/lib/Format/Format.cpp @@ -1237,7 +1237,7 @@ public: if (Line.Type == LT_Invalid) return; - determineTokenTypes(Line.First, /*IsRHS=*/false); + determineTokenTypes(Line.First, /*IsExpression=*/ false); if (Line.First.Type == TT_ObjCMethodSpecifier) Line.Type = LT_ObjCMethodDecl; @@ -1256,16 +1256,23 @@ public: } private: - void determineTokenTypes(AnnotatedToken &Current, bool IsRHS) { - if (getPrecedence(Current) == prec::Assignment || - Current.is(tok::kw_return) || Current.is(tok::kw_throw)) - IsRHS = true; - if (Current.is(tok::l_paren) && !Line.MustBeDeclaration) - IsRHS = true; + void determineTokenTypes(AnnotatedToken &Current, bool IsExpression) { + if (getPrecedence(Current) == prec::Assignment) { + IsExpression = true; + AnnotatedToken *Previous = Current.Parent; + while (Previous != NULL) { + if (Previous->Type == TT_BinaryOperator) + Previous->Type = TT_PointerOrReference; + Previous = Previous->Parent; + } + } + if (Current.is(tok::kw_return) || Current.is(tok::kw_throw) || + (Current.is(tok::l_paren) && !Line.MustBeDeclaration)) + IsExpression = true; if (Current.Type == TT_Unknown) { if (Current.is(tok::star) || Current.is(tok::amp)) { - Current.Type = determineStarAmpUsage(Current, IsRHS); + Current.Type = determineStarAmpUsage(Current, IsExpression); } else if (Current.is(tok::minus) || Current.is(tok::plus) || Current.is(tok::caret)) { Current.Type = determinePlusMinusCaretUsage(Current); @@ -1308,7 +1315,7 @@ private: } if (!Current.Children.empty()) - determineTokenTypes(Current.Children[0], IsRHS); + determineTokenTypes(Current.Children[0], IsExpression); } bool isBinaryOperator(const AnnotatedToken &Tok) { @@ -1338,7 +1345,8 @@ private: } /// \brief Return the type of the given token assuming it is * or &. - TokenType determineStarAmpUsage(const AnnotatedToken &Tok, bool IsRHS) { + TokenType determineStarAmpUsage(const AnnotatedToken &Tok, + bool IsExpression) { const AnnotatedToken *PrevToken = getPreviousToken(Tok); if (PrevToken == NULL) return TT_UnaryOperator; @@ -1372,7 +1380,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 (IsRHS) + if (IsExpression) return TT_BinaryOperator; return TT_PointerOrReference; |