* 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
64 lines
2.1 KiB
C#
64 lines
2.1 KiB
C#
using PascalABCCompiler.SyntaxTree;
|
|
using System.Collections.Generic;
|
|
|
|
namespace Languages.SPython.Frontend.Converters
|
|
{
|
|
internal class ImportToUsesVisitor : BaseChangeVisitor
|
|
{
|
|
Dictionary<string, SourceContext> modulesNames = new Dictionary<string, SourceContext>();
|
|
|
|
public ImportToUsesVisitor() { }
|
|
|
|
private Dictionary<string, string> specialModulesAliases = Facade.LanguageProvider.Instance.SelectLanguageByName("SPython").LanguageInformation.SpecialModulesAliases;
|
|
|
|
private string GetNameToImport(string nameToImport)
|
|
{
|
|
if (!specialModulesAliases.ContainsKey(nameToImport))
|
|
return nameToImport;
|
|
else
|
|
return specialModulesAliases[nameToImport];
|
|
}
|
|
|
|
private void AddName(ident id)
|
|
{
|
|
string nameToImport = GetNameToImport(id.name);
|
|
if (!modulesNames.ContainsKey(nameToImport))
|
|
modulesNames.Add(nameToImport, id.source_context);
|
|
}
|
|
|
|
public override void visit(import_statement _import_statement)
|
|
{
|
|
foreach (as_statement as_Statement in _import_statement.modules_names.as_statements)
|
|
AddName(as_Statement.real_name);
|
|
}
|
|
|
|
public override void visit(from_import_statement _from_import_statement)
|
|
{
|
|
AddName(_from_import_statement.module_name);
|
|
}
|
|
|
|
public void AddUsesToUsesList(uses_list _uses_list)
|
|
{
|
|
foreach (string module_name in modulesNames.Keys)
|
|
{
|
|
SourceContext sc = modulesNames[module_name];
|
|
uses_list us = new uses_list(new unit_or_namespace(module_name, sc), sc);
|
|
us[0].source_context = sc;
|
|
_uses_list.AddUsesList(us, sc);
|
|
}
|
|
}
|
|
|
|
public override void Exit(syntax_tree_node stn)
|
|
{
|
|
if (stn is program_module pm)
|
|
{
|
|
AddUsesToUsesList(pm.used_units);
|
|
}
|
|
if (stn is unit_module um)
|
|
{
|
|
AddUsesToUsesList(um.interface_part.uses_modules);
|
|
}
|
|
}
|
|
}
|
|
}
|