Пример #1
0
 /// <summary>
 /// Adds LastUse/LastWrite dataflow edges to SourceGraph.
 /// Requires LastUsedVariables in the graph.
 /// </summary>
 public static void AddDataFlowGraph(SourceGraph sourceGraph)
 {
     foreach (var tokenOfInterest in sourceGraph.VariableUseNodes)
     {
         AddDataFlowEdges(sourceGraph, tokenOfInterest);
     }
 }
 private void AddNodesMenus(ContextualMenuPopulateEvent evt, Vector3 nodePosition)
 {
     foreach (var nodeType in NodeEditorUtilities.NodeTypes)
     {
         var menuName = $"{NodesMenu}/{nodeType.GetNodeMenuName()}";
         evt.menu.AppendAction(menuName,
                               (e) => {
             var node = SourceGraph.CreateNode(nodeType, nodePosition);
         },
                               DropdownMenuAction.AlwaysEnabled
                               );
     }
 }
        private void AddNodesMenus(ContextualMenuPopulateEvent evt, Vector3 nodePosition)
        {
            foreach (var nodeType in NodeEditorUtilities.NodeTypes)
            {
                var isHidden = nodeType.HasAttribute(typeof(HideNodeAttribute)) || nodeType.IsGenericType;
                if (isHidden)
                {
                    continue;
                }

                var menuName = $"{NodesMenu}/{nodeType.GetNodeMenuName()}";
                evt.menu.AppendAction(menuName, (e) => SourceGraph.CreateNode(nodeType, nodePosition),
                                      DropdownMenuAction.AlwaysEnabled
                                      );
            }
        }
Пример #4
0
        void RunningProcessExited(object sender, EventArgs e)
        {
            Dispatcher.Invoke(() =>
            {
                Grid1.IsEnabled = true;
                Grid2.IsEnabled = true;

                if (File.Exists(_targetFile))
                {
                    try
                    {
                        var runtimeWrap = new RuntimeWrap();

                        var fileInfo = new Dictionary <string, string>();
                        var response = runtimeWrap.GetFileResponse(_targetFile, ref fileInfo);

                        var responseConvert =
                            response.Select(
                                tuple => new PointF((float)tuple.Item1, (float)Math.Log(tuple.Item2)))
                            .ToArray();

                        ResultGraph.SetPoints(0, responseConvert, Colors.DarkSalmon, "Result");

                        var points = SourceGraph.GetPoints(0);
                        ResultGraph.SetPoints(1, (PointF[])points.Item1.Clone(), points.Item2, "Source");
                    }
                    catch
                    {
                        Dispatcher.InvokeAsync(() => MyAnimations.AnimateOpacity(TargetInfoError, 0, 1.0, 300));
                    }
                }

                if (TargetInfoError.Opacity > 0)
                {
                    MyAnimations.AnimateOpacity(TargetInfoError, 1.0, 0, 300);
                }

                MyAnimations.AnimateOpacity(ImageProcessingInfo, 1.0, 0, 300);
                MyAnimations.AnimateOpacity(Image3, 0, 1.0, 300);
            });
        }
 public static void AddMethodUseInformation(SourceGraph graph)
 {
     new MethodUseInformationCollector(graph).Visit(graph.SemanticModel.SyntaxTree.GetRoot());
 }
 private MethodUseInformationCollector(SourceGraph graph)
 {
     _graph = graph;
 }
Пример #7
0
        private void SelectSourceMouseDown(object sender, MouseButtonEventArgs e)
        {
            if (Grid1.IsEnabled == false)
            {
                return;
            }

            var grid = (Grid)sender;

            MyAnimations.AnimateRenderScale(grid, 1.0, 0.98,
                                            grid.ActualWidth / 2, grid.ActualHeight / 2, 100, (o, args) =>
            {
                var fileName = "";
                if (OpenFileDialog(ref fileName) == false)
                {
                    return;
                }

                _sourceFile = fileName;

                var runtimeWrap = new RuntimeWrap();

                try
                {
                    var fileInfo = new Dictionary <string, string>();
                    var response = runtimeWrap.GetFileResponse(fileName, ref fileInfo);

                    var fileFreq    = long.Parse(fileInfo["samplerate"]);
                    var fileSamples = long.Parse(fileInfo["samples_per_channel"]);
                    var duration    = fileSamples * 8 / fileFreq;

                    DurationLabel.Content = "File duration: " + TimeSpan.FromSeconds(duration).ToString();

                    var responseConvert =
                        response.Select(
                            tuple => new PointF((float)tuple.Item1, (float)Math.Log(tuple.Item2)))
                        .ToArray();

                    SourceGraph.SetPoints(0, responseConvert, Colors.LightSteelBlue, "Source");

                    if (Grid2.Opacity < 1.0)
                    {
                        Dispatcher.InvokeAsync(() =>
                        {
                            MyAnimations.AnimateRenderTranslation(Grid2, TranslateTransform.YProperty,
                                                                  -Grid1.ActualHeight - 20, 0, 300, 50);
                            MyAnimations.AnimateOpacity(Grid2, 0, 0.7, 100, 50);
                            MyAnimations.AnimateOpacity(LabelSelectDsdiff, 1.0, 0.0, 300);
                            MyAnimations.AnimateOpacity(Image1, 0.0, 1.0, 300);

                            if (LabelLoadError.Opacity > 0)
                            {
                                MyAnimations.AnimateOpacity(LabelLoadError, 1.0, 0, 300);
                            }
                        });
                    }

                    if (LabelWriteOutput.Opacity < 1.0)
                    {
                        Dispatcher.InvokeAsync(() =>
                        {
                            MyAnimations.AnimateOpacity(LabelWriteOutput, 0, 1.0, 300);
                            MyAnimations.AnimateOpacity(ImageProcessingInfo, 1.0, 0, 300);
                        });
                    }

                    if (FiltersGraph.GetFiltersCount() > 0)
                    {
                        Dispatcher.InvokeAsync(() =>
                        {
                            if (Image3.Opacity > 0)
                            {
                                MyAnimations.AnimateOpacity(Image3, 1.0, 0, 300);
                            }

                            if (Grid3.Opacity < 1.0)
                            {
                                MyAnimations.AnimateOpacity(Grid3, 0, 1.0, 300);
                            }
                        });
                    }
                }
                catch (Exception ex)
                {
                    Dispatcher.InvokeAsync(() =>
                    {
                        LabelLoadError.Content = "Unable to open file: " + ex.Message;

                        MyAnimations.AnimateOpacity(LabelLoadError, 0, 1.0, 300);

                        if (LabelSelectDsdiff.Opacity < 1.0)
                        {
                            MyAnimations.AnimateOpacity(LabelSelectDsdiff, 0, 1.0, 300);
                        }

                        if (Grid2.Opacity > 0)
                        {
                            MyAnimations.AnimateOpacity(Grid2, 1.0, 0, 300);
                        }

                        if (Grid3.Opacity > 0)
                        {
                            MyAnimations.AnimateOpacity(Grid3, 1.0, 0, 300);
                        }

                        if (Image1.Opacity > 0)
                        {
                            MyAnimations.AnimateOpacity(Image1, 1.0, 0, 300);
                        }
                    });
                }
            }, null, true);
        }
Пример #8
0
 public static void AddASTGraph(SourceGraph sourceGraph)
 {
     new ASTGraphBuilder(sourceGraph).Visit(sourceGraph.SemanticModel.SyntaxTree.GetRoot());
 }
Пример #9
0
 private ASTGraphBuilder(SourceGraph graph)
 {
     _graph = graph;
 }
Пример #10
0
 public static void AddGuardedByGraph(SourceGraph graph)
 {
     new GuardedByGraphBuilder(graph).Visit(graph.SemanticModel.SyntaxTree.GetRoot());
 }
Пример #11
0
 private GuardedByGraphBuilder(SourceGraph graph)
 {
     _graph = graph;
 }
Пример #12
0
        public static void AddDataFlowEdges(SourceGraph sourceGraph, SyntaxNodeOrToken tokenOfInterest,
                                            ICollection <SyntaxNodeOrToken> forbiddenNodes = null,
                                            ICollection <Edge <SyntaxNodeOrToken, SourceGraphEdge> > addedEdges = null)
        {
            var semanticModel = sourceGraph.SemanticModel;

            //There's nothing before the declaration, so we don't need to bother:
            if (sourceGraph.VariableDeclarationNodes.Contains(tokenOfInterest))
            {
                return;
            }

            //We only ever need to visit each node once, so collect visited nodes here:
            var visitedNodes = new HashSet <(SyntaxNodeOrToken, bool)>();

            //Start from all predecessors of the token of interest:
            var toVisit = new Stack <(SyntaxNodeOrToken node, bool haveFoundUse)>();

            foreach (var(_, label, target) in sourceGraph.GetOutEdges(tokenOfInterest))
            {
                if (label != SourceGraphEdge.LastUsedVariable || (forbiddenNodes?.Contains(target) ?? false))
                {
                    continue;
                }
                if (visitedNodes.Add((target, false)))
                {
                    toVisit.Push((target, false));
                }
            }

            var     nodeOfInterest  = tokenOfInterest.IsToken ? tokenOfInterest.AsToken().Parent : tokenOfInterest.AsNode();
            ISymbol symbolToLookFor = nodeOfInterest != null?semanticModel.GetSymbolInfo(nodeOfInterest).Symbol?.OriginalDefinition : null;

            string nodeLabelToLookFor = tokenOfInterest.ToString();

            while (toVisit.Count > 0)
            {
                var(node, haveFoundUse) = toVisit.Pop();
                var nodeSyntaxNode = node.IsToken ? node.AsToken().Parent : node.AsNode();
                var nodeSymbol     = nodeSyntaxNode != null?semanticModel.GetSymbolInfo(nodeSyntaxNode).Symbol?.OriginalDefinition : null;

                bool matches;
                if (symbolToLookFor == null || nodeSymbol == null)
                {
                    // This may happen in cases where Roslyn doesn't have symbol info
                    // or when one of the nodes is a dummy node (and thus doesn't belong to the SyntaxTree)
                    matches = node.ToString().Equals(nodeLabelToLookFor);
                }
                else
                {
                    matches = nodeSymbol.Equals(symbolToLookFor);
                }

                if (matches)
                {
                    if (!haveFoundUse)
                    {
                        var lastUseEdge = new Edge <SyntaxNodeOrToken, SourceGraphEdge>(tokenOfInterest, SourceGraphEdge.LastUse, node);
                        if (sourceGraph.AddEdge(lastUseEdge))
                        {
                            addedEdges?.Add(lastUseEdge);
                        }
                        haveFoundUse = true;
                    }

                    if (sourceGraph.VariableWriteNodes.Contains(node))
                    {
                        var lastWriteEdge = new Edge <SyntaxNodeOrToken, SourceGraphEdge>(tokenOfInterest, SourceGraphEdge.LastWrite, node);
                        if (sourceGraph.AddEdge(lastWriteEdge))
                        {
                            addedEdges?.Add(lastWriteEdge);
                        }
                        //We are done with this path -- we found a use and a write!
                        continue;
                    }

                    //There's nothing before the declaration, so we don't need to bother to recurse further:
                    if (sourceGraph.VariableDeclarationNodes.Contains(node))
                    {
                        continue;
                    }
                }

                foreach (var(_, label, target) in sourceGraph.GetOutEdges(node))
                {
                    if (label != SourceGraphEdge.LastUsedVariable || (forbiddenNodes?.Contains(target) ?? false))
                    {
                        continue;
                    }
                    if (visitedNodes.Add((target, haveFoundUse)))
                    {
                        toVisit.Push((target, haveFoundUse));
                    }
                }
            }
        }
 public static void AddGuardAnnotationsToGraph(SourceGraph graph, SyntaxNode rootNode)
 {
     new GuardAnnotationGraphExtractor(graph).Visit(rootNode);
 }
 private GuardAnnotationGraphExtractor(SourceGraph graph)
 {
     _graph = graph;
 }
Пример #15
0
 public static void AddReturnToGraph(SourceGraph graph)
 {
     new ReturnToGraphBuilder(graph).Visit(graph.SemanticModel.SyntaxTree.GetRoot());
 }
Пример #16
0
 private ReturnToGraphBuilder(SourceGraph graph)
 {
     _graph          = graph;
     _returningPoint = new Stack <SyntaxNodeOrToken>();
 }