private void _CompileToAstNodes(NodeModel node, List <AssociativeNode> resultList, bool isDeltaExecution) { var inputAstNodes = new List <AssociativeNode>(); foreach (int index in Enumerable.Range(0, node.InPortData.Count)) { Tuple <int, NodeModel> inputTuple; if (node.TryGetInput(index, out inputTuple)) { int outputIndexOfInput = inputTuple.Item1; NodeModel inputModel = inputTuple.Item2; AssociativeNode inputNode = inputModel.GetAstIdentifierForOutputIndex(outputIndexOfInput); inputAstNodes.Add(inputNode); } else { PortData port = node.InPortData[index]; inputAstNodes.Add( port.HasDefaultValue ? AstFactory.BuildPrimitiveNodeFromObject(port.DefaultValue) : new NullNode()); } } //TODO: This should do something more than just log a generic message. --SJE if (node.State == ElementState.Error) { dynSettings.Controller.DynamoLogger.Log("Error in Node. Not sent for building and compiling"); } if (isDeltaExecution) { OnAstNodeBuilding(node.GUID); } IEnumerable <AssociativeNode> astNodes = node.BuildAst(inputAstNodes); if (astNodes != null && isDeltaExecution) { OnAstNodeBuilt(node.GUID, astNodes); } resultList.AddRange(astNodes ?? new AssociativeNode[0]); }
private void CompileToAstNodes( NodeModel node, List <AssociativeNode> resultList, CompilationContext context, bool verboseLogging) { var inputAstNodes = new List <AssociativeNode>(); var inPortsCount = node.InPorts.Count; for (int index = 0; index < inPortsCount; index++) { Tuple <int, NodeModel> inputTuple; if (node.TryGetInput(index, out inputTuple)) { int outputIndexOfInput = inputTuple.Item1; NodeModel inputModel = inputTuple.Item2; AssociativeNode inputNode = inputModel.GetAstIdentifierForOutputIndex(outputIndexOfInput); inputAstNodes.Add(inputNode ?? new NullNode()); } else { if (node.InPorts.Count > index) { var port = node.InPorts[index]; if (port.UsingDefaultValue && port.DefaultValue != null) { inputAstNodes.Add(port.DefaultValue); } else { inputAstNodes.Add(new NullNode()); } } else { Log("Node does not have InPortData at the requested index."); } } } //TODO: This should do something more than just log a generic message. --SJE if (node.State == ElementState.Error) { Log("Error in Node. Not sent for building and compiling"); } if (context == CompilationContext.DeltaExecution) { OnAstNodeBuilding(node.GUID); if (ProfilingSession != null) { ProfilingSession.RegisterNode(node); resultList.Add(ProfilingSession.CreatePreCompilationAstNode(node, inputAstNodes)); } } else if (context == CompilationContext.PreviewGraph) { OnAstNodeBuilding(node.GUID); } #if DEBUG Validity.Assert(inputAstNodes.All(n => n != null), "Shouldn't have null nodes in the AST list"); #endif var scopedNode = node as ScopedNodeModel; IEnumerable <AssociativeNode> astNodes = scopedNode != null ? scopedNode.BuildAstInScope(inputAstNodes, verboseLogging, this) : node.BuildAst(inputAstNodes, context); foreach (var astNode in astNodes) { if (astNode.Kind == AstKind.BinaryExpression) { (astNode as BinaryExpressionNode).guid = node.GUID; } } if (context == CompilationContext.DeltaExecution) { resultList.AddRange(astNodes); if (ProfilingSession != null) { resultList.Add(ProfilingSession.CreatePostCompilationAstNode(node, inputAstNodes)); } OnAstNodeBuilt(node.GUID, resultList); } else if (context == CompilationContext.PreviewGraph) { resultList.AddRange(astNodes); OnAstNodeBuilt(node.GUID, resultList); } else if (context == CompilationContext.NodeToCode) { resultList.AddRange(astNodes); } else { // Inside custom node compilation bool notified = false; foreach (var item in astNodes) { if (item is FunctionDefinitionNode) { if (!notified) { OnAstNodeBuilding(node.GUID); } notified = true; // Register the function node in global scope with Graph Sync data, // so that we don't have a function definition inside the function def // of custom node. OnAstNodeBuilt(node.GUID, new[] { item }); } else { resultList.Add(item); } } if (verboseLogging) { foreach (var n in resultList) { Log(n.ToString()); } } } }
private void CompileToAstNodes(NodeModel node, List <AssociativeNode> resultList, CompilationContext context, bool verboseLogging) { var inputAstNodes = new List <AssociativeNode>(); foreach (int index in Enumerable.Range(0, node.InPortData.Count)) { Tuple <int, NodeModel> inputTuple; if (node.TryGetInput(index, out inputTuple)) { int outputIndexOfInput = inputTuple.Item1; NodeModel inputModel = inputTuple.Item2; AssociativeNode inputNode = inputModel.GetAstIdentifierForOutputIndex(outputIndexOfInput); #if DEBUG Validity.Assert(inputNode != null, "Shouldn't have null nodes in the AST list"); #endif inputAstNodes.Add(inputNode); } else { PortData port = node.InPortData[index]; inputAstNodes.Add(port.DefaultValue ?? new NullNode()); } } //TODO: This should do something more than just log a generic message. --SJE if (node.State == ElementState.Error) { Log("Error in Node. Not sent for building and compiling"); } if (context == CompilationContext.DeltaExecution) { OnAstNodeBuilding(node.GUID); } #if DEBUG Validity.Assert(inputAstNodes.All(n => n != null), "Shouldn't have null nodes in the AST list"); #endif var scopedNode = node as ScopedNodeModel; IEnumerable <AssociativeNode> astNodes = scopedNode != null ? scopedNode.BuildAstInScope(inputAstNodes, verboseLogging, this) : node.BuildAst(inputAstNodes, context); if (verboseLogging) { foreach (var n in astNodes) { Log(n.ToString()); } } if (null == astNodes) { resultList.AddRange(new AssociativeNode[0]); } else if (context == CompilationContext.DeltaExecution) { OnAstNodeBuilt(node.GUID, astNodes); resultList.AddRange(astNodes); } else if (context == CompilationContext.NodeToCode) { resultList.AddRange(astNodes); } else //Inside custom node compilation. { bool notified = false; foreach (var item in astNodes) { if (item is FunctionDefinitionNode) { if (!notified) { OnAstNodeBuilding(node.GUID); } notified = true; //Register the function node in global scope with Graph Sync data, //so that we don't have a function definition inside the function def //of custom node. OnAstNodeBuilt(node.GUID, new[] { item }); } else { resultList.Add(item); } } } }