Commit fb952aa6 authored by Jason Choy's avatar Jason Choy

Add enumerant as a target for the name annotation

parent 559fd84a
......@@ -25,4 +25,4 @@
$namespace("capnp::annotations");
annotation namespace(file): Text;
annotation name(field): Text;
annotation name(field, enumerant): Text;
......@@ -32,7 +32,7 @@ const ::capnp::_::RawSchema s_b9c6f99ebf805f2c = {
static const ::capnp::_::AlignedData<17> b_f264a779fef191ce = {
{ 0, 0, 0, 0, 5, 0, 5, 0,
206, 145, 241, 254, 121, 167, 100, 242,
10, 0, 0, 0, 5, 0, 32, 0,
10, 0, 0, 0, 5, 0, 40, 0,
129, 78, 48, 184, 123, 125, 248, 189,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
......
......@@ -271,6 +271,15 @@ private:
KJ_UNREACHABLE;
}
kj::StringPtr enumerantName(schema::Enumerant::Reader proto) {
for (auto annotation: proto.getAnnotations()) {
if (annotation.getId() == NAME_ANNOTATION_ID) {
return annotation.getValue().getText();
}
}
return proto.getName();
}
kj::StringTree literalValue(schema::Type::Reader type, schema::Value::Reader value) {
switch (value.which()) {
case schema::Value::VOID: return kj::strTree(" ::capnp::VOID");
......@@ -290,7 +299,7 @@ private:
if (value.getEnum() < schema.getEnumerants().size()) {
return kj::strTree(
cppFullName(schema), "::",
toUpperCase(schema.getEnumerants()[value.getEnum()].getProto().getName()));
toUpperCase(enumerantName(schema.getEnumerants()[value.getEnum()].getProto())));
} else {
return kj::strTree("static_cast<", cppFullName(schema), ">(", value.getEnum(), ")");
}
......@@ -1742,7 +1751,7 @@ private:
scope.size() == 0 ? kj::strTree() : kj::strTree(
" enum class ", name, ": uint16_t {\n",
KJ_MAP(e, enumerants) {
return kj::strTree(" ", toUpperCase(e.getProto().getName()), ",\n");
return kj::strTree(" ", toUpperCase(enumerantName(e.getProto())), ",\n");
},
" };\n"
"\n"),
......@@ -1750,7 +1759,7 @@ private:
scope.size() > 0 ? kj::strTree() : kj::strTree(
"enum class ", name, ": uint16_t {\n",
KJ_MAP(e, enumerants) {
return kj::strTree(" ", toUpperCase(e.getProto().getName()), ",\n");
return kj::strTree(" ", toUpperCase(enumerantName(e.getProto())), ",\n");
},
"};\n"
"\n"),
......
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