public ArrayVariant([NotNull] Variable value, [NotNull] AnalysisContext context) : base(value, context) { Value = new DataValueArray(Array.Empty <LogicExpressionBase>()); IndexRange = ValueInterval.Empty; if (!(value.TypeRef is ArrayTypeRef arrayTypeRef)) { Log.Error("ArrayVariant expects ArrayTypeRef, not {Type}", value.TypeRef); return; } if (!(arrayTypeRef.Length is OrderedLiteralBase length)) { Log.Information("ArrayVariant expects OrderedLiteralBase as length, not {Type}", arrayTypeRef.Length); return; } IndexRange = new ValueInterval(IntegerLiteral.Zero, length, toInclusive: false); foreach (var i in IndexRange.Iterate(IntegerLiteral.One)) { var itemVariant = new ArrayItemVariant(value, InnerTypeRef, ValueInterval.Single(i), context); this[context, i] = itemVariant; } }
public ArrayItemVariant([NotNull] Variable arrayStorage, [NotNull] TypeReference typeRef, [NotNull] ValueInterval index, [NotNull] AnalysisContext context) : base(arrayStorage, typeRef, context) { Index = index ?? throw new ArgumentNullException(nameof(index)); Value = new DataValueUnknown(); switch (typeRef) { case PrimitiveTypeRef primitiveTypeRef: var defaultValue = primitiveTypeRef.DefaultValue; if (defaultValue is OrderedLiteralBase defaultOrderedValue) { Value = new DataValueInterval(ValueInterval.Single(defaultOrderedValue), Array.Empty <LogicExpressionBase>()); } break; default: throw new ArgumentOutOfRangeException(nameof(typeRef)); } }