Unverified Commit 542e75c2 authored by Kenton Varda's avatar Kenton Varda Committed by GitHub

Merge pull request #643 from capnproto/harris/explicate-list-element-kinds-for-msvc

Explicate List element Kinds in generated code
parents 3079784b dc860e65
This diff is collapsed.
......@@ -301,6 +301,43 @@ kj::String KJ_STRINGIFY(const CppTypeName& typeName) {
}
}
CppTypeName whichKind(schema::Type::Which which) {
// Make a CppTypeName representing the capnp::Kind value for the given schema type. This makes
// CppTypeName conflate types and values, but this is all just a hack for MSVC's benefit. Its
// primary use is as a non-type template parameter to `capnp::List<T, K>` -- normally the Kind K
// is deduced via SFINAE, but MSVC just can't do it in certain cases, such as when a nested type
// of `capnp::List<T, K>` is the return type of a function, and the element type T is a template
// instantiation.
switch (which) {
case schema::Type::VOID: return CppTypeName::makePrimitive(" ::capnp::Kind::PRIMITIVE");
case schema::Type::BOOL: return CppTypeName::makePrimitive(" ::capnp::Kind::PRIMITIVE");
case schema::Type::INT8: return CppTypeName::makePrimitive(" ::capnp::Kind::PRIMITIVE");
case schema::Type::INT16: return CppTypeName::makePrimitive(" ::capnp::Kind::PRIMITIVE");
case schema::Type::INT32: return CppTypeName::makePrimitive(" ::capnp::Kind::PRIMITIVE");
case schema::Type::INT64: return CppTypeName::makePrimitive(" ::capnp::Kind::PRIMITIVE");
case schema::Type::UINT8: return CppTypeName::makePrimitive(" ::capnp::Kind::PRIMITIVE");
case schema::Type::UINT16: return CppTypeName::makePrimitive(" ::capnp::Kind::PRIMITIVE");
case schema::Type::UINT32: return CppTypeName::makePrimitive(" ::capnp::Kind::PRIMITIVE");
case schema::Type::UINT64: return CppTypeName::makePrimitive(" ::capnp::Kind::PRIMITIVE");
case schema::Type::FLOAT32: return CppTypeName::makePrimitive(" ::capnp::Kind::PRIMITIVE");
case schema::Type::FLOAT64: return CppTypeName::makePrimitive(" ::capnp::Kind::PRIMITIVE");
case schema::Type::TEXT: return CppTypeName::makePrimitive(" ::capnp::Kind::BLOB");
case schema::Type::DATA: return CppTypeName::makePrimitive(" ::capnp::Kind::BLOB");
case schema::Type::ENUM: return CppTypeName::makePrimitive(" ::capnp::Kind::ENUM");
case schema::Type::STRUCT: return CppTypeName::makePrimitive(" ::capnp::Kind::STRUCT");
case schema::Type::INTERFACE: return CppTypeName::makePrimitive(" ::capnp::Kind::INTERFACE");
case schema::Type::LIST: return CppTypeName::makePrimitive(" ::capnp::Kind::LIST");
case schema::Type::ANY_POINTER: return CppTypeName::makePrimitive(" ::capnp::Kind::OTHER");
}
KJ_UNREACHABLE;
}
// =======================================================================================
class CapnpcCppMain {
......@@ -473,8 +510,10 @@ private:
case schema::Type::LIST: {
CppTypeName result = CppTypeName::makeNamespace("capnp");
auto params = kj::heapArrayBuilder<CppTypeName>(1);
params.add(typeName(type.asList().getElementType(), method));
auto params = kj::heapArrayBuilder<CppTypeName>(2);
auto list = type.asList();
params.add(typeName(list.getElementType(), method));
params.add(whichKind(list.whichElementType()));
result.addMemberTemplate("List", params.finish());
return result;
}
......
This diff is collapsed.
This diff is collapsed.
......@@ -1922,7 +1922,7 @@ public:
inline ::capnp::AnyPointer::Reader getContent() const;
inline bool hasCapTable() const;
inline ::capnp::List< ::capnp::rpc::CapDescriptor>::Reader getCapTable() const;
inline ::capnp::List< ::capnp::rpc::CapDescriptor, ::capnp::Kind::STRUCT>::Reader getCapTable() const;
private:
::capnp::_::StructReader _reader;
......@@ -1957,11 +1957,11 @@ public:
inline ::capnp::AnyPointer::Builder initContent();
inline bool hasCapTable();
inline ::capnp::List< ::capnp::rpc::CapDescriptor>::Builder getCapTable();
inline void setCapTable( ::capnp::List< ::capnp::rpc::CapDescriptor>::Reader value);
inline ::capnp::List< ::capnp::rpc::CapDescriptor>::Builder initCapTable(unsigned int size);
inline void adoptCapTable(::capnp::Orphan< ::capnp::List< ::capnp::rpc::CapDescriptor>>&& value);
inline ::capnp::Orphan< ::capnp::List< ::capnp::rpc::CapDescriptor>> disownCapTable();
inline ::capnp::List< ::capnp::rpc::CapDescriptor, ::capnp::Kind::STRUCT>::Builder getCapTable();
inline void setCapTable( ::capnp::List< ::capnp::rpc::CapDescriptor, ::capnp::Kind::STRUCT>::Reader value);
inline ::capnp::List< ::capnp::rpc::CapDescriptor, ::capnp::Kind::STRUCT>::Builder initCapTable(unsigned int size);
inline void adoptCapTable(::capnp::Orphan< ::capnp::List< ::capnp::rpc::CapDescriptor, ::capnp::Kind::STRUCT>>&& value);
inline ::capnp::Orphan< ::capnp::List< ::capnp::rpc::CapDescriptor, ::capnp::Kind::STRUCT>> disownCapTable();
private:
::capnp::_::StructBuilder _builder;
......@@ -2134,7 +2134,7 @@ public:
inline ::uint32_t getQuestionId() const;
inline bool hasTransform() const;
inline ::capnp::List< ::capnp::rpc::PromisedAnswer::Op>::Reader getTransform() const;
inline ::capnp::List< ::capnp::rpc::PromisedAnswer::Op, ::capnp::Kind::STRUCT>::Reader getTransform() const;
private:
::capnp::_::StructReader _reader;
......@@ -2168,11 +2168,11 @@ public:
inline void setQuestionId( ::uint32_t value);
inline bool hasTransform();
inline ::capnp::List< ::capnp::rpc::PromisedAnswer::Op>::Builder getTransform();
inline void setTransform( ::capnp::List< ::capnp::rpc::PromisedAnswer::Op>::Reader value);
inline ::capnp::List< ::capnp::rpc::PromisedAnswer::Op>::Builder initTransform(unsigned int size);
inline void adoptTransform(::capnp::Orphan< ::capnp::List< ::capnp::rpc::PromisedAnswer::Op>>&& value);
inline ::capnp::Orphan< ::capnp::List< ::capnp::rpc::PromisedAnswer::Op>> disownTransform();
inline ::capnp::List< ::capnp::rpc::PromisedAnswer::Op, ::capnp::Kind::STRUCT>::Builder getTransform();
inline void setTransform( ::capnp::List< ::capnp::rpc::PromisedAnswer::Op, ::capnp::Kind::STRUCT>::Reader value);
inline ::capnp::List< ::capnp::rpc::PromisedAnswer::Op, ::capnp::Kind::STRUCT>::Builder initTransform(unsigned int size);
inline void adoptTransform(::capnp::Orphan< ::capnp::List< ::capnp::rpc::PromisedAnswer::Op, ::capnp::Kind::STRUCT>>&& value);
inline ::capnp::Orphan< ::capnp::List< ::capnp::rpc::PromisedAnswer::Op, ::capnp::Kind::STRUCT>> disownTransform();
private:
::capnp::_::StructBuilder _builder;
......@@ -4422,29 +4422,29 @@ inline bool Payload::Builder::hasCapTable() {
return !_builder.getPointerField(
::capnp::bounded<1>() * ::capnp::POINTERS).isNull();
}
inline ::capnp::List< ::capnp::rpc::CapDescriptor>::Reader Payload::Reader::getCapTable() const {
return ::capnp::_::PointerHelpers< ::capnp::List< ::capnp::rpc::CapDescriptor>>::get(_reader.getPointerField(
inline ::capnp::List< ::capnp::rpc::CapDescriptor, ::capnp::Kind::STRUCT>::Reader Payload::Reader::getCapTable() const {
return ::capnp::_::PointerHelpers< ::capnp::List< ::capnp::rpc::CapDescriptor, ::capnp::Kind::STRUCT>>::get(_reader.getPointerField(
::capnp::bounded<1>() * ::capnp::POINTERS));
}
inline ::capnp::List< ::capnp::rpc::CapDescriptor>::Builder Payload::Builder::getCapTable() {
return ::capnp::_::PointerHelpers< ::capnp::List< ::capnp::rpc::CapDescriptor>>::get(_builder.getPointerField(
inline ::capnp::List< ::capnp::rpc::CapDescriptor, ::capnp::Kind::STRUCT>::Builder Payload::Builder::getCapTable() {
return ::capnp::_::PointerHelpers< ::capnp::List< ::capnp::rpc::CapDescriptor, ::capnp::Kind::STRUCT>>::get(_builder.getPointerField(
::capnp::bounded<1>() * ::capnp::POINTERS));
}
inline void Payload::Builder::setCapTable( ::capnp::List< ::capnp::rpc::CapDescriptor>::Reader value) {
::capnp::_::PointerHelpers< ::capnp::List< ::capnp::rpc::CapDescriptor>>::set(_builder.getPointerField(
inline void Payload::Builder::setCapTable( ::capnp::List< ::capnp::rpc::CapDescriptor, ::capnp::Kind::STRUCT>::Reader value) {
::capnp::_::PointerHelpers< ::capnp::List< ::capnp::rpc::CapDescriptor, ::capnp::Kind::STRUCT>>::set(_builder.getPointerField(
::capnp::bounded<1>() * ::capnp::POINTERS), value);
}
inline ::capnp::List< ::capnp::rpc::CapDescriptor>::Builder Payload::Builder::initCapTable(unsigned int size) {
return ::capnp::_::PointerHelpers< ::capnp::List< ::capnp::rpc::CapDescriptor>>::init(_builder.getPointerField(
inline ::capnp::List< ::capnp::rpc::CapDescriptor, ::capnp::Kind::STRUCT>::Builder Payload::Builder::initCapTable(unsigned int size) {
return ::capnp::_::PointerHelpers< ::capnp::List< ::capnp::rpc::CapDescriptor, ::capnp::Kind::STRUCT>>::init(_builder.getPointerField(
::capnp::bounded<1>() * ::capnp::POINTERS), size);
}
inline void Payload::Builder::adoptCapTable(
::capnp::Orphan< ::capnp::List< ::capnp::rpc::CapDescriptor>>&& value) {
::capnp::_::PointerHelpers< ::capnp::List< ::capnp::rpc::CapDescriptor>>::adopt(_builder.getPointerField(
::capnp::Orphan< ::capnp::List< ::capnp::rpc::CapDescriptor, ::capnp::Kind::STRUCT>>&& value) {
::capnp::_::PointerHelpers< ::capnp::List< ::capnp::rpc::CapDescriptor, ::capnp::Kind::STRUCT>>::adopt(_builder.getPointerField(
::capnp::bounded<1>() * ::capnp::POINTERS), kj::mv(value));
}
inline ::capnp::Orphan< ::capnp::List< ::capnp::rpc::CapDescriptor>> Payload::Builder::disownCapTable() {
return ::capnp::_::PointerHelpers< ::capnp::List< ::capnp::rpc::CapDescriptor>>::disown(_builder.getPointerField(
inline ::capnp::Orphan< ::capnp::List< ::capnp::rpc::CapDescriptor, ::capnp::Kind::STRUCT>> Payload::Builder::disownCapTable() {
return ::capnp::_::PointerHelpers< ::capnp::List< ::capnp::rpc::CapDescriptor, ::capnp::Kind::STRUCT>>::disown(_builder.getPointerField(
::capnp::bounded<1>() * ::capnp::POINTERS));
}
......@@ -4691,29 +4691,29 @@ inline bool PromisedAnswer::Builder::hasTransform() {
return !_builder.getPointerField(
::capnp::bounded<0>() * ::capnp::POINTERS).isNull();
}
inline ::capnp::List< ::capnp::rpc::PromisedAnswer::Op>::Reader PromisedAnswer::Reader::getTransform() const {
return ::capnp::_::PointerHelpers< ::capnp::List< ::capnp::rpc::PromisedAnswer::Op>>::get(_reader.getPointerField(
inline ::capnp::List< ::capnp::rpc::PromisedAnswer::Op, ::capnp::Kind::STRUCT>::Reader PromisedAnswer::Reader::getTransform() const {
return ::capnp::_::PointerHelpers< ::capnp::List< ::capnp::rpc::PromisedAnswer::Op, ::capnp::Kind::STRUCT>>::get(_reader.getPointerField(
::capnp::bounded<0>() * ::capnp::POINTERS));
}
inline ::capnp::List< ::capnp::rpc::PromisedAnswer::Op>::Builder PromisedAnswer::Builder::getTransform() {
return ::capnp::_::PointerHelpers< ::capnp::List< ::capnp::rpc::PromisedAnswer::Op>>::get(_builder.getPointerField(
inline ::capnp::List< ::capnp::rpc::PromisedAnswer::Op, ::capnp::Kind::STRUCT>::Builder PromisedAnswer::Builder::getTransform() {
return ::capnp::_::PointerHelpers< ::capnp::List< ::capnp::rpc::PromisedAnswer::Op, ::capnp::Kind::STRUCT>>::get(_builder.getPointerField(
::capnp::bounded<0>() * ::capnp::POINTERS));
}
inline void PromisedAnswer::Builder::setTransform( ::capnp::List< ::capnp::rpc::PromisedAnswer::Op>::Reader value) {
::capnp::_::PointerHelpers< ::capnp::List< ::capnp::rpc::PromisedAnswer::Op>>::set(_builder.getPointerField(
inline void PromisedAnswer::Builder::setTransform( ::capnp::List< ::capnp::rpc::PromisedAnswer::Op, ::capnp::Kind::STRUCT>::Reader value) {
::capnp::_::PointerHelpers< ::capnp::List< ::capnp::rpc::PromisedAnswer::Op, ::capnp::Kind::STRUCT>>::set(_builder.getPointerField(
::capnp::bounded<0>() * ::capnp::POINTERS), value);
}
inline ::capnp::List< ::capnp::rpc::PromisedAnswer::Op>::Builder PromisedAnswer::Builder::initTransform(unsigned int size) {
return ::capnp::_::PointerHelpers< ::capnp::List< ::capnp::rpc::PromisedAnswer::Op>>::init(_builder.getPointerField(
inline ::capnp::List< ::capnp::rpc::PromisedAnswer::Op, ::capnp::Kind::STRUCT>::Builder PromisedAnswer::Builder::initTransform(unsigned int size) {
return ::capnp::_::PointerHelpers< ::capnp::List< ::capnp::rpc::PromisedAnswer::Op, ::capnp::Kind::STRUCT>>::init(_builder.getPointerField(
::capnp::bounded<0>() * ::capnp::POINTERS), size);
}
inline void PromisedAnswer::Builder::adoptTransform(
::capnp::Orphan< ::capnp::List< ::capnp::rpc::PromisedAnswer::Op>>&& value) {
::capnp::_::PointerHelpers< ::capnp::List< ::capnp::rpc::PromisedAnswer::Op>>::adopt(_builder.getPointerField(
::capnp::Orphan< ::capnp::List< ::capnp::rpc::PromisedAnswer::Op, ::capnp::Kind::STRUCT>>&& value) {
::capnp::_::PointerHelpers< ::capnp::List< ::capnp::rpc::PromisedAnswer::Op, ::capnp::Kind::STRUCT>>::adopt(_builder.getPointerField(
::capnp::bounded<0>() * ::capnp::POINTERS), kj::mv(value));
}
inline ::capnp::Orphan< ::capnp::List< ::capnp::rpc::PromisedAnswer::Op>> PromisedAnswer::Builder::disownTransform() {
return ::capnp::_::PointerHelpers< ::capnp::List< ::capnp::rpc::PromisedAnswer::Op>>::disown(_builder.getPointerField(
inline ::capnp::Orphan< ::capnp::List< ::capnp::rpc::PromisedAnswer::Op, ::capnp::Kind::STRUCT>> PromisedAnswer::Builder::disownTransform() {
return ::capnp::_::PointerHelpers< ::capnp::List< ::capnp::rpc::PromisedAnswer::Op, ::capnp::Kind::STRUCT>>::disown(_builder.getPointerField(
::capnp::bounded<0>() * ::capnp::POINTERS));
}
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment