[cfe-commits] r49310 - in /cfe/trunk/lib: AST/ASTContext.cpp Parse/ParseObjc.cpp
Chris Lattner
sabre at nondot.org
Sun Apr 6 21:56:42 PDT 2008
Author: lattner
Date: Sun Apr 6 23:56:42 2008
New Revision: 49310
URL: http://llvm.org/viewvc/llvm-project?rev=49310&view=rev
Log:
move sorting of qualifying protocols from the parser into
sema. This allows clients of the parser to have the unmolested
list if desired, and guarantees that noone can create an
ObjCQualifiedInterfaceType with an unsorted list.
Modified:
cfe/trunk/lib/AST/ASTContext.cpp
cfe/trunk/lib/Parse/ParseObjc.cpp
Modified: cfe/trunk/lib/AST/ASTContext.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTContext.cpp?rev=49310&r1=49309&r2=49310&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ASTContext.cpp (original)
+++ cfe/trunk/lib/AST/ASTContext.cpp Sun Apr 6 23:56:42 2008
@@ -811,10 +811,33 @@
return QualType(Decl->TypeForDecl, 0);
}
+/// CmpProtocolNames - Comparison predicate for sorting protocols
+/// alphabetically.
+static bool CmpProtocolNames(const ObjCProtocolDecl *LHS,
+ const ObjCProtocolDecl *RHS) {
+ return strcmp(LHS->getName(), RHS->getName()) < 0;
+}
+
+static void SortAndUniqueProtocols(ObjCProtocolDecl **&Protocols,
+ unsigned &NumProtocols) {
+ ObjCProtocolDecl **ProtocolsEnd = Protocols+NumProtocols;
+
+ // Sort protocols, keyed by name.
+ std::sort(Protocols, Protocols+NumProtocols, CmpProtocolNames);
+
+ // Remove duplicates.
+ ProtocolsEnd = std::unique(Protocols, ProtocolsEnd);
+ NumProtocols = ProtocolsEnd-Protocols;
+}
+
+
/// getObjCQualifiedInterfaceType - Return a ObjCQualifiedInterfaceType type for
/// the given interface decl and the conforming protocol list.
QualType ASTContext::getObjCQualifiedInterfaceType(ObjCInterfaceDecl *Decl,
ObjCProtocolDecl **Protocols, unsigned NumProtocols) {
+ // Sort the protocol list alphabetically to canonicalize it.
+ SortAndUniqueProtocols(Protocols, NumProtocols);
+
llvm::FoldingSetNodeID ID;
ObjCQualifiedInterfaceType::Profile(ID, Protocols, NumProtocols);
@@ -831,12 +854,14 @@
return QualType(QType, 0);
}
-/// getObjCQualifiedIdType - Return a
-/// getObjCQualifiedIdType type for the 'id' decl and
-/// the conforming protocol list.
+/// getObjCQualifiedIdType - Return an ObjCQualifiedIdType for the 'id' decl
+/// and the conforming protocol list.
QualType ASTContext::getObjCQualifiedIdType(QualType idType,
ObjCProtocolDecl **Protocols,
unsigned NumProtocols) {
+ // Sort the protocol list alphabetically to canonicalize it.
+ SortAndUniqueProtocols(Protocols, NumProtocols);
+
llvm::FoldingSetNodeID ID;
ObjCQualifiedIdType::Profile(ID, Protocols, NumProtocols);
Modified: cfe/trunk/lib/Parse/ParseObjc.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseObjc.cpp?rev=49310&r1=49309&r2=49310&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseObjc.cpp (original)
+++ cfe/trunk/lib/Parse/ParseObjc.cpp Sun Apr 6 23:56:42 2008
@@ -701,18 +701,11 @@
MethodImplKind, isVariadic);
}
-/// 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 '>'
///
bool Parser::ParseObjCProtocolReferences(
- llvm::SmallVectorImpl<IdentifierInfo*> &ProtocolRefs, SourceLocation &endLoc)
-{
+ llvm::SmallVectorImpl<IdentifierInfo*> &ProtocolRefs, SourceLocation &endLoc){
assert(Tok.is(tok::less) && "expected <");
ConsumeToken(); // the "<"
@@ -731,13 +724,6 @@
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 '>'.
if (Tok.is(tok::greater)) {
endLoc = ConsumeAnyToken();
More information about the cfe-commits
mailing list