aboutsummaryrefslogtreecommitdiff
path: root/lib/Format/UnwrappedLineParser.cpp
diff options
context:
space:
mode:
authorNico Weber <nicolasweber@gmx.de>2013-01-09 21:15:03 +0000
committerNico Weber <nicolasweber@gmx.de>2013-01-09 21:15:03 +0000
commit1abe6ea5b8961a0fc14c2e0bdbd7451f643ca065 (patch)
tree9dce7b92a3f04afa006cd9f12e74274ce49eb60a /lib/Format/UnwrappedLineParser.cpp
parentfa49c18071500d43c86a3c0029aecaea954a64ca (diff)
Formatting: Add support for @protocol.
Pull pieces of the @interface code into reusable methods. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172001 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Format/UnwrappedLineParser.cpp')
-rw-r--r--lib/Format/UnwrappedLineParser.cpp56
1 files changed, 40 insertions, 16 deletions
diff --git a/lib/Format/UnwrappedLineParser.cpp b/lib/Format/UnwrappedLineParser.cpp
index 131d982906..688937c1e6 100644
--- a/lib/Format/UnwrappedLineParser.cpp
+++ b/lib/Format/UnwrappedLineParser.cpp
@@ -210,6 +210,8 @@ void UnwrappedLineParser::parseStructuralElement() {
return parseAccessSpecifier();
case tok::objc_interface:
return parseObjCInterface();
+ case tok::objc_protocol:
+ return parseObjCProtocol();
default:
break;
}
@@ -496,6 +498,25 @@ void UnwrappedLineParser::parseStructOrClass() {
} while (!eof());
}
+void UnwrappedLineParser::parseObjCProtocolList() {
+ assert(FormatTok.Tok.is(tok::less) && "'<' expected.");
+ do
+ nextToken();
+ while (!eof() && FormatTok.Tok.isNot(tok::greater));
+ nextToken(); // Skip '>'.
+}
+
+void UnwrappedLineParser::parseObjCUntilAtEnd() {
+ do {
+ if (FormatTok.Tok.isObjCAtKeyword(tok::objc_end)) {
+ nextToken();
+ addUnwrappedLine();
+ break;
+ }
+ parseStructuralElement();
+ } while (!eof());
+}
+
void UnwrappedLineParser::parseObjCInterface() {
nextToken();
nextToken(); // interface name
@@ -508,13 +529,8 @@ void UnwrappedLineParser::parseObjCInterface() {
// 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 (FormatTok.Tok.is(tok::less))
+ parseObjCProtocolList();
// If instance variables are present, keep the '{' on the first line too.
if (FormatTok.Tok.is(tok::l_brace))
@@ -524,16 +540,24 @@ void UnwrappedLineParser::parseObjCInterface() {
// variables, this ends the @interface line.
addUnwrappedLine();
- // Read everything up to the @end.
- do {
- if (FormatTok.Tok.isObjCAtKeyword(tok::objc_end)) {
- nextToken();
- addUnwrappedLine();
- break;
- }
+ parseObjCUntilAtEnd();
+}
- parseStructuralElement();
- } while (!eof());
+void UnwrappedLineParser::parseObjCProtocol() {
+ nextToken();
+ nextToken(); // protocol name
+
+ if (FormatTok.Tok.is(tok::less))
+ parseObjCProtocolList();
+
+ // Check for protocol declaration.
+ if (FormatTok.Tok.is(tok::semi)) {
+ nextToken();
+ return addUnwrappedLine();
+ }
+
+ addUnwrappedLine();
+ parseObjCUntilAtEnd();
}
void UnwrappedLineParser::addUnwrappedLine() {