Add GenericSubscriptExpr to represent subscripting into a generic type.

Swift SVN r2336
This commit is contained in:
Eli Friedman
2012-07-10 23:39:46 +00:00
parent 908cf4573f
commit 43e7559310
8 changed files with 164 additions and 1 deletions

View File

@@ -254,6 +254,15 @@ ArchetypeSubscriptExpr(Expr *Base, SourceLoc LBracketLoc, Expr *Index,
"use SubscriptExpr for non-archetype type subscript");
}
GenericSubscriptExpr::
GenericSubscriptExpr(Expr *Base, SourceLoc LBracketLoc, Expr *Index,
SourceLoc RBracketLoc, SubscriptDecl *D)
: Expr(ExprKind::GenericSubscript, D? D->getElementType() : Type()),
D(D), Brackets(LBracketLoc, RBracketLoc), Base(Base), Index(Index) {
assert(Base->getType()->getRValueType()->is<BoundGenericType>() &&
"use SubscriptExpr for non-generic type subscript");
}
Expr *OverloadedSubscriptExpr::createWithCopy(Expr *Base,
ArrayRef<ValueDecl*> Decls,
SourceLoc LBracketLoc,
@@ -274,6 +283,11 @@ Expr *OverloadedSubscriptExpr::createWithCopy(Expr *Base,
RBracketLoc,
cast<SubscriptDecl>(Decls[0]));
if (ContainerTy->is<BoundGenericType>())
return new (C) GenericSubscriptExpr(Base, LBracketLoc, Index,
RBracketLoc,
cast<SubscriptDecl>(Decls[0]));
return new (C) SubscriptExpr(Base, LBracketLoc, Index, RBracketLoc,
cast<SubscriptDecl>(Decls[0]));
}
@@ -505,6 +519,14 @@ public:
printRec(E->getIndex());
OS << ')';
}
void visitGenericSubscriptExpr(GenericSubscriptExpr *E) {
printCommon(E, "generic_subscript_expr");
OS << '\n';
printRec(E->getBase());
OS << '\n';
printRec(E->getIndex());
OS << ')';
}
void visitOverloadedSubscriptExpr(OverloadedSubscriptExpr *E) {
printCommon(E, "overloaded_subscript_expr");
OS << '\n';