[PATCH] Support for pointers-to-members usage via .*
Alexander Kornienko
alexfh at google.com
Wed Mar 20 08:46:34 PDT 2013
Hi djasper,
Added support for pointers-to-members usage via .* and a few tests.
http://llvm-reviews.chandlerc.com/D556
Files:
lib/Format/TokenAnnotator.cpp
unittests/Format/FormatTest.cpp
Index: lib/Format/TokenAnnotator.cpp
===================================================================
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -1058,7 +1058,8 @@
if (Tok.is(tok::l_paren) && !Tok.Children.empty() &&
Tok.Children[0].Type == TT_PointerOrReference &&
!Tok.Children[0].Children.empty() &&
- Tok.Children[0].Children[0].isNot(tok::r_paren))
+ Tok.Children[0].Children[0].isNot(tok::r_paren) &&
+ Tok.Parent->isNot(tok::l_paren))
return true;
if (Tok.Parent->Type == TT_UnaryOperator || Tok.Parent->Type == TT_CastRParen)
return false;
@@ -1071,7 +1072,8 @@
Tok.Parent->Type == TT_TemplateCloser &&
Style.Standard != FormatStyle::LS_Cpp11;
}
- if (Tok.is(tok::arrowstar) || Tok.Parent->is(tok::arrowstar))
+ if (Tok.isOneOf(tok::arrowstar, tok::periodstar) ||
+ Tok.Parent->isOneOf(tok::arrowstar, tok::periodstar))
return false;
if (Tok.Type == TT_BinaryOperator || Tok.Parent->Type == TT_BinaryOperator)
return true;
Index: unittests/Format/FormatTest.cpp
===================================================================
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -2000,7 +2000,18 @@
TEST_F(FormatTest, UnderstandsBinaryOperators) {
verifyFormat("COMPARE(a, ==, b);");
- verifyFormat("(a->*f)()");
+}
+
+TEST_F(FormatTest, UnderstandsPointersToMembers) {
+ verifyFormat("int A::*x;");
+ // FIXME: Recognize pointers to member functions.
+ //verifyFormat("int (S::*func)(void *);");
+ verifyFormat("int(S::*func)(void *);");
+ verifyFormat("(a->*f)();");
+ verifyFormat("a->*x;");
+ verifyFormat("(a.*f)();");
+ verifyFormat("((*a).*f)();");
+ verifyFormat("a.*x;");
}
TEST_F(FormatTest, UnderstandsUnaryOperators) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D556.1.patch
Type: text/x-patch
Size: 1808 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20130320/a1e7c298/attachment.bin>
More information about the cfe-commits
mailing list