Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
// swift/stdlib/public/runtime/Metadata.cpp をプリプロセッサのみ実行した結果から抜粋
struct ValueWitnessTable;
namespace value_witness_types {
typedef OpaqueValue * (*initializeBufferWithCopyOfBuffer) (ValueBuffer *, ValueBuffer *, const Metadata *);
typedef void (*destroy) (OpaqueValue *, const Metadata *);
typedef OpaqueValue * (*initializeWithCopy) (OpaqueValue *, OpaqueValue *, const Metadata *);
typedef OpaqueValue * (*assignWithCopy) (OpaqueValue *, OpaqueValue *, const Metadata *);
typedef OpaqueValue * (*initializeWithTake) (OpaqueValue *, OpaqueValue *, const Metadata *);
typedef OpaqueValue * (*assignWithTake) (OpaqueValue *, OpaqueValue *, const Metadata *);
typedef unsigned (*getEnumTagSinglePayload) (const OpaqueValue *, unsigned, const Metadata *);
typedef void (*storeEnumTagSinglePayload) (OpaqueValue *, unsigned, unsigned, const Metadata *);
typedef void (*storeExtraInhabitant) (OpaqueValue *, int, const Metadata *);
typedef int (*getExtraInhabitantIndex) (const OpaqueValue *, const Metadata *);
typedef int (*getEnumTag) (const OpaqueValue *, const Metadata *);
typedef void (*destructiveProjectEnumData) (OpaqueValue *, const Metadata *);
typedef void (*destructiveInjectEnumTag) (OpaqueValue *, unsigned, const Metadata *);
typedef size_t size;
typedef ValueWitnessFlags flags;
typedef size_t stride;
typedef ExtraInhabitantFlags extraInhabitantFlags;
}
struct ValueWitnessTable {
value_witness_types::initializeBufferWithCopyOfBuffer initializeBufferWithCopyOfBuffer;
value_witness_types::destroy destroy;
value_witness_types::initializeWithCopy initializeWithCopy;
value_witness_types::assignWithCopy assignWithCopy;
value_witness_types::initializeWithTake initializeWithTake;
value_witness_types::assignWithTake assignWithTake;
value_witness_types::getEnumTagSinglePayload getEnumTagSinglePayload;
value_witness_types::storeEnumTagSinglePayload storeEnumTagSinglePayload;
value_witness_types::size size;
value_witness_types::flags flags;
value_witness_types::stride stride;
bool isIncomplete() const {
return flags.isIncomplete();
}
static bool isValueInline(bool isBitwiseTakable, size_t size, size_t alignment) {
return (isBitwiseTakable && size <= sizeof(ValueBuffer) &&
alignment <= alignof(ValueBuffer));
}
bool isValueInline() const {
return flags.isInlineStorage();
}
bool isPOD() const {
return flags.isPOD();
}
bool isBitwiseTakable() const {
return flags.isBitwiseTakable();
}
size_t getSize() const {
return size;
}
size_t getStride() const {
return stride;
}
size_t getAlignment() const {
return flags.getAlignment();
}
size_t getAlignmentMask() const {
return flags.getAlignmentMask();
}
unsigned getNumExtraInhabitants() const;
const struct ExtraInhabitantsValueWitnessTable *_asXIVWT() const;
const struct EnumValueWitnessTable *_asEVWT() const;
const TypeLayout *getTypeLayout() const {
return reinterpret_cast<const TypeLayout *>(&size);
}
bool checkIsComplete() const;
void publishLayout(const TypeLayout &layout);
};
struct ExtraInhabitantsValueWitnessTable : ValueWitnessTable {
value_witness_types::extraInhabitantFlags extraInhabitantFlags;
value_witness_types::storeExtraInhabitant storeExtraInhabitant;
value_witness_types::getExtraInhabitantIndex getExtraInhabitantIndex;
constexpr ExtraInhabitantsValueWitnessTable()
: ValueWitnessTable{}, extraInhabitantFlags(),
storeExtraInhabitant(nullptr),
getExtraInhabitantIndex(nullptr) {}
constexpr ExtraInhabitantsValueWitnessTable(
const ValueWitnessTable &base,
value_witness_types::extraInhabitantFlags eif,
value_witness_types::storeExtraInhabitant sei,
value_witness_types::getExtraInhabitantIndex geii)
: ValueWitnessTable(base),
extraInhabitantFlags(eif),
storeExtraInhabitant(sei),
getExtraInhabitantIndex(geii) {}
static bool classof(const ValueWitnessTable *table) {
return table->flags.hasExtraInhabitants();
}
};
struct EnumValueWitnessTable : ExtraInhabitantsValueWitnessTable {
value_witness_types::getEnumTag getEnumTag;
value_witness_types::destructiveProjectEnumData destructiveProjectEnumData;
value_witness_types::destructiveInjectEnumTag destructiveInjectEnumTag;
constexpr EnumValueWitnessTable()
: ExtraInhabitantsValueWitnessTable(),
getEnumTag(nullptr),
destructiveProjectEnumData(nullptr),
destructiveInjectEnumTag(nullptr) {}
constexpr EnumValueWitnessTable(
const ExtraInhabitantsValueWitnessTable &base,
value_witness_types::getEnumTag getEnumTag,
value_witness_types::destructiveProjectEnumData destructiveProjectEnumData,
value_witness_types::destructiveInjectEnumTag destructiveInjectEnumTag)
: ExtraInhabitantsValueWitnessTable(base),
getEnumTag(getEnumTag),
destructiveProjectEnumData(destructiveProjectEnumData),
destructiveInjectEnumTag(destructiveInjectEnumTag) {}
static bool classof(const ValueWitnessTable *table) {
return table->flags.hasEnumWitnesses();
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.