Introduce "inherited" default arguments and use them for inherited initializers.

Previously, we were cloning the default arguments completely, which
meant code duplication (when inheriting within a module) or simply a
failure (when inheriting across modules). Now, we reference the
default arguments where we inherited them, eliminating the
duplication. Part of <rdar://problem/16318855>.

Swift SVN r15062
This commit is contained in:
Doug Gregor
2014-03-14 18:31:22 +00:00
parent 8cf018a1d2
commit d32f668fb2
10 changed files with 106 additions and 12 deletions

View File

@@ -222,10 +222,21 @@ Pattern *Pattern::clone(ASTContext &context,
auto tuple = cast<TuplePattern>(this);
SmallVector<TuplePatternElt, 2> elts;
elts.reserve(tuple->getNumFields());
for (const auto &elt : tuple->getFields())
elts.push_back(TuplePatternElt(elt.getPattern()->clone(context, options),
elt.getInit(),
elt.getDefaultArgKind()));
for (const auto &elt : tuple->getFields()) {
auto eltPattern = elt.getPattern()->clone(context, options);
// If we're inheriting a default argument, mark it as such.
if (elt.getDefaultArgKind() != DefaultArgumentKind::None &&
(options & Inherited)) {
elts.push_back(TuplePatternElt(eltPattern, nullptr,
DefaultArgumentKind::Inherited));
} else {
elts.push_back(TuplePatternElt(eltPattern,
elt.getInit(),
elt.getDefaultArgKind()));
}
}
result = TuplePattern::create(context, tuple->getLParenLoc(), elts,
tuple->getRParenLoc(),
tuple->hasVararg(),