TeacherControl встроен в число стандартных визиторов

This commit is contained in:
Mikhalkovich Stanislav 2022-07-18 19:39:13 +03:00
parent bf980555fa
commit 758dc2eb65
9 changed files with 129 additions and 21 deletions

View file

@ -15,7 +15,7 @@ internal static class RevisionClass
public const string Major = "3";
public const string Minor = "8";
public const string Build = "3";
public const string Revision = "3144";
public const string Revision = "3146";
public const string MainVersion = Major + "." + Minor;
public const string FullVersion = Major + "." + Minor + "." + Build + "." + Revision;

View file

@ -1,4 +1,4 @@
%COREVERSION%=3
%REVISION%=3144
%REVISION%=3146
%MINOR%=8
%MAJOR%=3

View file

@ -1 +1 @@
3.8.3.3144
3.8.3.3146

View file

@ -1 +1 @@
!define VERSION '3.8.3.3144'
!define VERSION '3.8.3.3146'

View file

@ -86,6 +86,9 @@ namespace PascalABCCompiler.SyntaxTreeConverters
CacheFunctionVisitor.New.ProcessNode(root);
// При наличии файла lightpt.dat подключает модули LightPT и Tasks
root = TeacherContolConverter.New.Convert(root);
#if DEBUG
//new SimplePrettyPrinterVisitor("D:\\Tree.txt").ProcessNode(root);
//FillParentNodeVisitor.New.ProcessNode(root);

View file

@ -47,6 +47,7 @@
<Compile Include="BaseVisitors\HasStatementVisitor.cs" />
<Compile Include="SugarVisitors\CacheFunctionVisitor.cs" />
<Compile Include="SugarVisitors\UnpackLambdaParametersVisitor.cs" />
<Compile Include="TeacherControl\TeacherControl.cs" />
<Compile Include="UniversalVisitors\ABCStatisticsVisitors.cs" />
<Compile Include="BaseVisitors\SmallHelperVisitors.cs" />
<Compile Include="ChangeWhileVisitor.cs" />

View file

@ -0,0 +1,47 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PascalABCCompiler.SyntaxTree;
namespace SyntaxVisitors
{
public class TeacherContolConverter : WalkingVisitorNew
{
public static TeacherContolConverter New
{
get { return new TeacherContolConverter(); }
}
public string Name { get => "TeacherContolConverter"; }
public syntax_tree_node Convert(syntax_tree_node root)
{
try
{
var program = root as program_module;
if (program == null) // если это не главная программа, то не преобразовывать
return root;
var FileName = program.file_name;
var fi = new System.IO.FileInfo(FileName);
var SourceFileDirectory = fi.DirectoryName;
var FullLightPTName = System.IO.Path.Combine(SourceFileDirectory, "lightpt.dat");
if (!System.IO.File.Exists(FullLightPTName))
return root;
if (program.used_units == null)
program.used_units = new uses_list();
program.used_units.Add(new unit_or_namespace("LightPT", null));
program.used_units.Add(new unit_or_namespace("Tasks", null));
}
catch
{
}
return root;
}
}
}

View file

@ -8,7 +8,7 @@ using PascalABCCompiler.SyntaxTree;
namespace VisualPascalABCPlugins
{
public class TeacherContolConverter: ISyntaxTreeConverter
/*public class TeacherContolConverter: ISyntaxTreeConverter
{
public string Name { get => "TeacherContolConverter"; }
public syntax_tree_node Convert(syntax_tree_node root)
@ -16,13 +16,21 @@ namespace VisualPascalABCPlugins
var program = root as program_module;
if (program == null) // если это не главная программа, то не преобразовывать
return root;
var FileName = program.file_name;
var fi = new System.IO.FileInfo(FileName);
var SourceFileDirectory = fi.DirectoryName;
var FullLightPTName = System.IO.Path.Combine(SourceFileDirectory, "lightpt.dat");
if (!System.IO.File.Exists(FullLightPTName))
return root;
if (program.used_units == null)
program.used_units = new uses_list();
program.used_units.Add(new unit_or_namespace("LightPT", null));
program.used_units.Add(new unit_or_namespace("Tasks", null));
return root;
}
}
}*/
//имя класса *_VisualPascalABCPlugin
public class VisualPascalABCPlugin_TeacherControlPlugin : IVisualPascalABCPlugin
@ -32,8 +40,6 @@ namespace VisualPascalABCPlugins
public static string StringsPrefix = "VPP_REGISTER_AND_CONTROL_PLUGIN_";
IVisualEnvironmentCompiler VisualEnvironmentCompiler;
PascalABCCompiler.Compiler compiler;
IWorkbench Workbench;
private TeacherControlForm RegisterForm = new TeacherControlForm();
private PluginGUIItem Item;
@ -57,12 +63,9 @@ namespace VisualPascalABCPlugins
VisualEnvironmentCompiler = Workbench.VisualEnvironmentCompiler;
RegisterForm.VisualEnvironmentCompiler = VisualEnvironmentCompiler;
compiler = VisualEnvironmentCompiler.Compiler as PascalABCCompiler.Compiler;
//compiler.SyntaxTreeConvertersController
// Регистрация обработчика
this.Workbench.ServiceContainer.RunService.Starting += RunStartingHandler;
Workbench.ServiceContainer.BuildService.BeforeCompile += BeforeCompileHandler;
//Workbench.ServiceContainer.BuildService.BeforeCompile += BeforeCompileHandler;
}
public void GetGUI(List<IPluginGUIItem> MenuItems, List<IPluginGUIItem> ToolBarItems)
{
@ -71,25 +74,27 @@ namespace VisualPascalABCPlugins
ToolBarItems.Add(Item);
}
private void BeforeCompileHandler(string filename) // filename - pas-файл
/*private void BeforeCompileHandler(string filename) // filename - pas-файл
{
// Проверяем присутствие файла lightpt.dat
var fi = new System.IO.FileInfo(filename);
var SourceFileDirectory = fi.DirectoryName;
var FullLightPTName = System.IO.Path.Combine(SourceFileDirectory, "lightpt.dat");
// VisualEnvironmentCompiler.Compiler.SyntaxTreeConvertersController возвращает NotSupportedException для RemoteCompiler. Странно... И как это вообще срабатывает?
var SyntaxTreeConverters = VisualEnvironmentCompiler.Compiler.SyntaxTreeConvertersController.SyntaxTreeConverters;
// Если осталось с прошлого раза
compiler.SyntaxTreeConvertersController.SyntaxTreeConverters.RemoveAll(st => st.Name == "TeacherContolConverter");
if (System.IO.File.Exists(FullLightPTName)) // Если в папке есть файл lightpt.dat
SyntaxTreeConverters.RemoveAll(st => st.Name == "TeacherContolConverter");
//if (System.IO.File.Exists(FullLightPTName)) // Если в папке есть файл lightpt.dat
{
compiler.SyntaxTreeConvertersController.SyntaxTreeConverters.Add(new TeacherContolConverter());
//SyntaxTreeConverters.Add(new TeacherContolConverter());
}
//System.IO.File.AppendAllText("d:\\Stmd.txt", string.Join(" ", StandartModules.Select(sm => sm.Name)) + '\n');
//System.IO.File.AppendAllText("d:\\Stmd.txt", FullLightPTName + " " + DateTime.Now + '\n');
}
}*/
private void RunStartingHandler(string filename)
{

View file

@ -20,6 +20,7 @@ type
end;
var
NewLineBeforeMessage := True;
TaskResult: TaskStatus := NotUnderControl; // Записывается в БД
TaskException: PTException := new PTException;
@ -296,6 +297,7 @@ function ReadString: string;
begin
Result := PABCSystem.ReadString;
InputList.Add(Result);
NewLineBeforeMessage := True;
end;
function ReadlnString := ReadString;
@ -309,6 +311,7 @@ begin
Result := PABCSystem.ReadInteger(prompt);
OutputList.RemoveAt(OutputList.Count - 1);
OutputList.RemoveAt(OutputList.Count - 1);
NewLineBeforeMessage := True;
end;
function ReadInteger2(prompt: string): (integer, integer);
@ -316,6 +319,7 @@ begin
Result := PABCSystem.ReadInteger2(prompt);
OutputList.RemoveAt(OutputList.Count - 1);
OutputList.RemoveAt(OutputList.Count - 1);
NewLineBeforeMessage := True;
end;
@ -326,24 +330,28 @@ begin
PABCSystem.Print(ob);
OutputList.RemoveAt(OutputList.Count - 1)
end;
NewLineBeforeMessage := False;
end;
procedure Println(params args: array of object);
begin
Print(args);
Writeln;
NewLineBeforeMessage := True;
end;
procedure Print(ob: object);
begin
PABCSystem.Print(ob);
OutputList.RemoveAt(OutputList.Count - 1)
OutputList.RemoveAt(OutputList.Count - 1);
NewLineBeforeMessage := False;
end;
procedure Print(s: string);
begin
PABCSystem.Print(s);
OutputList.RemoveAt(OutputList.Count - 1)
OutputList.RemoveAt(OutputList.Count - 1);
NewLineBeforeMessage := False;
end;
type
@ -354,96 +362,124 @@ type
inherited write(obj);
OutputString += obj.ToString;
OutputList += obj;
NewLineBeforeMessage := False;
end;
procedure writeln; override;
begin
inherited writeln;
OutputString += NewLine;
NewLineBeforeMessage := True;
end;
function ReadLine: string; override;
begin
Result := inherited ReadLine;
NewLineBeforeMessage := True;
end;
procedure readln; virtual;
begin
inherited readln;
NewLineBeforeMessage := True;
end;
procedure read(var x: integer); override;
begin
inherited Read(x);
InputList.Add(x);
NewLineBeforeMessage := False;
end;
procedure read(var x: real); override;
begin
inherited Read(x);
InputList.Add(x);
NewLineBeforeMessage := False;
end;
procedure read(var x: char); override;
begin
inherited Read(x);
InputList.Add(x);
NewLineBeforeMessage := False;
end;
procedure read(var x: string); override;
begin
inherited Read(x);
InputList.Add(x);
NewLineBeforeMessage := False;
end;
procedure read(var x: byte); override;
begin
inherited Read(x);
InputList.Add(x);
NewLineBeforeMessage := False;
end;
procedure read(var x: shortint); override;
begin
inherited Read(x);
InputList.Add(x);
NewLineBeforeMessage := False;
end;
procedure read(var x: smallint); override;
begin
inherited Read(x);
InputList.Add(x);
NewLineBeforeMessage := False;
end;
procedure read(var x: word); override;
begin
inherited Read(x);
InputList.Add(x);
NewLineBeforeMessage := False;
end;
procedure read(var x: longword); override;
begin
inherited Read(x);
InputList.Add(x);
NewLineBeforeMessage := False;
end;
procedure read(var x: int64); override;
begin
inherited Read(x);
InputList.Add(x);
NewLineBeforeMessage := False;
end;
procedure read(var x: uint64); override;
begin
inherited Read(x);
InputList.Add(x);
NewLineBeforeMessage := False;
end;
procedure read(var x: single); override;
begin
inherited Read(x);
InputList.Add(x);
NewLineBeforeMessage := False;
end;
procedure read(var x: boolean); override;
begin
inherited Read(x);
InputList.Add(x);
NewLineBeforeMessage := False;
end;
procedure read(var x: BigInteger); override;
begin
inherited Read(x);
InputList.Add(x);
NewLineBeforeMessage := False;
end;
end;
@ -548,7 +584,8 @@ end;
procedure ColoredMessage(msg: string; color: MessageColorT := MsgColorRed);
begin
Writeln;
if not NewLineBeforeMessage then
Writeln;
Writeln(MsgColorCode(color) + msg);
end;
@ -561,6 +598,21 @@ begin
end;
end;
procedure RobotCheckSolution;
begin
TaskResult := BadSolution;
var a := System.Reflection.Assembly.GetExecutingAssembly();
var t := a.GetType('RobotField.RobotField');
if t<>nil then
begin
var f := t.GetField('RobField',System.Reflection.BindingFlags.Public or System.Reflection.BindingFlags.Static);
var IsSol := f.FieldType.GetMethod('IsSolution');
var bool := IsSol.Invoke(f.GetValue(nil),nil);
if boolean(bool) then
TaskResult := Solved;
end;
end;
procedure CheckMyPT;
begin
if CheckTask = nil then