[serialization] Add support for TupleTypes.

These are implementing using trailing TUPLE_TYPE_ELT records after the
initial TUPLE_TYPE record. This is the next step towards function decls.

Element initializers are silently ignored for now.

Also, do serialize a record for IdentifierTypes, even though we're not
including the components yet, so that we don't serialize the underlying
type more than once.

Swift SVN r5683
This commit is contained in:
Jordan Rose
2013-06-19 18:19:41 +00:00
parent ce84b185ea
commit dbf41543f5
5 changed files with 146 additions and 19 deletions

View File

@@ -13,6 +13,7 @@
#include "ModuleFile.h"
#include "ModuleFormat.h"
#include "swift/AST/AST.h"
#include "swift/Serialization/BCReadingExtras.h"
#include "llvm/Support/MemoryBuffer.h"
using namespace swift;
@@ -370,6 +371,46 @@ Type ModuleFile::getType(TypeID TID) {
break;
}
case decls_block::TUPLE_TYPE: {
// The tuple record itself is empty. Read all trailing elements.
SmallVector<TupleTypeElt, 8> elements;
while (true) {
auto entry = DeclTypeCursor.advance();
if (entry.Kind != llvm::BitstreamEntry::Record)
break;
scratch.clear();
unsigned recordID = DeclTypeCursor.readRecord(entry.ID, scratch,
&blobData);
if (recordID != decls_block::TUPLE_TYPE_ELT)
break;
IdentifierID nameID;
TypeID typeID;
TypeID varargBaseID;
decls_block::TupleTypeEltLayout::readRecord(scratch, nameID, typeID,
varargBaseID);
{
BCOffsetRAII restoreOffset(DeclTypeCursor);
elements.push_back({getType(typeID), getIdentifier(nameID),
/*initializer=*/nullptr, getType(varargBaseID)});
}
}
typeOrOffset = TupleType::get(elements, ModuleContext->Ctx);
break;
}
case decls_block::IDENTIFIER_TYPE: {
TypeID mappedID;
decls_block::IdentifierTypeLayout::readRecord(scratch, mappedID);
// FIXME: Actually recreate the IdentifierType instead of just aliasing the
// underlying mapped type.
typeOrOffset = getType(mappedID);
break;
}
default:
// We don't know how to deserialize this kind of type.
error();