Skip to content
This repository was archived by the owner on Nov 3, 2023. It is now read-only.

Commit

Permalink
Merge pull request #23 from ssrmm/disable-semantic-analysis-in-visual…
Browse files Browse the repository at this point in the history
…izer

[Visualizer.Old] Add an option to disable semantic analysis
  • Loading branch information
VladD2 authored Oct 31, 2016
2 parents c4ec93a + e53bed6 commit 68a58b9
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 27 deletions.
14 changes: 10 additions & 4 deletions Nitra.TestsLauncher.Old/Serialization/SerializationHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,22 @@ public static class SerializationHelper
{
private static XmlSerializer _serializer = new XmlSerializer(typeof(Language));

public static string Serialize(Nitra.Language language, IEnumerable<GrammarDescriptor> dynamicExtensions, LibReference[] libs, Func<string, string> pathConverter)
public static string Serialize(Nitra.Language language, IEnumerable<GrammarDescriptor> dynamicExtensions, LibReference[] libs, Func<string, string> pathConverter, bool disableSemanticAnalysis = false)
{
var writer = new StringWriter();
var data = new Language
{
Name = language.FullName,
Path = pathConverter(language.GetType().Assembly.Location),
DynamicExtensions = dynamicExtensions.Select(g => new DynamicExtension { Name = g.FullName, Path = pathConverter(g.GetType().Assembly.Location) }).ToArray(),
Libs = libs.Select(x => x.Serialize()).ToArray()
Libs = libs.Select(x => x.Serialize()).ToArray(),
DisableSemanticAnalysis = disableSemanticAnalysis
};
_serializer.Serialize(writer, data);
return writer.ToString();
}

public static Tuple<Nitra.Language, GrammarDescriptor[], LibReference[]> Deserialize(string text, Func<string, Assembly> assemblyResolver)
public static Tuple<Nitra.Language, GrammarDescriptor[], LibReference[], bool> Deserialize(string text, Func<string, Assembly> assemblyResolver)
{
var reader = new StringReader(text);
var languageInfo = (Language)_serializer.Deserialize(reader);
Expand All @@ -51,7 +52,9 @@ public static string Serialize(Nitra.Language language, IEnumerable<GrammarDescr
? new LibReference[0]
: languageInfo.Libs.Select(LibReference.Deserialize).ToArray();

return Tuple.Create(language, dynamicExtensions.ToArray(), libs);
var disableSemanticAnalysis = languageInfo.DisableSemanticAnalysis;

return Tuple.Create(language, dynamicExtensions.ToArray(), libs, disableSemanticAnalysis);
}
}

Expand All @@ -66,6 +69,9 @@ public sealed class Language
public DynamicExtension[] DynamicExtensions { get; set; }

public string[] Libs { get; set; }

[XmlAttribute]
public bool DisableSemanticAnalysis { get; set; }
}

public sealed class DynamicExtension
Expand Down
4 changes: 2 additions & 2 deletions Nitra.TestsLauncher.Old/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@ public static bool IsInvalidDirName(string testSuiteName)
return testSuiteName.Any(invalidChars.Contains);
}

public static string MakeXml([NotNull] string root, [NotNull] Language language, [NotNull] IEnumerable<GrammarDescriptor> dynamicExtensions, LibReference[] libs)
public static string MakeXml([NotNull] string root, [NotNull] Language language, [NotNull] IEnumerable<GrammarDescriptor> dynamicExtensions, LibReference[] libs, bool disableSemanticAnalysis = true)
{
return SerializationHelper.Serialize(language, dynamicExtensions, libs, path => MakeRelativePath(@from: root, isFromDir: true, to: path, isToDir: false));
return SerializationHelper.Serialize(language, dynamicExtensions, libs, path => MakeRelativePath(@from: root, isFromDir: true, to: path, isToDir: false), disableSemanticAnalysis);
}

public static bool IsEmpty(this IEnumerable seq)
Expand Down
28 changes: 15 additions & 13 deletions Nitra.TestsLauncher.Old/ViewModels/TestSuiteVm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,19 @@ public class TestSuiteVm : FullPathVm, ITestTreeContainerNode
{
public static string ConfigFileName = "config.xml";

public SolutionVm Solution { get; private set; }
public string Name { get; private set; }
public Language Language { get; private set; }
public ObservableCollection<GrammarDescriptor> DynamicExtensions { get; private set; }
public ObservableCollection<ITest> Tests { get; private set; }
public IEnumerable<ITest> Children { get { return Tests; } }
public string TestSuitePath { get; set; }
public Exception Exception { get; private set; }
public TimeSpan TestTime { get; private set; }
public StatisticsTask.Container Statistics { get; private set; }
public Assembly[] Assemblies { get; private set; }
public LibReference[] Libs { get; private set; }
public SolutionVm Solution { get; private set; }
public string Name { get; private set; }
public Language Language { get; private set; }
public ObservableCollection<GrammarDescriptor> DynamicExtensions { get; private set; }
public ObservableCollection<ITest> Tests { get; private set; }
public IEnumerable<ITest> Children { get { return Tests; } }
public string TestSuitePath { get; set; }
public Exception Exception { get; private set; }
public TimeSpan TestTime { get; private set; }
public StatisticsTask.Container Statistics { get; private set; }
public Assembly[] Assemblies { get; private set; }
public LibReference[] Libs { get; private set; }
public bool DisableSemanticAnalysis { get; }

public string _hint;
public override string Hint { get { return _hint; } }
Expand Down Expand Up @@ -80,6 +81,7 @@ public TestSuiteVm(SolutionVm solution, string name, string config)
Assemblies = assemblyRelativePaths.Values.ToArray();

libs.AddRange(languageAndExtensions.Item3);
DisableSemanticAnalysis = languageAndExtensions.Item4;

var indent = Environment.NewLine + " ";
var para = Environment.NewLine + Environment.NewLine;
Expand Down Expand Up @@ -139,7 +141,7 @@ public TestSuiteVm(SolutionVm solution, string name, string config)
solution.TestSuites.Add(this);
}

public string Xml { get { return Utils.MakeXml(_rootPath, Language, DynamicExtensions, Libs); } }
public string Xml { get { return Utils.MakeXml(_rootPath, Language, DynamicExtensions, Libs, DisableSemanticAnalysis); } }

public RecoveryAlgorithm RecoveryAlgorithm { get; set; }

Expand Down
2 changes: 1 addition & 1 deletion Nitra.TestsLauncher.Old/ViewModels/TestVm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public bool Run(RecoveryAlgorithm recoveryAlgorithm = RecoveryAlgorithm.Smart, i
_file._completionPrefix = completionPrefix;
_file.ResetCache();

if (_file.Ast == null)
if (TestSuite.DisableSemanticAnalysis || _file.Ast == null)
return false;

var tests = _testFolder == null ? (IEnumerable<TestVm>)new[] {this} : _testFolder.Tests;
Expand Down
5 changes: 4 additions & 1 deletion Nitra.Visualizer.Old/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,10 @@ private void DoParse()
_currentTest.Run(GetRecoveryAlgorithm());
_performanceTreeView.ItemsSource = new[] { (_currentTest.Statistics ?? _currentTestFolder.Statistics) };

_astRoot = _currentTest.File.Ast;
if (_currentTest.File.HasAst)
{
_astRoot = _currentTest.File.Ast;
}
_parseResult = _currentTest.File.ParseResult;
_foldingStrategy.ParseResult = _parseResult;
_foldingStrategy.UpdateFoldings(_foldingManager, _text.Document);
Expand Down
14 changes: 13 additions & 1 deletion Nitra.Visualizer.Old/TestSuiteCreateOrEditModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@
using Nitra.ViewModels;
using Nitra.Visualizer.Properties;
using File = System.IO.File;
using Type = Nitra.Declarations.Type;

namespace Nitra.Visualizer
{
internal class TestSuiteCreateOrEditModel : DependencyObject
{
private readonly Settings _settings;

public TestSuiteCreateOrEditModel(Settings settings, bool isCreate)
public TestSuiteCreateOrEditModel(Settings settings, bool isCreate, bool isSemanticAnalysisDisabled = false)
{
_settings = settings;

Expand All @@ -26,6 +27,7 @@ public TestSuiteCreateOrEditModel(Settings settings, bool isCreate)
RootFolder = Path.GetDirectoryName(_settings.CurrentSolution);
Languages = new ObservableCollection<Language>();
DynamicExtensions = new ObservableCollection<DynamicExtensionModel>();
IsSemanticAnalysisDisabled = isSemanticAnalysisDisabled;
}

public bool IsCreate
Expand Down Expand Up @@ -76,6 +78,16 @@ public string Assemblies
public static readonly DependencyProperty AssembliesProperty =
DependencyProperty.Register("Assemblies", typeof(string), typeof(TestSuiteCreateOrEditModel), new FrameworkPropertyMetadata("", OnAssembliesChanged));

public bool IsSemanticAnalysisDisabled
{
get { return (bool) GetValue(IsSemanticAnalysisDisabledProperty); }
set { SetValue(IsSemanticAnalysisDisabledProperty, value);}
}

public static readonly DependencyProperty IsSemanticAnalysisDisabledProperty =
DependencyProperty.Register("IsSemanticAnalysisDisabled", typeof(bool), typeof(TestSuiteCreateOrEditModel),
new FrameworkPropertyMetadata(false));

private static void OnAssembliesChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var model = (TestSuiteCreateOrEditModel)d;
Expand Down
13 changes: 10 additions & 3 deletions Nitra.Visualizer.Old/TestSuiteDialog.xaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Window x:Class="Nitra.Visualizer.TestSuiteDialog"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="{Binding Path=Title}" Height="634.263" Width="700" ResizeMode="NoResize" FontSize="16" WindowStartupLocation="CenterOwner" ShowInTaskbar="False"
Title="{Binding Path=Title}" Height="700" Width="700" ResizeMode="NoResize" FontSize="16" WindowStartupLocation="CenterOwner" ShowInTaskbar="False"
x:ClassModifier="internal">
<Grid>
<Grid.Resources>
Expand Down Expand Up @@ -42,6 +42,8 @@
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
Expand Down Expand Up @@ -73,9 +75,14 @@
</DataTemplate>
</ListView.ItemTemplate>
</ListView>

<Label Grid.Column="1" Grid.Row="6" Content="Options"/>
<StackPanel Grid.Column="3" Grid.Row="6" VerticalAlignment="Center">
<CheckBox Content="Disable semantic analysis" IsChecked="{Binding IsSemanticAnalysisDisabled}"/>
</StackPanel>

<Button Content="_OK" Name="_okButton" IsDefault="True" Grid.Row="5" Grid.Column="3" Margin="0,0,100,9" Click="_okButton_Click" />
<Button Content="_Cancel" Name="_cancelButton" IsCancel="True" Grid.Row="5" Grid.Column="3" Margin="0,0,0,9" />
<Button Content="_OK" Name="_okButton" IsDefault="True" Grid.Row="7" Grid.Column="3" Margin="0,0,100,9" Click="_okButton_Click" />
<Button Content="_Cancel" Name="_cancelButton" IsCancel="True" Grid.Row="7" Grid.Column="3" Margin="0,0,0,9" />
<Label Grid.Column="1" Grid.Row="5" Content="Libraries" Margin="1,10,8,0" Grid.ColumnSpan="2" />
<TextBox Grid.Column="3" Grid.Row="5" Grid.ColumnSpan="2" x:Name="_libs" VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto" AcceptsReturn="True" LostFocus="_libs_LostFocus" KeyUp="_libs_KeyUp" Height="140" Margin="0,6,0,6" VerticalAlignment="Top" />
</Grid>
Expand Down
4 changes: 2 additions & 2 deletions Nitra.Visualizer.Old/TestSuiteDialog.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public TestSuiteDialog(bool isCreate, TestSuiteVm baseTestSuite, Settings settin
_libsChangedTimer.Interval = TimeSpan.FromSeconds(1.3);
_libsChangedTimer.Tick += _libsEdit_timer_Tick;

DataContext = _model = new TestSuiteCreateOrEditModel(settings, isCreate);
DataContext = _model = new TestSuiteCreateOrEditModel(settings, isCreate, baseTestSuite.DisableSemanticAnalysis);

InitializeComponent();

Expand Down Expand Up @@ -172,7 +172,7 @@ private void _okButton_Click(object sender, RoutedEventArgs e)
}

var dynamicExtensions = _model.DynamicExtensions.Where(x => x.IsEnabled && x.IsChecked).Select(x => x.Descriptor);
var xml = Utils.MakeXml(root, selectedLanguage, dynamicExtensions, _model.NormalizedLibs);
var xml = Utils.MakeXml(root, selectedLanguage, dynamicExtensions, _model.NormalizedLibs, _model.IsSemanticAnalysisDisabled);
var configPath = Path.Combine(path, TestSuiteVm.ConfigFileName);
File.WriteAllText(configPath, xml);
}
Expand Down

0 comments on commit 68a58b9

Please sign in to comment.