Better fix for r177725.

It turns out that

-foo;

can be an objective C method declaration. So instead of the previous
solution, recognize objective C methods only if we are in a declaration
scope.

llvm-svn: 177740
This commit is contained in:
Daniel Jasper 2013-03-22 16:55:40 +00:00
parent bc0fa39d69
commit dd9276e464
3 changed files with 5 additions and 7 deletions

View File

@ -313,11 +313,7 @@ private:
switch (Tok->FormatTok.Tok.getKind()) {
case tok::plus:
case tok::minus:
// At the start of the line, +/- specify ObjectiveC method declarations.
if (Tok->Children.empty() || Tok->Children[0].Children.empty())
break; // Can't be an ObjectiveC method declaration.
if (Tok->Parent == NULL && (Tok->Children[0].is(tok::l_paren) ||
Tok->Children[0].Children[0].is(tok::colon)))
if (Tok->Parent == NULL && Line.MustBeDeclaration)
Tok->Type = TT_ObjCMethodSpecifier;
break;
case tok::colon:

View File

@ -144,8 +144,9 @@ bool UnwrappedLineParser::parse() {
}
bool UnwrappedLineParser::parseFile() {
ScopedDeclarationState DeclarationState(*Line, DeclarationScopeStack,
/*MustBeDeclaration=*/ true);
ScopedDeclarationState DeclarationState(
*Line, DeclarationScopeStack,
/*MustBeDeclaration=*/ !Line->InPPDirective);
bool Error = parseLevel(/*HasOpeningBrace=*/ false);
// Make sure to format the remaining tokens.
flushComments(true);

View File

@ -2815,6 +2815,7 @@ TEST_F(FormatTest, FormatForObjectiveCMethodDecls) {
// If there's no return type (very rare in practice!), LLVM and Google style
// agree.
verifyFormat("- foo;");
verifyFormat("- foo:(int)f;");
verifyGoogleFormat("- foo:(int)foo;");
}