From 05f158875d0f2a2bb7c850d98c269bdc3bed3948 Mon Sep 17 00:00:00 2001 From: Mikhalkovich Stanislav Date: Wed, 24 Feb 2021 18:41:51 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9C=D0=BD=D0=BE=D0=B3=D0=BE=D0=BC=D0=B5?= =?UTF-8?q?=D1=80=D0=BD=D1=8B=D0=B5=20=D1=81=D1=80=D0=B5=D0=B7=D1=8B=20-?= =?UTF-8?q?=20=D0=BF=D0=BE=D0=BA=D0=B0=20=D0=B1=D0=B5=D0=B7=20=D1=81=D0=B5?= =?UTF-8?q?=D0=BC=D0=B0=D0=BD=D1=82=D0=B8=D1=87=D0=B5=D1=81=D0=BA=D0=BE?= =?UTF-8?q?=D0=B3=D0=BE=20=D0=BA=D0=BE=D0=BD=D1=82=D1=80=D0=BE=D0=BB=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit И интеллисенс a[1,:] неверно показывает тип --- Configuration/GlobalAssemblyInfo.cs | 2 +- Configuration/Version.defs | 4 +- .../PascalABCParserNewSaushkin/ABCPascal.cs | 2 +- .../PascalABCParserNewSaushkin/ABCPascal.y | 2 +- .../ABCPascalYacc.cs | 4 +- Parsers/PascalABCParserNewSaushkin/PABC.ymc | 1 + Release/pabcversion.txt | 2 +- ReleaseGenerators/PascalABCNET_version.nsh | 2 +- .../StandardSyntaxConverter.cs | 4 +- SyntaxVisitors/SugarVisitors/IndexVisitor.cs | 2 +- .../SugarVisitors/SliceDesugarVisitor.cs | 17 ++++-- TestSuite/CompilationSamples/PABCSystem.pas | 60 ++++++++++++++----- TestSuite/TestMultiSlices_1.pas | 30 ++++++++++ .../semantic_checks_for_sugar.cs | 6 ++ .../TreeConversion/syntax_tree_visitor.cs | 6 +- bin/Lib/PABCSystem.pas | 60 ++++++++++++++----- 16 files changed, 154 insertions(+), 50 deletions(-) create mode 100644 TestSuite/TestMultiSlices_1.pas diff --git a/Configuration/GlobalAssemblyInfo.cs b/Configuration/GlobalAssemblyInfo.cs index f87253f13..73b153c7a 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 = "2"; - public const string Revision = "2827"; + public const string Revision = "2830"; 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 e6c0dfcf7..a207685fc 100644 --- a/Configuration/Version.defs +++ b/Configuration/Version.defs @@ -1,4 +1,4 @@ -%MINOR%=7 -%REVISION%=2827 %COREVERSION%=2 +%REVISION%=2830 +%MINOR%=7 %MAJOR%=3 diff --git a/Parsers/PascalABCParserNewSaushkin/ABCPascal.cs b/Parsers/PascalABCParserNewSaushkin/ABCPascal.cs index feefc36e4..1ef4263ad 100644 --- a/Parsers/PascalABCParserNewSaushkin/ABCPascal.cs +++ b/Parsers/PascalABCParserNewSaushkin/ABCPascal.cs @@ -2,7 +2,7 @@ // This CSharp output file generated by Gardens Point LEX // Version: 1.1.3.301 // Machine: DESKTOP-G8V08V4 -// DateTime: 24.02.2021 0:24:55 +// DateTime: 24.02.2021 14:31:41 // UserName: ????????? // GPLEX input file // GPLEX frame file diff --git a/Parsers/PascalABCParserNewSaushkin/ABCPascal.y b/Parsers/PascalABCParserNewSaushkin/ABCPascal.y index 02ed0746a..8f3efa29a 100644 --- a/Parsers/PascalABCParserNewSaushkin/ABCPascal.y +++ b/Parsers/PascalABCParserNewSaushkin/ABCPascal.y @@ -4185,7 +4185,7 @@ variable } else { - ll.Add(Tuple.Create(ex, ex, (expression)new int32_const(int.MaxValue, ex.source_context))); // + ll.Add(Tuple.Create(ex, (expression)new int32_const(0, ex.source_context), (expression)new int32_const(int.MaxValue, ex.source_context))); // } } var sle = new slice_expr($1 as addressed_value,null,null,null,@$); diff --git a/Parsers/PascalABCParserNewSaushkin/ABCPascalYacc.cs b/Parsers/PascalABCParserNewSaushkin/ABCPascalYacc.cs index a61fefb8c..93802e3bb 100644 --- a/Parsers/PascalABCParserNewSaushkin/ABCPascalYacc.cs +++ b/Parsers/PascalABCParserNewSaushkin/ABCPascalYacc.cs @@ -2,7 +2,7 @@ // GPPG version 1.3.6 // Machine: DESKTOP-G8V08V4 -// DateTime: 24.02.2021 0:24:55 +// DateTime: 24.02.2021 14:31:42 // UserName: ????????? // Input file @@ -6609,7 +6609,7 @@ public partial class GPPGParser: ShiftReduceParser { var u = s.Item3 as int32_const; return u == null || u.val != int.MaxValue; }); var mc = method_call.NewP(dot_node.NewP(sl.v, new ident("SystemSliceN"+N, sl.v.source_context), sl.v.source_context), el, sl.source_context); + var sug = sugared_addressed_value.NewP(sl, mc, sl.source_context); // пока без семантической проверки - ReplaceUsingParent(sl, mc); + ReplaceUsingParent(sl, sug); visit(mc); } } diff --git a/TestSuite/CompilationSamples/PABCSystem.pas b/TestSuite/CompilationSamples/PABCSystem.pas index 21e8e72ba..9705c7561 100644 --- a/TestSuite/CompilationSamples/PABCSystem.pas +++ b/TestSuite/CompilationSamples/PABCSystem.pas @@ -12046,20 +12046,26 @@ end; type SliceType = class situation,from, &to, step, count: integer; - oneelem: boolean; - constructor (sit,f,t: integer; st: integer := 1; oneel: boolean := false); + fromInverted, toInverted: boolean; + function oneelem: boolean := step = integer.MaxValue; // если шаг = integer.MaxValue, то это один элемент, а не срез (договорённость) + constructor (sit,f,t: integer; st: integer := 1); begin situation := sit; from := f; &to := t; + fromInverted := False; + toInverted := False; step := st; - count := -1; // заполняется во внешней функции - oneelem := oneel; - if step = integer.MaxValue then - oneelem := True; + count := -1; // заполняется во внешней функции CorrectSliceAndCalcCount при известной длине по данной размерности + //oneelem := step = integer.MaxValue; // если шаг = integer.MaxValue, то это один элемент, а не срез (договорённость) end; procedure CorrectSliceAndCalcCount(len: integer); begin + if fromInverted then // Надеюсь, что ровно здесь. Это означает, что эти значения точно не пропущены + from := len - from; + if toInverted then + &to := len - &to; + if oneelem then count := 1 else count := CheckAndCorrectFromToAndCalcCountForSystemSlice(situation, len, from, &to, step); @@ -12067,21 +12073,28 @@ type static function operator implicit(i: integer): SliceType; static function operator implicit(ir: IntRange): SliceType; static function operator implicit(sl: (integer,integer,integer)): SliceType; + static function operator implicit(sl: (SystemIndex,SystemIndex,integer)): SliceType; // a[^1:,^2] + static function operator implicit(sl: (integer,SystemIndex,integer)): SliceType; // a[^1:,^2] + static function operator implicit(sl: (SystemIndex,integer,integer)): SliceType; // a[^1:,^2] end; -function Diap(f, t: integer) := new SliceType(0, f, t, 1, false); -function Elem(ind: integer) := new SliceType(0, ind, ind+1, 1, true); -function Slice(f, t: integer; st: integer := 1; oneel: boolean := false): SliceType; +function Diap(f, t: integer) := new SliceType(0, f, t, 1); +function Elem(ind: integer) := new SliceType(0, ind, ind+1, integer.MaxValue); +function Slice(f, t: integer; st: integer := 1): SliceType; begin var sit := 0; if f = integer.MaxValue then sit += 1; if t = integer.MaxValue then sit += 2; - if st = integer.MaxValue then - oneel := True; - Result := new SliceType(sit, f, t, st, oneel); + Result := new SliceType(sit, f, t, st); end; +{function Slice(f, t: SystemIndex; st: integer := 1): SliceType; +begin + Result := Slice(f.IndexValue, t.IndexValue, st); + Result.fromInverted := f.IsInverted; + Result.toInverted := t.IsInverted; +end;} static function SliceType.operator implicit(i: integer): SliceType; begin @@ -12098,6 +12111,24 @@ begin Result := Slice(sl[0],sl[1],sl[2]); end; +static function SliceType.operator implicit(sl: (SystemIndex,SystemIndex,integer)): SliceType; +begin + Result := Slice(sl[0].IndexValue,sl[1].IndexValue,sl[2]); + Result.fromInverted := sl[0].IsInverted; + Result.toInverted := sl[1].IsInverted; +end; + +static function SliceType.operator implicit(sl: (integer,SystemIndex,integer)): SliceType; +begin + Result := Slice(sl[0],sl[1].IndexValue,sl[2]); + Result.toInverted := sl[1].IsInverted; +end; + +static function SliceType.operator implicit(sl: (SystemIndex,integer,integer)): SliceType; +begin + Result := Slice(sl[0].IndexValue,sl[1],sl[2]); + Result.fromInverted := sl[0].IsInverted; +end; function ToOneDim(a: array [,] of T; l: array of SliceType): array of T; begin @@ -12192,7 +12223,6 @@ end; function FromOneDim2(r: array of T; l: array of SliceType): array [,] of T; begin var dims := l.FindAll(x -> x.oneelem = False).ConvertAll(x -> x.count); - Assert(dims.Length = 2); var cur := 0; var res := new T[dims[0],dims[1]]; for var i0:=0 to dims[0]-1 do @@ -12207,7 +12237,6 @@ end; function FromOneDim3(r: array of T; l: array of SliceType): array [,,] of T; begin var dims := l.FindAll(x -> x.oneelem = False).ConvertAll(x -> x.count); - Assert(dims.Length = 3); var cur := 0; var res := new T[dims[0],dims[1],dims[2]]; for var i0:=0 to dims[0]-1 do @@ -12223,7 +12252,6 @@ end; function FromOneDim4(r: array of T; l: array of SliceType): array [,,,] of T; begin var dims := l.FindAll(x -> x.oneelem = False).ConvertAll(x -> x.count); - Assert(dims.Length = 4); var cur := 0; var res := new T[dims[0],dims[1],dims[2],dims[3]]; for var i0:=0 to dims[0]-1 do @@ -12266,7 +12294,7 @@ begin Result := FromOneDimN(r,l); end; -{type +{type // это не компилируется в PABCSystem ArrT = array of T; Arr2T = array [,] of T; Arr3T = array [,,] of T; diff --git a/TestSuite/TestMultiSlices_1.pas b/TestSuite/TestMultiSlices_1.pas new file mode 100644 index 000000000..f2041985f --- /dev/null +++ b/TestSuite/TestMultiSlices_1.pas @@ -0,0 +1,30 @@ +procedure AssertEq(m: array [,] of T; a: array of array of T); +begin + Assert(m.MatrEqual(MatrByRow(a))); +end; + +procedure AssertEq(m,a: array [,] of T); +begin + Assert(m.MatrEqual(a)); +end; + +procedure AssertEq(m: array of T; a: array of T); +begin + Assert(m.SequenceEqual(a)); +end; + +begin + var d := [[6,7,8],[10,11,12]]; + var m := MatrByRow(||1,2,3,4|,|5,6,7,8|,|9,10,11,12||); + AssertEq(m[:,:],m); + AssertEq(m[::1,::1],m); + AssertEq(m[1:3,1:4],||6,7,8|,|10,11,12||); + AssertEq(m[::2,::3],||1,4|,|9,12||); + AssertEq(m[::-2,::-1],||12,11,10,9|,|4,3,2,1||); + AssertEq(m[^2::-1,^2::-1],||7,6,5|,|3,2,1||); + AssertEq(m[:^1,:^1],||1,2,3|,|5,6,7||); + AssertEq(m[1,:],|5,6,7,8|); + AssertEq(m[^1,:],|9,10,11,12|); + AssertEq(m[:,^1],|4,8,12|); + Print(m[:,^1]); +end. \ No newline at end of file diff --git a/TreeConverter/TreeConversion/semantic_checks_for_sugar.cs b/TreeConverter/TreeConversion/semantic_checks_for_sugar.cs index c568a0f40..cdb0ddb25 100644 --- a/TreeConverter/TreeConversion/semantic_checks_for_sugar.cs +++ b/TreeConverter/TreeConversion/semantic_checks_for_sugar.cs @@ -136,6 +136,12 @@ namespace PascalABCCompiler.TreeConverter } } + + void semantic_check_method_call_as_slice_expr_multi(SyntaxTree.method_call mc) + { + + } + /*void semantic_check_tuple(SyntaxTree.tuple_node tup) { //if (tup.el.expressions.Count > 7) diff --git a/TreeConverter/TreeConversion/syntax_tree_visitor.cs b/TreeConverter/TreeConversion/syntax_tree_visitor.cs index de735b483..7c75fbd2d 100644 --- a/TreeConverter/TreeConversion/syntax_tree_visitor.cs +++ b/TreeConverter/TreeConversion/syntax_tree_visitor.cs @@ -21019,9 +21019,11 @@ namespace PascalABCCompiler.TreeConverter { semantic_check_method_call_as_diapason_expr(av.new_addr_value as SyntaxTree.method_call); } - else if (av.sugared_expr is SyntaxTree.slice_expr) // и slice_expr_question + else if (av.sugared_expr is SyntaxTree.slice_expr slex) // и slice_expr_question { - semantic_check_method_call_as_slice_expr(av.new_addr_value as SyntaxTree.method_call); + if (slex.slices == null) + semantic_check_method_call_as_slice_expr(av.new_addr_value as SyntaxTree.method_call); + else semantic_check_method_call_as_slice_expr_multi(av.new_addr_value as SyntaxTree.method_call); } else if (av.sugared_expr is SyntaxTree.dot_question_node) { diff --git a/bin/Lib/PABCSystem.pas b/bin/Lib/PABCSystem.pas index 21e8e72ba..9705c7561 100644 --- a/bin/Lib/PABCSystem.pas +++ b/bin/Lib/PABCSystem.pas @@ -12046,20 +12046,26 @@ end; type SliceType = class situation,from, &to, step, count: integer; - oneelem: boolean; - constructor (sit,f,t: integer; st: integer := 1; oneel: boolean := false); + fromInverted, toInverted: boolean; + function oneelem: boolean := step = integer.MaxValue; // если шаг = integer.MaxValue, то это один элемент, а не срез (договорённость) + constructor (sit,f,t: integer; st: integer := 1); begin situation := sit; from := f; &to := t; + fromInverted := False; + toInverted := False; step := st; - count := -1; // заполняется во внешней функции - oneelem := oneel; - if step = integer.MaxValue then - oneelem := True; + count := -1; // заполняется во внешней функции CorrectSliceAndCalcCount при известной длине по данной размерности + //oneelem := step = integer.MaxValue; // если шаг = integer.MaxValue, то это один элемент, а не срез (договорённость) end; procedure CorrectSliceAndCalcCount(len: integer); begin + if fromInverted then // Надеюсь, что ровно здесь. Это означает, что эти значения точно не пропущены + from := len - from; + if toInverted then + &to := len - &to; + if oneelem then count := 1 else count := CheckAndCorrectFromToAndCalcCountForSystemSlice(situation, len, from, &to, step); @@ -12067,21 +12073,28 @@ type static function operator implicit(i: integer): SliceType; static function operator implicit(ir: IntRange): SliceType; static function operator implicit(sl: (integer,integer,integer)): SliceType; + static function operator implicit(sl: (SystemIndex,SystemIndex,integer)): SliceType; // a[^1:,^2] + static function operator implicit(sl: (integer,SystemIndex,integer)): SliceType; // a[^1:,^2] + static function operator implicit(sl: (SystemIndex,integer,integer)): SliceType; // a[^1:,^2] end; -function Diap(f, t: integer) := new SliceType(0, f, t, 1, false); -function Elem(ind: integer) := new SliceType(0, ind, ind+1, 1, true); -function Slice(f, t: integer; st: integer := 1; oneel: boolean := false): SliceType; +function Diap(f, t: integer) := new SliceType(0, f, t, 1); +function Elem(ind: integer) := new SliceType(0, ind, ind+1, integer.MaxValue); +function Slice(f, t: integer; st: integer := 1): SliceType; begin var sit := 0; if f = integer.MaxValue then sit += 1; if t = integer.MaxValue then sit += 2; - if st = integer.MaxValue then - oneel := True; - Result := new SliceType(sit, f, t, st, oneel); + Result := new SliceType(sit, f, t, st); end; +{function Slice(f, t: SystemIndex; st: integer := 1): SliceType; +begin + Result := Slice(f.IndexValue, t.IndexValue, st); + Result.fromInverted := f.IsInverted; + Result.toInverted := t.IsInverted; +end;} static function SliceType.operator implicit(i: integer): SliceType; begin @@ -12098,6 +12111,24 @@ begin Result := Slice(sl[0],sl[1],sl[2]); end; +static function SliceType.operator implicit(sl: (SystemIndex,SystemIndex,integer)): SliceType; +begin + Result := Slice(sl[0].IndexValue,sl[1].IndexValue,sl[2]); + Result.fromInverted := sl[0].IsInverted; + Result.toInverted := sl[1].IsInverted; +end; + +static function SliceType.operator implicit(sl: (integer,SystemIndex,integer)): SliceType; +begin + Result := Slice(sl[0],sl[1].IndexValue,sl[2]); + Result.toInverted := sl[1].IsInverted; +end; + +static function SliceType.operator implicit(sl: (SystemIndex,integer,integer)): SliceType; +begin + Result := Slice(sl[0].IndexValue,sl[1],sl[2]); + Result.fromInverted := sl[0].IsInverted; +end; function ToOneDim(a: array [,] of T; l: array of SliceType): array of T; begin @@ -12192,7 +12223,6 @@ end; function FromOneDim2(r: array of T; l: array of SliceType): array [,] of T; begin var dims := l.FindAll(x -> x.oneelem = False).ConvertAll(x -> x.count); - Assert(dims.Length = 2); var cur := 0; var res := new T[dims[0],dims[1]]; for var i0:=0 to dims[0]-1 do @@ -12207,7 +12237,6 @@ end; function FromOneDim3(r: array of T; l: array of SliceType): array [,,] of T; begin var dims := l.FindAll(x -> x.oneelem = False).ConvertAll(x -> x.count); - Assert(dims.Length = 3); var cur := 0; var res := new T[dims[0],dims[1],dims[2]]; for var i0:=0 to dims[0]-1 do @@ -12223,7 +12252,6 @@ end; function FromOneDim4(r: array of T; l: array of SliceType): array [,,,] of T; begin var dims := l.FindAll(x -> x.oneelem = False).ConvertAll(x -> x.count); - Assert(dims.Length = 4); var cur := 0; var res := new T[dims[0],dims[1],dims[2],dims[3]]; for var i0:=0 to dims[0]-1 do @@ -12266,7 +12294,7 @@ begin Result := FromOneDimN(r,l); end; -{type +{type // это не компилируется в PABCSystem ArrT = array of T; Arr2T = array [,] of T; Arr3T = array [,,] of T;