From db9679d89ff7548ed432a8bc28677887284aa6c9 Mon Sep 17 00:00:00 2001 From: Mikhalkovich Stanislav Date: Tue, 10 Dec 2024 10:59:20 +0300 Subject: [PATCH] =?UTF-8?q?=D0=97=D0=B0=D0=BA=D0=BE=D0=BD=D1=87=D0=B8?= =?UTF-8?q?=D0=BB=20=D0=BF=D1=80=D0=B5=D0=B2=D1=80=D0=B0=D1=89=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D0=B5=20=D1=81=D0=B8=D0=BD=D1=82=D0=B0=D0=BA=D1=81=D0=B8?= =?UTF-8?q?=D1=81=D0=B0=20[]=20=D0=BF=D0=BE=20=D1=83=D0=BC=D0=BE=D0=BB?= =?UTF-8?q?=D1=87=D0=B0=D0=BD=D0=B8=D1=8E=20=D0=B2=20=D0=BC=D0=B0=D1=81?= =?UTF-8?q?=D1=81=D0=B8=D0=B2=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Configuration/GlobalAssemblyInfo.cs | 2 +- Configuration/Version.defs | 2 +- Release/pabcversion.txt | 2 +- ReleaseGenerators/PascalABCNET_version.nsh | 2 +- .../CompilationSamples/PABCExtensions.pas | 134 +++++++++++++++++- TestSuite/CompilationSamples/PABCSystem.pas | 10 +- TestSuite/class2.pas | 4 +- TestSuite/delegates4.pas | 2 +- TestSuite/foreachvar3.pas | 4 +- TestSuite/set1.pas | 32 ++--- TestSuite/set10.pas | 4 +- TestSuite/set11.pas | 2 +- TestSuite/set2u.pas | 31 ++-- TestSuite/set6.pas | 2 +- TestSuite/set7.pas | 3 +- TestSuite/typedconst1.pas | 2 +- TestSuite/typedconst2.pas | 6 +- TestSuite/units/u_class2.pas | 4 +- TestSuite/units/u_set1.pas | 32 ++--- TestSuite/units/u_set7.pas | 2 +- .../TreeConversion/syntax_tree_visitor.cs | 118 +++++++++++++-- bin/Lib/PABCExtensions.pas | 134 +++++++++++++++++- bin/Lib/PABCSystem.pas | 10 +- 23 files changed, 454 insertions(+), 90 deletions(-) diff --git a/Configuration/GlobalAssemblyInfo.cs b/Configuration/GlobalAssemblyInfo.cs index 5bd9cd8b3..de6f3a968 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 = "10"; public const string Build = "1"; - public const string Revision = "3581"; + public const string Revision = "3589"; 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 96e2158e8..3eb1bd1a4 100644 --- a/Configuration/Version.defs +++ b/Configuration/Version.defs @@ -1,4 +1,4 @@ %MINOR%=10 -%REVISION%=3581 +%REVISION%=3589 %COREVERSION%=1 %MAJOR%=3 diff --git a/Release/pabcversion.txt b/Release/pabcversion.txt index b1ac2081c..efb9a4ee1 100644 --- a/Release/pabcversion.txt +++ b/Release/pabcversion.txt @@ -1 +1 @@ -3.10.1.3581 +3.10.1.3589 diff --git a/ReleaseGenerators/PascalABCNET_version.nsh b/ReleaseGenerators/PascalABCNET_version.nsh index e6142740b..14369c7e6 100644 --- a/ReleaseGenerators/PascalABCNET_version.nsh +++ b/ReleaseGenerators/PascalABCNET_version.nsh @@ -1 +1 @@ -!define VERSION '3.10.1.3581' +!define VERSION '3.10.1.3589' diff --git a/TestSuite/CompilationSamples/PABCExtensions.pas b/TestSuite/CompilationSamples/PABCExtensions.pas index ca84f0288..0411e324a 100644 --- a/TestSuite/CompilationSamples/PABCExtensions.pas +++ b/TestSuite/CompilationSamples/PABCExtensions.pas @@ -34,7 +34,7 @@ const SLICE_SIZE_AND_RIGHT_VALUE_SIZE_MUST_BE_EQUAL = 'Размеры среза и присваиваемого выражения должны быть равны!!Slice size and assigned expression size must be equal'; OUT_OF_TYPE_RANGE_IN_SET_ASSIGNMENT = 'Выход за границы типа множества!!Out of type range in set assignment'; OUT_OF_TYPE_RANGE_IN_SET_OPERATION = 'Выход за границы типа множества!!Out of type range in set operation'; - + OUT_OF_TYPE_RANGE_IN_ARR_OPERATION = 'Выход за границы типа массива!!Out of type range in array operation'; //{{{doc: Начало секции расширений строк для срезов }}} @@ -967,7 +967,7 @@ begin end; function operator+(a: set of byte; b: set of integer): set of integer; extensionmethod - := b * a; + := b + a; function operator+(a: set of integer; b: set of int64): set of int64; extensionmethod; begin @@ -976,7 +976,7 @@ begin end; function operator+(a: set of int64; b: set of integer): set of int64; extensionmethod - := b * a; + := b + a; // set + array function operator+(a: array of integer; b: set of byte): set of integer; extensionmethod; @@ -986,7 +986,7 @@ begin end; function operator+(a: set of byte; b: array of integer): set of integer; extensionmethod - := b * a; + := b + a; function operator+(a: array of integer; b: set of int64): set of int64; extensionmethod; begin @@ -995,7 +995,7 @@ begin end; function operator+(a: set of int64; b: array of integer): set of int64; extensionmethod - := b * a; + := b + a; function operator+(a: set of integer; b: array of integer): set of integer; extensionmethod; begin @@ -1004,7 +1004,42 @@ begin end; function operator+(a: array of integer; b: set of integer): set of integer; extensionmethod - := b * a; + := b + a; + + +// operator+ для array of num + [1,2,3] +function operator+(a: array of byte; b: array of integer): array of integer; extensionmethod + := a.ConvertAll(x -> integer(x)) + b; +function operator+(a: array of integer; b: array of byte): array of integer; extensionmethod + := b + a; +function operator+(a: array of shortint; b: array of integer): array of integer; extensionmethod + := a.ConvertAll(x -> integer(x)) + b; +function operator+(a: array of integer; b: array of shortint): array of integer; extensionmethod + := b + a; +function operator+(a: array of smallint; b: array of integer): array of integer; extensionmethod + := a.ConvertAll(x -> integer(x)) + b; +function operator+(a: array of integer; b: array of smallint): array of integer; extensionmethod + := b + a; +function operator+(a: array of word; b: array of integer): array of integer; extensionmethod + := a.ConvertAll(x -> integer(x)) + b; +function operator+(a: array of integer; b: array of word): array of integer; extensionmethod + := b + a; +function operator+(a: array of longword; b: array of integer): array of int64; extensionmethod + := a.ConvertAll(x -> int64(x)) + b.ConvertAll(x -> int64(x)); +function operator+(a: array of integer; b: array of longword): array of int64; extensionmethod + := b + a; +function operator+(a: array of int64; b: array of integer): array of int64; extensionmethod + := a + b.ConvertAll(x -> int64(x)); +function operator+(a: array of integer; b: array of int64): array of int64; extensionmethod + := b + a; +function operator+(a: array of uint64; b: array of integer): array of uint64; extensionmethod; +begin + if b.Any(x -> x < 0) then + raise new System.ArgumentException(GetTranslation(OUT_OF_TYPE_RANGE_IN_ARR_OPERATION)); + Result := a + b.ConvertAll(x -> uint64(x)); +end; +function operator+(a: array of integer; b: array of uint64): array of uint64; extensionmethod + := b + a; // operator- sets @@ -1069,6 +1104,93 @@ begin Result.hs.ExceptWith(b); end; +{function operator in(x: byte; a: array of integer): boolean; extensionmethod + := a.Contains(integer(x)); +function operator in(x: word; a: array of integer): boolean; extensionmethod + := a.Contains(integer(x)); +function operator in(x: shortint; a: array of integer): boolean; extensionmethod + := a.Contains(integer(x)); +function operator in(x: smallint; a: array of integer): boolean; extensionmethod + := a.Contains(integer(x)); +function operator in(x: longword; a: array of integer): boolean; extensionmethod + := a.Select(x -> int64(x)).Contains(int64(x)); +function operator in(x: int64; a: array of integer): boolean; extensionmethod + := a.Select(x -> int64(x)).Contains(x); +function operator in(x: uint64; a: array of integer): boolean; extensionmethod; +begin + if x > integer.MaxValue then + Result := False + else Result := a.Contains(integer(x)); +end;} + +function operator in(x: int64; a: array of byte): boolean; extensionmethod + := (x >= byte.MinValue) and (x <= byte.MaxValue) and a.Contains(byte(x)); +function operator in(x: int64; a: array of shortint): boolean; extensionmethod + := (x >= shortint.MinValue) and (x <= shortint.MaxValue) and a.Contains(shortint(x)); +function operator in(x: int64; a: array of smallint): boolean; extensionmethod + := (x >= smallint.MinValue) and (x <= smallint.MaxValue) and a.Contains(smallint(x)); +function operator in(x: int64; a: array of word): boolean; extensionmethod + := (x >= word.MinValue) and (x <= word.MaxValue) and a.Contains(word(x)); +function operator in(x: int64; a: array of longword): boolean; extensionmethod + := (x >= longword.MinValue) and (x <= longword.MaxValue) and a.Contains(longword(x)); +function operator in(x: int64; a: array of integer): boolean; extensionmethod + := (x >= integer.MinValue) and (x <= integer.MaxValue) and a.Contains(integer(x)); +function operator in(x: int64; a: array of uint64): boolean; extensionmethod + := (x >= uint64.MinValue) and a.Contains(uint64(x)); + +function operator in(x: byte; a: array of byte): boolean; extensionmethod := int64(x) in a; +function operator in(x: byte; a: array of shortint): boolean; extensionmethod := int64(x) in a; +function operator in(x: byte; a: array of smallint): boolean; extensionmethod := int64(x) in a; +function operator in(x: byte; a: array of word): boolean; extensionmethod := int64(x) in a; +function operator in(x: byte; a: array of longword): boolean; extensionmethod := int64(x) in a; +function operator in(x: byte; a: array of integer): boolean; extensionmethod := int64(x) in a; +function operator in(x: byte; a: array of int64): boolean; extensionmethod := int64(x) in a; +function operator in(x: byte; a: array of uint64): boolean; extensionmethod := int64(x) in a; + +function operator in(x: shortint; a: array of byte): boolean; extensionmethod := int64(x) in a; +function operator in(x: shortint; a: array of shortint): boolean; extensionmethod := int64(x) in a; +function operator in(x: shortint; a: array of smallint): boolean; extensionmethod := int64(x) in a; +function operator in(x: shortint; a: array of word): boolean; extensionmethod := int64(x) in a; +function operator in(x: shortint; a: array of longword): boolean; extensionmethod := int64(x) in a; +function operator in(x: shortint; a: array of integer): boolean; extensionmethod := int64(x) in a; +function operator in(x: shortint; a: array of int64): boolean; extensionmethod := int64(x) in a; +function operator in(x: shortint; a: array of uint64): boolean; extensionmethod := int64(x) in a; + +function operator in(x: smallint; a: array of byte): boolean; extensionmethod := int64(x) in a; +function operator in(x: smallint; a: array of shortint): boolean; extensionmethod := int64(x) in a; +function operator in(x: smallint; a: array of smallint): boolean; extensionmethod := int64(x) in a; +function operator in(x: smallint; a: array of word): boolean; extensionmethod := int64(x) in a; +function operator in(x: smallint; a: array of longword): boolean; extensionmethod := int64(x) in a; +function operator in(x: smallint; a: array of integer): boolean; extensionmethod := int64(x) in a; +function operator in(x: smallint; a: array of int64): boolean; extensionmethod := int64(x) in a; +function operator in(x: smallint; a: array of uint64): boolean; extensionmethod := int64(x) in a; + +function operator in(x: word; a: array of byte): boolean; extensionmethod := int64(x) in a; +function operator in(x: word; a: array of shortint): boolean; extensionmethod := int64(x) in a; +function operator in(x: word; a: array of smallint): boolean; extensionmethod := int64(x) in a; +function operator in(x: word; a: array of word): boolean; extensionmethod := int64(x) in a; +function operator in(x: word; a: array of longword): boolean; extensionmethod := int64(x) in a; +function operator in(x: word; a: array of integer): boolean; extensionmethod := int64(x) in a; +function operator in(x: word; a: array of int64): boolean; extensionmethod := int64(x) in a; +function operator in(x: word; a: array of uint64): boolean; extensionmethod := int64(x) in a; + +function operator in(x: longword; a: array of byte): boolean; extensionmethod := int64(x) in a; +function operator in(x: longword; a: array of shortint): boolean; extensionmethod := int64(x) in a; +function operator in(x: longword; a: array of smallint): boolean; extensionmethod := int64(x) in a; +function operator in(x: longword; a: array of word): boolean; extensionmethod := int64(x) in a; +function operator in(x: longword; a: array of longword): boolean; extensionmethod := int64(x) in a; +function operator in(x: longword; a: array of integer): boolean; extensionmethod := int64(x) in a; +function operator in(x: longword; a: array of int64): boolean; extensionmethod := int64(x) in a; +function operator in(x: longword; a: array of uint64): boolean; extensionmethod := int64(x) in a; + +function operator in(x: integer; a: array of byte): boolean; extensionmethod := int64(x) in a; +function operator in(x: integer; a: array of shortint): boolean; extensionmethod := int64(x) in a; +function operator in(x: integer; a: array of smallint): boolean; extensionmethod := int64(x) in a; +function operator in(x: integer; a: array of word): boolean; extensionmethod := int64(x) in a; +function operator in(x: integer; a: array of longword): boolean; extensionmethod := int64(x) in a; +function operator in(x: integer; a: array of integer): boolean; extensionmethod := int64(x) in a; +function operator in(x: integer; a: array of int64): boolean; extensionmethod := int64(x) in a; +function operator in(x: integer; a: array of uint64): boolean; extensionmethod := int64(x) in a; var __initialized: boolean; diff --git a/TestSuite/CompilationSamples/PABCSystem.pas b/TestSuite/CompilationSamples/PABCSystem.pas index 9c4d637f5..66615463a 100644 --- a/TestSuite/CompilationSamples/PABCSystem.pas +++ b/TestSuite/CompilationSamples/PABCSystem.pas @@ -540,6 +540,9 @@ type Result.hs.UnionWith(first); Result._hs.ExceptWith(second); end; static function operator=(first, second: NewSet) := first.hs.SetEquals(second.hs); + {static function operator=(first: NewSet; second: array of T) := first.hs.SetEquals(second); + static function operator=(first: array of T; second: NewSet) := second = first;} + static function operator<>(first, second: NewSet) := not (first = second); static function operator<(first, second: NewSet) := first.hs.IsProperSubsetOf(second.hs); static function operator<=(first, second: NewSet) := first.hs.IsSubsetOf(second.hs); @@ -5015,6 +5018,7 @@ end; ///-- function operator in(x: T; a: array of T): boolean; extensionmethod := a.Contains(x); +// operator in для конкретных num in [1,2,3] - в PABCExtensions function operator*(a: array of T; n: integer): array of T; extensionmethod; begin @@ -15478,7 +15482,11 @@ end; -//function operator implicit(ns: NewSetEmpty): NewSet; extensionmethod; begin end; +function operator implicit(a: array of T): HashSet; extensionmethod + := new HashSet(a); + +function operator implicit(a: array of integer): HashSet; extensionmethod + := new HashSet(a); // ----------------------------------------------------------------------------- // Внутренние вспомогательные функции diff --git a/TestSuite/class2.pas b/TestSuite/class2.pas index 9ccf9494a..cbf246edb 100644 --- a/TestSuite/class2.pas +++ b/TestSuite/class2.pas @@ -1,4 +1,4 @@ -type TClass = class +type TClass = class function Test1 : integer; begin Result := 1; @@ -50,7 +50,7 @@ if Test3 then begin end; while not Test3 do; -var set1 := [Test1,Test2]; +var set1: set of integer := [Test1,Test2]; assert(Test1 in set1); var set2 := [Test1..Test2]; assert(3 in set2); diff --git a/TestSuite/delegates4.pas b/TestSuite/delegates4.pas index b94a272b6..95dbb3223 100644 --- a/TestSuite/delegates4.pas +++ b/TestSuite/delegates4.pas @@ -1,4 +1,4 @@ -type TFunc = function(i: integer):integer; +type TFunc = function(i: integer):integer; function f1(i : integer) : integer; begin diff --git a/TestSuite/foreachvar3.pas b/TestSuite/foreachvar3.pas index 6f70a80e6..8278fe0af 100644 --- a/TestSuite/foreachvar3.pas +++ b/TestSuite/foreachvar3.pas @@ -1,4 +1,4 @@ -procedure p(s: set of T; f: T->T); +procedure p(s: set of T; f: T->T); begin foreach var x in s do begin @@ -8,6 +8,6 @@ begin end; begin - var s := [1,2,3,7,2,4]; + var s: set of integer := [1,2,3,7,2,4]; p(s,x->x); end. diff --git a/TestSuite/set1.pas b/TestSuite/set1.pas index 6f1b231a6..8e74eec30 100644 --- a/TestSuite/set1.pas +++ b/TestSuite/set1.pas @@ -48,10 +48,10 @@ begin assert([2..4]=[2,3,4]); assert(['a','c'..'f']>['a']); assert([1..6]<>[2..4]); - assert([2,3]+[7,8]=[2,3,7,8]); - assert([1,4,6]*[1,6]=[1,6]); - assert([1]+[2] <= [1..3]); - assert([2,3,5]-[2,3] = [5]); + assert(SetOf(2,3)+[7,8]=[2,3,7,8]); + assert(SetOf(1,4,6)*[1,6]=[1,6]); + assert(SetOf(1)+[2] <= [1..3]); + assert(SetOf(2,3,5)-[2,3] = [5]); assert(5 in [4,5,8]); assert([1,2]+[] = [1,2]); assert([1,2]*[] = []); @@ -113,10 +113,10 @@ s2 := [1,4]; assert(s2 = [1,4]); assert([2..4]=[2,3,4]); assert(['a','c'..'f']>['a']); assert([1..6]<>[2..4]); - assert([2,3]+[7,8]=[2,3,7,8]); - assert([1,4,6]*[1,6]=[1,6]); - assert([1]+[2] <= [1..3]); - assert([2,3,5]-[2,3] = [5]); + assert(SetOf(2,3)+[7,8]=[2,3,7,8]); + assert(SetOf(1,4,6)*[1,6]=[1,6]); + assert(SetOf(1)+[2] <= [1..3]); + assert(SetOf(2,3,5)-[2,3] = [5]); assert(5 in [4,5,8]); assert([1,2]+[] = [1,2]); assert([1,2]*[] = []); @@ -162,10 +162,10 @@ begin assert([2..4]=[2,3,4]); assert(['a','c'..'f']>['a']); assert([1..6]<>[2..4]); - assert([2,3]+[7,8]=[2,3,7,8]); - assert([1,4,6]*[1,6]=[1,6]); - assert([1]+[2] <= [1..3]); - assert([2,3,5]-[2,3] = [5]); + assert(SetOf(2,3)+[7,8]=[2,3,7,8]); + assert(SetOf(1,4,6)*[1,6]=[1,6]); + assert(SetOf(1)+[2] <= [1..3]); + assert(SetOf(2,3,5)-[2,3] = [5]); assert(5 in [4,5,8]); assert([1,2]+[] = [1,2]); assert([1,2]*[] = []); @@ -249,10 +249,10 @@ begin assert([2..4]=[2,3,4]); assert(['a','c'..'f']>['a']); assert([1..6]<>[2..4]); - assert([2,3]+[7,8]=[2,3,7,8]); - assert([1,4,6]*[1,6]=[1,6]); - assert([1]+[2] <= [1..3]); - assert([2,3,5]-[2,3] = [5]); + assert(SetOf(2,3)+[7,8]=[2,3,7,8]); + assert(SetOf(1,4,6)*[1,6]=[1,6]); + assert(SetOf(1)+[2] <= [1..3]); + assert(SetOf(2,3,5)-[2,3] = [5]); assert(5 in [4,5,8]); assert([1,2]+[] = [1,2]); assert([1,2]*[] = []); diff --git a/TestSuite/set10.pas b/TestSuite/set10.pas index 7795b0431..29847f4a3 100644 --- a/TestSuite/set10.pas +++ b/TestSuite/set10.pas @@ -1,5 +1,5 @@ -begin +begin var s1 := ['a']; - var s := ['a','b','c']-s1; + var s := SetOf('a','b','c')-s1; assert('b' in s); end. \ No newline at end of file diff --git a/TestSuite/set11.pas b/TestSuite/set11.pas index 1f58c8dad..127c246f1 100644 --- a/TestSuite/set11.pas +++ b/TestSuite/set11.pas @@ -1,7 +1,7 @@ begin var tupl := (1,2,[3,4,5]); assert(tupl.Item1 = 1); - assert(tupl.Item3 = [3,4,5]); + assert(tupl.Item3 = SetOf(3,4,5)); assert(4 in tupl.Item3); var s: set of integer := tupl.Item3; assert(4 in s); diff --git a/TestSuite/set2u.pas b/TestSuite/set2u.pas index 0b301ebed..3520f0912 100644 --- a/TestSuite/set2u.pas +++ b/TestSuite/set2u.pas @@ -50,10 +50,11 @@ begin assert([2..4]=[2,3,4]); assert(['a','c'..'f']>['a']); assert([1..6]<>[2..4]); - assert([2,3]+[7,8]=[2,3,7,8]); - assert([1,4,6]*[1,6]=[1,6]); - assert([1]+[2] <= [1..3]); - assert([2,3,5]-[2,3] = [5]); + assert(SetOf(2,3)+[7,8]=[2,3,7,8]); + var sss: set of integer := [1,4,6]; + assert(sss*[1,6]=[1,6]); + assert(SetOf(1)+[2] <= [1..3]); + assert(SetOf(2,3,5)-[2,3] = [5]); assert(5 in [4,5,8]); assert([1,2]+[] = [1,2]); assert([1,2]*[] = []); @@ -115,10 +116,10 @@ s2 := [1,4]; assert(s2 = [1,4]); assert([2..4]=[2,3,4]); assert(['a','c'..'f']>['a']); assert([1..6]<>[2..4]); - assert([2,3]+[7,8]=[2,3,7,8]); - assert([1,4,6]*[1,6]=[1,6]); + assert(SetOf(2,3)+[7,8]=[2,3,7,8]); + assert(SetOf(1,4,6)*[1,6]=[1,6]); assert([1]+[2] <= [1..3]); - assert([2,3,5]-[2,3] = [5]); + assert(SetOf(2,3,5)-[2,3] = [5]); assert(5 in [4,5,8]); assert([1,2]+[] = [1,2]); assert([1,2]*[] = []); @@ -164,10 +165,10 @@ begin assert([2..4]=[2,3,4]); assert(['a','c'..'f']>['a']); assert([1..6]<>[2..4]); - assert([2,3]+[7,8]=[2,3,7,8]); - assert([1,4,6]*[1,6]=[1,6]); - assert([1]+[2] <= [1..3]); - assert([2,3,5]-[2,3] = [5]); + assert(SetOf(2,3)+[7,8]=[2,3,7,8]); + assert(SetOf(1,4,6)*[1,6]=[1,6]); + assert(SetOf(1)+[2] <= [1..3]); + assert(SetOf(2,3,5)-[2,3] = [5]); assert(5 in [4,5,8]); assert([1,2]+[] = [1,2]); assert([1,2]*[] = []); @@ -252,10 +253,10 @@ begin assert([2..4]=[2,3,4]); assert(['a','c'..'f']>['a']); assert([1..6]<>[2..4]); - assert([2,3]+[7,8]=[2,3,7,8]); - assert([1,4,6]*[1,6]=[1,6]); - assert([1]+[2] <= [1..3]); - assert([2,3,5]-[2,3] = [5]); + assert(SetOf(2,3)+[7,8]=[2,3,7,8]); + assert(SetOf(1,4,6)*[1,6]=[1,6]); + assert(SetOf(1)+[2] <= [1..3]); + assert(SetOf(2,3,5)-[2,3] = [5]); assert(5 in [4,5,8]); assert([1,2]+[] = [1,2]); assert([1,2]*[] = []); diff --git a/TestSuite/set6.pas b/TestSuite/set6.pas index bf04ecd42..018e61e03 100644 --- a/TestSuite/set6.pas +++ b/TestSuite/set6.pas @@ -2,7 +2,7 @@ s : set of 1..3 = [1,2,3,4]; s2 : set of char = {['a','b']*}['b']; -var s3 : set of 1..3 := [1,2]+[3,4]; +var s3 : set of 1..3 := SetOf(1,2)+[3,4]; begin assert(s=[1,2,3,4]); diff --git a/TestSuite/set7.pas b/TestSuite/set7.pas index 1ae966943..fc29536b9 100644 --- a/TestSuite/set7.pas +++ b/TestSuite/set7.pas @@ -11,7 +11,8 @@ s2 : set of integer; begin -assert([b,sh,sm,w,i,lw,li,ui]=[1,2,3,4,5,6,7,8]); +var s1_8: set of integer := [1,2,3,4,5,6,7,8]; +assert([b,sh,sm,w,i,lw,li,ui]=s1_8); Include(s1,integer.MaxValue); s1.Add(longword.MaxValue); //s1 += [longword.MaxValue]; diff --git a/TestSuite/typedconst1.pas b/TestSuite/typedconst1.pas index 95f49d7e4..fc048dfd3 100644 --- a/TestSuite/typedconst1.pas +++ b/TestSuite/typedconst1.pas @@ -1,4 +1,4 @@ -type TArr = array[1..3] of integer; +type TArr = array[1..3] of integer; TRec = record a : integer; b : real; end; TSet = set of byte; diff --git a/TestSuite/typedconst2.pas b/TestSuite/typedconst2.pas index 34cb49856..18b176391 100644 --- a/TestSuite/typedconst2.pas +++ b/TestSuite/typedconst2.pas @@ -1,4 +1,4 @@ -uses typedconst2u; +uses typedconst2u; begin assert(a=[1..4]); assert(2 in a); @@ -9,13 +9,13 @@ assert('b' in e); assert(e=['a','b','c']); assert(f=two); assert(one in g); -assert(g=[one,three]); +assert(g=SetOf(one,three)); assert(h=one); assert(i=3); assert(j[3]=2.6); assert(k=two); assert(three in l); -assert(l=[one,three]); +assert(l=SetOf(one,three)); assert(m.b[1]=3); assert(n[1,2]=2); end. \ No newline at end of file diff --git a/TestSuite/units/u_class2.pas b/TestSuite/units/u_class2.pas index 4d9e4925e..2a1c02113 100644 --- a/TestSuite/units/u_class2.pas +++ b/TestSuite/units/u_class2.pas @@ -1,4 +1,4 @@ -unit u_class2; +unit u_class2; type TClass = class function Test1 : integer; begin @@ -51,7 +51,7 @@ if Test3 then begin end; while not Test3 do; -var set1 := [Test1,Test2]; +var set1: set of integer := [Test1,Test2]; assert(Test1 in set1); var set2 := [Test1..Test2]; assert(3 in set2); diff --git a/TestSuite/units/u_set1.pas b/TestSuite/units/u_set1.pas index 74df58030..2f41c73a0 100644 --- a/TestSuite/units/u_set1.pas +++ b/TestSuite/units/u_set1.pas @@ -49,10 +49,10 @@ begin assert([2..4]=[2,3,4]); assert(['a','c'..'f']>['a']); assert([1..6]<>[2..4]); - assert([2,3]+[7,8]=[2,3,7,8]); - assert([1,4,6]*[1,6]=[1,6]); - assert([1]+[2] <= [1..3]); - assert([2,3,5]-[2,3] = [5]); + assert(SetOf(2,3)+[7,8]=[2,3,7,8]); + assert(SetOf(1,4,6)*[1,6]=[1,6]); + assert(SetOf(1)+[2] <= [1..3]); + assert(SetOf(2,3,5)-[2,3] = [5]); assert(5 in [4,5,8]); assert([1,2]+[] = [1,2]); assert([1,2]*[] = []); @@ -114,10 +114,10 @@ s2 := [1,4]; assert(s2 = [1,4]); assert([2..4]=[2,3,4]); assert(['a','c'..'f']>['a']); assert([1..6]<>[2..4]); - assert([2,3]+[7,8]=[2,3,7,8]); - assert([1,4,6]*[1,6]=[1,6]); - assert([1]+[2] <= [1..3]); - assert([2,3,5]-[2,3] = [5]); + assert(SetOf(2,3)+[7,8]=[2,3,7,8]); + assert(SetOf(1,4,6)*[1,6]=[1,6]); + assert(SetOf(1)+[2] <= [1..3]); + assert(SetOf(2,3,5)-[2,3] = [5]); assert(5 in [4,5,8]); assert([1,2]+[] = [1,2]); assert([1,2]*[] = []); @@ -163,10 +163,10 @@ begin assert([2..4]=[2,3,4]); assert(['a','c'..'f']>['a']); assert([1..6]<>[2..4]); - assert([2,3]+[7,8]=[2,3,7,8]); - assert([1,4,6]*[1,6]=[1,6]); - assert([1]+[2] <= [1..3]); - assert([2,3,5]-[2,3] = [5]); + assert(SetOf(2,3)+[7,8]=[2,3,7,8]); + assert(SetOf(1,4,6)*[1,6]=[1,6]); + assert(SetOf(1)+[2] <= [1..3]); + assert(SetOf(2,3,5)-[2,3] = [5]); assert(5 in [4,5,8]); assert([1,2]+[] = [1,2]); assert([1,2]*[] = []); @@ -250,10 +250,10 @@ begin assert([2..4]=[2,3,4]); assert(['a','c'..'f']>['a']); assert([1..6]<>[2..4]); - assert([2,3]+[7,8]=[2,3,7,8]); - assert([1,4,6]*[1,6]=[1,6]); - assert([1]+[2] <= [1..3]); - assert([2,3,5]-[2,3] = [5]); + assert(SetOf(2,3)+[7,8]=[2,3,7,8]); + assert(SetOf(1,4,6)*[1,6]=[1,6]); + assert(SetOf(1)+[2] <= [1..3]); + assert(SetOf(2,3,5)-[2,3] = [5]); assert(5 in [4,5,8]); assert([1,2]+[] = [1,2]); assert([1,2]*[] = []); diff --git a/TestSuite/units/u_set7.pas b/TestSuite/units/u_set7.pas index ed5ff5af4..471b8bcf9 100644 --- a/TestSuite/units/u_set7.pas +++ b/TestSuite/units/u_set7.pas @@ -13,7 +13,7 @@ var s2 : set of integer; begin -assert([b,sh,sm,w,i,lw,li,ui]=[1,2,3,4,5,6,7,8]); +assert([b,sh,sm,w,i,lw,li,ui]=SetOf(1,2,3,4,5,6,7,8)); Include(s1,integer.MaxValue); s1.Add(longword.MaxValue); s1 += [int64.MaxValue,uint64.MaxValue]; diff --git a/TreeConverter/TreeConversion/syntax_tree_visitor.cs b/TreeConverter/TreeConversion/syntax_tree_visitor.cs index 497676e76..7fac9e2c6 100644 --- a/TreeConverter/TreeConversion/syntax_tree_visitor.cs +++ b/TreeConverter/TreeConversion/syntax_tree_visitor.cs @@ -5232,6 +5232,19 @@ namespace PascalABCCompiler.TreeConverter public override void visit(SyntaxTree.pascal_set_constant _pascal_set_constant) { + // Если хоть одно - diapason_expr, то это множество иначе литеральный массив + if (_pascal_set_constant.values == null || + _pascal_set_constant.values.expressions.Any(ex => ex is SyntaxTree.diapason_expr) + ) + { // это множество + } + else + { + var exl = new expression_list(_pascal_set_constant.values.expressions, _pascal_set_constant.source_context); + array_const_new ac = new array_const_new(exl,exl.source_context); + visit(ac); + return; + } // надо разбить на 2 списка констант expressions_list consts = new expressions_list(); expressions_list consts_diap = new expressions_list(); @@ -5374,10 +5387,15 @@ namespace PascalABCCompiler.TreeConverter public override void visit(SyntaxTree.array_const_new acn) { var lst = acn.elements.expressions.Select(ex => { var semex = convert_strong(ex); try_convert_typed_expression_to_function_call(ref semex); return semex; }).ToList(); - + type_node_list types = new type_node_list(); foreach (var tn in lst.Select(ex => ex.type)) - types.AddElement(tn); + { + if (tn.type_special_kind == type_special_kind.diap_type) // SSM 4/12/24 - стирание информации о типе диапазона + types.AddElement(tn.base_type); + else types.AddElement(tn); + } + var el_type = convertion_data_and_alghoritms.select_base_type_for_arr_const_new(types, lst, true); var syntax_type = new SyntaxTree.semantic_type_node(el_type); //SyntaxTree.semantic_addr_value sav; @@ -15098,6 +15116,8 @@ namespace PascalABCCompiler.TreeConverter AddError(get_location(_array_type.indexers), "ARRAY_RANK_CANNOT_BE_GREATER_32"); type_node ret = null; type_node et = convert_strong(_array_type.elements_type); + if (et.type_special_kind == type_special_kind.diap_type) // SSM 4/12/24 + et = et.base_type; //if (et == SystemLibrary.SystemLibrary.void_type) //AddError(new VoidNotValid(get_location(_array_type.elemets_types))); check_for_type_allowed(et,get_location(_array_type.elements_type)); @@ -15311,6 +15331,27 @@ namespace PascalABCCompiler.TreeConverter is_userdefined = !(cnf.function_node.namespace_node.namespace_name.Equals(StringConstants.pascalSystemUnitName) || cnf.function_node.namespace_node.namespace_name.Equals("PABCSystem_implementation______")); } + /*if (exp.type is ArrayConstType + || convertion_data_and_alghoritms.eq_type_nodes(exp.type, tn)) + { + return convert_strong_to_constant_node(exp, tn, is_const_section && is_userdefined, is_const_section); + } + else + { + var conv = convertion_data_and_alghoritms.convert_type(exp, tn); + return convert_strong_to_constant_node(conv, tn, is_const_section && is_userdefined, is_const_section); + }*/ + + /*if (expr is pascal_set_constant) + { + var conv = convertion_data_and_alghoritms.convert_type(exp, tn); + return convert_strong_to_constant_node(conv, tn, is_const_section && is_userdefined, is_const_section); + } + else + { + return convert_strong_to_constant_node(exp, tn, is_const_section && is_userdefined, is_const_section); + }*/ + return convert_strong_to_constant_node(exp, tn, is_const_section && is_userdefined, is_const_section); } @@ -15424,12 +15465,14 @@ namespace PascalABCCompiler.TreeConverter constant = new common_namespace_function_call_as_constant(expr as common_namespace_function_call, loc); return constant; } - foreach (expression_node el in cnfc.parameters) - convert_strong_to_constant_node(el, el.type, false, false, cnfc.location); + if (cnfc.function_node.name != "op_Implicit") + foreach (expression_node el in cnfc.parameters) + convert_strong_to_constant_node(el, el.type, false, false, cnfc.location); //if (cnfc.function_node.namespace_node == context.converted_namespace) // AddError(loc, "CONSTANT_EXPRESSION_EXPECTED"); // throw new ConstantExpressionExpected(loc); constant = new common_namespace_function_call_as_constant(expr as common_namespace_function_call, loc); + return constant; } else if (expr is common_namespace_function_call_as_constant cnfcac && cnfcac.type.name == "NewSetEmpty") @@ -15444,6 +15487,11 @@ namespace PascalABCCompiler.TreeConverter constant = cnfcac1; return constant; } + else if (expr is common_constructor_call) + { + constant = new common_constructor_call_as_constant(expr as common_constructor_call, null); + return constant; + } else if (expr is common_constructor_call_as_constant cccac) { // @@ -15455,9 +15503,38 @@ namespace PascalABCCompiler.TreeConverter basic_function_call cnfc = expr as basic_function_call; //if (cnfc.function_node.namespace_node == context.converted_namespace) // throw new ConstantExpressionExpected(loc); - foreach (expression_node el in cnfc.parameters) - convert_strong_to_constant_node(el, el.type); - constant = new basic_function_call_as_constant(expr as basic_function_call, loc); + + // Как быть с new integer[5](2,3,4)? Там cnfc.parameters сщдержит 1 элемент, у которого в parameters первые три элемента - информационные + if (cnfc.parameters[0] is common_namespace_function_call cnsfc && + cnsfc.function_node.SpecialFunctionKind == SpecialFunctionKind.NewArray) + { + foreach (expression_node el in cnsfc.parameters.Skip(3)) // это для 1 + 2 * 3 + convert_strong_to_constant_node(el, el.type); + if (convertion_data_and_alghoritms.eq_type_nodes(expr.type, tn)) + { + constant = new basic_function_call_as_constant(expr as basic_function_call, loc); + return constant; + } + else + { + var conv = convertion_data_and_alghoritms.convert_type(expr, tn); + constant = convert_strong_to_constant_node(conv, tn); + return constant; + } + } + else + { + foreach (expression_node el in cnfc.parameters) // это для 1 + 2 * 3 - этот код был + convert_strong_to_constant_node(el, el.type); + } + + constant = new basic_function_call_as_constant(expr as basic_function_call, loc); // - этот код был + return constant; + } + else if (expr is basic_function_call_as_constant bfcac) + { + constant = bfcac; + return constant; } else if (expr is typed_expression) { @@ -15625,6 +15702,11 @@ namespace PascalABCCompiler.TreeConverter constant = new common_static_method_call_as_constant(csmc, null); break; } + if (csmc.function_node.name == "op_Implicit") // SSM 04/12/24 - это делается для преобразования array в set + { + constant = new common_static_method_call_as_constant(csmc, loc); + return constant; + } } else { @@ -15991,7 +16073,17 @@ namespace PascalABCCompiler.TreeConverter else throw new CompilerInternalError("Unexpected array type"); for (int i = 0; i < constant.element_values.Count; i++) - constant.element_values[i] = convert_strong_to_constant_node(constant.element_values[i], element_type); + { + if (constant.element_values[i].type is ArrayConstType + || convertion_data_and_alghoritms.eq_type_nodes(constant.element_values[i].type,element_type)) + constant.element_values[i] = convert_strong_to_constant_node(constant.element_values[i], element_type); + else + { + var conv = convertion_data_and_alghoritms.convert_type(constant.element_values[i], element_type); + constant.element_values[i] = convert_strong_to_constant_node(conv, element_type); + } + //convertion_data_and_alghoritms.check_convert_type(constant.element_values[i], element_type,constant.element_values[i].location); + } constant.SetType(tn); return constant; } @@ -18207,6 +18299,16 @@ namespace PascalABCCompiler.TreeConverter { expression_node left = convert_strong(_bin_expr.left); expression_node right = convert_strong(_bin_expr.right); + + // SSM 04/12/24 - массивы нельзя умножать и вычитать. Это запрещено т.к. в библиотеку добавлены arr * set и arr - set + if (left.type != null && left.type.type_special_kind == type_special_kind.array_kind + && right.type != null && right.type.type_special_kind == type_special_kind.array_kind + && (_bin_expr.operation_type == Operators.Multiplication || _bin_expr.operation_type == Operators.Minus) + ) + { + AddError(get_location(_bin_expr), "OPERATOR_{0}_CAN_NOT_BE_APPLIED_TO_TYPES_{1}_AND_{2}", name_reflector.get_name(_bin_expr.operation_type), left.type, right.type); + } + if (_bin_expr.operation_type == Operators.In) try_convert_typed_expression_to_function_call(ref left); expression_node res = find_operator(_bin_expr.operation_type, left, right, get_location(_bin_expr)); diff --git a/bin/Lib/PABCExtensions.pas b/bin/Lib/PABCExtensions.pas index bd8b7be99..2b9fdbe19 100644 --- a/bin/Lib/PABCExtensions.pas +++ b/bin/Lib/PABCExtensions.pas @@ -34,7 +34,7 @@ const SLICE_SIZE_AND_RIGHT_VALUE_SIZE_MUST_BE_EQUAL = 'Размеры среза и присваиваемого выражения должны быть равны!!Slice size and assigned expression size must be equal'; OUT_OF_TYPE_RANGE_IN_SET_ASSIGNMENT = 'Выход за границы типа множества!!Out of type range in set assignment'; OUT_OF_TYPE_RANGE_IN_SET_OPERATION = 'Выход за границы типа множества!!Out of type range in set operation'; - + OUT_OF_TYPE_RANGE_IN_ARR_OPERATION = 'Выход за границы типа массива!!Out of type range in array operation'; //{{{doc: Начало секции расширений строк для срезов }}} @@ -967,7 +967,7 @@ begin end; function operator+(a: set of byte; b: set of integer): set of integer; extensionmethod - := b * a; + := b + a; function operator+(a: set of integer; b: set of int64): set of int64; extensionmethod; begin @@ -976,7 +976,7 @@ begin end; function operator+(a: set of int64; b: set of integer): set of int64; extensionmethod - := b * a; + := b + a; // set + array function operator+(a: array of integer; b: set of byte): set of integer; extensionmethod; @@ -986,7 +986,7 @@ begin end; function operator+(a: set of byte; b: array of integer): set of integer; extensionmethod - := b * a; + := b + a; function operator+(a: array of integer; b: set of int64): set of int64; extensionmethod; begin @@ -995,7 +995,7 @@ begin end; function operator+(a: set of int64; b: array of integer): set of int64; extensionmethod - := b * a; + := b + a; function operator+(a: set of integer; b: array of integer): set of integer; extensionmethod; begin @@ -1004,7 +1004,42 @@ begin end; function operator+(a: array of integer; b: set of integer): set of integer; extensionmethod - := b * a; + := b + a; + + +// operator+ для array of num + [1,2,3] +function operator+(a: array of byte; b: array of integer): array of integer; extensionmethod + := a.ConvertAll(x -> integer(x)) + b; +function operator+(a: array of integer; b: array of byte): array of integer; extensionmethod + := b + a; +function operator+(a: array of shortint; b: array of integer): array of integer; extensionmethod + := a.ConvertAll(x -> integer(x)) + b; +function operator+(a: array of integer; b: array of shortint): array of integer; extensionmethod + := b + a; +function operator+(a: array of smallint; b: array of integer): array of integer; extensionmethod + := a.ConvertAll(x -> integer(x)) + b; +function operator+(a: array of integer; b: array of smallint): array of integer; extensionmethod + := b + a; +function operator+(a: array of word; b: array of integer): array of integer; extensionmethod + := a.ConvertAll(x -> integer(x)) + b; +function operator+(a: array of integer; b: array of word): array of integer; extensionmethod + := b + a; +function operator+(a: array of longword; b: array of integer): array of int64; extensionmethod + := a.ConvertAll(x -> int64(x)) + b.ConvertAll(x -> int64(x)); +function operator+(a: array of integer; b: array of longword): array of int64; extensionmethod + := b + a; +function operator+(a: array of int64; b: array of integer): array of int64; extensionmethod + := a + b.ConvertAll(x -> int64(x)); +function operator+(a: array of integer; b: array of int64): array of int64; extensionmethod + := b + a; +function operator+(a: array of uint64; b: array of integer): array of uint64; extensionmethod; +begin + if b.Any(x -> x < 0) then + raise new System.ArgumentException(GetTranslation(OUT_OF_TYPE_RANGE_IN_ARR_OPERATION)); + Result := a + b.ConvertAll(x -> uint64(x)); +end; +function operator+(a: array of integer; b: array of uint64): array of uint64; extensionmethod + := b + a; // operator- sets @@ -1069,6 +1104,93 @@ begin Result.hs.ExceptWith(b); end; +{function operator in(x: byte; a: array of integer): boolean; extensionmethod + := a.Contains(integer(x)); +function operator in(x: word; a: array of integer): boolean; extensionmethod + := a.Contains(integer(x)); +function operator in(x: shortint; a: array of integer): boolean; extensionmethod + := a.Contains(integer(x)); +function operator in(x: smallint; a: array of integer): boolean; extensionmethod + := a.Contains(integer(x)); +function operator in(x: longword; a: array of integer): boolean; extensionmethod + := a.Select(x -> int64(x)).Contains(int64(x)); +function operator in(x: int64; a: array of integer): boolean; extensionmethod + := a.Select(x -> int64(x)).Contains(x); +function operator in(x: uint64; a: array of integer): boolean; extensionmethod; +begin + if x > integer.MaxValue then + Result := False + else Result := a.Contains(integer(x)); +end;} + +function operator in(x: int64; a: array of byte): boolean; extensionmethod + := (x >= byte.MinValue) and (x <= byte.MaxValue) and a.Contains(byte(x)); +function operator in(x: int64; a: array of shortint): boolean; extensionmethod + := (x >= shortint.MinValue) and (x <= shortint.MaxValue) and a.Contains(shortint(x)); +function operator in(x: int64; a: array of smallint): boolean; extensionmethod + := (x >= smallint.MinValue) and (x <= smallint.MaxValue) and a.Contains(smallint(x)); +function operator in(x: int64; a: array of word): boolean; extensionmethod + := (x >= word.MinValue) and (x <= word.MaxValue) and a.Contains(word(x)); +function operator in(x: int64; a: array of longword): boolean; extensionmethod + := (x >= longword.MinValue) and (x <= longword.MaxValue) and a.Contains(longword(x)); +function operator in(x: int64; a: array of integer): boolean; extensionmethod + := (x >= integer.MinValue) and (x <= integer.MaxValue) and a.Contains(integer(x)); +function operator in(x: int64; a: array of uint64): boolean; extensionmethod + := (x >= uint64.MinValue) and a.Contains(uint64(x)); + +function operator in(x: byte; a: array of byte): boolean; extensionmethod := int64(x) in a; +function operator in(x: byte; a: array of shortint): boolean; extensionmethod := int64(x) in a; +function operator in(x: byte; a: array of smallint): boolean; extensionmethod := int64(x) in a; +function operator in(x: byte; a: array of word): boolean; extensionmethod := int64(x) in a; +function operator in(x: byte; a: array of longword): boolean; extensionmethod := int64(x) in a; +function operator in(x: byte; a: array of integer): boolean; extensionmethod := int64(x) in a; +function operator in(x: byte; a: array of int64): boolean; extensionmethod := int64(x) in a; +function operator in(x: byte; a: array of uint64): boolean; extensionmethod := int64(x) in a; + +function operator in(x: shortint; a: array of byte): boolean; extensionmethod := int64(x) in a; +function operator in(x: shortint; a: array of shortint): boolean; extensionmethod := int64(x) in a; +function operator in(x: shortint; a: array of smallint): boolean; extensionmethod := int64(x) in a; +function operator in(x: shortint; a: array of word): boolean; extensionmethod := int64(x) in a; +function operator in(x: shortint; a: array of longword): boolean; extensionmethod := int64(x) in a; +function operator in(x: shortint; a: array of integer): boolean; extensionmethod := int64(x) in a; +function operator in(x: shortint; a: array of int64): boolean; extensionmethod := int64(x) in a; +function operator in(x: shortint; a: array of uint64): boolean; extensionmethod := int64(x) in a; + +function operator in(x: smallint; a: array of byte): boolean; extensionmethod := int64(x) in a; +function operator in(x: smallint; a: array of shortint): boolean; extensionmethod := int64(x) in a; +function operator in(x: smallint; a: array of smallint): boolean; extensionmethod := int64(x) in a; +function operator in(x: smallint; a: array of word): boolean; extensionmethod := int64(x) in a; +function operator in(x: smallint; a: array of longword): boolean; extensionmethod := int64(x) in a; +function operator in(x: smallint; a: array of integer): boolean; extensionmethod := int64(x) in a; +function operator in(x: smallint; a: array of int64): boolean; extensionmethod := int64(x) in a; +function operator in(x: smallint; a: array of uint64): boolean; extensionmethod := int64(x) in a; + +function operator in(x: word; a: array of byte): boolean; extensionmethod := int64(x) in a; +function operator in(x: word; a: array of shortint): boolean; extensionmethod := int64(x) in a; +function operator in(x: word; a: array of smallint): boolean; extensionmethod := int64(x) in a; +function operator in(x: word; a: array of word): boolean; extensionmethod := int64(x) in a; +function operator in(x: word; a: array of longword): boolean; extensionmethod := int64(x) in a; +function operator in(x: word; a: array of integer): boolean; extensionmethod := int64(x) in a; +function operator in(x: word; a: array of int64): boolean; extensionmethod := int64(x) in a; +function operator in(x: word; a: array of uint64): boolean; extensionmethod := int64(x) in a; + +function operator in(x: longword; a: array of byte): boolean; extensionmethod := int64(x) in a; +function operator in(x: longword; a: array of shortint): boolean; extensionmethod := int64(x) in a; +function operator in(x: longword; a: array of smallint): boolean; extensionmethod := int64(x) in a; +function operator in(x: longword; a: array of word): boolean; extensionmethod := int64(x) in a; +function operator in(x: longword; a: array of longword): boolean; extensionmethod := int64(x) in a; +function operator in(x: longword; a: array of integer): boolean; extensionmethod := int64(x) in a; +function operator in(x: longword; a: array of int64): boolean; extensionmethod := int64(x) in a; +function operator in(x: longword; a: array of uint64): boolean; extensionmethod := int64(x) in a; + +function operator in(x: integer; a: array of byte): boolean; extensionmethod := int64(x) in a; +function operator in(x: integer; a: array of shortint): boolean; extensionmethod := int64(x) in a; +function operator in(x: integer; a: array of smallint): boolean; extensionmethod := int64(x) in a; +function operator in(x: integer; a: array of word): boolean; extensionmethod := int64(x) in a; +function operator in(x: integer; a: array of longword): boolean; extensionmethod := int64(x) in a; +function operator in(x: integer; a: array of integer): boolean; extensionmethod := int64(x) in a; +function operator in(x: integer; a: array of int64): boolean; extensionmethod := int64(x) in a; +function operator in(x: integer; a: array of uint64): boolean; extensionmethod := int64(x) in a; var __initialized: boolean; diff --git a/bin/Lib/PABCSystem.pas b/bin/Lib/PABCSystem.pas index 9c4d637f5..66615463a 100644 --- a/bin/Lib/PABCSystem.pas +++ b/bin/Lib/PABCSystem.pas @@ -540,6 +540,9 @@ type Result.hs.UnionWith(first); Result._hs.ExceptWith(second); end; static function operator=(first, second: NewSet) := first.hs.SetEquals(second.hs); + {static function operator=(first: NewSet; second: array of T) := first.hs.SetEquals(second); + static function operator=(first: array of T; second: NewSet) := second = first;} + static function operator<>(first, second: NewSet) := not (first = second); static function operator<(first, second: NewSet) := first.hs.IsProperSubsetOf(second.hs); static function operator<=(first, second: NewSet) := first.hs.IsSubsetOf(second.hs); @@ -5015,6 +5018,7 @@ end; ///-- function operator in(x: T; a: array of T): boolean; extensionmethod := a.Contains(x); +// operator in для конкретных num in [1,2,3] - в PABCExtensions function operator*(a: array of T; n: integer): array of T; extensionmethod; begin @@ -15478,7 +15482,11 @@ end; -//function operator implicit(ns: NewSetEmpty): NewSet; extensionmethod; begin end; +function operator implicit(a: array of T): HashSet; extensionmethod + := new HashSet(a); + +function operator implicit(a: array of integer): HashSet; extensionmethod + := new HashSet(a); // ----------------------------------------------------------------------------- // Внутренние вспомогательные функции