public void MutateNodeWithCount(string expression, int expectedCount)
        {
            var node          = new NodeAnalyzer().Parse(expression);
            var optimizedNode = new OptimizationMutator().MutateNodeWithCount(node);

            optimizedNode.Count.Should().Be(expectedCount);
        }
예제 #2
0
        public void simple_test(string expression)
        {
            var theoreticalNode      = new NodeAnalyzer().Parse(expression);
            var theoreticalResultSet = new double[_bound.StepCount + 1, _bound.StepCount + 1];

            _inRangeExpressionComputer.Compute(theoreticalNode, theoreticalResultSet, _bound);

            Node best = null;

            _geneticExpressionGenerator
            .Invoking
            (
                sut => best = sut.Generate
                              (
                    theoreticalResultSet,
                    _bound,
                    _bound,
                    Population,
                    GenerationCount,
                    GenerationDepth
                              )
            )
            .Should()
            .NotThrow();
            best.Should().NotBeNull();

            var printer = new PrettyPrintVisitor();

            printer.VisitNode(best);
            Console.WriteLine(printer.Output);
        }
예제 #3
0
        public void index_visitor_can_access_nodes_at_given_index()
        {
            var analyzer     = new NodeAnalyzer();
            var tree         = analyzer.Parse("x + y");
            var lookupIndex  = 0;
            var indexVisitor = new IndexVisitor(() => lookupIndex);

            lookupIndex = -1;
            indexVisitor
            .Invoking(sut => sut.VisitNode(tree))
            .Should()
            .Throw <ArgumentException>();

            lookupIndex = 10;
            indexVisitor
            .Invoking(sut => sut.VisitNode(tree))
            .Should()
            .Throw <ArgumentException>();

            lookupIndex = 3;
            indexVisitor.VisitNode(tree);
            var expected = indexVisitor.NodeAtIndex as IdentifierNode;

            expected.Should().NotBeNull();
            expected?.Identifier.Should().Be("y");
        }
예제 #4
0
        void Analyze(CompilationStartAnalysisContext compilationContext)
        {
            var compilation = compilationContext.Compilation;

            compilationContext.RegisterSyntaxTreeAction(delegate(SyntaxTreeAnalysisContext context)
            {
                try
                {
                    if (!compilation.SyntaxTrees.Contains(context.Tree))
                    {
                        return;
                    }
                    var semanticModel = compilation.GetSemanticModel(context.Tree);
                    var root          = context.Tree.GetRoot(context.CancellationToken);
                    var model         = compilationContext.Compilation.GetSemanticModel(context.Tree);
                    if (model.IsFromGeneratedCode(compilationContext.CancellationToken))
                    {
                        return;
                    }
                    var usageVisitor = new GetDelgateUsagesVisitor(semanticModel, context.CancellationToken);
                    usageVisitor.Visit(root);

                    var analyzer = new NodeAnalyzer(context, model, usageVisitor);
                    analyzer.Visit(root);
                }
                catch (OperationCanceledException) {}
            });
        }
예제 #5
0
        public void count_with_optimize_mutator(string expression, int expected)
        {
            var tree    = new NodeAnalyzer().Parse(expression);
            var mutator = new OptimizationMutator();

            var(_, count) = mutator.MutateNodeWithCount(tree);
            count.Should().Be(expected);
        }
            public static void OnCodeBlockStarted(CodeBlockStartAnalysisContext <SyntaxKind> context)
            {
                Action <Action <SyntaxNodeAnalysisContext>, ImmutableArray <SyntaxKind> > registerMethod =
                    (action, Kinds) => context.RegisterSyntaxNodeAction(action, Kinds);
                var analyzer = new NodeAnalyzer();

                analyzer.Initialize(registerMethod);
            }
예제 #7
0
        public void compute_visitor(string expression, double expected)
        {
            var analyzer       = new NodeAnalyzer();
            var tree           = analyzer.Parse(expression);
            var computeVisitor = new ComputeVisitor();

            computeVisitor.VisitNode(tree);
            computeVisitor.ComputedResult.Should().Be(expected);
        }
        public void optimizer_in_action(string input, string optimized)
        {
            var node          = new NodeAnalyzer().Parse(input);
            var optimizedNode = new OptimizationMutator().MutateNode(node);
            var printer       = new PrettyPrintVisitor();

            printer.VisitNode(optimizedNode);
            printer.ToString().Should().Be(optimized);
        }
예제 #9
0
        private void OnFixMisc(object sender, RoutedEventArgs e)
        {
            if (this.SelectedNode == null)
            {
                return;
            }

            if (this.SelectedNode.ContainsMiscErrors)
            {
                NodeAnalyzer.CleanMesh(this.SelectedNode);
            }
        }
예제 #10
0
        public void plus_to_minus_mutator(string expression, double expected)
        {
            var analyzer = new NodeAnalyzer();
            var tree     = analyzer.Parse(expression);
            var mutator  = new PlusToMinusMutator();

            tree = mutator.MutateNode(tree);
            var computeVisitor = new ComputeVisitor();

            computeVisitor.VisitNode(tree);
            computeVisitor.ComputedResult.Should().Be(expected);
        }
예제 #11
0
        public void pretty_print_visitor(string expression)
        {
            var analyzer       = new NodeAnalyzer();
            var tree           = analyzer.Parse(expression);
            var computeVisitor = new PrettyPrintVisitor();

            computeVisitor.VisitNode(tree);
            var output = computeVisitor.Output;

            computeVisitor.Output.Should().NotBeNullOrEmpty();
            Console.WriteLine(output);
        }
 public override void Initialize(AnalysisContext context)
 {
     if (_isCodeBlockAnalyzer)
     {
         context.RegisterCodeBlockStartAction <SyntaxKind>(OnCodeBlockStarted);
         context.RegisterCodeBlockAction(OnCodeBlockEnded);
     }
     else
     {
         Action <Action <SyntaxNodeAnalysisContext>, ImmutableArray <SyntaxKind> > registerMethod =
             (action, Kinds) => context.RegisterSyntaxNodeAction(action, Kinds);
         var analyzer = new NodeAnalyzer();
         analyzer.Initialize(registerMethod);
     }
 }
        void Analyze(CompilationStartAnalysisContext compilationContext)
        {
            var compilation = compilationContext.Compilation;
            compilationContext.RegisterSyntaxTreeAction(async delegate (SyntaxTreeAnalysisContext context)
            {
                try
                {
                    if (!compilation.SyntaxTrees.Contains(context.Tree))
                        return;
                    var semanticModel = compilation.GetSemanticModel(context.Tree);
                    var root = await context.Tree.GetRootAsync(context.CancellationToken).ConfigureAwait(false);
                    var model = compilationContext.Compilation.GetSemanticModel(context.Tree);
                    if (model.IsFromGeneratedCode(compilationContext.CancellationToken))
                        return;
                    var usageVisitor = new GetDelgateUsagesVisitor(semanticModel, context.CancellationToken);
                    usageVisitor.Visit(root);

                    var analyzer = new NodeAnalyzer(context, model, usageVisitor);
                    analyzer.Visit(root);
                }
                catch (OperationCanceledException) {}
            });
        }
 public void Initialize()
 {
     _computer     = new InRangeExpressionComputer();
     _nodeAnalyzer = new NodeAnalyzer();
 }
예제 #15
0
 public override void Initialize(AnalysisContext context)
 {
     if (_isCodeBlockAnalyzer)
     {
         context.RegisterCodeBlockStartAction<SyntaxKind>(OnCodeBlockStarted);
         context.RegisterCodeBlockAction(OnCodeBlockEnded);
     }
     else
     {
         Action<Action<SyntaxNodeAnalysisContext>, ImmutableArray<SyntaxKind>> registerMethod =
             (action, Kinds) => context.RegisterSyntaxNodeAction(action, Kinds);
         var analyzer = new NodeAnalyzer();
         analyzer.Initialize(registerMethod);
     }
 }
예제 #16
0
 public static void OnCodeBlockStarted(CodeBlockStartAnalysisContext<SyntaxKind> context)
 {
     Action<Action<SyntaxNodeAnalysisContext>, ImmutableArray<SyntaxKind>> registerMethod =
         (action, Kinds) => context.RegisterSyntaxNodeAction(action, Kinds);
     var analyzer = new NodeAnalyzer();
     analyzer.Initialize(registerMethod);
 }
예제 #17
0
        public void parsing_simple_expression(string toParse, string toString)
        {
            var a = new NodeAnalyzer();

            a.Parse(toParse).ToString().Should().Be(toString);
        }