]> granicus.if.org Git - clang/commitdiff
Formatter: Refactor the cast detection code to be a bit more readable.
authorNico Weber <nicolasweber@gmx.de>
Wed, 13 Feb 2013 04:13:13 +0000 (04:13 +0000)
committerNico Weber <nicolasweber@gmx.de>
Wed, 13 Feb 2013 04:13:13 +0000 (04:13 +0000)
No functionality change. Also add another cast test.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@175029 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Format/TokenAnnotator.cpp
unittests/Format/FormatTest.cpp

index ececc7c98a008ace84c0ec5434b55d3f9942d6e3..d2e19af56f13b736963373b39db8a27f5c4934e0 100644 (file)
@@ -578,15 +578,16 @@ 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) &&
-                 (Current.Children.empty() ||
-                  (Current.Children[0].isNot(tok::equal) &&
-                   Current.Children[0].isNot(tok::semi) &&
-                   Current.Children[0].isNot(tok::l_brace)))) {
-        // FIXME: We need to get smarter and understand more cases of casts.
-        Current.Type = TT_CastRParen;
+      } else if (Current.is(tok::r_paren)) {
+        bool ParensNotExpr = Current.Parent->Type == TT_PointerOrReference ||
+                             Current.Parent->Type == TT_TemplateCloser;
+        bool ParensCouldEndDecl =
+            !Current.Children.empty() && (Current.Children[0].is(tok::equal) ||
+                                          Current.Children[0].is(tok::semi) ||
+                                          Current.Children[0].is(tok::l_brace));
+        if (ParensNotExpr && !ParensCouldEndDecl)
+          // FIXME: We need to get smarter and understand more cases of casts.
+          Current.Type = TT_CastRParen;
       } else if (Current.is(tok::at) && Current.Children.size()) {
         switch (Current.Children[0].FormatTok.Tok.getObjCKeywordID()) {
         case tok::objc_interface:
index f2ccdb002250f77da36ca85edcf72f47c3b2e135..a91d325b51094a53079005acf9a7e6f6b40028a5 100644 (file)
@@ -1723,6 +1723,7 @@ TEST_F(FormatTest, FormatsCasts) {
 
   // These are not casts.
   verifyFormat("void f(int *) {}");
+  verifyFormat("f(foo)[4];");
   verifyFormat("void f(int *);");
   verifyFormat("void f(int *) = 0;");
   verifyFormat("void f(SmallVector<int>) {}");