Skip to content

Commit

Permalink
Split out sequence type enum into more cases.
Browse files Browse the repository at this point in the history
  • Loading branch information
MeltyPlayer committed Jul 15, 2023
1 parent 7defa28 commit 4a4ed4c
Show file tree
Hide file tree
Showing 8 changed files with 392 additions and 301 deletions.
28 changes: 14 additions & 14 deletions Schema Tests/SchemaStructureParserTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class ByteWrapper {

var primitiveType = (memberType as IPrimitiveMemberType)!;
Assert.AreEqual(SchemaPrimitiveType.BYTE, primitiveType.PrimitiveType);
Assert.AreEqual(false, primitiveType.IsReadonly);
Assert.AreEqual(false, primitiveType.IsReadOnly);
Assert.AreEqual(false, primitiveType.UseAltFormat);
Assert.AreEqual(SchemaNumberType.UNDEFINED, primitiveType.AltFormat);
}
Expand Down Expand Up @@ -63,7 +63,7 @@ public class SByteWrapper {

var primitiveType = (memberType as IPrimitiveMemberType)!;
Assert.AreEqual(SchemaPrimitiveType.SBYTE, primitiveType.PrimitiveType);
Assert.AreEqual(false, primitiveType.IsReadonly);
Assert.AreEqual(false, primitiveType.IsReadOnly);
Assert.AreEqual(false, primitiveType.UseAltFormat);
Assert.AreEqual(SchemaNumberType.UNDEFINED, primitiveType.AltFormat);
}
Expand Down Expand Up @@ -95,7 +95,7 @@ public class Int16Wrapper {

var primitiveType = (memberType as IPrimitiveMemberType)!;
Assert.AreEqual(SchemaPrimitiveType.INT16, primitiveType.PrimitiveType);
Assert.AreEqual(false, primitiveType.IsReadonly);
Assert.AreEqual(false, primitiveType.IsReadOnly);
Assert.AreEqual(false, primitiveType.UseAltFormat);
Assert.AreEqual(SchemaNumberType.UNDEFINED, primitiveType.AltFormat);
}
Expand Down Expand Up @@ -134,7 +134,7 @@ public class EnumWrapper {

var primitiveType = (memberType as IPrimitiveMemberType)!;
Assert.AreEqual(SchemaPrimitiveType.ENUM, primitiveType.PrimitiveType);
Assert.AreEqual(false, primitiveType.IsReadonly);
Assert.AreEqual(false, primitiveType.IsReadOnly);
Assert.AreEqual(true, primitiveType.UseAltFormat);
Assert.AreEqual(SchemaNumberType.UINT16, primitiveType.AltFormat);
}
Expand All @@ -158,12 +158,12 @@ public class ArrayWrapper {
Assert.AreEqual(TypeKind.Array, memberType.TypeSymbol.TypeKind);

var arrayType = (memberType as ISequenceMemberType)!;
Assert.AreEqual(SequenceType.ARRAY, arrayType.SequenceType);
Assert.AreEqual(SequenceLengthSourceType.READONLY, arrayType.LengthSourceType);
Assert.AreEqual(SequenceType.MUTABLE_ARRAY, arrayType.SequenceTypeInfo.SequenceType);
Assert.AreEqual(SequenceLengthSourceType.READ_ONLY, arrayType.LengthSourceType);

var primitiveType = (arrayType.ElementType as IPrimitiveMemberType)!;
Assert.AreEqual(SchemaPrimitiveType.INT32, primitiveType.PrimitiveType);
Assert.AreEqual(false, primitiveType.IsReadonly);
Assert.AreEqual(false, primitiveType.IsReadOnly);
Assert.AreEqual(false, primitiveType.UseAltFormat);
Assert.AreEqual(SchemaNumberType.UNDEFINED, primitiveType.AltFormat);
}
Expand All @@ -187,12 +187,12 @@ public class CharWrapper {
Assert.AreEqual(TypeKind.Array, memberType.TypeSymbol.TypeKind);

var arrayType = (memberType as ISequenceMemberType)!;
Assert.AreEqual(SequenceType.ARRAY, arrayType.SequenceType);
Assert.AreEqual(SequenceLengthSourceType.READONLY, arrayType.LengthSourceType);
Assert.AreEqual(SequenceType.MUTABLE_ARRAY, arrayType.SequenceTypeInfo.SequenceType);
Assert.AreEqual(SequenceLengthSourceType.READ_ONLY, arrayType.LengthSourceType);

var primitiveType = (arrayType.ElementType as IPrimitiveMemberType)!;
Assert.AreEqual(SchemaPrimitiveType.CHAR, primitiveType.PrimitiveType);
Assert.AreEqual(false, primitiveType.IsReadonly);
Assert.AreEqual(false, primitiveType.IsReadOnly);
Assert.AreEqual(false, primitiveType.UseAltFormat);
Assert.AreEqual(SchemaNumberType.UNDEFINED, primitiveType.AltFormat);
}
Expand Down Expand Up @@ -224,7 +224,7 @@ public class ByteWrapper {

var primitiveType = (memberType as IPrimitiveMemberType)!;
Assert.AreEqual(SchemaPrimitiveType.BYTE, primitiveType.PrimitiveType);
Assert.AreEqual(false, primitiveType.IsReadonly);
Assert.AreEqual(false, primitiveType.IsReadOnly);
Assert.AreEqual(false, primitiveType.UseAltFormat);
Assert.AreEqual(SchemaNumberType.UNDEFINED, primitiveType.AltFormat);
}
Expand Down Expand Up @@ -256,7 +256,7 @@ public class ByteWrapper {

var primitiveType = (memberType as IPrimitiveMemberType)!;
Assert.AreEqual(SchemaPrimitiveType.BYTE, primitiveType.PrimitiveType);
Assert.AreEqual(false, primitiveType.IsReadonly);
Assert.AreEqual(false, primitiveType.IsReadOnly);
Assert.AreEqual(false, primitiveType.UseAltFormat);
Assert.AreEqual(SchemaNumberType.UNDEFINED, primitiveType.AltFormat);
}
Expand Down Expand Up @@ -288,7 +288,7 @@ public class ByteWrapper {

var primitiveType = (memberType as IPrimitiveMemberType)!;
Assert.AreEqual(SchemaPrimitiveType.BYTE, primitiveType.PrimitiveType);
Assert.AreEqual(true, primitiveType.IsReadonly);
Assert.AreEqual(true, primitiveType.IsReadOnly);
Assert.AreEqual(false, primitiveType.UseAltFormat);
Assert.AreEqual(SchemaNumberType.UNDEFINED, primitiveType.AltFormat);
}
Expand Down Expand Up @@ -320,7 +320,7 @@ public class ByteWrapper {

var primitiveType = (memberType as IPrimitiveMemberType)!;
Assert.AreEqual(SchemaPrimitiveType.BYTE, primitiveType.PrimitiveType);
Assert.AreEqual(true, primitiveType.IsReadonly);
Assert.AreEqual(true, primitiveType.IsReadOnly);
Assert.AreEqual(false, primitiveType.UseAltFormat);
Assert.AreEqual(SchemaNumberType.UNDEFINED, primitiveType.AltFormat);
}
Expand Down
28 changes: 14 additions & 14 deletions Schema/src/binary/BinarySchemaStructureParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public interface ISchemaMember {
public interface IMemberType {
ITypeInfo TypeInfo { get; }
ITypeSymbol TypeSymbol { get; }
bool IsReadonly { get; }
bool IsReadOnly { get; }
}

public interface IPrimitiveMemberType : IMemberType {
Expand Down Expand Up @@ -143,24 +143,26 @@ public interface IStringType : IMemberType {
}

public enum SequenceType {
ARRAY,
LIST,
MUTABLE_ARRAY,
IMMUTABLE_ARRAY,
MUTABLE_LIST,
READ_ONLY_LIST,
MUTABLE_SEQUENCE,
READ_ONLY_SEQUENCE,
}

public enum SequenceLengthSourceType {
UNSPECIFIED,
IMMEDIATE_VALUE,
OTHER_MEMBER,
CONST_LENGTH,
READONLY,
READ_ONLY,
UNTIL_END_OF_STREAM,
}

public interface ISequenceMemberType : IMemberType {
ISequenceTypeInfo SequenceTypeInfo { get; }

SequenceType SequenceType { get; }

SequenceLengthSourceType LengthSourceType { get; }
SchemaIntegerType ImmediateLengthType { get; }
ISchemaMember? LengthMember { get; }
Expand Down Expand Up @@ -556,7 +558,7 @@ memberType is BinarySchemaStructureParser.PrimitiveMemberType
Rules.NotSupported));
}

if (memberTypeInfo.IsReadonly) {
if (memberTypeInfo.IsReadOnly) {
diagnostics.Add(
Rules.CreateDiagnostic(memberSymbol,
Rules.UnexpectedAttribute));
Expand Down Expand Up @@ -656,7 +658,7 @@ public class PrimitiveMemberType : IPrimitiveMemberType {
public IPrimitiveTypeInfo PrimitiveTypeInfo { get; set; }
public ITypeInfo TypeInfo => PrimitiveTypeInfo;
public ITypeSymbol TypeSymbol => TypeInfo.TypeSymbol;
public bool IsReadonly => this.TypeInfo.IsReadonly;
public bool IsReadOnly => this.TypeInfo.IsReadOnly;

public SchemaPrimitiveType PrimitiveType
=> this.PrimitiveTypeInfo.PrimitiveType;
Expand All @@ -673,7 +675,7 @@ public class StructureMemberType : IStructureMemberType {
public IStructureTypeInfo StructureTypeInfo { get; set; }
public ITypeInfo TypeInfo => StructureTypeInfo;
public ITypeSymbol TypeSymbol => TypeInfo.TypeSymbol;
public bool IsReadonly => this.TypeInfo.IsReadonly;
public bool IsReadOnly => this.TypeInfo.IsReadOnly;

public bool IsReferenceType { get; set; }
public bool IsChild { get; set; }
Expand All @@ -685,7 +687,7 @@ public class GenericMemberType : IGenericMemberType {
public IGenericTypeInfo GenericTypeInfo { get; set; }
public ITypeInfo TypeInfo => GenericTypeInfo;
public ITypeSymbol TypeSymbol => TypeInfo.TypeSymbol;
public bool IsReadonly => this.TypeInfo.IsReadonly;
public bool IsReadOnly => this.TypeInfo.IsReadOnly;
}

public class IfBoolean : IIfBoolean {
Expand All @@ -702,7 +704,7 @@ public class Offset : IOffset {
public class StringType : IStringType {
public ITypeInfo TypeInfo { get; set; }
public ITypeSymbol TypeSymbol => TypeInfo.TypeSymbol;
public bool IsReadonly => this.TypeInfo.IsReadonly;
public bool IsReadOnly => this.TypeInfo.IsReadOnly;

public StringLengthSourceType LengthSourceType { get; set; }
public SchemaIntegerType ImmediateLengthType { get; set; }
Expand All @@ -714,9 +716,7 @@ public class SequenceMemberType : ISequenceMemberType {
public ISequenceTypeInfo SequenceTypeInfo { get; set; }
public ITypeInfo TypeInfo => SequenceTypeInfo;
public ITypeSymbol TypeSymbol => TypeInfo.TypeSymbol;
public bool IsReadonly => this.TypeInfo.IsReadonly;

public SequenceType SequenceType { get; set; }
public bool IsReadOnly => this.TypeInfo.IsReadOnly;

public SequenceLengthSourceType LengthSourceType { get; set; }
public SchemaIntegerType ImmediateLengthType { get; set; }
Expand Down
5 changes: 1 addition & 4 deletions Schema/src/binary/parser/MemberReferenceUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,11 @@ public static IMemberType WrapTypeInfoWithMemberType(ITypeInfo typeInfo) {
case ISequenceTypeInfo sequenceTypeInfo: {
return new BinarySchemaStructureParser.SequenceMemberType {
SequenceTypeInfo = sequenceTypeInfo,
SequenceType = sequenceTypeInfo.IsArray
? SequenceType.ARRAY
: SequenceType.LIST,
ElementType =
WrapTypeInfoWithMemberType(sequenceTypeInfo.ElementTypeInfo),
LengthSourceType =
sequenceTypeInfo.IsLengthConst
? SequenceLengthSourceType.READONLY
? SequenceLengthSourceType.READ_ONLY
: ((ISequenceLengthSourceAttribute?) SymbolTypeUtil
.GetAttribute<SequenceLengthSourceAttribute>(
null,
Expand Down
Loading

0 comments on commit 4a4ed4c

Please sign in to comment.