diff options
author | Douglas Gregor <dgregor@apple.com> | 2008-11-13 20:12:29 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2008-11-13 20:12:29 +0000 |
commit | bf3af056289893f58d37b05a2c80970708781d61 (patch) | |
tree | 7168457002a5ee22d8162990e6b49f6f1252369d /lib/Sema/SemaOverload.cpp | |
parent | ace6625f236af4fc81d87d63d79d7819944524dc (diff) |
Some cleanup for the implementation of built-in operator
candidates. Thanks to Chris for the review!
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@59260 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaOverload.cpp')
-rw-r--r-- | lib/Sema/SemaOverload.cpp | 52 |
1 files changed, 45 insertions, 7 deletions
diff --git a/lib/Sema/SemaOverload.cpp b/lib/Sema/SemaOverload.cpp index 9229fa35d2..58ab5aa759 100644 --- a/lib/Sema/SemaOverload.cpp +++ b/lib/Sema/SemaOverload.cpp @@ -18,7 +18,7 @@ #include "clang/AST/ASTContext.h" #include "clang/AST/Expr.h" #include "clang/AST/TypeOrdering.h" -#include "llvm/ADT/DenseSet.h" +#include "llvm/ADT/SmallPtrSet.h" #include "llvm/Support/Compiler.h" #include <algorithm> @@ -1588,7 +1588,7 @@ void Sema::AddBuiltinCandidate(QualType ResultTy, QualType *ParamTys, /// enumeration types. class BuiltinCandidateTypeSet { /// TypeSet - A set of types. - typedef llvm::DenseSet<QualType> TypeSet; + typedef llvm::SmallPtrSet<void*, 8> TypeSet; /// PointerTypes - The set of pointer types that will be used in the /// built-in candidates. @@ -1605,7 +1605,45 @@ class BuiltinCandidateTypeSet { public: /// iterator - Iterates through the types that are part of the set. - typedef TypeSet::iterator iterator; + class iterator { + TypeSet::iterator Base; + + public: + typedef QualType value_type; + typedef QualType reference; + typedef QualType pointer; + typedef std::ptrdiff_t difference_type; + typedef std::input_iterator_tag iterator_category; + + iterator(TypeSet::iterator B) : Base(B) { } + + iterator& operator++() { + ++Base; + return *this; + } + + iterator operator++(int) { + iterator tmp(*this); + ++(*this); + return tmp; + } + + reference operator*() const { + return QualType::getFromOpaquePtr(*Base); + } + + pointer operator->() const { + return **this; + } + + friend bool operator==(iterator LHS, iterator RHS) { + return LHS.Base == RHS.Base; + } + + friend bool operator!=(iterator LHS, iterator RHS) { + return LHS.Base != RHS.Base; + } + }; BuiltinCandidateTypeSet(ASTContext &Context) : Context(Context) { } @@ -1633,7 +1671,7 @@ public: /// false otherwise. bool BuiltinCandidateTypeSet::AddWithMoreQualifiedTypeVariants(QualType Ty) { // Insert this type. - if (!PointerTypes.insert(Ty).second) + if (!PointerTypes.insert(Ty.getAsOpaquePtr())) return false; if (const PointerType *PointerTy = Ty->getAsPointerType()) { @@ -1703,7 +1741,7 @@ void BuiltinCandidateTypeSet::AddTypesConvertedFrom(QualType Ty, } } } else if (Ty->isEnumeralType()) { - EnumerationTypes.insert(Ty); + EnumerationTypes.insert(Ty.getAsOpaquePtr()); } else if (AllowUserConversions) { if (const RecordType *TyRec = Ty->getAsRecordType()) { CXXRecordDecl *ClassDecl = cast<CXXRecordDecl>(TyRec->getDecl()); @@ -1953,7 +1991,7 @@ Sema::AddBuiltinBinaryOperatorCandidates(OverloadedOperatorKind Op, AddBuiltinCandidate(ParamTypes[0], ParamTypes, Args, 2, CandidateSet); // volatile T& operator=(volatile T&, T) - ParamTypes[0] = Context.getReferenceType(Enum->withVolatile()); + ParamTypes[0] = Context.getReferenceType((*Enum).withVolatile()); ParamTypes[1] = *Enum; AddBuiltinCandidate(ParamTypes[0], ParamTypes, Args, 2, CandidateSet); } @@ -1987,7 +2025,7 @@ Sema::AddBuiltinBinaryOperatorCandidates(OverloadedOperatorKind Op, AddBuiltinCandidate(ParamTypes[0], ParamTypes, Args, 2, CandidateSet); // volatile version - ParamTypes[0] = Context.getReferenceType(Ptr->withVolatile()); + ParamTypes[0] = Context.getReferenceType((*Ptr).withVolatile()); AddBuiltinCandidate(ParamTypes[0], ParamTypes, Args, 2, CandidateSet); } // Fall through. |