pascalabcnet/AdditionalLanguages/SPython/SyntaxTreeConverters/SPythonStandardTreeConverter/FunctionsWithNamedParametersDesugarVisitor.cs
Александр Земляк 17f6a9b956
Spython test suite (#3362)
* Reorganize files in TestSuite dir for multiple languages

* Add SPython samples to TestSuite

* Update TestRunner to support multiple languages

* Delete dll files accidentally pushed

* Update .gitignore

* Revert "Delete dll files accidentally pushed"

This reverts commit 62bcba2b821d58ae51ec98e9dadcf621bb0fc003.

* Update testing dir path in Testing.cs

* Improve TestRunner output

* Add random module and it's usage sample

* Reorganize gitignore files

* Move pascal tests back to TestSuite and create new TestSuiteLanguagePlugins folder for SPython

* Revert "Update testing dir path in Testing.cs"

This reverts commit 7d94eafb25292421bce8315520b4f6a0de001bbd.

* Revert crlf changes in pascal tests

* Test changes of _RebuildReleaseAndRunTestsForGitHubActions.bat

* Revert "Test changes of _RebuildReleaseAndRunTestsForGitHubActions.bat"

This reverts commit 234ceae3e3a339fbc68a6170e2bd201dab14d67d.

* Test changes in StorageLocationPicker

* Another test changes in StorageLocationPicker.cs

* Rename LanguagePlugins folder to AdditionalLanguages

* Decouple TestRunner from language names and parameters

* Revert calling TestRunner without parameters in .bat files

* Fix formatter tests nogui exception handling

* Small refactoring in Testing.cs and TestRunner fix of working directory
2025-12-21 21:11:52 +03:00

65 lines
2.7 KiB
C#

using PascalABCCompiler.SyntaxTree;
using System;
using System.Linq;
namespace Languages.SPython.Frontend.Converters
{
internal class FunctionsWithNamedParametersDesugarVisitor : BaseChangeVisitor
{
public FunctionsWithNamedParametersDesugarVisitor() { }
public override void visit(method_call _method_call)
{
if (_method_call.parameters is expression_list exprl) {
expression_list args = new expression_list();
expression_list kwargs_names_array = new expression_list();
expression_list kwargs = new expression_list();
foreach (var expr in exprl.expressions)
{
if (expr is name_assign_expr nae)
{
kwargs_names_array.Add(new string_const(nae.name.name));
kwargs_names_array.source_context
= new SourceContext(kwargs_names_array.source_context, expr.source_context);
kwargs.Add(nae.expr);
kwargs.source_context
= new SourceContext(kwargs.source_context, expr.source_context);
}
else if (kwargs.expressions.Count() == 0)
{
args.Add(expr);
args.source_context = new SourceContext(args.source_context, expr.source_context);
}
else throw new SPythonSyntaxVisitorError("ARG_AFTER_KWARGS", expr.source_context);
}
if (kwargs.expressions.Count() != 0)
{
array_const_new acn = new array_const_new(kwargs_names_array, '|');
kwargs.expressions.Insert(0, acn);
ident method_name = new ident();
if (_method_call.dereferencing_value is ident id)
{
method_name = id;
}
else if (_method_call.dereferencing_value is dot_node dnn)
{
method_name = dnn.right as ident;
}
ident class_name = new ident("!" + method_name);
new_expr ne = new new_expr(new named_type_reference(class_name), kwargs, false, null);
dot_node dn = new dot_node(ne, new ident(method_name.name), _method_call.source_context);
method_call new_method_call = new method_call(dn, args, _method_call.source_context);
Replace(_method_call, new_method_call);
return;
}
}
base.visit(_method_call);
}
}
}