public GraphBuilder(SynchronizeData sd, GraphToDSCompiler.GraphCompiler gc) { nodesToAdd = sd.AddedNodes; nodesToModify = sd.ModifiedNodes; nodesToRemove = sd.RemovedNodes; this.gc = gc; }
private static SynchronizeData ListLevel(string[] b) { SynchronizeData sd = new SynchronizeData(); for (int i = 0; i < b.Length - 1; i++) { string[] c = b[i].Split(NodesCountMarker); int count = Int32.Parse(c[0]); if (count == 0) { continue; } else { if (i == 0) { sd.RemovedNodes = UintNodesProcess(c[1]); } else if (i == 1) { sd.AddedNodes = SnapshotNodeListProcess(c[1]); } else { sd.ModifiedNodes = SnapshotNodeListProcess(c[1]); } } } return(sd); }
public GraphUpdateReadyEventArgs(SynchronizeData syncData, EventStatus resultStatus, String errorString) { this.SyncData = syncData; this.ResultStatus = resultStatus; this.ErrorString = errorString; if (string.IsNullOrEmpty(this.ErrorString)) this.ErrorString = ""; Errors = new List<ErrorObject>(); Warnings = new List<ErrorObject>(); }
public void BuildGraphFromNodes(List<SnapshotNode> snapshotNodeList) { // Instantiate SynchronizeData and GraphCompiler SynchronizeData syncData = new SynchronizeData(); syncData.AddedNodes = snapshotNodeList; GraphCompiler gc = GraphToDSCompiler.GraphCompiler.CreateInstance(); GraphBuilder gb = new GraphBuilder(syncData, gc); gb.AddNodesToAST(); gb.MakeConnectionsForAddedNodes(); graph = gb.Graph; }
public void BuildGraphFromNodes(List <SnapshotNode> snapshotNodeList) { // Instantiate SynchronizeData and GraphCompiler SynchronizeData syncData = new SynchronizeData(); syncData.AddedNodes = snapshotNodeList; GraphCompiler gc = GraphToDSCompiler.GraphCompiler.CreateInstance(); GraphBuilder gb = new GraphBuilder(syncData, gc); gb.AddNodesToAST(); gb.MakeConnectionsForAddedNodes(); graph = gb.Graph; }
private void SynchronizeInternal(GraphToDSCompiler.SynchronizeData syncData, out string code) { Validity.Assert(null != runner); Validity.Assert(null != graphCompiler); if (syncData.AddedNodes.Count == 0 && syncData.ModifiedNodes.Count == 0 && syncData.RemovedNodes.Count == 0) { code = ""; ResetVMForDeltaExecution(); return; } else { System.Diagnostics.Debug.WriteLine("Begin SyncInternal: {0}", syncData); GraphToDSCompiler.GraphBuilder g = new GraphBuilder(syncData, graphCompiler); code = g.BuildGraphDAG(); System.Diagnostics.Debug.WriteLine("SyncInternal => " + code); //List<string> deletedVars = new List<string>(); ResetVMForDeltaExecution(); //Synchronize the core configuration before compilation and execution. if (syncCoreConfigurations) { SyncCoreConfigurations(runnerCore, executionOptions); syncCoreConfigurations = false; } bool succeeded = CompileAndExecute(code); if (succeeded) { graphCompiler.ResetPropertiesForNextExecution(); } } }
public void TestDeltaExecution01() { //=========================================================================== // Creates: // a = 10 // // Adds: // b = 20 //=========================================================================== ILiveRunner liveRunner = new ProtoScript.Runners.Obsolete.LiveRunner(); //=========================================================================== // Build the first snapshot nodes a = 10 //=========================================================================== GraphToDSCompiler.SynchronizeData data = new GraphToDSCompiler.SynchronizeData(); uint uidIdent = 1; uint uidLiteral = 2; Connection k1 = new Connection(); k1.LocalIndex = 0; k1.OtherIndex = 0; k1.OtherNode = uidLiteral; Connection k2 = new Connection(); k2.LocalIndex = 0; k2.OtherIndex = 0; k2.OtherNode = uidIdent; SnapshotNode n1 = new SnapshotNode(uidIdent, SnapshotNodeType.Identifier, "a"); n1.InputList.Add(k1); SnapshotNode n2 = new SnapshotNode(uidLiteral, SnapshotNodeType.Literal, "10"); n2.OutputList.Add(k2); data.AddedNodes.Add(n1); data.AddedNodes.Add(n2); //=========================================================================== // Compile the current graph //=========================================================================== liveRunner.UpdateGraph(data); //=========================================================================== // Build the first snapshot nodes b = 10 //=========================================================================== uint uidIdent2 = 10; uint uidLiteral2 = 20; data = new GraphToDSCompiler.SynchronizeData(); k1 = new Connection(); k1.LocalIndex = 0; k1.OtherIndex = 0; k1.OtherNode = uidLiteral2; k2 = new Connection(); k2.LocalIndex = 0; k2.OtherIndex = 0; k2.OtherNode = uidIdent2; n1 = new SnapshotNode(uidIdent2, SnapshotNodeType.Identifier, "b"); n1.InputList.Add(k1); n2 = new SnapshotNode(uidLiteral2, SnapshotNodeType.Literal, "20"); n2.OutputList.Add(k2); data.AddedNodes.Add(n1); data.AddedNodes.Add(n2); //=========================================================================== // Compile the current graph and added graph //=========================================================================== liveRunner.UpdateGraph(data); //=========================================================================== // Verify the value of 'a' //=========================================================================== ProtoCore.Mirror.RuntimeMirror mirror = liveRunner.QueryNodeValue(uidIdent); Assert.IsTrue(mirror.GetData().GetStackValue().opdata == 10); //=========================================================================== // Verify the value of 'b' //=========================================================================== mirror = liveRunner.QueryNodeValue(uidIdent2); Assert.IsTrue(mirror.GetData().GetStackValue().opdata == 20); }
public void UpdateGraph(SynchronizeData syndData) { while (true) { lock (taskQueue) { //Spin waiting for the queue to be empty if (taskQueue.Count == 0) { string code = null; SynchronizeInternal(syndData, out code); return; } } Thread.Sleep(0); } }
private SynchronizeData CreateSynchronizeDataForGuidList(Dictionary<uint, string> modfiedGuidList) { Dictionary<uint, SnapshotNode> modifiedGuids = new Dictionary<uint, SnapshotNode>(); SynchronizeData syncDataReturn = new SynchronizeData(); if (modfiedGuidList != null) { //foreach (uint guid in modfiedGuidList) foreach (var kvp in modfiedGuidList) { // Get the uid recognized by the graphIDE uint guid = kvp.Key; string name = kvp.Value; SnapshotNode sNode = new SnapshotNode(this.graphCompiler.GetRealUID(guid), SnapshotNodeType.Identifier, name); if (!modifiedGuids.ContainsKey(sNode.Id)) { modifiedGuids.Add(sNode.Id, sNode); } } foreach (KeyValuePair<uint, SnapshotNode> kvp in modifiedGuids) syncDataReturn.ModifiedNodes.Add(kvp.Value); } return syncDataReturn; }
public GraphUpdateReadyEventArgs(SynchronizeData syncData) : this(syncData, EventStatus.OK, null) { }
/// <summary> /// Push new synchronization data, returns immediately and will /// trigger a GraphUpdateReady when the value when the execution /// is completed /// </summary> /// <param name="syncData"></param> public void BeginUpdateGraph(SynchronizeData syncData) { lock (taskQueue) { taskQueue.Enqueue( new UpdateGraphTask(syncData, this)); } //Todo(Luke) add a Monitor queue to prevent having to have the //work poll }
internal void SynchronizeToLiveRunner(DeltaNodes deltaNodes) { if (false != deltaNodes.IsEmpty) throw new InvalidOperationException("Nothing to send to 'lifeRunner'"); // If there is something that we would like to query // the value for, add it into the modified node list. if (false == scheduledDeltaNodes.IsEmpty) { deltaNodes.AppendToRemovedNodes(scheduledDeltaNodes.RemovedNodes); deltaNodes.AppendToAddedNodes(scheduledDeltaNodes.AddedNodes); deltaNodes.AppendToModifiedNodes(scheduledDeltaNodes.ModifiedNodes); scheduledDeltaNodes.Reset(); } // Compact the DeltaNodes so that there is no duplicate and no node // exists in more than one list (e.g. addedNodes and modifiedNodes). deltaNodes.Compact(); SynchronizeData sd = new SynchronizeData(); if (null != deltaNodes.RemovedNodes && (deltaNodes.RemovedNodes.Count > 0)) { foreach (IVisualNode node in deltaNodes.RemovedNodes) sd.RemovedNodes.Add(node.NodeId); } if (null != deltaNodes.AddedNodes && (deltaNodes.AddedNodes.Count > 0)) sd.AddedNodes = this.CreateSnapshotNodesFromVisualNodes(deltaNodes.AddedNodes); if (null != deltaNodes.ModifiedNodes && (deltaNodes.ModifiedNodes.Count > 0)) sd.ModifiedNodes = this.CreateSnapshotNodesFromVisualNodes(deltaNodes.ModifiedNodes); // Tell the graph compiler that some variables are undefined. MergeUndefinedVariablesIntoData(deltaNodes.Undefinitions, sd); this.sdc.sdList.Add(sd); if (Configurations.EnableLiveExection) { try { this.CurrentSynchronizer.PushUpdate(sd); } catch (Exception e) { Debug.WriteLine(e); } } }
private void ReportRuntimeWarnings(string code, SynchronizeData syncDataReturn, Dictionary<uint, string> modifiedGuidList, ref GraphUpdateReadyEventArgs retArgs) { //GraphUpdateReadyEventArgs retArgs = null; if (runner.runnerCore.RuntimeStatus.Warnings.Count > 0) { if (retArgs == null) retArgs = new GraphUpdateReadyEventArgs(syncDataReturn); foreach (var err in runner.runnerCore.RuntimeStatus.Warnings) { string msg = err.message; int lineNo = err.Line; // TODO: How can the lineNo be invalid ? if (lineNo == ProtoCore.DSASM.Constants.kInvalidIndex) { retArgs.Warnings.Add(new GraphUpdateReadyEventArgs.ErrorObject { Message = msg, Id = 0 }); continue; } string varName = GetVarNameFromCode(lineNo, code); foreach (var kvp in modifiedGuidList) { // Get the uid recognized by the graphIDE uint guid = kvp.Key; string name = kvp.Value; if (name.Equals(varName)) { retArgs.Warnings.Add(new GraphUpdateReadyEventArgs.ErrorObject { Message = msg, Id = runner.graphCompiler.GetRealUID(guid) }); break; } } if (retArgs.Warnings.Count == 0) { LogWarningsFromInputNodes(retArgs, varName, msg); } } } }
private void ReportBuildErrorsAndWarnings(string code, SynchronizeData syncDataReturn, Dictionary<uint, string> modifiedGuidList, ref GraphUpdateReadyEventArgs retArgs) { //GraphUpdateReadyEventArgs retArgs = null; if (runner.compileState.BuildStatus.ErrorCount > 0) { retArgs = new GraphUpdateReadyEventArgs(syncDataReturn); foreach (var err in runner.compileState.BuildStatus.Errors) { string msg = err.Message; int lineNo = err.Line; // TODO: How can the lineNo be invalid ? if (lineNo == ProtoCore.DSASM.Constants.kInvalidIndex) { retArgs.Errors.Add(new GraphUpdateReadyEventArgs.ErrorObject { Message = msg, Id = 0 }); continue; } string varName = GetVarNameFromCode(lineNo, code); foreach (var ssnode in syncData.AddedNodes) { if (ssnode.Content.Contains(varName)) { uint id = ssnode.Id; retArgs.Errors.Add(new GraphUpdateReadyEventArgs.ErrorObject { Message = msg, Id = id }); break; } } if (retArgs.Errors.Count == 0) { foreach (var ssnode in syncData.ModifiedNodes) { if (ssnode.Content.Contains(varName)) { uint id = ssnode.Id; retArgs.Errors.Add(new GraphUpdateReadyEventArgs.ErrorObject { Message = msg, Id = id }); break; } } } } } if (runner.compileState.BuildStatus.WarningCount > 0) { if (retArgs == null) retArgs = new GraphUpdateReadyEventArgs(syncDataReturn); foreach (var warning in runner.compileState.BuildStatus.Warnings) { string msg = warning.msg; int lineNo = warning.line; // TODO: How can the lineNo be invalid ? if (lineNo == ProtoCore.DSASM.Constants.kInvalidIndex) { retArgs.Warnings.Add(new GraphUpdateReadyEventArgs.ErrorObject { Message = msg, Id = 0 }); continue; } string varName = GetVarNameFromCode(lineNo, code); // This array should be empty for Build errors /*foreach (var ssnode in syncDataReturn.ModifiedNodes) { if(ssnode.Content.Contains(varName)) { uint id = ssnode.Id; retArgs.Warnings.Add(new GraphUpdateReadyEventArgs.ErrorObject { Message = msg, Id = id }); break; } }*/ foreach (var kvp in modifiedGuidList) { // Get the uid recognized by the graphIDE uint guid = kvp.Key; string name = kvp.Value; if (name.Equals(varName)) { retArgs.Warnings.Add(new GraphUpdateReadyEventArgs.ErrorObject { Message = msg, Id = runner.graphCompiler.GetRealUID(guid) }); break; } } if (retArgs.Warnings.Count == 0) { LogWarningsFromInputNodes(retArgs, varName, msg); } } } }
public static List<SnapshotNode> NodeToCodeBlocks(List<SnapshotNode> inputs, GraphToDSCompiler.GraphCompiler originalGC) { List<SnapshotNode> codeBlocks = new List<SnapshotNode>(); GraphToDSCompiler.GraphCompiler newGC = GraphCompiler.CreateInstance(); newGC.SetCore(core); GraphToDSCompiler.SynchronizeData newSyncData = new SynchronizeData(); newSyncData.AddedNodes = inputs; newSyncData.ModifiedNodes = new List<SnapshotNode>(); newSyncData.RemovedNodes = new List<uint>(); GraphToDSCompiler.GraphBuilder GB = new GraphBuilder(newSyncData, newGC); #region fix connection for multi-line CBN /*for multi-line code blocks*/ List<Node> completeList = originalGC.Graph.nodeList; List<uint> originalNodeUIDList = new List<uint>(); foreach (Node oriGcNode in completeList) { originalNodeUIDList.Add(oriGcNode.Guid); } GB.AddNodesToAST(); //List<SnapshotNode> inputsCopy = new List<SnapshotNode>(inputs); for (int i = 0; i < inputs.Count; i++) { SnapshotNode inputSnapshotNode = inputs[i]; for (int j = 0; j < inputSnapshotNode.InputList.Count; j++) { Connection inputConnection = inputSnapshotNode.InputList[j]; if (!originalNodeUIDList.Contains(inputConnection.OtherNode)) { Connection correctedInputConnection = new Connection(); correctedInputConnection.LocalName = inputConnection.LocalName; correctedInputConnection.LocalIndex = inputConnection.LocalIndex; correctedInputConnection.IsImplicit = inputConnection.IsImplicit; correctedInputConnection.OtherIndex = inputConnection.OtherIndex; if (newGC.codeBlockUIDMap.ContainsKey(inputConnection.OtherNode)) { correctedInputConnection.OtherNode = newGC.codeBlockUIDMap[inputConnection.OtherNode][inputConnection.OtherIndex]; } else { correctedInputConnection.OtherNode = originalGC.codeBlockUIDMap[inputConnection.OtherNode][inputConnection.OtherIndex]; } inputSnapshotNode.InputList.Remove(inputConnection); inputSnapshotNode.InputList.Insert(j, correctedInputConnection); } } for (int j = 0; j < inputSnapshotNode.OutputList.Count; j++) { Connection outputConnection = inputSnapshotNode.OutputList[j]; if (!originalNodeUIDList.Contains(outputConnection.OtherNode)) // if the other node is split { Connection correctedInputConnection = new Connection(); correctedInputConnection.LocalName = outputConnection.LocalName; correctedInputConnection.LocalIndex = outputConnection.LocalIndex; correctedInputConnection.IsImplicit = outputConnection.IsImplicit; correctedInputConnection.OtherIndex = outputConnection.OtherIndex; if (newGC.codeBlockUIDMap.ContainsKey(outputConnection.OtherNode)) { correctedInputConnection.OtherNode = newGC.GetUidOfRHSIdentifierInCodeBlock( outputConnection.OtherNode, outputConnection.OtherIndex, outputConnection.LocalName); //correctedInputConnection.OtherNode = newGC.codeBlockUIDMap[outputConnection.OtherNode][outputConnection.OtherIndex]; } else { correctedInputConnection.OtherNode = originalGC.codeBlockUIDMap[outputConnection.OtherNode][outputConnection.OtherIndex]; } inputSnapshotNode.OutputList.Remove(outputConnection); inputSnapshotNode.OutputList.Insert(j, correctedInputConnection); } } } GB.nodesToAdd = inputs; GB.MakeConnectionsForAddedNodes_NodeToCode(GB.nodesToAdd); newGC.PrintGraph(); #endregion //GB.BuildGraphForCodeBlock(); List<uint> nodesToBeAdded = new List<uint>(); List<Node> nodesToBeReplaced = new List<Node>(); //adding children node from the originalGC to the newGC needed for the newGC to generate code foreach (Node n in completeList) { foreach (Node child in n.GetChildren()) { if (newGC.Graph.GetNode(child.Guid) != null) { if (child.Name != newGC.Graph.GetNode(child.Guid).Name) { nodesToBeReplaced.Add(child); } } } } foreach (uint n in nodesToBeAdded) { Node n1 = completeList.FirstOrDefault(q => q.Guid == n); //n1.children.Clear(); nodesToBeReplaced.Add(n1); //newSyncData.RemovedNodes.Add(n); } List<uint> nodeToCodeUIDs = new List<uint>(); foreach (SnapshotNode ssn in inputs) nodeToCodeUIDs.Add(ssn.Id); newGC.nodeToCodeUIDs = nodeToCodeUIDs; /*create output snapshot nodes*/ List<Connection> inputNodeInputConnections = new List<Connection>(); List<Connection> inputNodeOutputConnections = new List<Connection>(); foreach (SnapshotNode ssn in inputs) { foreach (Connection inputConnection in ssn.InputList) { if (!nodeToCodeUIDs.Contains(inputConnection.OtherNode)) inputNodeInputConnections.Add(inputConnection); } foreach (Connection outputConnection in ssn.OutputList) { if (!nodeToCodeUIDs.Contains(outputConnection.OtherNode)) inputNodeOutputConnections.Add(outputConnection); } } newGC.ReplaceNodesFromAList(nodesToBeReplaced); newSyncData.AddedNodes = new List<SnapshotNode>(); newSyncData.ModifiedNodes = new List<SnapshotNode>(); newSyncData.RemovedNodes = new List<uint>(); GB = new GraphBuilder(newSyncData, newGC); //string result = GB.BuildGraphDAG(); List<SnapshotNode> nodeToCodeBlocks = GB.PrintCodeForSelectedNodes(originalGC, inputs); /*for now, only connected nodes are supported: return all connections that are not internal connections (connections between the selected nodes)*/ //uint id = 0; //foreach (string content in toCode) //{ // SnapshotNode ssn = new SnapshotNode(); // ssn.Type = SnapshotNodeType.CodeBlock; // ssn.Content = content; // ssn.Id = id++; // ssn.InputList = new List<Connection>(); // //stupid stub // foreach (Connection inputConnection in inputNodeInputConnections) // { // Connection newInputConnection = new Connection(); // newInputConnection.OtherNode = inputConnection.OtherNode; // newInputConnection.OtherIndex = inputConnection.OtherIndex; // newInputConnection.IsImplicit = inputConnection.IsImplicit; // string[] tokens = newGC.Graph.GetNode(inputConnection.OtherNode).Name.Split('='); // newInputConnection.LocalName = tokens[0]; // ssn.InputList.Add(newInputConnection); // } // //ssn.InputList = inputNodeInputConnections; // ssn.OutputList = new List<Connection>(); // foreach (Connection outputConnection in inputNodeOutputConnections) // { // Connection newOutputConnection = new Connection(); // newOutputConnection.OtherNode = outputConnection.OtherNode; // newOutputConnection.OtherIndex = outputConnection.OtherIndex; // newOutputConnection.IsImplicit = outputConnection.IsImplicit; // //string[] tokens = originalGC.Graph.GetNode(outputConnection.OtherNode).Name.Split('='); // newOutputConnection.LocalName = outputConnection.LocalName; // ssn.OutputList.Add(newOutputConnection); // } // //ssn.OutputList = inputNodeOutputConnections; // codeBlocks.Add(ssn); //} /*update the original GC*/ foreach (SnapshotNode inputNode in inputs) { if (originalNodeUIDList.Contains(inputNode.Id)) originalGC.RemoveNodes(inputNode.Id, false); else { foreach (KeyValuePair<uint, Dictionary<int, uint>> kvp in originalGC.codeBlockUIDMap) { if (kvp.Value.ContainsValue(inputNode.Id)) { originalGC.RemoveNodes(kvp.Key, false); } } } } foreach (Node node in newGC.Graph.nodeList) { node.Name = node.Name.TrimEnd(';') + ";"; } originalGC.Graph.nodeList.Union<Node>(newGC.Graph.nodeList); //originalGC = newGC; /**/ return nodeToCodeBlocks; //return codeBlocks; }
public static List<SnapshotNode> NodeToCodeBlocks(List<SnapshotNode> inputs, GraphToDSCompiler.GraphCompiler originalGC) { List<SnapshotNode> codeBlocks = new List<SnapshotNode>(); GraphToDSCompiler.GraphCompiler newGC = GraphCompiler.CreateInstance(); newGC.SetCore(compileState); GraphToDSCompiler.SynchronizeData newSyncData = new SynchronizeData(); newSyncData.AddedNodes = inputs; newSyncData.ModifiedNodes = new List<SnapshotNode>(); newSyncData.RemovedNodes = new List<uint>(); GraphToDSCompiler.GraphBuilder GB = new GraphBuilder(newSyncData, newGC); #region fix connection for multi-line CBN /*for multi-line code blocks*/ List<Node> completeList = originalGC.Graph.nodeList; List<uint> originalNodeUIDList = new List<uint>(); foreach (Node oriGcNode in completeList) { originalNodeUIDList.Add(oriGcNode.Guid); } GB.AddNodesToAST(); //List<SnapshotNode> inputsCopy = new List<SnapshotNode>(inputs); for (int i = 0; i < inputs.Count; i++) { SnapshotNode inputSnapshotNode = inputs[i]; for (int j = 0; j < inputSnapshotNode.InputList.Count; j++) { Connection inputConnection = inputSnapshotNode.InputList[j]; if (!originalNodeUIDList.Contains(inputConnection.OtherNode)) { Connection correctedInputConnection = new Connection(); correctedInputConnection.LocalName = inputConnection.LocalName; correctedInputConnection.LocalIndex = inputConnection.LocalIndex; correctedInputConnection.IsImplicit = inputConnection.IsImplicit; correctedInputConnection.OtherIndex = inputConnection.OtherIndex; if (newGC.codeBlockUIDMap.ContainsKey(inputConnection.OtherNode)) { correctedInputConnection.OtherNode = newGC.codeBlockUIDMap[inputConnection.OtherNode][inputConnection.OtherIndex]; } else { correctedInputConnection.OtherNode = originalGC.codeBlockUIDMap[inputConnection.OtherNode][inputConnection.OtherIndex]; } inputSnapshotNode.InputList.Remove(inputConnection); inputSnapshotNode.InputList.Insert(j, correctedInputConnection); } } for (int j = 0; j < inputSnapshotNode.OutputList.Count; j++) { Connection outputConnection = inputSnapshotNode.OutputList[j]; if (!originalNodeUIDList.Contains(outputConnection.OtherNode)) // if the other node is split { Connection correctedInputConnection = new Connection(); correctedInputConnection.LocalName = outputConnection.LocalName; correctedInputConnection.LocalIndex = outputConnection.LocalIndex; correctedInputConnection.IsImplicit = outputConnection.IsImplicit; correctedInputConnection.OtherIndex = outputConnection.OtherIndex; if (newGC.codeBlockUIDMap.ContainsKey(outputConnection.OtherNode)) { correctedInputConnection.OtherNode = newGC.GetUidOfRHSIdentifierInCodeBlock( outputConnection.OtherNode, outputConnection.OtherIndex, outputConnection.LocalName); //correctedInputConnection.OtherNode = newGC.codeBlockUIDMap[outputConnection.OtherNode][outputConnection.OtherIndex]; } else { correctedInputConnection.OtherNode = originalGC.codeBlockUIDMap[outputConnection.OtherNode][outputConnection.OtherIndex]; } inputSnapshotNode.OutputList.Remove(outputConnection); inputSnapshotNode.OutputList.Insert(j, correctedInputConnection); } } } GB.nodesToAdd = inputs; GB.MakeConnectionsForAddedNodes_NodeToCode(GB.nodesToAdd); newGC.PrintGraph(); #endregion //GB.BuildGraphForCodeBlock(); List<uint> nodesToBeAdded = new List<uint>(); List<Node> nodesToBeReplaced = new List<Node>(); //adding children node from the originalGC to the newGC needed for the newGC to generate code foreach (Node n in completeList) { foreach (Node child in n.GetChildren()) { if (newGC.Graph.GetNode(child.Guid) != null) { if (child.Name != newGC.Graph.GetNode(child.Guid).Name) { nodesToBeReplaced.Add(child); } } } } foreach (uint n in nodesToBeAdded) { Node n1 = completeList.FirstOrDefault(q => q.Guid == n); //n1.children.Clear(); nodesToBeReplaced.Add(n1); //newSyncData.RemovedNodes.Add(n); } List<uint> nodeToCodeUIDs = new List<uint>(); foreach (SnapshotNode ssn in inputs) nodeToCodeUIDs.Add(ssn.Id); newGC.nodeToCodeUIDs = nodeToCodeUIDs; /*create output snapshot nodes*/ List<Connection> inputNodeInputConnections = new List<Connection>(); List<Connection> inputNodeOutputConnections = new List<Connection>(); foreach (SnapshotNode ssn in inputs) { foreach (Connection inputConnection in ssn.InputList) { if (!nodeToCodeUIDs.Contains(inputConnection.OtherNode)) inputNodeInputConnections.Add(inputConnection); } foreach (Connection outputConnection in ssn.OutputList) { if (!nodeToCodeUIDs.Contains(outputConnection.OtherNode)) inputNodeOutputConnections.Add(outputConnection); } } newGC.ReplaceNodesFromAList(nodesToBeReplaced); newSyncData.AddedNodes = new List<SnapshotNode>(); newSyncData.ModifiedNodes = new List<SnapshotNode>(); newSyncData.RemovedNodes = new List<uint>(); GB = new GraphBuilder(newSyncData, newGC); //string result = GB.BuildGraphDAG(); List<SnapshotNode> nodeToCodeBlocks = GB.PrintCodeForSelectedNodes(originalGC, inputs); /*for now, only connected nodes are supported: return all connections that are not internal connections (connections between the selected nodes)*/ //uint id = 0; //foreach (string content in toCode) //{ // SnapshotNode ssn = new SnapshotNode(); // ssn.Type = SnapshotNodeType.CodeBlock; // ssn.Content = content; // ssn.Id = id++; // ssn.InputList = new List<Connection>(); // //stupid stub // foreach (Connection inputConnection in inputNodeInputConnections) // { // Connection newInputConnection = new Connection(); // newInputConnection.OtherNode = inputConnection.OtherNode; // newInputConnection.OtherIndex = inputConnection.OtherIndex; // newInputConnection.IsImplicit = inputConnection.IsImplicit; // string[] tokens = newGC.Graph.GetNode(inputConnection.OtherNode).Name.Split('='); // newInputConnection.LocalName = tokens[0]; // ssn.InputList.Add(newInputConnection); // } // //ssn.InputList = inputNodeInputConnections; // ssn.OutputList = new List<Connection>(); // foreach (Connection outputConnection in inputNodeOutputConnections) // { // Connection newOutputConnection = new Connection(); // newOutputConnection.OtherNode = outputConnection.OtherNode; // newOutputConnection.OtherIndex = outputConnection.OtherIndex; // newOutputConnection.IsImplicit = outputConnection.IsImplicit; // //string[] tokens = originalGC.Graph.GetNode(outputConnection.OtherNode).Name.Split('='); // newOutputConnection.LocalName = outputConnection.LocalName; // ssn.OutputList.Add(newOutputConnection); // } // //ssn.OutputList = inputNodeOutputConnections; // codeBlocks.Add(ssn); //} /*update the original GC*/ foreach (SnapshotNode inputNode in inputs) { if (originalNodeUIDList.Contains(inputNode.Id)) originalGC.RemoveNodes(inputNode.Id, false); else { foreach (KeyValuePair<uint, Dictionary<int, uint>> kvp in originalGC.codeBlockUIDMap) { if (kvp.Value.ContainsValue(inputNode.Id)) { originalGC.RemoveNodes(kvp.Key, false); } } } } foreach (Node node in newGC.Graph.nodeList) { node.Name = node.Name.TrimEnd(';') + ";"; } originalGC.Graph.nodeList.Union<Node>(newGC.Graph.nodeList); //originalGC = newGC; /**/ return nodeToCodeBlocks; //return codeBlocks; } /// <summary> /// This is called to Parse individual assignment statements in Codeblock nodes in GraphUI /// and return the resulting ProtoAST node /// </summary> /// <param name="statement"></param> public static ProtoCore.AST.Node Parse(string statement, out ProtoCore.AST.AssociativeAST.CodeBlockNode commentNode) { commentNode = null; BuildCompileState(true); Validity.Assert(compileState != null); Validity.Assert(statement != null); if (string.IsNullOrEmpty(statement)) return null; System.IO.MemoryStream memstream = new System.IO.MemoryStream(System.Text.Encoding.UTF8.GetBytes(statement)); ProtoCore.DesignScriptParser.Scanner s = new ProtoCore.DesignScriptParser.Scanner(memstream); ProtoCore.DesignScriptParser.Parser p = new ProtoCore.DesignScriptParser.Parser(s, compileState); p.Parse(); commentNode = p.commentNode; return p.root; } public static List<ProtoCore.AST.Node> ParseCodeBlock(string code) { Validity.Assert(code != null); if (string.IsNullOrEmpty(code)) return null; // TODO: Change the logic to ignore Import statements in this case using parser - pratapa // Check if this will work with modifier blocks as well /*string[] stmts = code.Split(';'); string source = ""; for (int i=0; i < stmts.Length; ++i) { if (!stmts[i].Contains("import")) source += stmts[i] + ";"; }*/ ProtoLanguage.CompileOptions options = new ProtoLanguage.CompileOptions(); ProtoLanguage.CompileStateTracker compileState = new ProtoLanguage.CompileStateTracker(options); //compileState.Executives.Add(ProtoCore.Language.kAssociative, new ProtoAssociative.Executive(compileState)); //compileState.Executives.Add(ProtoCore.Language.kImperative, new ProtoImperative.Executive(compileState)); System.IO.MemoryStream memstream = new System.IO.MemoryStream(System.Text.Encoding.UTF8.GetBytes(code)); ProtoCore.DesignScriptParser.Scanner s = new ProtoCore.DesignScriptParser.Scanner(memstream); ProtoCore.DesignScriptParser.Parser p = new ProtoCore.DesignScriptParser.Parser(s, compileState); p.Parse(); ProtoCore.AST.AssociativeAST.CodeBlockNode cbn = p.root as ProtoCore.AST.AssociativeAST.CodeBlockNode; Validity.Assert(cbn != null); return p.GetParsedASTList(cbn); }
public UpdateGraphTask(SynchronizeData syncData, LiveRunner runner) : base(runner) { this.syncData = syncData; }
public void TestDeltaExecution03() { //=========================================================================== // Creates: // driver node a = 10 // driver node b= 20 // and using '+' operator node and assign it to idetifier //=========================================================================== ILiveRunner liveRunner = new ProtoScript.Runners.Obsolete.LiveRunner(); //=========================================================================== // Build the driver node a=10 //=========================================================================== GraphToDSCompiler.SynchronizeData data = new GraphToDSCompiler.SynchronizeData(); uint uidDriver1 = 1; uint uidDriver2 = 2; uint uidOp1 = 3; uint uidIdent1 = 4; Connection k1 = new Connection(); k1.LocalIndex = 0;// output slot k1.OtherIndex = 0;// input slot k1.OtherNode = uidOp1; k1.LocalName = "a"; Connection k2 = new Connection(); k2.LocalIndex = 0; k2.OtherIndex = 1; k2.OtherNode = uidOp1; k2.LocalName = "b"; Connection k4 = new Connection(); k4.LocalIndex = 0; k4.OtherIndex = 0; k4.OtherNode = uidDriver1; Connection k5 = new Connection(); k5.LocalIndex = 1; k5.OtherIndex = 0; k5.OtherNode = uidDriver2; Connection k6 = new Connection(); k6.LocalIndex = 0; k6.OtherIndex = 0; k6.OtherNode = uidIdent1; Connection k7 = new Connection(); k7.LocalIndex = 0; k7.OtherIndex = 0; k7.OtherNode = uidOp1; SnapshotNode n1 = new SnapshotNode(uidDriver1, SnapshotNodeType.CodeBlock, "a=10;"); n1.OutputList.Add(k1); SnapshotNode n2 = new SnapshotNode(uidDriver2, SnapshotNodeType.CodeBlock, "b=20;"); n2.OutputList.Add(k2); SnapshotNode n3 = new SnapshotNode(uidOp1, SnapshotNodeType.Function, ";+;double,double;temp"); n3.InputList.Add(k4); n3.InputList.Add(k5); n3.OutputList.Add(k6); SnapshotNode n4 = new SnapshotNode(uidIdent1, SnapshotNodeType.Identifier, "A"); n4.InputList.Add(k7); data.AddedNodes.Add(n1); data.AddedNodes.Add(n2); data.AddedNodes.Add(n3); data.AddedNodes.Add(n4); //=========================================================================== // Compile the current graph //=========================================================================== liveRunner.UpdateGraph(data); //=========================================================================== // Verify the value of Identifier //=========================================================================== ProtoCore.Mirror.RuntimeMirror mirror = liveRunner.QueryNodeValue(uidIdent1); Assert.IsTrue(mirror.GetData().GetStackValue().opdata == 30); }
private void ReportErrors(string code, SynchronizeData syncDataReturn, Dictionary<uint, string> modifiedGuidList, ref GraphUpdateReadyEventArgs retArgs) { Dictionary<ulong, ProtoCore.Core.ErrorEntry> errorMap = runner.runnerCore.LocationErrorMap; if (errorMap.Count == 0) return; retArgs = new GraphUpdateReadyEventArgs(syncDataReturn); foreach (var kvp in errorMap) { ProtoCore.Core.ErrorEntry err = kvp.Value; string msg = err.Message; int lineNo = err.Line; // If error is a Build error if (err.BuildId != ProtoCore.BuildData.WarningID.kDefault) { // Error comes from imported DS file if (!string.IsNullOrEmpty(err.FileName)) { msg += " At line " + err.Line + ", column " + err.Col + ", in " + Path.GetFileName(err.FileName); if (err.Type == ProtoCore.Core.ErrorType.Error) { retArgs.Errors.Add(new GraphUpdateReadyEventArgs.ErrorObject { Message = msg, Id = 0 }); } else if (err.Type == ProtoCore.Core.ErrorType.Warning) { retArgs.Warnings.Add(new GraphUpdateReadyEventArgs.ErrorObject { Message = msg, Id = 0 }); } continue; } } string varName = GetVarNameFromCode(lineNo, code); // Errors if (err.Type == ProtoCore.Core.ErrorType.Error) { // TODO: How can the lineNo be invalid ? if (lineNo == ProtoCore.DSASM.Constants.kInvalidIndex || varName == null) { retArgs.Errors.Add(new GraphUpdateReadyEventArgs.ErrorObject { Message = msg, Id = 0 }); continue; } foreach (var pair in runner.graphCompiler.mapModifiedName) { string name = pair.Key; if (name.Equals(varName)) { uint guid = pair.Value; retArgs.Errors.Add(new GraphUpdateReadyEventArgs.ErrorObject { Message = msg, Id = runner.graphCompiler.GetRealUID(guid) }); break; } } } else if (err.Type == ProtoCore.Core.ErrorType.Warning) // Warnings { // TODO: How can the lineNo be invalid ? if (lineNo == ProtoCore.DSASM.Constants.kInvalidIndex || varName == null) { retArgs.Warnings.Add(new GraphUpdateReadyEventArgs.ErrorObject { Message = msg, Id = 0 }); continue; } foreach (var pair in modifiedGuidList) { // Get the uid recognized by the graphIDE string name = pair.Value; if (name.Equals(varName)) { uint guid = pair.Key; retArgs.Warnings.Add(new GraphUpdateReadyEventArgs.ErrorObject { Message = msg, Id = runner.graphCompiler.GetRealUID(guid) }); break; } } if (retArgs.Warnings.Count == 0) { foreach (var pair in runner.graphCompiler.mapModifiedName) { string name = pair.Key; if (name.Equals(varName)) { uint guid = pair.Value; retArgs.Warnings.Add(new GraphUpdateReadyEventArgs.ErrorObject { Message = msg, Id = runner.graphCompiler.GetRealUID(guid) }); break; } } } } } }
private static SynchronizeData ListLevel(string[] b) { SynchronizeData sd = new SynchronizeData(); for (int i = 0; i < b.Length - 1; i++) { string[] c = b[i].Split(NodesCountMarker); int count = Int32.Parse(c[0]); if (count == 0) continue; else { if (i == 0) sd.RemovedNodes = UintNodesProcess(c[1]); else if (i == 1) sd.AddedNodes = SnapshotNodeListProcess(c[1]); else sd.ModifiedNodes = SnapshotNodeListProcess(c[1]); } } return sd; }
public static List<SnapshotNode> NodeToCodeBlocks(List<SnapshotNode> inputs, GraphToDSCompiler.GraphCompiler originalGC) { List<SnapshotNode> codeBlocks = new List<SnapshotNode>(); GraphToDSCompiler.GraphCompiler newGC = GraphCompiler.CreateInstance(); newGC.SetCore(core); GraphToDSCompiler.SynchronizeData newSyncData = new SynchronizeData(); newSyncData.AddedNodes = inputs; newSyncData.ModifiedNodes = new List<SnapshotNode>(); newSyncData.RemovedNodes = new List<uint>(); GraphToDSCompiler.GraphBuilder GB = new GraphBuilder(newSyncData, newGC); #region fix connection for multi-line CBN /*for multi-line code blocks*/ List<Node> completeList = originalGC.Graph.nodeList; List<uint> originalNodeUIDList = new List<uint>(); foreach (Node oriGcNode in completeList) { originalNodeUIDList.Add(oriGcNode.Guid); } GB.AddNodesToAST(); //List<SnapshotNode> inputsCopy = new List<SnapshotNode>(inputs); for (int i = 0; i < inputs.Count; i++) { SnapshotNode inputSnapshotNode = inputs[i]; for (int j = 0; j < inputSnapshotNode.InputList.Count; j++) { Connection inputConnection = inputSnapshotNode.InputList[j]; if (!originalNodeUIDList.Contains(inputConnection.OtherNode)) { Connection correctedInputConnection = new Connection(); correctedInputConnection.LocalName = inputConnection.LocalName; correctedInputConnection.LocalIndex = inputConnection.LocalIndex; correctedInputConnection.IsImplicit = inputConnection.IsImplicit; correctedInputConnection.OtherIndex = inputConnection.OtherIndex; if (newGC.codeBlockUIDMap.ContainsKey(inputConnection.OtherNode)) { correctedInputConnection.OtherNode = newGC.codeBlockUIDMap[inputConnection.OtherNode][inputConnection.OtherIndex]; } else { correctedInputConnection.OtherNode = originalGC.codeBlockUIDMap[inputConnection.OtherNode][inputConnection.OtherIndex]; } inputSnapshotNode.InputList.Remove(inputConnection); inputSnapshotNode.InputList.Insert(j, correctedInputConnection); } } for (int j = 0; j < inputSnapshotNode.OutputList.Count; j++) { Connection outputConnection = inputSnapshotNode.OutputList[j]; if (!originalNodeUIDList.Contains(outputConnection.OtherNode)) // if the other node is split { Connection correctedInputConnection = new Connection(); correctedInputConnection.LocalName = outputConnection.LocalName; correctedInputConnection.LocalIndex = outputConnection.LocalIndex; correctedInputConnection.IsImplicit = outputConnection.IsImplicit; correctedInputConnection.OtherIndex = outputConnection.OtherIndex; if (newGC.codeBlockUIDMap.ContainsKey(outputConnection.OtherNode)) { correctedInputConnection.OtherNode = newGC.GetUidOfRHSIdentifierInCodeBlock( outputConnection.OtherNode, outputConnection.OtherIndex, outputConnection.LocalName); //correctedInputConnection.OtherNode = newGC.codeBlockUIDMap[outputConnection.OtherNode][outputConnection.OtherIndex]; } else { correctedInputConnection.OtherNode = originalGC.codeBlockUIDMap[outputConnection.OtherNode][outputConnection.OtherIndex]; } inputSnapshotNode.OutputList.Remove(outputConnection); inputSnapshotNode.OutputList.Insert(j, correctedInputConnection); } } } GB.nodesToAdd = inputs; GB.MakeConnectionsForAddedNodes_NodeToCode(GB.nodesToAdd); newGC.PrintGraph(); #endregion //GB.BuildGraphForCodeBlock(); List<uint> nodesToBeAdded = new List<uint>(); List<Node> nodesToBeReplaced = new List<Node>(); //adding children node from the originalGC to the newGC needed for the newGC to generate code foreach (Node n in completeList) { foreach (Node child in n.GetChildren()) { if (newGC.Graph.GetNode(child.Guid) != null) { if (child.Name != newGC.Graph.GetNode(child.Guid).Name) { nodesToBeReplaced.Add(child); } } } } foreach (uint n in nodesToBeAdded) { Node n1 = completeList.FirstOrDefault(q => q.Guid == n); //n1.children.Clear(); nodesToBeReplaced.Add(n1); //newSyncData.RemovedNodes.Add(n); } List<uint> nodeToCodeUIDs = new List<uint>(); foreach (SnapshotNode ssn in inputs) nodeToCodeUIDs.Add(ssn.Id); newGC.nodeToCodeUIDs = nodeToCodeUIDs; /*create output snapshot nodes*/ List<Connection> inputNodeInputConnections = new List<Connection>(); List<Connection> inputNodeOutputConnections = new List<Connection>(); foreach (SnapshotNode ssn in inputs) { foreach (Connection inputConnection in ssn.InputList) { if (!nodeToCodeUIDs.Contains(inputConnection.OtherNode)) inputNodeInputConnections.Add(inputConnection); } foreach (Connection outputConnection in ssn.OutputList) { if (!nodeToCodeUIDs.Contains(outputConnection.OtherNode)) inputNodeOutputConnections.Add(outputConnection); } } newGC.ReplaceNodesFromAList(nodesToBeReplaced); newSyncData.AddedNodes = new List<SnapshotNode>(); newSyncData.ModifiedNodes = new List<SnapshotNode>(); newSyncData.RemovedNodes = new List<uint>(); GB = new GraphBuilder(newSyncData, newGC); //string result = GB.BuildGraphDAG(); List<SnapshotNode> nodeToCodeBlocks = GB.PrintCodeForSelectedNodes(originalGC, inputs); /*for now, only connected nodes are supported: return all connections that are not internal connections (connections between the selected nodes)*/ //uint id = 0; //foreach (string content in toCode) //{ // SnapshotNode ssn = new SnapshotNode(); // ssn.Type = SnapshotNodeType.CodeBlock; // ssn.Content = content; // ssn.Id = id++; // ssn.InputList = new List<Connection>(); // //stupid stub // foreach (Connection inputConnection in inputNodeInputConnections) // { // Connection newInputConnection = new Connection(); // newInputConnection.OtherNode = inputConnection.OtherNode; // newInputConnection.OtherIndex = inputConnection.OtherIndex; // newInputConnection.IsImplicit = inputConnection.IsImplicit; // string[] tokens = newGC.Graph.GetNode(inputConnection.OtherNode).Name.Split('='); // newInputConnection.LocalName = tokens[0]; // ssn.InputList.Add(newInputConnection); // } // //ssn.InputList = inputNodeInputConnections; // ssn.OutputList = new List<Connection>(); // foreach (Connection outputConnection in inputNodeOutputConnections) // { // Connection newOutputConnection = new Connection(); // newOutputConnection.OtherNode = outputConnection.OtherNode; // newOutputConnection.OtherIndex = outputConnection.OtherIndex; // newOutputConnection.IsImplicit = outputConnection.IsImplicit; // //string[] tokens = originalGC.Graph.GetNode(outputConnection.OtherNode).Name.Split('='); // newOutputConnection.LocalName = outputConnection.LocalName; // ssn.OutputList.Add(newOutputConnection); // } // //ssn.OutputList = inputNodeOutputConnections; // codeBlocks.Add(ssn); //} /*update the original GC*/ foreach (SnapshotNode inputNode in inputs) { if (originalNodeUIDList.Contains(inputNode.Id)) originalGC.RemoveNodes(inputNode.Id, false); else { foreach (KeyValuePair<uint, Dictionary<int, uint>> kvp in originalGC.codeBlockUIDMap) { if (kvp.Value.ContainsValue(inputNode.Id)) { originalGC.RemoveNodes(kvp.Key, false); } } } } foreach (Node node in newGC.Graph.nodeList) { node.Name = node.Name.TrimEnd(';') + ";"; } originalGC.Graph.nodeList.Union<Node>(newGC.Graph.nodeList); //originalGC = newGC; /**/ return nodeToCodeBlocks; //return codeBlocks; } /// <summary> /// This is called to Parse individual assignment statements in Codeblock nodes in GraphUI /// and return the resulting ProtoAST node /// </summary> /// <param name="statement"></param> public static ProtoCore.AST.Node Parse(string statement, out ProtoCore.AST.AssociativeAST.CodeBlockNode commentNode) { commentNode = null; BuildCore(true); Validity.Assert(core != null); Validity.Assert(statement != null); if (string.IsNullOrEmpty(statement)) return null; System.IO.MemoryStream memstream = new System.IO.MemoryStream(System.Text.Encoding.UTF8.GetBytes(statement)); ProtoCore.DesignScriptParser.Scanner s = new ProtoCore.DesignScriptParser.Scanner(memstream); ProtoCore.DesignScriptParser.Parser p = new ProtoCore.DesignScriptParser.Parser(s, core); p.Parse(); commentNode = p.commentNode; return p.root; } public static bool Parse(Guid nodeGUID, ref string code, out List<ProtoCore.AST.Node> parsedNodes, out IEnumerable<ProtoCore.BuildData.ErrorEntry> errors, out IEnumerable<ProtoCore.BuildData.WarningEntry> warnings, List<String> unboundIdentifiers, out List<String> tempIdentifiers) { tempIdentifiers = new List<string>(); List<String> compiledCode = new List<String>(); parsedNodes = null; //----------------------------------------------------------------------------------- //--------------------------------Correct the code----------------------------------- //----------------------------------------------------------------------------------- // Use the compile expression to format the code by adding the required %t temp vars // needed for non assignment statements CompileExpression(code, out compiledCode); string codeToParse = ""; for (int i = 0; i < compiledCode.Count; i++) { string tempVariableName = string.Format("temp_{0}_", i) + nodeGUID.ToString().Replace("-", "_"); tempIdentifiers.Add(tempVariableName); string singleExpression = compiledCode[i]; singleExpression = singleExpression.Replace("%t", tempVariableName); codeToParse += singleExpression; } code = codeToParse; //Catch the errors thrown by compile expression, namely function modiferstack and class decl found if (core.BuildStatus.ErrorCount > 0) { errors = core.BuildStatus.Errors; warnings = core.BuildStatus.Warnings; parsedNodes = null; return false; } // Parse and compile the code to get the result AST nodes as well as // any errors or warnings that were caught by the comiler ProtoCore.BuildStatus buildStatus; var tempUnboundIdentifiers = new Dictionary<int, List<VariableLine>>(); List<ProtoCore.AST.Node> nodeList = new List<ProtoCore.AST.Node>(); ParseCodeBlockNodeStatements(codeToParse, out tempUnboundIdentifiers, out nodeList, out buildStatus); errors = buildStatus.Errors; warnings = buildStatus.Warnings; //Get the unboundIdentifiers from the warnings foreach (KeyValuePair<int, List<VariableLine>> kvp in tempUnboundIdentifiers) { foreach (VariableLine vl in kvp.Value) { if (!unboundIdentifiers.Contains(vl.variable)) { unboundIdentifiers.Add(vl.variable); } } } // Assign the 'out' variables // Use the parse function to get the parsed nodes to return to the // user if (nodeList != null) { parsedNodes = new List<ProtoCore.AST.Node>(); ProtoCore.AST.AssociativeAST.CodeBlockNode cNode; parsedNodes = ParserUtils.GetAstNodes(Parse(codeToParse, out cNode)); } else { parsedNodes = null; } return true; } public static List<ProtoCore.AST.Node> ParseCodeBlock(string code) { Validity.Assert(code != null); if (string.IsNullOrEmpty(code)) return null; // TODO: Change the logic to ignore Import statements in this case using parser - pratapa // Check if this will work with modifier blocks as well /*string[] stmts = code.Split(';'); string source = ""; for (int i=0; i < stmts.Length; ++i) { if (!stmts[i].Contains("import")) source += stmts[i] + ";"; }*/ ProtoCore.Options options = new ProtoCore.Options(); ProtoCore.Core core = new ProtoCore.Core(options); core.Executives.Add(ProtoCore.Language.kAssociative, new ProtoAssociative.Executive(core)); core.Executives.Add(ProtoCore.Language.kImperative, new ProtoImperative.Executive(core)); System.IO.MemoryStream memstream = new System.IO.MemoryStream(System.Text.Encoding.UTF8.GetBytes(code)); ProtoCore.DesignScriptParser.Scanner s = new ProtoCore.DesignScriptParser.Scanner(memstream); ProtoCore.DesignScriptParser.Parser p = new ProtoCore.DesignScriptParser.Parser(s, core); p.Parse(); ProtoCore.AST.AssociativeAST.CodeBlockNode cbn = p.root as ProtoCore.AST.AssociativeAST.CodeBlockNode; Validity.Assert(cbn != null); return p.GetParsedASTList(cbn); }
private void MergeUndefinedVariablesIntoData(Dictionary<uint, List<string>> undefinitions, SynchronizeData sd) { // For more details please see "RuntimeStates.BeginDefinitionMonitor". if (null == undefinitions || (undefinitions.Count <= 0) || (null == sd)) return; List<SnapshotNode> modifiedNodes = sd.ModifiedNodes; if ((null == modifiedNodes) || (modifiedNodes.Count <= 0)) return; foreach (KeyValuePair<uint, List<string>> undefinition in undefinitions) { uint nodeId = undefinition.Key; SnapshotNode ssn = modifiedNodes.Find((x) => (x.Id == nodeId)); if (null != ssn) ssn.UndefinedVariables.AddRange(undefinition.Value); } }