From 9d29543284e75648ac89c6e9586fc7cf786cf66f Mon Sep 17 00:00:00 2001 From: Argyrios Kyrtzidis Date: Wed, 28 Nov 2012 03:56:09 +0000 Subject: [PATCH] Don't return a pointer to an UnresolvedSetImpl in the CXXRecordDecl interface, expose only the iterators instead. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@168770 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/AST/DeclCXX.h | 18 ++++-------- lib/AST/DeclCXX.cpp | 34 ++++++++++++---------- lib/Sema/SemaDecl.cpp | 8 ++--- lib/Sema/SemaExprCXX.cpp | 8 +++-- lib/Sema/SemaInit.cpp | 19 ++++++------ lib/Sema/SemaLookup.cpp | 5 ++-- lib/Sema/SemaOverload.cpp | 55 +++++++++++++++++++---------------- lib/Sema/SemaPseudoObject.cpp | 9 +++--- 8 files changed, 79 insertions(+), 77 deletions(-) diff --git a/include/clang/AST/DeclCXX.h b/include/clang/AST/DeclCXX.h index 91a26d885e..6abc82d7be 100644 --- a/include/clang/AST/DeclCXX.h +++ b/include/clang/AST/DeclCXX.h @@ -1018,21 +1018,12 @@ public: return isLambda() ? captures_begin() + getLambdaData().NumCaptures : NULL; } - /// getConversions - Retrieve the overload set containing all of the - /// conversion functions in this class. - UnresolvedSetImpl *getConversionFunctions() { - return &data().Conversions; - } - const UnresolvedSetImpl *getConversionFunctions() const { - return &data().Conversions; - } - - typedef UnresolvedSetImpl::iterator conversion_iterator; + typedef UnresolvedSetIterator conversion_iterator; conversion_iterator conversion_begin() const { - return getConversionFunctions()->begin(); + return data().Conversions.begin(); } conversion_iterator conversion_end() const { - return getConversionFunctions()->end(); + return data().Conversions.end(); } /// Removes a conversion function from this class. The conversion @@ -1042,7 +1033,8 @@ public: /// getVisibleConversionFunctions - get all conversion functions visible /// in current class; including conversion function templates. - const UnresolvedSetImpl *getVisibleConversionFunctions(); + std::pair + getVisibleConversionFunctions(); /// isAggregate - Whether this class is an aggregate (C++ /// [dcl.init.aggr]), which is a class with no user-declared diff --git a/lib/AST/DeclCXX.cpp b/lib/AST/DeclCXX.cpp index a0ff6508ce..bf6107f052 100644 --- a/lib/AST/DeclCXX.cpp +++ b/lib/AST/DeclCXX.cpp @@ -1007,12 +1007,13 @@ static void CollectVisibleConversions(ASTContext &Context, // Collect the direct conversions and figure out which conversions // will be hidden in the subclasses. - UnresolvedSetImpl &Cs = *Record->getConversionFunctions(); - if (!Cs.empty()) { + CXXRecordDecl::conversion_iterator ConvI = Record->conversion_begin(); + CXXRecordDecl::conversion_iterator ConvE = Record->conversion_end(); + if (ConvI != ConvE) { HiddenTypesBuffer = ParentHiddenTypes; HiddenTypes = &HiddenTypesBuffer; - for (UnresolvedSetIterator I = Cs.begin(), E = Cs.end(); I != E; ++I) { + for (CXXRecordDecl::conversion_iterator I = ConvI; I != ConvE; ++I) { CanQualType ConvType(GetConversionType(Context, I.getDecl())); bool Hidden = ParentHiddenTypes.count(ConvType); if (!Hidden) @@ -1073,10 +1074,11 @@ static void CollectVisibleConversions(ASTContext &Context, // Go ahead and collect the direct conversions and add them to the // hidden-types set. - UnresolvedSetImpl &Cs = *Record->getConversionFunctions(); - Output.append(Cs.begin(), Cs.end()); - for (UnresolvedSetIterator I = Cs.begin(), E = Cs.end(); I != E; ++I) - HiddenTypes.insert(GetConversionType(Context, I.getDecl())); + CXXRecordDecl::conversion_iterator ConvI = Record->conversion_begin(); + CXXRecordDecl::conversion_iterator ConvE = Record->conversion_end(); + Output.append(ConvI, ConvE); + for (; ConvI != ConvE; ++ConvI) + HiddenTypes.insert(GetConversionType(Context, ConvI.getDecl())); // Recursively collect conversions from base classes. for (CXXRecordDecl::base_class_iterator @@ -1099,16 +1101,18 @@ static void CollectVisibleConversions(ASTContext &Context, /// getVisibleConversionFunctions - get all conversion functions visible /// in current class; including conversion function templates. -const UnresolvedSetImpl *CXXRecordDecl::getVisibleConversionFunctions() { +std::pair +CXXRecordDecl::getVisibleConversionFunctions() { // If root class, all conversions are visible. if (bases_begin() == bases_end()) - return &data().Conversions; + return std::make_pair(data().Conversions.begin(), data().Conversions.end()); // If visible conversion list is already evaluated, return it. - if (data().ComputedVisibleConversions) - return &data().VisibleConversions; - CollectVisibleConversions(getASTContext(), this, data().VisibleConversions); - data().ComputedVisibleConversions = true; - return &data().VisibleConversions; + if (!data().ComputedVisibleConversions) { + CollectVisibleConversions(getASTContext(), this, data().VisibleConversions); + data().ComputedVisibleConversions = true; + } + return std::make_pair(data().VisibleConversions.begin(), + data().VisibleConversions.end()); } void CXXRecordDecl::removeConversion(const NamedDecl *ConvDecl) { @@ -1123,7 +1127,7 @@ void CXXRecordDecl::removeConversion(const NamedDecl *ConvDecl) { // with sufficiently large numbers of directly-declared conversions // that asymptotic behavior matters. - UnresolvedSetImpl &Convs = *getConversionFunctions(); + UnresolvedSetImpl &Convs = data().Conversions; for (unsigned I = 0, E = Convs.size(); I != E; ++I) { if (Convs[I].getDecl() == ConvDecl) { Convs.erase(I); diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index edf50d20ec..eb75329461 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -10369,10 +10369,10 @@ void Sema::ActOnFields(Scope* S, if (CXXRecordDecl *CXXRecord = dyn_cast(Record)) { if (!CXXRecord->isInvalidDecl()) { // Set access bits correctly on the directly-declared conversions. - UnresolvedSetImpl *Convs = CXXRecord->getConversionFunctions(); - for (UnresolvedSetIterator I = Convs->begin(), E = Convs->end(); - I != E; ++I) - Convs->setAccess(I, (*I)->getAccess()); + for (CXXRecordDecl::conversion_iterator + I = CXXRecord->conversion_begin(), + E = CXXRecord->conversion_end(); I != E; ++I) + I.setAccess((*I)->getAccess()); if (!CXXRecord->isDependentType()) { // Adjust user-defined destructor exception spec. diff --git a/lib/Sema/SemaExprCXX.cpp b/lib/Sema/SemaExprCXX.cpp index 3b2da04ca3..de9a9ba47d 100644 --- a/lib/Sema/SemaExprCXX.cpp +++ b/lib/Sema/SemaExprCXX.cpp @@ -2037,9 +2037,11 @@ Sema::ActOnCXXDelete(SourceLocation StartLoc, bool UseGlobal, SmallVector ObjectPtrConversions; CXXRecordDecl *RD = cast(Record->getDecl()); - const UnresolvedSetImpl *Conversions = RD->getVisibleConversionFunctions(); - for (UnresolvedSetImpl::iterator I = Conversions->begin(), - E = Conversions->end(); I != E; ++I) { + std::pair + Conversions = RD->getVisibleConversionFunctions(); + for (CXXRecordDecl::conversion_iterator + I = Conversions.first, E = Conversions.second; I != E; ++I) { NamedDecl *D = I.getDecl(); if (isa(D)) D = cast(D)->getTargetDecl(); diff --git a/lib/Sema/SemaInit.cpp b/lib/Sema/SemaInit.cpp index 5b7fb4656d..6344aa44b1 100644 --- a/lib/Sema/SemaInit.cpp +++ b/lib/Sema/SemaInit.cpp @@ -3200,10 +3200,11 @@ static OverloadingResult TryRefInitWithConversionFunction(Sema &S, // functions. CXXRecordDecl *T2RecordDecl = cast(T2RecordType->getDecl()); - const UnresolvedSetImpl *Conversions - = T2RecordDecl->getVisibleConversionFunctions(); - for (UnresolvedSetImpl::const_iterator I = Conversions->begin(), - E = Conversions->end(); I != E; ++I) { + std::pair + Conversions = T2RecordDecl->getVisibleConversionFunctions(); + for (CXXRecordDecl::conversion_iterator + I = Conversions.first, E = Conversions.second; I != E; ++I) { NamedDecl *D = *I; CXXRecordDecl *ActingDC = cast(D->getDeclContext()); if (isa(D)) @@ -3759,11 +3760,11 @@ static void TryUserDefinedConversion(Sema &S, CXXRecordDecl *SourceRecordDecl = cast(SourceRecordType->getDecl()); - const UnresolvedSetImpl *Conversions - = SourceRecordDecl->getVisibleConversionFunctions(); - for (UnresolvedSetImpl::const_iterator I = Conversions->begin(), - E = Conversions->end(); - I != E; ++I) { + std::pair + Conversions = SourceRecordDecl->getVisibleConversionFunctions(); + for (CXXRecordDecl::conversion_iterator + I = Conversions.first, E = Conversions.second; I != E; ++I) { NamedDecl *D = *I; CXXRecordDecl *ActingDC = cast(D->getDeclContext()); if (isa(D)) diff --git a/lib/Sema/SemaLookup.cpp b/lib/Sema/SemaLookup.cpp index 003c525e9f..4b1c6649be 100644 --- a/lib/Sema/SemaLookup.cpp +++ b/lib/Sema/SemaLookup.cpp @@ -673,9 +673,8 @@ static bool LookupDirect(Sema &S, LookupResult &R, const DeclContext *DC) { if (!Record->isCompleteDefinition()) return Found; - const UnresolvedSetImpl *Unresolved = Record->getConversionFunctions(); - for (UnresolvedSetImpl::iterator U = Unresolved->begin(), - UEnd = Unresolved->end(); U != UEnd; ++U) { + for (CXXRecordDecl::conversion_iterator U = Record->conversion_begin(), + UEnd = Record->conversion_end(); U != UEnd; ++U) { FunctionTemplateDecl *ConvTemplate = dyn_cast(*U); if (!ConvTemplate) continue; diff --git a/lib/Sema/SemaOverload.cpp b/lib/Sema/SemaOverload.cpp index 0c37c599e8..f31c12bb77 100644 --- a/lib/Sema/SemaOverload.cpp +++ b/lib/Sema/SemaOverload.cpp @@ -3065,10 +3065,11 @@ IsUserDefinedConversion(Sema &S, Expr *From, QualType ToType, if (CXXRecordDecl *FromRecordDecl = dyn_cast(FromRecordType->getDecl())) { // Add all of the conversion functions as candidates. - const UnresolvedSetImpl *Conversions - = FromRecordDecl->getVisibleConversionFunctions(); - for (UnresolvedSetImpl::iterator I = Conversions->begin(), - E = Conversions->end(); I != E; ++I) { + std::pair + Conversions = FromRecordDecl->getVisibleConversionFunctions(); + for (CXXRecordDecl::conversion_iterator + I = Conversions.first, E = Conversions.second; I != E; ++I) { DeclAccessPair FoundDecl = I.getPair(); NamedDecl *D = FoundDecl.getDecl(); CXXRecordDecl *ActingContext = cast(D->getDeclContext()); @@ -3959,10 +3960,11 @@ FindConversionForRefInit(Sema &S, ImplicitConversionSequence &ICS, = dyn_cast(T2->getAs()->getDecl()); OverloadCandidateSet CandidateSet(DeclLoc); - const UnresolvedSetImpl *Conversions - = T2RecordDecl->getVisibleConversionFunctions(); - for (UnresolvedSetImpl::iterator I = Conversions->begin(), - E = Conversions->end(); I != E; ++I) { + std::pair + Conversions = T2RecordDecl->getVisibleConversionFunctions(); + for (CXXRecordDecl::conversion_iterator + I = Conversions.first, E = Conversions.second; I != E; ++I) { NamedDecl *D = *I; CXXRecordDecl *ActingDC = cast(D->getDeclContext()); if (isa(D)) @@ -5104,15 +5106,15 @@ Sema::ConvertToIntegralOrEnumerationType(SourceLocation Loc, Expr *From, // Look for a conversion to an integral or enumeration type. UnresolvedSet<4> ViableConversions; UnresolvedSet<4> ExplicitConversions; - const UnresolvedSetImpl *Conversions + std::pair Conversions = cast(RecordTy->getDecl())->getVisibleConversionFunctions(); - bool HadMultipleCandidates = (Conversions->size() > 1); + bool HadMultipleCandidates + = (std::distance(Conversions.first, Conversions.second) > 1); - for (UnresolvedSetImpl::iterator I = Conversions->begin(), - E = Conversions->end(); - I != E; - ++I) { + for (CXXRecordDecl::conversion_iterator + I = Conversions.first, E = Conversions.second; I != E; ++I) { if (CXXConversionDecl *Conversion = dyn_cast((*I)->getUnderlyingDecl())) { if (isIntegralOrEnumerationType( @@ -6286,10 +6288,11 @@ BuiltinCandidateTypeSet::AddTypesConvertedFrom(QualType Ty, return; CXXRecordDecl *ClassDecl = cast(TyRec->getDecl()); - const UnresolvedSetImpl *Conversions - = ClassDecl->getVisibleConversionFunctions(); - for (UnresolvedSetImpl::iterator I = Conversions->begin(), - E = Conversions->end(); I != E; ++I) { + std::pair + Conversions = ClassDecl->getVisibleConversionFunctions(); + for (CXXRecordDecl::conversion_iterator + I = Conversions.first, E = Conversions.second; I != E; ++I) { NamedDecl *D = I.getDecl(); if (isa(D)) D = cast(D)->getTargetDecl(); @@ -6355,11 +6358,12 @@ static Qualifiers CollectVRQualifiers(ASTContext &Context, Expr* ArgExpr) { if (!ClassDecl->hasDefinition()) return VRQuals; - const UnresolvedSetImpl *Conversions = - ClassDecl->getVisibleConversionFunctions(); + std::pair + Conversions = ClassDecl->getVisibleConversionFunctions(); - for (UnresolvedSetImpl::iterator I = Conversions->begin(), - E = Conversions->end(); I != E; ++I) { + for (CXXRecordDecl::conversion_iterator + I = Conversions.first, E = Conversions.second; I != E; ++I) { NamedDecl *D = I.getDecl(); if (isa(D)) D = cast(D)->getTargetDecl(); @@ -10878,10 +10882,11 @@ Sema::BuildCallToObjectOfClassType(Scope *S, Expr *Obj, // functions for each conversion function declared in an // accessible base class provided the function is not hidden // within T by another intervening declaration. - const UnresolvedSetImpl *Conversions + std::pair Conversions = cast(Record->getDecl())->getVisibleConversionFunctions(); - for (UnresolvedSetImpl::iterator I = Conversions->begin(), - E = Conversions->end(); I != E; ++I) { + for (CXXRecordDecl::conversion_iterator + I = Conversions.first, E = Conversions.second; I != E; ++I) { NamedDecl *D = *I; CXXRecordDecl *ActingContext = cast(D->getDeclContext()); if (isa(D)) diff --git a/lib/Sema/SemaPseudoObject.cpp b/lib/Sema/SemaPseudoObject.cpp index a8d75b290f..74d0818b0e 100644 --- a/lib/Sema/SemaPseudoObject.cpp +++ b/lib/Sema/SemaPseudoObject.cpp @@ -954,16 +954,15 @@ Sema::ObjCSubscriptKind // objective-C pointer type. UnresolvedSet<4> ViableConversions; UnresolvedSet<4> ExplicitConversions; - const UnresolvedSetImpl *Conversions + std::pair Conversions = cast(RecordTy->getDecl())->getVisibleConversionFunctions(); int NoIntegrals=0, NoObjCIdPointers=0; SmallVector ConversionDecls; - for (UnresolvedSetImpl::iterator I = Conversions->begin(), - E = Conversions->end(); - I != E; - ++I) { + for (CXXRecordDecl::conversion_iterator + I = Conversions.first, E = Conversions.second; I != E; ++I) { if (CXXConversionDecl *Conversion = dyn_cast((*I)->getUnderlyingDecl())) { QualType CT = Conversion->getConversionType().getNonReferenceType(); -- 2.40.0