diff options
| author | Chris Lattner <sabre@nondot.org> | 2008-04-07 04:56:42 +0000 |
|---|---|---|
| committer | Chris Lattner <sabre@nondot.org> | 2008-04-07 04:56:42 +0000 |
| commit | e0ea37ace75375de6e10926194d06e87a349db84 (patch) | |
| tree | 60dbf07b2ac6b3be9865e11b27cadfabf458a00b /clang/lib/AST/ASTContext.cpp | |
| parent | 513494b32b2c9762833690637952a7a41d3b9cb6 (diff) | |
| download | bcm5719-llvm-e0ea37ace75375de6e10926194d06e87a349db84.tar.gz bcm5719-llvm-e0ea37ace75375de6e10926194d06e87a349db84.zip | |
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.
llvm-svn: 49310
Diffstat (limited to 'clang/lib/AST/ASTContext.cpp')
| -rw-r--r-- | clang/lib/AST/ASTContext.cpp | 31 |
1 files changed, 28 insertions, 3 deletions
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp index bb03479a012..5119cfb026c 100644 --- a/clang/lib/AST/ASTContext.cpp +++ b/clang/lib/AST/ASTContext.cpp @@ -811,10 +811,33 @@ QualType ASTContext::getObjCInterfaceType(ObjCInterfaceDecl *Decl) { 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 @@ QualType ASTContext::getObjCQualifiedInterfaceType(ObjCInterfaceDecl *Decl, 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); |

