[cfe-commits] r171388 - in /cfe/trunk: lib/Format/Format.cpp test/Index/comment-to-html-xml-conversion.cpp unittests/Format/FormatTest.cpp
Daniel Jasper
djasper at google.com
Wed Jan 2 07:08:59 PST 2013
Author: djasper
Date: Wed Jan 2 09:08:56 2013
New Revision: 171388
URL: http://llvm.org/viewvc/llvm-project?rev=171388&view=rev
Log:
Prefer splitting after "template <...>" and fix indentation.
This addresses llvm.org/PR14699
Before:
template <typename T>
void looooooooooooooooooooooongFunction(int Param1, int Param2);
template <typename T> void looooooooooooooooooooongFunction(
int Paaaaaaaaaaaaaaaaaaaaram1, int Paaaaaaaaaaaaaaaaaaaaram2);
After:
template <typename T>
void looooooooooooooooooooooongFunction(int Param1, int Param2);
template <typename T>
void looooooooooooooooooooongFunction(int Paaaaaaaaaaaaaaaaaaaaram1,
int Paaaaaaaaaaaaaaaaaaaaram2);
Modified:
cfe/trunk/lib/Format/Format.cpp
cfe/trunk/test/Index/comment-to-html-xml-conversion.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=171388&r1=171387&r2=171388&view=diff
==============================================================================
--- cfe/trunk/lib/Format/Format.cpp (original)
+++ cfe/trunk/lib/Format/Format.cpp Wed Jan 2 09:08:56 2013
@@ -50,6 +50,8 @@
bool SpaceRequiredBefore;
bool CanBreakBefore;
bool MustBreakBefore;
+
+ bool ClosesTemplateDeclaration;
};
static prec::Level getPrecedence(const FormatToken &Tok) {
@@ -250,6 +252,8 @@
} else if (
Line.Tokens[0].Tok.is(tok::kw_for) && Previous.Tok.is(tok::comma)) {
State.Column = State.ForLoopVariablePos;
+ } else if (Annotations[Index - 1].ClosesTemplateDeclaration) {
+ State.Column = State.Indent[ParenLevel] - 4;
} else {
State.Column = State.Indent[ParenLevel];
}
@@ -342,7 +346,8 @@
(Left.Tok.isNot(tok::comma) && Left.Tok.isNot(tok::semi)))
return 20;
- if (Left.Tok.is(tok::semi) || Left.Tok.is(tok::comma))
+ if (Left.Tok.is(tok::semi) || Left.Tok.is(tok::comma) ||
+ Annotations[Index].ClosesTemplateDeclaration)
return 0;
if (Left.Tok.is(tok::l_paren))
return 20;
@@ -549,6 +554,19 @@
return false;
}
+ bool parseTemplateDeclaration() {
+ if (Index < Tokens.size() && Tokens[Index].Tok.is(tok::less)) {
+ Annotations[Index].Type = TokenAnnotation::TT_TemplateOpener;
+ next();
+ if (!parseAngle())
+ return false;
+ Annotations[Index - 1].ClosesTemplateDeclaration = true;
+ parseLine();
+ return true;
+ }
+ return false;
+ }
+
void consumeToken() {
unsigned CurrentIndex = Index;
next();
@@ -592,6 +610,9 @@
case tok::question:
parseConditional();
break;
+ case tok::kw_template:
+ parseTemplateDeclaration();
+ break;
default:
break;
}
Modified: cfe/trunk/test/Index/comment-to-html-xml-conversion.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/comment-to-html-xml-conversion.cpp?rev=171388&r1=171387&r2=171388&view=diff
==============================================================================
--- cfe/trunk/test/Index/comment-to-html-xml-conversion.cpp (original)
+++ cfe/trunk/test/Index/comment-to-html-xml-conversion.cpp Wed Jan 2 09:08:56 2013
@@ -670,7 +670,7 @@
template<typename T, typename U>
class comment_to_xml_conversion_11 { };
-// CHECK: comment-to-html-xml-conversion.cpp:[[@LINE-2]]:7: ClassTemplate=comment_to_xml_conversion_11:{{.*}} FullCommentAsXML=[<Class templateKind="template" file="{{[^"]+}}comment-to-html-xml-conversion.cpp" line="[[@LINE-2]]" column="7"><Name>comment_to_xml_conversion_11</Name><USR>c:@CT>2#T#T at comment_to_xml_conversion_11</USR><Declaration>template <typename T = int, typename U = int>\n class comment_to_xml_conversion_11 {\n}\ntemplate <typename T, typename U> class comment_to_xml_conversion_11 {\n}</Declaration><Abstract><Para> Aaa.</Para></Abstract></Class>]
+// CHECK: comment-to-html-xml-conversion.cpp:[[@LINE-2]]:7: ClassTemplate=comment_to_xml_conversion_11:{{.*}} FullCommentAsXML=[<Class templateKind="template" file="{{[^"]+}}comment-to-html-xml-conversion.cpp" line="[[@LINE-2]]" column="7"><Name>comment_to_xml_conversion_11</Name><USR>c:@CT>2#T#T at comment_to_xml_conversion_11</USR><Declaration>template <typename T = int, typename U = int>\nclass comment_to_xml_conversion_11 {\n}\ntemplate <typename T, typename U> class comment_to_xml_conversion_11 {\n}</Declaration><Abstract><Para> Aaa.</Para></Abstract></Class>]
/// Aaa.
template<typename T>
Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=171388&r1=171387&r2=171388&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Wed Jan 2 09:08:56 2013
@@ -594,6 +594,19 @@
"}");
}
+TEST_F(FormatTest, WrapsTemplateDeclarations) {
+ verifyFormat("template <typename T>\n"
+ "virtual void loooooooooooongFunction(int Param1, int Param2);");
+ verifyFormat(
+ "template <typename T> void f(int Paaaaaaaaaaaaaaaaaaaaaaaaaaaaaaram1,\n"
+ " int Paaaaaaaaaaaaaaaaaaaaaaaaaaaaaaram2);");
+ verifyFormat(
+ "template <typename T>\n"
+ "void looooooooooooooooooooongFunction(int Paaaaaaaaaaaaaaaaaaaaram1,\n"
+ " int Paaaaaaaaaaaaaaaaaaaaram2);");
+
+}
+
TEST_F(FormatTest, UnderstandsTemplateParameters) {
verifyFormat("A<int> a;");
verifyFormat("A<A<A<int> > > a;");
More information about the cfe-commits
mailing list