summaryrefslogtreecommitdiffstats
path: root/clang/lib
diff options
context:
space:
mode:
authorDaniel Jasper <djasper@google.com>2013-01-10 11:14:08 +0000
committerDaniel Jasper <djasper@google.com>2013-01-10 11:14:08 +0000
commit7194e1818eb6ac99d988a97e7f80e41ec34f500b (patch)
treeffdb57987411ea23ecbc4b955db476d66448d5a3 /clang/lib
parentab111fa51174f94cf063f58767666cdced09dc82 (diff)
downloadbcm5719-llvm-7194e1818eb6ac99d988a97e7f80e41ec34f500b.tar.gz
bcm5719-llvm-7194e1818eb6ac99d988a97e7f80e41ec34f500b.zip
Improve clang-format's understanding of casts.
This fixes llvm.org/PR14684. Before: int *pa = (int *) & a; After: int *pa = (int *)&a; We still don't understand all kinds of casts. I added a FIXME to address that. llvm-svn: 172056
Diffstat (limited to 'clang/lib')
-rw-r--r--clang/lib/Format/Format.cpp32
1 files changed, 20 insertions, 12 deletions
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index 4de26e2b4ef..dfb43afafa1 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -27,21 +27,22 @@ namespace clang {
namespace format {
enum TokenType {
- TT_Unknown,
- TT_TemplateOpener,
- TT_TemplateCloser,
TT_BinaryOperator,
- TT_UnaryOperator,
- TT_TrailingUnaryOperator,
- TT_OverloadedOperator,
- TT_PointerOrReference,
+ TT_BlockComment,
+ TT_CastRParen,
TT_ConditionalExpr,
TT_CtorInitializerColon,
- TT_LineComment,
- TT_BlockComment,
TT_DirectorySeparator,
+ TT_LineComment,
+ TT_ObjCMethodSpecifier,
+ TT_OverloadedOperator,
+ TT_PointerOrReference,
TT_PureVirtualSpecifier,
- TT_ObjCMethodSpecifier
+ TT_TemplateCloser,
+ TT_TemplateOpener,
+ TT_TrailingUnaryOperator,
+ TT_UnaryOperator,
+ TT_Unknown
};
enum LineType {
@@ -897,6 +898,11 @@ private:
Current.Type = TT_LineComment;
else
Current.Type = TT_BlockComment;
+ } else if (Current.is(tok::r_paren) &&
+ (Current.Parent->Type == TT_PointerOrReference ||
+ Current.Parent->Type == TT_TemplateCloser)) {
+ // FIXME: We need to get smarter and understand more cases of casts.
+ Current.Type = TT_CastRParen;
}
}
@@ -919,7 +925,8 @@ private:
if (PrevToken.Tok.is(tok::l_paren) || PrevToken.Tok.is(tok::l_square) ||
PrevToken.Tok.is(tok::comma) || PrevToken.Tok.is(tok::kw_return) ||
- PrevToken.Tok.is(tok::colon) || Tok.Parent->Type == TT_BinaryOperator)
+ PrevToken.Tok.is(tok::colon) || Tok.Parent->Type == TT_BinaryOperator ||
+ Tok.Parent->Type == TT_CastRParen)
return TT_UnaryOperator;
if (PrevToken.Tok.isLiteral() || NextToken.Tok.isLiteral() ||
@@ -1050,7 +1057,8 @@ private:
return false;
if (Tok.is(tok::colon))
return RootToken.isNot(tok::kw_case) && (!Tok.Children.empty());
- if (Tok.Parent->Type == TT_UnaryOperator)
+ if (Tok.Parent->Type == TT_UnaryOperator ||
+ Tok.Parent->Type == TT_CastRParen)
return false;
if (Tok.Type == TT_UnaryOperator)
return Tok.Parent->isNot(tok::l_paren) &&
OpenPOWER on IntegriCloud