* Make standardModules Dictionary instead of LanguageId usage * Create new common string constants for pascal language * Add LanguagesData class template * Move some compiler directive string constants to Compiler project * Extract LanguagesData class to separate file Also extracted RuntimeServiceModule (IO-modules) management to new functions. * Fix pabcnetc crashing (KeyNotFoundException) * Make similar change in pabcnetc_clear * Return PABCExtensions in DomConverter.cs * Return compiler string constants to Tree Converter * Rename MoveSystemUnitForward method * Rename system unit variable * Add new parser load error (localized versions) * Fix pascal language name constant * Add system units property to parsers * Add LanguageKits directory with a test file * Implement language integrator Был реализован загрузчик комплектов дополнительных языков (всех кроме Pascal). Был пересмотрен подход к реализации ParsersController и этот класс сделан синглтоном. Добавлена загрузка стандартных модулей языков в CompilerOptions. * Squashed commit of the following: commit8f9dc7e5a0Author: Mikhalkovich Stanislav <miks@math.sfedu.ru> Date: Mon Mar 11 20:33:13 2024 +0300 fix #3050 commit90363ced45Author: Mikhalkovich Stanislav <miks@math.sfedu.ru> Date: Sun Mar 3 21:37:25 2024 +0300 Недобитки при сортировке строк commitc9d7ba7758Author: Mikhalkovich Stanislav <miks@math.sfedu.ru> Date: Sat Mar 2 13:32:14 2024 +0300 Order и OrderDescending для строк с Ordinal commit6fbc0200bfAuthor: AlexanderZemlyak <92867056+AlexanderZemlyak@users.noreply.github.com> Date: Tue Feb 27 23:21:26 2024 +0300 Fix interface loop dependency check (#3047) Tests for problematic case were added commite4d63bfef9Author: bormant <bormant@mail.ru> Date: Tue Feb 27 23:18:25 2024 +0300 Fix typo: C (ru) -> C (en) (#3042) commit0d37232d21Author: Mikhalkovich Stanislav <miks@math.sfedu.ru> Date: Tue Feb 27 19:15:08 2024 +0300 School - исправление пустого диапазона простых и IP-адресов commit9fd4c7f338Merge:3cca2a896027083bAuthor: Ivan Bondarev <ibond84@googlemail.com> Date: Wed Feb 21 20:57:10 2024 +0100 Merge branch 'master' of https://github.com/pascalabcnet/pascalabcnet commit3cca2a8949Author: Ivan Bondarev <ibond84@googlemail.com> Date: Wed Feb 21 20:56:49 2024 +0100 fix in formatter
271 lines
13 KiB
C#
271 lines
13 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Drawing;
|
|
using System.Text;
|
|
using System.Windows.Forms;
|
|
using PascalABCCompiler.Errors;
|
|
using System.IO;
|
|
|
|
namespace VisualPascalABCPlugins
|
|
{
|
|
public partial class SyntaxTreeVisualisatorForm : Form
|
|
{
|
|
public IVisualEnvironmentCompiler VisualEnvironmentCompiler;
|
|
private System.Collections.Hashtable Errors = new System.Collections.Hashtable();
|
|
|
|
public SyntaxTreeVisualisatorForm()
|
|
{
|
|
InitializeComponent();
|
|
PascalABCCompiler.StringResources.SetTextForAllObjects(this, SyntaxTreeVisualisator_VisualPascalABCPlugin.StringsPrefix);
|
|
}
|
|
|
|
private void SyntaxTreeVisualisatorForm_Load(object sender, EventArgs e)
|
|
{
|
|
|
|
}
|
|
|
|
private void SyntaxTreeVisualisatorForm_FormClosing(object sender, FormClosingEventArgs e)
|
|
{
|
|
e.Cancel = true;
|
|
this.Visible = false;
|
|
}
|
|
|
|
private void SyntaxTreeVisualisatorForm_Shown(object sender, EventArgs e)
|
|
{
|
|
VisualEnvironmentCompiler.StandartCompiler.OnChangeCompilerState += new PascalABCCompiler.ChangeCompilerStateEventDelegate(Compiler_OnChangeCompilerState);
|
|
}
|
|
private class SyntaxTreeSelectComboBoxItem
|
|
{
|
|
public PascalABCCompiler.SyntaxTree.syntax_tree_node Node;
|
|
public string FileName;
|
|
public SyntaxTreeSelectComboBoxItem(PascalABCCompiler.SyntaxTree.syntax_tree_node Node, string FileName)
|
|
{
|
|
this.Node=Node;
|
|
this.FileName=FileName;
|
|
}
|
|
public override string ToString()
|
|
{
|
|
return System.IO.Path.GetFileName(FileName);
|
|
}
|
|
}
|
|
bool BuildButtonsEnabled
|
|
{
|
|
set
|
|
{
|
|
tbRebuild.Enabled = tbBuild.Enabled = value;
|
|
}
|
|
get
|
|
{
|
|
return tbRebuild.Enabled;
|
|
}
|
|
}
|
|
void Compiler_OnChangeCompilerState(PascalABCCompiler.ICompiler sender, PascalABCCompiler.CompilerState State, string FileName)
|
|
{
|
|
if (!Visible) return;
|
|
switch (State)
|
|
{
|
|
case PascalABCCompiler.CompilerState.CompilationStarting:
|
|
BuildButtonsEnabled = syntaxTreeSelectComboBox.Enabled = false;
|
|
this.Refresh();
|
|
break;
|
|
case PascalABCCompiler.CompilerState.CompilationFinished:
|
|
Errors.Clear();
|
|
if (VisualEnvironmentCompiler.Compiler.ErrorsList.Count > 0)
|
|
{
|
|
SyntaxError er;
|
|
for (int i = 0; i < VisualEnvironmentCompiler.Compiler.ErrorsList.Count; i++)
|
|
{
|
|
er = VisualEnvironmentCompiler.Compiler.ErrorsList[i] as SyntaxError;
|
|
if (er!=null && er.bad_node != null)
|
|
Errors[er.bad_node] = i;
|
|
}
|
|
}
|
|
UpdateSelectList();
|
|
ShowTree();
|
|
BuildButtonsEnabled = true;
|
|
break;
|
|
}
|
|
}
|
|
private void UpdateSelectList()
|
|
{
|
|
SyntaxTreeSelectComboBoxItem lastItem = syntaxTreeSelectComboBox.SelectedItem as SyntaxTreeSelectComboBoxItem;
|
|
syntaxTreeSelectComboBox.Items.Clear();
|
|
foreach (PascalABCCompiler.CompilationUnit unit in VisualEnvironmentCompiler.Compiler.UnitTable.Values)
|
|
if (unit.SyntaxTree != null)
|
|
syntaxTreeSelectComboBox.Items.Add(new SyntaxTreeSelectComboBoxItem(unit.SyntaxTree, unit.SyntaxTree.file_name));
|
|
if (lastItem != null)
|
|
foreach (SyntaxTreeSelectComboBoxItem item in syntaxTreeSelectComboBox.Items)
|
|
if (item.ToString() == lastItem.ToString())
|
|
syntaxTreeSelectComboBox.SelectedItem = item;
|
|
if (syntaxTreeSelectComboBox.Items.Count > 0)
|
|
{
|
|
syntaxTreeSelectComboBox.Enabled = !showAllCheckBox.Checked;
|
|
if (syntaxTreeSelectComboBox.SelectedItem == null)
|
|
syntaxTreeSelectComboBox.SelectedIndex = 0;
|
|
}
|
|
}
|
|
public void ShowTree()
|
|
{
|
|
treeView.Nodes.Clear();
|
|
visualizator vs = new visualizator(treeView.Nodes);
|
|
if (showAllCheckBox.Checked)
|
|
foreach (SyntaxTreeSelectComboBoxItem item in syntaxTreeSelectComboBox.Items)
|
|
vs.prepare_node(item.Node, "compilation_unit");
|
|
else
|
|
if (syntaxTreeSelectComboBox.SelectedItem!=null)
|
|
vs.prepare_node((syntaxTreeSelectComboBox.SelectedItem as SyntaxTreeSelectComboBoxItem).Node, "compilation_unit");
|
|
}
|
|
|
|
/* //ssyy
|
|
public void SaveTree()
|
|
{
|
|
if (syntaxTreeSelectComboBox.SelectedItem != null)
|
|
{
|
|
PascalABCCompiler.SyntaxTree.compilation_unit cu = (syntaxTreeSelectComboBox.SelectedItem as SyntaxTreeSelectComboBoxItem).Node as PascalABCCompiler.SyntaxTree.compilation_unit;
|
|
PascalABCCompiler.SyntaxTree.CPSyntaxTreeStreamWriter sw = new PascalABCCompiler.SyntaxTree.CPSyntaxTreeStreamWriter();
|
|
System.IO.FileStream fs = new System.IO.FileStream(cu.file_name + ".tre", System.IO.FileMode.Create, System.IO.FileAccess.Write);
|
|
System.IO.BinaryWriter fbw = new System.IO.BinaryWriter(fs);
|
|
sw.bw = fbw;
|
|
fbw.Write((byte)1);
|
|
cu.visit(sw);
|
|
fbw.Close();
|
|
fs.Close();
|
|
}
|
|
}
|
|
//\ssyy
|
|
*/
|
|
private void syntaxTreeSelectComboBox_SelectedIndexChanged(object sender, EventArgs e)
|
|
{
|
|
ShowTree();
|
|
}
|
|
|
|
private void showAllCheckBox_CheckedChanged(object sender, EventArgs e)
|
|
{
|
|
syntaxTreeSelectComboBox.Enabled = (syntaxTreeSelectComboBox.Items.Count > 0)&&!showAllCheckBox.Checked;
|
|
ShowTree();
|
|
}
|
|
|
|
private void showAllCheckBox_VisibleChanged(object sender, EventArgs e)
|
|
{
|
|
if (Visible)
|
|
{
|
|
UpdateSelectList();
|
|
ShowTree();
|
|
}
|
|
}
|
|
|
|
private void treeView_AfterSelect(object sender, TreeViewEventArgs e)
|
|
{
|
|
TreeNode tn = treeView.SelectedNode;
|
|
StatusLabel.Text = "";
|
|
PascalABCCompiler.SyntaxTree.syntax_tree_node syntax_tree_node = tn.Tag as PascalABCCompiler.SyntaxTree.syntax_tree_node;
|
|
if (syntax_tree_node.source_context == null) return;
|
|
StatusLabel.Text = syntax_tree_node.source_context.ToString() + string.Format("({0},+{1})", syntax_tree_node.source_context.Position, syntax_tree_node.source_context.Length);
|
|
if(syntax_tree_node.source_context.FileName!=null)
|
|
StatusLabel.Text+=Path.GetFileName(syntax_tree_node.source_context.FileName);
|
|
if (Errors.Count > 0)
|
|
if (Errors[syntax_tree_node] != null)
|
|
StatusLabel.Text += string.Format(" [BAD{0}]", Errors[syntax_tree_node]);
|
|
this.VisualEnvironmentCompiler.ExecuteSourceLocationAction(
|
|
PascalABCCompiler.Tools.ConvertSourceContextToSourceLocation((syntaxTreeSelectComboBox.SelectedItem as SyntaxTreeSelectComboBoxItem).FileName, syntax_tree_node.source_context),
|
|
SourceLocationAction.SelectAndGotoBeg);
|
|
}
|
|
|
|
private void label1_Click(object sender, EventArgs e)
|
|
{
|
|
|
|
}
|
|
|
|
private void toolStripButton1_Click(object sender, EventArgs e)
|
|
{
|
|
PascalABCCompiler.CompilerType ct = VisualEnvironmentCompiler.DefaultCompilerType;
|
|
VisualEnvironmentCompiler.DefaultCompilerType = PascalABCCompiler.CompilerType.Standart;
|
|
VisualEnvironmentCompiler.ExecuteAction(VisualEnvironmentCompilerAction.Build, null);
|
|
VisualEnvironmentCompiler.DefaultCompilerType = ct;
|
|
}
|
|
|
|
private void toolStripButton2_Click(object sender, EventArgs e)
|
|
{
|
|
PascalABCCompiler.CompilerType ct = VisualEnvironmentCompiler.DefaultCompilerType;
|
|
VisualEnvironmentCompiler.DefaultCompilerType = PascalABCCompiler.CompilerType.Standart;
|
|
VisualEnvironmentCompiler.ExecuteAction(VisualEnvironmentCompilerAction.Rebuild, null);
|
|
VisualEnvironmentCompiler.DefaultCompilerType = ct;
|
|
}
|
|
|
|
private void tbCPSaveTree_Click(object sender, EventArgs e)
|
|
{
|
|
// SaveTree();
|
|
|
|
}
|
|
|
|
private void tsParse_Click(object sender, EventArgs e)
|
|
{
|
|
string FileName = (string)VisualEnvironmentCompiler.ExecuteAction(VisualEnvironmentCompilerAction.GetCurrentSourceFileName, null);
|
|
string FileText = (string)VisualEnvironmentCompiler.Compiler.SourceFilesProvider(FileName, PascalABCCompiler.SourceFileOperation.GetText);
|
|
List<Error> Errors=new List<Error>();
|
|
List<CompilerWarning> Warnings = new List<CompilerWarning>();
|
|
//PascalABCCompiler.SyntaxTree.syntax_tree_node sn = VisualEnvironmentCompiler.Compiler.ParsersController.Compile(file_name, FileText, Errors, PascalABCCompiler.ParserTools.ParseMode.Expression);
|
|
PascalABCCompiler.SyntaxTree.syntax_tree_node sn = VisualEnvironmentCompiler.StandartCompiler.ParsersController.GetExpression(FileName, FileText, Errors, Warnings);
|
|
if (Errors.Count > 0)
|
|
StatusLabel.Text = Errors.Count + " errors";
|
|
syntaxTreeSelectComboBox.Items.Clear();
|
|
if (sn == null)
|
|
return;
|
|
syntaxTreeSelectComboBox.Items.Add(new SyntaxTreeSelectComboBoxItem(sn, FileName));
|
|
syntaxTreeSelectComboBox.SelectedIndex = 0;
|
|
}
|
|
|
|
private void tsParsePart_Click(object sender, EventArgs e)
|
|
{
|
|
string FileName = (string)VisualEnvironmentCompiler.ExecuteAction(VisualEnvironmentCompilerAction.GetCurrentSourceFileName, null);
|
|
string FileText = (string)VisualEnvironmentCompiler.Compiler.SourceFilesProvider(FileName, PascalABCCompiler.SourceFileOperation.GetText);
|
|
List<Error> Errors = new List<Error>();
|
|
List<CompilerWarning> Warnings = new List<CompilerWarning>();
|
|
PascalABCCompiler.SyntaxTree.syntax_tree_node sn = VisualEnvironmentCompiler.StandartCompiler.ParsersController.SelectParserForUnitAndBuildTree(FileName+"part_", FileText, Errors, Warnings, PascalABCCompiler.Parsers.ParseMode.Normal);
|
|
if (Errors.Count > 0)
|
|
StatusLabel.Text = Errors.Count + " errors";
|
|
syntaxTreeSelectComboBox.Items.Clear();
|
|
if (sn == null)
|
|
return;
|
|
syntaxTreeSelectComboBox.Items.Add(new SyntaxTreeSelectComboBoxItem(sn, FileName));
|
|
syntaxTreeSelectComboBox.SelectedIndex = 0;
|
|
|
|
}
|
|
|
|
PascalABCCompiler.SyntaxTree.syntax_tree_node ParseCurrent(List<Error> Errors, string fileNamePosfix)
|
|
{
|
|
string FileName = (string)VisualEnvironmentCompiler.ExecuteAction(VisualEnvironmentCompilerAction.GetCurrentSourceFileName, null);
|
|
string FileText = (string)VisualEnvironmentCompiler.StandartCompiler.SourceFilesProvider(FileName, PascalABCCompiler.SourceFileOperation.GetText);
|
|
return VisualEnvironmentCompiler.StandartCompiler.ParsersController.SelectParserForUnitAndBuildTree(FileName + fileNamePosfix, FileText, Errors, new List<CompilerWarning>(), PascalABCCompiler.Parsers.ParseMode.Normal);
|
|
}
|
|
|
|
private void toolStripButton1_Click_1(object sender, EventArgs e)
|
|
{
|
|
List<Error> Errors = new List<Error>();
|
|
DateTime dt = DateTime.Now;
|
|
PascalABCCompiler.SyntaxTree.syntax_tree_node sn = ParseCurrent(Errors,"");
|
|
StatusLabel.Text = string.Format("[{0}ms]", (DateTime.Now - dt).TotalMilliseconds);
|
|
if (Errors.Count > 0)
|
|
StatusLabel.Text += Errors.Count + " errors";
|
|
syntaxTreeSelectComboBox.Items.Clear();
|
|
if (sn == null)
|
|
return;
|
|
string FileName = (string)VisualEnvironmentCompiler.ExecuteAction(VisualEnvironmentCompilerAction.GetCurrentSourceFileName, null);
|
|
syntaxTreeSelectComboBox.Items.Add(new SyntaxTreeSelectComboBoxItem(sn, FileName));
|
|
syntaxTreeSelectComboBox.SelectedIndex = 0;
|
|
|
|
}
|
|
|
|
private void toolStripButton2_Click_1(object sender, EventArgs e)
|
|
{
|
|
List<Error> Errors = new List<Error>();
|
|
PascalABCCompiler.SyntaxTree.syntax_tree_node sn = ParseCurrent(Errors, "");
|
|
PascalABCCompiler.SyntaxTree.documentation_comment_list dt = ParseCurrent(Errors, "dt_") as PascalABCCompiler.SyntaxTree.documentation_comment_list;
|
|
PascalABCCompiler.DocumentationConstructor docconst = new PascalABCCompiler.DocumentationConstructor();
|
|
Dictionary<PascalABCCompiler.SyntaxTree.syntax_tree_node, string> documentation = docconst.Construct(sn, dt);
|
|
}
|
|
}
|
|
}
|