r188172 - clang-format: Correctly format alias declarations.
Daniel Jasper
djasper at google.com
Mon Aug 12 05:16:34 PDT 2013
Author: djasper
Date: Mon Aug 12 07:16:34 2013
New Revision: 188172
URL: http://llvm.org/viewvc/llvm-project?rev=188172&view=rev
Log:
clang-format: Correctly format alias declarations.
Before:
template <class CallbackClass>
using MyCallback = void(CallbackClass::*)(SomeObject * Data);");
After:
template <class CallbackClass>
using MyCallback = void (CallbackClass::*)(SomeObject *Data);");
Also fix three wrong indentations.
Modified:
cfe/trunk/lib/Format/Format.cpp
cfe/trunk/lib/Format/TokenAnnotator.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=188172&r1=188171&r2=188172&view=diff
==============================================================================
--- cfe/trunk/lib/Format/Format.cpp (original)
+++ cfe/trunk/lib/Format/Format.cpp Mon Aug 12 07:16:34 2013
@@ -973,7 +973,7 @@ private:
// Exempts unterminated string literals from line breaking. The user will
// likely want to terminate the string before any line breaking is done.
if (Current.IsUnterminatedLiteral)
- return 0;
+ return 0;
Token.reset(new BreakableStringLiteral(Current, StartColumn,
Line.InPPDirective, Encoding));
@@ -1228,7 +1228,7 @@ private:
return true;
if (!Style.Cpp11BracedListStyle && Current.is(tok::r_brace) &&
State.Stack.back().BreakBeforeClosingBrace)
- return true;
+ return true;
if (Previous.is(tok::semi) && State.LineContainsContinuedForLoopSection)
return true;
if (Style.BreakConstructorInitializersBeforeComma) {
Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=188172&r1=188171&r2=188172&view=diff
==============================================================================
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Mon Aug 12 07:16:34 2013
@@ -123,6 +123,10 @@ private:
}
}
+ if (CurrentToken->Previous->Type == TT_PointerOrReference &&
+ CurrentToken->Previous->Previous->isOneOf(tok::l_paren,
+ tok::coloncolon))
+ MightBeFunctionType = true;
if (CurrentToken->is(tok::r_paren)) {
if (MightBeFunctionType && CurrentToken->Next &&
(CurrentToken->Next->is(tok::l_paren) ||
@@ -152,10 +156,6 @@ private:
}
if (CurrentToken->isOneOf(tok::r_square, tok::r_brace))
return false;
- if (CurrentToken->Previous->Type == TT_PointerOrReference &&
- CurrentToken->Previous->Previous->isOneOf(tok::l_paren,
- tok::coloncolon))
- MightBeFunctionType = true;
updateParameterCount(Left, CurrentToken);
if (CurrentToken->is(tok::comma) && CurrentToken->Next &&
!CurrentToken->Next->HasUnescapedNewline &&
@@ -577,6 +577,7 @@ private:
void determineTokenType(FormatToken &Current) {
if (Current.getPrecedence() == prec::Assignment &&
+ !Line.First->isOneOf(tok::kw_template, tok::kw_using) &&
(!Current.Previous || Current.Previous->isNot(tok::kw_operator))) {
Contexts.back().IsExpression = true;
for (FormatToken *Previous = Current.Previous;
@@ -593,7 +594,7 @@ private:
(Current.is(tok::l_paren) && !Line.MustBeDeclaration &&
!Line.InPPDirective &&
(!Current.Previous ||
- !Current.Previous->isOneOf(tok::kw_for, tok::kw_catch)))) {
+ !Current.Previous->isOneOf(tok::kw_for, tok::kw_catch)))) {
Contexts.back().IsExpression = true;
} else if (Current.isOneOf(tok::r_paren, tok::greater, tok::comma)) {
for (FormatToken *Previous = Current.Previous;
Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=188172&r1=188171&r2=188172&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Mon Aug 12 07:16:34 2013
@@ -3797,9 +3797,14 @@ TEST_F(FormatTest, FormatsFunctionTypes)
verifyFormat("void *(*a)(int *, SomeType *);");
verifyFormat("int (*func)(void *);");
verifyFormat("void f() { int (*func)(void *); }");
+ verifyFormat("template <class CallbackClass>\n"
+ "using MyCallback = void (CallbackClass::*)(SomeObject *Data);");
verifyGoogleFormat("A<void*(int*, SomeType*)>;");
verifyGoogleFormat("void* (*a)(int);");
+ verifyGoogleFormat(
+ "template <class CallbackClass>\n"
+ "using MyCallback = void (CallbackClass::*)(SomeObject* Data);");
// Other constructs can look somewhat like function types:
verifyFormat("A<sizeof(*x)> a;");
More information about the cfe-commits
mailing list