]> granicus.if.org Git - clang/commitdiff
Don't put spaces around hyphens in include paths.
authorDaniel Jasper <djasper@google.com>
Sun, 13 Jan 2013 08:12:18 +0000 (08:12 +0000)
committerDaniel Jasper <djasper@google.com>
Sun, 13 Jan 2013 08:12:18 +0000 (08:12 +0000)
Before: #include <a - a>
After:  #include <a-a>

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

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

index 5de171791187a95dc4f5c2a01fa508e0704bf5e7..64a6224b0b9f4cad40d10c1452fc0aca28844dc0 100644 (file)
@@ -34,7 +34,7 @@ enum TokenType {
   TT_CastRParen,
   TT_ConditionalExpr,
   TT_CtorInitializerColon,
-  TT_DirectorySeparator,
+  TT_IncludePath,
   TT_LineComment,
   TT_ObjCBlockLParen,
   TT_ObjCDecl,
@@ -834,12 +834,7 @@ public:
 
     void parseIncludeDirective() {
       while (CurrentToken != NULL) {
-        if (CurrentToken->is(tok::slash))
-          CurrentToken->Type = TT_DirectorySeparator;
-        else if (CurrentToken->is(tok::less))
-          CurrentToken->Type = TT_TemplateOpener;
-        else if (CurrentToken->is(tok::greater))
-          CurrentToken->Type = TT_TemplateCloser;
+        CurrentToken->Type = TT_IncludePath;
         next();
       }
     }
@@ -1154,6 +1149,8 @@ private:
         (Tok.is(tok::equal) || Tok.Parent->is(tok::equal)))
       return false;
 
+    if (Tok.Type == TT_IncludePath)
+      return Tok.is(tok::less) || Tok.is(tok::string_literal);
     if (Tok.Type == TT_CtorInitializerColon || Tok.Type == TT_ObjCBlockLParen)
       return true;
     if (Tok.Type == TT_OverloadedOperator)
@@ -1176,9 +1173,6 @@ private:
       return Tok.Type == TT_TemplateCloser && Tok.Parent->Type ==
              TT_TemplateCloser && Style.SplitTemplateClosingGreater;
     }
-    if (Tok.Type == TT_DirectorySeparator ||
-        Tok.Parent->Type == TT_DirectorySeparator)
-      return false;
     if (Tok.Type == TT_BinaryOperator || Tok.Parent->Type == TT_BinaryOperator)
       return true;
     if (Tok.Parent->Type == TT_TemplateCloser && Tok.is(tok::l_paren))
@@ -1206,6 +1200,8 @@ private:
         // Don't break at ':' if identifier before it can beak.
         return false;
     }
+    if (Right.Type == TT_IncludePath)
+      return false;
     if (Right.is(tok::colon) && Right.Type == TT_ObjCMethodExpr)
       return false;
     if (Left.is(tok::colon) && Left.Type == TT_ObjCMethodExpr)
index 765d16f99ae710b8cc863487f9bd866ceccc5a16..984732571e07a96dc5b321eaa97703319c8b3d6f 100644 (file)
@@ -1102,17 +1102,18 @@ TEST_F(FormatTest, LineStartsWithSpecialCharacter) {
 }
 
 TEST_F(FormatTest, HandlesIncludeDirectives) {
-  EXPECT_EQ("#include <string>\n", format("#include <string>\n"));
-  EXPECT_EQ("#include <a/b/c.h>\n", format("#include <a/b/c.h>\n"));
-  EXPECT_EQ("#include \"a/b/string\"\n", format("#include \"a/b/string\"\n"));
-  EXPECT_EQ("#include \"string.h\"\n", format("#include \"string.h\"\n"));
-  EXPECT_EQ("#include \"string.h\"\n", format("#include \"string.h\"\n"));
-
-  EXPECT_EQ("#import <string>\n", format("#import <string>\n"));
-  EXPECT_EQ("#import <a/b/c.h>\n", format("#import <a/b/c.h>\n"));
-  EXPECT_EQ("#import \"a/b/string\"\n", format("#import \"a/b/string\"\n"));
-  EXPECT_EQ("#import \"string.h\"\n", format("#import \"string.h\"\n"));
-  EXPECT_EQ("#import \"string.h\"\n", format("#import \"string.h\"\n"));
+  verifyFormat("#include <string>");
+  verifyFormat("#include <a/b/c.h>");
+  verifyFormat("#include \"a/b/string\"");
+  verifyFormat("#include \"string.h\"");
+  verifyFormat("#include \"string.h\"");
+  verifyFormat("#include <a-a>");
+
+  verifyFormat("#import <string>");
+  verifyFormat("#import <a/b/c.h>");
+  verifyFormat("#import \"a/b/string\"");
+  verifyFormat("#import \"string.h\"");
+  verifyFormat("#import \"string.h\"");
 }
 
 //===----------------------------------------------------------------------===//