From 714e84be4615d6e1195f2798c0c3c8c54017dd5f Mon Sep 17 00:00:00 2001 From: Florian Hahn Date: Thu, 4 Jun 2020 20:15:21 +0100 Subject: [PATCH] [SemaOverload] Use iterator_range to iterate over VectorTypes (NFC). We can simplify the code a bit by using iterator_range instead of plain iterators. Matrix type support here (added in 6f6e91d19337) already uses an iterator_range. Reviewers: rjmccall, arphaman, jfb, Bigcheese Reviewed By: rjmccall Differential Revision: https://reviews.llvm.org/D81138 --- clang/lib/Sema/SemaOverload.cpp | 47 ++++++++++------------------------------- 1 file changed, 11 insertions(+), 36 deletions(-) diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp index 11b6e40..f3ac203 100644 --- a/clang/lib/Sema/SemaOverload.cpp +++ b/clang/lib/Sema/SemaOverload.cpp @@ -7745,8 +7745,7 @@ public: /// enumeration_end - Past the last enumeration type found; iterator enumeration_end() { return EnumerationTypes.end(); } - iterator vector_begin() { return VectorTypes.begin(); } - iterator vector_end() { return VectorTypes.end(); } + llvm::iterator_range vector_types() { return VectorTypes; } llvm::iterator_range matrix_types() { return MatrixTypes; } @@ -8292,13 +8291,8 @@ public: } // Extension: We also add these operators for vector types. - for (BuiltinCandidateTypeSet::iterator - Vec = CandidateTypes[0].vector_begin(), - VecEnd = CandidateTypes[0].vector_end(); - Vec != VecEnd; ++Vec) { - QualType VecTy = *Vec; + for (QualType VecTy : CandidateTypes[0].vector_types()) S.AddBuiltinCandidate(&VecTy, Args, CandidateSet); - } } // C++ [over.built]p8: @@ -8332,13 +8326,8 @@ public: } // Extension: We also add this operator for vector types. - for (BuiltinCandidateTypeSet::iterator - Vec = CandidateTypes[0].vector_begin(), - VecEnd = CandidateTypes[0].vector_end(); - Vec != VecEnd; ++Vec) { - QualType VecTy = *Vec; + for (QualType VecTy : CandidateTypes[0].vector_types()) S.AddBuiltinCandidate(&VecTy, Args, CandidateSet); - } } // C++ [over.match.oper]p16: @@ -8569,18 +8558,11 @@ public: // Extension: Add the binary operators ==, !=, <, <=, >=, >, *, /, and the // conditional operator for vector types. - for (BuiltinCandidateTypeSet::iterator - Vec1 = CandidateTypes[0].vector_begin(), - Vec1End = CandidateTypes[0].vector_end(); - Vec1 != Vec1End; ++Vec1) { - for (BuiltinCandidateTypeSet::iterator - Vec2 = CandidateTypes[1].vector_begin(), - Vec2End = CandidateTypes[1].vector_end(); - Vec2 != Vec2End; ++Vec2) { - QualType LandR[2] = { *Vec1, *Vec2 }; + for (QualType Vec1Ty : CandidateTypes[0].vector_types()) + for (QualType Vec2Ty : CandidateTypes[1].vector_types()) { + QualType LandR[2] = {Vec1Ty, Vec2Ty}; S.AddBuiltinCandidate(LandR, Args, CandidateSet); } - } } /// Add binary operator overloads for each candidate matrix type M1, M2: @@ -8861,30 +8843,23 @@ public: } // Extension: Add the binary operators =, +=, -=, *=, /= for vector types. - for (BuiltinCandidateTypeSet::iterator - Vec1 = CandidateTypes[0].vector_begin(), - Vec1End = CandidateTypes[0].vector_end(); - Vec1 != Vec1End; ++Vec1) { - for (BuiltinCandidateTypeSet::iterator - Vec2 = CandidateTypes[1].vector_begin(), - Vec2End = CandidateTypes[1].vector_end(); - Vec2 != Vec2End; ++Vec2) { + for (QualType Vec1Ty : CandidateTypes[0].vector_types()) + for (QualType Vec2Ty : CandidateTypes[0].vector_types()) { QualType ParamTypes[2]; - ParamTypes[1] = *Vec2; + ParamTypes[1] = Vec2Ty; // Add this built-in operator as a candidate (VQ is empty). - ParamTypes[0] = S.Context.getLValueReferenceType(*Vec1); + ParamTypes[0] = S.Context.getLValueReferenceType(Vec1Ty); S.AddBuiltinCandidate(ParamTypes, Args, CandidateSet, /*IsAssignmentOperator=*/isEqualOp); // Add this built-in operator as a candidate (VQ is 'volatile'). if (VisibleTypeConversionsQuals.hasVolatile()) { - ParamTypes[0] = S.Context.getVolatileType(*Vec1); + ParamTypes[0] = S.Context.getVolatileType(Vec1Ty); ParamTypes[0] = S.Context.getLValueReferenceType(ParamTypes[0]); S.AddBuiltinCandidate(ParamTypes, Args, CandidateSet, /*IsAssignmentOperator=*/isEqualOp); } } - } } // C++ [over.built]p22: -- 2.7.4