pascalabcnet/SyntaxTreeConverters/StandardSyntaxConverter.cs
Александр Земляк 1f4b44c2c0
Исправление ошибок при перекомпиляции pcu файлов (#3398)
* Move yield string constants to StringConstants class

* Add GeneratedNamesManager class to store all generated names during unit compilation

* Make GeneratedNamesManager class non static

* Add Utils project to installer files

* Add GeneratedNamesManager usage in CapturedVariablesSubstitutionsManager

* Move GeneratedNamesManager initialization in CompilationUnit constructor

* More GeneratedNamesManager usage

* QuestionPointDesugarVisitor fix
2026-03-08 18:30:33 +03:00

122 lines
5.6 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// 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 PascalABCCompiler.SyntaxTree;
using SyntaxVisitors;
using SyntaxVisitors.SugarVisitors;
using SyntaxVisitors.CheckingVisitors;
using SyntaxVisitors.PatternsVisitors;
using PascalABCCompiler.SyntaxTreeConverters;
namespace Languages.Pascal.Frontend.Converters
{
public class StandardSyntaxTreeConverter : BaseSyntaxTreeConverter
{
public override string Name { get; } = "Standard";
protected override syntax_tree_node ApplyConversions(syntax_tree_node root, bool forIntellisense)
{
var generatedNamesManager = new PascalABCCompiler.CoreUtils.GeneratedNamesManager();
ExitParamVisitor.New.ProcessNode(root);
var binder = new BindCollectLightSymInfo(root as compilation_unit);
#if DEBUG
// var stat = new ABCStatisticsVisitor();
// stat.ProcessNode(root);
#endif
// SSM 02.01.24
//LetExprVisitor.New.ProcessNode(root);
// new range - до всего! До выноса выражения с лямбдой из foreach. 11.07 добавил поиск yields и присваивание pd.HasYield
NewRangeDesugarAndFindHasYieldVisitor.New.ProcessNode(root);
// Распаковка параметров в лямбдах
UnpackLambdaParametersVisitor.Create(generatedNamesManager).ProcessNode(root);
// Unnamed Records перенёс сюда
UnnamedRecordsCheckVisitor.New.ProcessNode(root);
// Выносим выражения с лямбдами из заголовка foreach + считаем максимум 10 вложенных лямбд
StandOutExprWithLambdaInForeachSequenceAndNestedLambdasVisitor.Create(generatedNamesManager).ProcessNode(root);
new VarNamesInMethodsWithSameNameAsClassGenericParamsReplacer(root as compilation_unit).ProcessNode(root);
FindOnExceptVarsAndApplyRenameVisitor.Create(generatedNamesManager).ProcessNode(root);
// loop
LoopDesugarVisitor.Create(generatedNamesManager).ProcessNode(root);
#if DEBUG
//new SimplePrettyPrinterVisitor("D:/out.txt").ProcessNode(root);
#endif
bool optimize_tuple_assign = true;
// tuple_node
TupleVisitor.Create(optimize_tuple_assign, generatedNamesManager).ProcessNode(root);
// index
IndexVisitor.New.ProcessNode(root);
// slice_expr и slice_expr_question
SliceDesugarVisitor.New.ProcessNode(root);
// поставил раньше AssignTuplesDesugarVisitor из за var (a,b) := a[1:3];
// теперь коллизия с (a[1:6], a[6:11]):= (a[6:11], a[1:6]);
// assign_tuple и assign_var_tuple
if (!optimize_tuple_assign)
AssignTuplesDesugarVisitor.Create(generatedNamesManager).ProcessNode(root); // теперь это - на семантике
else
NewAssignTuplesDesugarVisitor.Create(binder, generatedNamesManager).ProcessNode(root);
// question_point_desugar_visitor
QuestionPointDesugarVisitor.Create(generatedNamesManager).ProcessNode(root);
// double_question_desugar_visitor
// Закомментировал, потому что cейчас он ничего не делает EVA 08.03.2026
// DoubleQuestionDesugarVisitor.New.ProcessNode(root);
// Patterns
// SingleDeconstructChecker.New.ProcessNode(root); // SSM 21.10.18 - пока разрешил множественные деконструкторы. Если будут проблемы - запретить
ExtendedIsDesugaringVisitor.New.ProcessNode(root); // Десахаризация расширенного is, который используется в сложных логических выражениях
PatternsDesugaringVisitor.Create(generatedNamesManager).ProcessNode(root); // Обязательно в этом порядке.
#if DEBUG
//new SimplePrettyPrinterVisitor("D:/out.txt").ProcessNode(root);
// TestAssignIsDefVisitor.New.ProcessNode(root);
#endif
// simple_property
PropertyDesugarVisitor.Create(generatedNamesManager).ProcessNode(root);
// Всё, связанное с yield
MarkMethodHasYieldAndCheckSomeErrorsVisitor.New.ProcessNode(root);
ProcessYieldCapturedVarsVisitor.Create(generatedNamesManager).ProcessNode(root);
CacheFunctionVisitor.Create(generatedNamesManager).ProcessNode(root);
ToExprVisitor.New.ProcessNode(root);
// При наличии файла lightpt.dat подключает модули LightPT и Tasks
root = TeacherControlConverter.New.Convert(root);
#if DEBUG
//new SimplePrettyPrinterVisitor("D:\\Tree.txt").ProcessNode(root);
//FillParentNodeVisitor.New.ProcessNode(root);
/*var cv = CollectLightSymInfoVisitor.New;
cv.ProcessNode(root);
cv.Output(@"Light1.txt");*/
/*try
{
root.visit(new SimplePrettyPrinterVisitor(@"d:\\zzz1.txt"));
}
catch(Exception e)
{
System.IO.File.AppendAllText(@"d:\\zzz1.txt",e.Message);
}*/
#endif
return root;
}
}
}