SetOf на замену [1,2,3]

Преобразование массивов стандартных типов к множествам того же типа
This commit is contained in:
Mikhalkovich Stanislav 2024-07-19 11:30:18 +03:00
parent 8c22930a8c
commit 84205f86bf
6 changed files with 42 additions and 18 deletions

View file

@ -2,7 +2,7 @@
// This CSharp output file generated by Gardens Point LEX
// Version: 1.1.3.301
// Machine: DESKTOP-G8V08V4
// DateTime: 15.07.2024 13:28:05
// DateTime: 19.07.2024 11:28:35
// UserName: ?????????
// GPLEX input file <ABCPascal.lex>
// GPLEX frame file <embedded resource>

View file

@ -986,7 +986,7 @@ const_factor
const_set
: tkSquareOpen elem_list tkSquareClose
{
{
$$ = new pascal_set_constant($2 as expression_list, @$);
}
| tkVertParen elem_list tkVertParen

View file

@ -2,7 +2,7 @@
// GPPG version 1.3.6
// Machine: DESKTOP-G8V08V4
// DateTime: 15.07.2024 13:28:05
// DateTime: 19.07.2024 11:28:36
// UserName: ?????????
// Input file <D:\PABC_Git\Parsers\PascalABCParserNewSaushkin\ABCPascal.y>
@ -3661,7 +3661,13 @@ public partial class GPPGParser: ShiftReduceParser<PascalABCCompiler.ParserTools
{ CurrentSemanticValue.ex = ValueStack[ValueStack.Depth-1].ex; }
break;
case 164: // const_set -> tkSquareOpen, elem_list, tkSquareClose
{
{
// <20>?сли elem_list п<>?с<>? или соде<D0B4>?жи<D0B6>? диапазон, <20>?о э<>?о множес<D0B5>?во, ина<D0BD>?е массив. С PascalABC.NET 3.10
var is_set = false;
var el = ValueStack[ValueStack.Depth-2].stn as expression_list;
if (el.Count == 0)
is_set = true;
CurrentSemanticValue.ex = new pascal_set_constant(ValueStack[ValueStack.Depth-2].stn as expression_list, CurrentLocationSpan);
}
break;

View file

@ -384,5 +384,6 @@ script=

View file

@ -409,6 +409,36 @@ begin
Result += x;
end;}
/// Функция создания множества set по указанным значениям
function SetOf<T>(params a: array of T): set of T;
begin
Result := TypedSet.InitBy(a);
end;
///--
function operator implicit(a: array of integer): set of integer; extensionmethod := TypedSet.InitBy(a);
///--
function operator implicit(a: array of real): set of real; extensionmethod := TypedSet.InitBy(a);
///--
function operator implicit(a: array of string): set of string; extensionmethod := TypedSet.InitBy(a);
///--
function operator implicit(a: array of char): set of char; extensionmethod := TypedSet.InitBy(a);
///--
function operator implicit(a: array of shortint): set of shortint; extensionmethod := TypedSet.InitBy(a);
///--
function operator implicit(a: array of int64): set of int64; extensionmethod := TypedSet.InitBy(a);
///--
function operator implicit(a: array of byte): set of byte; extensionmethod := TypedSet.InitBy(a);
///--
function operator implicit(a: array of word): set of word; extensionmethod := TypedSet.InitBy(a);
///--
function operator implicit(a: array of longword): set of longword; extensionmethod := TypedSet.InitBy(a);
///--
function operator implicit(a: array of BigInteger): set of BigInteger; extensionmethod := TypedSet.InitBy(a);
///--
function operator implicit(a: array of decimal): set of decimal; extensionmethod := TypedSet.InitBy(a);
///--
function operator implicit(a: array of single): set of single; extensionmethod := TypedSet.InitBy(a);
//------------------------------------------------------------------------------
// Операции для procedure

View file

@ -519,9 +519,7 @@ type
function ToString: string; override;
class function operator implicit<T>(s: TypedSet): HashSet<T>;
class function operator implicit<T>(s: HashSet<T>): TypedSet;
class function operator implicit<T>(s: array of T): TypedSet;
class function InitBy<T>(s: sequence of T): TypedSet;
//class function operator implicit<T>(a: array of T): TypedSet;
function Count: integer := ht.Count;
procedure Print(delim: string := ' ');
procedure Println(delim: string := ' ');
@ -3537,7 +3535,7 @@ begin
end;
///--
class function TypedSet.operator implicit<T>(s: array of T): TypedSet;
{class function TypedSet.operator implicit<T>(s: array of T): TypedSet;
begin
var ts := new TypedSet();
foreach key: T in s do
@ -3545,17 +3543,6 @@ begin
ts.ht[key] := key;
end;
Result := ts;
end;
///--
{class function TypedSet.operator implicit<T>(a: array of T): TypedSet;
begin
var ts := new TypedSet();
foreach key: T in a do
begin
ts.ht[key] := key;
end;
Result := ts;
end;}
///--