[cfe-commits] r86055 - /cfe/trunk/lib/AST/DeclarationName.cpp
Douglas Gregor
dgregor at apple.com
Wed Nov 4 14:24:30 PST 2009
Author: dgregor
Date: Wed Nov 4 16:24:30 2009
New Revision: 86055
URL: http://llvm.org/viewvc/llvm-project?rev=86055&view=rev
Log:
Give DeclarationName's operator< a more predictable, useful ordering
Modified:
cfe/trunk/lib/AST/DeclarationName.cpp
Modified: cfe/trunk/lib/AST/DeclarationName.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclarationName.cpp?rev=86055&r1=86054&r2=86055&view=diff
==============================================================================
--- cfe/trunk/lib/AST/DeclarationName.cpp (original)
+++ cfe/trunk/lib/AST/DeclarationName.cpp Wed Nov 4 16:24:30 2009
@@ -13,6 +13,7 @@
//===----------------------------------------------------------------------===//
#include "clang/AST/DeclarationName.h"
#include "clang/AST/Type.h"
+#include "clang/AST/TypeOrdering.h"
#include "clang/AST/Decl.h"
#include "clang/Basic/IdentifierTable.h"
#include "llvm/ADT/DenseMap.h"
@@ -49,11 +50,50 @@
};
bool operator<(DeclarationName LHS, DeclarationName RHS) {
- if (IdentifierInfo *LhsId = LHS.getAsIdentifierInfo())
- if (IdentifierInfo *RhsId = RHS.getAsIdentifierInfo())
- return LhsId->getName() < RhsId->getName();
-
- return LHS.getAsOpaqueInteger() < RHS.getAsOpaqueInteger();
+ if (LHS.getNameKind() != RHS.getNameKind())
+ return LHS.getNameKind() < RHS.getNameKind();
+
+ switch (LHS.getNameKind()) {
+ case DeclarationName::Identifier:
+ return LHS.getAsIdentifierInfo()->getName() <
+ RHS.getAsIdentifierInfo()->getName();
+
+ case DeclarationName::ObjCZeroArgSelector:
+ case DeclarationName::ObjCOneArgSelector:
+ case DeclarationName::ObjCMultiArgSelector: {
+ Selector LHSSelector = LHS.getObjCSelector();
+ Selector RHSSelector = RHS.getObjCSelector();
+ for (unsigned I = 0,
+ N = std::min(LHSSelector.getNumArgs(), RHSSelector.getNumArgs());
+ I != N; ++I) {
+ IdentifierInfo *LHSId = LHSSelector.getIdentifierInfoForSlot(I);
+ IdentifierInfo *RHSId = RHSSelector.getIdentifierInfoForSlot(I);
+ if (!LHSId || !RHSId)
+ return LHSId && !RHSId;
+
+ switch (LHSId->getName().compare(RHSId->getName())) {
+ case -1: return true;
+ case 1: return false;
+ default: break;
+ }
+ }
+
+ return LHSSelector.getNumArgs() < RHSSelector.getNumArgs();
+ }
+
+ case DeclarationName::CXXConstructorName:
+ case DeclarationName::CXXDestructorName:
+ case DeclarationName::CXXConversionFunctionName:
+ return QualTypeOrdering()(LHS.getCXXNameType(), RHS.getCXXNameType());
+
+ case DeclarationName::CXXOperatorName:
+ return LHS.getCXXOverloadedOperator() < RHS.getCXXOverloadedOperator();
+
+ case DeclarationName::CXXUsingDirective:
+ return false;
+ }
+
+ return false;
}
} // end namespace clang
More information about the cfe-commits
mailing list