SILGen: Add a new RValue(AbstractionPattern, CanType) constructor

This commit is contained in:
Slava Pestov
2016-01-11 18:35:12 -08:00
parent a6de98460d
commit 1dff04ebe7
2 changed files with 25 additions and 0 deletions

View File

@@ -19,6 +19,7 @@
#include "Initialization.h"
#include "RValue.h"
#include "swift/SIL/AbstractionPattern.h"
#include "swift/SIL/SILArgument.h"
#include "swift/AST/CanTypeVisitor.h"
#include "swift/Basic/Fallthrough.h"
@@ -33,6 +34,20 @@ static unsigned getTupleSize(CanType t) {
return 1;
}
static unsigned getRValueSize(AbstractionPattern pattern, CanType formalType) {
if (pattern.isTuple()) {
unsigned count = 0;
auto formalTupleType = cast<TupleType>(formalType);
for (auto i : indices(formalTupleType.getElementTypes())) {
count += getRValueSize(pattern.getTupleElementType(i),
formalTupleType.getElementType(i));
}
return count;
}
return 1;
}
/// Return the number of rvalue elements in the given canonical type.
static unsigned getRValueSize(CanType type) {
if (auto tupleType = dyn_cast<TupleType>(type)) {
@@ -393,6 +408,10 @@ RValue::RValue(CanType type)
: type(type), elementsToBeAdded(getTupleSize(type)) {
}
RValue::RValue(AbstractionPattern pattern, CanType type)
: type(type), elementsToBeAdded(getRValueSize(pattern, type)) {
}
void RValue::addElement(RValue &&element) & {
assert(!element.isUsed() && "adding consumed value to r-value");
assert(!isComplete() && "rvalue already complete");