Add Self- and SelfWitnessTable metadata sources to capture descriptors

These can show up in partial applications of functions with the
witness_method calling convention.
This commit is contained in:
David Farler
2016-04-22 10:40:04 -07:00
parent 09d0cfee8d
commit 6a51ae84b2
5 changed files with 98 additions and 2 deletions

View File

@@ -182,6 +182,9 @@ class MetadataSource {
return decodeGenericArgument(A, it, end);
case 'P':
return decodeParent(A, it, end);
case 'S':
++it;
return A.template createSelf();
default:
return nullptr;
}
@@ -315,6 +318,7 @@ public:
}
};
/// Metadata gotten through the parent of a nominal type's metadata.
class ParentMetadataSource final : public MetadataSource {
const MetadataSource *Child;
public:
@@ -337,6 +341,41 @@ public:
}
};
/// A source of metadata from the Self metadata parameter passed via
/// a witness_method convention function.
class SelfMetadataSource final : public MetadataSource {
public:
SelfMetadataSource() : MetadataSource(MetadataSourceKind::Self) {}
template <typename Allocator>
static const SelfMetadataSource*
create(Allocator &A) {
return A.template make_source<SelfMetadataSource>();
}
static bool classof(const MetadataSource *MS) {
return MS->getKind() == MetadataSourceKind::Self;
}
};
/// A source of metadata from the Self witness table parameter passed via
/// a witness_method convention function.
class SelfWitnessTableMetadataSource final : public MetadataSource {
public:
SelfWitnessTableMetadataSource()
: MetadataSource(MetadataSourceKind::SelfWitnessTable) {}
template <typename Allocator>
static const SelfWitnessTableMetadataSource*
create(Allocator &A) {
return A.template make_source<SelfWitnessTableMetadataSource>();
}
static bool classof(const MetadataSource *MS) {
return MS->getKind() == MetadataSourceKind::SelfWitnessTable;
}
};
template <typename ImplClass, typename RetTy = void, typename... Args>
class MetadataSourceVisitor {
public:

View File

@@ -62,6 +62,16 @@ public:
createParent(const MetadataSource *Child) {
return ParentMetadataSource::create(*this, Child);
}
const SelfMetadataSource *
createSelf() {
return SelfMetadataSource::create(*this);
}
const SelfWitnessTableMetadataSource *
createSelfWitnessTable() {
return SelfWitnessTableMetadataSource::create(*this);
}
};
} // end namespace reflection

View File

@@ -21,3 +21,5 @@ METADATA_SOURCE(ReferenceCapture, MetadataSource)
METADATA_SOURCE(MetadataCapture, MetadataSource)
METADATA_SOURCE(GenericArgument, MetadataSource)
METADATA_SOURCE(Parent, MetadataSource)
METADATA_SOURCE(Self, MetadataSource)
METADATA_SOURCE(SelfWitnessTable, MetadataSource)