Здоровье кода в Status Bar

This commit is contained in:
Mikhalkovich Stanislav 2020-09-19 23:45:19 +03:00
parent eeeb2563a2
commit db107c5ebf
11 changed files with 59 additions and 10 deletions

View file

@ -738,6 +738,8 @@ namespace PascalABCCompiler
public class Compiler : MarshalByRefObject, ICompiler
{
//public ISyntaxTreeChanger SyntaxTreeChanger = null; // SSM 17/08/15 - для операций над синтаксическим деревом после его построения
int pABCCodeHealth = 0;
public int PABCCodeHealth { get { return pABCCodeHealth; } }
public static string Version
{
@ -1053,6 +1055,8 @@ namespace PascalABCCompiler
{
OnChangeCompilerState(this, CompilerState.Reloading, null);
pABCCodeHealth = 0;
//А это что?
TreeRealization.type_node tn = SystemLibrary.SystemLibrary.void_type;
@ -1191,6 +1195,7 @@ namespace PascalABCCompiler
CurrentCompilationUnit = null;
FirstCompilationUnit = null;
linesCompiled = 0;
pABCCodeHealth = 0;
PCUReadersAndWritersClosed = false;
ParsersController.Reset();
SyntaxTreeToSemanticTreeConverter.Reset();
@ -3103,7 +3108,17 @@ namespace PascalABCCompiler
OnChangeCompilerState(this, CompilerState.EndParsingFile, FileName);
//Вычисляем сколько строк скомпилировали
if (ErrorList.Count == 0 && cu != null && cu.source_context!=null)
{
linesCompiled += (uint)(cu.source_context.end_position.line_num - cu.source_context.begin_position.line_num + 1);
// 500 - это наибольшая программа для начинающих. БОльшая программа - здоровье кода только по кнопке (чтобы не замедлять)
if (linesCompiled <= 500)
{
// Это только для локального компилятора?
var stat = new SyntaxVisitors.ABCStatisticsVisitor();
stat.ProcessNode(cu);
pABCCodeHealth = stat.CalcHealth(out int neg, out int pos);
}
}
return cu;
}

View file

@ -148,6 +148,10 @@
<Project>{C2CAC65A-B2AE-4CCC-B067-E6B8E75DF73A}</Project>
<Package>{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</Package>
</ProjectReference>
<ProjectReference Include="..\SyntaxVisitors\SyntaxVisitors.csproj">
<Project>{a9ab4282-83b4-41a7-86c3-e5bf6a45e7e2}</Project>
<Name>SyntaxVisitors</Name>
</ProjectReference>
<ProjectReference Include="..\TreeConverter\TreeConverter.csproj">
<Name>TreeConverter</Name>
<Project>{1C9C945A-586D-42A2-A06B-65D84FA7FF78}</Project>

View file

@ -26,6 +26,7 @@ namespace PascalABCCompiler
public const int GetLastWriteTime = 186;
public const int VarBeginOffest = 187;
public const int InternalError = 188;
public const int PABCHealth = 189;
//2xx to pabcnetc.exe

View file

@ -14,6 +14,13 @@ namespace PascalABCCompiler
public enum CompilerType { Standart, Remote }
public interface ICompiler
{
/// Здоровье кода на всякий случай выносим в интерфейс компилятора
/// Реально оно будет использоваться только при запуске из под оболочки (Remote Compiler)
int PABCCodeHealth
{
get;
}
SyntaxTreeConvertersController SyntaxTreeConvertersController
{
get;

View file

@ -128,6 +128,9 @@ namespace PascalABCCompiler
}
switch (command)
{
case ConsoleCompilerConstants.PABCHealth:
pABCCodeHealth = Convert.ToInt32(arg);
break;
case ConsoleCompilerConstants.LinesCompiled:
linesCompiled = Convert.ToUInt32(arg);
break;
@ -241,6 +244,10 @@ namespace PascalABCCompiler
}
}
// SSM 18/09/20
int pABCCodeHealth = 0;
public int PABCCodeHealth { get { return pABCCodeHealth; } }
CompilerInternalDebug internalDebug=new CompilerInternalDebug();
public CompilerInternalDebug InternalDebug
{
@ -452,12 +459,6 @@ namespace PascalABCCompiler
}
}
public SupportedSourceFile[] SupportedSourceFiles
{
get
@ -527,6 +528,7 @@ namespace PascalABCCompiler
bool compilerReloading = true;
public void Reload()
{
pABCCodeHealth = 0;
compilerReloading = true;
stopCompiler();
pabcnetcProcess = new Process();

View file

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

View file

@ -1,4 +1,4 @@
%COREVERSION%=1
%REVISION%=2694
%REVISION%=2696
%MINOR%=7
%MAJOR%=3

View file

@ -1 +1 @@
3.7.1.2694
3.7.1.2696

View file

@ -1 +1 @@
!define VERSION '3.7.1.2694'
!define VERSION '3.7.1.2696'

View file

@ -840,6 +840,25 @@ namespace VisualPascalABC
private void StartMenuItem_Click(object sender, EventArgs e)
{
WorkbenchServiceFactory.RunService.Run(true);
if (VisualEnvironmentCompiler.Compiler != null && VisualEnvironmentCompiler.Compiler.ErrorsList.Count == 0)
{
var Percent = VisualEnvironmentCompiler.Compiler.PABCCodeHealth;
if (Percent > 0)
{
if (Percent >= 100)
{
HealthLabel.Text = "";
return;
}
HealthLabel.Text = $"{Percent}%";
var c = SystemColors.Control;
var PM100 = 100 - Percent;
HealthLabel.BackColor = Color.FromArgb(c.R - PM100 - 20, c.G - PM100 - 20, c.B - PM100 - 20);
}
}
/*if (VisualEnvironmentCompiler.StandartCompiler != null &&
VisualEnvironmentCompiler.StandartCompiler.LinesCompiled > 1000)
return;

View file

@ -30,6 +30,7 @@ namespace PascalABCCompiler
if (compiler.Warnings.Count > 0)
foreach (Errors.Error er in compiler.Warnings)
SendErrorOrWarning(er);
SendCommand(ConsoleCompilerConstants.PABCHealth, compiler.PABCCodeHealth.ToString());
SendCommand(ConsoleCompilerConstants.LinesCompiled, compiler.LinesCompiled.ToString());
SendCommand(ConsoleCompilerConstants.BeginOffest, compiler.BeginOffset.ToString());
SendCommand(ConsoleCompilerConstants.VarBeginOffest, compiler.VarBeginOffset.ToString());