pascalabcnet/SyntaxTreeConverters/StandardSyntaxConverter.cs

105 lines
4.3 KiB
C#
Raw Normal View History

// 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 PascalABCCompiler.SyntaxTree;
using SyntaxVisitors;
using SyntaxVisitors.SugarVisitors;
using SyntaxVisitors.CheckingVisitors;
2020-07-14 13:05:02 +03:00
using SyntaxVisitors.PatternsVisitors;
namespace PascalABCCompiler.SyntaxTreeConverters
{
public class StandardSyntaxTreeConverter: ISyntaxTreeConverter
{
public string Name { get; } = "Standard";
public syntax_tree_node Convert(syntax_tree_node root)
{
// Прошивание ссылками на Parent nodes. Должно идти первым
// FillParentNodeVisitor расположен в SyntaxTree/tree как базовый визитор, отвечающий за построение дерева
2018-10-24 20:39:07 +03:00
//FillParentNodeVisitor.New.ProcessNode(root); // почему-то перепрошивает не всё. А следующий вызов - всё
root.FillParentsInAllChilds();
#if DEBUG
// var stat = new ABCStatisticsVisitor();
// stat.ProcessNode(root);
#endif
// new range - до всего! До выноса выражения с лямбдой из foreach. 11.07 добавил поиск yields и присваивание pd.HasYield
NewRangeDesugarAndFindHasYieldVisitor.New.ProcessNode(root);
// Unnamed Records перенёс сюда
UnnamedRecordsCheckVisitor.New.ProcessNode(root);
2021-01-09 01:31:53 +03:00
// Выносим выражения с лямбдами из заголовка foreach + считаем максимум 10 вложенных лямбд
2021-01-10 07:54:31 +03:00
StandOutExprWithLambdaInForeachSequenceAndNestedLambdasVisitor.New.ProcessNode(root);
VarNamesInMethodsWithSameNameAsClassGenericParamsReplacer.New.ProcessNode(root); // SSM bug fix #1147
2019-06-29 19:28:18 +03:00
FindOnExceptVarsAndApplyRenameVisitor.New.ProcessNode(root);
2018-06-28 22:12:52 +03:00
#if DEBUG
2018-05-17 03:00:10 +03:00
//new SimplePrettyPrinterVisitor("E:/projs/out.txt").ProcessNode(root);
2018-06-28 22:12:52 +03:00
#endif
2020-01-04 12:19:36 +03:00
2017-06-08 17:56:17 +03:00
// loop
LoopDesugarVisitor.New.ProcessNode(root);
2017-01-22 20:54:13 +03:00
// tuple_node
TupleVisitor.New.ProcessNode(root);
// index
2020-05-02 11:44:20 +03:00
IndexVisitor.New.ProcessNode(root);
2017-01-22 20:54:13 +03:00
// assign_tuple и assign_var_tuple
AssignTuplesDesugarVisitor.New.ProcessNode(root); // теперь это - на семантике
2017-01-22 20:54:13 +03:00
// slice_expr и slice_expr_question
SliceDesugarVisitor.New.ProcessNode(root);
// question_point_desugar_visitor
QuestionPointDesugarVisitor.New.ProcessNode(root);
2017-02-03 11:31:40 +03:00
// double_question_desugar_visitor
DoubleQuestionDesugarVisitor.New.ProcessNode(root);
2018-05-11 13:46:59 +03:00
// Patterns
// SingleDeconstructChecker.New.ProcessNode(root); // SSM 21.10.18 - пока разрешил множественные деконструкторы. Если будут проблемы - запретить
2019-05-28 09:21:59 +03:00
ExtendedIsDesugaringVisitor.New.ProcessNode(root); // Десахаризация расширенного is, который используется в сложных логических выражениях
PatternsDesugaringVisitor.New.ProcessNode(root); // Обязательно в этом порядке.
2017-02-03 11:31:40 +03:00
// simple_property
PropertyDesugarVisitor.New.ProcessNode(root);
// Всё, связанное с yield
2018-10-26 20:12:42 +03:00
CapturedNamesHelper.Reset();
MarkMethodHasYieldAndCheckSomeErrorsVisitor.New.ProcessNode(root);
ProcessYieldCapturedVarsVisitor.New.ProcessNode(root);
#if DEBUG
2018-09-27 17:59:37 +03:00
//new SimplePrettyPrinterVisitor("D:\\Tree.txt").ProcessNode(root);
//FillParentNodeVisitor.New.ProcessNode(root);
2018-05-17 22:49:07 +03:00
2018-11-08 00:24:28 +03:00
/*var cv = CollectLightSymInfoVisitor.New;
cv.ProcessNode(root);
cv.Output(@"Light1.txt");*/
2018-11-08 00:24:28 +03:00
/*try
2017-10-20 11:54:32 +03:00
{
root.visit(new SimplePrettyPrinterVisitor(@"d:\\zzz1.txt"));
2017-10-20 11:54:32 +03:00
}
2018-10-11 16:27:07 +03:00
catch(Exception e)
2017-10-20 11:54:32 +03:00
{
System.IO.File.AppendAllText(@"d:\\zzz1.txt",e.Message);
}*/
2018-11-08 00:24:28 +03:00
2017-10-20 11:54:32 +03:00
#endif
return root;
}
}
}