summaryrefslogtreecommitdiffstats
path: root/clang/lib/Format/TokenAnnotator.cpp
diff options
context:
space:
mode:
authorNico Weber <nicolasweber@gmx.de>2013-02-06 16:54:35 +0000
committerNico Weber <nicolasweber@gmx.de>2013-02-06 16:54:35 +0000
commitac9bde236f4eced309712829b6009f902f8de20e (patch)
tree5b0e25da99d7596ef9b132eb2806a94b925ad3dd /clang/lib/Format/TokenAnnotator.cpp
parenteed92fb10c39e9af2413d25d7d32ad8c086aba02 (diff)
downloadbcm5719-llvm-ac9bde236f4eced309712829b6009f902f8de20e.tar.gz
bcm5719-llvm-ac9bde236f4eced309712829b6009f902f8de20e.zip
Formatter: Correctly detect ObjC message expressions preceded by a comment.
llvm-svn: 174521
Diffstat (limited to 'clang/lib/Format/TokenAnnotator.cpp')
-rw-r--r--clang/lib/Format/TokenAnnotator.cpp25
1 files changed, 14 insertions, 11 deletions
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp
index 12e7eac80ed..9c7834f5640 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -42,12 +42,15 @@ static bool isBinaryOperator(const AnnotatedToken &Tok) {
}
// Returns the previous token ignoring comments.
-static const AnnotatedToken *getPreviousToken(const AnnotatedToken &Tok) {
- const AnnotatedToken *PrevToken = Tok.Parent;
+static AnnotatedToken *getPreviousToken(AnnotatedToken &Tok) {
+ AnnotatedToken *PrevToken = Tok.Parent;
while (PrevToken != NULL && PrevToken->is(tok::comment))
PrevToken = PrevToken->Parent;
return PrevToken;
}
+static const AnnotatedToken *getPreviousToken(const AnnotatedToken &Tok) {
+ return getPreviousToken(const_cast<AnnotatedToken &>(Tok));
+}
// Returns the next token ignoring comments.
static const AnnotatedToken *getNextToken(const AnnotatedToken &Tok) {
@@ -181,12 +184,12 @@ public:
// ')' or ']'), or it could be the start of an Objective-C method
// expression.
AnnotatedToken *Left = CurrentToken->Parent;
+ AnnotatedToken *Parent = getPreviousToken(*Left);
bool StartsObjCMethodExpr =
- !Left->Parent || Left->Parent->is(tok::colon) ||
- Left->Parent->is(tok::l_square) || Left->Parent->is(tok::l_paren) ||
- Left->Parent->is(tok::kw_return) || Left->Parent->is(tok::kw_throw) ||
- isUnaryOperator(*Left->Parent) ||
- getBinOpPrecedence(Left->Parent->FormatTok.Tok.getKind(), true, true) >
+ !Parent || Parent->is(tok::colon) || Parent->is(tok::l_square) ||
+ Parent->is(tok::l_paren) || Parent->is(tok::kw_return) ||
+ Parent->is(tok::kw_throw) || isUnaryOperator(*Parent) ||
+ getBinOpPrecedence(Parent->FormatTok.Tok.getKind(), true, true) >
prec::Unknown;
if (StartsObjCMethodExpr) {
@@ -208,10 +211,10 @@ public:
// determineStarAmpUsage() thinks that '*' '[' is allocating an
// array of pointers, but if '[' starts a selector then '*' is a
// binary operator.
- if (Left->Parent != NULL &&
- (Left->Parent->is(tok::star) || Left->Parent->is(tok::amp)) &&
- Left->Parent->Type == TT_PointerOrReference)
- Left->Parent->Type = TT_BinaryOperator;
+ if (Parent != NULL &&
+ (Parent->is(tok::star) || Parent->is(tok::amp)) &&
+ Parent->Type == TT_PointerOrReference)
+ Parent->Type = TT_BinaryOperator;
}
Left->MatchingParen = CurrentToken;
CurrentToken->MatchingParen = Left;
OpenPOWER on IntegriCloud