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