Ejemplo n.º 1
0
        private List<AssociativeNode> GetAstsForBranch(int branch, List<AssociativeNode> inputAstNodes, bool verboseLogging, AstBuilder builder)
        {
            // Get all upstream nodes and then remove nodes that are not 
            var nodes = GetInScopeNodesForInport(branch, false).Where(n => !(n is Symbol));
            nodes = ScopedNodeModel.GetNodesInTopScope(nodes);

            // The second parameter, isDeltaExecution, is set to false so that
            // all AST nodes will be added to this IF graph node instead of 
            // adding to the corresponding graph node. 
            var allAstNodes = builder.CompileToAstNodes(nodes, Dynamo.DSEngine.AstBuilder.CompilationContext.None, verboseLogging);
            var astNodes = allAstNodes.SelectMany(t => t.Item2).ToList();
            astNodes.Add(AstFactory.BuildReturnStatement(inputAstNodes[branch]));
            return astNodes;
        }
Ejemplo n.º 2
0
        private List <AssociativeNode> GetAstsForBranch(int branch, List <AssociativeNode> inputAstNodes)
        {
            AstBuilder astBuilder = new AstBuilder(this.Workspace.DynamoModel, null);

            // Get all upstream nodes and then remove nodes that are not
            var nodes = GetInScopeNodesForInport(branch, false).Where(n => !(n is Symbol));

            nodes = ScopedNodeModel.GetNodesInTopScope(nodes);

            // The second parameter, isDeltaExecution, is set to false so that
            // all AST nodes will be added to this IF graph node instead of
            // adding to the corresponding graph node.
            var astNodes = astBuilder.CompileToAstNodes(nodes, false);

            astNodes.Add(AstFactory.BuildReturnStatement(inputAstNodes[branch]));
            return(astNodes);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Compile a collection of NodeModel to AST nodes in different contexts.
        /// If the context is ForNodeToCode, nodes should already be sorted in
        /// topological order.
        /// </summary>
        /// <param name="nodes"></param>
        /// <param name="context"></param>
        /// <param name="verboseLogging"></param>
        /// <returns></returns>
        public IEnumerable <Tuple <NodeModel, IEnumerable <AssociativeNode> > > CompileToAstNodes(
            IEnumerable <NodeModel> nodes,
            CompilationContext context,
            bool verboseLogging)
        {
            if (nodes == null)
            {
                throw new ArgumentNullException("nodes");
            }

            var topScopedNodes = ScopedNodeModel.GetNodesInTopScope(nodes);

            IEnumerable <NodeModel> sortedNodes = null;

            // Node should already be sorted!
            if (context == CompilationContext.NodeToCode)
            {
                sortedNodes = topScopedNodes;
            }
            else
            {
                sortedNodes = TopologicalSort(topScopedNodes);
            }

            if (context == CompilationContext.DeltaExecution)
            {
                sortedNodes = sortedNodes.Where(n => n.IsModified);
            }

            var result = new List <List <AssociativeNode> >();

            foreach (NodeModel node in sortedNodes)
            {
                var astNodes = new List <AssociativeNode>();
                CompileToAstNodes(node, astNodes, context, verboseLogging);
                result.Add(astNodes);
            }

            return(result.Zip(
                       sortedNodes,
                       (astNodes, node) => Tuple.Create(node, astNodes as IEnumerable <AssociativeNode>)));
        }
Ejemplo n.º 4
0
        /// <summary>
        ///     Compiling a collection of Dynamo nodes to AST nodes, no matter
        ///     whether Dynamo node has been compiled or not.
        /// </summary>
        /// <param name="nodes"></param>
        /// <param name="isDeltaExecution"></param>
        public List <AssociativeNode> CompileToAstNodes(IEnumerable <NodeModel> nodes, bool isDeltaExecution)
        {
            // TODO: compile to AST nodes should be triggered after a node is
            // modified.

            var topScopedNodes = ScopedNodeModel.GetNodesInTopScope(nodes);
            var sortedNodes    = TopologicalSort(topScopedNodes);

            if (isDeltaExecution)
            {
                foreach (var node in sortedNodes)
                {
                    var scopedNode = node as ScopedNodeModel;
                    if (scopedNode != null)
                    {
                        var dirtyInScopeNodes = scopedNode.GetInScopeNodes(false).Where(n => n.RequiresRecalc || n.ForceReExecuteOfNode);
                        scopedNode.RequiresRecalc = dirtyInScopeNodes.Any();
                        foreach (var dirtyNode in dirtyInScopeNodes)
                        {
                            dirtyNode.RequiresRecalc = false;
                        }
                    }
                }

                sortedNodes = sortedNodes.Where(n => n.RequiresRecalc || n.ForceReExecuteOfNode);
            }

            var result = new List <AssociativeNode>();

            foreach (NodeModel node in sortedNodes)
            {
                _CompileToAstNodes(node, result, isDeltaExecution);

                if (isDeltaExecution)
                {
                    node.RequiresRecalc = false;
                }
            }

            return(result);
        }
Ejemplo n.º 5
0
        /// <summary>
        ///     Compiling a collection of Dynamo nodes to AST nodes, no matter
        ///     whether Dynamo node has been compiled or not.
        /// </summary>
        /// <param name="nodes"></param>
        /// <param name="isDeltaExecution"></param>
        /// <param name="verboseLogging"></param>
        public List <AssociativeNode> CompileToAstNodes(IEnumerable <NodeModel> nodes, bool isDeltaExecution, bool verboseLogging)
        {
            // TODO: compile to AST nodes should be triggered after a node is
            // modified.

            var topScopedNodes = ScopedNodeModel.GetNodesInTopScope(nodes);
            var sortedNodes    = TopologicalSort(topScopedNodes);

            if (isDeltaExecution)
            {
                sortedNodes = sortedNodes.Where(n => n.IsModified);
            }

            var result = new List <AssociativeNode>();

            foreach (NodeModel node in sortedNodes)
            {
                _CompileToAstNodes(node, result, isDeltaExecution, verboseLogging);
            }

            return(result);
        }