mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
MetadataSource Improvements: Builder; Parent, Impossible kinds
Create a builder divorced from the ReflectionContext so that MetadataSources can be created in other contexts, such as emitting private heap metadata during IRGen, where we'll have to record the layout of captures and how to get metadata for generic arguments in order to construct typerefs of the captures, etc. Add Parent, Metadata capture, and Impossible metadata sources.
This commit is contained in:
@@ -12,6 +12,8 @@
|
||||
|
||||
#include "swift/Reflection/MetadataSource.h"
|
||||
|
||||
#include <sstream>
|
||||
|
||||
using namespace swift;
|
||||
using namespace reflection;
|
||||
|
||||
@@ -70,6 +72,13 @@ public:
|
||||
closeForm();
|
||||
}
|
||||
|
||||
void
|
||||
visitMetadataCaptureMetadataSource(const MetadataCaptureMetadataSource *MC){
|
||||
printHeader("metadata-capture");
|
||||
printField("index", MC->getIndex());
|
||||
closeForm();
|
||||
}
|
||||
|
||||
void
|
||||
visitGenericArgumentMetadataSource(const GenericArgumentMetadataSource *GA) {
|
||||
printHeader("generic-argument");
|
||||
@@ -77,6 +86,67 @@ public:
|
||||
printRec(GA->getSource());
|
||||
closeForm();
|
||||
}
|
||||
|
||||
void
|
||||
visitParentMetadataSource(const ParentMetadataSource *P) {
|
||||
printHeader("parent-of");
|
||||
printRec(P->getChild());
|
||||
closeForm();
|
||||
}
|
||||
|
||||
void
|
||||
visitImpossibleMetadataSource(const ImpossibleMetadataSource *I) {
|
||||
printHeader("impossible");
|
||||
closeForm();
|
||||
}
|
||||
};
|
||||
|
||||
class MetadataSourceEncoder
|
||||
: public MetadataSourceVisitor<MetadataSourceEncoder> {
|
||||
std::stringstream OS;
|
||||
bool Finalized = false;
|
||||
public:
|
||||
void
|
||||
visitClosureBindingMetadataSource(const ClosureBindingMetadataSource *CB) {
|
||||
OS << 'B';
|
||||
OS << CB->getIndex();
|
||||
}
|
||||
|
||||
void
|
||||
visitReferenceCaptureMetadataSource(const ReferenceCaptureMetadataSource *RC){
|
||||
OS << 'R';
|
||||
OS << RC->getIndex();
|
||||
}
|
||||
|
||||
void
|
||||
visitMetadataCaptureMetadataSource(const MetadataCaptureMetadataSource *MC) {
|
||||
OS << 'M';
|
||||
OS << MC->getIndex();
|
||||
}
|
||||
|
||||
void
|
||||
visitGenericArgumentMetadataSource(const GenericArgumentMetadataSource *GA) {
|
||||
OS << 'G';
|
||||
OS << GA->getIndex();
|
||||
visit(GA->getSource());
|
||||
OS << '_';
|
||||
}
|
||||
|
||||
void visitParentMetadataSource(const ParentMetadataSource *P) {
|
||||
OS << 'P';
|
||||
visit(P->getChild());
|
||||
OS << '_';
|
||||
}
|
||||
|
||||
void visitImpossibleMetadataSource(const ImpossibleMetadataSource *I) {
|
||||
OS << 'I';
|
||||
}
|
||||
|
||||
std::string finalize() {
|
||||
assert(!Finalized && "Attempted to reuse finalized MetadataSourceEncoder");
|
||||
Finalized = true;
|
||||
return OS.str();
|
||||
}
|
||||
};
|
||||
|
||||
void MetadataSource::dump() const {
|
||||
@@ -85,5 +155,15 @@ void MetadataSource::dump() const {
|
||||
|
||||
void MetadataSource::dump(std::ostream &OS, unsigned Indent) const {
|
||||
PrintMetadataSource(OS, Indent).visit(this);
|
||||
OS << std::endl;
|
||||
}
|
||||
|
||||
std::string MetadataSource::encode() const {
|
||||
MetadataSourceEncoder Encoder;
|
||||
Encoder.visit(this);
|
||||
return Encoder.finalize();
|
||||
}
|
||||
|
||||
const ImpossibleMetadataSource *
|
||||
ImpossibleMetadataSource::Singleton = new ImpossibleMetadataSource();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user