diff options
author | John McCall <rjmccall@apple.com> | 2010-02-13 01:04:05 +0000 |
---|---|---|
committer | John McCall <rjmccall@apple.com> | 2010-02-13 01:04:05 +0000 |
commit | 7fe0b9ea2c8137c035402e6ea01dfdfbc93214cb (patch) | |
tree | f2563e0d6deec8c7a5457786b9d2e000ca96173b /lib/AST/DeclarationName.cpp | |
parent | c1ddcabef0b0e1185b6ea35d64a1ff41dabd7626 (diff) |
Switch the standard DeclarationName comparator to be a tri-valued comparator.
Use that while fixing a nasty misuse of qsort in vtable codegen which, somehow,
has not actually caused a crash.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@96062 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/AST/DeclarationName.cpp')
-rw-r--r-- | lib/AST/DeclarationName.cpp | 47 |
1 files changed, 29 insertions, 18 deletions
diff --git a/lib/AST/DeclarationName.cpp b/lib/AST/DeclarationName.cpp index ff810735bc..19b58bcbaf 100644 --- a/lib/AST/DeclarationName.cpp +++ b/lib/AST/DeclarationName.cpp @@ -66,27 +66,33 @@ public: } }; -bool operator<(DeclarationName LHS, DeclarationName RHS) { +static int compareInt(unsigned A, unsigned B) { + return (A < B ? -1 : (A > B ? 1 : 0)); +} + +int DeclarationName::compare(DeclarationName LHS, DeclarationName RHS) { if (LHS.getNameKind() != RHS.getNameKind()) - return LHS.getNameKind() < RHS.getNameKind(); + return (LHS.getNameKind() < RHS.getNameKind() ? -1 : 1); switch (LHS.getNameKind()) { - case DeclarationName::Identifier: - return LHS.getAsIdentifierInfo()->getName() < - RHS.getAsIdentifierInfo()->getName(); + case DeclarationName::Identifier: { + IdentifierInfo *LII = LHS.getAsIdentifierInfo(); + IdentifierInfo *RII = RHS.getAsIdentifierInfo(); + if (!LII) return RII ? -1 : 0; + if (!RII) return 1; + + return LII->getName().compare(RII->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) { + unsigned LN = LHSSelector.getNumArgs(), RN = RHSSelector.getNumArgs(); + for (unsigned I = 0, N = std::min(LN, RN); 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; @@ -94,27 +100,32 @@ bool operator<(DeclarationName LHS, DeclarationName RHS) { default: break; } } - - return LHSSelector.getNumArgs() < RHSSelector.getNumArgs(); + + return compareInt(LN, RN); } case DeclarationName::CXXConstructorName: case DeclarationName::CXXDestructorName: case DeclarationName::CXXConversionFunctionName: - return QualTypeOrdering()(LHS.getCXXNameType(), RHS.getCXXNameType()); + if (QualTypeOrdering()(LHS.getCXXNameType(), RHS.getCXXNameType())) + return -1; + if (QualTypeOrdering()(RHS.getCXXNameType(), LHS.getCXXNameType())) + return 1; + return 0; case DeclarationName::CXXOperatorName: - return LHS.getCXXOverloadedOperator() < RHS.getCXXOverloadedOperator(); + return compareInt(LHS.getCXXOverloadedOperator(), + RHS.getCXXOverloadedOperator()); case DeclarationName::CXXLiteralOperatorName: - return LHS.getCXXLiteralIdentifier()->getName() < - RHS.getCXXLiteralIdentifier()->getName(); + return LHS.getCXXLiteralIdentifier()->getName().compare( + RHS.getCXXLiteralIdentifier()->getName()); case DeclarationName::CXXUsingDirective: - return false; + return 0; } - return false; + return 0; } } // end namespace clang |