diff options
author | Bruno Ricci <riccibrun@gmail.com> | 2019-01-28 14:18:11 +0000 |
---|---|---|
committer | Bruno Ricci <riccibrun@gmail.com> | 2019-01-28 14:18:11 +0000 |
commit | b43033c532d2cea761b9766ed4b47d7b7840693b (patch) | |
tree | b378e9cfe08cb50554c1a9761cc1f09895cd1287 /lib | |
parent | 62765d829f254f8888a8fa18a2ea091193f0e40e (diff) | |
download | clang-b43033c532d2cea761b9766ed4b47d7b7840693b.tar.gz |
[AST] Introduce GenericSelectionExpr::Association
Introduce a new class GenericSelectionExpr::Association which bundle together
an association expression and its TypeSourceInfo.
An iterator GenericSelectionExpr::AssociationIterator is additionally added to
make it possible to iterate over ranges of Associations. This iterator is a
kind of proxy iterator which abstract over how exactly the expressions and the
TypeSourceInfos are stored.
Differential Revision: https://reviews.llvm.org/D57106
Reviewed By: aaron.ballman
Reviewers: aaron.ballman, steveire, dblaikie, mclow.lists
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@352369 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r-- | lib/AST/ASTDumper.cpp | 10 | ||||
-rw-r--r-- | lib/AST/StmtPrinter.cpp | 6 | ||||
-rw-r--r-- | lib/AST/StmtProfile.cpp | 7 | ||||
-rw-r--r-- | lib/Sema/SemaExprObjC.cpp | 16 | ||||
-rw-r--r-- | lib/Sema/SemaPseudoObject.cpp | 22 | ||||
-rw-r--r-- | lib/Sema/TreeTransform.h | 11 |
6 files changed, 40 insertions, 32 deletions
diff --git a/lib/AST/ASTDumper.cpp b/lib/AST/ASTDumper.cpp index b91dab5aa3..5c99dab356 100644 --- a/lib/AST/ASTDumper.cpp +++ b/lib/AST/ASTDumper.cpp @@ -1462,21 +1462,21 @@ void ASTDumper::VisitGenericSelectionExpr(const GenericSelectionExpr *E) { dumpStmt(E->getControllingExpr()); dumpTypeAsChild(E->getControllingExpr()->getType()); // FIXME: remove - for (unsigned I = 0, N = E->getNumAssocs(); I != N; ++I) { + for (const auto &Assoc : E->associations()) { dumpChild([=] { - if (const TypeSourceInfo *TSI = E->getAssocTypeSourceInfo(I)) { + if (const TypeSourceInfo *TSI = Assoc.getTypeSourceInfo()) { OS << "case "; NodeDumper.dumpType(TSI->getType()); } else { OS << "default"; } - if (!E->isResultDependent() && E->getResultIndex() == I) + if (Assoc.isSelected()) OS << " selected"; - if (const TypeSourceInfo *TSI = E->getAssocTypeSourceInfo(I)) + if (const TypeSourceInfo *TSI = Assoc.getTypeSourceInfo()) dumpTypeAsChild(TSI->getType()); - dumpStmt(E->getAssocExpr(I)); + dumpStmt(Assoc.getAssociationExpr()); }); } } diff --git a/lib/AST/StmtPrinter.cpp b/lib/AST/StmtPrinter.cpp index 221d134d33..acf19aaaf4 100644 --- a/lib/AST/StmtPrinter.cpp +++ b/lib/AST/StmtPrinter.cpp @@ -1261,15 +1261,15 @@ void StmtPrinter::VisitUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr *Node){ void StmtPrinter::VisitGenericSelectionExpr(GenericSelectionExpr *Node) { OS << "_Generic("; PrintExpr(Node->getControllingExpr()); - for (unsigned i = 0; i != Node->getNumAssocs(); ++i) { + for (const GenericSelectionExpr::Association &Assoc : Node->associations()) { OS << ", "; - QualType T = Node->getAssocType(i); + QualType T = Assoc.getType(); if (T.isNull()) OS << "default"; else T.print(OS, Policy); OS << ": "; - PrintExpr(Node->getAssocExpr(i)); + PrintExpr(Assoc.getAssociationExpr()); } OS << ")"; } diff --git a/lib/AST/StmtProfile.cpp b/lib/AST/StmtProfile.cpp index 8f8de61f34..c064ea90a2 100644 --- a/lib/AST/StmtProfile.cpp +++ b/lib/AST/StmtProfile.cpp @@ -1259,13 +1259,14 @@ void StmtProfiler::VisitBlockExpr(const BlockExpr *S) { void StmtProfiler::VisitGenericSelectionExpr(const GenericSelectionExpr *S) { VisitExpr(S); - for (unsigned i = 0; i != S->getNumAssocs(); ++i) { - QualType T = S->getAssocType(i); + for (const GenericSelectionExpr::ConstAssociation &Assoc : + S->associations()) { + QualType T = Assoc.getType(); if (T.isNull()) ID.AddPointer(nullptr); else VisitType(T); - VisitExpr(S->getAssocExpr(i)); + VisitExpr(Assoc.getAssociationExpr()); } } diff --git a/lib/Sema/SemaExprObjC.cpp b/lib/Sema/SemaExprObjC.cpp index 4ca3b851c1..fdb59874cc 100644 --- a/lib/Sema/SemaExprObjC.cpp +++ b/lib/Sema/SemaExprObjC.cpp @@ -4332,14 +4332,16 @@ Expr *Sema::stripARCUnbridgedCast(Expr *e) { assert(!gse->isResultDependent()); unsigned n = gse->getNumAssocs(); - SmallVector<Expr*, 4> subExprs(n); - SmallVector<TypeSourceInfo*, 4> subTypes(n); - for (unsigned i = 0; i != n; ++i) { - subTypes[i] = gse->getAssocTypeSourceInfo(i); - Expr *sub = gse->getAssocExpr(i); - if (i == gse->getResultIndex()) + SmallVector<Expr *, 4> subExprs; + SmallVector<TypeSourceInfo *, 4> subTypes; + subExprs.reserve(n); + subTypes.reserve(n); + for (const GenericSelectionExpr::Association &assoc : gse->associations()) { + subTypes.push_back(assoc.getTypeSourceInfo()); + Expr *sub = assoc.getAssociationExpr(); + if (assoc.isSelected()) sub = stripARCUnbridgedCast(sub); - subExprs[i] = sub; + subExprs.push_back(sub); } return GenericSelectionExpr::Create( diff --git a/lib/Sema/SemaPseudoObject.cpp b/lib/Sema/SemaPseudoObject.cpp index 37dd7b1e8d..28a4d62b03 100644 --- a/lib/Sema/SemaPseudoObject.cpp +++ b/lib/Sema/SemaPseudoObject.cpp @@ -140,19 +140,23 @@ namespace { unsigned resultIndex = gse->getResultIndex(); unsigned numAssocs = gse->getNumAssocs(); - SmallVector<Expr*, 8> assocs(numAssocs); - SmallVector<TypeSourceInfo*, 8> assocTypes(numAssocs); - - for (unsigned i = 0; i != numAssocs; ++i) { - Expr *assoc = gse->getAssocExpr(i); - if (i == resultIndex) assoc = rebuild(assoc); - assocs[i] = assoc; - assocTypes[i] = gse->getAssocTypeSourceInfo(i); + SmallVector<Expr *, 8> assocExprs; + SmallVector<TypeSourceInfo *, 8> assocTypes; + assocExprs.reserve(numAssocs); + assocTypes.reserve(numAssocs); + + for (const GenericSelectionExpr::Association &assoc : + gse->associations()) { + Expr *assocExpr = assoc.getAssociationExpr(); + if (assoc.isSelected()) + assocExpr = rebuild(assocExpr); + assocExprs.push_back(assocExpr); + assocTypes.push_back(assoc.getTypeSourceInfo()); } return GenericSelectionExpr::Create( S.Context, gse->getGenericLoc(), gse->getControllingExpr(), - assocTypes, assocs, gse->getDefaultLoc(), gse->getRParenLoc(), + assocTypes, assocExprs, gse->getDefaultLoc(), gse->getRParenLoc(), gse->containsUnexpandedParameterPack(), resultIndex); } diff --git a/lib/Sema/TreeTransform.h b/lib/Sema/TreeTransform.h index 389031d491..2e434a3c0e 100644 --- a/lib/Sema/TreeTransform.h +++ b/lib/Sema/TreeTransform.h @@ -9071,10 +9071,10 @@ TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) { SmallVector<Expr *, 4> AssocExprs; SmallVector<TypeSourceInfo *, 4> AssocTypes; - for (unsigned i = 0; i != E->getNumAssocs(); ++i) { - TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i); - if (TS) { - TypeSourceInfo *AssocType = getDerived().TransformType(TS); + for (const GenericSelectionExpr::Association &Assoc : E->associations()) { + TypeSourceInfo *TSI = Assoc.getTypeSourceInfo(); + if (TSI) { + TypeSourceInfo *AssocType = getDerived().TransformType(TSI); if (!AssocType) return ExprError(); AssocTypes.push_back(AssocType); @@ -9082,7 +9082,8 @@ TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) { AssocTypes.push_back(nullptr); } - ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i)); + ExprResult AssocExpr = + getDerived().TransformExpr(Assoc.getAssociationExpr()); if (AssocExpr.isInvalid()) return ExprError(); AssocExprs.push_back(AssocExpr.get()); |