当前位置: 首页>>代码示例>>C#>>正文


C# NodeModel.BuildAst方法代码示例

本文整理汇总了C#中Dynamo.Models.NodeModel.BuildAst方法的典型用法代码示例。如果您正苦于以下问题:C# NodeModel.BuildAst方法的具体用法?C# NodeModel.BuildAst怎么用?C# NodeModel.BuildAst使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Dynamo.Models.NodeModel的用法示例。


在下文中一共展示了NodeModel.BuildAst方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: _CompileToAstNodes

        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);

#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.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.DynamoLogger.Log("Error in Node. Not sent for building and compiling");

            if (isDeltaExecution)
                OnAstNodeBuilding(node.GUID);

#if DEBUG
            Validity.Assert(!inputAstNodes.Any((n) => n == null), 
                "Shouldn't have null nodes in the AST list");
#endif

            IEnumerable<AssociativeNode> astNodes = node.BuildAst(inputAstNodes);
            
            if (dynSettings.Controller.DebugSettings.VerboseLogging)
            {
                foreach (var n in astNodes)
                {
                    dynSettings.DynamoLogger.Log(n.ToString());
                }
            }

            if(null == astNodes)
                resultList.AddRange(new AssociativeNode[0]);
            else if (isDeltaExecution)
            {
                OnAstNodeBuilt(node.GUID, astNodes);
                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 AssociativeNode[] { item });
                    }
                    else
                        resultList.Add(item);
                }
            }
        }
开发者ID:heegwon,项目名称:Dynamo,代码行数:79,代码来源:AstBuilder.cs

示例2: CompileToAstNodes

        private void CompileToAstNodes(NodeModel node, List<AssociativeNode> resultList, CompilationContext context, bool verboseLogging)
        {

            var inputAstNodes = new List<AssociativeNode>();
            var inPortsCount = node.InPorts.Count;
            var inPortDataCount = node.InPortData.Count;

            //TODO: inputsCount should be removed in future. 
            // InPortData won't be used anymore, so we shouldn't take into account InPortData.Count.
            int inputsCount = inPortsCount > inPortDataCount ? inPortsCount : inPortDataCount;

            for (int index = 0; index < inputsCount; index++)
            {
                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
                {
                    if (node.InPorts.Count > index)
                    {
                        var port = node.InPorts[index];
                        if (port.UsingDefaultValue && port.DefaultValueEnabled)
                        {
                            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 || 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);

            if (verboseLogging)
            {
                foreach (var n in astNodes)
                {
                    Log(n.ToString());
                }
            }

            if(null == astNodes)
                resultList.AddRange(new AssociativeNode[0]);
            else if (context == CompilationContext.DeltaExecution || context == CompilationContext.PreviewGraph)
            {
                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 });
                    }
//.........这里部分代码省略.........
开发者ID:sh4nnongoh,项目名称:Dynamo,代码行数:101,代码来源:AstBuilder.cs


注:本文中的Dynamo.Models.NodeModel.BuildAst方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。