[cfe-commits] r172350 - in /cfe/trunk: lib/Format/Format.cpp unittests/Format/FormatTest.cpp
Daniel Jasper
djasper at google.com
Sun Jan 13 00:12:19 PST 2013
Author: djasper
Date: Sun Jan 13 02:12:18 2013
New Revision: 172350
URL: http://llvm.org/viewvc/llvm-project?rev=172350&view=rev
Log:
Don't put spaces around hyphens in include paths.
Before: #include <a - a>
After: #include <a-a>
Modified:
cfe/trunk/lib/Format/Format.cpp
cfe/trunk/unittests/Format/FormatTest.cpp
Modified: cfe/trunk/lib/Format/Format.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/Format.cpp?rev=172350&r1=172349&r2=172350&view=diff
==============================================================================
--- cfe/trunk/lib/Format/Format.cpp (original)
+++ cfe/trunk/lib/Format/Format.cpp Sun Jan 13 02:12:18 2013
@@ -34,7 +34,7 @@
TT_CastRParen,
TT_ConditionalExpr,
TT_CtorInitializerColon,
- TT_DirectorySeparator,
+ TT_IncludePath,
TT_LineComment,
TT_ObjCBlockLParen,
TT_ObjCDecl,
@@ -834,12 +834,7 @@
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 @@
(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 @@
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 @@
// 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)
Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=172350&r1=172349&r2=172350&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Sun Jan 13 02:12:18 2013
@@ -1102,17 +1102,18 @@
}
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\"");
}
//===----------------------------------------------------------------------===//
More information about the cfe-commits
mailing list