Codify the default argument hack for __FILE__/__LINE__/__COLUMN__.

Teach TuplePatternElt to keep track of the kind of the default
argument: none, normal (provided by calling into the appropriate
callee generator), __FILE__, __LINE__, or __COLUMN__. For the latter
three cases, the type checker forms the appropriate argument as part
of the call. 

The actual default argument expression will only be held in the tuple
pattern element when we've parsed it; it won't be serialized or
deserialized, because only the defining module cares. This is a step
toward eliminate the initialization expression from tuple types.

The extension to TupleShuffleExpr is a hack, which will also be
replicated in ScalarToTupleExpr, until we finally rework the
representation of TupleShuffleExpr (<rdar://problem/12340004>).


Swift SVN r6299
This commit is contained in:
Doug Gregor
2013-07-16 22:52:38 +00:00
parent ca7c9cb95b
commit 423abc5038
14 changed files with 284 additions and 106 deletions

View File

@@ -86,6 +86,25 @@ validateControlBlock(llvm::BitstreamCursor &cursor,
return result;
}
/// Translate from the serialization DefaultArgumentKind enumerators, which are
/// guaranteed to be stable, to the AST ones.
static Optional<swift::DefaultArgumentKind>
getActualDefaultArgKind(uint8_t raw) {
switch (static_cast<serialization::DefaultArgumentKind>(raw)) {
case serialization::DefaultArgumentKind::None:
return swift::DefaultArgumentKind::None;
case serialization::DefaultArgumentKind::Normal:
return swift::DefaultArgumentKind::Normal;
case serialization::DefaultArgumentKind::Column:
return swift::DefaultArgumentKind::Column;
case serialization::DefaultArgumentKind::File:
return swift::DefaultArgumentKind::File;
case serialization::DefaultArgumentKind::Line:
return swift::DefaultArgumentKind::Line;
}
return Nothing;
}
Pattern *ModuleFile::maybeReadPattern() {
using namespace decls_block;
@@ -124,12 +143,21 @@ Pattern *ModuleFile::maybeReadPattern() {
assert(kind == decls_block::TUPLE_PATTERN_ELT);
// FIXME: Add something for this record or remove it.
// TuplePatternEltLayout::readRecord(scratch);
uint8_t rawDefaultArg;
TuplePatternEltLayout::readRecord(scratch, rawDefaultArg);
Pattern *subPattern = maybeReadPattern();
assert(subPattern);
elements.push_back(TuplePatternElt(subPattern, nullptr));
// Decode the default argument kind.
// FIXME: Default argument expression, if available.
swift::DefaultArgumentKind defaultArgKind
= swift::DefaultArgumentKind::None;
if (auto defaultArg = getActualDefaultArgKind(rawDefaultArg))
defaultArgKind = *defaultArg;
elements.push_back(TuplePatternElt(subPattern, nullptr,
defaultArgKind));
}
auto result = TuplePattern::create(ModuleContext->Ctx, SourceLoc(),