Commit cfbe1abe authored by Kenton Varda's avatar Kenton Varda

Rename non-group again, now to 'slot', which is much nicer. Also introduce…

Rename non-group again, now to 'slot', which is much nicer.  Also introduce fixed lists as a third kind of field (but not implemented yet).
parent e5faa86e
...@@ -84,8 +84,8 @@ void enumerateDeps(schema::Node::Reader node, std::set<uint64_t>& deps) { ...@@ -84,8 +84,8 @@ void enumerateDeps(schema::Node::Reader node, std::set<uint64_t>& deps) {
auto structNode = node.getStruct(); auto structNode = node.getStruct();
for (auto field: structNode.getFields()) { for (auto field: structNode.getFields()) {
switch (field.which()) { switch (field.which()) {
case schema::Field::NON_GROUP: case schema::Field::SLOT:
enumerateDeps(field.getNonGroup().getType(), deps); enumerateDeps(field.getSlot().getType(), deps);
break; break;
case schema::Field::GROUP: case schema::Field::GROUP:
deps.insert(field.getGroup().getTypeId()); deps.insert(field.getGroup().getTypeId());
...@@ -431,9 +431,9 @@ private: ...@@ -431,9 +431,9 @@ private:
for (auto field: schema.getFields()) { for (auto field: schema.getFields()) {
auto proto = field.getProto(); auto proto = field.getProto();
switch (proto.which()) { switch (proto.which()) {
case schema::Field::NON_GROUP: { case schema::Field::SLOT: {
auto nonGroup = proto.getNonGroup(); auto slot = proto.getSlot();
slots.add(Slot { nonGroup.getType().which(), nonGroup.getOffset() }); slots.add(Slot { slot.getType().which(), slot.getOffset() });
break; break;
} }
case schema::Field::GROUP: case schema::Field::GROUP:
...@@ -545,7 +545,7 @@ private: ...@@ -545,7 +545,7 @@ private:
} }
switch (proto.which()) { switch (proto.which()) {
case schema::Field::NON_GROUP: case schema::Field::SLOT:
// Continue below. // Continue below.
break; break;
...@@ -634,18 +634,18 @@ private: ...@@ -634,18 +634,18 @@ private:
} }
} }
auto nonGroup = proto.getNonGroup(); auto slot = proto.getSlot();
FieldKind kind = FieldKind::PRIMITIVE; FieldKind kind = FieldKind::PRIMITIVE;
kj::String ownedType; kj::String ownedType;
kj::String type = typeName(nonGroup.getType()).flatten(); kj::String type = typeName(slot.getType()).flatten();
kj::StringPtr setterDefault; // only for void kj::StringPtr setterDefault; // only for void
kj::String defaultMask; // primitives only kj::String defaultMask; // primitives only
size_t defaultOffset = 0; // pointers only: offset of the default value within the schema. size_t defaultOffset = 0; // pointers only: offset of the default value within the schema.
size_t defaultSize = 0; // blobs only: byte size of the default value. size_t defaultSize = 0; // blobs only: byte size of the default value.
auto typeBody = nonGroup.getType(); auto typeBody = slot.getType();
auto defaultBody = nonGroup.getDefaultValue(); auto defaultBody = slot.getDefaultValue();
switch (typeBody.which()) { switch (typeBody.which()) {
case schema::Type::VOID: case schema::Type::VOID:
kind = FieldKind::PRIMITIVE; kind = FieldKind::PRIMITIVE;
...@@ -743,7 +743,7 @@ private: ...@@ -743,7 +743,7 @@ private:
defaultMaskParam = kj::str(", ", defaultMask); defaultMaskParam = kj::str(", ", defaultMask);
} }
uint offset = nonGroup.getOffset(); uint offset = slot.getOffset();
if (kind == FieldKind::PRIMITIVE) { if (kind == FieldKind::PRIMITIVE) {
return FieldText { return FieldText {
......
...@@ -368,19 +368,19 @@ private: ...@@ -368,19 +368,19 @@ private:
kj::StringTree genStructField(schema::Field::Reader field, Schema scope, Indent indent) { kj::StringTree genStructField(schema::Field::Reader field, Schema scope, Indent indent) {
switch (field.which()) { switch (field.which()) {
case schema::Field::NON_GROUP: { case schema::Field::SLOT: {
auto nonGroup = field.getNonGroup(); auto slot = field.getSlot();
int size = typeSizeBits(nonGroup.getType()); int size = typeSizeBits(slot.getType());
return kj::strTree( return kj::strTree(
indent, field.getName(), " @", field.getOrdinal().getExplicit(), indent, field.getName(), " @", field.getOrdinal().getExplicit(),
" :", genType(nonGroup.getType(), scope), " :", genType(slot.getType(), scope),
isEmptyValue(nonGroup.getDefaultValue()) ? kj::strTree("") : isEmptyValue(slot.getDefaultValue()) ? kj::strTree("") :
kj::strTree(" = ", genValue( kj::strTree(" = ", genValue(
nonGroup.getType(), nonGroup.getDefaultValue(), scope)), slot.getType(), slot.getDefaultValue(), scope)),
genAnnotations(field.getAnnotations(), scope), genAnnotations(field.getAnnotations(), scope),
"; # ", size == -1 ? kj::strTree("ptr[", nonGroup.getOffset(), "]") "; # ", size == -1 ? kj::strTree("ptr[", slot.getOffset(), "]")
: kj::strTree("bits[", nonGroup.getOffset() * size, ", ", : kj::strTree("bits[", slot.getOffset() * size, ", ",
(nonGroup.getOffset() + 1) * size, ")"), (slot.getOffset() + 1) * size, ")"),
field.hasDiscriminantValue() field.hasDiscriminantValue()
? kj::strTree(", union tag = ", field.getDiscriminantValue()) : kj::strTree(), ? kj::strTree(", union tag = ", field.getDiscriminantValue()) : kj::strTree(),
"\n"); "\n");
......
...@@ -702,8 +702,8 @@ void Compiler::Node::traverseNodeDependencies( ...@@ -702,8 +702,8 @@ void Compiler::Node::traverseNodeDependencies(
case schema::Node::STRUCT: case schema::Node::STRUCT:
for (auto field: schemaNode.getStruct().getFields()) { for (auto field: schemaNode.getStruct().getFields()) {
switch (field.which()) { switch (field.which()) {
case schema::Field::NON_GROUP: case schema::Field::SLOT:
traverseType(field.getNonGroup().getType(), eagerness, seen); traverseType(field.getSlot().getType(), eagerness, seen);
break; break;
case schema::Field::GROUP: case schema::Field::GROUP:
// Aux node will be scanned later. // Aux node will be scanned later.
......
...@@ -477,7 +477,7 @@ Orphan<DynamicValue> makeExampleValue( ...@@ -477,7 +477,7 @@ Orphan<DynamicValue> makeExampleValue(
// Type is "Int32Struct" or the like. // Type is "Int32Struct" or the like.
auto field = structType.getFieldByName("f0"); auto field = structType.getFieldByName("f0");
builder.adopt(field, makeExampleValue(orphanage, structType, ordinal, builder.adopt(field, makeExampleValue(orphanage, structType, ordinal,
field.getProto().getNonGroup().getType(), field.getProto().getSlot().getType(),
sharedOrdinalCount)); sharedOrdinalCount));
} }
...@@ -520,7 +520,7 @@ void checkExampleValue(DynamicValue::Reader value, uint ordinal, schema::Type::R ...@@ -520,7 +520,7 @@ void checkExampleValue(DynamicValue::Reader value, uint ordinal, schema::Type::R
// Type is "Int32Struct" or the like. // Type is "Int32Struct" or the like.
auto field = structType.getFieldByName("f0"); auto field = structType.getFieldByName("f0");
checkExampleValue(structValue.get(field), ordinal, checkExampleValue(structValue.get(field), ordinal,
field.getProto().getNonGroup().getType(), sharedOrdinalCount); field.getProto().getSlot().getType(), sharedOrdinalCount);
} }
break; break;
} }
...@@ -543,10 +543,10 @@ void setExampleField(DynamicStruct::Builder builder, StructSchema::Field field, ...@@ -543,10 +543,10 @@ void setExampleField(DynamicStruct::Builder builder, StructSchema::Field field,
uint sharedOrdinalCount) { uint sharedOrdinalCount) {
auto fieldProto = field.getProto(); auto fieldProto = field.getProto();
switch (fieldProto.which()) { switch (fieldProto.which()) {
case schema::Field::NON_GROUP: case schema::Field::SLOT:
builder.adopt(field, makeExampleValue( builder.adopt(field, makeExampleValue(
Orphanage::getForMessageContaining(builder), field.getContainingStruct(), Orphanage::getForMessageContaining(builder), field.getContainingStruct(),
getOrdinal(field), fieldProto.getNonGroup().getType(), sharedOrdinalCount)); getOrdinal(field), fieldProto.getSlot().getType(), sharedOrdinalCount));
break; break;
case schema::Field::GROUP: case schema::Field::GROUP:
builder.adopt(field, makeExampleStruct( builder.adopt(field, makeExampleStruct(
...@@ -561,11 +561,11 @@ void checkExampleField(DynamicStruct::Reader reader, StructSchema::Field field, ...@@ -561,11 +561,11 @@ void checkExampleField(DynamicStruct::Reader reader, StructSchema::Field field,
uint sharedOrdinalCount) { uint sharedOrdinalCount) {
auto fieldProto = field.getProto(); auto fieldProto = field.getProto();
switch (fieldProto.which()) { switch (fieldProto.which()) {
case schema::Field::NON_GROUP: { case schema::Field::SLOT: {
uint ordinal = getOrdinal(field); uint ordinal = getOrdinal(field);
if (ordinal < sharedOrdinalCount) { if (ordinal < sharedOrdinalCount) {
checkExampleValue(reader.get(field), ordinal, checkExampleValue(reader.get(field), ordinal,
fieldProto.getNonGroup().getType(), sharedOrdinalCount); fieldProto.getSlot().getType(), sharedOrdinalCount);
} }
break; break;
} }
......
...@@ -847,20 +847,20 @@ public: ...@@ -847,20 +847,20 @@ public:
switch (member.decl.which()) { switch (member.decl.which()) {
case Declaration::FIELD: { case Declaration::FIELD: {
auto fieldReader = member.decl.getField(); auto fieldReader = member.decl.getField();
auto nonGroup = fieldBuilder.initNonGroup(); auto slot = fieldBuilder.initSlot();
auto typeBuilder = nonGroup.initType(); auto typeBuilder = slot.initType();
if (translator.compileType(fieldReader.getType(), typeBuilder)) { if (translator.compileType(fieldReader.getType(), typeBuilder)) {
switch (fieldReader.getDefaultValue().which()) { switch (fieldReader.getDefaultValue().which()) {
case Declaration::Field::DefaultValue::VALUE: case Declaration::Field::DefaultValue::VALUE:
translator.compileBootstrapValue(fieldReader.getDefaultValue().getValue(), translator.compileBootstrapValue(fieldReader.getDefaultValue().getValue(),
typeBuilder, nonGroup.initDefaultValue()); typeBuilder, slot.initDefaultValue());
break; break;
case Declaration::Field::DefaultValue::NONE: case Declaration::Field::DefaultValue::NONE:
translator.compileDefaultDefaultValue(typeBuilder, nonGroup.initDefaultValue()); translator.compileDefaultDefaultValue(typeBuilder, slot.initDefaultValue());
break; break;
} }
} else { } else {
translator.compileDefaultDefaultValue(typeBuilder, nonGroup.initDefaultValue()); translator.compileDefaultDefaultValue(typeBuilder, slot.initDefaultValue());
} }
int lgSize = -1; int lgSize = -1;
...@@ -889,13 +889,13 @@ public: ...@@ -889,13 +889,13 @@ public:
if (lgSize == -2) { if (lgSize == -2) {
// pointer // pointer
nonGroup.setOffset(member.fieldScope->addPointer()); slot.setOffset(member.fieldScope->addPointer());
} else if (lgSize == -1) { } else if (lgSize == -1) {
// void // void
member.fieldScope->addVoid(); member.fieldScope->addVoid();
nonGroup.setOffset(0); slot.setOffset(0);
} else { } else {
nonGroup.setOffset(member.fieldScope->addData(lgSize)); slot.setOffset(member.fieldScope->addData(lgSize));
} }
break; break;
} }
...@@ -1737,8 +1737,8 @@ void ValueTranslator::fillStructValue(DynamicStruct::Builder builder, ...@@ -1737,8 +1737,8 @@ void ValueTranslator::fillStructValue(DynamicStruct::Builder builder,
auto value = assignment.getValue(); auto value = assignment.getValue();
switch (fieldProto.which()) { switch (fieldProto.which()) {
case schema::Field::NON_GROUP: case schema::Field::SLOT:
KJ_IF_MAYBE(compiledValue, compileValue(value, fieldProto.getNonGroup().getType())) { KJ_IF_MAYBE(compiledValue, compileValue(value, fieldProto.getSlot().getType())) {
builder.adopt(*field, kj::mv(*compiledValue)); builder.adopt(*field, kj::mv(*compiledValue));
} }
break; break;
......
This diff is collapsed.
...@@ -400,8 +400,8 @@ TEST(Encoding, UnnamedUnion) { ...@@ -400,8 +400,8 @@ TEST(Encoding, UnnamedUnion) {
// The discriminant is allocated just before allocating "bar". // The discriminant is allocated just before allocating "bar".
EXPECT_EQ(2u, schema.getProto().getStruct().getDiscriminantOffset()); EXPECT_EQ(2u, schema.getProto().getStruct().getDiscriminantOffset());
EXPECT_EQ(0u, schema.getFieldByName("foo").getProto().getNonGroup().getOffset()); EXPECT_EQ(0u, schema.getFieldByName("foo").getProto().getSlot().getOffset());
EXPECT_EQ(2u, schema.getFieldByName("bar").getProto().getNonGroup().getOffset()); EXPECT_EQ(2u, schema.getFieldByName("bar").getProto().getSlot().getOffset());
} }
TEST(Encoding, Groups) { TEST(Encoding, Groups) {
......
...@@ -185,8 +185,8 @@ Schema loadUnderAlternateTypeId(SchemaLoader& loader, uint64_t id) { ...@@ -185,8 +185,8 @@ Schema loadUnderAlternateTypeId(SchemaLoader& loader, uint64_t id) {
// If the struct contains any self-referential members, change their type IDs as well. // If the struct contains any self-referential members, change their type IDs as well.
auto fields = root.getStruct().getFields(); auto fields = root.getStruct().getFields();
for (auto field: fields) { for (auto field: fields) {
if (field.isNonGroup()) { if (field.isSlot()) {
auto type = field.getNonGroup().getType(); auto type = field.getSlot().getType();
if (type.isStruct() && type.getStruct().getTypeId() == typeId<T>()) { if (type.isStruct() && type.getStruct().getTypeId() == typeId<T>()) {
type.getStruct().setTypeId(id); type.getStruct().setTypeId(id);
} }
......
...@@ -309,17 +309,16 @@ private: ...@@ -309,17 +309,16 @@ private:
} }
switch (field.which()) { switch (field.which()) {
case schema::Field::NON_GROUP: { case schema::Field::SLOT: {
auto nonGroup = field.getNonGroup(); auto slot = field.getSlot();
uint fieldBits = 0; uint fieldBits = 0;
bool fieldIsPointer = false; bool fieldIsPointer = false;
validate(nonGroup.getType(), nonGroup.getDefaultValue(), validate(slot.getType(), slot.getDefaultValue(), &fieldBits, &fieldIsPointer);
&fieldBits, &fieldIsPointer); VALIDATE_SCHEMA(fieldBits * (slot.getOffset() + 1) <= dataSizeInBits &&
VALIDATE_SCHEMA(fieldBits * (nonGroup.getOffset() + 1) <= dataSizeInBits && fieldIsPointer * (slot.getOffset() + 1) <= pointerCount,
fieldIsPointer * (nonGroup.getOffset() + 1) <= pointerCount,
"field offset out-of-bounds", "field offset out-of-bounds",
nonGroup.getOffset(), dataSizeInBits, pointerCount); slot.getOffset(), dataSizeInBits, pointerCount);
break; break;
} }
...@@ -697,24 +696,24 @@ private: ...@@ -697,24 +696,24 @@ private:
VALIDATE_SCHEMA(discriminant == replacementDiscriminant, "Field discriminant changed."); VALIDATE_SCHEMA(discriminant == replacementDiscriminant, "Field discriminant changed.");
switch (field.which()) { switch (field.which()) {
case schema::Field::NON_GROUP: { case schema::Field::SLOT: {
auto nonGroup = field.getNonGroup(); auto slot = field.getSlot();
switch (replacement.which()) { switch (replacement.which()) {
case schema::Field::NON_GROUP: { case schema::Field::SLOT: {
auto replacementNonGroup = replacement.getNonGroup(); auto replacementSlot = replacement.getSlot();
checkCompatibility(nonGroup.getType(), replacementNonGroup.getType(), checkCompatibility(slot.getType(), replacementSlot.getType(),
NO_UPGRADE_TO_STRUCT); NO_UPGRADE_TO_STRUCT);
checkDefaultCompatibility(nonGroup.getDefaultValue(), checkDefaultCompatibility(slot.getDefaultValue(),
replacementNonGroup.getDefaultValue()); replacementSlot.getDefaultValue());
VALIDATE_SCHEMA(nonGroup.getOffset() == replacementNonGroup.getOffset(), VALIDATE_SCHEMA(slot.getOffset() == replacementSlot.getOffset(),
"field position changed"); "field position changed");
break; break;
} }
case schema::Field::GROUP: case schema::Field::GROUP:
checkUpgradeToStruct(nonGroup.getType(), replacement.getGroup().getTypeId(), checkUpgradeToStruct(slot.getType(), replacement.getGroup().getTypeId(),
existingNode, field); existingNode, field);
break; break;
} }
...@@ -724,8 +723,8 @@ private: ...@@ -724,8 +723,8 @@ private:
case schema::Field::GROUP: case schema::Field::GROUP:
switch (replacement.which()) { switch (replacement.which()) {
case schema::Field::NON_GROUP: case schema::Field::SLOT:
checkUpgradeToStruct(replacement.getNonGroup().getType(), field.getGroup().getTypeId(), checkUpgradeToStruct(replacement.getSlot().getType(), field.getGroup().getTypeId(),
replacementNode, replacement); replacementNode, replacement);
break; break;
case schema::Field::GROUP: case schema::Field::GROUP:
...@@ -984,8 +983,8 @@ private: ...@@ -984,8 +983,8 @@ private:
auto field = structNode.initFields(1)[0]; auto field = structNode.initFields(1)[0];
field.setName("member0"); field.setName("member0");
field.setCodeOrder(0); field.setCodeOrder(0);
auto nongroup = field.initNonGroup(); auto slot = field.initSlot();
nongroup.setType(type); slot.setType(type);
KJ_IF_MAYBE(p, matchPosition) { KJ_IF_MAYBE(p, matchPosition) {
if (p->getOrdinal().isExplicit()) { if (p->getOrdinal().isExplicit()) {
...@@ -993,14 +992,14 @@ private: ...@@ -993,14 +992,14 @@ private:
} else { } else {
field.getOrdinal().setImplicit(); field.getOrdinal().setImplicit();
} }
auto matchNongroup = p->getNonGroup(); auto matchSlot = p->getSlot();
nongroup.setOffset(matchNongroup.getOffset()); slot.setOffset(matchSlot.getOffset());
nongroup.setDefaultValue(matchNongroup.getDefaultValue()); slot.setDefaultValue(matchSlot.getDefaultValue());
} else { } else {
field.getOrdinal().setExplicit(0); field.getOrdinal().setExplicit(0);
nongroup.setOffset(0); slot.setOffset(0);
schema::Value::Builder value = nongroup.initDefaultValue(); schema::Value::Builder value = slot.initDefaultValue();
switch (type.which()) { switch (type.which()) {
case schema::Type::VOID: value.setVoid(); break; case schema::Type::VOID: value.setVoid(); break;
case schema::Type::BOOL: value.setBool(false); break; case schema::Type::BOOL: value.setBool(false); break;
......
...@@ -54,7 +54,7 @@ private: ...@@ -54,7 +54,7 @@ private:
static uint64_t getFieldTypeFileId(StructSchema::Field field) { static uint64_t getFieldTypeFileId(StructSchema::Field field) {
return field.getContainingStruct() return field.getContainingStruct()
.getDependency(field.getProto().getNonGroup().getType().getStruct().getTypeId()) .getDependency(field.getProto().getSlot().getType().getStruct().getTypeId())
.getProto().getScopeId(); .getProto().getScopeId();
} }
......
...@@ -228,7 +228,7 @@ TEST(Schema, Lists) { ...@@ -228,7 +228,7 @@ TEST(Schema, Lists) {
{ {
auto context = Schema::from<TestAllTypes>(); auto context = Schema::from<TestAllTypes>();
auto type = context.getFieldByName("enumList").getProto().getNonGroup().getType(); auto type = context.getFieldByName("enumList").getProto().getSlot().getType();
ListSchema schema = ListSchema::of(type.getList().getElementType(), context); ListSchema schema = ListSchema::of(type.getList().getElementType(), context);
EXPECT_EQ(schema::Type::ENUM, schema.whichElementType()); EXPECT_EQ(schema::Type::ENUM, schema.whichElementType());
......
...@@ -194,7 +194,7 @@ kj::Maybe<StructSchema::Field> StructSchema::getFieldByDiscriminant(uint16_t dis ...@@ -194,7 +194,7 @@ kj::Maybe<StructSchema::Field> StructSchema::getFieldByDiscriminant(uint16_t dis
} }
uint32_t StructSchema::Field::getDefaultValueSchemaOffset() const { uint32_t StructSchema::Field::getDefaultValueSchemaOffset() const {
return parent.getSchemaOffset(proto.getNonGroup().getDefaultValue()); return parent.getSchemaOffset(proto.getSlot().getDefaultValue());
} }
// ------------------------------------------------------------------- // -------------------------------------------------------------------
......
...@@ -178,8 +178,8 @@ struct Field { ...@@ -178,8 +178,8 @@ struct Field {
# returns false). # returns false).
union { union {
nonGroup :group { slot :group {
# A regular, non-group, field. # A regular, non-group, non-fixed-list field.
offset @4 :UInt32; offset @4 :UInt32;
# Offset, in units of the field's size, from the beginning of the section in which the field # Offset, in units of the field's size, from the beginning of the section in which the field
...@@ -196,6 +196,19 @@ struct Field { ...@@ -196,6 +196,19 @@ struct Field {
typeId @7 :Id; typeId @7 :Id;
# The ID of the group's node. # The ID of the group's node.
} }
fixedList :group {
# A fixed list stored inline within the struct.
startOffset @10 :UInt32;
# Offset of the first element, measured in the same way as for slot fields.
count @11 :UInt8;
# Number of elements.
elementType @12 :Type;
# Type of each element.
}
} }
ordinal :union { ordinal :union {
......
This diff is collapsed.
This diff is collapsed.
...@@ -102,8 +102,8 @@ private: ...@@ -102,8 +102,8 @@ private:
static schema::Type::Which whichFieldType(const StructSchema::Field& field) { static schema::Type::Which whichFieldType(const StructSchema::Field& field) {
auto proto = field.getProto(); auto proto = field.getProto();
switch (proto.which()) { switch (proto.which()) {
case schema::Field::NON_GROUP: case schema::Field::SLOT:
return proto.getNonGroup().getType().which(); return proto.getSlot().getType().which();
case schema::Field::GROUP: case schema::Field::GROUP:
return schema::Type::STRUCT; return schema::Type::STRUCT;
} }
......
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