Удаление supportedProjectFiles из Compiler и настройка использования SPython в проектах (#3374)

* Set up creating SPython projects

* Delete SupportedSourceFile class in Compiler

* Implement GetUnitTemplate function for SPython
This commit is contained in:
Александр Земляк 2026-01-16 20:13:20 +03:00 committed by GitHub
parent 834845213b
commit cb09e2340f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
30 changed files with 100 additions and 134 deletions

View file

@ -108,6 +108,11 @@ namespace Languages.SPython.Frontend.Data
}
}
public override string GetUnitTemplate(string unitName)
{
return "#unit " + unitName + Environment.NewLine;
}
public override string ConstructHeader(string meth, IProcScope scope, int tabCount)
{
throw new NotImplementedException();

View file

@ -508,39 +508,6 @@ namespace PascalABCCompiler
#endif
}
public class SupportedSourceFile
{
private readonly string[] extensions;
public string[] Extensions
{
get { return extensions; }
}
private readonly string languageName;
public string LanguageName
{
get { return languageName; }
}
public SupportedSourceFile(string[] extensions, string lname)
{
this.extensions = extensions;
languageName = lname;
}
public static SupportedSourceFile Make(ILanguage language)
{
return new SupportedSourceFile(language.FilesExtensions, language.Name);
}
public override string ToString()
{
return string.Format("{0} ({1})", LanguageName, FormatTools.ExtensionsToString(Extensions, "*", ";"));
}
}
public delegate void ChangeCompilerStateEventDelegate(ICompiler sender, CompilerState State, string FileName);
public class Compiler : MarshalByRefObject, ICompiler
@ -631,19 +598,6 @@ namespace PascalABCCompiler
get { return state; }
}
private void SetSupportedProjectFiles()
{
// проекты только на Паскале пока EVA
supportedProjectFiles = new SupportedSourceFile[] { new SupportedSourceFile(new string[1] { ".pabcproj" }, "PascalABC.NET") };
}
private SupportedSourceFile[] supportedProjectFiles = null;
public SupportedSourceFile[] SupportedProjectFiles
{
get { return supportedProjectFiles; }
}
private CompilationUnitHashTable unitTable = new CompilationUnitHashTable();
public CompilationUnitHashTable UnitTable { get { return unitTable; } }
public List<CompilationUnit> UnitsTopologicallySortedList = new List<CompilationUnit>();
@ -791,8 +745,6 @@ namespace PascalABCCompiler
if (ChangeCompilerState != null)
OnChangeCompilerState += ChangeCompilerState;
supportedProjectFiles = comp.SupportedProjectFiles;
// 29.07.2024 EVA
CompilerOptions = new CompilerOptions();
}
@ -827,8 +779,6 @@ namespace PascalABCCompiler
SyntaxTreeToSemanticTreeConverter = new TreeConverter.SyntaxTreeToSemanticTreeConverter();
CodeGeneratorsController = new CodeGenerators.Controller();
SetSupportedProjectFiles();
semanticTreeConvertersController = new SemanticTreeConvertersController(this);
semanticTreeConvertersController.ChangeState += semanticTreeConvertersController_ChangeState;
semanticTreeConvertersController.AddConverters();

View file

@ -51,11 +51,6 @@ namespace PascalABCCompiler
get;
}
SupportedSourceFile[] SupportedProjectFiles
{
get;
}
CompilerOptions CompilerOptions
{
get;

View file

@ -534,22 +534,6 @@ namespace PascalABCCompiler
}
}
public SupportedSourceFile[] SupportedSourceFiles
{
get
{
throw new NotSupportedException();
}
}
public SupportedSourceFile[] SupportedProjectFiles
{
get
{
throw new NotSupportedException();
}
}
// SSM 2026 Исключил это из ICompiler
/*public PascalABCCompiler.SyntaxTree.compilation_unit ParseText(string FileName, string Text, List<PascalABCCompiler.Errors.Error> ErrorList, List<CompilerWarning> Warnings)
{

View file

@ -616,6 +616,8 @@ namespace PascalABCCompiler.Parsers
return null;
}
public abstract string GetUnitTemplate(string unitName);
public string GetFullTypeName(ICompiledTypeScope scope, bool no_alias = true)
{
return GetFullTypeName(scope.CompiledType);

View file

@ -126,6 +126,12 @@ namespace PascalABCCompiler.Parsers
string FindOnlyIdentifier(int off, string Text, int line, int col, ref string name);
string FindPattern(int off, string Text, out bool is_pattern);
string GetDocumentTemplate(string lineText, string Text, int line, int col, int pos);
/// <summary>
/// Получить минимальный шаблон для модуля с именем unitName
/// </summary>
string GetUnitTemplate(string unitName);
/// <summary>
/// Проверить на ключевое слово
/// </summary>

View file

@ -867,6 +867,21 @@ namespace Languages.Pascal.Frontend.Data
return "";
}
public override string GetUnitTemplate(string unitName)
{
var sb = new StringBuilder();
sb.AppendLine("unit " + unitName + ";");
sb.AppendLine();
sb.AppendLine("interface");
sb.AppendLine();
sb.AppendLine("implementation");
sb.AppendLine();
sb.Append("end.");
return sb.ToString();
}
public override string ConstructHeader(string meth, IProcScope scope, int tabCount)
{
int i = 0;

View file

@ -393,6 +393,8 @@ namespace PascalABCCompiler
pascalLanguageDllName.ToLower()
};
public const string platformProjectExtension = ".pabcproj";
public static readonly string[] netSystemLibraries = new[] { "mscorlib.dll", "System.dll", "System.Core.dll", "System.Numerics.dll", "System.Windows.Forms.dll", "System.Drawing.dll" };
public static readonly string[] graph3DDependencies = new[] { "PresentationFramework.dll", "WindowsBase.dll", "PresentationCore.dll", "HelixToolkit.Wpf.dll", "HelixToolkit.dll" };

View file

@ -32,7 +32,6 @@ namespace VisualPascalABC
public static string CompletionWindowDeclarationViewWindowFontName = "Tahoma";
public static string CompletionWindowCodeCompletionListViewFontName = "Tahoma";
public static string CompletionInsightWindowFontName = "Tahoma";
public static string ProjectExtension = ".pabcproj";
public static bool FileNamesCaseSensetive = false;
static Constants()

View file

@ -69,7 +69,7 @@ namespace VisualPascalABC
{
string sf = PascalABCCompiler.FormatTools.ExtensionsToString(Extensions, "*", ";");
sf = string.Format(VECStringResources.Get("DIALOGS_PROJECT_FILTER_PART_{0}{1}|{1}|"), Name, sf);
if (sf.IndexOf(".pabcproj") >= 0)
if (sf.IndexOf(StringConstants.platformProjectExtension) >= 0)
return sf + Filter;
else
return Filter + sf;

View file

@ -190,11 +190,14 @@ namespace VisualPascalABC
if (standartCompiler == null)
return null;
string Filter = "", AllFilter = "";
foreach (PascalABCCompiler.SupportedSourceFile ssf in standartCompiler.SupportedProjectFiles)
foreach (ILanguage lang in LanguageProvider.Instance.Languages)
{
Filter = Tools.MakeProjectFilter(Filter, ssf.LanguageName, ssf.Extensions);
AllFilter = Tools.MakeAllFilter(AllFilter, ssf.LanguageName, ssf.Extensions);
Filter = Tools.MakeProjectFilter(Filter, lang.Name,
new string[1] { PascalABCCompiler.StringConstants.platformProjectExtension });
}
AllFilter = Tools.MakeAllFilter(AllFilter, PascalABCCompiler.StringConstants.pascalLanguageName,
new string[1] { PascalABCCompiler.StringConstants.platformProjectExtension });
return Tools.FinishMakeFilter(Filter, AllFilter);
}

View file

@ -103,7 +103,7 @@ namespace VisualPascalABC
string[] file_name = e.Data.GetData(DataFormats.FileDrop) as string[];
if (file_name != null && file_name.Length>0)
{
if (string.Compare(System.IO.Path.GetExtension(file_name[0]),Constants.ProjectExtension,true)==0)
if (string.Compare(System.IO.Path.GetExtension(file_name[0]), PascalABCCompiler.StringConstants.platformProjectExtension,true)==0)
WorkbenchServiceFactory.ProjectService.OpenProject(file_name[0]);
else
WorkbenchServiceFactory.FileService.OpenFile(file_name[0], null);

View file

@ -390,14 +390,14 @@ namespace VisualPascalABC
init = true;
foreach (string FileName in VisualPascalABCProgram.CommandLineArgs)
{
if (Path.GetExtension(FileName) == ".pabcproj")
if (Path.GetExtension(FileName) == PascalABCCompiler.StringConstants.platformProjectExtension)
WorkbenchServiceFactory.ProjectService.OpenProject(FileName);
else
WorkbenchServiceFactory.FileService.OpenFile(FileName, null);
}
if (FileNameToWait != null)
{
if (Path.GetExtension(FileNameToWait) == ".pabcproj")
if (Path.GetExtension(FileNameToWait) == PascalABCCompiler.StringConstants.platformProjectExtension)
WorkbenchServiceFactory.ProjectService.OpenProject(FileNameToWait);
else
WorkbenchServiceFactory.FileService.OpenFile(FileNameToWait, null);
@ -1237,7 +1237,7 @@ namespace VisualPascalABC
//MessageBox.Show(cds.cbData.ToString());
if (init)
{
if (System.IO.Path.GetExtension(file_name) != ".pabcproj")
if (System.IO.Path.GetExtension(file_name) != PascalABCCompiler.StringConstants.platformProjectExtension)
WorkbenchServiceFactory.FileService.OpenFile(file_name, null);
else
WorkbenchServiceFactory.ProjectService.OpenProject(file_name);

View file

@ -66,6 +66,8 @@ namespace VisualPascalABC
CodeCompletion.CodeCompletionController controller = new CodeCompletion.CodeCompletionController();
string text = WorkbenchServiceFactory.Workbench.VisualEnvironmentCompiler.SourceFilesProvider(FileName, PascalABCCompiler.SourceFileOperation.GetText) as string;
PascalABCCompiler.SyntaxTree.compilation_unit cu = controller.ParseOnlySyntaxTree(FileName, text);
if (cu == null)
return;
PascalABCCompiler.SyntaxTree.ident unitName = null;
if (cu is PascalABCCompiler.SyntaxTree.unit_module)
{

View file

@ -3,8 +3,9 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Windows.Forms;
namespace VisualPascalABC
@ -65,7 +66,13 @@ namespace VisualPascalABC
MessageBox.Show(Form1StringResources.Get("FILE_NAME_EMPTY"), PascalABCCompiler.StringResources.Get("!ERROR"), MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (File.Exists(Path.Combine(ProjectFactory.Instance.ProjectDirectory,tbFileName.Text)))
if (!Languages.Facade.LanguageProvider.Instance.HasLanguageForExtension(tbFileName.Text))
{
e.Cancel = true;
MessageBox.Show(Form1StringResources.Get("INVALID_SOURCE_FILE_EXTENSION"), PascalABCCompiler.StringResources.Get("!ERROR"), MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (File.Exists(Path.Combine(ProjectFactory.Instance.ProjectDirectory,tbFileName.Text)))
{
e.Cancel = true;
MessageBox.Show(string.Format(Form1StringResources.Get("FILE_ALREADY_EXISTS{0}"), tbFileName.Text), PascalABCCompiler.StringResources.Get("!ERROR"), MessageBoxButtons.OK, MessageBoxIcon.Error);

View file

@ -60,7 +60,7 @@ namespace VisualPascalABC
{
get
{
return System.IO.Path.Combine(tbProjectDir.Text,ProjectName+".pabcproj");
return System.IO.Path.Combine(tbProjectDir.Text,ProjectName+PascalABCCompiler.StringConstants.platformProjectExtension);
}
}

View file

@ -4,11 +4,7 @@ using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Drawing;
using System.Windows.Forms;
using Microsoft.Build.BuildEngine;
using PascalABCCompiler;
using PascalABCCompiler.TreeConverter;
namespace VisualPascalABC
{
@ -384,7 +380,7 @@ namespace VisualPascalABC
MessageBox.Show(Form1StringResources.Get("INVALID_SOURCE_FILE_NAME"), PascalABCCompiler.StringResources.Get("!ERROR"), MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (string.Compare(Path.GetExtension(e.Label), StringConstants.pascalSourceFileExtension, true) != 0)
if (!Languages.Facade.LanguageProvider.Instance.HasLanguageForExtension(e.Label))
{
e.CancelEdit = true;
MessageBox.Show(Form1StringResources.Get("INVALID_SOURCE_FILE_EXTENSION"), PascalABCCompiler.StringResources.Get("!ERROR"), MessageBoxButtons.OK, MessageBoxIcon.Error);

View file

@ -1,14 +1,12 @@
// 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;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using ICSharpCode.FormsDesigner;
using PascalABCCompiler;
using PascalABCCompiler.Parsers;
namespace VisualPascalABC
{
@ -115,15 +113,12 @@ namespace VisualPascalABC
ProjectExplorerWindow.AddSourceFile(fi,false);
string full_file_name = Path.Combine(Path.GetDirectoryName(ProjectFactory.Instance.CurrentProject.Path),frm.FileName);
StreamWriter sw = File.CreateText(full_file_name);
ILanguageInformation languageInfo = Languages.Facade.LanguageProvider.Instance.SelectLanguageByExtension(frm.FileName).LanguageInformation;
if (frm.GetFileFilter() == FileType.Unit)
{
sw.WriteLine("unit " + Path.GetFileNameWithoutExtension(frm.FileName) + ";");
sw.WriteLine();
sw.WriteLine("interface");
sw.WriteLine();
sw.WriteLine("implementation");
sw.WriteLine();
sw.Write("end.");
sw.Write(languageInfo.GetUnitTemplate(Path.GetFileNameWithoutExtension(frm.FileName)));
}
else
{

View file

@ -34,7 +34,6 @@ namespace VisualPascalABC
public static string CompletionWindowDeclarationViewWindowFontName = "Tahoma";
public static string CompletionWindowCodeCompletionListViewFontName = "Tahoma";
public static string CompletionInsightWindowFontName = "Tahoma";
public static string ProjectExtension = ".pabcproj";
public static bool FileNamesCaseSensetive = false;
static Constants()

View file

@ -70,7 +70,7 @@ namespace VisualPascalABC
{
string sf = PascalABCCompiler.FormatTools.ExtensionsToString(Extensions, "*", ";");
sf = string.Format(VECStringResources.Get("DIALOGS_PROJECT_FILTER_PART_{0}{1}|{1}|"), Name, sf);
if (sf.IndexOf(".pabcproj") >= 0)
if (sf.IndexOf(PascalABCCompiler.StringConstants.platformProjectExtension) >= 0)
return sf + Filter;
else
return Filter + sf;

View file

@ -8,6 +8,8 @@ using System.IO;
using System.Text;
using System.Windows.Forms;
using VisualPascalABCPlugins;
using Languages.Integration;
using Languages.Facade;
namespace VisualPascalABC
{
@ -185,14 +187,17 @@ namespace VisualPascalABC
public string GetProjectFilterForDialogs()
{
if (standartCompiler == null)
if (standartCompiler == null)
return null;
string Filter = "", AllFilter = "";
foreach (PascalABCCompiler.SupportedSourceFile ssf in standartCompiler.SupportedProjectFiles)
foreach (ILanguage lang in LanguageProvider.Instance.Languages)
{
Filter = Tools.MakeProjectFilter(Filter, ssf.LanguageName, ssf.Extensions);
AllFilter = Tools.MakeAllFilter(AllFilter, ssf.LanguageName, ssf.Extensions);
Filter = Tools.MakeProjectFilter(Filter, lang.Name,
new string[1] { PascalABCCompiler.StringConstants.platformProjectExtension });
}
AllFilter = Tools.MakeAllFilter(AllFilter, PascalABCCompiler.StringConstants.pascalLanguageName,
new string[1] { PascalABCCompiler.StringConstants.platformProjectExtension });
return Tools.FinishMakeFilter(Filter, AllFilter);
}

View file

@ -103,7 +103,7 @@ namespace VisualPascalABC
string[] file_name = e.Data.GetData(DataFormats.FileDrop) as string[];
if (file_name != null && file_name.Length>0)
{
if (string.Compare(System.IO.Path.GetExtension(file_name[0]),Constants.ProjectExtension,true)==0)
if (string.Compare(System.IO.Path.GetExtension(file_name[0]), PascalABCCompiler.StringConstants.platformProjectExtension,true)==0)
WorkbenchServiceFactory.ProjectService.OpenProject(file_name[0]);
else
WorkbenchServiceFactory.FileService.OpenFile(file_name[0], null);

View file

@ -480,14 +480,14 @@ namespace VisualPascalABC
init = true;
foreach (string FileName in VisualPascalABCProgram.CommandLineArgs)
{
if (Path.GetExtension(FileName) == ".pabcproj")
if (Path.GetExtension(FileName) == PascalABCCompiler.StringConstants.platformProjectExtension)
WorkbenchServiceFactory.ProjectService.OpenProject(FileName);
else
WorkbenchServiceFactory.FileService.OpenFile(FileName, null);
}
if (FileNameToWait != null)
{
if (Path.GetExtension(FileNameToWait) == ".pabcproj")
if (Path.GetExtension(FileNameToWait) == PascalABCCompiler.StringConstants.platformProjectExtension)
WorkbenchServiceFactory.ProjectService.OpenProject(FileNameToWait);
else
WorkbenchServiceFactory.FileService.OpenFile(FileNameToWait, null);
@ -1355,7 +1355,7 @@ namespace VisualPascalABC
//MessageBox.Show(cds.cbData.ToString());
if (init)
{
if (System.IO.Path.GetExtension(file_name) != ".pabcproj")
if (System.IO.Path.GetExtension(file_name) != PascalABCCompiler.StringConstants.platformProjectExtension)
WorkbenchServiceFactory.FileService.OpenFile(file_name, null);
else
WorkbenchServiceFactory.ProjectService.OpenProject(file_name);

View file

@ -66,6 +66,8 @@ namespace VisualPascalABC
CodeCompletion.CodeCompletionController controller = new CodeCompletion.CodeCompletionController();
string text = WorkbenchServiceFactory.Workbench.VisualEnvironmentCompiler.SourceFilesProvider(FileName, PascalABCCompiler.SourceFileOperation.GetText) as string;
PascalABCCompiler.SyntaxTree.compilation_unit cu = controller.ParseOnlySyntaxTree(FileName, text);
if (cu == null)
return;
PascalABCCompiler.SyntaxTree.ident unitName = null;
if (cu is PascalABCCompiler.SyntaxTree.unit_module)
{

View file

@ -3,8 +3,9 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Windows.Forms;
namespace VisualPascalABC
@ -65,7 +66,13 @@ namespace VisualPascalABC
MessageBox.Show(Form1StringResources.Get("FILE_NAME_EMPTY"), PascalABCCompiler.StringResources.Get("!ERROR"), MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (File.Exists(Path.Combine(ProjectFactory.Instance.ProjectDirectory,tbFileName.Text)))
if (!Languages.Facade.LanguageProvider.Instance.HasLanguageForExtension(tbFileName.Text))
{
e.Cancel = true;
MessageBox.Show(Form1StringResources.Get("INVALID_SOURCE_FILE_EXTENSION"), PascalABCCompiler.StringResources.Get("!ERROR"), MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (File.Exists(Path.Combine(ProjectFactory.Instance.ProjectDirectory,tbFileName.Text)))
{
e.Cancel = true;
MessageBox.Show(string.Format(Form1StringResources.Get("FILE_ALREADY_EXISTS{0}"), tbFileName.Text), PascalABCCompiler.StringResources.Get("!ERROR"), MessageBoxButtons.OK, MessageBoxIcon.Error);

View file

@ -60,7 +60,7 @@ namespace VisualPascalABC
{
get
{
return System.IO.Path.Combine(tbProjectDir.Text,ProjectName+".pabcproj");
return System.IO.Path.Combine(tbProjectDir.Text,ProjectName+PascalABCCompiler.StringConstants.platformProjectExtension);
}
}

View file

@ -4,10 +4,7 @@ using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Drawing;
using System.Windows.Forms;
using Microsoft.Build.BuildEngine;
using PascalABCCompiler;
namespace VisualPascalABC
{
@ -378,7 +375,7 @@ namespace VisualPascalABC
MessageBox.Show(Form1StringResources.Get("INVALID_SOURCE_FILE_NAME"), PascalABCCompiler.StringResources.Get("!ERROR"), MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (string.Compare(Path.GetExtension(e.Label), ".pas", true) != 0)
if (!Languages.Facade.LanguageProvider.Instance.HasLanguageForExtension(e.Label))
{
e.CancelEdit = true;
MessageBox.Show(Form1StringResources.Get("INVALID_SOURCE_FILE_EXTENSION"), PascalABCCompiler.StringResources.Get("!ERROR"), MessageBoxButtons.OK, MessageBoxIcon.Error);

View file

@ -1,14 +1,12 @@
// 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;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
//using ICSharpCode.FormsDesigner;
using PascalABCCompiler;
using PascalABCCompiler.Parsers;
using System.Collections.Generic;
using System.IO;
using System.Runtime.InteropServices;
using System.Windows.Forms;
namespace VisualPascalABC
{
@ -100,15 +98,12 @@ namespace VisualPascalABC
ProjectExplorerWindow.AddSourceFile(fi,false);
string full_file_name = Path.Combine(Path.GetDirectoryName(ProjectFactory.Instance.CurrentProject.Path),frm.FileName);
StreamWriter sw = File.CreateText(full_file_name);
ILanguageInformation languageInfo = Languages.Facade.LanguageProvider.Instance.SelectLanguageByExtension(frm.FileName).LanguageInformation;
if (frm.GetFileFilter() == FileType.Unit)
{
sw.WriteLine("unit " + Path.GetFileNameWithoutExtension(frm.FileName) + ";");
sw.WriteLine();
sw.WriteLine("interface");
sw.WriteLine();
sw.WriteLine("implementation");
sw.WriteLine();
sw.Write("end.");
sw.Write(languageInfo.GetUnitTemplate(Path.GetFileNameWithoutExtension(frm.FileName)));
}
else
{

View file

@ -278,7 +278,7 @@ namespace PascalABCCompiler
Console.WriteLine(msg);
DateTime ldt = DateTime.Now;
CompilerOptions co = new CompilerOptions(FileName, outputType);
if (FileName.ToLower().EndsWith(".pabcproj"))
if (FileName.ToLower().EndsWith(StringConstants.platformProjectExtension))
co.ProjectCompiled = true;
if (OutputDirectory != "")
co.OutputDirectory=OutputDirectory;

View file

@ -221,7 +221,7 @@ namespace PascalABCCompiler
outputType = CompilerOptions.OutputType.ConsoleApplicaton;
CompilerOptions co = new CompilerOptions(FileName, outputType);
if (FileName.ToLower().EndsWith(".pabcproj"))
if (FileName.ToLower().EndsWith(StringConstants.platformProjectExtension))
co.ProjectCompiled = true;
if (n1 == n - 1)
//co.OutputDirectory = ""