aboutsummaryrefslogtreecommitdiff
path: root/lib/Format/TokenAnnotator.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Format/TokenAnnotator.cpp')
-rw-r--r--lib/Format/TokenAnnotator.cpp35
1 files changed, 10 insertions, 25 deletions
diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp
index 833a0c062b..44421c4bbe 100644
--- a/lib/Format/TokenAnnotator.cpp
+++ b/lib/Format/TokenAnnotator.cpp
@@ -16,7 +16,6 @@
#include "TokenAnnotator.h"
#include "clang/Basic/SourceManager.h"
#include "clang/Lex/Lexer.h"
-#include "llvm/Support/Debug.h"
namespace clang {
namespace format {
@@ -783,9 +782,12 @@ public:
if (Precedence > prec::PointerToMember || Current == NULL)
return;
+ // Skip over "return" until we can properly parse it.
+ if (Current->is(tok::kw_return))
+ next();
+
// Eagerly consume trailing comments.
- while (Current && Current->FormatTok.NewlinesBefore == 0 &&
- isTrailingComment(Current)) {
+ while (isTrailingComment(Current)) {
next();
}
@@ -800,7 +802,8 @@ public:
if (Current) {
if (Current->Type == TT_ConditionalExpr)
CurrentPrecedence = 1 + (int) prec::Conditional;
- else if (Current->is(tok::semi) || Current->Type == TT_InlineASMColon)
+ else if (Current->is(tok::semi) || Current->Type == TT_InlineASMColon ||
+ Current->Type == TT_CtorInitializerColon)
CurrentPrecedence = 1;
else if (Current->Type == TT_BinaryOperator || Current->is(tok::comma))
CurrentPrecedence = 1 + (int) getPrecedence(*Current);
@@ -811,7 +814,7 @@ public:
if (Current == NULL || closesScope(*Current) ||
(CurrentPrecedence != 0 && CurrentPrecedence < Precedence)) {
if (OperatorFound) {
- Start->FakeLParens.push_back(Precedence);
+ ++Start->FakeLParens;
if (Current)
++Current->Parent->FakeRParens;
}
@@ -826,9 +829,9 @@ public:
parse();
}
// Remove fake parens that just duplicate the real parens.
- if (Current && !Left->Children[0].FakeLParens.empty() &&
+ if (Current && Left->Children[0].FakeLParens > 0 &&
Current->Parent->FakeRParens > 0) {
- Left->Children[0].FakeLParens.pop_back();
+ --Left->Children[0].FakeLParens;
--Current->Parent->FakeRParens;
}
next();
@@ -860,10 +863,6 @@ void TokenAnnotator::annotate(AnnotatedLine &Line) {
ExpressionParser ExprParser(Line);
ExprParser.parse();
- DEBUG({
- printDebugInfo(Line);
- });
-
if (Line.First.Type == TT_ObjCMethodSpecifier)
Line.Type = LT_ObjCMethodDecl;
else if (Line.First.Type == TT_ObjCDecl)
@@ -1188,19 +1187,5 @@ bool TokenAnnotator::canBreakBefore(const AnnotatedLine &Line,
(Left.is(tok::l_square) && !Right.is(tok::r_square));
}
-void TokenAnnotator::printDebugInfo(const AnnotatedLine &Line) {
- llvm::errs() << "AnnotatedTokens:\n";
- const AnnotatedToken *Tok = &Line.First;
- while (Tok) {
- llvm::errs() << Tok->FormatTok.Tok.getName() << ":"
- << " Type=" << Tok->Type << " FakeLParens=";
- for (unsigned i = 0, e = Tok->FakeLParens.size(); i != e; ++i)
- llvm::errs() << Tok->FakeLParens[i] << "/";
- llvm::errs() << " FakeRParens=" << Tok->FakeRParens << "\n";
- Tok = Tok->Children.empty() ? NULL : &Tok->Children[0];
- }
- llvm::errs() << "----\n";
-}
-
} // namespace format
} // namespace clang