mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[serialization] Serialize DeclContexts, VarDecls, and StructTypes.
Unlike Clang, Swift's DeclContexts are not all Decls. However, I believe each DeclContext that is /serialized/ will be either a decl, a TranslationUnit, or a FuncExpr for a function with an actual declaration. This might turn out to be wrong if (a) SIL needs proper DeclContexts for variables in function bodies, or (b) we need to serialize anonymous closure default arguments. Along with an extension of the ConstructorDecl placeholder code, this allows us to round-trip empty structs. Swift SVN r5532
This commit is contained in:
@@ -45,17 +45,15 @@ enum class DeclOrType {
|
||||
IsType
|
||||
};
|
||||
|
||||
// The serialized format uses 32 bits for potential alignment benefits, even
|
||||
// though bitcode is generally unaligned.
|
||||
using DeclID = Fixnum<31>;
|
||||
using DeclIDField = BCFixed<32>;
|
||||
using DeclIDField = BCFixed<31>;
|
||||
|
||||
// TypeID must be the same as DeclID because it is stored in the same way.
|
||||
using TypeID = DeclID;
|
||||
using TypeIDField = DeclIDField;
|
||||
|
||||
using BitOffset = Fixnum<31>;
|
||||
using BitOffsetField = BCFixed<32>;
|
||||
using BitOffsetField = BCFixed<31>;
|
||||
|
||||
|
||||
/// The various types of blocks that can occur within a serialized Swift
|
||||
@@ -140,10 +138,12 @@ namespace decls_block {
|
||||
enum : uint8_t {
|
||||
BUILTIN_TYPE = 1,
|
||||
NAME_ALIAS_TYPE,
|
||||
STRUCT_TYPE,
|
||||
|
||||
TYPE_ALIAS_DECL = 100,
|
||||
STRUCT_DECL,
|
||||
CONSTRUCTOR_DECL,
|
||||
VAR_DECL,
|
||||
|
||||
DECL_CONTEXT = 254,
|
||||
NAME_HACK = 255
|
||||
@@ -159,8 +159,15 @@ namespace decls_block {
|
||||
DeclIDField // typealias decl
|
||||
>;
|
||||
|
||||
using StructTypeLayout = BCRecordLayout<
|
||||
STRUCT_TYPE,
|
||||
DeclIDField, // struct decl
|
||||
TypeIDField // parent
|
||||
>;
|
||||
|
||||
using TypeAliasLayout = BCRecordLayout<
|
||||
TYPE_ALIAS_DECL,
|
||||
DeclIDField, // context decl
|
||||
TypeIDField, // underlying type
|
||||
BCFixed<1>, // generic flag
|
||||
BCFixed<1>, // implicit flag
|
||||
@@ -169,14 +176,27 @@ namespace decls_block {
|
||||
|
||||
using StructLayout = BCRecordLayout<
|
||||
STRUCT_DECL,
|
||||
DeclIDField, // context decl
|
||||
BCFixed<1>, // implicit flag
|
||||
BCArray<TypeIDField> // inherited types
|
||||
>;
|
||||
|
||||
using ConstructorLayout = BCRecordLayout<
|
||||
CONSTRUCTOR_DECL,
|
||||
BCFixed<1>, // implicit flag
|
||||
DeclIDField // implicit this decl
|
||||
DeclIDField, // context decl
|
||||
BCFixed<1>, // implicit flag
|
||||
DeclIDField // implicit this decl
|
||||
>;
|
||||
|
||||
using VarLayout = BCRecordLayout<
|
||||
VAR_DECL,
|
||||
DeclIDField, // context decl
|
||||
BCFixed<1>, // implicit flag
|
||||
BCFixed<1>, // never lvalue flag
|
||||
TypeIDField, // type
|
||||
DeclIDField, // getter
|
||||
DeclIDField, // setter
|
||||
DeclIDField // overridden decl
|
||||
>;
|
||||
|
||||
using DeclContextLayout = BCRecordLayout<
|
||||
|
||||
Reference in New Issue
Block a user