diff options
author | Manuel Klimek <klimek@google.com> | 2013-01-23 09:32:48 +0000 |
---|---|---|
committer | Manuel Klimek <klimek@google.com> | 2013-01-23 09:32:48 +0000 |
commit | 70b03f4edaefcc5b9aa2e084d1c12e9d91b32a77 (patch) | |
tree | e43b61232306a4d0ea1fee82dc51eab210a1710e /lib/Format/Format.cpp | |
parent | 69652660e765ec2bbcf1877ac05c66e91b8fa745 (diff) |
Allow us to better guess the context of an unwrapped line.
This gives us the ability to guess better defaults for whether a *
between identifiers is a pointer dereference or binary operator.
Now correctly formats:
void f(a *b);
void f() { f(a * b); }
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@173243 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Format/Format.cpp')
-rw-r--r-- | lib/Format/Format.cpp | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/lib/Format/Format.cpp b/lib/Format/Format.cpp index 1405fc23e1..391528a031 100644 --- a/lib/Format/Format.cpp +++ b/lib/Format/Format.cpp @@ -112,7 +112,8 @@ class AnnotatedLine { public: AnnotatedLine(const UnwrappedLine &Line) : First(Line.Tokens.front()), Level(Line.Level), - InPPDirective(Line.InPPDirective) { + InPPDirective(Line.InPPDirective), + MustBeDeclaration(Line.MustBeDeclaration) { assert(!Line.Tokens.empty()); AnnotatedToken *Current = &First; for (std::list<FormatToken>::const_iterator I = ++Line.Tokens.begin(), @@ -126,7 +127,8 @@ public: } AnnotatedLine(const AnnotatedLine &Other) : First(Other.First), Type(Other.Type), Level(Other.Level), - InPPDirective(Other.InPPDirective) { + InPPDirective(Other.InPPDirective), + MustBeDeclaration(Other.MustBeDeclaration) { Last = &First; while (!Last->Children.empty()) { Last->Children[0].Parent = Last; @@ -140,6 +142,7 @@ public: LineType Type; unsigned Level; bool InPPDirective; + bool MustBeDeclaration; }; static prec::Level getPrecedence(const AnnotatedToken &Tok) { @@ -1368,7 +1371,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 (IsRHS || !Line.MustBeDeclaration) return TT_BinaryOperator; return TT_PointerOrReference; |