Commit 9da143f8 authored by Kenton Varda's avatar Kenton Varda

Have Node's enum and interface fields be groups with a single field, for future expandability.

parent 561f5ed2
......@@ -98,7 +98,7 @@ void enumerateDeps(schema::Node::Reader node, std::set<uint64_t>& deps) {
break;
}
case schema::Node::INTERFACE:
for (auto method: node.getInterface()) {
for (auto method: node.getInterface().getMethods()) {
for (auto param: method.getParams()) {
enumerateDeps(param.getType(), deps);
}
......
......@@ -262,7 +262,7 @@ private:
case schema::Value::ENUM: {
KJ_REQUIRE(type.which() == schema::Type::ENUM, "type/value mismatch");
auto enumNode = scope.getDependency(type.getEnum()).asEnum().getProto();
auto enumerants = enumNode.getEnum();
auto enumerants = enumNode.getEnum().getEnumerants();
KJ_REQUIRE(value.getEnum() < enumerants.size(),
"Enum value out-of-range.", value.getEnum(), enumNode.getDisplayName());
return kj::strTree(enumerants[value.getEnum()].getName());
......
......@@ -715,13 +715,13 @@ void Compiler::Node::traverseNodeDependencies(
break;
case schema::Node::ENUM:
for (auto enumerant: schemaNode.getEnum()) {
for (auto enumerant: schemaNode.getEnum().getEnumerants()) {
traverseAnnotations(enumerant.getAnnotations(), eagerness, seen);
}
break;
case schema::Node::INTERFACE:
for (auto method: schemaNode.getInterface()) {
for (auto method: schemaNode.getInterface().getMethods()) {
for (auto param: method.getParams()) {
traverseType(param.getType(), eagerness, seen);
traverseAnnotations(param.getAnnotations(), eagerness, seen);
......
......@@ -761,7 +761,7 @@ void NodeTranslator::compileEnum(Void decl,
}
}
auto list = builder.initEnum(enumerants.size());
auto list = builder.initEnum().initEnumerants(enumerants.size());
uint i = 0;
DuplicateOrdinalDetector dupDetector(errorReporter);
......
......@@ -351,7 +351,8 @@ private:
}
}
void validate(const List<schema::Enumerant>::Reader& enumerants) {
void validate(const schema::Node::Enum::Reader& enumNode) {
auto enumerants = enumNode.getEnumerants();
KJ_STACK_ARRAY(bool, sawCodeOrder, enumerants.size(), 32, 256);
memset(sawCodeOrder.begin(), 0, sawCodeOrder.size() * sizeof(sawCodeOrder[0]));
......@@ -366,7 +367,8 @@ private:
}
}
void validate(const List<schema::Method>::Reader& methods) {
void validate(const schema::Node::Interface::Reader& interfaceNode) {
auto methods = interfaceNode.getMethods();
KJ_STACK_ARRAY(bool, sawCodeOrder, methods.size(), 32, 256);
memset(sawCodeOrder.begin(), 0, sawCodeOrder.size() * sizeof(sawCodeOrder[0]));
......@@ -694,10 +696,10 @@ private:
}
}
void checkCompatibility(const List<schema::Enumerant>::Reader& enumerants,
const List<schema::Enumerant>::Reader& replacementEnumerants) {
uint size = enumerants.size();
uint replacementSize = replacementEnumerants.size();
void checkCompatibility(const schema::Node::Enum::Reader& enumNode,
const schema::Node::Enum::Reader& replacement) {
uint size = enumNode.getEnumerants().size();
uint replacementSize = replacement.getEnumerants().size();
if (replacementSize > size) {
replacementIsNewer();
} else if (replacementSize < size) {
......@@ -705,8 +707,11 @@ private:
}
}
void checkCompatibility(const List<schema::Method>::Reader& methods,
const List<schema::Method>::Reader& replacementMethods) {
void checkCompatibility(const schema::Node::Interface::Reader& interfaceNode,
const schema::Node::Interface::Reader& replacement) {
auto methods = interfaceNode.getMethods();
auto replacementMethods = replacement.getMethods();
if (replacementMethods.size() > methods.size()) {
replacementIsNewer();
} else if (replacementMethods.size() < methods.size()) {
......@@ -1169,8 +1174,8 @@ _::RawSchema* SchemaLoader::Impl::loadEmpty(
node.setDisplayName(name);
switch (kind) {
case schema::Node::STRUCT: node.initStruct(); break;
case schema::Node::ENUM: node.initEnum(0); break;
case schema::Node::INTERFACE: node.initInterface(0); break;
case schema::Node::ENUM: node.initEnum(); break;
case schema::Node::INTERFACE: node.initInterface(); break;
case schema::Node::FILE:
case schema::Node::CONST:
......
......@@ -131,7 +131,7 @@ TEST(Schema, Enums) {
EXPECT_TRUE(schema.asEnum() == schema);
ASSERT_EQ(schema.getEnumerants().size(),
schema.getProto().getEnum().size());
schema.getProto().getEnum().getEnumerants().size());
EnumSchema::Enumerant enumerant = schema.getEnumerants()[0];
EXPECT_EQ("foo", enumerant.getProto().getName());
EXPECT_TRUE(enumerant.getContainingEnum() == schema);
......
......@@ -189,7 +189,7 @@ uint32_t StructSchema::Field::getDefaultValueSchemaOffset() const {
// -------------------------------------------------------------------
EnumSchema::EnumerantList EnumSchema::getEnumerants() const {
return EnumerantList(*this, getProto().getEnum());
return EnumerantList(*this, getProto().getEnum().getEnumerants());
}
kj::Maybe<EnumSchema::Enumerant> EnumSchema::findEnumerantByName(kj::StringPtr name) const {
......@@ -207,7 +207,7 @@ EnumSchema::Enumerant EnumSchema::getEnumerantByName(kj::StringPtr name) const {
// -------------------------------------------------------------------
InterfaceSchema::MethodList InterfaceSchema::getMethods() const {
return MethodList(*this, getProto().getInterface());
return MethodList(*this, getProto().getInterface().getMethods());
}
kj::Maybe<InterfaceSchema::Method> InterfaceSchema::findMethodByName(kj::StringPtr name) const {
......
......@@ -120,11 +120,15 @@ struct Node {
# most sense to use the field's index in this list rather than its ordinal.
}
enum @14 :List(Enumerant);
# Enumerants ordered by numeric value (ordinal).
enum :group {
enumerants@14 :List(Enumerant);
# Enumerants ordered by numeric value (ordinal).
}
interface @15 :List(Method);
# Methods ordered by ordinal.
interface :group {
methods @15 :List(Method);
# Methods ordered by ordinal.
}
const :group {
type @16 :Type;
......
......@@ -5,7 +5,7 @@
namespace capnp {
namespace schemas {
static const ::capnp::_::AlignedData<189> b_e682ab4cf923a417 = {
static const ::capnp::_::AlignedData<171> b_e682ab4cf923a417 = {
{ 0, 0, 0, 0, 5, 0, 5, 0,
23, 164, 35, 249, 76, 171, 130, 230,
0, 0, 0, 0, 1, 0, 5, 0,
......@@ -82,31 +82,31 @@ static const ::capnp::_::AlignedData<189> b_e682ab4cf923a417 = {
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
8, 0, 253, 255, 3, 0, 0, 0,
0, 0, 1, 0, 14, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
8, 0, 253, 255, 0, 0, 0, 0,
1, 0, 0, 0, 0, 0, 0, 0,
152, 245, 51, 67, 54, 179, 74, 181,
85, 1, 0, 0, 42, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
80, 1, 0, 0, 2, 0, 1, 0,
100, 1, 0, 0, 2, 0, 1, 0,
9, 0, 252, 255, 3, 0, 0, 0,
0, 0, 1, 0, 15, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
97, 1, 0, 0, 82, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
96, 1, 0, 0, 2, 0, 1, 0,
116, 1, 0, 0, 2, 0, 1, 0,
9, 0, 252, 255, 0, 0, 0, 0,
1, 0, 0, 0, 0, 0, 0, 0,
143, 33, 194, 240, 207, 83, 39, 232,
61, 1, 0, 0, 82, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
10, 0, 251, 255, 0, 0, 0, 0,
1, 0, 0, 0, 0, 0, 0, 0,
32, 148, 13, 122, 172, 165, 138, 177,
113, 1, 0, 0, 50, 0, 0, 0,
41, 1, 0, 0, 50, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
11, 0, 250, 255, 0, 0, 0, 0,
1, 0, 0, 0, 0, 0, 0, 0,
144, 2, 10, 64, 212, 25, 22, 236,
89, 1, 0, 0, 90, 0, 0, 0,
17, 1, 0, 0, 90, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
......@@ -172,43 +172,25 @@ static const ::capnp::_::AlignedData<189> b_e682ab4cf923a417 = {
0, 0, 0, 0, 0, 0, 0, 0,
115, 116, 114, 117, 99, 116, 0, 0,
101, 110, 117, 109, 0, 0, 0, 0,
14, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 2, 0, 1, 0,
16, 0, 0, 0, 0, 0, 0, 0,
77, 154, 84, 220, 235, 124, 138, 151,
0, 0, 0, 0, 0, 0, 0, 0,
14, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
105, 110, 116, 101, 114, 102, 97, 99,
101, 0, 0, 0, 0, 0, 0, 0,
14, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 2, 0, 1, 0,
16, 0, 0, 0, 0, 0, 0, 0,
128, 77, 51, 59, 226, 204, 0, 149,
0, 0, 0, 0, 0, 0, 0, 0,
14, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
99, 111, 110, 115, 116, 0, 0, 0,
97, 110, 110, 111, 116, 97, 116, 105,
111, 110, 0, 0, 0, 0, 0, 0, }
};
static const ::capnp::_::RawSchema* const d_e682ab4cf923a417[] = {
&s_9500cce23b334d80,
&s_978a7cebdc549a4d,
&s_9ea0b19b37fb4435,
&s_b18aa5ac7a0d9420,
&s_b54ab3364333f598,
&s_debf55bbfa0fc242,
&s_e82753cff0c2218f,
&s_ec1619d4400a0290,
&s_f1c8950dab257542,
};
static const uint16_t m_e682ab4cf923a417[] = {11, 5, 10, 1, 2, 8, 6, 0, 9, 4, 3, 7};
static const uint16_t i_e682ab4cf923a417[] = {6, 7, 8, 9, 10, 11, 0, 1, 2, 3, 4, 5};
const ::capnp::_::RawSchema s_e682ab4cf923a417 = {
0xe682ab4cf923a417, b_e682ab4cf923a417.words, 189, d_e682ab4cf923a417, m_e682ab4cf923a417,
0xe682ab4cf923a417, b_e682ab4cf923a417.words, 171, d_e682ab4cf923a417, m_e682ab4cf923a417,
7, 12, i_e682ab4cf923a417, nullptr, nullptr
};
static const ::capnp::_::AlignedData<46> b_debf55bbfa0fc242 = {
......@@ -407,6 +389,98 @@ const ::capnp::_::RawSchema s_9ea0b19b37fb4435 = {
0x9ea0b19b37fb4435, b_9ea0b19b37fb4435.words, 127, d_9ea0b19b37fb4435, m_9ea0b19b37fb4435,
3, 7, i_9ea0b19b37fb4435, nullptr, nullptr
};
static const ::capnp::_::AlignedData<34> b_b54ab3364333f598 = {
{ 0, 0, 0, 0, 5, 0, 5, 0,
152, 245, 51, 67, 54, 179, 74, 181,
24, 0, 0, 0, 1, 0, 5, 0,
23, 164, 35, 249, 76, 171, 130, 230,
5, 0, 7, 0, 1, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
17, 0, 0, 0, 234, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
21, 0, 0, 0, 63, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
99, 97, 112, 110, 112, 47, 115, 99,
104, 101, 109, 97, 46, 99, 97, 112,
110, 112, 58, 78, 111, 100, 101, 46,
101, 110, 117, 109, 0, 0, 0, 0,
4, 0, 0, 0, 3, 0, 4, 0,
0, 0, 0, 0, 3, 0, 0, 0,
0, 0, 1, 0, 14, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
13, 0, 0, 0, 90, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
12, 0, 0, 0, 2, 0, 1, 0,
32, 0, 0, 0, 2, 0, 1, 0,
101, 110, 117, 109, 101, 114, 97, 110,
116, 115, 0, 0, 0, 0, 0, 0,
14, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 2, 0, 1, 0,
16, 0, 0, 0, 0, 0, 0, 0,
77, 154, 84, 220, 235, 124, 138, 151,
0, 0, 0, 0, 0, 0, 0, 0,
14, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, }
};
static const ::capnp::_::RawSchema* const d_b54ab3364333f598[] = {
&s_978a7cebdc549a4d,
&s_e682ab4cf923a417,
};
static const uint16_t m_b54ab3364333f598[] = {0};
static const uint16_t i_b54ab3364333f598[] = {0};
const ::capnp::_::RawSchema s_b54ab3364333f598 = {
0xb54ab3364333f598, b_b54ab3364333f598.words, 34, d_b54ab3364333f598, m_b54ab3364333f598,
2, 1, i_b54ab3364333f598, nullptr, nullptr
};
static const ::capnp::_::AlignedData<34> b_e82753cff0c2218f = {
{ 0, 0, 0, 0, 5, 0, 5, 0,
143, 33, 194, 240, 207, 83, 39, 232,
24, 0, 0, 0, 1, 0, 5, 0,
23, 164, 35, 249, 76, 171, 130, 230,
5, 0, 7, 0, 1, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
17, 0, 0, 0, 18, 1, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
25, 0, 0, 0, 63, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
99, 97, 112, 110, 112, 47, 115, 99,
104, 101, 109, 97, 46, 99, 97, 112,
110, 112, 58, 78, 111, 100, 101, 46,
105, 110, 116, 101, 114, 102, 97, 99,
101, 0, 0, 0, 0, 0, 0, 0,
4, 0, 0, 0, 3, 0, 4, 0,
0, 0, 0, 0, 3, 0, 0, 0,
0, 0, 1, 0, 15, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
13, 0, 0, 0, 66, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
8, 0, 0, 0, 2, 0, 1, 0,
28, 0, 0, 0, 2, 0, 1, 0,
109, 101, 116, 104, 111, 100, 115, 0,
14, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 2, 0, 1, 0,
16, 0, 0, 0, 0, 0, 0, 0,
128, 77, 51, 59, 226, 204, 0, 149,
0, 0, 0, 0, 0, 0, 0, 0,
14, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, }
};
static const ::capnp::_::RawSchema* const d_e82753cff0c2218f[] = {
&s_9500cce23b334d80,
&s_e682ab4cf923a417,
};
static const uint16_t m_e82753cff0c2218f[] = {0};
static const uint16_t i_e82753cff0c2218f[] = {0};
const ::capnp::_::RawSchema s_e82753cff0c2218f = {
0xe82753cff0c2218f, b_e82753cff0c2218f.words, 34, d_e82753cff0c2218f, m_e82753cff0c2218f,
2, 1, i_e82753cff0c2218f, nullptr, nullptr
};
static const ::capnp::_::AlignedData<44> b_b18aa5ac7a0d9420 = {
{ 0, 0, 0, 0, 5, 0, 5, 0,
32, 148, 13, 122, 172, 165, 138, 177,
......@@ -2161,6 +2235,10 @@ CAPNP_DEFINE_STRUCT(
::capnp::schema::Node::NestedNode);
CAPNP_DEFINE_STRUCT(
::capnp::schema::Node::Struct);
CAPNP_DEFINE_STRUCT(
::capnp::schema::Node::Enum);
CAPNP_DEFINE_STRUCT(
::capnp::schema::Node::Interface);
CAPNP_DEFINE_STRUCT(
::capnp::schema::Node::Const);
CAPNP_DEFINE_STRUCT(
......
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