FIX #2265
This commit is contained in:
parent
a51e2d9b3f
commit
44a5bee28c
|
|
@ -15,7 +15,7 @@ internal static class RevisionClass
|
||||||
public const string Major = "3";
|
public const string Major = "3";
|
||||||
public const string Minor = "6";
|
public const string Minor = "6";
|
||||||
public const string Build = "3";
|
public const string Build = "3";
|
||||||
public const string Revision = "2514";
|
public const string Revision = "2518";
|
||||||
|
|
||||||
public const string MainVersion = Major + "." + Minor;
|
public const string MainVersion = Major + "." + Minor;
|
||||||
public const string FullVersion = Major + "." + Minor + "." + Build + "." + Revision;
|
public const string FullVersion = Major + "." + Minor + "." + Build + "." + Revision;
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
%COREVERSION%=3
|
%COREVERSION%=3
|
||||||
%REVISION%=2514
|
%REVISION%=2518
|
||||||
%MINOR%=6
|
%MINOR%=6
|
||||||
%MAJOR%=3
|
%MAJOR%=3
|
||||||
|
|
|
||||||
Binary file not shown.
|
|
@ -1 +1 @@
|
||||||
3.6.3.2514
|
3.6.3.2518
|
||||||
|
|
|
||||||
|
|
@ -1 +1 @@
|
||||||
!define VERSION '3.6.3.2514'
|
!define VERSION '3.6.3.2518'
|
||||||
|
|
|
||||||
|
|
@ -207,6 +207,14 @@ namespace SyntaxVisitors.SugarVisitors
|
||||||
visit(desugaredMatchWith);
|
visit(desugaredMatchWith);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private int num = 0;
|
||||||
|
|
||||||
|
public string GenerateNewName(string name)
|
||||||
|
{
|
||||||
|
num += 1;
|
||||||
|
return "$RenIsVarYield" + num + "$" + name;
|
||||||
|
}
|
||||||
|
|
||||||
public override void visit(is_pattern_expr isPatternExpr)
|
public override void visit(is_pattern_expr isPatternExpr)
|
||||||
{
|
{
|
||||||
if (GetLocation(isPatternExpr) == PatternLocation.Unknown)
|
if (GetLocation(isPatternExpr) == PatternLocation.Unknown)
|
||||||
|
|
@ -214,6 +222,46 @@ namespace SyntaxVisitors.SugarVisitors
|
||||||
|
|
||||||
Debug.Assert(GetAscendant<statement_list>(isPatternExpr) != null, "Couldn't find statement list in upper nodes");
|
Debug.Assert(GetAscendant<statement_list>(isPatternExpr) != null, "Couldn't find statement list in upper nodes");
|
||||||
|
|
||||||
|
var l = new List<statement>();
|
||||||
|
//l.Add(stat);
|
||||||
|
var pp = isPatternExpr.right?.parameters;
|
||||||
|
if (pp != null)
|
||||||
|
{
|
||||||
|
foreach (var p in pp)
|
||||||
|
{
|
||||||
|
if (p is var_deconstructor_parameter vdp)
|
||||||
|
{
|
||||||
|
var idClone = vdp.identifier.TypedClone();
|
||||||
|
var idNew = vdp.identifier.TypedClone();
|
||||||
|
idNew.name = GenerateNewName(idNew.name);
|
||||||
|
var vs = new var_statement(idClone, idNew, idClone.source_context);
|
||||||
|
vdp.identifier.name = idNew.name;
|
||||||
|
l.Add(vs);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var stat = GetAscendant<statement>(isPatternExpr);
|
||||||
|
if (stat is if_node ifn)
|
||||||
|
{
|
||||||
|
//l.Add(ifn.then_body);
|
||||||
|
if (!(ifn.then_body is statement_list))
|
||||||
|
{
|
||||||
|
ifn.then_body = new statement_list(ifn.then_body);
|
||||||
|
}
|
||||||
|
(ifn.then_body as statement_list).list.InsertRange(0, l);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
l.Insert(0, stat);
|
||||||
|
foreach (var x in l)
|
||||||
|
x.Parent = stat.Parent;
|
||||||
|
var stl = stat.Parent as statement_list;
|
||||||
|
stl.ReplaceInList(stat, l);
|
||||||
|
}
|
||||||
|
|
||||||
|
//ReplaceStatement(stat, l); // тут нельзя.
|
||||||
|
|
||||||
DesugarIsExpression(isPatternExpr);
|
DesugarIsExpression(isPatternExpr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -65,6 +65,7 @@
|
||||||
<Compile Include="VisitorsForLambdas\RenameOnExceptVarsVisitor.cs" />
|
<Compile Include="VisitorsForLambdas\RenameOnExceptVarsVisitor.cs" />
|
||||||
<Compile Include="VisitorsForLambdas\RenameSameVarNamesVisitor.cs" />
|
<Compile Include="VisitorsForLambdas\RenameSameVarNamesVisitor.cs" />
|
||||||
<Compile Include="VisitorsForLambdas\StandOutExprWithLambdaInForeachSequenceVisitor.cs" />
|
<Compile Include="VisitorsForLambdas\StandOutExprWithLambdaInForeachSequenceVisitor.cs" />
|
||||||
|
<Compile Include="YieldVisitors\IsVarRenameVisitor.cs" />
|
||||||
<Compile Include="YieldVisitors\ObjectCopier\ObjectCopier.cs" />
|
<Compile Include="YieldVisitors\ObjectCopier\ObjectCopier.cs" />
|
||||||
<Compile Include="Optimization\CalcConstExprs.cs" />
|
<Compile Include="Optimization\CalcConstExprs.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
|
|
|
||||||
|
|
@ -85,5 +85,11 @@ namespace SyntaxVisitors
|
||||||
|
|
||||||
// еще - не заходить в лямбды
|
// еще - не заходить в лямбды
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override void visit(desugared_deconstruction dd)
|
||||||
|
{
|
||||||
|
DefaultVisit(dd);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
60
SyntaxVisitors/YieldVisitors/IsVarRenameVisitor.cs
Normal file
60
SyntaxVisitors/YieldVisitors/IsVarRenameVisitor.cs
Normal file
|
|
@ -0,0 +1,60 @@
|
||||||
|
// Copyright (c) Ivan Bondarev, Stanislav Mikhalkovich (for details please see \doc\copyright.txt)
|
||||||
|
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
using PascalABCCompiler;
|
||||||
|
using PascalABCCompiler.SyntaxTree;
|
||||||
|
|
||||||
|
namespace SyntaxVisitors
|
||||||
|
{
|
||||||
|
public class IsVarRenameVisitor : BaseChangeVisitor
|
||||||
|
{
|
||||||
|
|
||||||
|
public IsVarRenameVisitor()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public static IsVarRenameVisitor New
|
||||||
|
{
|
||||||
|
get { return new IsVarRenameVisitor(); }
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void Accept(procedure_definition pd)
|
||||||
|
{
|
||||||
|
New.ProcessNode(pd);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void visit(procedure_header proc_header)
|
||||||
|
{
|
||||||
|
// DO THIS THING!
|
||||||
|
}
|
||||||
|
/* public override void visit(desugared_deconstruction dd)
|
||||||
|
{
|
||||||
|
var l = new List<statement>();
|
||||||
|
l.Add(dd);
|
||||||
|
foreach (var d in dd.variables.definitions)
|
||||||
|
{
|
||||||
|
foreach (var id in d.vars.idents)
|
||||||
|
{
|
||||||
|
// добавить после неё кучу объявлений с присваиваниями
|
||||||
|
//ReplaceStatement(dd,)
|
||||||
|
var newvar = new ident(NewVariableName(id.name),id.source_context);
|
||||||
|
var vs = new var_statement(new ident(id.name, id.source_context), newvar, id.source_context);
|
||||||
|
l.Add(vs);
|
||||||
|
id.name = newvar.name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ReplaceStatement(dd, l);
|
||||||
|
}*/
|
||||||
|
|
||||||
|
private string NewVariableName(string name)
|
||||||
|
{
|
||||||
|
name = name.ToLower();
|
||||||
|
return "$RenIsVarYield$" + name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -971,6 +971,11 @@ namespace SyntaxVisitors
|
||||||
pd.visit(checkVarRedefVisitor);
|
pd.visit(checkVarRedefVisitor);
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
// Если есть в pd узлы is_pattern_expr, то запустить визитор, добавляющий присваивание временной переменной и заменяющий
|
||||||
|
// везде далее имя исходной переменной на имя временной
|
||||||
|
// SSM 20/06 - не очень так получается. Сложно
|
||||||
|
//IsVarRenameVisitor.Accept(pd);
|
||||||
|
|
||||||
// Выносим выражение из yield в отдельную переменную
|
// Выносим выражение из yield в отдельную переменную
|
||||||
ReplaceYieldExprByVarVisitor.Accept(pd);
|
ReplaceYieldExprByVarVisitor.Accept(pd);
|
||||||
|
|
||||||
|
|
|
||||||
18
TestSuite/isvar2.pas
Normal file
18
TestSuite/isvar2.pas
Normal file
|
|
@ -0,0 +1,18 @@
|
||||||
|
function f1(o: object): sequence of object;
|
||||||
|
begin
|
||||||
|
|
||||||
|
//var c := o is object(var a);
|
||||||
|
if o is object(var a) then
|
||||||
|
begin
|
||||||
|
// var b := a;
|
||||||
|
// Writeln(a); // object
|
||||||
|
yield a;
|
||||||
|
Assert(a <> nil); // nil
|
||||||
|
// Writeln(b); // object
|
||||||
|
// b := b;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
begin
|
||||||
|
foreach var o in f1(new object) do
|
||||||
|
end.
|
||||||
19
TestSuite/isvar3.pas
Normal file
19
TestSuite/isvar3.pas
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
function f1(o: object): sequence of object;
|
||||||
|
begin
|
||||||
|
|
||||||
|
//var c := o is object(var a);
|
||||||
|
if o is object(var a) then
|
||||||
|
//begin
|
||||||
|
// var b := a;
|
||||||
|
// Writeln(a); // object
|
||||||
|
yield a;
|
||||||
|
//Assert(a <> nil); // nil
|
||||||
|
// Writeln(b); // object
|
||||||
|
// b := b;
|
||||||
|
//end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
begin
|
||||||
|
foreach var o in f1(new object) do
|
||||||
|
Assert(o<>nil)
|
||||||
|
end.
|
||||||
19
TestSuite/isvar4.pas
Normal file
19
TestSuite/isvar4.pas
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
function f1(o: object): sequence of object;
|
||||||
|
begin
|
||||||
|
|
||||||
|
var c := o is object(var a);
|
||||||
|
//if o is object(var a) then
|
||||||
|
//begin
|
||||||
|
// var b := a;
|
||||||
|
// Writeln(a); // object
|
||||||
|
yield a;
|
||||||
|
Assert(a <> nil); // nil
|
||||||
|
// Writeln(b); // object
|
||||||
|
// b := b;
|
||||||
|
//end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
begin
|
||||||
|
foreach var o in f1(new object) do
|
||||||
|
|
||||||
|
end.
|
||||||
|
|
@ -39,3 +39,4 @@ ONE_DIM_ARRAY_OR_LIST_EXPECTED=One-dimensional array or list expected
|
||||||
TUPLE_TYPE_ELEMENTS_COUNT_MUST_BE_LESSEQUAL_7=Number of elements in tuple type must be less than 8
|
TUPLE_TYPE_ELEMENTS_COUNT_MUST_BE_LESSEQUAL_7=Number of elements in tuple type must be less than 8
|
||||||
OVERRIDE_METHODS_CANNOT_CONTAIN_WHERE_SECTION=Methods with override modifier can't contain where section
|
OVERRIDE_METHODS_CANNOT_CONTAIN_WHERE_SECTION=Methods with override modifier can't contain where section
|
||||||
Ìåòîäû ñ ìîäèôèêàòîðîì override íå ìîãóò ñîäåðæàòü ñîáñòâåííóþ ñåêöèþ where
|
Ìåòîäû ñ ìîäèôèêàòîðîì override íå ìîãóò ñîäåðæàòü ñîáñòâåííóþ ñåêöèþ where
|
||||||
|
EXPLICIT_CASTS_FOR_LAMBDA_EXPRESSIONS_ARE_FORBIDDEN=Explicit type casts for lambda expressions are forbidden
|
||||||
Loading…
Reference in a new issue