From: Daniel Jasper Date: Sun, 13 Jan 2013 08:12:18 +0000 (+0000) Subject: Don't put spaces around hyphens in include paths. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8134e1e575f862799c361b9c146eae7672010fa0;p=clang Don't put spaces around hyphens in include paths. Before: #include After: #include git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172350 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Format/Format.cpp b/lib/Format/Format.cpp index 5de1717911..64a6224b0b 100644 --- a/lib/Format/Format.cpp +++ b/lib/Format/Format.cpp @@ -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) diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index 765d16f99a..984732571e 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -1102,17 +1102,18 @@ TEST_F(FormatTest, LineStartsWithSpecialCharacter) { } TEST_F(FormatTest, HandlesIncludeDirectives) { - EXPECT_EQ("#include \n", format("#include \n")); - EXPECT_EQ("#include \n", format("#include \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 \n", format("#import \n")); - EXPECT_EQ("#import \n", format("#import \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 "); + verifyFormat("#include "); + verifyFormat("#include \"a/b/string\""); + verifyFormat("#include \"string.h\""); + verifyFormat("#include \"string.h\""); + verifyFormat("#include "); + + verifyFormat("#import "); + verifyFormat("#import "); + verifyFormat("#import \"a/b/string\""); + verifyFormat("#import \"string.h\""); + verifyFormat("#import \"string.h\""); } //===----------------------------------------------------------------------===//