2019-07-28 23:53:15 +03:00
|
|
|
|
// Copyright (c) Ivan Bondarev, Stanislav Mikhalkovich (for details please see \doc\copyright.txt)
|
2017-02-19 16:29:24 +03:00
|
|
|
|
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
|
|
|
|
|
using System;
|
2016-07-18 13:07:08 +03:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
|
|
using PascalABCCompiler.Errors;
|
|
|
|
|
|
using PascalABCCompiler;
|
|
|
|
|
|
using PascalABCCompiler.SyntaxTree;
|
|
|
|
|
|
|
|
|
|
|
|
namespace SyntaxVisitors
|
|
|
|
|
|
{
|
|
|
|
|
|
public class ReplaceBreakContinueWithGotoLabelVisitor : BaseChangeVisitor
|
|
|
|
|
|
{
|
|
|
|
|
|
public goto_statement GotoContinue { get; private set; }
|
|
|
|
|
|
public goto_statement GotoBreak { get; private set; }
|
|
|
|
|
|
|
|
|
|
|
|
public ReplaceBreakContinueWithGotoLabelVisitor(goto_statement gotoContinue, goto_statement gotoBreak)
|
|
|
|
|
|
{
|
|
|
|
|
|
this.GotoContinue = gotoContinue;
|
|
|
|
|
|
this.GotoBreak = gotoBreak;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public override void Enter(syntax_tree_node st)
|
|
|
|
|
|
{
|
|
|
|
|
|
base.Enter(st);
|
|
|
|
|
|
// Не заходим во вложенные циклы, там свои break-continue
|
|
|
|
|
|
if ((st is for_node || st is foreach_stmt || st is while_node || st is repeat_node))
|
|
|
|
|
|
{
|
|
|
|
|
|
visitNode = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public override void visit(procedure_call pc)
|
|
|
|
|
|
{
|
|
|
|
|
|
var pcIdent = pc.func_name as ident;
|
|
|
|
|
|
if (pcIdent != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
var pcName = pcIdent.name.ToLower();
|
|
|
|
|
|
if (pcName == "break")
|
|
|
|
|
|
{
|
2018-12-17 00:27:40 +03:00
|
|
|
|
ReplaceUsingParent(pc, this.GotoBreak);
|
2016-07-18 13:07:08 +03:00
|
|
|
|
}
|
|
|
|
|
|
else if (pcName == "continue")
|
|
|
|
|
|
{
|
2018-12-17 00:27:40 +03:00
|
|
|
|
ReplaceUsingParent(pc, this.GotoContinue);
|
2016-07-18 13:07:08 +03:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|