diff options
author | Nico Weber <nicolasweber@gmx.de> | 2013-01-09 20:25:35 +0000 |
---|---|---|
committer | Nico Weber <nicolasweber@gmx.de> | 2013-01-09 20:25:35 +0000 |
commit | 27d1367871a6eab347346497e87ea1adb2fd15a5 (patch) | |
tree | c87bd5b78c37c01a6117e1213a378993bb7043a5 /lib/Format/UnwrappedLineParser.cpp | |
parent | ccdb2a5e0ab4b0a7fc9d3859c6bb1676182169d5 (diff) |
Formatter: Add support for @interface.
Previously:
@interface Foo + (id)init; @end
Now:
@interface Foo
+ (id)init;
@end
Some tweaking remains, but this is a good first step.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@171995 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Format/UnwrappedLineParser.cpp')
-rw-r--r-- | lib/Format/UnwrappedLineParser.cpp | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/lib/Format/UnwrappedLineParser.cpp b/lib/Format/UnwrappedLineParser.cpp index 99d5f6279d..131d982906 100644 --- a/lib/Format/UnwrappedLineParser.cpp +++ b/lib/Format/UnwrappedLineParser.cpp @@ -208,6 +208,8 @@ void UnwrappedLineParser::parseStructuralElement() { case tok::objc_package: case tok::objc_private: return parseAccessSpecifier(); + case tok::objc_interface: + return parseObjCInterface(); default: break; } @@ -494,6 +496,46 @@ void UnwrappedLineParser::parseStructOrClass() { } while (!eof()); } +void UnwrappedLineParser::parseObjCInterface() { + nextToken(); + nextToken(); // interface name + + // @interface can be followed by either a base class, or a category. + if (FormatTok.Tok.is(tok::colon)) { + nextToken(); + nextToken(); // base class name + } else if (FormatTok.Tok.is(tok::l_paren)) + // Skip category, if present. + parseParens(); + + // Skip protocol list, if present. + if (FormatTok.Tok.is(tok::less)) { + do + nextToken(); + while (!eof() && FormatTok.Tok.isNot(tok::greater)); + nextToken(); // Skip '>'. + } + + // If instance variables are present, keep the '{' on the first line too. + if (FormatTok.Tok.is(tok::l_brace)) + parseBlock(); + + // With instance variables, this puts '}' on its own line. Without instance + // variables, this ends the @interface line. + addUnwrappedLine(); + + // Read everything up to the @end. + do { + if (FormatTok.Tok.isObjCAtKeyword(tok::objc_end)) { + nextToken(); + addUnwrappedLine(); + break; + } + + parseStructuralElement(); + } while (!eof()); +} + void UnwrappedLineParser::addUnwrappedLine() { if (!RootTokenInitialized) return; |