Added a new class for Interfaces qualified by protocol list.
Protocols are now sorted and made unique in the list.
Enhanced pretty printer for @interface (So, I can see the protocol list).
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@42776 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/Parse/ParseObjc.cpp b/Parse/ParseObjc.cpp
index b7ec93a..31caa58 100644
--- a/Parse/ParseObjc.cpp
+++ b/Parse/ParseObjc.cpp
@@ -618,6 +618,12 @@
MethodAttrs, MethodImplKind);
}
+/// CmpProtocolVals - Comparison predicate for sorting protocols.
+static bool CmpProtocolVals(const IdentifierInfo* const& lhs,
+ const IdentifierInfo* const& rhs) {
+ return strcmp(lhs->getName(), rhs->getName()) < 0;
+}
+
/// objc-protocol-refs:
/// '<' identifier-list '>'
///
@@ -640,6 +646,15 @@
break;
ConsumeToken();
}
+
+ // Sort protocols, keyed by name.
+ // Later on, we remove duplicates.
+ std::stable_sort(ProtocolRefs.begin(), ProtocolRefs.end(), CmpProtocolVals);
+
+ // Make protocol names unique.
+ ProtocolRefs.erase(std::unique(ProtocolRefs.begin(), ProtocolRefs.end()),
+ ProtocolRefs.end());
+
// Consume the '>'.
return ExpectAndConsume(tok::greater, diag::err_expected_greater);
}