forked from OSchip/llvm-project
Fix formatting of overloaded operator definitions.
Before: operatorvoid*(); operator vector< A< A>>(); After: operator void *(); operator vector<A<A> >(); llvm-svn: 174863
This commit is contained in:
parent
ca846ae622
commit
35d2dc765e
|
@ -369,19 +369,13 @@ public:
|
|||
Tok->Type = TT_BinaryOperator;
|
||||
break;
|
||||
case tok::kw_operator:
|
||||
if (CurrentToken != NULL && CurrentToken->is(tok::l_paren)) {
|
||||
CurrentToken->Type = TT_OverloadedOperator;
|
||||
next();
|
||||
if (CurrentToken != NULL && CurrentToken->is(tok::r_paren)) {
|
||||
CurrentToken->Type = TT_OverloadedOperator;
|
||||
next();
|
||||
}
|
||||
} else {
|
||||
while (CurrentToken != NULL && CurrentToken->isNot(tok::l_paren)) {
|
||||
CurrentToken->Type = TT_OverloadedOperator;
|
||||
next();
|
||||
}
|
||||
while (CurrentToken && CurrentToken->isNot(tok::l_paren)) {
|
||||
if (CurrentToken->is(tok::star) || CurrentToken->is(tok::amp))
|
||||
CurrentToken->Type = TT_PointerOrReference;
|
||||
consumeToken();
|
||||
}
|
||||
if (CurrentToken)
|
||||
CurrentToken->Type = TT_OverloadedOperatorLParen;
|
||||
break;
|
||||
case tok::question:
|
||||
parseConditional();
|
||||
|
@ -962,6 +956,9 @@ bool TokenAnnotator::spaceRequiredBetween(const AnnotatedLine &Line,
|
|||
|
||||
bool TokenAnnotator::spaceRequiredBefore(const AnnotatedLine &Line,
|
||||
const AnnotatedToken &Tok) {
|
||||
if (Tok.FormatTok.Tok.getIdentifierInfo() &&
|
||||
Tok.Parent->FormatTok.Tok.getIdentifierInfo())
|
||||
return true; // Never ever merge two identifiers.
|
||||
if (Line.Type == LT_ObjCMethodDecl) {
|
||||
if (Tok.Parent->Type == TT_ObjCMethodSpecifier)
|
||||
return true;
|
||||
|
@ -977,10 +974,9 @@ bool TokenAnnotator::spaceRequiredBefore(const AnnotatedLine &Line,
|
|||
return true;
|
||||
if (Tok.Type == TT_CtorInitializerColon || Tok.Type == TT_ObjCBlockLParen)
|
||||
return true;
|
||||
if (Tok.Type == TT_OverloadedOperator)
|
||||
return Tok.is(tok::identifier) || Tok.is(tok::kw_new) ||
|
||||
Tok.is(tok::kw_delete) || Tok.is(tok::kw_bool);
|
||||
if (Tok.Parent->Type == TT_OverloadedOperator)
|
||||
if (Tok.Parent->FormatTok.Tok.is(tok::kw_operator))
|
||||
return false;
|
||||
if (Tok.Type == TT_OverloadedOperatorLParen)
|
||||
return false;
|
||||
if (Tok.is(tok::colon))
|
||||
return Line.First.isNot(tok::kw_case) && !Tok.Children.empty() &&
|
||||
|
|
|
@ -42,7 +42,7 @@ enum TokenType {
|
|||
TT_ObjCMethodSpecifier,
|
||||
TT_ObjCProperty,
|
||||
TT_ObjCSelectorName,
|
||||
TT_OverloadedOperator,
|
||||
TT_OverloadedOperatorLParen,
|
||||
TT_PointerOrReference,
|
||||
TT_PureVirtualSpecifier,
|
||||
TT_RangeBasedForLoopColon,
|
||||
|
|
|
@ -1541,11 +1541,18 @@ TEST_F(FormatTest, UndestandsOverloadedOperators) {
|
|||
verifyFormat("bool operator()();");
|
||||
verifyFormat("bool operator[]();");
|
||||
verifyFormat("operator bool();");
|
||||
verifyFormat("operator int();");
|
||||
verifyFormat("operator void *();");
|
||||
verifyFormat("operator SomeType<int>();");
|
||||
verifyFormat("operator SomeType<int, int>();");
|
||||
verifyFormat("operator SomeType<SomeType<int> >();");
|
||||
verifyFormat("void *operator new(std::size_t size);");
|
||||
verifyFormat("void *operator new[](std::size_t size);");
|
||||
verifyFormat("void operator delete(void *ptr);");
|
||||
verifyFormat("void operator delete[](void *ptr);");
|
||||
|
||||
verifyGoogleFormat("operator void*();");
|
||||
verifyGoogleFormat("operator SomeType<SomeType<int>>();");
|
||||
}
|
||||
|
||||
TEST_F(FormatTest, UnderstandsNewAndDelete) {
|
||||
|
|
Loading…
Reference in New Issue