diff --git a/YangParser/SemanticModel/Range.cs b/YangParser/SemanticModel/Range.cs index c7e446c..c12b508 100644 --- a/YangParser/SemanticModel/Range.cs +++ b/YangParser/SemanticModel/Range.cs @@ -35,7 +35,47 @@ public Range(YangStatement statement) : base(statement) public string GetConstructorValidation() { - var qualifiers = Bounds.Select(bound => double.IsNaN(bound.Item2) ? $"input >= {bound.Item1}" : $"input is >= {bound.Item1} and <= {bound.Item2}"); + foreach (var bound in Bounds.ToArray()) + { + var max = Parent!.Argument switch + { + "int8" => sbyte.MaxValue, + "uint8" => byte.MaxValue, + "int16" => short.MaxValue, + "uint16" => ushort.MaxValue, + "int32" => int.MaxValue, + "uint32" => uint.MaxValue, + "int64" => long.MaxValue, + "uint64" => ulong.MaxValue, + "decimal64" => double.MaxValue, + _ => 0, + }; + var min = Parent!.Argument switch + { + "int8" => sbyte.MinValue, + "uint8" => byte.MinValue, + "int16" => short.MinValue, + "uint16" => ushort.MinValue, + "int32" => int.MinValue, + "uint32" => uint.MinValue, + "int64" => long.MinValue, + "uint64" => ulong.MinValue, + "decimal64" => double.MinValue, + _ => 0, + }; + if (bound.Item2 >= max && bound.Item1 <= min) + { + Bounds.Remove(bound); + } + } + + if (Bounds.Count == 0) + { + return string.Empty; + } + + var qualifiers = Bounds.Select(bound => + double.IsNaN(bound.Item2) ? $"input >= {bound.Item1}" : $"input is >= {bound.Item1} and <= {bound.Item2}"); var all = string.Join("||", qualifiers); var hasError = this.TryGetChild(out var errorMessage); var hasTag = this.TryGetChild(out var appTag);