aboutsummaryrefslogtreecommitdiff
path: root/lib/Format/Format.cpp
diff options
context:
space:
mode:
authorDaniel Jasper <djasper@google.com>2013-01-02 15:08:56 +0000
committerDaniel Jasper <djasper@google.com>2013-01-02 15:08:56 +0000
commit9a64fb5690ba2b53c761def068e20ec64c584d96 (patch)
tree4e473fceb6c223efd9f26835646d769093246e3b /lib/Format/Format.cpp
parent723f0304eaaf1aed20aece9021a1bb8578477e75 (diff)
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); git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@171388 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Format/Format.cpp')
-rw-r--r--lib/Format/Format.cpp23
1 files changed, 22 insertions, 1 deletions
diff --git a/lib/Format/Format.cpp b/lib/Format/Format.cpp
index 8f77c77a8e..d354078231 100644
--- a/lib/Format/Format.cpp
+++ b/lib/Format/Format.cpp
@@ -50,6 +50,8 @@ struct TokenAnnotation {
bool SpaceRequiredBefore;
bool CanBreakBefore;
bool MustBreakBefore;
+
+ bool ClosesTemplateDeclaration;
};
static prec::Level getPrecedence(const FormatToken &Tok) {
@@ -250,6 +252,8 @@ private:
} 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 @@ private:
(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 @@ public:
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 @@ public:
case tok::question:
parseConditional();
break;
+ case tok::kw_template:
+ parseTemplateDeclaration();
+ break;
default:
break;
}