From 513f7857a58fe5a6ca69a259248142455c95bb34 Mon Sep 17 00:00:00 2001 From: Mikhalkovich Stanislav Date: Wed, 25 Nov 2020 17:51:59 +0300 Subject: [PATCH] fix #2350 --- Configuration/GlobalAssemblyInfo.cs | 2 +- Configuration/Version.defs | 4 +- Release/pabcversion.txt | 2 +- ReleaseGenerators/PascalABCNET_version.nsh | 2 +- TestSuite/BigIntSeqSumProduct.pas | 7 +++ TestSuite/CompilationSamples/PABCSystem.pas | 59 +++++++++++++++++- TreeConverter/TreeRealization/types.cs | 2 +- bin/Lib/PABCSystem.pas | 69 ++++++++++++++++++--- bin/Lng/Rus/SemanticErrors_ms.dat | 2 +- 9 files changed, 131 insertions(+), 18 deletions(-) create mode 100644 TestSuite/BigIntSeqSumProduct.pas diff --git a/Configuration/GlobalAssemblyInfo.cs b/Configuration/GlobalAssemblyInfo.cs index b498d3736..4917c89a3 100644 --- a/Configuration/GlobalAssemblyInfo.cs +++ b/Configuration/GlobalAssemblyInfo.cs @@ -15,7 +15,7 @@ internal static class RevisionClass public const string Major = "3"; public const string Minor = "7"; public const string Build = "1"; - public const string Revision = "2747"; + public const string Revision = "2750"; public const string MainVersion = Major + "." + Minor; public const string FullVersion = Major + "." + Minor + "." + Build + "." + Revision; diff --git a/Configuration/Version.defs b/Configuration/Version.defs index 436e19ac5..05c7d2ccb 100644 --- a/Configuration/Version.defs +++ b/Configuration/Version.defs @@ -1,4 +1,4 @@ -%MINOR%=7 -%REVISION%=2747 %COREVERSION%=1 +%REVISION%=2750 +%MINOR%=7 %MAJOR%=3 diff --git a/Release/pabcversion.txt b/Release/pabcversion.txt index 26d6fbd26..ddef9a407 100644 --- a/Release/pabcversion.txt +++ b/Release/pabcversion.txt @@ -1 +1 @@ -3.7.1.2747 +3.7.1.2750 diff --git a/ReleaseGenerators/PascalABCNET_version.nsh b/ReleaseGenerators/PascalABCNET_version.nsh index be4e4abcf..06322afbc 100644 --- a/ReleaseGenerators/PascalABCNET_version.nsh +++ b/ReleaseGenerators/PascalABCNET_version.nsh @@ -1 +1 @@ -!define VERSION '3.7.1.2747' +!define VERSION '3.7.1.2750' diff --git a/TestSuite/BigIntSeqSumProduct.pas b/TestSuite/BigIntSeqSumProduct.pas new file mode 100644 index 000000000..4b1ee1edc --- /dev/null +++ b/TestSuite/BigIntSeqSumProduct.pas @@ -0,0 +1,7 @@ +begin + var a := Arr(1bi,2bi,4bi); + Assert(a.Sum = 7bi); + Assert(a.Product = 8bi); + var lst := new List(); + lst.Sum; +end. \ No newline at end of file diff --git a/TestSuite/CompilationSamples/PABCSystem.pas b/TestSuite/CompilationSamples/PABCSystem.pas index a579cd0af..d3b21b524 100644 --- a/TestSuite/CompilationSamples/PABCSystem.pas +++ b/TestSuite/CompilationSamples/PABCSystem.pas @@ -2142,6 +2142,10 @@ function NextPermutation(a: array of integer): boolean; function Range(a, b: integer): sequence of integer; /// Возвращает последовательность целых от a до b с шагом step function Range(a, b, step: integer): sequence of integer; +/// Возвращает последовательность длинных целых от a до b +function Range(a, b: BigInteger): sequence of BigInteger; +/// Возвращает последовательность длинных целых от a до b с шагом step +function Range(a, b, step: BigInteger): sequence of BigInteger; /// Возвращает последовательность символов от c1 до c2 function Range(c1, c2: char): sequence of char; /// Возвращает последовательность символов от c1 до c2 с шагом step @@ -4557,7 +4561,7 @@ begin else Result := System.Linq.Enumerable.Range(a, b - a + 1); end; -function Range(a, b: real; n: integer): sequence of real; +function PartitionPoints(a, b: real; n: integer): sequence of real; begin if n = 0 then raise new System.ArgumentException('Range: n=0'); @@ -4582,11 +4586,26 @@ begin Result := Range(integer(c1), integer(c2), step).Select(x -> Chr(x)); end; -function PartitionPoints(a, b: real; n: integer): sequence of real; +function Range(a, b, step: BigInteger): sequence of BigInteger; begin - Result := Range(a, b, n) + if step = 0 then + raise new System.ArgumentException('step=0'); + if step > 0 then + while a<=b do + begin + yield a; + a += step; + end + else + while a>=b do + begin + yield a; + a += step; + end end; +function Range(a, b: BigInteger): sequence of BigInteger := Range(a,b,1); + type ArithmSeq = auto class a, step: integer; @@ -9745,6 +9764,40 @@ begin Result += f(x); end;} +// SSM 23/11/2020 - Sum Average Product for sequence of BigInteger + +/// Возвращает сумму элементов последовательности +function Sum(Self: sequence of BigInteger): BigInteger; extensionmethod; +begin + Result := 0bi; + foreach var a in Self do + Result += a +end; + +/// Возвращает среднее элементов последовательности +function Average(Self: sequence of BigInteger): real; extensionmethod; +begin + var cnt := 0; + var sum := 0bi; + foreach var a in Self do + begin + sum += a; + cnt += 1; + end; + if cnt <> 0 then + Result := sum/cnt + else Result := 0 +end; + +/// Возвращает произведение элементов последовательности +function Product(Self: sequence of BigInteger): BigInteger; extensionmethod; +begin + Result := 1bi; + foreach var a in Self do + Result *= a +end; + + /// Возвращает отсортированную по возрастанию последовательность function Sorted(Self: sequence of T): sequence of T; extensionmethod; diff --git a/TreeConverter/TreeRealization/types.cs b/TreeConverter/TreeRealization/types.cs index 3c3d2ceb1..a36fec435 100644 --- a/TreeConverter/TreeRealization/types.cs +++ b/TreeConverter/TreeRealization/types.cs @@ -3582,7 +3582,7 @@ namespace PascalABCCompiler.TreeRealization start = ext.GetRange(cur_index, ext.Count() - cur_index); if (result != null) { - result.RemoveRange(1, result.Count() - 1); + //result.RemoveRange(1, result.Count() - 1); result.AddRange(start); } } diff --git a/bin/Lib/PABCSystem.pas b/bin/Lib/PABCSystem.pas index a579cd0af..dc34d1587 100644 --- a/bin/Lib/PABCSystem.pas +++ b/bin/Lib/PABCSystem.pas @@ -628,7 +628,7 @@ type Result := (l = r2.l) and (h = r2.h); end; function GetHashCode: integer; override := l.GetHashCode xor h.GetHashCode; - function ToArray: array of integer; + {function ToArray: array of integer; begin Result := new integer[Count]; var x := l; @@ -640,14 +640,14 @@ type end; function ToList: List; begin - Result := new List; + Result := new List(Count); var x := l; loop Count do begin Result.Add(x); x += 1; end; - end; + end;} function ToLinkedList: LinkedList; begin Result := new LinkedList(System.Linq.Enumerable.Range(l,Count)); @@ -701,7 +701,7 @@ type end; function GetHashCode: integer; override := l.GetHashCode xor h.GetHashCode; - function ToArray: array of char; + {function ToArray: array of char; begin Result := new char[Count]; var x := l; @@ -720,7 +720,7 @@ type Result.Add(x); x := char(integer(x) + 1); end; - end; + end;} function ToLinkedList: LinkedList; begin Result := new LinkedList(System.Linq.Enumerable.Range(integer(l),Count).Select(i -> char(i))); @@ -2142,6 +2142,10 @@ function NextPermutation(a: array of integer): boolean; function Range(a, b: integer): sequence of integer; /// Возвращает последовательность целых от a до b с шагом step function Range(a, b, step: integer): sequence of integer; +/// Возвращает последовательность длинных целых от a до b +function Range(a, b: BigInteger): sequence of BigInteger; +/// Возвращает последовательность длинных целых от a до b с шагом step +function Range(a, b, step: BigInteger): sequence of BigInteger; /// Возвращает последовательность символов от c1 до c2 function Range(c1, c2: char): sequence of char; /// Возвращает последовательность символов от c1 до c2 с шагом step @@ -4557,7 +4561,7 @@ begin else Result := System.Linq.Enumerable.Range(a, b - a + 1); end; -function Range(a, b: real; n: integer): sequence of real; +function PartitionPoints(a, b: real; n: integer): sequence of real; begin if n = 0 then raise new System.ArgumentException('Range: n=0'); @@ -4582,11 +4586,26 @@ begin Result := Range(integer(c1), integer(c2), step).Select(x -> Chr(x)); end; -function PartitionPoints(a, b: real; n: integer): sequence of real; +function Range(a, b, step: BigInteger): sequence of BigInteger; begin - Result := Range(a, b, n) + if step = 0 then + raise new System.ArgumentException('step=0'); + if step > 0 then + while a<=b do + begin + yield a; + a += step; + end + else + while a>=b do + begin + yield a; + a += step; + end end; +function Range(a, b: BigInteger): sequence of BigInteger := Range(a,b,1); + type ArithmSeq = auto class a, step: integer; @@ -9745,6 +9764,40 @@ begin Result += f(x); end;} +// SSM 23/11/2020 - Sum Average Product for sequence of BigInteger + +/// Возвращает сумму элементов последовательности +function Sum(Self: sequence of BigInteger): BigInteger; extensionmethod; +begin + Result := 0bi; + foreach var a in Self do + Result += a +end; + +/// Возвращает среднее элементов последовательности +function Average(Self: sequence of BigInteger): real; extensionmethod; +begin + var cnt := 0; + var sum := 0bi; + foreach var a in Self do + begin + sum += a; + cnt += 1; + end; + if cnt <> 0 then + Result := sum/cnt + else Result := 0 +end; + +/// Возвращает произведение элементов последовательности +function Product(Self: sequence of BigInteger): BigInteger; extensionmethod; +begin + Result := 1bi; + foreach var a in Self do + Result *= a +end; + + /// Возвращает отсортированную по возрастанию последовательность function Sorted(Self: sequence of T): sequence of T; extensionmethod; diff --git a/bin/Lng/Rus/SemanticErrors_ms.dat b/bin/Lng/Rus/SemanticErrors_ms.dat index 4c3f71bbb..e88a11051 100644 --- a/bin/Lng/Rus/SemanticErrors_ms.dat +++ b/bin/Lng/Rus/SemanticErrors_ms.dat @@ -11,7 +11,7 @@ INTEGER_OR_CHAR_VALUE_EXPECTED=Ожидалось значение целого INCOMPATIBLE_DIAPASON_BOUNDS_TYPES=Несовместимые типы границ диапазона INCOMPATIBLE_TYPES_OF_ELEMENT_AND_DIAPASON=Тип элемента несовместим с типом диапазона BAD_SLICE_OBJECT=Срезы допустимы только для строк, динамических массивов и списков -ONLY_IN_SHORT_FUNC_DEFS_RETURN_TYPE_CANBE_OMITTED=Только в коротких определениях функций можно не указывать тип возвращаемого значения +ONLY_IN_SHORT_FUNC_DEFS_RETURN_TYPE_CANBE_OMITTED=Тип возвращаемого значения следует указать явно ONE_TKIDENTIFIER=В качестве типа ожидался идентификатор SUGARED_NODE_{0}_IN_SYNTAX_TREE_VISITOR=Сахарный узел {0} не должен обходиться в syntax_tree_visitor. Обратитесь к разработчикам PascalABC.NET MISSED_SEMANTIC_CHECK_FOR_SUGARED_NODE_{0}=Отсутствует семантическая проверка для сахарного узла {0}