forked from swiftlang/swift
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMetadataLayout.h
92 lines (75 loc) · 2.88 KB
/
MetadataLayout.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
//===--- MetadataLayout.h - CRTP for metadata layout ------------*- C++ -*-===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2015 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See http://swift.org/LICENSE.txt for license information
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
//
// A CRTP helper class for laying out type metadata.
//
//===----------------------------------------------------------------------===//
#ifndef SWIFT_IRGEN_METADATALAYOUT_H
#define SWIFT_IRGEN_METADATALAYOUT_H
#include "llvm/ADT/SmallVector.h"
#include "swift/AST/Decl.h"
#include "swift/SIL/TypeLowering.h"
#include "GenProto.h"
namespace swift {
namespace irgen {
class IRGenModule;
/// A CRTP class for laying out type metadata. Note that this does
/// *not* handle the metadata template stuff.
template <class Impl> class MetadataLayout {
protected:
Impl &asImpl() { return *static_cast<Impl*>(this); }
protected:
IRGenModule &IGM;
MetadataLayout(IRGenModule &IGM) : IGM(IGM) {}
public:
void layout() {
// Common fields.
asImpl().addValueWitnessTable();
asImpl().noteAddressPoint();
asImpl().addMetadataFlags();
}
/// This is the address point.
void noteAddressPoint() {}
/// Add fields related to the generics of this class declaration.
/// TODO: don't add new fields that are implied by the superclass
/// fields. e.g., if B<T> extends A<T>, the witness for T in A's
/// section should be enough.
template <class... T>
void addGenericFields(const GenericParamList &generics,
T &&...args) {
// The archetype order here needs to be consistent with
// NominalTypeDescriptorBase::addGenericParams.
// Note that we intentionally don't forward the generic arguments.
// Add all the primary archetypes.
// TODO: only the *primary* archetypes.
// TODO: not archetypes from outer contexts.
for (auto archetype : generics.getAllArchetypes()) {
asImpl().addGenericArgument(archetype, args...);
}
// Add protocol witness tables for those archetypes.
for (auto archetype : generics.getAllArchetypes()) {
asImpl().beginGenericWitnessTables(archetype, args...);
for (auto protocol : archetype->getConformsTo()) {
if (Lowering::TypeConverter::protocolRequiresWitnessTable(protocol))
asImpl().addGenericWitnessTable(archetype, protocol, args...);
}
asImpl().endGenericWitnessTables(archetype, args...);
}
}
template <class... T>
void beginGenericWitnessTables(ArchetypeType *type, T &&...args) {}
template <class... T>
void endGenericWitnessTables(ArchetypeType *type, T &&...args) {}
};
} // end namespace irgen
} // end namespace swift
#endif