public override DcParameter AppendArraySpecification(DcUIntRange size) { // If we are a typedef wrap directly if (Typedef != null) { return(new DcArrayParameter(this, size)); } _elementType = _elementType.AppendArraySpecification(size); return(this); }
public DcArrayParameter(DcParameter elementType, DcUIntRange size) { _elementType = elementType; _arraySize = -1; _arraySizeRange = size; HasFixedByteSize = false; Name = elementType.Name; elementType.Name = string.Empty; if (_arraySizeRange.HasOneValue()) { _arraySize = (int)_arraySizeRange.GetOneValue(); } else { HasRangeLimits = true; } if (_arraySize >= 0 && _elementType.HasFixedByteSize) { HasFixedByteSize = true; FixedByteSize = _arraySize * _elementType.FixedByteSize; HasFixedStructure = true; } else { NumLengthBytes = 2; } if (_elementType.HasRangeLimits) { HasRangeLimits = true; } if (_elementType.HasDefaultValue) { HasDefaultValue = true; } HasNestedFields = true; NumNestedFields = _arraySize; PackType = DcPackType.Array; if (_elementType is DcSimpleParameter simpleType) { if (simpleType.Type == DcSubatomicType.Char) { PackType = DcPackType.String; } } }
private void ReadRangeArgumentsIntoRange(DcParser.Range_argumentsContext context, DcUIntRange range) { while (context != null) { var arg = context.range_argument(); if (arg.single != null) { if (!uint.TryParse(arg.single.GetText(), out var single)) { throw new Exception($"Error parsing array range '{arg.single.GetText()}' on line {arg.single.Start.Line}"); } range.Add(single, single); } else if (arg.@char != null) { // Index 1 because the text includes quotes var value = (uint)[email protected][1]; range.Add(value, value); } else { if (!uint.TryParse(arg.min.GetText(), out var min)) { throw new Exception($"Error parsing array range min '{arg.min.GetText()}' on line {arg.min.Start.Line}"); } if (!uint.TryParse(arg.min.GetText(), out var max)) { throw new Exception($"Error parsing array range max '{arg.max.GetText()}' on line {arg.max.Start.Line}"); } range.Add(min, max); } context = context.next; } }
private DcParameter BuildDcParameterFromContext(DcParser.ParameterContext context) { DcParameter parameter; uint divisor = 1; if (context.divisor != null) { divisor = uint.Parse(context.divisor.Text); } DcLongRange?paramRange = null; if (context.parameter_range() != null) { paramRange = new DcLongRange(); ReadRangeArgumentsIntoRange(context.parameter_range().range_arguments(), paramRange); } // Array parameters var array = context.array; if (array != null) { var elementType = CreateParameterFromName(context.type.Text, divisor, paramRange); var range = new DcUIntRange(); if (context.array.range != null) { ReadRangeArgumentsIntoRange(context.array.range, range); } parameter = new DcArrayParameter(elementType, range); array = array.next; while (array != null) { range = new DcUIntRange(); if (context.array.range != null) { ReadRangeArgumentsIntoRange(context.array.range, range); } parameter.AppendArraySpecification(range); array = array.next; } } else { parameter = CreateParameterFromName(context.type.Text, divisor, paramRange); } parameter.Name = context.name?.Text ?? ""; if (context.default_value() != null) { var bw = new SpanBufferWriter(stackalloc byte[512]); bw.WriteValueConstant(parameter, context.default_value().value); parameter.DefaultValue = bw.Data.ToArray(); parameter.HasDefaultValue = true; } return(parameter); }