public void BuildExecutionGraph() { if (_executionGraphBuilt) { return; } _executionGraphBuilt = true; //InitNode.EnsureReady(); //EnterNode.SubGraph.Graph.BeginNode.EnsureReady(); if (Graph.BeginNode.ReturnPath.IsInvalid) { return; } EmptyPath = new ExecutionPath(InitNode, new[] { EnterNode, Graph.BeginNode, }.Concat(Graph.BeginNode.ReturnPath.Nodes).ToArray(), -1); Automata.RegisterExecutionPath(EmptyPath); }
public EntryPointSubGraph(Automata <TInstruction, TOperand> automata, FiniteState state) : base(automata, state, null) { InitNode = new InitStateNode(automata, this); EndNode = new EndStateNode(automata, this); InitNode.OutEdges.Add(new Edge(InitNode, EnterNode)); LeaveNode.OutEdges.Add(new Edge(LeaveNode, EndNode)); EndPath = new ExecutionPath(LeaveNode, new Node[] { EndNode }, -1); Automata.RegisterExecutionPath(EndPath); //EndNode.EnsureReady(); }
private ExecutionPath[] BuildExecutionGraph() { if (_finalExecutionPaths != null) { return(_finalExecutionPaths); } _finalExecutionPaths = Array.Empty <ExecutionPath>(); var executionPaths = ExecutionPaths; var jointPaths = new List <ExecutionPath>(); for (var index = 0; index < executionPaths.Length; index++) { jointPaths.Clear(); var executionPath = executionPaths[index]; var output = executionPath.Output; executionPath.PriorityIndex = index; if (executionPath.IsPredicate) { continue; } if (LookAheadEnabled) { var nodeSet = new HashSet <Node>(executionPath.Nodes) { this }; while (output.ExecutionPaths.Length == 1 && output.ReturnPath.IsInvalid) { var path = output.ExecutionPaths[0]; if (path.IsPredicate) { break; } if (path.Nodes.All(nodeSet.Add) == false) { break; } if (jointPaths.Count == 0) { jointPaths.Add(executionPath); } jointPaths.Add(path); output = path.Output; } if (jointPaths.Count == 0) { continue; } //if (output.ExecutionPaths.Length == 0 && output.ReturnPath.IsInvalid == false) // jointPaths.Add(output.ReturnPath); executionPath.LookAhead = ExecutionPath.JoinPaths(jointPaths); } else if (output.ExecutionPaths.Length == 0 && output.ReturnPath.IsInvalid == false) { //jointPaths.Add(executionPath); //jointPaths.Add(output.ReturnPath); //var joinPaths = ExecutionPath.JoinPaths(jointPaths); //joinPaths.PriorityIndex = index; //executionPaths[index] = joinPaths; } } foreach (var executionPath in executionPaths) { _automata.RegisterExecutionPath(executionPath); if (executionPath.LookAhead != null) { _automata.RegisterExecutionPath(executionPath.LookAhead); } } _finalExecutionPaths = executionPaths; return(_finalExecutionPaths); }