fix #2282
This commit is contained in:
parent
5f85d9aadf
commit
85181251c6
|
|
@ -15,7 +15,7 @@ internal static class RevisionClass
|
|||
public const string Major = "3";
|
||||
public const string Minor = "6";
|
||||
public const string Build = "3";
|
||||
public const string Revision = "2577";
|
||||
public const string Revision = "2584";
|
||||
|
||||
public const string MainVersion = Major + "." + Minor;
|
||||
public const string FullVersion = Major + "." + Minor + "." + Build + "." + Revision;
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
%MINOR%=6
|
||||
%REVISION%=2577
|
||||
%COREVERSION%=3
|
||||
%REVISION%=2584
|
||||
%MINOR%=6
|
||||
%MAJOR%=3
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
3.6.3.2577
|
||||
3.6.3.2584
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
!define VERSION '3.6.3.2577'
|
||||
!define VERSION '3.6.3.2584'
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ using PascalABCCompiler.SyntaxTree;
|
|||
using SyntaxVisitors;
|
||||
using SyntaxVisitors.SugarVisitors;
|
||||
using SyntaxVisitors.CheckingVisitors;
|
||||
using SyntaxVisitors.PatternsVisitors;
|
||||
|
||||
namespace PascalABCCompiler.SyntaxTreeConverters
|
||||
{
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ using System.Collections.Generic;
|
|||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace SyntaxVisitors.SugarVisitors
|
||||
namespace SyntaxVisitors.PatternsVisitors
|
||||
{
|
||||
public class ExtendedIsDesugaringVisitor : BaseChangeVisitor
|
||||
{
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ using PascalABCCompiler.SyntaxTree;
|
|||
using PascalABCCompiler.TreeConversion;
|
||||
using PascalABCCompiler.TreeConverter;
|
||||
|
||||
namespace SyntaxVisitors.SugarVisitors
|
||||
namespace SyntaxVisitors.PatternsVisitors
|
||||
{
|
||||
// Patterns
|
||||
|
||||
|
|
@ -217,6 +217,23 @@ namespace SyntaxVisitors.SugarVisitors
|
|||
return "$RenIsVarYield" + num + "$" + name;
|
||||
}
|
||||
|
||||
public override void visit(procedure_definition pd)
|
||||
{
|
||||
//ReplaceNamesInIsVarVisitor.New.ProcessNode(pd);
|
||||
base.visit(pd);
|
||||
}
|
||||
|
||||
public class StrBool
|
||||
{
|
||||
public string name;
|
||||
public bool needtorename;
|
||||
public StrBool(string name, bool b = false)
|
||||
{
|
||||
this.name = name;
|
||||
this.needtorename = b;
|
||||
}
|
||||
}
|
||||
|
||||
public override void visit(is_pattern_expr isPatternExpr)
|
||||
{
|
||||
if (GetLocation(isPatternExpr) == PatternLocation.Unknown)
|
||||
|
|
@ -224,11 +241,12 @@ namespace SyntaxVisitors.SugarVisitors
|
|||
|
||||
Debug.Assert(GetAscendant<statement_list>(isPatternExpr) != null, "Couldn't find statement list in upper nodes");
|
||||
|
||||
syntax_tree_node stn = isPatternExpr;
|
||||
while (stn != null && !(stn is procedure_definition) && !(stn is function_lambda_definition))
|
||||
stn = stn.Parent;
|
||||
if (stn is procedure_definition pd && pd.has_yield) // SSM 11/07/20 Надо сделать обход с переименованием!!! Сейчас and не работает в yield + ... is A(var a1)
|
||||
{
|
||||
//syntax_tree_node stn = isPatternExpr;
|
||||
//while (stn != null && !(stn is procedure_definition) && !(stn is function_lambda_definition))
|
||||
// stn = stn.Parent;
|
||||
//if (stn is procedure_definition pd && pd.has_yield) // SSM 11/07/20 Надо сделать обход с переименованием!!! Сейчас and не работает в yield + ... is A(var a1)
|
||||
//{
|
||||
var dict = new Dictionary<string, StrBool>(StringComparer.InvariantCultureIgnoreCase); // bool - надо ли начинать renaming
|
||||
var l = new List<statement>();
|
||||
var pp = isPatternExpr.right?.parameters;
|
||||
if (pp != null)
|
||||
|
|
@ -241,12 +259,54 @@ namespace SyntaxVisitors.SugarVisitors
|
|||
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;
|
||||
// проверять, что имя не начинается с $ и если начинается, то ошибка - уже переименовывали такое же!
|
||||
if (vdp.identifier.name.StartsWith("$"))
|
||||
throw new SyntaxVisitorError("Повторное объявление", vdp.identifier.source_context);
|
||||
dict.Add(vdp.identifier.name, new StrBool(idNew.name,false));
|
||||
//vdp.identifier.name = idNew.name; // в следующем цикле переименую
|
||||
l.Add(vs);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// подниматься пока выражение
|
||||
syntax_tree_node ex = isPatternExpr;
|
||||
syntax_tree_node ex1 = ex;
|
||||
while (ex is expression)
|
||||
{
|
||||
ex1 = ex;
|
||||
ex = ex.Parent;
|
||||
}
|
||||
ex = ex1; // саммое внешнее выражение. В нём и переименовать!
|
||||
var nams = ex.DescendantNodes().Where(stn => stn is ident).Cast<ident>();
|
||||
foreach (var n in nams)
|
||||
{
|
||||
// надо как-то пробросить до первой is_var
|
||||
if (dict.ContainsKey(n.name))
|
||||
{
|
||||
var isvar = GetAscendant<is_pattern_expr>(n);
|
||||
if (isvar != null)
|
||||
{
|
||||
dict[n.name].needtorename = true; // всё - можно переименовывать далее
|
||||
n.name = dict[n.name].name; // переименовываем в is_var
|
||||
continue;
|
||||
}
|
||||
if (!dict[n.name].needtorename) // если еще не дошли до is_var, то это какая-то внешняя и не переименовываем
|
||||
continue;
|
||||
if (n.Parent is dot_node dn && dn.left == n) // т.е. не переименовываем только если ident - в правой части dot_node
|
||||
{
|
||||
// переименовываем
|
||||
n.name = dict[n.name].name;
|
||||
}
|
||||
else
|
||||
{
|
||||
// переименовываем
|
||||
n.name = dict[n.name].name;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
var stat = GetAscendant<statement>(isPatternExpr);
|
||||
if (stat is if_node ifn)
|
||||
{
|
||||
|
|
@ -265,7 +325,7 @@ namespace SyntaxVisitors.SugarVisitors
|
|||
var stl = stat.Parent as statement_list;
|
||||
stl.ReplaceInList(stat, l);
|
||||
}
|
||||
}
|
||||
//}
|
||||
|
||||
|
||||
//ReplaceStatement(stat, l); // тут нельзя.
|
||||
|
|
|
|||
|
|
@ -52,6 +52,7 @@
|
|||
<Compile Include="LightSymInfoVisitors\SymInfoCollect1Helper.cs" />
|
||||
<Compile Include="PatternsVisitors\ExtendedIsDesugaringVisitor.cs" />
|
||||
<Compile Include="PatternsVisitors\PatternsDesugaringVisitor.cs" />
|
||||
<Compile Include="PatternsVisitors\ReplaceNamesInIsVarVisitor.cs" />
|
||||
<Compile Include="PatternsVisitors\SingleDeconstructChecker.cs" />
|
||||
<Compile Include="SugarVisitors\AssignTuplesDesugarVisitor.cs" />
|
||||
<Compile Include="SugarVisitors\DoubleQuestionDesugarVisitor.cs" />
|
||||
|
|
|
|||
11
TestSuite/isVar0.pas
Normal file
11
TestSuite/isVar0.pas
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
var a := 666;
|
||||
|
||||
procedure p;
|
||||
begin
|
||||
var b := (a = 1) or (a = 3) or ('abc' is string(var a)) and (a = 'abc');
|
||||
Assert(b);
|
||||
end;
|
||||
|
||||
begin
|
||||
p;
|
||||
end.
|
||||
|
|
@ -1,15 +1,9 @@
|
|||
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;
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue